/* Escape The Boardroom — interface.
 *
 * PALETTE NOTE: the Purplex boilerplate design system deliberately ships no
 * colour or type tokens, so --accent below is a PLACEHOLDER, not brand.
 * Swap the three accent values for the real brand palette and nothing else
 * needs to change. Layout steps follow the boilerplate's 4/8px scale.
 */

:root {
  --ink: #0e0d0b;
  --surface: rgba(22, 21, 18, 0.94);
  --surface-2: rgba(255, 255, 255, 0.05);
  --line: rgba(236, 231, 220, 0.14);
  --text: #ece7dc;
  --dim: rgba(236, 231, 220, 0.52);

  /* PLACEHOLDER accent — replace with the brand palette. */
  --accent: #c9a4ff;
  --accent-ink: #1b1233;
  --accent-soft: rgba(201, 164, 255, 0.16);

  --warn: #ffb26b;
  --good: #7fe0a0;
  --bad: #ff8f7f;

  --r-sm: 8px;
  --r-md: 16px;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

/* The ID rules below set `display`, which outranks the user-agent
   `[hidden] { display: none }`. Without this, nothing ever hides. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--ink);
  color: var(--text);
  font: 400 15px/1.55 var(--sans);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#game {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  isolation: isolate;
}

#stage {
  position: absolute;
  inset: 0;
  cursor: grab;
}
/* The stage calls setSize(w, h, false), which updates the drawing buffer but
   deliberately leaves the canvas style alone. These two lines are what keep
   the CSS size in step — without them the canvas holds its initial size and
   the scene drifts off-centre the moment the viewport changes. */
#stage canvas { display: block; width: 100%; height: 100%; }

/* ------------------------------------------------------------------- HUD - */
#hud {
  position: absolute;
  inset: 0 0 auto 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: linear-gradient(to bottom, rgba(8, 8, 7, 0.82), rgba(8, 8, 7, 0));
  pointer-events: none;
  flex-wrap: wrap;
}
#hud > * { pointer-events: auto; }

.brand {
  font-weight: 700;
  letter-spacing: 0.14em;
  font-size: 12px;
  text-transform: uppercase;
  color: var(--dim);
  margin-right: 4px;
}
.brand b { color: var(--text); }

.stat {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-variant-numeric: tabular-nums;
}
.stat span {
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--dim);
}
.stat b { font: 700 15px/1 var(--mono); }
#hud-timer.late { color: var(--bad); }

.spacer { flex: 1 1 auto; }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: 600 13px/1 var(--sans);
  padding: 9px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 120ms, border-color 120ms, transform 80ms;
}
.btn:hover { background: var(--surface-2); border-color: rgba(236, 231, 220, 0.3); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn-primary:hover { background: #d9bcff; border-color: #d9bcff; }

/* Progress rail under the HUD. */
#progress {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: rgba(236, 231, 220, 0.1);
  z-index: 4;
}
#progress::after {
  content: "";
  display: block;
  height: 100%;
  width: var(--p, 0%);
  background: var(--accent);
  transition: width 380ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* ----------------------------------------------------------------- notes - */
#notes {
  position: absolute;
  left: 16px;
  bottom: 16px;
  z-index: 3;
  width: min(320px, calc(100vw - 32px));
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  backdrop-filter: blur(8px);
  overflow: hidden;
}
#notes > summary {
  cursor: pointer;
  padding: 10px 14px;
  font: 700 11px/1 var(--sans);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--dim);
  list-style: none;
}
#notes > summary::-webkit-details-marker { display: none; }
#notes > summary::after { content: " ▾"; }
#notes[open] > summary::after { content: " ▴"; }
#notes ul {
  margin: 0;
  padding: 0 14px 12px 30px;
  max-height: 34vh;
  overflow-y: auto;
  font-size: 13.5px;
}
#notes li { margin: 0 0 6px; color: rgba(236, 231, 220, 0.86); }

.hint-controls {
  position: absolute;
  right: 16px;
  bottom: 16px;
  z-index: 3;
  font-size: 12px;
  color: rgba(236, 231, 220, 0.4);
  text-align: right;
  pointer-events: none;
  line-height: 1.7;
}

/* ------------------------------------------------------------ hover label */
#label {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 5;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font: 700 12px/1.4 var(--sans);
  white-space: nowrap;
  pointer-events: none;
  will-change: transform;
}

/* ----------------------------------------------------------------- toast - */
#toast {
  position: absolute;
  left: 50%;
  top: 76px;
  transform: translateX(-50%);
  z-index: 5;
  max-width: min(460px, calc(100vw - 32px));
  padding: 12px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--r-sm);
  backdrop-filter: blur(8px);
  animation: rise 260ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
