:root {
  --bg: #0d1424;
  --panel: #16203a;
  --panel-2: #1e2b4d;
  --ink: #eef2fb;
  --muted: #9aa8c7;
  --accent: #2fd3c5;
  --accent-ink: #062b28;
  --good: #3ddc84;
  --warn: #f4b740;
  --bad: #ff6b6b;
  --tile: #f6f1e4;
  --tile-ink: #1b2236;
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); }
h1, h2, h3 { margin: 0 0 0.4em; }
button {
  font: inherit; font-weight: 700; border: 0; border-radius: 999px; padding: 0.8em 1.4em;
  background: var(--panel-2); color: var(--ink); cursor: pointer;
}
button.primary { background: var(--accent); color: var(--accent-ink); }
button.selected { background: var(--accent); color: var(--accent-ink); }
button:disabled { opacity: 0.45; cursor: default; }
input {
  font: inherit; font-size: 1.2rem; padding: 0.7em 1em; border-radius: var(--radius);
  border: 2px solid var(--panel-2); background: var(--panel); color: var(--ink); width: 100%;
}
.brand { font-weight: 800; letter-spacing: 0.02em; }
.brand span { color: var(--accent); }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* Board */
.board {
  --size: 4;
  display: grid; grid-template-columns: repeat(var(--size), 1fr); gap: 2.2%;
  aspect-ratio: 1; width: 100%; position: relative; user-select: none; -webkit-user-select: none;
}
.tile {
  background: var(--tile); color: var(--tile-ink); border-radius: 16%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; aspect-ratio: 1; box-shadow: 0 0.25em 0 rgba(0, 0, 0, 0.25);
  transition: transform 80ms, background 80ms;
}
.tile.on { background: var(--accent); color: var(--accent-ink); transform: scale(0.94); }
.board.flash-good .tile.on { background: var(--good); }
.board.flash-warn .tile.on { background: var(--warn); }
.board.flash-bad .tile.on { background: var(--bad); color: #fff; }
.board svg.trail { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.board svg.trail polyline { fill: none; stroke: rgba(47, 211, 197, 0.55); stroke-linecap: round; stroke-linejoin: round; }

/* Display page */
body.display { padding: 2.5vh 3vw; min-height: 100vh; }
.display header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 2vh; }
.display header .brand { font-size: 3vh; }
.display .code-pill { font-size: 2.4vh; background: var(--panel); padding: 0.3em 0.9em; border-radius: 999px; }
.display .code-pill b { letter-spacing: 0.2em; color: var(--accent); }
.lobby-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 4vw; align-items: center; }
.qr-card { background: #fff; border-radius: 24px; padding: 2vh; width: min(60vh, 100%); justify-self: center; }
.qr-card img { width: 100%; display: block; }
.join-help { font-size: 2.6vh; }
.join-help .url { color: var(--accent); font-weight: 700; word-break: break-all; }
.player-list { list-style: none; padding: 0; margin: 2vh 0; display: grid; grid-template-columns: 1fr 1fr; gap: 1vh 2vw; }
.player-list li { background: var(--panel); border-radius: var(--radius); padding: 1.2vh 1.4vw; font-size: 2.4vh; display: flex; justify-content: space-between; }
.player-list li.away { opacity: 0.45; }
.badge { font-size: 0.7em; background: var(--accent); color: var(--accent-ink); border-radius: 999px; padding: 0.1em 0.6em; font-weight: 800; }
.play-grid { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4vw; align-items: start; }
.play-grid .board { width: min(82vh, 55vw); font-size: calc(min(82vh, 55vw) / var(--size) * 0.45); }
.timer { font-size: 9vh; font-weight: 800; font-variant-numeric: tabular-nums; }
.timer.low { color: var(--bad); }
.results-head { text-align: center; margin-bottom: 3vh; }
.results-head .winner { font-size: 6vh; font-weight: 800; color: var(--accent); }
.results-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1.5vw; }
.result-card { background: var(--panel); border-radius: var(--radius); padding: 1.6vh 1.2vw; }
.result-card.win { outline: 3px solid var(--accent); }
.result-card h3 { display: flex; justify-content: space-between; font-size: 2.6vh; }
.word-list { list-style: none; padding: 0; margin: 0; columns: 2; font-size: 1.9vh; }
.word-list li { break-inside: avoid; display: flex; justify-content: space-between; gap: 0.6em; padding: 0.1em 0; }
.word-list li.unique { color: var(--accent); font-weight: 700; }
.x2 { font-size: 0.75em; background: var(--accent); color: var(--accent-ink); border-radius: 6px; padding: 0 0.35em; margin-left: 0.3em; }

