/* ============================================================
   THE WOVEN — Reader Portal ("The Living Map")
   Surface 4. Immersive, child-facing. Same navy-and-gold DNA as
   the rest of the site, warmed up: this is San Lirio at dusk, a
   place to wander, not a page to read.

   Loads AFTER style.css — inherits the :root design tokens
   (--ink-*, --gold*, --serif-*, --ease*). Portal-only tokens and
   overrides live here.
   ============================================================ */

:root {
  --portal-warm:   #F2C879;   /* lantern amber, the portal's signal colour */
  --portal-coral:  #E08A5B;   /* coral accent */
  --portal-glow:   rgba(242, 200, 121, 0.5);
  --portal-deep:   #090C14;   /* portal background, a touch deeper than --ink-1 */
}

/* ---- Page shell -------------------------------------------- */
html, body {
  height: 100%;
}
body.portal-body {
  margin: 0;
  background: var(--portal-deep);
  color: var(--text);
  font-family: var(--serif-body);
  overflow: hidden; /* the map owns the viewport */
}

.portal {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  opacity: 0;
  transition: opacity 700ms var(--ease-premium);
}
.portal.is-ready { opacity: 1; }

/* Accessibility / fail-safe: if JS never runs, the noscript block
   and the direct page are still here; nothing is trapped. */

/* ---- Top bar: title, book buttons, grown-ups link ---------- */
.portal-bar {
  position: relative;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  background: linear-gradient(180deg, rgba(9,12,20,0.92) 0%, rgba(9,12,20,0) 100%);
  pointer-events: none; /* let map pan-zoom through the gradient; children re-enable */
}
.portal-bar > * { pointer-events: auto; }

.portal-mark {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  text-decoration: none;
  color: var(--text-soft);
}
.portal-mark img { width: 30px; height: 30px; }
.portal-mark__text {
  font-family: var(--serif-display);
  font-size: var(--text-lg);
  letter-spacing: 0.01em;
}

/* The three book buttons */
.book-buttons {
  display: flex;
  gap: var(--space-3);
  list-style: none;
  margin: 0;
  padding: 0;
}
/* Image buttons. Art carries the "Book One/Two/Three" label; an
   sr-only span keeps the accessible name. 2172x724 art -> 3:1 box.
   Off art by default, glowing -on art when the book is selected. */
.book-btn {
  width: 138px;
  height: 46px;
  padding: 0;
  border: 0;
  background: transparent center / contain no-repeat;
  cursor: pointer;
  opacity: 0.82;
  transition: transform 220ms var(--ease-premium),
              opacity 220ms var(--ease), filter 220ms var(--ease);
}
.book-btn[data-book="1"] { background-image: url("../img/world/ui-book-button-1-off.png"); }
.book-btn[data-book="2"] { background-image: url("../img/world/ui-book-button-2-off.png"); }
.book-btn[data-book="3"] { background-image: url("../img/world/ui-book-button-3-off.png"); }
.book-btn:hover { opacity: 1; transform: translateY(-1px) scale(1.04); }
.book-btn.is-on {
  opacity: 1;
  filter: drop-shadow(0 0 9px var(--portal-glow));
}
.book-btn.is-on[data-book="1"] { background-image: url("../img/world/ui-book-button-1-on.png"); }
.book-btn.is-on[data-book="2"] { background-image: url("../img/world/ui-book-button-2-on.png"); }
.book-btn.is-on[data-book="3"] { background-image: url("../img/world/ui-book-button-3-on.png"); }
.book-btn:focus-visible {
  outline: 2px solid var(--portal-warm);
  outline-offset: 3px;
  border-radius: 6px;
}

.grownups-link {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--sans-ui);
  font-size: var(--text-xs);
  letter-spacing: 0.08em;
  color: var(--text-muted);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: color 240ms var(--ease), border-color 240ms var(--ease);
}
.grownups-link:hover {
  color: var(--text-soft);
  border-color: var(--gold-deep);
}
.grownups-icon {
  width: 28px;
  height: 28px;
  object-fit: contain;
  flex: none;
  transform-origin: center;
  transition: transform 280ms var(--ease-premium),
              filter 280ms var(--ease);
}
.grownups-link:hover .grownups-icon,
.grownups-link:focus-visible .grownups-icon {
  transform: scale(2.6);
  filter: drop-shadow(0 0 14px var(--gold-glow))
          drop-shadow(0 0 28px rgba(242,200,121,0.4));
}