#toast b { display: block; font-size: 14px; }
#toast span { display: block; color: var(--dim); font-size: 13px; margin-top: 2px; }
@keyframes rise { from { opacity: 0; transform: translateX(-50%) translateY(-8px); } }

/* ------------------------------------------------------------- cinematic - */
/* The HUD has nothing to say until the clock is running. */
#game.cine #hud,
#game.cine #notes,
#game.cine #progress,
#game.cine .hint-controls {
  opacity: 0;
  pointer-events: none;
  transition: opacity 400ms ease;
}

#cinematic {
  position: absolute;
  inset: 0;
  z-index: 8;
  pointer-events: none;
}
#cinematic .btn { pointer-events: auto; }

/* Letterbox. Scaling from 0 keeps it to compositor work. */
#cinematic .bar {
  position: absolute;
  left: 0;
  right: 0;
  height: 12vh;
  background: #070706;
  transform: scaleY(0);
  transition: transform 700ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
#cinematic .bar-top { top: 0; transform-origin: top; }
#cinematic .bar-bottom { bottom: 0; transform-origin: bottom; }
#cinematic.rolling .bar { transform: scaleY(1); }

/* A vignette so the room reads as a shot rather than a viewport. */
#cinematic::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 45%, transparent 38%, rgba(5, 5, 4, 0.72) 100%);
  opacity: 0;
  transition: opacity 700ms ease;
  z-index: 1; /* ::after paints last, so the captions need to out-rank it */
}
#cinematic.rolling::after { opacity: 1; }

#cine-text {
  position: absolute;
  z-index: 2;
  left: 50%;
  bottom: 18vh;
  transform: translateX(-50%);
  width: min(760px, calc(100vw - 48px));
  text-align: center;
  text-wrap: balance;
}
.cine-line {
  margin: 0;
  font-weight: 700;
  font-size: clamp(22px, 3.6vw, 40px);
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: #fbf8f2;
  text-shadow: 0 2px 24px rgba(0, 0, 0, 0.85);
}
.cine-sub {
  margin: 10px 0 0;
  font-size: clamp(13px, 1.5vw, 16px);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  text-shadow: 0 2px 16px rgba(0, 0, 0, 0.9);
}
.cine-line:empty, .cine-sub:empty { display: none; }

/* Re-triggered per beat by removing and re-adding the class. */
#cine-text.beat .cine-line { animation: cineIn 620ms cubic-bezier(0.2, 0.8, 0.2, 1) both; }
#cine-text.beat .cine-sub { animation: cineIn 620ms cubic-bezier(0.2, 0.8, 0.2, 1) 90ms both; }
@keyframes cineIn {
  from { opacity: 0; transform: translateY(14px); filter: blur(6px); }
  to   { opacity: 1; transform: none; filter: none; }
}

/* Centred by box, not by transform: cineIn animates `transform`, and with
   fill mode `both` it would otherwise land on `none` and throw a translated
   element back against the left edge. */
#cine-clock {
  position: absolute;
  z-index: 2;
  left: 0;
  right: 0;
  top: 38%;
  text-align: center;
  animation: cineIn 620ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
#cine-clock::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(620px, 92vw);
  height: 320px;
  transform: translate(-50%, -50%);
  background: radial-gradient(ellipse, rgba(6, 6, 5, 0.82) 0%, rgba(6, 6, 5, 0) 70%);
  z-index: -1;
}
#cine-clock-value {
  display: block;
  font: 700 clamp(64px, 13vw, 148px)/1 var(--mono);
  letter-spacing: -0.03em;
  color: #fff;
  text-shadow: 0 0 60px rgba(255, 90, 70, 0.5), 0 4px 30px rgba(0, 0, 0, 0.9);
  animation: pulse 1s ease-in-out infinite;
}
#cine-clock small {
  display: block;
  margin-top: 10px;
  font-size: clamp(12px, 1.4vw, 15px);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--bad);
}
@keyframes pulse { 50% { opacity: 0.86; } }

#btn-skip {
  position: absolute;
  z-index: 3;
  right: 16px;
  bottom: calc(12vh + 16px);
  opacity: 0.65;
}
#btn-skip:hover { opacity: 1; }

/* ----------------------------------------------------------------- panel - */
#panel, #intro {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(6, 6, 5, 0.62);
  backdrop-filter: blur(3px);
}

.card {
  position: relative;
  width: min(560px, 100%);
  max-height: min(86vh, 720px);
  overflow-y: auto;
  background: #171613;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 28px 28px 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  animation: rise 200ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.card h2 {
  margin: 0 0 14px;
  font-size: 22px;
  letter-spacing: -0.01em;
}
.card p { margin: 0 0 12px; }
.card .dim { color: var(--dim); font-size: 13.5px; }
.card .warn { color: var(--warn); font-size: 13.5px; }
.card .win { color: var(--good); font-weight: 700; }

