/* Twenty-One Rooms: interactive layer.
   Everything here is additive. Without JavaScript, or with reduced motion,
   the story reads exactly as a plain scrolling page. Motion styles only
   apply under html.fx, which rooms.js sets once it is ready. */

/* ---------- Controls: sound toggle + door rail (shown in all JS modes) ---------- */
.rooms-sound {
  position: fixed; top: 14px; right: 14px; z-index: 30;
  display: inline-flex; align-items: center; gap: 8px;
  font-family: 'Special Elite', 'Courier New', monospace;
  font-size: 0.8rem; letter-spacing: 0.12em; text-transform: uppercase;
  color: #8a8f9c; background: rgba(11,11,15,0.82);
  border: 2px solid #2b2f3a; border-radius: 999px;
  padding: 7px 14px 7px 11px; cursor: pointer;
}
.rooms-sound:hover { color: #f4ecd8; border-color: #8a8f9c; }
.rooms-sound[aria-pressed="true"] { color: #e8b923; border-color: #e8b923; }
.rooms-sound svg { width: 16px; height: 16px; flex: 0 0 auto; }
.rooms-sound, .rooms-rail { transition: transform .3s ease, opacity .3s ease; }
.rooms-tucked .rooms-rail { transform: translate(-50%, calc(100% + 24px)); }
.rooms-tucked .rooms-sound { transform: translateY(calc(-100% - 24px)); opacity: 0; }
.rooms-sound .wave { opacity: 0; }
.rooms-sound[aria-pressed="true"] .wave { opacity: 1; }
.rooms-sound[aria-pressed="true"] .mute { opacity: 0; }

.rooms-rail {
  position: fixed; left: 50%; bottom: 12px; z-index: 30;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px;
  background: rgba(11,11,15,0.86);
  border: 2px solid #2b2f3a; border-radius: 999px;
  padding: 7px 16px;
  max-width: calc(100vw - 24px);
}
.rooms-rail ol { list-style: none; margin: 0; padding: 0; display: flex; gap: 5px; align-items: flex-end; }
.rooms-rail a {
  display: block; width: 14px; height: 22px; position: relative;
  background: #14213d; border: 2px solid #2b2f3a; border-bottom-width: 3px;
  border-radius: 2px 2px 0 0;
  transition: background-color .3s, border-color .3s, box-shadow .3s;
}
.rooms-rail a::before { /* a bigger target than the little door */
  content: ""; position: absolute; left: -3px; right: -3px; top: -12px; bottom: -12px;
}
.rooms-rail .rail-head {
  font-family: 'Special Elite', 'Courier New', monospace; color: #8a8f9c;
  font-size: 0.72rem; letter-spacing: 0.14em; text-transform: uppercase;
}
.rooms-rail a::after { /* knob */
  content: ""; position: absolute; right: 2px; top: 9px;
  width: 2px; height: 2px; background: #8a8f9c; border-radius: 50%;
}
.rooms-rail a[aria-disabled="true"] { cursor: not-allowed; opacity: 0.55; }
.rooms-rail a.open { background: #fff3b0; border-color: #e8b923; }
.rooms-rail a.open::after { background: #d9891c; }
.rooms-rail a.here { box-shadow: 0 0 12px rgba(232,185,35,0.75); border-color: #e8b923; }
.rooms-rail a:focus-visible, .rooms-sound:focus-visible {
  outline: 3px solid #e8b923; outline-offset: 3px;
}
.rooms-rail .rail-label {
  font-family: 'Special Elite', 'Courier New', monospace;
  color: #f4ecd8; font-size: 0.82rem; letter-spacing: 0.08em;
  white-space: nowrap; min-width: 0; overflow: hidden; text-overflow: ellipsis;
  max-width: 220px;
}
.rooms-rail .rail-label b { color: #e8b923; font-weight: normal; }
.rooms-js body { padding-bottom: 64px; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto !important; } }

/* ---------- Chapter door (decorative) ---------- */
.room-door {
  display: block; position: relative;
  width: 58px; height: 88px; margin: 0 auto 16px;
  perspective: 260px;
}
.room-door .frame {
  position: absolute; inset: 0;
  background: #fff3b0;
  border: 3px solid #e8b923; border-bottom: none;
  box-shadow: 0 0 0 rgba(232,185,35,0);
  transition: box-shadow .4s;
}
.room-door .leaf {
  position: absolute; inset: 0;
  background: #14213d;
  border: 3px solid #e8b923; border-bottom: none;
  transform-origin: 0 50%;
  transform: rotateY(calc(var(--open, 0) * -78deg));
  backface-visibility: visible;
}
.room-door .leaf::after { /* knob */
  content: ""; position: absolute; right: 7px; top: 46%;
  width: 5px; height: 5px; border-radius: 50%; background: #e8b923;
}
.room-door .sill { position: absolute; left: -8px; right: -8px; bottom: -4px; height: 4px; background: #e8b923; }
.room-door .spill { /* light falling out of the room */
  position: absolute; left: -30%; right: -30%; top: 100%; height: 70px;
  background: linear-gradient(to bottom, rgba(232,185,35,0.38), rgba(232,185,35,0));
  clip-path: polygon(30% 0, 70% 0, 100% 100%, 0 100%);
  opacity: var(--open, 0);
  pointer-events: none;
}
.room-door.unlocked .frame { box-shadow: 0 0 34px rgba(232,185,35,0.55); }
/* Without motion (no html.fx) every door simply stands open. */
html:not(.fx) .room-door { --open: 0.85 !important; }

/* ---------- Cover: a wall of twenty-one doors ---------- */
.door-wall {
  position: absolute; inset: 0; z-index: 0; pointer-events: none;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.door-wall .grid {
  display: grid; grid-template-columns: repeat(7, 34px); gap: 22px 18px;
  opacity: 0.14;
}
.door-wall i {
  display: block; width: 34px; height: 54px; position: relative;
  background: #14213d; border: 2px solid #22305a;
}
.door-wall i::after {
  content: ""; position: absolute; right: 5px; top: 26px;
  width: 3px; height: 3px; border-radius: 50%; background: #8a8f9c;
}
.door-wall i.lit { background: #fff3b0; border-color: #e8b923; box-shadow: 0 0 30px rgba(232,185,35,0.9); }
.door-wall::after { /* vignette keeps the title readable */
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(ellipse at center, rgba(11,11,15,0.65) 0%, rgba(11,11,15,0.2) 45%, rgba(11,11,15,0.9) 100%);
}
.cover-inner { position: relative; z-index: 1; }

/* ---------- Background dust (parallax) ---------- */
.rooms-sky { position: fixed; inset: 0; z-index: -1; pointer-events: none; overflow: hidden; }
.rooms-sky div {
  position: absolute; left: 0; right: 0; top: 0; height: calc(100% + 480px);
  will-change: transform;
}
.rooms-sky .far {
  background-image:
    radial-gradient(1px 1px at 37px 61px, rgba(244,236,216,0.35), transparent 60%),
    radial-gradient(1px 1px at 151px 203px, rgba(244,236,216,0.25), transparent 60%),
    radial-gradient(1px 1px at 233px 97px, rgba(232,185,35,0.3), transparent 60%);
  background-size: 240px 240px;
}
.rooms-sky .near {
  background-image:
    radial-gradient(1.5px 1.5px at 71px 143px, rgba(232,185,35,0.35), transparent 60%),
    radial-gradient(2px 2px at 289px 37px, rgba(244,236,216,0.22), transparent 60%);
  background-size: 360px 360px;
}

/* ================= MOTION (only when html.fx) ================= */
.fx .room-panel {
  opacity: 0; translate: 0 24px;
  transition: opacity .4s ease, translate .5s cubic-bezier(.2,.75,.2,1);
}
.fx .room-panel.in { opacity: 1; translate: 0 0; }

.fx .room-panel .bubble,
.fx .room-panel .caption:not(.top) {
  opacity: 0; translate: 0 8px;
  transition: opacity .3s ease, translate .35s cubic-bezier(.2,.75,.2,1);
  transition-delay: min(calc(var(--i, 0) * 40ms + 60ms), 150ms);
}
.fx .room-panel.in .bubble,
.fx .room-panel.in .caption:not(.top) { opacity: 1; translate: 0 0; }

.fx .room-panel .sfx {
  opacity: 0; scale: 1.9;
  transition: opacity .2s ease, scale .45s cubic-bezier(.3,1.6,.45,1);
  transition-delay: min(calc(var(--i, 0) * 40ms + 60ms), 150ms);
}
.fx .room-panel.in .sfx { opacity: 1; scale: 1; }

/* Parallax inside panels: rooms.js sets --py (px offset from viewport centre). */
.fx .room-panel .figure-row { translate: 0 clamp(-14px, calc(var(--py, 0) * var(--pk, 1) * -0.04px), 14px); }
.fx .room-panel .glow       { translate: 0 calc(var(--py, 0) * var(--pk, 1) * 0.12px); }
/* Words always sit above the moving art. */
.fx .room-panel .caption:not(.top) { position: relative; }
.fx .room-panel .caption, .fx .room-panel .bubble { z-index: 2; }
.room-panel .sfx { position: relative; z-index: 3; }
.fx .door-wall .grid        { will-change: transform; }


@media (max-width: 760px) {
  .rooms-rail { padding: 6px 12px; gap: 8px; }
  .rooms-rail ol { gap: 3px; }
  .rooms-rail a { width: 12px; height: 19px; }
  .rooms-rail a::after { top: 7px; }
  .rooms-rail .rail-label, .rooms-rail .rail-head { display: none; }
  .rooms-rail { background: #0b0b0f; }
  .rooms-sound { top: 8px; right: 8px; width: 44px; height: 44px; padding: 0; justify-content: center; background: #0b0b0f; }
  .rooms-sound span { display: none; }
  .rooms-sound svg { width: 18px; height: 18px; }
  .door-wall .grid { grid-template-columns: repeat(7, 24px); gap: 16px 12px; }
  .door-wall i { width: 24px; height: 38px; }
  .door-wall i::after { top: 18px; right: 4px; }
}

@media print {
  .rooms-rail, .rooms-sound, .rooms-sky { display: none !important; }
  .fx .room-panel, .fx .room-panel * { opacity: 1 !important; translate: none !important; scale: none !important; }
}
