/* ROOM ENGINE styles (room.css). Pairs with room.js. A room is made of Words:

     the MONUMENT  the title in letters with depth (a white face on a red body, 6 slices),
                   standing on the end wall of the last zone
     the SEED      the same idea one zone earlier, flat: RUNS ON RAILS hung across the corridor
     the REVEAL    one sentence whose letters are scattered through depth and fall into line
                   from exactly one place (and, near it, are drawn together so it is easy to find)
     the FIELD     a few phrases hung across the last zone, readable head-on as you approach
     the CLIMATE   fog, edge shade, horizon glow and haze, driven by how far you have walked

   Only .wa[data-mode="walk"] is 3D. READ mode is the page's plain text (the article's blocks)
   under a slim control bar; a device that cannot walk the room (reduced motion, no 3D, no CSS
   nesting) is always in READ mode. No filter / opacity / overflow / mask anywhere in the depth
   chain (.wa-room and everything between it and the planes) - they would flatten the 3D. */

/* ---------- controls (both modes) ---------- */
.wa-hud {
  position: static;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  padding: 4px max(20px, env(safe-area-inset-left));
}
.wa-ctl, .wa-go { display: flex; align-items: center; gap: 4px; }
.wa-btn {
  appearance: none;
  border: 0;
  background: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0 10px;
  color: rgba(255, 255, 255, 0.82);
  font: 600 11px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  letter-spacing: 0.16em;
  text-decoration: none;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.85);
  cursor: pointer;
}
.wa-btn:hover,
.wa-btn:focus-visible { color: #fff; }
.wa-step { font-size: 18px; letter-spacing: 0; }
.wa-go, .wa-x, .wa-follow { display: none; }
.wa[data-can-walk="0"] .wa-mode { display: none; }
.wa[data-can-listen="0"] .wa-listen { display: none; }

/* READ mode: the room is not drawn; just the control bar, then the article's own text below */
.wa[data-mode="read"] .wa-room,
.wa[data-mode="read"] .wa-climate { display: none; }
.wa[data-mode="read"] .wa-pin { min-height: 0; }

/* the quiet listen / enter buttons in the page header (also for an article with no room) */
#reader .rd-listen {
  appearance: none;
  align-self: flex-start;
  min-height: 44px;
  margin: 0 0 0 18px;
  padding: 0;
  border: 0;
  background: none;
  color: rgba(255, 255, 255, 0.7);
  font: 600 12px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  letter-spacing: 0.22em;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.85);
  cursor: pointer;
}
#reader .rd-listen:hover,
#reader .rd-listen:focus-visible { color: #fff; text-decoration: underline; text-underline-offset: 6px; }
#reader .rd-listen[hidden] { display: none; }
/* the line being read aloud */
#reader .is-reading { color: var(--ink); box-shadow: -14px 0 0 0 rgba(196, 39, 27, 0.55); }

