:root {
  --bg: #e9ecf7;
  --surface: #ffffff;
  --ink: #1b1e3a;
  --muted: #5d6285;
  --line: #c4c9e3;
  --key: #d3d8ee;
  --hit: #3e9b5e;
  --near: #d39b22;
  --miss: #7a7f99;
  --red: #c4454d;
  --on-tile: #ffffff;
  --danger: #c2334d;
  --p0: #3f7ef0;
  --p1: #e2559a;
  --p2: #8b5cf6;
  --p3: #0e9f9a;
  --p4: #ee6a2f;
  --font: "Bricolage Grotesque", "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: light;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14172b;
    --surface: #1e2240;
    --ink: #eceefb;
    --muted: #9aa0c4;
    --line: #363c66;
    --key: #4a5080;
    --hit: #48a868;
    --near: #d5a332;
    --miss: #2e3250;
    --red: #d05a62;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: inherit; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.muted { color: var(--muted); }

h1, h2 { line-height: 1.15; margin: 0; }

:focus-visible { outline: 3px solid var(--p0); outline-offset: 2px; }

/* ---------- Buttons & fields ---------- */
.btn {
  font: 600 1rem/1 var(--font);
  border: 2px solid var(--ink);
  background: transparent;
  color: var(--ink);
  padding: 0.85rem 1.2rem;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.08s ease;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--ink); color: var(--bg); }
.btn.ghost { border-color: var(--line); }
.btn.link { border: 0; padding: 0.6rem; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.field { display: grid; gap: 0.35rem; font-weight: 600; }
.field input {
  font: 600 1.1rem var(--font);
  color: var(--ink);
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
  width: 100%;
}
.field input:focus { border-color: var(--ink); outline: none; }
#code-input { text-transform: uppercase; letter-spacing: 0.3em; text-align: center; }
#code-input::placeholder { letter-spacing: normal; text-transform: none; }

.error { color: var(--danger); min-height: 1.5em; font-weight: 600; margin: 0.75rem 0 0; }

/* ---------- Home ---------- */
.screen { min-height: 100%; }

.home { display: grid; place-items: center; padding: 2rem 1.25rem; }
.home-inner { width: 100%; max-width: 560px; }

.logo { display: grid; justify-items: start; gap: 0.2rem; margin-bottom: 1rem; }
.logo-row { display: flex; gap: clamp(4px, 1.2vw, 6px); }
/* leaf-shaped tiles: two round corners, two sharp */
.logo .t {
  font-style: normal;
  display: grid; place-items: center;
  width: clamp(36px, 10.5vw, 56px); aspect-ratio: 1;
  font-size: clamp(1.3rem, 4.8vw, 1.95rem); font-weight: 800;
  color: var(--on-tile); border-radius: 45% 6px 45% 6px;
  animation: logo-flip 0.5s ease both;
}
.logo .t:nth-child(2) { animation-delay: 0.08s; }
.logo .t:nth-child(3) { animation-delay: 0.16s; }
.logo .t:nth-child(4) { animation-delay: 0.24s; }
.logo .t:nth-child(5) { animation-delay: 0.32s; }
.logo .t:nth-child(6) { animation-delay: 0.40s; }
.logo .t:nth-child(7) { animation-delay: 0.48s; }
.logo-sub {
  font-size: clamp(2.6rem, 10vw, 4rem);
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1;
  padding-left: 2px;
}
@keyframes logo-flip { from { transform: rotateX(90deg); } to { transform: none; } }

.lede { font-size: 1.15rem; max-width: 34ch; margin: 0 0 2rem; }

.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 1.5rem; }
.choice {
  display: grid; gap: 0.75rem; align-content: start;
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 1.1rem;
}
.choice h2 { font-size: 1.2rem; }
.choice p { margin: 0; color: var(--muted); font-size: 0.95rem; }
.choice .btn { margin-top: auto; }

@media (max-width: 520px) { .choices { grid-template-columns: 1fr; } }