/* ---- The map stage ----------------------------------------- */
.map-stage {
  position: relative;
  flex: 1;
  margin-top: -88px; /* slide up under the translucent bar */
  overflow: hidden;
}

/* Both map layers share this. */
.map-view {
  position: absolute;
  inset: 0;
  transition: opacity 900ms var(--ease-premium),
              transform 1100ms var(--ease-premium);
}

/* Base San Lirio map. The map fills the stage (background-size:
   cover) so the complete world is visible — no scale-up, nothing
   cropped beyond what cover already handles for non-16:9 viewports. */
#map-view { opacity: 1; transform: scale(1); transform-origin: 50% 50%; }
.portal.is-academy #map-view {
  opacity: 0;
  transform: scale(1.6); /* the camera pushes past the city... */
  pointer-events: none;
}
/* When the base map is hidden, its icons must not catch taps
   underneath the academy map. */
.portal.is-academy #map-view .loc-icon { pointer-events: none; }

/* Academy-world map — hidden until Book Three */
#academy-view {
  opacity: 0;
  transform: scale(0.7); /* ...and the wider world settles in */
  transform-origin: 50% 50%;
  pointer-events: none;
}
.portal.is-academy #academy-view {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}

/* The Book Three zoom-out transition video */
.zoom-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 20;
  opacity: 0;
  pointer-events: none;
  transition: opacity 300ms var(--ease);
}
.zoom-video.is-playing { opacity: 1; }
@media (prefers-reduced-motion: reduce) {
  .zoom-video { display: none; }
}

/* The painted map image / placeholder */
.map-base {
  position: absolute;
  inset: 0;
  background-color: var(--portal-deep);
  background-size: cover;
  background-position: center;
}

/* Placeholder look until the real PNG is dropped in.
   A warm dusk gradient that reads as "San Lirio at evening" so the
   portal is fully presentable for review with zero art. */
.map-base.art-missing {
  background-image:
    radial-gradient(ellipse 60% 50% at 50% 38%, rgba(242,200,121,0.22), transparent 70%),
    radial-gradient(ellipse 80% 60% at 50% 100%, rgba(35,52,82,0.9), transparent 70%),
    linear-gradient(180deg, #1a2236 0%, #12182a 45%, #0c1120 100%);
}
.map-base.art-missing::after {
  content: 'PLACEHOLDER  ·  ' attr(data-art-file);
  position: absolute;
  left: 50%;
  bottom: 1.4rem;
  transform: translateX(-50%);
  font-family: var(--sans-ui);
  font-size: var(--text-xs);
  letter-spacing: 0.18em;
  color: var(--text-faint);
  background: rgba(9,12,20,0.6);
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--rule-soft);
}

/* ---- Location icons ---------------------------------------- */
.icon-layer {
  position: absolute;
  inset: 0;
}

.loc-icon {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 76px;
  height: 76px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  /* z grows on hover so the label clears its neighbours */
  z-index: 1;
}
.loc-icon:hover,
.loc-icon:focus-visible { z-index: 5; outline: none; }

.loc-icon__medallion {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background-size: cover;
  background-position: center;
  /* No code-drawn ring — the new icon art is itself a complete
     medallion. We add only a soft drop shadow for depth. */
  filter: drop-shadow(0 3px 8px rgba(0,0,0,0.55));
  transition: transform 240ms var(--ease-premium),
              filter 240ms var(--ease);
}
/* Placeholder fill only — the ring above is shared, so a missing
   icon looks like the same medallion, just blank-gold. */
