/* Tokens first. Colours and faces are the app's own now, kept here so a later
   look is one coherent change. The shell's slot must survive every redesign:
   a 48px round button floats in the bottom-right corner, 16px in from each
   edge, above everything. Nothing tappable goes there. */
:root {
  --shell-switcher-size: 48px;
  --shell-switcher-inset: 16px;
  --shell-switcher-gap: 16px;
  --shell-slot: 80px; /* inset + size + gap: the corner the shell owns */

  --teal: #0a3a40;
  --teal-deep: #052226;
  --navy: #101d33;
  --sky: #12233f;
  --cream: #f6eedb;
  --aqua: #3fe0c5;
  --purple: #6b46b8;
  --purple-ink: #4b2e83;
  --yellow: #ffd23f;
  --muted: #9ab0ae;
  --stone: #4c5a58;

  --px-display: 'Press Start 2P', 'Courier New', monospace;
  --px-body: 'VT323', 'IBM Plex Mono', monospace;
  --px-mono: 'IBM Plex Mono', 'Courier New', monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; overflow-x: hidden; }
body {
  min-height: 100dvh;
  background:
    linear-gradient(rgba(255, 255, 255, 0.028) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.028) 1px, transparent 1px),
    var(--teal);
  background-size: 8px 8px, 8px 8px, auto;
  color: var(--cream);
  font: 20px/1.2 var(--px-body);
}
button, input, select, textarea { font: inherit; }
a { color: inherit; }

/* CRT scanlines over everything, gently */
body::after {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 40;
  background: repeating-linear-gradient(0deg, rgba(3, 18, 22, 0.09) 0 1px, transparent 1px 3px);
}

/* ---------- HUD strip ---------- */
.hud {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--yellow); color: var(--navy);
  border-bottom: 4px solid var(--navy);
  padding: 8px 16px;
  padding-top: max(8px, var(--shell-safe-top, 0px));
}
.hud .left { display: flex; align-items: center; gap: 8px; font: 700 19px/1 var(--px-body); letter-spacing: 0.5px; }
.hud .right { font: 700 13px/1 var(--px-mono); letter-spacing: 1px; }

/* ---------- page: phone first, a real layout when wide ---------- */
.page {
  margin: 0 auto;
  max-width: 1080px;
  padding-top: calc(22px + max(var(--shell-safe-top, 0px), env(safe-area-inset-top, 0px)));
  padding-right: calc(20px + max(var(--shell-safe-right, 0px), env(safe-area-inset-right, 0px)));
  padding-bottom: calc(max(var(--shell-safe-bottom, 0px), env(safe-area-inset-bottom, 0px)) + var(--shell-slot) + 56px);
  padding-left: calc(20px + max(var(--shell-safe-left, 0px), env(safe-area-inset-left, 0px)));
  display: grid;
  gap: 28px;
  grid-template-columns: 1fr;
}
@media (min-width: 900px) {
  .page {
    grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
    gap: 40px;
    align-items: start;
  }
  .col-hero { position: sticky; top: 24px; }
}

