/* TRUR – styles from the approved Claude Design ("Olive board", light and dark).
   No inline styles anywhere (CSP); JS only sets custom properties and data-* attributes. */

@font-face { font-family: "Space Grotesk"; font-weight: 400; font-display: swap; src: url("../fonts/space-grotesk-latin-400.woff2") format("woff2"); }
@font-face { font-family: "Space Grotesk"; font-weight: 500; font-display: swap; src: url("../fonts/space-grotesk-latin-500.woff2") format("woff2"); }
@font-face { font-family: "Space Grotesk"; font-weight: 700; font-display: swap; src: url("../fonts/space-grotesk-latin-700.woff2") format("woff2"); }
@font-face { font-family: "Space Mono"; font-weight: 400; font-display: swap; src: url("../fonts/space-mono-latin-400.woff2") format("woff2"); }
@font-face { font-family: "Space Mono"; font-weight: 700; font-display: swap; src: url("../fonts/space-mono-latin-700.woff2") format("woff2"); }

/* --- tokens: light is the default --- */
:root {
  --ground: #FFFFFF;
  --ink: #1E1E1E;
  --muted: #5C5C5C;
  --line: #E2E2DC;
  --panel: #EEF0E6;
  --tile: #6B7B3A;
  --tile-ink: #FFFFFF;
  --tile-edge: #4D5829;
  --tile-shadow: rgba(0, 0, 0, .25);
  --accent: #6B7B3A;
  --accent-ink: #FFFFFF;
  --orange: #D9853B;
  --on-orange: #1E1E1E;
  --red: #C0392B;
  --on-red: #FFFFFF;
  --frame: #1E1E1E;
  --frame-shadow: rgba(0, 0, 0, .2);
  --page: #F6F6F3;
  --font-ui: "Space Grotesk", system-ui, sans-serif;
  --font-tile: "Space Mono", ui-monospace, monospace;
  color-scheme: light;
}

/* dark: follows the system until the player picks a mode with the toggle */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #171A12; --ink: #FFFFFF; --muted: #B9BDAE; --line: #2F3524; --panel: #232819;
    --tile-edge: #F2EDE0; --tile-shadow: rgba(242, 237, 224, .5);
    --frame: #F2EDE0; --frame-shadow: rgba(242, 237, 224, .5); --page: #0F110B;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --ground: #171A12; --ink: #FFFFFF; --muted: #B9BDAE; --line: #2F3524; --panel: #232819;
  --tile-edge: #F2EDE0; --tile-shadow: rgba(242, 237, 224, .5);
  --frame: #F2EDE0; --frame-shadow: rgba(242, 237, 224, .5); --page: #0F110B;
  color-scheme: dark;
}

/* --- page and the fixed 640×640 game area --- */
* { box-sizing: border-box; }
html, body { margin: 0; }
/* Phones: no double-tap zoom delay, no text inflation, no grey tap flash. None of these changes desktop.
   Never text-size-adjust: none, which would block the player's text scaling. */
html { touch-action: manipulation; -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font-ui);
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
[hidden] { display: none !important; }
/* the frame colour: 16.7:1 on light, 15.1:1 on dark; orange was 2.85:1 on white (owner, 2026-10-13) */
:focus-visible { outline: 3px solid var(--frame); outline-offset: 2px; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.app {
  position: relative;
  width: 640px;
  height: 640px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--ground);
  color: var(--ink);
}