/* Phone page */
body.phone {
  position: fixed; inset: 0; overflow: hidden; touch-action: manipulation; overscroll-behavior: none;
  padding: max(env(safe-area-inset-top), 12px) 16px max(env(safe-area-inset-bottom), 12px);
  display: flex; flex-direction: column;
}
.phone .screen { display: flex; flex-direction: column; gap: 14px; flex: 1; min-height: 0; }
.phone .top { display: flex; justify-content: space-between; align-items: center; }
.phone .top .brand { font-size: 1.2rem; }
.phone .status { font-size: 0.85rem; color: var(--warn); }
.phone .card { background: var(--panel); border-radius: var(--radius); padding: 16px; }
.phone .options { display: flex; gap: 8px; flex-wrap: wrap; }
.phone .options button { flex: 1; padding: 0.7em 0.4em; }
.phone .big { font-size: 1.25rem; padding: 1em; width: 100%; }
.phone .players { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.phone .players li { background: var(--panel-2); border-radius: 999px; padding: 0.35em 0.8em; font-size: 0.95rem; }
.phone .hud { display: flex; justify-content: space-between; align-items: baseline; }
.phone .hud .timer { font-size: 2.2rem; }
.phone .current { height: 2.4rem; font-size: 1.8rem; font-weight: 800; text-align: center; letter-spacing: 0.08em; }
.phone .current.good { color: var(--good); }
.phone .current.warn { color: var(--warn); }
.phone .current.bad { color: var(--bad); }
.phone .board { touch-action: none; font-size: calc((100vw - 32px) / var(--size) * 0.45); max-width: 520px; margin: 0 auto; }
.phone .found { flex: 1; min-height: 0; overflow-y: auto; }
.phone .found ul { columns: 3; font-size: 0.95rem; }
.phone .score { font-weight: 800; color: var(--accent); }

/* Score reveal on the display: board on top, a panel per player under it (owner 2026-12-02) */
.reveal { display: flex; flex-direction: column; align-items: center; gap: 1.6vh; }
.reveal-banner { min-height: 7vh; font-size: 5vh; font-weight: 800; display: flex; align-items: center; gap: 0.6em; }
.reveal-banner .rword { letter-spacing: 0.08em; }
.reveal-banner .rpoints { color: var(--good); }
.reveal-banner .rwinner { color: var(--accent); }
.reveal-banner .x2 { font-size: 0.6em; padding: 0.1em 0.4em; }
.reveal-board { width: min(43vh, 60vw); font-size: calc(min(43vh, 60vw) / var(--size) * 0.45); } /* 43vh: gives back the gauge's height, so the page is no taller than before it (review 13) */
.panels { display: flex; flex-wrap: wrap; justify-content: center; gap: 1.2vw; width: 100%; }
.panel {
  background: var(--panel); border-radius: var(--radius); padding: 1.2vh 1.2vw; min-width: 11vw; text-align: center;
  transition: transform 150ms, background 150ms, outline-color 150ms; outline: 3px solid transparent;
}
.panel .pname { font-size: 2.3vh; font-weight: 700; display: flex; justify-content: center; align-items: baseline; gap: 0.4em; }
.panel .pname .plabel { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel .pname .pyou { flex: none; }
.panel .pname .ptally { flex: none; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.panel .pscore { font-size: 5vh; font-weight: 800; font-variant-numeric: tabular-nums; }
.panel .pchip { min-height: 2.6vh; font-size: 2vh; font-weight: 700; color: var(--good); }
.panel.got { transform: translateY(-0.6vh); background: var(--panel-2); }
.panel.got-unique { transform: translateY(-0.6vh); background: var(--panel-2); outline-color: var(--accent); }
.panel.got-unique .pchip { color: var(--accent); }
.panel.winner { outline-color: var(--accent); }
.reveal-foot { font-size: 2.1vh; text-align: center; max-width: 80vw; }

/* Phone during the reveal */
.phone .word-list li { opacity: 0.35; transition: opacity 200ms; }
.phone .word-list li.landed { opacity: 1; }
.phone .word-list li.now { color: var(--good); }
.phone .live-score { font-size: 2.4rem; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.phone .host-end { padding: 0.45em 0.9em; font-size: 0.85rem; }
.phone .host-end.armed { background: var(--bad); color: #fff; }

/* Game controls and music on the display (owner 2026-12-02) */
.display .controls { display: flex; align-items: center; gap: 0.8vw; }
.display .ctl { font-size: 1.8vh; padding: 0.5em 1em; }
.display .ctl.armed, .phone .end-game.armed { background: var(--bad); color: #fff; }
.display .music-hint { font-size: 1.7vh; color: var(--warn); }
.display #game-btns { display: flex; gap: 0.8vw; }
.ended { text-align: center; margin-top: 18vh; }
.ended h1 { font-size: 8vh; }
.big-start { font-size: 3vh; padding: 0.9em 2em; margin-top: 3vh; }
.phone .end-game { width: 100%; }
.display .notice { font-size: 1.7vh; color: var(--bad); max-width: 30vw; }

/* Join code in the corner during rounds and the reveal (owner 2026-12-03) */
.join-corner {
  position: fixed; right: 2vw; bottom: 2.5vh; display: flex; align-items: center; gap: 1vw;
  background: var(--panel); border-radius: var(--radius); padding: 1vh 1vw; font-size: 1.7vh; z-index: 5;
  box-shadow: 0 0.6vh 2vh rgba(0, 0, 0, 0.35);
}
.join-corner img { width: 12vh; height: 12vh; background: #fff; border-radius: 10px; padding: 0.6vh; }
.join-corner b { color: var(--accent); font-size: 2vh; }
.join-corner span { color: var(--muted); word-break: break-all; }
body.display.with-join .panels, body.display.with-join .reveal-foot { padding-right: 32vh; } /* the corner card never covers a panel or the summary */
.display .track-name { font-size: 1.7vh; color: var(--muted); }
/* Header controls wrap cleanly on narrow screens */
.display header { flex-wrap: wrap; gap: 1vh 1vw; }
.display .controls { flex-wrap: wrap; justify-content: flex-end; }
.display .ctl, .display .track-name, .display .code-pill { white-space: nowrap; }

/* Join links are real links (owner 2026-12-03) */
.display a.url { text-decoration: underline; text-underline-offset: 0.15em; }
.display a.url:hover { color: var(--ink); }

/* The score reveal on phones: same view as the big screen, compact (owner 2026-12-03) */
.phone .screen.scrolls { overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.reveal.compact { gap: 10px; align-items: stretch; }
.reveal.compact .reveal-banner { min-height: 2.6rem; font-size: 1.5rem; justify-content: center; flex-wrap: wrap; gap: 0.4em; }
.reveal.compact .reveal-board { width: 100%; max-width: 520px; margin: 0 auto; font-size: calc((100vw - 32px) / var(--size) * 0.42); }
.reveal.compact .panels.rows { display: flex; flex-direction: column; gap: 6px; padding: 0; }
.reveal.compact .panel {
  display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 8px;
  min-width: 0; padding: 8px 12px; text-align: left; transform: none;
}
.reveal.compact .panel .pname { font-size: 1rem; }
.reveal.compact .panel .pscore { font-size: 1.4rem; grid-column: 3; grid-row: 1; }
.reveal.compact .panel .pchip { font-size: 0.85rem; min-height: 0; grid-column: 2; grid-row: 1; }
.reveal.compact .panel.you { box-shadow: inset 4px 0 0 var(--accent); } /* a side marker, so x2 and winner outlines still show */
.reveal.compact .panel .pname { min-width: 0; justify-content: flex-start; }
.reveal.compact .panel .pchip { max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.phone .skip-sticky { position: sticky; bottom: 0; z-index: 2; }
.reveal.compact .reveal-foot { font-size: 0.85rem; padding-right: 0; }
.reveal .ryou { font-size: 0.6em; background: var(--good); color: #062b16; border-radius: 6px; padding: 0.1em 0.45em; }
.phone .reveal-controls { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }

/* Join a room by its code, on the splash page (owner 2026-12-03). */
.display .join-box { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6em 1.2em; margin: 0 0 2vh; padding: 1.2vh 1.6vh; background: var(--panel); border-radius: 16px; font-size: 2.2vh; }
.display .join-box.hidden { display: none; }
.display .join-box label { font-weight: 700; }
.display .join-row { display: flex; gap: 0.6em; }
.display .join-box input { width: 6.5em; font: inherit; font-size: 1.2em; font-weight: 800; letter-spacing: 0.25em; text-transform: uppercase; text-align: center; padding: 0.3em 0.4em; border-radius: 10px; border: 2px solid transparent; background: #fff; color: #111; }
.display .join-box input:focus { outline: none; border-color: var(--accent); }
.display .join-box button { font-size: 1em; padding: 0.4em 1.2em; }
/* Always rendered (screen readers announce a live region only if it exists before it fills; review). */
.display .join-msg, .display .invite-msg { margin: 0; flex-basis: 100%; min-height: 1.2em; color: #ffb4a8; font-size: 0.9em; }

/* Invite a friend (owner 2026-12-03): big screen and phones. */
.display .invite-box { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6em 1.2em; margin: 0 0 2vh; padding: 1.2vh 1.6vh; background: var(--panel); border-radius: 16px; font-size: 2vh; }
.display .invite-box.hidden { display: none; }
.display .invite-box label { font-weight: 700; }
.display .invite-box input { width: 18em; font: inherit; padding: 0.35em 0.6em; border-radius: 10px; border: 2px solid transparent; background: #fff; color: #111; }
.display .invite-box input:focus { outline: none; border-color: var(--accent); }
.display .invite-box button { font-size: 1em; padding: 0.4em 1.1em; }
.display .invite-note { margin: 0; flex-basis: 100%; font-size: 0.8em; }
.phone .invite-wrap { margin-top: 10px; padding: 12px 16px; }
.phone .invite-wrap summary { font-weight: 700; cursor: pointer; }
.phone .invite-box { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.phone .invite-box .join-row button { flex: 1; }
.phone .invite-box .join-row button[type="submit"] { flex: 0 0 auto; padding-left: 1.2em; padding-right: 1.2em; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.phone .invite-box label { font-weight: 700; }
.phone .invite-box .join-row { display: flex; gap: 8px; }
.phone .invite-box input { flex: 1; min-width: 0; font: inherit; font-size: 16px; padding: 0.55em 0.7em; border-radius: 10px; border: 2px solid transparent; background: #fff; color: #111; }
.phone .invite-box input:focus { outline: none; border-color: var(--accent); }
.phone .invite-note { margin: 0; font-size: 0.8rem; }
.phone .invite-msg { margin: 0; min-height: 1.1em; color: #ffb4a8; font-size: 0.9rem; }

/* A phone on the big screen's page (owner's report 2026-12-03). */
.display .phone-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.6em; margin: 0 0 2vh; padding: 0.8em 1em; border-radius: 14px; background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 16px; }
.display .phone-bar.hidden { display: none; }
.display .phone-bar a { color: var(--accent-ink); background: #fff; border-radius: 999px; padding: 0.5em 1em; text-decoration: none; white-space: nowrap; }
.display .phone-start { max-width: 34em; }
.display .phone-start h1 { margin-top: 0; }
.display.phone-start-mode .invite-box { display: none; }
@media (max-width: 600px) {
  .display .join-row { flex-wrap: wrap; }
  .display .invite-box input { width: 100%; }
  .display .join-box, .display .invite-box { font-size: 16px; }
}

/* Player rows: a gap between name and count, and a long name is cut short, never pushed off the screen
   (play test 2026-12-03: "Bmiller0 words"). */
.player-list li { gap: 0.6em; min-width: 0; }
.player-list li > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-list li > span:last-child:not(:first-child) { flex: none; } /* a lone name still truncates (review round 10) */

/* The big screen's page on a narrow screen (a phone used as the big screen): one column, sizes in rem, the join
   card in the page flow instead of pinned over it (play test 2026-12-03: text ran off the screen). */
@media (max-width: 700px) {
  body.display { padding: 12px; }
  .display header .brand { font-size: 1.4rem; }
  .lobby-grid, .play-grid { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .qr-card { width: min(70vw, 280px); }
  .display h1 { font-size: 1.8rem; }
  .join-help, .display .join-help { font-size: 1rem; }
  .play-grid .board { width: 100%; font-size: calc((100vw - 24px) / var(--size) * 0.42); }
  .timer { font-size: 3rem; }
  .player-list { grid-template-columns: minmax(0, 1fr); }
  .player-list li { font-size: 1rem; padding: 10px 12px; }
  .join-corner { position: static; margin-top: 16px; max-width: none; }
  .join-corner img { width: 96px; height: 96px; }
  .join-corner b { font-size: 1rem; }
  body.display.with-join .panels, body.display.with-join .reveal-foot { padding-right: 0; }
  .display .code-pill { font-size: 1rem; }
  .display .controls .ctl { font-size: 0.85rem; }
  .ended { margin-top: 6vh; }
  .ended h1 { font-size: 2.6rem; }
  .big-start { font-size: 1.1rem; }
}

/* The room code, always on the phone's screen, so a player can tell someone else (owner 2026-12-03). */
.phone .top .room-chip { font-size: 0.9rem; background: var(--panel); border-radius: 999px; padding: 0.25em 0.8em; white-space: nowrap; }
.phone .top .room-chip b { letter-spacing: 0.15em; color: var(--accent); }
.phone .top { gap: 8px; }
.phone .top .status { flex: 1; min-width: 0; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.display.phone-start-mode #music-btn, .display.phone-start-mode #track-name, .display.phone-start-mode #next-track, .display.phone-start-mode .music-hint { display: none; }
.cancelled { font-size: 0.6em; background: var(--bad); color: #fff; border-radius: 6px; padding: 0 0.35em; margin-left: 0.3em; text-transform: uppercase; }
.phone .card .options + .muted { margin: 8px 0 0; font-size: 0.9rem; }

/* Two-part gauge during the reveal: words in common, then words only one player found (owner 2026-12-03) */
.gauge { display: flex; flex-direction: column; gap: 0.5vh; width: min(70vw, 120vh); }
.gauge .gbars { display: flex; gap: 0.6vw; }
.gauge .gbar { flex-basis: 0; min-width: 10px; height: 1.8vh; min-height: 8px; border-radius: 999px; background: var(--panel); overflow: hidden; }
.gauge .gfill { height: 100%; width: 0; border-radius: inherit; transition: width 400ms ease-out; }
.gauge .common .gfill { background: var(--good); }
.gauge .different .gfill { background: var(--accent); }
.gauge .glabels { display: flex; justify-content: space-between; gap: 1em; font-size: 2.3vh; color: var(--muted); }
.gauge .glabel { display: flex; gap: 0.5em; white-space: nowrap; }
.gauge .gname { font-weight: 700; }
.gauge .glabel.common .gname { color: var(--good); }
.gauge .glabel.different .gname { color: var(--accent); }
.gauge .gnum { font-variant-numeric: tabular-nums; }
.reveal.compact .gauge { width: 100%; gap: 4px; }
.reveal.compact .gauge .gbars { gap: 6px; }
.reveal.compact .gauge .gbar { height: 10px; }
.reveal.compact .gauge .glabels { font-size: 0.8rem; }
@media (prefers-reduced-motion: reduce) { .gauge .gfill { transition: none; } }

/* This phone's music button (owner 2026-12-04), beside the room code */
.phone .top .music-chip { flex: none; font: inherit; font-size: 1rem; font-weight: 700; color: var(--muted); background: var(--panel); border: 0; border-radius: 999px; padding: 0 0.6em; min-height: 40px; min-width: 40px; cursor: pointer; }
.phone .top .music-chip[aria-pressed="true"] { color: var(--accent-ink); background: var(--accent); }
.phone .top .music-chip.waiting { color: var(--accent); background: var(--panel); box-shadow: inset 0 0 0 2px var(--accent); }
/* The connection status shows as a strip just under the header, over the screen, so neither the music button
   nor the room code squeezes it out on a narrow phone, and it never moves the board under a swiping finger
   (review round 16 and its delta). With nothing to say, it is not drawn. */
.phone .top { position: relative; }
.phone .top .brand { margin-right: auto; }
.phone .top .status {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 5; flex: none; text-align: center; white-space: normal;
  padding: 2px 8px; background: var(--bg); border-radius: 0 0 8px 8px; pointer-events: none; /* taps reach what is under it */
}
.phone .top .status:empty { display: none; }