/* ---------- WALK mode ---------- */
.wa[data-mode="walk"] {
  --t: 0;
  --rv: 1;
  --fog: 0.55;
  --vig: 0.8;
  --glow: 0.1;
  --haze: 0.1;
  height: 0;
  margin: 0;

  .wa-pin {
    position: fixed;
    inset: 0;
    z-index: 2;
    padding: 0;
    overflow: hidden;
    perspective: var(--wa-eye, 520px);
    perspective-origin: 50% 46%;
    background: #000;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
  }
  /* the edges of the view fall into dark (strength from the atmosphere curve) */
  .wa-pin::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 3;
    pointer-events: none;
    background: radial-gradient(ellipse at 50% 46%, rgba(0, 0, 0, 0) 42%, rgba(0, 0, 0, var(--vig)) 100%);
  }

  /* climate: screen-space layers over the 3D scene */
  .wa-climate { position: absolute; inset: 0; z-index: 2; pointer-events: none; overflow: hidden; }
  .wa-haze {
    position: absolute;
    left: -20%;
    width: 140%;
    height: 60%;
    border-radius: 50%;
    background: radial-gradient(closest-side, rgba(150, 170, 200, 0.2), rgba(150, 170, 200, 0));
    opacity: var(--haze);
  }
  .wa-h1 { top: 4%; }
  .wa-h2 { top: 50%; }
  .wa-fog {
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at 50% 46%, rgba(0, 0, 0, 0.95) 0, rgba(0, 0, 0, 0) 62%);
    opacity: var(--fog);
  }
  .wa-ember {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 34%;
    background: radial-gradient(ellipse at 50% 100%, rgba(201, 130, 74, 0.55), rgba(201, 130, 74, 0) 70%);
    opacity: var(--glow);
  }
  .wa-grain {
    position: absolute;
    inset: 0;
    opacity: 0.05;
    background: repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.8) 0 1px, rgba(255, 255, 255, 0) 1px 3px);
  }

  /* the world: ONE transform from the camera (media/room.js), nothing else moves */
  .wa-room { position: absolute; inset: 0; transform-style: preserve-3d; will-change: transform; }
  .wa-shell, .wa-reveal, .wa-mono { position: absolute; inset: 0; margin: 0; transform-style: preserve-3d; display: block; }
  .wa-surface { position: absolute; left: 50%; top: 50%; display: block; }

  /* a zone is four planes (its --z0 is the distance from the mouth, --zl its length, --sw its width) */
  .wa-floor {
    width: var(--sw);
    height: var(--zl);
    margin: calc(var(--zl) / -2) 0 0 calc(var(--sw) / -2);
    transform: translateY(calc(var(--h) / 2)) translateZ(calc(var(--z0) * -1 - var(--zl) / 2)) rotateX(90deg);
    background:
      linear-gradient(to right, rgba(0, 0, 0, 0.45), rgba(0, 0, 0, 0) 20%, rgba(0, 0, 0, 0) 80%, rgba(0, 0, 0, 0.45)),
      repeating-linear-gradient(to bottom, var(--wa-line) 0 2px, rgba(255, 255, 255, 0) 2px 180px),
      var(--c-floor);
  }
  .wa-ceil {
    width: var(--sw);
    height: var(--zl);
    margin: calc(var(--zl) / -2) 0 0 calc(var(--sw) / -2);
    transform: translateY(calc(var(--h) / -2)) translateZ(calc(var(--z0) * -1 - var(--zl) / 2)) rotateX(-90deg);
    background:
      repeating-linear-gradient(to bottom, var(--wa-line) 0 2px, rgba(255, 255, 255, 0) 2px 240px),
      var(--c-ceil);
  }
  .wa-wall-l, .wa-wall-r {
    width: var(--zl);
    height: var(--h);
    margin: calc(var(--h) / -2) 0 0 calc(var(--zl) / -2);
  }
  .wa-wall-l {
    transform: translateX(calc(var(--sw) / -2)) translateZ(calc(var(--z0) * -1 - var(--zl) / 2)) rotateY(90deg);
    background:
      linear-gradient(to bottom, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0) 30%, rgba(0, 0, 0, 0) 70%, rgba(0, 0, 0, 0.5)),
      repeating-linear-gradient(to right, var(--wa-line) 0 2px, rgba(255, 255, 255, 0) 2px 200px),
      var(--c-wall);
  }
  .wa-wall-r {
    transform: translateX(calc(var(--sw) / 2)) translateZ(calc(var(--z0) * -1 - var(--zl) / 2)) rotateY(-90deg);
    background:
      linear-gradient(to bottom, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0) 30%, rgba(0, 0, 0, 0) 70%, rgba(0, 0, 0, 0.5)),
      repeating-linear-gradient(to left, var(--wa-line) 0 2px, rgba(255, 255, 255, 0) 2px 200px),
      var(--c-wall);
  }
  /* where the corridor opens into a wider zone: a wall across the gap, one each side */
  .wa-frame {
    width: var(--fw);
    height: var(--h);
    margin: calc(var(--h) / -2) 0 0 calc(var(--fw) / -2);
    transform: translateX(var(--fx)) translateZ(calc(var(--zj) * -1));
    background: var(--c-wall);
  }
  /* the front wall closes the room behind where you start; the end wall holds the monument */
  .wa-wall-f {
    width: var(--sw);
    height: var(--h);
    margin: calc(var(--h) / -2) 0 0 calc(var(--sw) / -2);
    transform: rotateY(180deg);
    background: var(--c-wall);
  }
  .wa-wall-b {
    width: var(--sw);
    height: var(--h);
    margin: calc(var(--h) / -2) 0 0 calc(var(--sw) / -2);
    transform: translateZ(calc(var(--L) * -1));
    background:
      radial-gradient(ellipse at 50% 100%, rgba(201, 130, 74, 0.3), rgba(201, 130, 74, 0) 62%),
      var(--c-wall);
  }

  /* phrases hung across the corridor, facing the walker (readable head-on) */
  .wa-banner {
    position: absolute;
    left: 50%;
    top: 50%;
    width: var(--bw);
    height: 1.1em;
    translate: -50% -50%;
    transform: translate3d(0, var(--by), calc(var(--bz) * -1));
    transform-style: preserve-3d;
    text-align: center;
    color: var(--wa-ink);
    font: 800 var(--bfs, 36px)/1.1 -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    letter-spacing: -0.01em;
    text-transform: uppercase;
    text-shadow: 0 2px 14px rgba(0, 0, 0, 0.7);
    white-space: nowrap;
  }
  /* the seed is flat: a face and one red shadow just behind it (the monument later has six) */
  .wa-seed .wa-bsh, .wa-seed .wa-bf { position: absolute; left: 0; right: 0; top: 0; }
  .wa-seed .wa-bsh { color: var(--wa-accent); transform: translate3d(5px, 5px, -8px); text-shadow: none; }

  /* the reveal: --rf is the letter size; each letter sits on its own ray from the reveal eyepoint.
     --k is how far along that ray (1 = on the target plane, aligned); --rv (0 near the eyepoint,
     1 far) blends from the aligned place (k=1) to its scattered place (k=k0). */
  .wa-reveal { font-size: var(--rf); }
  .wa-rl {
    --k: calc(1 + (var(--k0) - 1) * var(--rv));
    position: absolute;
    left: 50%;
    top: 50%;
    width: 1.1em;
    margin: -0.55em 0 0 -0.55em;
    text-align: center;
    font-weight: 800;
    line-height: 1.1;
    text-shadow: 0 2px 12px rgba(0, 0, 0, 0.7);
    color: var(--wa-ink);
    color: color-mix(in srgb, var(--wa-ink) calc((1 - var(--rv)) * 100%), var(--wa-accent));
    transform:
      translate3d(calc(var(--k) * var(--x)), calc(var(--k) * var(--y)), calc(var(--ze) - var(--k) * var(--rt)))
      scale(var(--k));
  }

  /* the monument: each letter is a stack of slices; the first is the white face, the rest the red body behind it */
  .wa-mono { font-size: var(--mf); }
  .wa-mch {
    position: absolute;
    left: 50%;
    top: 50%;
    transform-style: preserve-3d;
    transform: translate3d(var(--mx), 0, calc(var(--L) * -1 + var(--lift)));
  }
  .wa-sl {
    position: absolute;
    left: 0;
    top: 0;
    width: 1.2em;
    margin: -0.6em 0 0 -0.6em;
    text-align: center;
    font-weight: 800;
    line-height: 1.2;
    text-transform: uppercase;
    color: var(--wa-accent);
    transform: translateZ(calc(var(--j) * var(--sstep) * -1));
  }
  .wa-face { color: var(--wa-ink); }

  /* the control bar becomes the bottom bar of the room */
  .wa-hud {
    position: absolute;
    left: 0;
    right: 0;
    bottom: max(14px, env(safe-area-inset-bottom));
    z-index: 4;
    justify-content: space-between;
    padding: 0 max(18px, env(safe-area-inset-left));
  }
  .wa-go { display: flex; }
  .wa-x { display: inline-flex; }
  &[data-guide="off"][data-speaking="1"] .wa-follow { display: inline-flex; }
}

/* slow weather: time-based, a few px of travel, only where motion is allowed */
@media (prefers-reduced-motion: no-preference) {
  .wa-h1 { animation: wa-drift 52s ease-in-out infinite alternate; }
  .wa-h2 { animation: wa-drift 70s ease-in-out infinite alternate-reverse; }
}
@keyframes wa-drift { from { translate: 0 6%; } to { translate: -6% -10%; } }
