/* CrowdClear: a calm control-room console in the language of stadium safety signage.
   Gate plates (letter + state) are the one bold element; everything else stays quiet. */
:root {
  --navy: #0f1b2b;
  --slate: #18273a;
  --slate-2: #213349;
  --line: #2f445e;
  --ink: #eef3f8;
  --muted: #a3b5ca;
  --signal: #e4dc7b;
  --exit: #2fbf71;
  --stop: #e5484d;
  --word-open: #6bdea0;
  --word-send: #8dc8ff;
  --word-clear: #ffd27d;
  --display: "Overpass", "Arial Narrow", system-ui, sans-serif;
  --text: "Atkinson Hyperlegible", system-ui, sans-serif;
  --radius: 10px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  /* A faint overhead glow, like concourse lighting, so the console is not a flat slab. */
  background: radial-gradient(120% 55% at 50% -12%, #1a2d44 0%, var(--navy) 62%) fixed var(--navy);
  color: var(--ink);
  font: 1rem/1.55 var(--text);
}

header, main {
  max-width: 1360px;
  margin-inline: auto;
  padding: 20px 28px;
}

header {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
  padding-bottom: 16px;
}
header .brand {
  display: flex;
  align-items: center;
  gap: 14px;
}
header .brand img {
  width: 52px;
  height: 52px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid var(--line);
  background: #d8dde3;
}
header h1 {
  margin: 0;
  font: 900 1.9rem/1 var(--display);
  letter-spacing: -0.01em;
}
header p { margin: 4px 0 0; color: var(--muted); }

h2, h3, h4 { font-family: var(--display); margin-top: 0; text-wrap: balance; }
p, li { text-wrap: pretty; }
h2 { letter-spacing: -0.01em; }
h2 { font-weight: 800; font-size: 1.9rem; line-height: 1.15; }
h3 { font-weight: 800; font-size: 1.35rem; line-height: 1.25; }
h4 { font-weight: 700; font-size: 1.05rem; }
.muted, .scene-caption { color: var(--muted); font-size: 0.9rem; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}

/* Buttons: one filled action color; secondary actions recede. */
button {
  font: 700 0.95rem/1.2 var(--display);
  min-height: 44px;
  padding: 11px 18px;
  margin: 0;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--signal);
  color: var(--navy);
  cursor: pointer;
  transition: filter 180ms ease, transform 180ms ease;
}
button:hover:not(:disabled) { filter: brightness(1.08); }
button:active:not(:disabled) { transform: translateY(1px); }
button:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
button:disabled { background: var(--slate-2); color: var(--muted); cursor: not-allowed; }
button.secondary { background: transparent; color: var(--ink); border-color: var(--line); }
button.secondary:hover:not(:disabled) { border-color: var(--muted); filter: none; }
button.task-target { box-shadow: 0 0 0 3px var(--navy), 0 0 0 5px var(--signal); }
.completion-check { color: var(--navy); margin-left: 6px; font-weight: 900; }
.word-open { color: var(--word-open); font-weight: 700; }
.word-send { color: var(--word-send); font-weight: 700; }
.word-clear { color: var(--word-clear); font-weight: 700; }
button.action-open:not(:disabled) { background: var(--word-open); }
button.action-send:not(:disabled) { background: var(--word-send); }
button.action-clear:not(:disabled) { background: var(--word-clear); }

/* Briefing */
#intro {
  max-width: 680px;
  margin: 56px 0;
}
.intro-gates { display: flex; gap: 12px; margin-bottom: 28px; }
.intro-gates .gate-letter { width: 96px; height: 96px; font-size: 3.8rem; border-radius: 8px; }
.intro-gates .gate-letter.closed { background: var(--stop); color: #fff; }
#intro h2 { font-size: clamp(2rem, 4vw, 2.8rem); margin-bottom: 12px; }
#intro p { max-width: 60ch; font-size: 1.08rem; }
#intro .muted { font-size: 0.95rem; margin-bottom: 24px; }
#load-status:empty { display: none; }

/* Drill */
#game { display: none; padding-top: 20px; }
.drill-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.drill-heading h2 { margin: 0; }
.heading-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* Status strip: counts read as one instrument, not separate cards. */
#hud {
  display: flex;
  flex-wrap: wrap;
  background: var(--slate);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 12px;
  font: 600 1rem/1.3 var(--display);
  font-variant-numeric: tabular-nums;
}
#hud span { padding: 12px 18px; }
#hud span + span { border-left: 1px solid var(--line); }