#panel-close {
  position: absolute;
  top: 14px;
  right: 14px;
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--dim);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--r-sm);
}
#panel-close:hover { color: var(--text); background: var(--surface-2); }

#panel-actions, .intro-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
  flex-wrap: wrap;
}

.code {
  font: 700 40px/1.2 var(--mono);
  letter-spacing: 0.14em;
  margin: 4px 0 14px !important;
}
.code .smudge { color: var(--dim); }

.kv {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 12px;
  background: var(--surface-2);
  border-radius: var(--r-sm);
  margin: 0 0 6px !important;
}
.kv span { color: var(--dim); font-size: 13px; }
.kv b { font-family: var(--mono); }

/* ------------------------------------------------------------- messages - */
.thread { display: grid; gap: 8px; margin-top: 4px; }
.msg {
  position: relative;
  padding: 12px 14px 12px 16px;
  background: var(--surface-2);
  border-left: 3px solid var(--accent);
  border-radius: var(--r-sm);
  font-size: 14px;
}
.msg-time {
  float: right;
  margin-left: 12px;
  font: 400 12px/1.6 var(--mono);
  color: var(--dim);
}
.msg:last-child { background: var(--accent-soft); }

/* ---------------------------------------------------------------- keypad - */
.pin {
  display: flex;
  gap: 10px;
  margin: 8px 0 16px !important;
}
.pin i {
  flex: 1;
  text-align: center;
  padding: 12px 0;
  font: 700 26px/1 var(--mono);
  font-style: normal;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
}
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.key {
  appearance: none;
  padding: 16px 0;
  font: 700 19px/1 var(--mono);
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  cursor: pointer;
}
.key:hover { background: rgba(255, 255, 255, 0.1); }
.key:active { transform: translateY(1px); }
.key-ok { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-size: 13px; }
.key-clr { font-size: 13px; color: var(--dim); }

/* ----------------------------------------------------------------- forms - */
.card label {
  display: block;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 6px;
}
.card input[type="text"] {
  width: 100%;
  padding: 12px 14px;
  font: 400 16px/1.2 var(--mono);
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
}
.card input[type="text"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.card input.bad { border-color: var(--bad); }

/* ------------------------------------------------------------ leaderboard */
.board { list-style: none; margin: 0 0 14px; padding: 0; }
.board li {
  display: grid;
  grid-template-columns: 28px 1fr auto 56px 40px;
  gap: 10px;
  align-items: center;
  padding: 9px 10px;
  border-radius: var(--r-sm);
  font-variant-numeric: tabular-nums;
}
.board li:nth-child(odd) { background: var(--surface-2); }
.board li.me { background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.board .pos { color: var(--dim); font: 700 13px/1 var(--mono); }
.board .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.board .pts { font: 700 15px/1 var(--mono); }
.board .tm, .board .dt { font: 400 12px/1 var(--mono); color: var(--dim); text-align: right; }

.tally { width: 100%; border-collapse: collapse; margin: 4px 0 18px; }
.tally td { padding: 7px 0; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.tally td:last-child { text-align: right; font-family: var(--mono); font-weight: 700; }
.tally td.neg { color: var(--bad); }
.tally .sum td { border-bottom: 0; padding-top: 12px; font-size: 18px; }
.tally .sum td:last-child { color: var(--accent); font-size: 22px; }

/* ----------------------------------------------------------------- intro - */
.intro-card { width: min(600px, 100%); }
.intro-card h1 {
  margin: 0 0 4px;
  font-size: clamp(28px, 5vw, 40px);
  line-height: 1.05;
  letter-spacing: -0.02em;
}
.intro-card .kicker {
  font: 700 11px/1 var(--sans);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 12px !important;
}
.rules {
  display: grid;
  gap: 6px;
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
}
.rules li {
  display: flex;
  gap: 10px;
  padding: 8px 12px;
  background: var(--surface-2);
  border-radius: var(--r-sm);
  font-size: 13.5px;
}
.rules b { color: var(--accent); font-family: var(--mono); flex: 0 0 auto; }

/* ---------------------------------------------------------------- mobile - */
@media (max-width: 640px) {
  #hud { padding: 10px 12px; gap: 6px; }
  .brand { width: 100%; margin-bottom: 2px; }
  .stat { padding: 5px 10px; }
  .spacer { display: none; } /* let the buttons sit next to the stats, not on their own line */
  #toast { top: 108px; }     /* the HUD is three rows tall down here */
  #notes { left: 12px; right: 12px; bottom: 12px; width: auto; }
  .hint-controls { display: none; }
  .card { padding: 22px 18px 16px; }
  #panel-actions .btn { flex: 1 1 auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::after { animation: none !important; transition: none !important; }
}