/* ---------- Lobby ---------- */
.lobby { display: grid; place-items: center; padding: 2rem 1.25rem; }
.lobby-inner { width: 100%; max-width: 420px; display: grid; gap: 1rem; text-align: center; }
.lobby-left { display: grid; gap: 0.45rem; align-content: start; min-width: 0; }
.lobby-left p { margin: 0; }
.lobby-left .btn.link { padding: 0.35rem; }
.lobby-left .btn.ghost { padding: 0.6rem 1rem; }
/* The host sees the settings beside the players, like Rotten and Flipchip; guests get the one compact column */
.lobby-inner.host { max-width: 900px; grid-template-columns: minmax(0, 380px) minmax(0, 1fr); gap: 2.5rem; align-items: start; text-align: left; }
.lobby-inner.host .lobby-left { text-align: center; }
/* Phones and narrow windows: players in two columns to keep the page short */
@media (max-width: 860px) {
  .lobby-players { grid-template-columns: 1fr 1fr; gap: 0.35rem; }
  .lobby-players li { padding: 0.4rem 0.6rem; font-size: 0.95rem; gap: 0.5rem; min-width: 0; }
  .lobby-players li span:nth-child(2) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .lobby-players li.empty { grid-column: 1 / -1; padding: 0.3rem 0.6rem; font-size: 0.85rem; }
  .lobby-players .tag { display: none; }
}
@media (max-width: 860px) { .lobby-inner.host { grid-template-columns: minmax(0, 1fr); max-width: 480px; gap: 0.75rem; } }
.lobby-inner > .muted:first-child { margin: 0; }
.room-code {
  font-size: clamp(2.4rem, 12vw, 3.6rem);
  font-weight: 800;
  letter-spacing: 0.12em;
  line-height: 1;
  margin-top: -0.25rem;
}
.lobby-players { list-style: none; padding: 0; margin: 0.25rem 0; display: grid; gap: 0.4rem; text-align: left; }
.lobby-players li {
  display: flex; align-items: center; gap: 0.75rem;
  background: var(--surface); border: 2px solid var(--line);
  border-radius: 12px; padding: 0.5rem 0.9rem; font-weight: 600;
}
.lobby-players li.empty { border-style: dashed; background: transparent; color: var(--muted); font-weight: 400; }
.lobby-players .tag { margin-left: auto; font-size: 0.85rem; color: var(--muted); font-weight: 400; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; background: var(--line); }

.toggle { display: flex; gap: 0.6rem; align-items: center; justify-content: center; margin-bottom: 1rem; cursor: pointer; }
.toggle input { width: 1.15rem; height: 1.15rem; accent-color: var(--hit); }

.rules { margin: 0; font-weight: 600; }
.public-toggle { margin-bottom: 0.25rem; }
.public-note { margin-bottom: 1rem; }
.small-note { font-size: 0.85rem; margin: 0; }
.win-rule {
  border: 2px solid var(--line); border-radius: 12px;
  padding: 0.6rem 0.9rem 0.75rem; margin: 0 0 1rem;
  display: flex; flex-wrap: wrap; gap: 0.4rem 1.25rem; justify-content: center;
}
.win-rule legend { font-weight: 700; padding: 0 0.35rem; }
.win-rule label { display: flex; align-items: center; gap: 0.4rem; cursor: pointer; }
.win-rule input { width: 1.1rem; height: 1.1rem; accent-color: var(--hit); }

.match-settings { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; margin-bottom: 1rem; text-align: left; }
.select-field { display: grid; gap: 0.35rem; font-weight: 600; }
.select-field select {
  font: 600 1rem var(--font); color: var(--ink); background: var(--surface);
  border: 2px solid var(--line); border-radius: 10px; padding: 0.65rem 0.75rem; width: 100%;
}
.select-field select:focus { border-color: var(--ink); outline: none; }
.crew-field { text-align: left; margin-bottom: 1rem; }
.crew-field label { font-weight: 600; }
.crew-field label .muted { font-weight: 400; font-size: 0.9rem; }
.crew-row { display: flex; gap: 0.5rem; }
.crew-row input { flex: 1; min-width: 0; }
.crew-row .btn { padding: 0.6rem 1rem; }

/* ---------- Game ---------- */
.game { display: flex; flex-direction: column; height: 100%; max-width: 1280px; margin: 0 auto; }

.game-bar {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.6rem 1rem; border-bottom: 2px solid var(--line);
}
.bar-code { white-space: nowrap; }
.bar-code b { letter-spacing: 0.1em; }
#game-round { white-space: nowrap; }
#game-round { margin-right: auto; }
.clock { font-weight: 800; font-variant-numeric: tabular-nums; font-size: 1.1rem; min-width: 3ch; text-align: right; }
.btn.small { padding: 0.4rem 0.7rem; font-size: 0.9rem; }
.clock.urgent { color: var(--danger); }
.final-block { text-align: left; border-top: 2px solid var(--line); padding-top: 0.75rem; }
.sheet-links { display: flex; justify-content: center; gap: 1rem; flex-wrap: wrap; }
.sheet { max-height: calc(100dvh - 2.5rem); overflow-y: auto; }