/* Gate plates: the stadium wayfinding sign for each exit. Colour always has a word beside it. */
.exit-status {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}
.gate {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 14px 8px 8px;
  background: var(--slate);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.gate-letter {
  flex: none;
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 6px;
  font: 900 2.2rem/1 var(--display);
  background: var(--exit);
  color: var(--navy);
}
.gate-text { display: grid; line-height: 1.25; }
.gate-text strong { font: 800 1.05rem/1.2 var(--display); }
.gate-text span:last-child { color: var(--muted); font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.gate[data-state="closed"] .gate-letter { background: var(--stop); color: #fff; }
.gate[data-state="hazard"] { border-color: var(--signal); }
.gate[data-state="hazard"] .gate-letter {
  background: repeating-linear-gradient(-45deg, var(--signal) 0 10px, #1d1d1d 10px 20px);
  color: #fff;
  text-shadow: 0 0 4px #000, 0 0 2px #000;
}
.gate[data-state="hazard"] strong { color: var(--word-clear); }
.gate[data-state="open"] strong { color: var(--word-open); }

.play-layout {
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

/* Task panel */
#instruction {
  background: var(--slate);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}
#instruction p { max-width: 60ch; }
/* Step labels arrive in capitals from game.js; show them as sentence case. */
.eyebrow {
  display: inline-block;
  margin: 0 0 10px;
  padding: 3px 10px;
  border-radius: 4px;
  background: var(--slate-2);
  color: var(--signal);
  font: 700 0.85rem/1.4 var(--display);
  text-transform: lowercase;
}
.eyebrow::first-letter { text-transform: uppercase; }
#task-title { margin-bottom: 8px; }
/* Per-exit Clear/Open/Send bank stays in the DOM for tests/handlers but is not the laptop UI. */
#actions[hidden] { display: none !important; }
#reassure-btn {
  position: relative;
  width: 100%;
  margin-top: 14px;
  overflow: hidden;
}
#feedback {
  margin: 16px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  color: var(--signal);
}
/* Cooldown overlays the scene — does not push layout. */
.cooldown-toast {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  min-width: min(320px, calc(100% - 24px));
  margin: 0;
  padding: 10px 14px;
  border: 1px solid var(--signal);
  border-radius: var(--radius);
  background: rgba(15, 27, 43, 0.88);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  align-items: center;
  font-size: 0.92rem;
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.cooldown-toast strong { color: var(--signal); font-weight: 700; }
.cooldown-toast-track {
  grid-column: 1 / -1;
  height: 4px;
  border-radius: 999px;
  background: rgba(15, 27, 43, 0.55);
  overflow: hidden;
}
#cooldown-toast-fill {
  display: block;
  height: 100%;
  width: 100%;
  transform-origin: left center;
  transform: scaleX(1);
  background: linear-gradient(90deg, var(--signal), var(--exit));
  transition: transform 120ms linear;
}
.guide-pulse {
  outline: 2px solid var(--exit);
  box-shadow: 0 0 0 3px rgba(47, 191, 113, 0.35);
  animation: guide-pulse 1.2s ease-in-out infinite;
}
@keyframes guide-pulse {
  50% { box-shadow: 0 0 0 7px rgba(47, 191, 113, 0.12); }
}
@media (prefers-reduced-motion: reduce) {
  #cooldown-toast-fill { transition: none; }
  .guide-pulse { animation: none; }
}
.pa-caption { display: none !important; }
#drill-btn { margin-top: 16px; width: 100%; }
#instruction > .muted { margin-bottom: 0; }

/* Scene: the crowd is the largest thing on the page. */
.scene-wrap { position: relative; min-width: 0; }
#game a-scene {
  width: 100%;
  height: clamp(360px, 62vh, 660px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.scene-caption { margin: 10px 2px 0; max-width: 90ch; line-height: 1.5; }

/* Results: encouragement leads, metrics follow, then the action log for learning. */
#results {
  padding: 28px 24px 32px;
  background:
    linear-gradient(180deg, rgba(47, 191, 113, 0.08) 0%, transparent 42%),
    var(--slate);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-align: center;
}
.result-card { max-width: 520px; margin: 0 auto; }
.result-kicker {
  margin: 0 0 8px;
  font: 700 0.85rem/1.2 var(--display);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
#result-message {
  margin: 0 auto 8px;
  font: 900 2.35rem/1.1 var(--display);
  color: var(--ink);
}
#result-tip { max-width: 52ch; margin: 0 auto 14px; color: var(--muted); }
.result-peak {
  max-width: 54ch;
  margin: 0 auto 8px;
  color: var(--word-clear);
  font-weight: 700;
  font-size: 0.98rem;
}
.run-analysis {
  margin: 0 0 14px;
  line-height: 1.5;
  color: var(--ink-soft, #d7e0ea);
}
.compare-legend {
  margin: 0 0 10px;
  font-size: 0.92rem;
  line-height: 1.4;
  color: var(--ink-soft, #d7e0ea);
  opacity: 0.9;
}
.result-metrics { margin: 18px 0 0; display: grid; gap: 6px; }
.result-metrics div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--slate-2);
  border: 1px solid transparent;
  text-align: left;
  font-variant-numeric: tabular-nums;
}
.result-metrics dd { margin: 0; font-weight: 700; }
.result-metrics .score-total {
  margin-top: 6px;
  background: rgba(228, 220, 123, 0.08);
  border-color: rgba(228, 220, 123, 0.35);
  padding-top: 14px;
  padding-bottom: 14px;
  align-items: baseline;
}
.result-metrics .score-total dt { font: 800 1.05rem var(--display); }
.result-metrics .score-total dd { font: 900 3.2rem/1 var(--display); color: var(--signal); }
/* Shared metric colors — results, compare, Presage scale */
.num-exit, #calm-scale-fill.num-exit { color: var(--exit); }
.num-open { color: var(--word-open); }
.num-send { color: var(--word-send); }
.num-stop, #calm-scale-fill.num-stop { color: var(--stop); }
.num-clear, #calm-scale-fill.num-clear { color: var(--word-clear); }
.num-signal { color: var(--signal); }
.num-muted { color: var(--muted); }
#calm-scale-fill.num-exit { background: var(--exit); }
#calm-scale-fill.num-clear { background: var(--word-clear); }
#calm-scale-fill.num-stop { background: var(--stop); }
.compare-result {
  margin: 12px 0 16px;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--slate-2);
  border: 1px solid var(--line);
}
.compare-headline { margin: 0 0 10px; font: 700 1.05rem/1.35 var(--display); }
.compare-metrics { margin: 0; display: grid; gap: 6px; }
.compare-metrics div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-variant-numeric: tabular-nums;
}
.compare-metrics dt { margin: 0; color: var(--muted); }
.compare-metrics dd { margin: 0; font-weight: 700; }
.compare-note { margin: 10px 0 0; color: var(--muted); font-size: 0.9rem; line-height: 1.45; }
.result-formula { margin: 14px 0 0; }