.loc-icon__medallion.art-missing {
  background-image:
    radial-gradient(circle at 38% 32%, #F6D58C, #C9A24A 62%, #8A6E2E 100%);
}
.loc-icon--home .loc-icon__medallion.art-missing {
  background-image:
    radial-gradient(circle at 38% 32%, #F0B98A, #E08A5B 64%, #9C5436 100%);
}
.loc-icon--academy .loc-icon__medallion.art-missing {
  background-image:
    radial-gradient(circle at 38% 32%, #BFE0E8, #6FA8B8 62%, #3C6675 100%);
}

.loc-icon:hover .loc-icon__medallion,
.loc-icon:focus-visible .loc-icon__medallion {
  transform: scale(1.16);
  filter: drop-shadow(0 0 18px var(--portal-glow))
          drop-shadow(0 4px 12px rgba(0,0,0,0.55));
}

/* Label — hidden by default, shown on hover (desktop) AND on
   focus (keyboard) AND on tap (touch sets :focus). */
.loc-icon__label {
  position: absolute;
  left: 50%;
  top: calc(100% + 8px);
  transform: translateX(-50%) translateY(-4px);
  white-space: nowrap;
  font-family: var(--sans-ui);
  font-size: var(--text-xs);
  letter-spacing: 0.06em;
  color: var(--text);
  background: rgba(9,12,20,0.92);
  border: 1px solid var(--gold-deep);
  border-radius: 6px;
  padding: 0.3rem 0.6rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms var(--ease), transform 200ms var(--ease);
}
.loc-icon:hover .loc-icon__label,
.loc-icon:focus-visible .loc-icon__label {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Newly unlocked icon — soft fade-and-glow reveal */
@keyframes iconReveal {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.4); }
  60%  { opacity: 1; transform: translate(-50%, -50%) scale(1.14); }
  100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
@keyframes iconRevealGlow {
  0%   { box-shadow: 0 0 0 0 var(--portal-glow); }
  100% { box-shadow: 0 0 26px 8px rgba(242,200,121,0); }
}
.loc-icon.is-revealing {
  animation: iconReveal 760ms var(--ease-premium) both;
}
.loc-icon.is-revealing .loc-icon__medallion {
  animation: iconRevealGlow 1400ms var(--ease) both;
}
.loc-icon.is-hiding {
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.5);
  transition: opacity 320ms var(--ease), transform 320ms var(--ease);
  pointer-events: none;
}

/* ---- Place modal ------------------------------------------- */
.place-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
}
.place-modal[hidden] { display: none; }
/* The dialog container is given tabindex="-1" so JS can focus it on open
   (W3C dialog pattern). The programmatic focus is intentionally invisible —
   keyboard users will see :focus-visible on the close button when they Tab. */
.place-modal:focus { outline: none; }

.modal-scrim {
  position: absolute;
  inset: 0;
  background: rgba(7,9,15,0.78);
  opacity: 0;
  transition: opacity 240ms var(--ease);
}
.place-modal.is-open .modal-scrim { opacity: 1; }

.modal-card {
  position: relative;
  width: min(560px, 100%);
  max-height: 86vh;
  overflow-y: auto;
  background: var(--ink-2);
  border: 1px solid var(--gold-deep);
  border-radius: 14px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.6);
  transform: translateY(20px) scale(0.97);
  opacity: 0;
  transition: transform 280ms var(--ease-premium), opacity 280ms var(--ease);
}
.place-modal.is-open .modal-card {
  transform: translateY(0) scale(1);
  opacity: 1;
}

.modal-close {
  position: absolute;
  top: 0.55rem;
  right: 0.55rem;
  z-index: 3;
  width: 46px;
  height: 46px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  transition: transform 200ms var(--ease-premium);
}
.modal-close img { width: 100%; height: 100%; object-fit: contain; display: block; }
.modal-close:hover { transform: scale(1.09); }
.modal-close:focus-visible { outline: 2px solid var(--portal-warm); outline-offset: 2px; }

.modal-body { padding: 0; }