/* --- header --- */
.bar {
  height: 64px;
  flex: none;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 20px;
  border-bottom: 2px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { width: 27px; height: 27px; display: block; }
.wordmark { font-weight: 700; font-size: 22px; letter-spacing: 2px; }
.stat { display: flex; flex-direction: column; line-height: 1.1; }
.stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.stat-value { font-family: var(--font-tile); font-size: 20px; }
.tries { display: flex; gap: 5px; padding-top: 5px; }
.dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--ink); }
.dot[data-full="true"] { background: var(--ink); }
.bar-end { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.found-open { display: none; } /* the status strip's counter, phones only (P4); it opens the found sheet from P5 */

.icon-button {
  width: 40px;
  height: 40px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 2px solid var(--ink);
}
.icon-button svg { width: 20px; height: 20px; }
.theme-sun { display: none; }
.is-dark .theme-sun { display: block; }
.is-dark .theme-moon { display: none; }

.modes { display: flex; border: 2px solid var(--ink); }
.modes button {
  padding: 6px 14px;
  border: 0;
  background: transparent;
  font-size: 14px;
  font-weight: 500;
}
.modes button[aria-current="page"] { background: var(--accent); color: var(--accent-ink); font-weight: 700; }

/* --- screens --- */
.screen { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.screen-center { align-items: center; justify-content: center; gap: 24px; padding: 24px; }
.status-text { color: var(--muted); }

/* --- game screen --- */
.game-main { flex: 1; min-height: 0; display: flex; }
.grid-area { flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center; }
.grid {
  --tile-size: 48px;
  --gap: 6px;
  /* fitGrid (js/grid.js) reads these. Desktop sizes tiles for the fixed --fit-w × --fit-h box. */
  --head: 30px;       /* the source-word tiles (owner, 2026-10-14: "Source words as orange tiles") */
  --max-tile: 48px;
  --gap-dense: 4px;   /* 8 or more columns or rows */
  --gap-loose: 6px;
  --fit-w: 410px;
  --fit-h: 470px;
  --won-h: 70px;      /* the daily "won" banner, margin included */
  display: grid;
  grid-template-columns: var(--head) repeat(var(--cols, 6), var(--tile-size));
  grid-template-rows: var(--head) repeat(var(--rows, 6), var(--tile-size));
  gap: var(--gap);
  align-items: center;
  justify-items: center;
}
/* each source-word letter on its own orange tile, at 150 % (14 → 21 px). No frame and no shadow, so it
   stays apart from a selected tile, which is also orange */
.grid .head {
  width: var(--head);
  height: var(--head);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-tile);
  font-size: 21px;
  font-weight: 700;
  background: var(--orange);
  color: var(--on-orange);
}
.grid .head-col { align-self: end; }

.tile {
  width: var(--tile-size);
  height: var(--tile-size);
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-tile);
  font-weight: 700;
  font-size: calc(var(--tile-size) * .35);
  letter-spacing: 1px;
  background: var(--tile);
  color: var(--tile-ink);
  border: 2px solid var(--tile-edge);
  box-shadow: 3px 3px 0 var(--tile-shadow);
}
.tile[data-state="selected"] { background: var(--orange); color: var(--on-orange); border-color: var(--frame); }
.tile[data-state="rejected"] {
  background: var(--red);
  color: var(--on-red);
  border-color: var(--frame);
  animation: shake 400ms ease-in-out;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
@media (prefers-reduced-motion: reduce) { .tile[data-state="rejected"] { animation: none; } }

.found, .m-side { /* .m-side: the match's own word panel (multiplayer, below) */
  width: 190px;
  flex: none;
  margin: 16px 16px 16px 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  min-height: 0;
}
.found-head { padding: 10px 14px; background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 14px; }
.found-list {
  list-style: none;
  margin: 0;
  padding: 8px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  font-family: var(--font-tile);
  font-size: 15px;
}
.found-list li { display: flex; justify-content: space-between; }
.found-list .pts { color: var(--muted); }
.found-foot { margin-top: auto; padding: 8px 14px 12px; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.found-note { margin: 0; font-size: 12px; line-height: 1.4; color: var(--muted); }
.link-button { padding: 0; border: 0; background: none; font-size: 13px; font-weight: 700; text-decoration: underline; }

/* --- daily: the won banner (it shrinks the grid area by its height, see WON_HEIGHT in game.js) --- */
.won {
  flex: none;
  margin: 12px 16px 0;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--orange);
  color: var(--on-orange);
  border: 2px solid var(--frame);
  box-shadow: 3px 3px 0 var(--frame-shadow);
}
.won svg { width: 22px; height: 22px; flex: none; }
.won-text { display: flex; flex-direction: column; line-height: 1.25; }
.won-text strong { font-size: 15px; }
.won-text span { font-size: 13px; }
.won-close { display: none; } /* phones only (P6) */

.solution {
  height: 88px;
  flex: none;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-top: 2px solid var(--line);
}
.solution-word { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; overflow: hidden; }
#chips { display: flex; gap: 6px; }
.chip {
  padding: 4px 6px;
  font-family: var(--font-tile);
  font-weight: 700;
  font-size: 14px;
  background: var(--orange);
  color: var(--on-orange);
  border: 2px solid var(--frame);
}
.preview { margin-left: 6px; font-family: var(--font-tile); font-size: 18px; white-space: nowrap; }
.preview[data-empty="true"] { color: var(--muted); font-size: 16px; }

.button {
  height: 44px;
  padding: 0 14px;
  background: transparent;
  border: 2px solid var(--ink);
  font-weight: 500;
}
.button-primary {
  padding: 0 18px;
  background: var(--orange);
  color: var(--on-orange);
  border-color: var(--frame);
  font-weight: 700;
  box-shadow: 3px 3px 0 var(--frame-shadow);
}
.button:disabled { opacity: .5; }

/* --- game over --- */
.over-main { flex: 1; min-height: 0; padding: 20px 24px; display: flex; flex-direction: column; gap: 16px; }
.over-top { display: flex; align-items: flex-end; justify-content: space-between; }
.over-title { margin: 0; font-size: 34px; line-height: 1; }
.over-sub { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.over-score { text-align: right; }
.over-points { font-family: var(--font-tile); font-size: 40px; line-height: 1; }
.over-meta { color: var(--muted); font-size: 13px; }
.over-lists { flex: 1; min-height: 0; display: flex; gap: 16px; }
.over-yours { width: 150px; flex: none; display: flex; flex-direction: column; min-height: 0; background: var(--panel); }
.over-missed { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; border: 2px solid var(--line); }
.over-head { margin: 0; padding: 8px 12px; font-size: 14px; }
.over-yours .over-head { background: var(--accent); color: var(--accent-ink); }
.over-missed .over-head { border-bottom: 2px solid var(--line); }
.over-list, .over-grid {
  list-style: none;
  margin: 0;
  padding: 8px 12px;
  overflow-y: auto;
  font-family: var(--font-tile);
}
.over-list { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.over-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-content: start;
  column-gap: 14px;
  row-gap: 3px;
  font-size: 12px;
}
.over-list li, .over-grid li { display: flex; justify-content: space-between; }
.over-list .pts, .over-grid .pts { color: var(--muted); }
.over-note { flex: 1; color: var(--muted); font-size: 13px; }
.over-hidden { flex: 1; min-width: 0; display: flex; flex-direction: column; border: 2px solid var(--line); }
.over-hidden .over-head { border-bottom: 2px solid var(--line); }
.over-hidden-text { margin: 0; padding: 12px; font-size: 14px; line-height: 1.5; color: var(--muted); }

/* --- past answers --- */
.bar-title { margin: 0; font-size: 18px; font-weight: 500; }
.bar-back { height: 40px; font-size: 14px; }
.answers-main { flex: 1; min-height: 0; padding: 16px 24px; display: flex; flex-direction: column; gap: 12px; }
.answers-top { display: flex; align-items: center; gap: 10px; }
.day-button {
  width: 44px;
  height: 44px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 2px solid var(--line);
}
.day-button svg { width: 18px; height: 18px; }
.day-button:disabled { color: var(--muted); opacity: .5; }
.answers-day { min-width: 210px; display: flex; flex-direction: column; line-height: 1.2; }
.answers-date { font-weight: 700; font-size: 18px; }
.answers-meta { font-family: var(--font-tile); font-size: 13px; color: var(--muted); }
.answers-you {
  margin-left: auto;
  padding: 6px 10px;
  font-weight: 700;
  font-size: 14px;
  background: var(--orange);
  color: var(--on-orange);
  border: 2px solid var(--frame);
}
.answers-legend { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.swatch { width: 14px; height: 14px; background: var(--orange); border: 2px solid var(--frame); }
.answers-sort { margin-left: 12px; }
.answers-empty { margin: 0; color: var(--muted); }
.answers-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  align-content: start;
  list-style: none;
  margin: 0;
  padding: 10px 12px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  column-gap: 12px;
  row-gap: 2px;
  background: var(--panel);
  font-family: var(--font-tile);
  font-size: 12px;
}
.answers-list li { display: flex; justify-content: space-between; padding: 1px 4px; }
.answers-list li[data-mine="true"] { background: var(--orange); color: var(--on-orange); font-weight: 700; }

/* --- leaderboards --- */
.boards-main { flex: 1; min-height: 0; padding: 18px 24px; display: flex; flex-direction: column; gap: 14px; }
.boards-tabs { display: flex; align-self: flex-start; border: 2px solid var(--ink); }
.boards-tabs button { height: 40px; padding: 0 14px; border: 0; background: transparent; font-size: 14px; font-weight: 500; }
.boards-tabs button[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.boards-top { display: flex; align-items: center; gap: 10px; }
.boards-period { min-width: 170px; text-align: center; font-weight: 700; font-size: 18px; }
.boards-hint { margin-left: auto; font-size: 13px; color: var(--muted); }
.boards-scroll { flex: 1; min-height: 0; overflow-y: auto; }
.boards-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.boards-table th {
  position: sticky;
  top: 0;
  padding: 8px 12px;
  text-align: left;
  background: var(--accent);
  color: var(--accent-ink);
}
.boards-table th:first-child { width: 64px; }
.boards-table td { padding: 7px 12px; overflow-wrap: anywhere; }
.boards-table th:last-child, .boards-table td:last-child { text-align: right; }
.boards-table td:first-child, .boards-table td:last-child { font-family: var(--font-tile); }
.boards-table tr:nth-child(even) { background: var(--panel); }
.boards-table tr[data-me="true"] { background: var(--orange); color: var(--on-orange); font-weight: 700; }
.boards-empty { margin: 0; color: var(--muted); }

/* --- word feedback popup --- */
.toast {
  position: absolute;
  left: 50%;
  bottom: 104px;
  transform: translateX(-50%);
  width: 380px;
  background: var(--ground);
  color: var(--ink);
  border: 2px solid var(--frame);
  box-shadow: 4px 4px 0 var(--frame-shadow);
}
.toast-head { display: flex; align-items: center; gap: 8px; padding: 8px 14px; background: var(--accent); color: var(--accent-ink); }
.toast[data-kind="rejected"] .toast-head { background: var(--red); color: var(--on-red); }
.toast-head svg { width: 18px; height: 18px; flex: none; }
.toast-title { font-size: 15px; }
.toast-body { padding: 10px 14px 12px; display: flex; flex-direction: column; gap: 6px; font-size: 14px; line-height: 1.4; }
.toast-hint { color: var(--muted); font-size: 13px; }

/* --- nickname screen --- */
.logo-full {
  display: grid;
  grid-template-columns: 28px 64px 64px;
  grid-template-rows: 28px 64px 64px;
  gap: 8px;
  padding: 0 36px 36px 0; /* centres the four tiles, not the headers */
  align-items: center;
  justify-items: center;
}
.logo-full .head { font-family: var(--font-tile); font-size: 18px; color: var(--muted); }
.logo-tile {
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-tile);
  font-weight: 700;
  font-size: 22px;
  border: 2px solid var(--frame);
  box-shadow: 4px 4px 0 var(--frame-shadow);
  background: var(--tile);
  color: var(--tile-ink);
}
.logo-tile.on { background: var(--orange); color: var(--on-orange); }
.nick-title { margin: 0; font-size: 30px; text-align: center; }
.nick-sub { margin: 8px 0 0; color: var(--muted); font-size: 15px; text-align: center; }
.nick-form { width: 360px; display: flex; flex-direction: column; gap: 8px; }
.nick-form label { font-weight: 500; font-size: 14px; }
.nick-row { display: flex; gap: 10px; }
.nick-row input {
  flex: 1;
  height: 48px;
  padding: 0 12px;
  border: 2px solid var(--ink);
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  font-size: 17px;
  box-shadow: 3px 3px 0 var(--frame-shadow);
}
.nick-row .button-primary { height: 48px; }
.nick-help { margin: 0; font-size: 13px; color: var(--muted); }
.nick-error { margin: 0; font-size: 13px; color: var(--red); font-weight: 700; }
.is-dark .nick-error { color: #F0A59C; }
.privacy { margin: 0; width: 420px; text-align: center; font-size: 12px; line-height: 1.5; color: var(--muted); }

/* --- the found sheet (phones, mobile.md §6.4): a <dialog> the found panel moves into; never opened on desktop --- */
.sheet {
  position: fixed;
  inset: auto 0 0;
  width: 100%;
  max-width: none;
  max-height: 60svh;
  margin: 0;
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overflow: hidden;
  background: var(--panel);
  color: var(--ink);
  border: 0;
  border-top: 2px solid var(--frame); /* the panel colour alone is only 1.15:1 against the ground */
  transition: transform 200ms ease-out, overlay 200ms allow-discrete, display 200ms allow-discrete;
}
.sheet[open] { display: flex; flex-direction: column; }
@starting-style { .sheet[open] { transform: translateY(100%); } }
.sheet::backdrop { background: rgba(0, 0, 0, .45); }
.sheet-top { flex: none; display: flex; justify-content: flex-end; }
.sheet-close {
  width: 44px;
  height: 44px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 0;
}
.sheet-close svg { width: 22px; height: 22px; }
.sheet .found { width: auto; margin: 0; flex: 1 1 auto; min-height: 0; }
html:has(dialog[open]) { overflow: hidden; }
@media (prefers-reduced-motion: reduce) { .sheet { transition: none; } }

/* === phones, portrait (docs/mobile.md §4–§6); every viewport of at least 640 × 640 is unchanged ===
   Keep the query in step with PHONE_QUERY in js/grid.js. */
@media (max-width: 639px) {
  /* page shell (P3): a full-bleed shell that never scrolls; screens other than the game scroll inside it */
  body { display: block; min-height: 0; background: var(--ground); }
  .app {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    padding-top: env(safe-area-inset-top);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
  .screen:not(#screen-game):not(#screen-match) { overflow-y: auto; padding-bottom: env(safe-area-inset-bottom); }
  .screen-center { justify-content: safe center; }
  .bar { height: auto; min-height: 64px; }
  .solution { height: auto; min-height: 88px; }
  .button { height: auto; min-height: 44px; }
  .found-list, .over-list, .over-grid, .answers-list, .boards-scroll { overscroll-behavior: contain; }

  .grid { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; cursor: pointer; }

  /* header (P4): row 1 (48 px) logo and controls; row 2 (32 px) the status strip, or the screen title.
     The ::after is a zero-height line break; order moves the strip and title after it. */
  .bar { min-height: 0; padding: 0 12px; flex-wrap: wrap; column-gap: 8px; row-gap: 0; }
  .bar::after { content: ""; order: 2; flex-basis: 100%; height: 0; }
  .brand, .bar-end { min-height: 48px; }
  .bar-end { gap: 8px; }
  .icon-button { width: 44px; height: 44px; }
  .modes button { min-width: 44px; min-height: 44px; }
  .stat, .found-open, .bar-title { order: 3; height: 32px; }
  .stat { flex-direction: row; align-items: center; gap: 6px; }
  .stat-value { font-size: 16px; }
  .tries { padding-top: 0; }
  .bar-title { font-size: 16px; line-height: 32px; }
  .found-open {
    position: relative;
    z-index: 1; /* its hit area reaches over the row above and the screen below */
    margin-left: auto;
    padding: 0 10px;
    display: flex;
    align-items: center;
    background: transparent;
    border: 2px solid var(--ink);
    font-size: 14px;
    font-weight: 700;
  }
  .found-open::after { content: ""; position: absolute; inset: -8px -2px; } /* 6 px past the border: a 44 px hit area at no layout cost */

  /* found sheet (P5): the side panel lives in the sheet on phones */
  .game-main > .found, .game-main > .m-side { display: none; }
  .found-flash {
    position: absolute;
    right: -4px;
    top: -12px;
    padding: 0 4px;
    font-family: var(--font-tile);
    font-size: 12px;
    background: var(--orange);
    color: var(--on-orange); /* ink on an orange chip: orange text on white is only 2.85:1 */
    border: 2px solid var(--frame);
    opacity: 0;
    pointer-events: none;
  }
  .found-open[data-flash="a"] .found-flash { animation: flash-a 1s ease-out; }
  .found-open[data-flash="b"] .found-flash { animation: flash-b 1s ease-out; }

  /* game screen (P6, mobile.md §5 and §6.3): a column of the compact won banner, the measured grid
     (flex: 1) and the action area. Values are provisional until the P9 design. */
  .grid-area { flex: 1 1 0; min-height: 0; overflow: hidden; padding: 8px 12px; }
  .grid {
    --head: 22px;     /* the source-word tiles; was 16px */
    --max-tile: 56px;
    --gap-dense: 3px;
    --gap-loose: 4px;
    --fit-w: none; /* fitGrid measures .grid-area instead of the desktop box */
    gap: 0;
    grid-template-columns: var(--head) repeat(var(--cols), calc(var(--tile-size) + var(--gap)));
    grid-template-rows: var(--head) repeat(var(--rows), calc(var(--tile-size) + var(--gap)));
  }
  .grid .head { font-size: 18px; } /* 150 % of 12px */

  /* every point of the grid is a tile button: it covers its whole cell, gaps included, and the visible
     tile is drawn on ::before, half a gap in (mobile.md §5.3) */
  .tile {
    width: calc(var(--tile-size) + var(--gap));
    height: calc(var(--tile-size) + var(--gap));
    position: relative;
    isolation: isolate;
    background: none;
    border: 0;
    box-shadow: none;
    font-size: max(12px, calc(var(--tile-size) * .35));
  }
  .tile[data-state] { background: none; } /* beats the desktop state rules (0,2,0) */
  .tile::before {
    content: "";
    position: absolute;
    inset: calc(var(--gap) / 2);
    z-index: -1;
    background: var(--tile);
    border: 2px solid var(--tile-edge);
    box-shadow: 2px 2px 0 var(--tile-shadow);
  }
  .tile[data-state="selected"]::before { background: var(--orange); border-color: var(--frame); }
  .tile[data-state="rejected"]::before { background: var(--red); border-color: var(--frame); }
  .tile:focus-visible { outline-offset: calc(var(--gap) / -2); }
  /* press feedback moves only the drawn tile: moving the button would let a press near its edge end on
     the neighbour, and the browser then fires no click at all */
  .tile:active:not(:disabled)::before { transform: translate(2px, 2px); box-shadow: none; }
  .grid[data-dense="true"] .tile { letter-spacing: 0; }

  .won { margin: 8px 12px 0; padding: 4px 4px 4px 10px; gap: 8px; }
  .won svg { width: 18px; height: 18px; }
  .won-text strong { font-size: 14px; }
  .won-text span { display: none; } /* one line on phones */
  .won-close {
    margin-left: auto;
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 0;
    color: inherit;
  }
  .won-close svg { width: 18px; height: 18px; }

  /* action area: row A the preview (no chips), row B End (small, far left), Clear, Submit (wide) */
  #screen-game .solution {
    min-height: 0;
    flex-wrap: wrap;
    padding: 8px 12px max(8px, env(safe-area-inset-bottom));
    gap: 8px;
  }
  #screen-game .solution-word { flex: 1 0 100%; min-height: 28px; }
  #screen-game #chips { display: none; }
  #screen-game .preview { margin-left: 0; white-space: normal; overflow-wrap: anywhere; line-height: 1.3; }
  #screen-game .solution .button { min-height: 48px; }
  #screen-game [data-testid="end"] { padding: 0 10px; font-size: 13px; }
  #screen-game [data-testid="submit"] { flex: 1; }

  /* toast (P8, mobile.md §6.5): docked over the action area and never over the grid, so it is compact;
     the hint line is left out on phones (to be confirmed in the P9 design) */
  .toast { bottom: env(safe-area-inset-bottom); width: min(380px, calc(100% - 24px)); }
  .toast-head { padding: 6px 12px; }
  .toast-title { font-size: 14px; }
  .toast-body { padding: 6px 12px 8px; font-size: 13px; line-height: 1.35; }
  .toast-hint { display: none; }

  /* press feedback replaces the tap highlight: the pressed offset, without the shadow */
  .button:active:not(:disabled), .icon-button:active {
    transform: translate(2px, 2px);
    box-shadow: none;
  }
}

/* narrow phones: the compact logo without the wordmark (P4) */
@media (max-width: 399px) {
  .wordmark { display: none; }
}

/* the +points flash (P5): two identical keyframes, so alternating data-flash restarts it */
@keyframes flash-a { 0%, 60% { opacity: 1; transform: translateY(0); } 100% { opacity: 0; transform: translateY(-6px); } }
@keyframes flash-b { 0%, 60% { opacity: 1; transform: translateY(0); } 100% { opacity: 0; transform: translateY(-6px); } }
@media (prefers-reduced-motion: reduce) {
  .found-open[data-flash] .found-flash { animation: none; opacity: 1; } /* a static highlight while data-flash lasts */
}

/* === multiplayer (docs/multiplayer.md §8) ===
   Built from the solo screens' parts, before its Claude Design pass: the queue and 3-2-1 reuse the centred
   screen, the match reuses the grid and action area, the vote and results the game-over layout. */

/* queue, match found, 3-2-1 and the notes */
.lobby-title { margin: 0; font-size: 30px; text-align: center; }
.lobby-text { margin: 0; max-width: 400px; color: var(--muted); font-size: 15px; line-height: 1.5; text-align: center; }
.lobby-players { list-style: none; margin: 0; padding: 0; max-width: 480px; display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.lobby-players li { padding: 6px 12px; background: var(--panel); border: 2px solid var(--frame); font-weight: 700; font-size: 15px; overflow-wrap: anywhere; }
.lobby-count { font-family: var(--font-tile); font-weight: 700; font-size: 96px; line-height: 1; }
.lobby-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }

/* the match: every tile shows its value; colour fades with it, and a tile you used is hatched and dashed,
   so neither state relies on colour alone */
#m-timer { min-width: 4ch; }
#m-timer[data-warning="true"] { color: var(--red); font-weight: 700; }
.is-dark #m-timer[data-warning="true"] { color: #F0A59C; }
#m-grid .tile { position: relative; }
#m-grid .tile[data-faded="true"]:not([data-state="selected"]):not([data-state="rejected"]) { color: var(--ink); }
#m-grid .tile[data-label]::after {
  content: attr(data-label);
  position: absolute;
  right: 3px;
  bottom: 2px;
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0;
  line-height: 1;
}
#m-grid[data-dense="true"] .tile::after { display: none; } /* under 36 px the fade alone shows the value */
#m-grid .tile[data-locked="true"] { cursor: not-allowed; }
@media (min-width: 640px) {
  #m-grid .tile:not([data-state="selected"]):not([data-state="rejected"]) {
    background-color: color-mix(in srgb, var(--tile) calc(var(--pct, 100) * 1%), var(--panel));
  }
  #m-grid .tile[data-locked="true"] {
    background-image: repeating-linear-gradient(135deg, transparent 0 6px, var(--tile-shadow) 6px 8px);
    border-style: dashed;
  }
}
.m-side .m-showcase { padding: 8px 14px; display: flex; flex-direction: column; gap: 2px; border-bottom: 2px solid var(--line); font-size: 12px; color: var(--muted); }
.m-side .m-showcase strong { font-family: var(--font-tile); font-size: 15px; color: var(--ink); overflow-wrap: anywhere; }
.m-words { display: none; } /* phones only: a one-line strip instead of the side panel */
.button-showcase { background: var(--accent); color: var(--accent-ink); border-color: var(--frame); font-weight: 700; }

/* the popup stack: over the bottom of the side panel on desktop, never over the grid */
.popups {
  position: absolute;
  right: 24px;
  bottom: 112px;
  width: 174px;
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
  z-index: 2;
}
.popup {
  padding: 6px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--ground);
  color: var(--ink);
  border: 2px solid var(--frame);
  border-left: 8px solid var(--accent);
  box-shadow: 3px 3px 0 var(--frame-shadow);
  font-size: 13px;
  line-height: 1.3;
}
.popup span { color: var(--muted); font-size: 12px; }
.popup[data-kind="note"] { border-left-color: var(--orange); }
.popup[data-kind="rejected"] { border-left-color: var(--red); }
.popup[data-kind="warning"] { background: var(--orange); color: var(--on-orange); }

