/*
 * screens.css — shared look for the Observe and Replay screens (Requirement 12).
 *
 * Ported from the approved Halloween look of pilot/look.php. Encodes:
 *   - DotGothic16 with a sans-serif fallback and text visible during font load
 *     via font-display: swap (Req 12.1, 12.2).
 *   - image-rendering: pixelated on the canvas so the 480x236 house scales
 *     crisply (Req 12.3).
 *   - mobile-first layout from a 320px viewport with 16px gutters and no
 *     horizontal scroll (Req 12.3).
 *   - a visible :focus-visible indicator with >= 3:1 contrast on controls
 *     (Req 12.4).
 *   - a prefers-reduced-motion rule that short-circuits CSS motion (Req 12.6).
 *
 * The overlay class names (.name.claude / .name.gpt / .name.man, .bubble with
 * .show / .think, .bubble .who, .tail with .show / .think) match exactly what
 * public/js/house-renderer.js emits in buildOverlay/placeOverlay, so the
 * overlay renders without the renderer changing. Structural classes for the
 * screen layouts (title, tagline, canvas wrap, breaker switches, meters, log,
 * controls) are included so tasks 9.2/10.1 only add markup.
 *
 * The @import pulls DotGothic16 with display=swap; the HTML pages also add the
 * Google Fonts <link> (tasks 9.2/10.1). font-display: swap keeps fallback text
 * visible while the webfont loads (Req 12.2).
 */
@import url('https://fonts.googleapis.com/css2?family=DotGothic16&display=swap');

/* ── Halloween palette (ported from pilot/look.php) ───────────────────────── */
:root {
  --night: #120e22;
  --wood: #3a2618;
  --wood-hi: #5a3d26;
  --straw: #d9c79a;
  --lantern: #f0922b;
  --ember: #ffcf7a;
  --bone: #efe6cb;
  --mute: #a99c84;
  --jade: #47c1a0;
  --amber: #e7ad45;
  --alarm: #e5533d;
  --gutter: 16px;
}

* { box-sizing: border-box; }

/* The hidden attribute must beat the layout rules below. The screen regions
   that start hidden (the house, reply panels, and controls on Replay) carry
   a display: grid/flex rule that would otherwise override the browser default
   [hidden] { display: none }, so they must stay hidden until an episode loads
   (Req 8.2, 8.7). */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--night);
  color: var(--bone);
  /* DotGothic16 with a sans-serif fallback; text stays visible during load
     (Req 12.1, 12.2 — the @import above sets display=swap). */
  font-family: 'DotGothic16', sans-serif;
}

body {
  min-height: 100vh;
  /* No horizontal scroll at any width from 320px up (Req 12.3). */
  overflow-x: hidden;
}

/* ── mobile-first container: 320px up, 16px gutters, no overflow (Req 12.3) ── */
.wrap {
  width: 100%;
  max-width: 1480px;
  margin: 0 auto;
  padding: var(--gutter);
}

/* ── header: title, tagline, model line (Req 4.2) ─────────────────────────── */
header { padding: 4px 0 12px; }

h1 {
  font-weight: 400;
  font-size: clamp(26px, 6vw, 52px);
  line-height: 1.08;
  margin: 0;
  color: var(--lantern);
  text-shadow: 0 0 14px rgba(240, 146, 43, .45);
}

.tag {
  margin: 6px 0 0;
  color: var(--mute);
  font-size: 15px;
  max-width: 62ch;
  line-height: 1.55;
}

.models {
  margin: 6px 0 0;
  color: var(--bone);
  font-size: 13px;
  line-height: 1.5;
}

a { color: var(--ember); }
a:hover { color: var(--lantern); }

/* ── stage: canvas wrap + overlay (renderer draws here) ───────────────────── */
.stage {
  background: #000;
  border: 3px solid var(--wood);
  border-radius: 4px;
  /* Allow the fixed-geometry inner to scroll only if a very narrow viewport
     forces it, never the page body. */
  overflow: hidden;
}