/* ---------- title ---------- */
.title {
  margin: 6px 0 0; font: 26px/1.35 var(--px-display); color: var(--cream);
  letter-spacing: 1px; text-shadow: 4px 4px 0 var(--purple);
}
.title .cursor {
  display: inline-block; width: 0.55em; height: 0.9em; background: var(--aqua);
  margin-left: 6px; vertical-align: -2px; animation: blink 0.8s steps(2, start) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.tagline { margin: 12px 0 0; font-size: 23px; line-height: 1.1; color: var(--aqua); }
.stars { display: flex; gap: 10px; margin: 14px 0 4px; }

/* ---------- pixel scene ---------- */
.scene {
  margin: 16px 0 0; border: 4px solid var(--navy); background: var(--sky);
  box-shadow: 8px 8px 0 var(--teal-deep); line-height: 0;
}
.scene svg { width: 100%; height: auto; display: block; shape-rendering: crispEdges; }
.win { animation: windowglow 2.4s steps(2, start) infinite; }
@keyframes windowglow { 50% { fill: #c79a16; } }
.tw { animation: blink 1.6s steps(2, start) infinite; }
.tw.b { animation-delay: 0.8s; }

/* ---------- divider glyphs ---------- */
.glyphs { display: flex; gap: 8px; justify-content: center; margin: 22px 0 18px; }
.glyphs i { width: 9px; height: 9px; }
.glyphs i:nth-child(1) { background: var(--yellow); }
.glyphs i:nth-child(2) { background: var(--aqua); }
.glyphs i:nth-child(3) { background: var(--purple); }
.glyphs i:nth-child(4) { background: var(--aqua); }
.glyphs i:nth-child(5) { background: var(--yellow); }

/* ---------- join ---------- */
.join h2 { margin: 0 0 8px; font: 13px/1.5 var(--px-display); color: var(--yellow); letter-spacing: 1px; }
.join label { display: block; font-size: 22px; color: var(--cream); margin: 10px 0 6px; }
.join-row { display: flex; gap: 10px; }
.join-row input {
  flex: 1; min-width: 0; background: var(--cream); color: var(--navy);
  border: 4px solid var(--navy); box-shadow: 4px 4px 0 var(--teal-deep);
  padding: 10px 12px; font-size: 24px;
}
.join-row input:focus-visible, .start:focus-visible, .chip:focus-visible,
.step:focus-visible, .mini:focus-visible, .score-input:focus-visible {
  outline: 3px dashed var(--yellow); outline-offset: 3px;
}
.me-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.quiet { color: var(--muted); }
.offline { margin: 8px 0; font-size: 21px; color: var(--yellow); }
.chip {
  appearance: none; cursor: pointer; background: transparent; color: var(--aqua);
  border: 3px solid var(--aqua); padding: 6px 10px; font: 700 13px/1 var(--px-mono);
}
.panel-soft { border-top: 4px dashed #2c5a5e; padding-top: 14px; }

/* ---------- players panel ---------- */
.panel {
  background: var(--cream); color: var(--navy); border: 4px solid var(--navy);
  box-shadow: 8px 8px 0 var(--teal-deep);
}
.panel-head {
  display: flex; align-items: baseline; justify-content: space-between;
  background: var(--cream); border-bottom: 4px solid var(--navy);
  padding: 12px 14px 10px;
}
.panel-head h2 { margin: 0; font: 11px/1 var(--px-display); color: var(--purple-ink); letter-spacing: 1px; }
.panel-head .count { font: 700 14px/1 var(--px-mono); }
.roster { list-style: none; margin: 0; padding: 6px 14px 10px; }
.roster li {
  display: flex; align-items: center; gap: 10px; padding: 9px 0;
  border-bottom: 2px solid #ddd2ba; flex-wrap: wrap;
}
.roster li:last-child { border-bottom: 0; }
.roster li.is-turn { background: #fff3c4; margin: 0 -14px; padding-left: 14px; padding-right: 14px; }
.face { width: 30px; height: 30px; flex: none; shape-rendering: crispEdges; }
.roster .name { flex: 1; min-width: 90px; font-size: 24px; line-height: 1; }
.badge {
  font: 8px/1 var(--px-display); color: var(--navy); border: 3px solid var(--navy);
  padding: 6px 7px 5px; box-shadow: 3px 3px 0 rgba(16, 29, 51, 0.28); white-space: nowrap;
}
.badge.ready { background: var(--aqua); }
.badge.way { background: var(--yellow); }
.you-tag { font: 700 12px/1 var(--px-mono); letter-spacing: 1px; color: var(--purple-ink); }
.score-row { display: flex; align-items: center; gap: 6px; }
.step {
  appearance: none; cursor: pointer; width: 34px; height: 34px;
  background: var(--navy); color: var(--cream); border: 3px solid var(--navy);
  font: 20px/1 var(--px-mono);
}
.step:active { transform: translate(2px, 2px); }
.score-input {
  width: 62px; text-align: center; font: 700 18px/1 var(--px-mono);
  border: 3px solid var(--navy); background: #fff; color: var(--navy); padding: 5px 2px;
}
.row-actions { display: flex; gap: 6px; flex-basis: 100%; }
.mini {
  appearance: none; cursor: pointer; background: #fff; color: var(--navy);
  border: 3px solid var(--navy); padding: 5px 8px; font: 700 12px/1 var(--px-mono);
}
.mini.nudge { background: var(--yellow); }
.empty { margin: 0; padding: 14px; font-size: 22px; color: var(--stone); }

/* ---------- start ---------- */
.start {
  display: block; margin: 26px 0 0; padding: 18px 12px; text-align: center;
  background: var(--aqua); color: var(--navy); border: 4px solid var(--navy);
  box-shadow: 6px 6px 0 var(--teal-deep); cursor: pointer; width: 100%;
  font: 13px/1 var(--px-display); letter-spacing: 1px;
}
.start.small { margin: 0; padding: 12px; width: auto; }
.start .tri { display: inline-block; margin-right: 10px; animation: blink 1s steps(2, start) infinite; }
.start:active { transform: translate(4px, 4px); box-shadow: 2px 2px 0 var(--teal-deep); }
.start[disabled] { opacity: 0.55; cursor: default; }
.start-note { margin: 12px 2px 0; font-size: 21px; line-height: 1.1; color: var(--muted); }

/* ---------- round log ---------- */
.log { margin-top: 30px; border-top: 4px dashed #2c5a5e; padding-top: 16px; }
.log h2 { margin: 0 0 6px; font: 10px/1 var(--px-display); color: var(--aqua); letter-spacing: 1px; }
.log p { margin: 0; font-size: 22px; color: var(--muted); }
.log ul { list-style: none; margin: 0; padding: 0; }
.log li { font-size: 22px; color: var(--cream); padding: 4px 0; border-bottom: 1px dotted #2c5a5e; }

/* ---------- ticker: stops short of the shell's corner ---------- */
.ticker {
  position: fixed; left: 0; right: var(--shell-slot); bottom: 0; z-index: 30;
  background: var(--navy); border-top: 4px solid var(--aqua);
  overflow: hidden; white-space: nowrap; padding: 8px 0;
}
.ticker .track { display: inline-flex; animation: tick 11s steps(56, end) infinite; }
.ticker span { font-size: 20px; line-height: 1; color: var(--aqua); letter-spacing: 1px; padding-right: 8px; }
.ticker b { display: inline-block; width: 8px; height: 8px; background: var(--yellow); margin: 0 14px; vertical-align: 1px; }
@keyframes tick { to { transform: translateX(-50%); } }

/* Messages that are not the page: keep out of the shell's 80x80 corner. */
#toast {
  position: fixed; left: 16px; right: var(--shell-slot);
  bottom: calc(env(safe-area-inset-bottom, 0px) + var(--shell-switcher-inset) + 40px);
  pointer-events: none; z-index: 50;
}
#toast:empty { display: none; }
#toast > * {
  background: var(--navy); color: var(--cream); border: 3px solid var(--aqua);
  padding: 12px 16px; font-size: 22px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; }
}