/* the creativity vote */
.vote-main, .res-main { flex: 1; min-height: 0; padding: 20px 24px; display: flex; flex-direction: column; gap: 16px; overflow-y: auto; }
.vote-cands { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 10px; }
.cand {
  min-height: 48px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border: 2px solid var(--ink);
  font-family: var(--font-tile);
  font-weight: 700;
  font-size: 17px;
}
.cand[aria-pressed="true"] { background: var(--orange); color: var(--on-orange); border-color: var(--frame); box-shadow: 3px 3px 0 var(--frame-shadow); }
.cand-rank { font-family: var(--font-ui); font-size: 12px; }
.cand:disabled { opacity: .6; }
.vote-slots { list-style: none; margin: 0; padding: 0; display: flex; gap: 10px; }
.slot { flex: 1; min-width: 0; min-height: 60px; padding: 8px 12px; display: flex; flex-direction: column; justify-content: center; gap: 2px; border: 2px dashed var(--line); }
.slot[data-filled="true"] { border-style: solid; border-color: var(--frame); }
.slot-label { font-size: 12px; color: var(--muted); }
.slot strong { font-family: var(--font-tile); font-size: 16px; overflow-wrap: anywhere; }

/* results */
.res-players { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.res-player { padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; background: var(--panel); }
.res-player[data-place="1"] { border: 2px solid var(--frame); background: var(--orange); color: var(--on-orange); }
.res-row { display: flex; align-items: baseline; gap: 12px; }
.res-place { width: 24px; font-family: var(--font-tile); font-weight: 700; font-size: 18px; }
.res-name { flex: 1; min-width: 0; font-weight: 700; font-size: 17px; overflow-wrap: anywhere; }
.res-score { font-family: var(--font-tile); font-weight: 700; font-size: 22px; }
.res-detail { margin: 0 0 0 36px; font-size: 13px; }
.res-words { list-style: none; margin: 0 0 0 36px; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 14px; font-family: var(--font-tile); font-size: 13px; }
.res-words li { display: flex; gap: 6px; }
.res-words .pts { opacity: .75; }
.res-missed { display: flex; flex-direction: column; border: 2px solid var(--line); }
.res-missed .over-head { border-bottom: 2px solid var(--line); }
.res-missed .over-grid { flex: none; }

@media (max-width: 639px) {
  /* the match screen follows the solo game screen (P6): measured grid, then a word strip and the action area */
  #m-grid .tile:not([data-state="selected"]):not([data-state="rejected"])::before {
    background-color: color-mix(in srgb, var(--tile) calc(var(--pct, 100) * 1%), var(--panel));
  }
  #m-grid .tile[data-locked="true"]::before {
    background-image: repeating-linear-gradient(135deg, transparent 0 5px, var(--tile-shadow) 5px 7px);
    border-style: dashed;
  }
  .m-words {
    display: block;
    flex: none;
    padding: 4px 12px;
    overflow-x: auto;
    white-space: nowrap;
    font-family: var(--font-tile);
    font-size: 13px;
    color: var(--muted);
    border-top: 2px solid var(--line);
  }
  #screen-match .solution { min-height: 0; flex-wrap: wrap; padding: 8px 12px max(8px, env(safe-area-inset-bottom)); gap: 8px; }
  #screen-match .solution-word { flex: 1 0 100%; min-height: 28px; }
  #screen-match .preview { margin-left: 0; white-space: normal; overflow-wrap: anywhere; line-height: 1.3; }
  #screen-match .solution .button { min-height: 48px; }
  #screen-match [data-testid="m-submit"] { flex: 1; } /* Showcase on the far left, Submit wide on the right */
  /* phones: only the newest popup, on one line over the preview row, so Submit and Clear stay in view
     (the stack has no room here; the screen reader still hears every one) */
  .popups {
    left: 50%;
    right: auto;
    bottom: calc(max(8px, env(safe-area-inset-bottom)) + 52px);
    transform: translateX(-50%);
    width: calc(100% - 24px);
  }
  .popup:not(:last-child), .popup span { display: none; }
  .popup { padding: 4px 10px; }
  #screen-results .over-note { display: none; }
  /* the column scrolls itself, above the action area: overflowing a squeezed column ran the lists on
     under Play again (live, 2026-10-15) */
  .vote-main, .res-main { padding: 16px 12px; overscroll-behavior: contain; }
  .vote-slots { flex-direction: column; }
  .res-detail, .res-words { margin-left: 0; }
  .lobby-count { font-size: 72px; }
}
/* the three-way mode switch on phones: compact buttons keep the header on one 48 px row from 320 px up,
   and from 400 px, where the wordmark comes back */
@media (max-width: 439px) {
  .modes button { padding: 6px 8px; font-size: 13px; }
}