/* Wide screens: scores | my board | rivals */
.arena {
  /* --rows (how many rows the board has) and --note (height of the line above it) are set by app.js */
  --tile: 60px;
  --tile: max(var(--tile-min, 34px), min(60px, calc((100vh - 310px - var(--note, 0px) - (var(--rows, 6) - 1) * 6px) / var(--rows, 6))));
  --tile: max(var(--tile-min, 34px), min(60px, calc((100dvh - 310px - var(--note, 0px) - (var(--rows, 6) - 1) * 6px) / var(--rows, 6))));
  --mini: min(22px, max(10px, calc((100dvh - 300px - 8px * (var(--rows, 6) - 1)) / (2 * var(--rows, 6)))));
  --mgap: 4px;
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(270px, 320px) auto minmax(0, 1fr);
  grid-template-areas: "scores me rivals";
  align-items: start;
  gap: 2rem;
  padding: 1.25rem 1.5rem;
}
.scoreboard { grid-area: scores; }
.me { grid-area: me; display: flex; flex-direction: column; align-items: center; gap: 1.25rem; }
.rivals {
  grid-area: rivals;
  display: grid;
  grid-template-columns: repeat(2, max-content);
  gap: 1rem;
  align-content: start;
}
@media (min-width: 1100px) { #scores-btn { display: none; } }

.board { display: grid; grid-auto-rows: var(--tile); gap: 6px; }
.row { display: grid; grid-template-columns: repeat(5, var(--tile)); gap: 6px; }
.row.shake { animation: shake 0.4s; }

.tile {
  display: grid; place-items: center;
  font-size: calc(var(--tile) * 0.55); font-weight: 800; text-transform: uppercase;
  border: 2px solid var(--line); border-radius: 6px;
  background: transparent; color: var(--ink);
  user-select: none;
}
.tile.filled { border-color: var(--muted); animation: pop 0.1s; }
.tile.hit, .tile.near, .tile.miss { color: var(--on-tile); border-color: transparent; }
.hit { background: var(--hit); }
.near { background: var(--near); }
.miss { background: var(--miss); }
.tile.flip { animation: flip 0.5s ease; }

@keyframes pop { 50% { transform: scale(1.08); } }
@keyframes flip { 0% { transform: rotateX(0); } 50% { transform: rotateX(90deg); } 100% { transform: rotateX(0); } }
@keyframes shake {
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

/* Rival boards */
.rival {
  --pc: var(--p0);
  display: grid; justify-items: center; gap: 0.45rem;
  padding: 0.9rem 0.9rem 0.7rem;
  border-radius: 14px;
  border: 3px solid var(--pc);
  background: var(--surface);
}
.rival.c1 { --pc: var(--p1); }
.rival.c2 { --pc: var(--p2); }
.rival.c3 { --pc: var(--p3); }
.rival.c4 { --pc: var(--p4); }
.rival.offline { opacity: 0.45; }
.rival-name { font-weight: 800; font-size: 1.05rem; max-width: 12ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rival-status { font-size: 0.9rem; color: var(--muted); }
.rival.solved .rival-status { color: var(--hit); font-weight: 600; }
.mini { display: grid; gap: var(--mgap); }
.mini .mrow { display: grid; grid-template-columns: repeat(5, var(--mini)); gap: var(--mgap); }
.mini i { width: var(--mini); height: var(--mini); border-radius: 4px; border: 2px solid var(--line); }
.mini i.hit, .mini i.near, .mini i.miss, .mini i.red { border-color: transparent; }
.mini .mrow.new i { animation: pop 0.35s ease; }
.mini .mrow.new i:nth-child(2) { animation-delay: 0.05s; }
.mini .mrow.new i:nth-child(3) { animation-delay: 0.10s; }
.mini .mrow.new i:nth-child(4) { animation-delay: 0.15s; }
.mini .mrow.new i:nth-child(5) { animation-delay: 0.20s; }

/* Scoreboard */
.scoreboard {
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 1rem 1rem 1.1rem;
}
.scoreboard h2, .scores-sheet h2 { font-size: 1.15rem; margin-bottom: 0.6rem; }
.scores-empty { color: var(--muted); margin: 0; font-size: 0.95rem; }
.scores-sub, .sheet .scores-sub { font-size: 0.95rem; font-weight: 700; margin: 0 0 0.4rem; color: var(--ink); }
.scores-sub:not(:first-child) { margin-top: 1.25rem; }
.scores-note, .sheet .scores-note { color: var(--muted); font-size: 0.8rem; margin: 0.5rem 0 0; }
.scores { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 0.95rem; }
.scores th {
  font-weight: 600; color: var(--muted); font-size: 0.8rem;
  text-align: right; padding: 0 0.3rem 0.35rem;
}
.scores td { text-align: right; padding: 0.45rem 0.3rem; border-top: 1px solid var(--line); }
.scores th:first-child, .scores td:first-child { text-align: left; padding-left: 0; }
.scores th:last-child, .scores td:last-child { padding-right: 0; }
.scores .pname { display: flex; align-items: center; gap: 0.45rem; font-weight: 700; }
.scores .pname span:last-child { max-width: 8.5rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scores td.wins { font-weight: 800; }
.scores tr.gone { opacity: 0.5; }
.history-title, .sheet .history-title { font-size: 0.95rem; font-weight: 700; margin: 1.1rem 0 0.4rem; color: var(--ink); }
.history { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.3rem; font-size: 0.9rem; color: var(--muted); }
.history b { color: var(--ink); letter-spacing: 0.06em; text-transform: uppercase; }
.sheet.scores-sheet { text-align: left; gap: 0; max-height: calc(100dvh - 2.5rem); overflow-y: auto; }
.scores-sheet .btn { margin-top: 0.75rem; }

/* Keyboard */
.keyboard { display: grid; gap: 6px; width: min(500px, calc(100vw - 1rem)); }
.krow { display: flex; gap: 5px; justify-content: center; }
.key {
  flex: 1 1 0; min-width: 0; height: 56px;
  font: 800 1rem var(--font); text-transform: uppercase;
  border: 0; border-radius: 6px; background: var(--key); color: var(--ink);
  cursor: pointer; touch-action: manipulation;
}
.key.wide { flex: 1.6 1 0; font-size: 0.85rem; text-transform: none; }
.key.hit { background: var(--hit); }
.key.near { background: var(--near); }
.key.miss { background: var(--miss); }
.key.hit, .key.near, .key.miss { color: var(--on-tile); }
.key:active { filter: brightness(0.92); }

/* Tablets: my board | rivals, scores behind the Scores button */
@media (max-width: 1099px) {
  .arena { grid-template-columns: auto auto; grid-template-areas: "me rivals"; justify-content: center; gap: 1.5rem; }
  .scoreboard { display: none; }
  .arena { --mini: min(18px, max(10px, calc((100dvh - 300px - 8px * (var(--rows, 6) - 1)) / (2 * var(--rows, 6))))); --mgap: 3px; }
}

/* Tablets only: Counts and Ladder rows are wider (three boxes, a label), so the tiles stop at 46px to keep the row beside the rivals */
@media (min-width: 761px) and (max-width: 1099px) {
  .keyboard { width: min(500px, calc(100vw - 390px)); }   /* beside the rivals column; it used to push the page 23px too wide at 768px */
  .arena.counts, .arena.ladder { --tile: max(var(--tile-min, 34px), min(46px, calc((100dvh - 310px - var(--note, 0px) - (var(--rows, 6) - 1) * 6px) / var(--rows, 6)))); }
}

/* Phones: rivals in a strip above the board, keyboard at the bottom */
@media (max-width: 760px) {
  .arena {
    --tile: max(var(--tile-min, 32px), min(56px, 11.5vw, calc((100vh - 470px - var(--note, 0px) - (var(--rows, 6) - 6) * 6px) / var(--rows, 6))));
    --tile: max(var(--tile-min, 32px), min(56px, 11.5vw, calc((100dvh - 470px - var(--note, 0px) - (var(--rows, 6) - 6) * 6px) / var(--rows, 6))));
    display: flex; flex-direction: column;
    gap: 0.75rem;
    padding: 0.6rem 0.5rem 0;
  }
  .rivals { order: -1; width: 100%; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
  .me { flex: 1; width: 100%; justify-content: space-between; gap: 0.75rem; }
  .rival {
    grid-template-columns: auto 1fr; grid-template-rows: auto auto;
    justify-items: start; align-items: center;
    column-gap: 0.6rem; row-gap: 0.1rem;
    padding: 0.4rem 0.55rem; border-width: 2px;
  }
  .arena { --mgap: 2px; }
  .rival .mini { grid-row: 1 / 3; --mini: clamp(6px, calc(84px / var(--rows, 6) - 2px), 12px); }
  .rival .mini i { border-width: 1px; border-radius: 2px; }
  .rival-name { font-size: 0.95rem; max-width: 100%; }
  .rival-status { font-size: 0.78rem; line-height: 1.25; }
  .keyboard { padding-bottom: 0.6rem; }
  .key { height: 50px; }
  .game-bar { gap: 0.5rem; padding: 0.5rem 0.75rem; }
}
@media (max-width: 420px) {
  #game-round { display: none; }
  .bar-code { margin-right: auto; }
}
@media (max-height: 700px) and (max-width: 760px) {
  .key { height: 44px; }
}

/* ---------- Overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-items: center; padding: 1.25rem;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  backdrop-filter: blur(4px);
}
.sheet {
  width: 100%; max-width: 400px;
  background: var(--surface); border: 2px solid var(--line);
  border-radius: 18px; padding: 1.5rem;
  display: grid; gap: 0.75rem; text-align: center;
  animation: rise 0.3s ease;
}
.sheet p { margin: 0; }
.sheet h2 { font-size: 1.6rem; }
@keyframes rise { from { transform: translateY(16px); opacity: 0; } }

.reveal-word { display: flex; gap: 5px; justify-content: center; }
.reveal-word i {
  font-style: normal; display: grid; place-items: center;
  width: 46px; height: 46px; border-radius: 6px;
  background: var(--hit); color: var(--on-tile); font-weight: 800; font-size: 1.5rem; text-transform: uppercase;
}

.ranking { list-style: none; padding: 0; margin: 0.5rem 0; display: grid; gap: 0.4rem; text-align: left; counter-reset: rank; }
.ranking li {
  counter-increment: rank;
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.6rem 0.8rem; border-radius: 10px; border: 2px solid var(--line);
}
.ranking li::before { content: counter(rank); font-weight: 800; width: 1.2rem; text-align: center; }
.ranking li.first { border-color: var(--hit); }
.ranking .who { font-weight: 700; }
.ranking .how { margin-left: auto; color: var(--muted); font-size: 0.9rem; font-variant-numeric: tabular-nums; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top, 0px) + 64px);
  transform: translateX(-50%);
  background: var(--ink); color: var(--bg);
  padding: 0.6rem 1rem; border-radius: 10px; font-weight: 700;
  opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 30;
  max-width: calc(100vw - 2rem); text-align: center;
}
.toast.show { opacity: 1; }

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


/* ---------- Accounts, settings, extras ---------- */
.home, .lobby { position: relative; padding-top: 4rem !important; }
.lobby { padding-top: 3rem !important; padding-bottom: 0.5rem; }
.home-top { position: absolute; top: 0.75rem; right: 1rem; }
.account-chip {
  display: flex; align-items: center; gap: 0.5rem;
  font: 600 0.95rem var(--font); color: var(--ink);
  background: var(--surface); border: 2px solid var(--line); border-radius: 999px;
  padding: 0.35rem 0.8rem 0.35rem 0.4rem; cursor: pointer;
}
.account-chip:not(:has(img:not([hidden]))) { padding-left: 0.8rem; }
.avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; flex: none; }
.avatar.big { width: 44px; height: 44px; }
.avatar.tiny { width: 20px; height: 20px; }
.icon-btn {
  font-size: 1.15rem; line-height: 1; padding: 0.35rem 0.45rem;
  background: transparent; color: var(--ink); border: 2px solid var(--line); border-radius: 8px; cursor: pointer;
}
.sheet.settings-sheet { text-align: left; gap: 0; max-width: 440px; }
.settings-sheet h2 { margin-bottom: 0.5rem; }
.set-section { border-top: 2px solid var(--line); padding: 0.9rem 0; display: grid; gap: 0.6rem; }
.set-section .muted { font-size: 0.95rem; }
.account-row { display: flex; align-items: center; gap: 0.75rem; }
.account-who { display: grid; min-width: 0; flex: 1; }
.account-who span { font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toggle.left { justify-content: flex-start; margin: 0; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; }
.stat { background: var(--bg); border-radius: 10px; padding: 0.55rem 0.5rem; text-align: center; }
.stat b { display: block; font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.stat span { font-size: 0.78rem; color: var(--muted); }
.dist { display: grid; gap: 4px; margin-top: 0.4rem; }
.dist-row { display: grid; grid-template-columns: 1rem 1fr; gap: 0.5rem; align-items: center; font-size: 0.85rem; font-weight: 700; }
.dist-bar {
  background: var(--miss); color: var(--on-tile); border-radius: 4px;
  padding: 0.1rem 0.45rem; text-align: right; min-width: 1.6rem; font-variant-numeric: tabular-nums;
}
.dist-bar.top { background: var(--hit); }
.stats-note { font-size: 0.85rem; color: var(--muted); margin: 0.4rem 0 0; }
.meaning { font-size: 0.95rem; text-align: left; background: var(--bg); border-radius: 10px; padding: 0.6rem 0.8rem; }
.meaning i { color: var(--muted); }
.sheet-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.lobby-players .avatar { width: 22px; height: 22px; }

/* High-contrast colors */
body.contrast { --hit: #f5793a; --near: #3b8eea; }

/* Back to the games page (pakdragoon.github.io/office-games) */
.all-games {
  position: absolute; top: 0.75rem; left: 1rem; z-index: 1;
  display: inline-flex; align-items: center; gap: 0.4rem; height: 2.25rem; padding: 0 0.85rem 0 0.7rem;
  font: 700 0.92rem var(--font); color: var(--ink); text-decoration: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
}
.all-games:hover { border-color: var(--ink); }
.all-games svg { width: 1.1rem; height: 1.1rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
@media (max-width: 330px) { .all-games span { display: none; } .all-games { padding: 0 0.6rem; } }

/* Delete my data (built by mountDeleteData in web/shared/cloud.js) */
.delete-data { display: grid; gap: 0.5rem; justify-items: start; margin-top: 0.5rem; padding-top: 0.9rem; border-top: 1px solid var(--line); }
.delete-data .delete-data-btn { border-color: var(--danger); color: var(--danger); }
.delete-data .delete-data-btn.sure { background: var(--danger); border-color: var(--danger); color: #fff; }
.delete-data .delete-data-note { margin: 0; text-align: left; }

/* ---------- Modes: lobby (host settings, same pattern as Rotten and Flipchip) ---------- */
.host-controls { display: grid; gap: 0.7rem; min-width: 0; align-content: start; }
.host-controls .toggle { margin: 0; justify-content: flex-start; }
.mode-pick { border: 1px solid var(--line); border-radius: 12px; margin: 0; padding: 0.3rem 0.8rem 0.55rem; display: flex; flex-wrap: wrap; gap: 0.3rem 1.1rem; justify-content: center; }
.mode-pick legend { font-weight: 700; padding: 0 0.35rem; font-size: 0.9rem; }
.mode-pick label { display: flex; align-items: center; gap: 0.4rem; cursor: pointer; font-weight: 600; }
.mode-pick input { width: 1.1rem; height: 1.1rem; accent-color: var(--hit); }
.mode-blurb { margin: -0.2rem 0 0; min-height: 2.4em; line-height: 1.3; }
.toggle.disabled { opacity: 0.5; cursor: not-allowed; }
.toggle.disabled input { cursor: not-allowed; }
.hard-note { margin: 0; }
.select-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.6rem 0.75rem; text-align: left; }
.select-grid .select-field { font-size: 0.88rem; min-width: 0; }
.select-grid select { font-size: 0.92rem; padding: 0.5rem 0.6rem; min-width: 0; max-width: 100%; }
.select-grid #attempts-field[hidden] { display: none; }
@media (max-width: 340px) { .select-grid { grid-template-columns: minmax(0, 1fr); } }
/* The inside of <details> sits in a ::details-content box that the box-sizing rule at the top can't reach */
details * { box-sizing: border-box; }
.more { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); text-align: left; }
.more summary { cursor: pointer; font-weight: 700; padding: 0.55rem 0.9rem; list-style: none; display: flex; align-items: center; gap: 0.5rem; }
.more summary::-webkit-details-marker { display: none; }
.more summary::before { content: ''; width: 7px; height: 7px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(-45deg); transition: transform 0.15s ease; }
.more[open] summary::before { transform: rotate(45deg); }
.more-body { display: grid; gap: 0.5rem; padding: 0 0.9rem 0.8rem; }
.public-field { text-align: left; }
.public-field .public-note { margin: 0.1rem 0 0 1.75rem; }
.host-controls .crew-field { gap: 0.25rem; }
.host-controls .crew-field label { font-size: 0.92rem; }
.host-controls .crew-row .btn { padding: 0.5rem 0.9rem; }
.host-controls .crew-row input { font-size: 1rem; padding: 0.55rem 0.8rem; }

/* ---------- Modes: the board ---------- */
.board-note { min-height: 1.4rem; margin: 0 0 -0.6rem; font-size: 0.9rem; font-weight: 600; color: var(--muted); text-align: center; }
.board-note[hidden] { display: none; }
.board-note.legend { display: flex; flex-wrap: wrap; gap: 0.2rem 0.9rem; justify-content: center; }
.board-note.legend span { display: inline-flex; align-items: center; gap: 0.35rem; }
.board-note.legend i { width: 0.8rem; height: 0.8rem; border-radius: 3px; display: inline-block; }
.red { background: var(--red); }
.tile.locked { border-color: var(--muted); color: var(--ink); }
.tile.locked.hit { color: var(--on-tile); border-color: transparent; }

/* Counts: three numbers beside each row */
.row.counts { grid-template-columns: repeat(5, var(--tile)) auto; gap: 6px 10px; }
.cboxes { display: flex; gap: 4px; }
.cbox {
  display: grid; place-items: center;
  width: calc(var(--tile) * 0.72); height: var(--tile);
  border-radius: 6px; font-weight: 800; font-size: calc(var(--tile) * 0.5);
  color: var(--on-tile); font-variant-numeric: tabular-nums;
}
.cbox.empty { background: transparent; border: 2px dashed var(--line); }
.cbox.near { color: #1b1e3a; }

/* Word ladder rows: a word plus a small tag (Start, Step 2, Target) */
.row.ladder-row { grid-template-columns: repeat(5, var(--tile)) auto; align-items: center; gap: 6px; }
.ladder-row .tile { height: var(--tile); }
.row-tag { margin-left: 0.4rem; min-width: 4.2rem; font-size: 0.8rem; font-weight: 700; color: var(--muted); }
.ladder-row.start .tile, .ladder-row.goal .tile { border-style: solid; }
.ladder-row.start .tile:not(.hit) { background: var(--bg); }
.ladder-row.goal .tile { border: 2px dashed var(--muted); color: var(--ink); background: transparent; }
.ladder-row.goal .tile { font-weight: 800; }
.ladder-row.blank .tile { opacity: 0.35; border-style: dashed; }

/* Rivals' small boards in Counts: three little boxes per row, five cells wide like Classic */
.mini .mrow.cnt { grid-template-columns: repeat(3, 1fr); width: calc(var(--mini) * 5 + var(--mgap) * 4); }
.mini .mrow.cnt i {
  width: auto; display: grid; place-items: center; font-style: normal; font-weight: 800;
  font-size: calc(var(--mini) * 0.62); line-height: 1; color: var(--on-tile); overflow: hidden;
}
.mini .mrow.cnt i.near { color: #1b1e3a; }
.mini.ladder .mrow i { border-radius: 50%; }
.mini.ladder { margin: 0.2rem 0; }

/* ---------- Modes: results ---------- */
.result-boards { text-align: left; display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0.5rem; border-top: 2px solid var(--line); padding-top: 0.75rem; }
.result-boards .scores-sub, .result-boards .ladder-path { margin: 0; grid-column: 1 / -1; }
.result-board { display: grid; gap: 0.2rem; background: var(--bg); border-radius: 10px; padding: 0.4rem 0.55rem; align-content: start; }
.rb-name { display: flex; align-items: center; gap: 0.45rem; font-weight: 700; }
.rrow { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.rtiles { display: flex; gap: 2px; }
.rtiles i {
  width: 1.3rem; height: 1.3rem; display: grid; place-items: center; font-style: normal;
  font-weight: 800; font-size: 0.75rem; text-transform: uppercase; color: var(--on-tile); border-radius: 4px;
}
.rnums { display: flex; gap: 2px; }
.rnums .cbox { width: 1.15rem; height: 1.3rem; font-size: 0.75rem; border-radius: 4px; }
.chain { margin: 0; font-size: 0.9rem; line-height: 1.8; overflow-wrap: anywhere; }
.chain b { text-transform: uppercase; letter-spacing: 0.05em; }
.chain b.reached { color: var(--hit); }
.ladder-path { display: grid; gap: 0.3rem; }
.stats-mode { margin: 1rem 0 0.4rem; font-size: 0.95rem; }
.stat-grid + .stats-note, .stats-mode:first-child { margin-top: 0.4rem; }

/* Many rows (7 to 10 guesses) and the phone keyboard: smaller keys so everything still fits */
@media (max-width: 760px) {
  .arena.many { --tile-min: 20px; }
  .arena.many .key { height: 38px; }
  .arena.many .me { gap: 0.4rem; }
  .arena.many { gap: 0.45rem; padding-top: 0.4rem; }
  .arena.many .keyboard { gap: 4px; padding-bottom: 0.35rem; }
  .row.counts { gap: 5px 6px; }
  .row.ladder-row { gap: 5px; }
  .row-tag { min-width: 0; font-size: 0.7rem; margin-left: 0.2rem; }
  .board-note { min-height: 1.1rem; font-size: 0.8rem; margin-bottom: -0.7rem; }
}

/* ---------- Counts: my own letter notes (never real results) ----------
   A soft tint, a dashed outline and a small marker, so a note can't be mistaken for the solid colors the server gives. */
button.tile { font-family: inherit; padding: 0; line-height: 1; margin: 0; cursor: default; position: relative; }
button.tile:not(:disabled) { cursor: pointer; touch-action: manipulation; }
button.tile:disabled { opacity: 1; }
button.tile.locked { color: var(--ink); }
.tile.mk1, .tile.mk2, .tile.mk3 { border-style: dashed; border-width: 2px; color: var(--ink); }
.tile.mk1, .key.mk1 { --mk: var(--hit); }
.tile.mk2, .key.mk2 { --mk: var(--near); }
.tile.mk3, .key.mk3 { --mk: var(--red); }
.tile.mk1, .tile.mk2, .tile.mk3 { background: color-mix(in srgb, var(--mk) 26%, var(--surface)); border-color: var(--mk); }
.tile.mk1::after, .tile.mk2::after, .tile.mk3::after, .key.mk1::after, .key.mk2::after, .key.mk3::after {
  position: absolute; top: 1px; right: 2px; font-size: max(8px, calc(var(--tile) * 0.3)); font-weight: 800; line-height: 1; color: var(--mk);
}
.tile.mk1::after, .key.mk1::after { content: '✓'; }
.tile.mk2::after, .key.mk2::after { content: '~'; }
.tile.mk3::after, .key.mk3::after { content: '✕'; }
button.tile:focus-visible, .key:focus-visible { outline: 3px solid var(--p0); outline-offset: 1px; }
.key { position: relative; }
.key.mk1, .key.mk2, .key.mk3 { background: color-mix(in srgb, var(--mk) 26%, var(--key)); outline: 2px dashed var(--mk); outline-offset: -3px; }
.key.mk1::after, .key.mk2::after, .key.mk3::after { font-size: 11px; top: 3px; right: 5px; }
/* Bigger tap area than the small tiles on phones: the invisible 3px halo fills the gaps between tiles */
button.tile:not(:disabled)::before { content: ''; position: absolute; inset: -3px; }

/* ---------- Results: wider on laptops and tablets, standings beside the word, actions pinned ---------- */
.results-sheet { max-width: 560px; padding-bottom: 0; }
.results-sheet.wide { max-width: 720px; }
.results-top { display: grid; gap: 0.75rem; }
.results-hero, .results-standings { display: grid; gap: 0.6rem; align-content: start; min-width: 0; }
@media (min-width: 640px) {
  .results-sheet.wide .results-top, .results-sheet .results-top { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1.25rem; align-items: start; }
}
.results-actions {
  position: sticky; bottom: 0; z-index: 1; display: grid; gap: 0.5rem;
  background: var(--surface); border-top: 2px solid var(--line);
  margin: 0.25rem -1.5rem 0; padding: 0.75rem 1.5rem 1rem;
}
.results-actions [hidden] { display: none; }
.results-actions .sheet-links .btn { padding: 0.35rem 0.6rem; }
@media (min-width: 640px) {
  .results-sheet { padding-left: 1.75rem; padding-right: 1.75rem; }
  .results-actions { margin-left: -1.75rem; margin-right: -1.75rem; padding-left: 1.75rem; padding-right: 1.75rem; }
}
/* Actions in pairs so the pinned bar stays short */
.results-actions { grid-template-columns: 1fr 1fr; gap: 0.4rem 0.5rem; padding-top: 0.6rem; padding-bottom: 0.6rem; }
.results-actions .btn.wide { padding: 0.7rem 0.6rem; }
.results-actions #again-wait, .results-actions .sheet-row, .results-actions .sheet-links { grid-column: 1 / -1; }
.results-actions .sheet-row .btn { padding: 0.6rem 0.6rem; }
.results-actions .sheet-links { gap: 0.5rem 1rem; }
.results-actions .sheet-links .btn { padding: 0.2rem 0.5rem; }
