/* Player styles. No inline styles anywhere (strict CSP): state is expressed with classes. */
:root {
  --bg: #050403;
  --fg: #d9cfc2;
  --muted: #8a7f73;
  --accent: #b3341f;
  --glyph: #3594d6;
  --focus: #f2ce8c;   /* a warm, high-contrast ring that stays visible on the darkest image */
  --panel: rgba(12, 9, 7, 0.94);
  --line: rgba(217, 207, 194, 0.18);
  --hot: rgba(217, 207, 194, 0.55);
  --font: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body, #app { margin: 0; min-height: 100%; background: var(--bg); color: var(--fg); font-family: var(--font); }
html, body { height: 100%; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.btn {
  font: inherit; color: var(--fg); background: transparent; border: 1px solid var(--line);
  padding: 0.6em 1.2em; border-radius: 2px; cursor: pointer; letter-spacing: 0.04em;
}
.btn:hover { border-color: var(--fg); }
.btn:disabled { opacity: 0.35; cursor: default; }
.btn-primary { border-color: var(--accent); }
.btn-primary:hover { background: rgba(179, 52, 31, 0.15); }
.btn-small { padding: 0.3em 0.8em; min-width: 2.6em; }
.btn-quiet { border-color: transparent; color: var(--muted); }

/* --- the way in: door, age gate, opening ----------------------------------- */
.door, .gate, .left, .error { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.door-card, .gate-card { max-width: 34rem; }
.beacon { width: 18px; height: 18px; border-radius: 50%; background: #2a0d08; margin-bottom: 2rem; }
.beacon.on { background: var(--accent); box-shadow: 0 0 18px 4px rgba(179, 52, 31, 0.5); }
.door-heading { font-weight: normal; font-size: 1.6rem; margin: 0 0 0.4em; }
.door-signal { font: 0.95rem var(--mono); color: var(--muted); letter-spacing: 0.15em; }
.door-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 1.5em; }
.door-form label { flex-basis: 100%; color: var(--muted); }
.door-form input {
  font: 1.2rem/1 var(--mono); letter-spacing: 0.3em; text-transform: uppercase; padding: 0.5em;
  background: #000; color: var(--fg); border: 1px solid var(--line); flex: 1 1 12rem; min-width: 0;
}
.door-feedback { color: var(--accent); min-height: 1.4em; font-family: var(--mono); }
.door-hint { color: var(--muted); font-family: var(--mono); }

.gate-rating { color: var(--accent); letter-spacing: 0.3em; font-size: 0.85rem; margin: 0; text-transform: uppercase; }
.gate h1, .opening h1 { font-weight: normal; font-size: 2rem; margin: 0.2em 0 0.6em; }
.gate-sub { font-weight: normal; font-size: 0.85rem; letter-spacing: 0.2em; text-transform: uppercase; color: var(--muted); }
.gate-descriptors { padding-left: 1.1em; line-height: 1.7; }
.gate-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 1.5em; }
.left { color: var(--muted); }
.error pre { white-space: pre-wrap; color: var(--muted); max-width: 60rem; }

.opening { position: relative; min-height: 100%; display: grid; place-items: center; background: #000; }
.opening-media, .opening-media video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.opening-card { position: relative; max-width: 34rem; padding: 24px 16px; }
.opening-note { color: var(--muted); }

/* --- stage: a 16:9 box; the room's text sits under it ---------------------- */
.game { min-height: 100%; display: flex; flex-direction: column; align-items: center; padding-bottom: 16px; }
.stage, .room-text, .hud { width: min(100vw, calc((100vh - 280px) * 16 / 9), 1600px); }
.stage {
  position: relative; aspect-ratio: 16 / 9; flex: none;
  background: #000; overflow: hidden; user-select: none; -webkit-user-select: none;
}
.media, .media > * { position: absolute; inset: 0; width: 100%; height: 100%; }
.media img, .media video, .media canvas { display: block; width: 100%; height: 100%; object-fit: cover; }
.media .layer { animation: fade-in 450ms ease-out both; }
.media .layer.leaving { animation: fade-out 450ms ease-in both; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out { from { opacity: 1; } to { opacity: 0; } }
.media .placeholder { display: grid; place-items: center; text-align: center; color: var(--muted); padding: 16px; }
.media canvas { cursor: grab; touch-action: none; }
.media canvas.dragging { cursor: grabbing; }
.media canvas.hot { cursor: pointer; }

.hotspots { position: absolute; inset: 0; width: 100%; height: 100%; }
.hotspots.passthrough { pointer-events: none; }
.hotspot { fill: transparent; stroke: transparent; cursor: pointer; vector-effect: non-scaling-stroke; }
.hotspot:hover { fill: rgba(242, 206, 140, 0.06); }
.hotspot.lit { fill: rgba(242, 206, 140, 0.10); stroke: var(--focus); stroke-width: 2px; }
.debug-on .hotspot { stroke: var(--hot); stroke-width: 1px; stroke-dasharray: 4 3; }

.caption {
  position: absolute; left: 0; right: 0; bottom: 0; margin: 0; padding: 14px 18px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.8)); font-style: italic; color: var(--fg);
  opacity: 0; transition: opacity 400ms; pointer-events: none;
}
.caption.show { opacity: 1; }
.skip { position: absolute; right: 12px; bottom: 12px; background: rgba(0, 0, 0, 0.5); }
.debug { position: absolute; top: 8px; left: 8px; margin: 0; padding: 4px 8px; font: 12px var(--mono); background: rgba(0,0,0,0.7); }

/* the fail card's recording: it arrives a moment after the card, without flashing */
.fail {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 18px 20px; display: flex; gap: 16px;
  align-items: flex-end; justify-content: space-between; flex-wrap: wrap;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.85));
}
.fail-recording { margin: 0; opacity: 0; transition: opacity 900ms ease-in; max-width: 40rem; }
.fail.speaking .fail-recording { opacity: 1; }
.fail-speaker { display: block; font: 0.75rem var(--mono); letter-spacing: 0.2em; color: var(--accent); text-transform: uppercase; }
.fail-line { font-style: italic; font-size: 1.25rem; }