.modal-art {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background-color: var(--ink-3);
  background-size: cover;
  background-position: center;
  border-radius: 14px 14px 0 0;
}
.modal-art.art-missing {
  display: flex;
  align-items: center;
  justify-content: center;
  background-image:
    radial-gradient(ellipse at 50% 40%, rgba(242,200,121,0.14), transparent 70%),
    linear-gradient(180deg, #1a2236, #12182a);
}
.modal-art.art-missing::after {
  content: 'pop-up art  ·  ' attr(data-art-file);
  font-family: var(--sans-ui);
  font-size: var(--text-xs);
  letter-spacing: 0.12em;
  color: var(--text-faint);
}

.modal-title {
  font-family: var(--serif-display);
  font-size: var(--text-xl);
  color: var(--text);
  margin: var(--space-5) var(--space-6) var(--space-3);
  font-weight: 500;
}
.modal-lore {
  font-family: var(--serif-body);
  font-size: var(--text-base);
  line-height: 1.66;
  color: var(--text-soft);
  margin: 0 var(--space-6) var(--space-6);
  /* Lore strings may carry "\n\n" between paragraphs (used by the
     character-home pop-ups to separate the character beat from the
     home description). pre-line collapses single spaces but honours
     line breaks. */
  white-space: pre-line;
}
.modal-lore--placeholder {
  color: var(--text-muted);
  font-style: italic;
  border-left: 2px solid var(--gold-deep);
  padding-left: var(--space-4);
}
.modal-activity { margin: 0 var(--space-6) var(--space-6); }

/* ---- Reduced motion ---------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .portal,
  .map-view,
  .loc-icon__medallion,
  .loc-icon__label,
  .modal-card,
  .modal-scrim {
    transition-duration: 1ms !important;
  }
  .loc-icon.is-revealing,
  .loc-icon.is-revealing .loc-icon__medallion {
    animation: none !important;
  }
  /* Book Three still resolves — it just snaps gently, no push. */
  .portal.is-academy #map-view { transform: scale(1); }
  #academy-view,
  .portal.is-academy #academy-view { transform: scale(1); }
}

/* ---- Small screens ----------------------------------------- */
@media (max-width: 640px) {
  .portal-bar {
    flex-wrap: wrap;
    padding: var(--space-3) var(--space-4);
  }
  .portal-mark__text { display: none; }
  .book-buttons { order: 3; width: 100%; justify-content: center; }
  .book-btn { width: 108px; height: 36px; }
  .map-stage { margin-top: 0; }
  .loc-icon { width: 52px; height: 52px; }
}

/* ---- All-places cluster (button on San Lirio) -------------- */
.cluster-toggle {
  position: absolute;
  left: var(--space-5);
  bottom: var(--space-5);
  z-index: 25;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.6rem 1rem 0.6rem 0.7rem;
  font-family: var(--sans-ui);
  font-size: var(--text-xs);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-soft);
  background: rgba(11,14,22,0.78);
  border: 1px solid var(--gold-deep);
  border-radius: 999px;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: color 220ms var(--ease), border-color 220ms var(--ease),
              box-shadow 220ms var(--ease), transform 220ms var(--ease-premium);
}
.cluster-toggle:hover {
  color: var(--portal-warm);
  border-color: var(--portal-warm);
  box-shadow: 0 0 18px var(--portal-glow);
  transform: translateY(-1px);
}
.cluster-toggle[aria-expanded="true"] {
  color: var(--portal-warm);
  border-color: var(--portal-warm);
  box-shadow: 0 0 22px var(--portal-glow);
}
.cluster-toggle__dots {
  display: grid;
  grid-template-columns: repeat(3, 4px);
  gap: 3px;
}
.cluster-toggle__dots span {
  width: 4px; height: 4px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.85;
}

.cluster-panel {
  position: absolute;
  left: var(--space-5);
  bottom: calc(var(--space-5) + 56px);
  z-index: 24;
  width: min(420px, calc(100% - var(--space-5) * 2));
  padding: var(--space-4);
  background: rgba(11,14,22,0.88);
  border: 1px solid var(--gold-deep);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  opacity: 0;
  transform: translateY(10px) scale(0.98);
  transition: opacity 220ms var(--ease), transform 220ms var(--ease-premium);
  /* Empty space of the panel is click-through so academy icons
     underneath stay reachable. Specific interactive children below
     reclaim pointer-events. */
  pointer-events: none;
}
.cluster-panel[hidden] { display: none; }
.cluster-panel.is-open { opacity: 1; transform: translateY(0) scale(1); }
.cluster-panel__head,
.cluster-panel__close,
.cluster-panel__grid .cluster-icon { pointer-events: auto; }

.cluster-panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}
.cluster-panel__title {
  margin: 0;
  font-family: var(--serif-display);
  font-size: var(--text-lg);
  color: var(--text);
  font-weight: 500;
  letter-spacing: 0.01em;
}
.cluster-panel__close {
  width: 32px; height: 32px;
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 50%;
  background: rgba(9,12,20,0.6);
  color: var(--text-soft);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  transition: color 200ms var(--ease), border-color 200ms var(--ease);
}
.cluster-panel__close:hover {
  color: var(--portal-warm);
  border-color: var(--gold-deep);
}