/* The inner holds the canvas and the absolutely-positioned overlay stacked on
   top. position: relative is required because the renderer sets each overlay
   element's left/top relative to this box. */
.inner {
  position: relative;
  width: 100%;
}

/* image-rendering: pixelated so the 480x236 house scales crisply (Req 1.1,
   12.3). The canvas fills the inner width and keeps its aspect ratio. */
canvas {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* The overlay sits over the canvas and never intercepts pointer events, so the
   switches and controls underneath stay clickable. */
.overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* ── name tags (classes emitted by house-renderer.js buildOverlay) ────────── */
.name {
  position: absolute;
  transform: translate(-50%, 0);
  font-size: clamp(9px, 2.6vw, 13px);
  padding: 0 4px;
  border-radius: 2px;
  color: #120e22;
  white-space: nowrap;
}
.name.claude { background: var(--amber); } /* Amber (robot_a) */
.name.gpt { background: var(--jade); }     /* Jade (robot_b) */
.name.man { background: var(--straw); }

/* ── speech bubbles (SPOKEN lines only; never a thought — Req 1.14, 3.6) ──── */
.bubble {
  position: absolute;
  max-width: min(36ch, 46%);
  background: var(--bone);
  color: #1a1420;
  border: 2px solid #1a1420;
  padding: 6px 9px 7px;
  font-size: clamp(11px, 3vw, 15px);
  line-height: 1.38;
  border-radius: 3px;
  box-shadow: 3px 3px 0 rgba(0, 0, 0, .5);
  opacity: 0;
  transition: opacity .2s;
}
.bubble.show { opacity: 1; }
/* The think style exists for parity with the ported markup, but the renderer
   never adds `think` with content — thoughts are never shown (Req 1.14, 3.6). */
.bubble.think {
  background: #2a2140;
  color: var(--bone);
  border-color: #8f80b8;
  font-style: italic;
}
.bubble .who {
  display: block;
  font-size: .78em;
  color: #6b5a48;
  font-style: normal;
}
.bubble.think .who { color: #b7a9dd; }

.tail {
  position: absolute;
  width: 0;
  height: 0;
  border: 6px solid transparent;
  border-top-color: #1a1420;
  opacity: 0;
  transition: opacity .2s;
}
.tail.show { opacity: 1; }
.tail.think { border-top-color: #8f80b8; }

/* ── narrow-screen caption strip (under the canvas below 560 CSS px) ───────
   The House_Renderer inserts this element itself (buildCaption) directly after
   the .stage and fills it only while the canvas is rendered narrower than
   560 CSS px, so bubbles never cover or overlap the house at 320–390 px
   (Req 1.13, 3.4, 3.5, 3.7, 12.3). Spoken lines only — never a thought. When
   empty it takes no space. */
.caption-strip {
  width: 100%;
  margin-top: 4px;
  padding: 6px 9px;
  background: #15101f;
  color: var(--bone);
  border: 2px solid #1a1420;
  border-radius: 3px;
  font-size: clamp(12px, 3.4vw, 15px);
  line-height: 1.4;
  box-sizing: border-box;
}
/* Take no visible space when there are no current spoken lines. */
.caption-strip:empty { display: none; }
.caption-line {
  overflow-wrap: anywhere;
  word-break: break-word;
}
.caption-line + .caption-line { margin-top: 3px; }
.caption-line .cap-name { font-weight: bold; }
.caption-line.claude .cap-name { color: var(--amber); }
.caption-line.gpt .cap-name { color: var(--jade); }
.caption-line.man .cap-name { color: var(--straw); }

/* ── panels for the screen layouts (switches, meters, log, replies) ───────── */
.board {
  margin-top: 12px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
/* From 960px up, lay the Observe board out in three columns. Mobile-first: the
   single-column default already satisfies 320px with no horizontal scroll. */
@media (min-width: 960px) {
  .board.observe {
    grid-template-columns: minmax(0, 1.25fr) minmax(0, .9fr) minmax(0, 1.25fr);
  }
}

.panel {
  background: linear-gradient(#3b2718, #2c1c11);
  border: 2px solid #1b110a;
  border-radius: 4px;
  padding: 12px 14px 14px;
  box-shadow: inset 0 0 0 1px var(--wood-hi);
  min-width: 0; /* let grid cells shrink below content width (no overflow) */
}
.panel h2 {
  font-weight: 400;
  font-size: 16px;
  margin: 0 0 10px;
  color: var(--straw);
}

/* ── breaker switches (Req 4.3, 4.4) ──────────────────────────────────────── */
.switches {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.sw {
  appearance: none;
  font: inherit;
  font-size: 15px;
  cursor: pointer;
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 10px 12px 9px;
  min-width: 96px;
  background: #1f150d;
  color: var(--bone);
  border: 2px solid #120b06;
  border-radius: 4px;
}
/* The lever graphic: up = ON, down = OFF (Req 4.3). */
.sw .lever {
  width: 20px;
  height: 36px;
  border-radius: 3px;
  background: linear-gradient(#5a3d26, #3a2618);
  position: relative;
}
.sw .lever::after {
  content: '';
  position: absolute;
  left: 3px;
  right: 3px;
  height: 14px;
  bottom: 3px; /* OFF: lever knob down */
  background: var(--mute);
  border-radius: 2px;
  transition: bottom .15s, background .15s;
}
.sw.on .lever::after {
  bottom: 19px; /* ON: lever knob up */
  background: var(--lantern);
}
.sw .mark { font-size: 11px; color: var(--mute); }
.sw.on .mark { color: var(--lantern); }
/* Disabled switches reject activation. */
.sw[disabled],
.sw.disabled {
  opacity: .5;
  cursor: not-allowed;
}

/* ── resident meters (Req 4.10) ───────────────────────────────────────────── */
.meters { display: grid; gap: 8px; }
.meter { display: grid; grid-template-columns: 7ch 1fr auto; gap: 8px; align-items: center; }
.meter .label { font-size: 13px; color: var(--mute); }
.meter .bar {
  height: 10px;
  background: #241812;
  border: 1px solid #120b06;
  border-radius: 3px;
  overflow: hidden;
}
.meter .fill { display: block; height: 100%; width: 0; background: var(--jade); transition: width .25s; }
.meter.injury .fill, .meter.fear .fill { background: var(--alarm); }
/* Heat wave only: the resident's room temperature, shown beside his meters
   (heat-wave Req 10.3). Hidden by default so an earthquake screen is unchanged. */
.meter[hidden] { display: none; }
.meter.room .fill { background: var(--lantern); }
/* "Heat wave" tag on the Replay list/screen and the End_Card (Req 10.4). */
.disaster-tag { font-size: 12px; color: var(--lantern); }
.meter .val { font-size: 13px; color: var(--bone); min-width: 4ch; text-align: right; }

/* ── "What happened" log (Req 4.10, 12.5) ─────────────────────────────────── */
.log { display: grid; gap: 10px; max-height: 40vh; overflow-y: auto; }
.log .turn { border-left: 3px solid var(--wood-hi); padding-left: 10px; }
.log .turn h3 { margin: 0 0 4px; font-size: 13px; font-weight: 400; color: var(--straw); }
.log .entry { font-size: 13px; line-height: 1.5; color: var(--bone); }
.log .entry .who { color: var(--amber); }
.log .entry .who.jade { color: var(--jade); }

/* ── controls: Start / Voices (Req 4.12, 9.1) ─────── */
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
/* "Turn N of M" position counter sitting in the Replay controls row (Req 9.1,
   9.8-9.11). Plain live-updating text; empty until playback renders a turn. */
.turn-indicator { font-size: 13px; color: var(--mute); margin-left: 4px; }
.btn {
  appearance: none;
  font: inherit;
  cursor: pointer;
  padding: 9px 14px;
  background: #1f150d;
  color: var(--bone);
  border: 2px solid var(--wood-hi);
  border-radius: 4px;
}
.btn:hover { background: #2a1d12; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn.primary { border-color: var(--lantern); color: var(--ember); }

/* ── Replay: replies beside/below the stage (Req 9.2, 9.3) ────────────────── */
.replies { display: grid; gap: 12px; margin-top: 12px; }
/* At >= 768px show the replies beside the renderer (Req 9.2); below 768px they
   stack under it (Req 9.3 — the single-column default). */
@media (min-width: 768px) {
  /* Two columns: the stage column (canvas + controls + Turn N of M + the
     "told" panel) on the left, the replies on the right. The controls now sit
     DIRECTLY UNDER the canvas inside the left column, not below the whole grid
     (task 19.2, Req 9.1, 12.3). align-items: start keeps both columns top-
     aligned so the stage column is not stretched to the reply column's height. */
  .replay-main { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 12px; align-items: start; }
  .replies { margin-top: 0; }
}
/* The stage column stacks the canvas, controls and panel vertically. Under
   768px the .replay-main is a single column, so the stage column (and its
   controls) already sits directly under the canvas (Req 12.3). */
.stage-col { display: flex; flex-direction: column; }
.reply { background: #231712; border: 1px solid #120b06; border-radius: 4px; padding: 10px 12px; }
.reply h3 { margin: 0 0 6px; font-size: 13px; font-weight: 400; }
.reply.amber h3 { color: var(--amber); }
.reply.jade h3 { color: var(--jade); }
/* End_Card collapsed full replies (Req 6.9): the <summary> is the disclosure
   label, styled like the old <h3> title. */
details.reply > summary { margin: 0; font-size: 13px; font-weight: 400; cursor: pointer; }
details.reply[open] > summary { margin-bottom: 6px; }
.reply.amber > summary { color: var(--amber); }
.reply.jade > summary { color: var(--jade); }
.reply .text { font-size: 13px; line-height: 1.55; white-space: pre-wrap; }
/* Replay started-with memory count (robot-memory Req 7.6): a small muted line
   under the robot's name showing how many memories it began the episode with. */
.reply .started-with { margin: 0 0 6px; font-size: 11px; opacity: 0.75; }
/* Evidence highlights: solid underline for the action quote (Req 9.4), dotted
   for words passed on (Req 9.5). */
.reply .evidence-action { text-decoration: underline solid var(--lantern); text-underline-offset: 2px; }
.reply .evidence-words { text-decoration: underline dotted var(--jade); text-underline-offset: 2px; }

/* ── episode list (Req 8.2, 8.5) ──────────────────────────────────────────── */
.episode-list { display: grid; gap: 10px; }
/* The items are <button>s, so they need the page's font/colour forced on and a
   full-width left-aligned block so the dark-panel text is readable (Req 8.2, 8.5)
   and keyboard-focusable (Req 12.4). */
.episode-list .item {
  background: #231712;
  border: 1px solid #120b06;
  border-radius: 4px;
  padding: 10px 12px;
  color: var(--bone);
  font: inherit;
  text-align: left;
  width: 100%;
  cursor: pointer;
}
.episode-list .list-heading { font-size: 16px; margin: 16px 0 8px; }
.episode-list .list-empty { font-size: 13px; color: var(--mute); margin: 0 0 8px; }
.episode-list .item:focus-visible { outline: 3px solid var(--ember); outline-offset: 2px; }
.episode-list .item .when { font-size: 12px; color: var(--mute); }
.episode-list .item .situation { font-size: 13px; line-height: 1.5; }

/* ── End_Card (Req 6) ─────────────────────────────────────────────────────── */
.endcard {
  margin-top: 12px;
  background: linear-gradient(#2c1c11, #1b110a);
  border: 2px solid var(--lantern);
  border-radius: 4px;
  padding: 14px 16px;
}
.endcard h2 { margin: 0 0 10px; color: var(--lantern); font-weight: 400; }

/* End_Card reflect-and-show (robot-memory Req 7.3, 7.4, 7.5): the awaiting
   line, a small heading, then one block per robot — a collapsible <details>
   holding the new memory in full for a robot that answered, or a plain line
   stating the empty-vs-failed outcome for one that did not. The robot colours
   reuse the amber/jade cues used elsewhere. */
.endcard-reflection { margin-top: 12px; }
.endcard-reflection-title { margin: 0 0 8px; font-size: 13px; font-weight: 400; color: var(--lantern); }
.reflection-waiting { margin: 10px 0 0; font-size: 13px; color: var(--mute); }
details.reflection { background: #231712; border: 1px solid #120b06; border-radius: 4px; padding: 10px 12px; margin-bottom: 8px; }
details.reflection > summary { margin: 0; font-size: 13px; font-weight: 400; cursor: pointer; }
details.reflection[open] > summary { margin-bottom: 6px; }
details.reflection.amber > summary { color: var(--amber); }
details.reflection.jade > summary { color: var(--jade); }
.reflection .text { font-size: 13px; line-height: 1.55; white-space: pre-wrap; }
p.reflection.failed { margin: 0 0 8px; font-size: 13px; color: var(--mute); }
p.reflection.failed.amber { color: var(--amber); }
p.reflection.failed.jade { color: var(--jade); }

/* ── messages / errors ────────────────────────────────────────────────────── */
.message { color: var(--mute); font-size: 14px; line-height: 1.5; }
.message.error { color: var(--alarm); }
/* Notice area under the levers; same margin on wide and narrow screens. */
#notice { margin-top: 10px; }

/* Judge_Note under the notice: small, muted; shown only with an active pass. */
.judge-note { margin: 8px 0 0; color: var(--mute); font-size: 12px; line-height: 1.5; }
.judge-note[hidden] { display: none; }
#notice[hidden] { display: none; }

/* ── visible focus indicator, >= 3:1 contrast (Req 12.4) ──────────────────── */
/* The ember outline on the dark panels gives well over 3:1 contrast against
   the adjacent backgrounds; keyboard focus is clearly visible. */
:focus-visible {
  outline: 3px solid var(--ember);
  outline-offset: 2px;
}
/* Browsers without :focus-visible still get a visible outline on :focus. */
.btn:focus,
.sw:focus,
a:focus {
  outline: 3px solid var(--ember);
  outline-offset: 2px;
}

/* ── reduced motion: short-circuit CSS-driven motion (Req 12.6) ───────────── */
/* The JS (act-out.js) also honours reduced motion for canvas animation; this
   rule covers CSS transitions/animations so nothing on the page animates. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ── robot memory bar + All-reset confirm panel (robot-memory Req 7.1, 7.2) ──
   The memory bar sits under the Observe controls: the status line
   "Generation N · Amber remembers k · Jade remembers k" (filled by observe.js
   from GET /api/memory) and the "All reset" button. The confirm panel below it
   is revealed in-page on "All reset" — no browser dialog (Req 7.2). Colours
   reuse the Halloween palette; the robot names are coloured with the same
   amber/jade cues used elsewhere. */
.memory-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}
/* The status line. It takes the remaining width so the button sits at the end
   on a wide row and wraps under on a narrow one (Req 12.3). aria-live=polite in
   the markup announces each refresh. */
.memory-status {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--bone);
  overflow-wrap: anywhere;
}
/* Empty line takes no extra space before observe.js fills it on load. */
.memory-status:empty { color: var(--mute); }

/* The in-page confirm panel host. Hidden (via [hidden]) until "All reset" is
   pressed; the panel itself is built by memory-ui.js. */
.confirm-host { margin-top: 8px; }
.confirm-panel {
  background: linear-gradient(#3b2718, #2c1c11);
  border: 2px solid var(--lantern);
  border-radius: 4px;
  padding: 12px 14px 14px;
  max-width: 62ch;
}
.confirm-panel .confirm-question {
  margin: 0 0 10px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--bone);
}
.confirm-panel .confirm-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