/* the room in words: description, places (the keyboard route), back, last thing said */
.room-text { padding: 12px 16px 0; }
.describe { margin: 0 0 10px; color: var(--fg); line-height: 1.55; max-width: 72ch; }
.places { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.btn-place { font-size: 0.95rem; padding: 0.4em 0.9em; }
#back { margin-top: 10px; }
.transcript { margin: 10px 0 0; color: var(--muted); font-style: italic; line-height: 1.5; max-width: 72ch; min-height: 1.5em; }

/* --- HUD ------------------------------------------------------------------ */
.hud { min-height: 56px; display: flex; align-items: center; gap: 16px; padding: 8px 16px; }
.inventory { display: flex; gap: 8px; list-style: none; margin: 0; padding: 0; flex-wrap: wrap; }
.inventory .item { font: inherit; font-size: 0.9rem; color: var(--fg); background: transparent; border: 1px solid var(--line); padding: 0.35em 0.8em; cursor: help; }
.inventory .item.new { border-color: var(--accent); animation: fade-in 800ms; }
.message { margin: 0 0 0 auto; color: var(--muted); font-style: italic; text-align: right; }

/* --- puzzle dialog ----------------------------------------------------------- */
.puzzle {
  background: var(--panel); color: var(--fg); border: 1px solid var(--line); padding: 24px;
  width: min(30rem, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow: auto;
}
.puzzle.wide { width: min(60rem, calc(100vw - 32px)); }
.puzzle::backdrop { background: rgba(0, 0, 0, 0.7); }
.puzzle-prompt { margin-top: 0; line-height: 1.5; }
.puzzle-body { display: grid; gap: 16px; }
.puzzle.comparing .puzzle-body { grid-template-columns: 1fr 1fr; align-items: start; }
.puzzle-input input:not([type]), .puzzle-input input[type="text"] {
  font: 1.6rem/1 var(--mono); letter-spacing: 0.4em; width: 100%; padding: 0.4em;
  background: #000; color: var(--fg); border: 1px solid var(--line);
}
.puzzle-input .choices { display: grid; gap: 8px; }
.puzzle-feedback { min-height: 1.4em; color: var(--accent); }
.puzzle-hint { color: var(--muted); font-style: italic; }
.puzzle-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.puzzle.shake { animation: shake 300ms; }
.puzzle.pending .puzzle-actions { opacity: 0.5; pointer-events: none; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

.evidence { display: grid; gap: 10px; }
.evidence-item { border-left: 2px solid var(--line); padding: 2px 0 2px 12px; }
.evidence-title { font: 0.75rem var(--mono); letter-spacing: 0.15em; text-transform: uppercase; color: var(--muted); margin: 0 0 6px; font-weight: normal; }
.evidence-text { margin: 6px 0 0; line-height: 1.45; }
.figure { display: block; width: 100%; max-width: 30rem; height: auto; }
.figure-mark { stroke: var(--fg); stroke-width: 3; }
.figure-gap { stroke: var(--glyph); stroke-width: 2; stroke-dasharray: 3 3; }
.figure-name { fill: var(--muted); font: 11px var(--mono); text-anchor: middle; }

.arrange { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 8px; }
.arrange-item { display: grid; grid-template-columns: 5.5rem 1fr auto; gap: 10px; align-items: center; border: 1px solid var(--line); padding: 8px 10px; }
.arrange-pos { font: 0.75rem var(--mono); letter-spacing: 0.15em; text-transform: uppercase; color: var(--glyph); }
.arrange-body { display: grid; gap: 4px; }
.arrange-detail { color: var(--muted); font-size: 0.9rem; line-height: 1.4; }
.arrange-tag { font: inherit; font-size: 0.9rem; background: #000; color: var(--fg); border: 1px solid var(--line); padding: 0.25em; justify-self: start; }
.arrange-moves { display: flex; gap: 6px; }
.slots { display: grid; gap: 8px; }
.slot { border: 1px solid var(--line); padding: 8px 12px; display: flex; gap: 18px; flex-wrap: wrap; }
.slot legend { padding: 0 6px; color: var(--glyph); font-family: var(--mono); font-size: 0.85rem; }
.slot-option { cursor: pointer; }

@media (max-width: 640px) {
  .stage, .room-text, .hud { width: 100vw; }
  .hud { flex-direction: column; align-items: flex-start; }
  .message { margin: 0; text-align: left; }
  .puzzle.comparing .puzzle-body { grid-template-columns: 1fr; }
  .arrange-item { grid-template-columns: 1fr auto; }
  .arrange-pos { grid-column: 1 / -1; }
}
@media (prefers-reduced-motion: reduce) {
  .media .layer, .media .layer.leaving, .inventory .item.new, .puzzle.shake { animation: none; }
  .fail-recording, .caption { transition: none; }
}

/* The node panel (main.js). */
.node-panel { max-width: 34rem; }
.node-note { color: var(--muted); font-size: 0.9rem; line-height: 1.5; }
.node-recovery { border: 1px solid var(--muted); padding: 0.75rem 1rem; margin: 0.75rem 0; }
.node-recovery-code { font-family: ui-monospace, Menlo, monospace; font-size: 1.25rem; letter-spacing: 0.08em;
                      user-select: all; }
.node-invite { font-family: ui-monospace, Menlo, monospace; word-break: break-all; user-select: all; }

/* --- the viewer (scene.js; docs/room.md → Direction) ---------------------------------------------------------
   body.scene-mode: the whole screen is the room. Landscape first; portrait shows the same scene narrower and
   one line. The room's text stays in the page for screen readers and the keyboard (it shows when focused). */
.scene-canvas, .scene-marks, .scene-lines, .scene-grain, .turn { display: none; }
body.scene-mode { overflow: hidden; touch-action: none; -webkit-tap-highlight-color: transparent; }
body.scene-mode .game { padding: 0; }
body.scene-mode .stage { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; aspect-ratio: auto; }
body.scene-mode .stage.in-scene .media, body.scene-mode .stage.in-scene .hotspots { display: none; }
.stage.in-scene .scene-canvas { display: block; position: absolute; inset: 0; width: 100%; height: 100%; cursor: grab; touch-action: none; }
.stage.in-scene .scene-canvas.dragging { cursor: grabbing; }
.stage.in-scene .scene-marks, .stage.in-scene .scene-lines {
  display: block; position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.scene-marks .mark .hit { fill: transparent; }
.scene-marks .mark .stroke { fill: none; stroke: var(--glyph); stroke-width: 1.3; stroke-linecap: round;
  stroke-dasharray: 1; stroke-dashoffset: 1; transition: stroke-dashoffset 0.6s ease-out; }
.scene-marks .mark .dot { fill: var(--glyph); opacity: 0; transition: opacity 0.6s ease-out; }
.scene-marks .mark.on .stroke { stroke-dashoffset: 0; }
.scene-marks .mark.on .dot { opacity: 1; }
.scene-marks .mark.on { pointer-events: auto; cursor: pointer; }
.scene-lines path { fill: none; stroke: var(--glyph); stroke-width: 1.2; stroke-linecap: round; stroke-linejoin: round;
  stroke-dasharray: 1; }
/* the look test's grain: fine and slow (3 changes a second); heavier after a fold */
body.scene-mode .scene-grain { display: block; position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none; opacity: 0.07; mix-blend-mode: screen; image-rendering: pixelated; transition: opacity 1.2s; }
body.scene-mode .stage.folded .scene-grain { opacity: 0.16; }
@media (orientation: portrait) {
  body.scene-mode .turn { display: block; position: absolute; left: 0; right: 0; bottom: 18%; margin: 0; z-index: 3;
    text-align: center; font: 11px var(--mono); letter-spacing: 0.1em; color: rgba(255, 255, 255, 0.55); pointer-events: none; }
}
body.scene-mode .caption { z-index: 3; padding: 14px max(18px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left)); }
body.scene-mode .fail { z-index: 4; }
/* the HUD floats, small and mono, over the room */
body.scene-mode .hud { position: fixed; top: max(6px, env(safe-area-inset-top)); left: max(8px, env(safe-area-inset-left));
  right: max(8px, env(safe-area-inset-right)); width: auto; min-height: 0; padding: 0; gap: 8px; z-index: 5; pointer-events: none; }
body.scene-mode .hud > * { pointer-events: auto; }
body.scene-mode .hud .btn, body.scene-mode .inventory .item { font: 11px var(--mono); letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.85); background: rgba(0, 0, 0, 0.5); border-color: transparent; padding: 6px 8px; }
.hud-back { display: none; }
body.scene-mode .hud-back:not([hidden]) { display: inline-block; }
body.scene-mode .message { font: 11px var(--mono); color: rgba(255, 255, 255, 0.7); text-shadow: 0 0 6px #000; }
body.scene-mode .room-text { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; width: auto; padding: 12px 16px;
  background: var(--panel); clip-path: inset(50%); }
body.scene-mode .room-text:focus-within { clip-path: none; }
/* puzzles: the existing inputs, as an overlay on the room (the mechanisms come in the next sessions) */
body.scene-mode .puzzle { background: rgba(8, 10, 12, 0.86); backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); }
body.scene-mode .puzzle::backdrop { background: rgba(0, 0, 0, 0.35); }
@media (prefers-reduced-motion: reduce) {
  .scene-marks .mark .stroke, .scene-marks .mark .dot, body.scene-mode .scene-grain { transition: none; }
}