.cluster-panel__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  gap: 0.45rem 0.4rem;
}
.cluster-icon {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  color: var(--text-soft);
  transition: transform 200ms var(--ease-premium), color 200ms var(--ease);
}
.cluster-icon .loc-icon__medallion {
  width: 48px;
  height: 48px;
  background-size: cover;
  background-position: center;
  border-radius: 50%;
  filter: drop-shadow(0 3px 8px rgba(0,0,0,0.5));
}
.cluster-icon__label {
  font-family: var(--sans-ui);
  font-size: 0.6rem;
  letter-spacing: 0.04em;
  text-align: center;
  line-height: 1.1;
  color: var(--text-muted);
  max-width: 64px;
  word-break: normal;
}
.cluster-icon:hover {
  transform: translateY(-2px);
  color: var(--text);
}
.cluster-icon:hover .loc-icon__medallion {
  filter: drop-shadow(0 0 14px var(--portal-glow))
          drop-shadow(0 3px 8px rgba(0,0,0,0.5));
}
.cluster-icon:focus-visible {
  outline: 2px solid var(--portal-warm);
  outline-offset: 4px;
  border-radius: 6px;
}

@media (max-width: 640px) {
  .cluster-panel {
    width: calc(100% - var(--space-4) * 2);
    left: var(--space-4);
  }
}

/* ---- Loading veil ------------------------------------------ */
.portal-loading {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  background: radial-gradient(ellipse at center, #161d30 0%, #090c14 78%);
  transition: opacity 600ms var(--ease);
}
.portal-loading.is-done { opacity: 0; pointer-events: none; }
.portal-loading[hidden] { display: none; }
.portal-loading__art {
  width: 168px;
  height: 168px;
  object-fit: contain;
  animation: loadingPulse 2.6s var(--ease) infinite;
}
.portal-loading__text {
  font-family: var(--sans-ui);
  font-size: var(--text-xs);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-muted);
}
@keyframes loadingPulse {
  0%, 100% { transform: scale(1);    opacity: 0.82; }
  50%      { transform: scale(1.05); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .portal-loading { transition-duration: 1ms; }
  .portal-loading__art { animation: none; }
}

/* ---- noscript fallback ------------------------------------- */
.portal-noscript {
  position: fixed;
  inset: 0;
  z-index: 200; /* above the loading veil if JS never runs */
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-6);
  background: var(--portal-deep);
  z-index: 100;
}
.portal-noscript p {
  max-width: 32rem;
  font-family: var(--serif-body);
  font-size: var(--text-lg);
  color: var(--text-soft);
  line-height: 1.6;
}

/* Language toggle on the immersive portal — slightly muted; lets the bar's
   natural space-between distribute San Lirio · books · grown-ups · EN·ES
   evenly across the width, the way the original three-item bar read. */
.portal-lang { opacity: 0.85; }
.portal-lang a { color: rgba(255,255,255,0.7); }
.portal-lang a:hover { color: var(--gold); }
.portal-lang a[aria-current="true"] { color: #fff; }

@media (max-width: 760px) {
  .portal-lang { opacity: 1; }
}

/* Spanish portal: swap the book buttons to localised art.
   Same 2172x724 source dimensions, so layout, sizing, and positioning
   are inherited from the .book-btn rules above unchanged. */
html[lang="es"] .book-btn[data-book="1"] { background-image: url("../img/world/ui-libro-button-1-off.png"); }
html[lang="es"] .book-btn[data-book="2"] { background-image: url("../img/world/ui-libro-button-2-off.png"); }
html[lang="es"] .book-btn[data-book="3"] { background-image: url("../img/world/ui-libro-button-3-off.png"); }
html[lang="es"] .book-btn.is-on[data-book="1"] { background-image: url("../img/world/ui-libro-button-1-on.png"); }
html[lang="es"] .book-btn.is-on[data-book="2"] { background-image: url("../img/world/ui-libro-button-2-on.png"); }
html[lang="es"] .book-btn.is-on[data-book="3"] { background-image: url("../img/world/ui-libro-button-3-on.png"); }