#review {
  margin: 16px 0 0;
  padding: 22px 22px 24px;
  background: var(--slate);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
#review h3 { margin: 0 0 8px; font-size: 1.25rem; }
#review h4 { margin: 18px 0 8px; color: var(--muted); font-size: 0.95rem; letter-spacing: 0.04em; text-transform: uppercase; }
.review-outcome { margin: 0 0 4px; color: var(--ink); }
.action-log {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 4px;
  font-variant-numeric: tabular-nums;
}
.action-log li {
  display: grid;
  grid-template-columns: 4.75rem minmax(0, 1fr);
  gap: 12px;
  align-items: baseline;
  padding: 9px 12px;
  border-radius: 8px;
  background: var(--slate-2);
  border-left: 3px solid var(--line);
}
.action-log .log-time {
  color: var(--word-send);
  font: 700 0.9rem/1.3 var(--display);
}
.action-log .log-label { color: var(--ink); }
.vitals-card {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: 8px;
  background: var(--navy);
  border: 1px solid var(--line);
}
.vitals-card h4 { margin: 0 0 6px; }
.calm-scale { margin: 8px 0 10px; }
.calm-scale-track {
  height: 10px;
  border-radius: 999px;
  background: #2a3544;
  overflow: hidden;
}
#calm-scale-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #e5484d, #e4dc7b, #2fbf71);
  transition: width 0.25s ease;
}
.calm-scale-ends {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  font-size: 0.75rem;
  color: var(--muted);
}
#result-breathing { margin: 0; font: 700 1.05rem/1.35 var(--display); color: var(--ink); }
#save-status { color: var(--muted); font-size: 0.92rem; margin: 10px 0 0; }
#compare-form { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); }
#compare-form label { display: block; margin-top: 12px; font-size: 0.92rem; color: var(--muted); }
#compare-when {
  width: 100%;
  margin-top: 8px;
  accent-color: var(--word-send, #8dc8ff);
}
#compare-when-readout {
  display: block;
  margin: 6px 0 10px;
  font: 700 0.95rem/1.3 var(--display);
  color: var(--ink);
}
#compare-form input[type="range"]:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
#compare-form button { margin-top: 14px; }
#compare-result { white-space: pre-line; }

/* When the results show, they replace the scene and lead the page. */
.play-layout:has(#results:not([hidden])) { display: flex; flex-direction: column; }
.play-layout:has(#results:not([hidden])) .scene-wrap { order: -1; }
.play-layout:has(#results:not([hidden])) #actions,
.play-layout:has(#results:not([hidden])) #step-label,
.play-layout:has(#results:not([hidden])) #task-title,
.play-layout:has(#results:not([hidden])) #task-copy { display: none; }

@media (max-width: 900px) {
  header, main { padding: 16px; }
  .intro-gates .gate-letter { width: 72px; height: 72px; font-size: 2.8rem; }
  .play-layout { grid-template-columns: 1fr; }
  .scene-wrap { order: -1; }
  #game a-scene { height: 52vh; min-height: 300px; }
}
@media (max-width: 560px) {
  /* Three compact plates side by side, so the scene starts higher on a phone. */
  .exit-status { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .gate { flex-direction: column; gap: 6px; padding: 8px 4px 10px; text-align: center; }
  .gate-letter { width: 44px; height: 44px; font-size: 1.7rem; }
  .gate-text span:last-child { font-size: 0.8rem; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

.skip-link {
  position: absolute;
  left: 16px;
  top: -60px;
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--signal);
  color: var(--navy);
  font: 700 0.95rem var(--display);
  text-decoration: none;
  z-index: 10;
}
.skip-link:focus { top: 12px; }
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}
