/* ===== Theme: warm paper + gold (light is the default) =====
   All foreground vars tuned to clear WCAG AA (~4.5:1) on --panel. */

/* ---- Light (default) ---- */
:root {
  --bg: #f2efe6; /* warm paper */
  --panel: #fbf9f3; /* board — near-white, pops */
  --panel2: #ebe6d8; /* inputs / buttons / pills */
  --peer: #f4ead0; /* soft gold row/col/box highlight */
  --line: #ddd5c2; /* borders */
  --line-strong: #9a7734; /* gold 3x3 separators */
  --text: #2a2825; /* entered numbers — near-black */
  --muted: #6a6459; /* small text (5.6:1) */
  --accent: #96690a; /* gold — selection / links (4.6:1) */
  --on-accent: #ffffff; /* text on gold fills */
  --given: #17150f; /* clue numbers */
  --correct: #1a7f37; /* green (4.8:1) */
  --wrong: #c62828; /* red (5.3:1) */
  --notes: #6a6459; /* pencil marks */
  --highlight: rgba(150, 105, 10, 0.16); /* same-number tint */
  --celebrate-gold: #b8860b;
}

/* ---- Dark: black + gold ---- */
[data-theme='dark'] {
  --bg: #0e0e11; /* near-black */
  --panel: #18181d; /* charcoal board */
  --panel2: #24242c;
  --peer: #2e2a1a; /* warm dark gold-tint highlight */
  --line: #34343e;
  --line-strong: #c79b3f; /* gold 3x3 separators on black */
  --text: #e7e2d4; /* entered numbers — warm off-white (13.7:1) */
  --muted: #9a9488; /* small text (5.9:1) */
  --accent: #e2b84c; /* bright gold — selection / links (9.4:1) */
  --on-accent: #201a05; /* near-black text on gold fills */
  --given: #f6f0dd; /* clue numbers — bright cream */
  --correct: #55c46e; /* green (8:1) */
  --wrong: #ff6f6f; /* red (6.5:1) */
  --notes: #9a9488;
  --highlight: rgba(226, 184, 76, 0.22);
  --celebrate-gold: #e2b84c;
}

/* ---- Solarized Light (contrast-tuned) ---- */
[data-theme='solarized'] {
  --bg: #eee8d5;
  --panel: #fdf6e3;
  --panel2: #e7dfc6;
  --peer: #dbe7f2;
  --line: #ccc4a8;
  --line-strong: #2aa198;
  --text: #586e75;
  --muted: #5c7278;
  --accent: #1c6ea4; /* solarized blue, darkened for AA on light */
  --on-accent: #ffffff;
  --given: #073642;
  --correct: #1a7f37;
  --wrong: #cb2b28;
  --notes: #5c7278;
  --highlight: rgba(38, 139, 210, 0.18);
  --celebrate-gold: #b58900;
}

/* ---- Solarized Dark (contrast-tuned) ---- */
[data-theme='solarized-dark'] {
  --bg: #002b36;
  --panel: #073642;
  --panel2: #124a5c;
  --peer: #14566b;
  --line: #1c6478;
  --line-strong: #2aa198;
  --text: #93a1a1;
  --muted: #93a8ad;
  --accent: #4ba3dd; /* solarized blue, brightened for dark */
  --on-accent: #002b36;
  --given: #fdf6e3;
  --correct: #3fb950;
  --wrong: #f47068;
  --notes: #93a3ab;
  --highlight: rgba(38, 139, 210, 0.32);
  --celebrate-gold: #b58900;
}

* {
  box-sizing: border-box;
}

:root {
  --board: min(94vw, 540px);
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background 0.25s, color 0.25s;
  /* manipulation = allow pinch-zoom but kill double-tap-to-zoom AND the ~300ms
     tap delay, so taps (incl. notes) feel instant on mobile */
  touch-action: manipulation;
}
* {
  -webkit-tap-highlight-color: transparent; /* no grey flash on tap */
}
.cell,
button,
.board,
.pad {
  touch-action: manipulation;
}
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Floating theme toggle, visible on every screen */
.theme-toggle {
  position: fixed;
  /* keep clear of the notch / Dynamic Island on iOS */
  top: calc(12px + env(safe-area-inset-top));
  right: calc(12px + env(safe-area-inset-right));
  width: auto;
  margin: 0;
  z-index: 50;
  padding: 7px 12px;
  font-size: 0.85rem;
  background: var(--panel);
  border-color: var(--line-strong);
}
/* Theme picker dropdown (anchored under the fixed toggle). */
.theme-menu {
  position: fixed;
  top: calc(48px + env(safe-area-inset-top));
  right: calc(12px + env(safe-area-inset-right));
  z-index: 80;
  min-width: 180px;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 6px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.theme-opt {
  width: 100%;
  margin: 0;
  min-height: 40px;
  text-align: left;
  border: none;
  background: transparent;
  border-radius: 8px;
  font-size: 0.9rem;
}
.theme-opt:hover {
  background: var(--panel2);
  border: none;
}
.theme-opt.active {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  color: var(--accent);
  font-weight: 600;
}

.screen {
  max-width: 980px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

/* Game screen fills the viewport and never scrolls; the board flexes to fit. */
#game.screen {
  max-width: 1120px;
  height: 100vh;
  height: 100dvh;
  /* respect the notch + home indicator on iOS (viewport-fit=cover) */
  padding: calc(8px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right))
    calc(8px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
  position: relative; /* anchors the floating banner overlay */
}
#game .topbar,
#game #banner,
#game #voteBox {
  flex: 0 0 auto;
  margin-bottom: 0;
}
#game .layout {
  flex: 1 1 auto;
  min-height: 0; /* let the board region shrink instead of overflowing */
  align-items: stretch;
  gap: 16px;
  /* Never wrap the game layout: on short screens a wrapping column would push
     the board into a second column off-screen. fitBoard() shrinks it instead. */
  flex-wrap: nowrap;
}
#game .board-area {
  display: flex;
  flex-direction: column;
  justify-content: center; /* keep board + pad together, centered as a group */
  align-items: center;
  gap: 8px;
  min-width: 0;
  min-height: 0;
  flex: 1 1 auto;
}
/* board-wrap shrink-wraps the square board; fitBoard() sizes --board to fit. */
.board-wrap {
  flex: 0 0 auto;
  position: relative;
  line-height: 0;
}

.hidden {
  display: none !important;
}

/* ---------- Home ---------- */
h1 {
  text-align: center;
  margin: 24px 0 4px;
  font-size: 2.2rem;
  letter-spacing: 0.5px;
}
.tagline {
  text-align: center;
  color: var(--muted);
  margin: 0 0 24px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  max-width: 380px;
  margin: 0 auto;
}
.card label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin: 12px 0 4px;
}
.card label .note {
  text-transform: none;
  font-weight: 400;
  opacity: 0.85;
}
.card input,
.card select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--text);
  font-size: 1rem;
}
.card input:focus,
.card select:focus {
  outline: 2px solid var(--accent);
}

/* ---- Auth & account screens ---- */
.auth-wrap {
  max-width: 380px;
  margin: 0 auto;
  padding: 8px 0 24px;
}
.auth-logo {
  text-align: center;
  margin: 8px 0 20px;
}
.auth-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px;
}
.auth-tabs {
  display: flex;
  gap: 6px;
  background: var(--panel2);
  border-radius: 12px;
  padding: 4px;
  margin: 0 0 18px;
}
.auth-tab {
  flex: 1;
  width: auto;
  margin: 0;
  padding: 10px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: 9px;
}
.auth-tab.active {
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.14);
}
.auth-card label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin: 12px 0 4px;
}
.auth-card input {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--text);
  font-size: 1rem;
}
.auth-card input:focus {
  outline: 2px solid var(--accent);
}
.auth-submit {
  width: 100%;
  margin-top: 16px;
}
.auth-guest {
  display: block;
  width: 100%;
  text-align: center;
  margin-top: 14px;
  background: transparent;
  border: none;
  color: var(--muted);
}
.auth-guest:hover {
  color: var(--text);
  border: none;
}
.auth-forgot {
  display: block;
  width: 100%;
  text-align: center;
  margin-top: 12px;
  background: transparent;
  border: none;
  color: var(--accent);
  font-size: 0.9rem;
}
.auth-forgot:hover {
  border: none;
  filter: brightness(1.1);
}
.auth-reset-title {
  margin: 0 0 4px;
}
#acctVerifyRow {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
#acctVerifyRow input {
  flex: 1 1 auto;
  margin-bottom: 0;
  letter-spacing: 3px;
  text-transform: none;
}
#acctVerifyRow button {
  flex: 0 0 auto;
  width: auto;
  margin-top: 0;
}

/* Home account bar */
.acct-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 14px;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 0.9rem;
}
.acct-who {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.acct-who strong {
  color: var(--text);
}
.acct-bar .link-btn {
  flex: 0 0 auto;
  white-space: nowrap;
}
.playing-as {
  margin: 12px 0 4px;
  color: var(--muted);
}
.playing-as strong {
  color: var(--text);
}

/* Account management */
.acct-section {
  border-top: 1px solid var(--line);
  padding-top: 14px;
  margin-top: 14px;
}
.acct-section label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0 0 6px;
}
.auth-card .acct-section input {
  margin-bottom: 8px;
}
#acctName {
  text-transform: none; /* it's a display name, not a room code */
}
.acct-danger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 20px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}
.acct-danger .link-btn {
  flex: 0 0 auto;
  width: auto;
}
.danger-btn {
  flex: 0 0 auto;
  width: auto;
  background: var(--wrong);
  border: 1px solid var(--wrong);
  color: #fff;
  font-weight: 600;
}
.danger-btn:hover {
  filter: brightness(1.06);
  border-color: var(--wrong);
}
.acct-delete-zone {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--wrong);
  border-radius: 12px;
  background: color-mix(in srgb, var(--wrong) 8%, var(--panel));
}
.acct-delete-zone input {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--text);
  margin: 8px 0;
}
.acct-delete-zone .danger-btn {
  width: 100%;
  margin-bottom: 6px;
}
.acct-delete-zone .link-btn {
  display: block;
  width: 100%;
  text-align: center;
}
/* Home one-off success notice reuses #homeError. */
.error.notice {
  color: var(--correct);
}

.divider {
  text-align: center;
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin: 22px 0 6px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}
/* Clear section headers for the home form (replaces faint .divider). */
.section-head {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  margin: 22px 0 8px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
/* Small helper text under a field. */
.field-hint {
  font-size: 0.78rem;
  color: var(--muted);
  margin: 4px 0 2px;
}
/* Room code + Join on one row. */
.join-row {
  display: flex;
  gap: 8px;
}
.join-row input {
  flex: 1 1 auto;
  text-transform: uppercase;
}
.join-row button {
  width: auto;
  flex: 0 0 auto;
  margin-top: 0;
  padding-left: 22px;
  padding-right: 22px;
}
/* Collapsible "Have an account? Sign in". */
details.signin {
  margin-top: 20px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}
details.signin > summary {
  cursor: pointer;
  list-style: none;
  color: var(--accent);
  font-size: 0.9rem;
  padding: 6px 0;
}
details.signin > summary::-webkit-details-marker {
  display: none;
}
details.signin > summary::before {
  content: "▸ ";
}
details.signin[open] > summary::before {
  content: "▾ ";
}
button {
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--text);
  padding: 11px 14px;
  border-radius: 10px;
  font-size: 1rem;
  width: 100%;
  margin-top: 10px;
  transition: 0.15s;
}
button:hover {
  border-color: var(--line-strong);
}
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent); /* readable text on the accent (gold) fill */
  font-weight: 600;
}
button.primary:hover {
  filter: brightness(1.1);
}
.error {
  color: var(--wrong);
  text-align: center;
  min-height: 1.2em;
  margin: 12px 0 0;
}

/* ---------- Game top bar ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.room-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.room-label {
  white-space: nowrap;
}
/* Game action buttons live together; leave room for the fixed theme toggle. */
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: 96px; /* clear the fixed .theme-toggle at top-right */
}
.pill {
  background: var(--panel2);
  border: 1px solid var(--line);
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  text-transform: capitalize;
}
.pill.coop {
  border-color: var(--correct);
  color: var(--correct);
}
.link-btn {
  width: auto;
  margin: 0;
  min-height: 40px; /* comfortable tap target (was ~25px) */
  padding: 8px 14px;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
}
/* Overflow "⋯ More" dropdown menu. */
.more-wrap {
  position: relative;
}
.topmenu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 70;
  min-width: 180px;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 6px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.menu-item {
  width: 100%;
  margin: 0;
  min-height: 44px;
  text-align: left;
  border: none;
  background: transparent;
  border-radius: 8px;
  font-size: 0.95rem;
}
.menu-item:hover {
  background: var(--panel2);
  border: none;
}
.status {
  display: flex;
  gap: 14px;
  align-items: center;
}
.mistakes {
  font-weight: 600;
}
.mistakes.danger {
  color: var(--wrong);
}
.remaining {
  color: var(--muted);
}

/* Floats over the number pad instead of sitting in the flow — showing/hiding
   it must never push the layout, and it must never cover the scoreboard
   (spectators watch that list). Click-transparent, so taps pass through. */
.banner {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  max-width: min(92%, 480px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  background: var(--panel2);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 10px 14px;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}
.banner.win {
  border-color: var(--correct);
  color: var(--correct);
}
.banner.lose {
  border-color: var(--wrong);
  color: var(--wrong);
}

.votebox {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  background: var(--panel2);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 12px;
}
.vote-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.vote-actions button {
  width: auto;
  margin: 0;
}
#voteYes {
  border-color: var(--correct);
  color: var(--correct);
}
#voteNo {
  border-color: var(--wrong);
  color: var(--wrong);
}
.vote-waiting {
  color: var(--muted);
  font-size: 0.85rem;
}

/* ---------- Layout ---------- */
.layout {
  display: flex;
  gap: 24px;
  align-items: flex-start;
  flex-wrap: wrap;
}
/* board-area layout is defined under #game (it fills the play region) */

.timer {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--accent);
}

/* Pause overlay covers the board (and pad) so the board can't be seen. */
.pause-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.pause-overlay .pause-title {
  font-size: 2.4rem;
  margin-bottom: 6px;
}
.pause-overlay p {
  color: var(--muted);
  margin: 0 0 16px;
}
.pause-overlay button {
  width: auto;
  padding: 12px 28px;
  font-size: 1.1rem;
}
.side {
  flex: 0 0 260px;
  min-width: 0;
  min-height: 0;
  overflow: auto; /* scroll the scoreboard internally, page stays put */
}

/* ---------- Board ---------- */
.board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  width: var(--board);
  height: var(--board);
  aspect-ratio: 1 / 1;
  background: var(--line-strong);
  border: 3px solid var(--line-strong);
  border-radius: 8px;
  overflow: hidden;
  gap: 1px;
}
.cell {
  background: var(--panel);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--board) / 16);
  font-weight: 600;
  position: relative;
  cursor: pointer;
  user-select: none;
  color: var(--text);
}
/* thicker lines between 3x3 boxes */
.cell[data-c="2"],
.cell[data-c="5"] {
  border-right: 2px solid var(--line-strong);
}
.cell[data-r="2"],
.cell[data-r="5"] {
  border-bottom: 2px solid var(--line-strong);
}
.cell.given {
  color: var(--given);
  font-weight: 700;
  cursor: default;
}
.cell.correct {
  color: var(--correct);
  font-weight: 600;
}
.cell.wrong {
  color: var(--wrong);
  font-weight: 600;
}
.cell.selected {
  box-shadow: inset 0 0 0 3px var(--accent);
}
.cell.peer {
  background: var(--peer);
}
.cell.samenum::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--highlight);
  pointer-events: none;
}

/* ---------- Celebrations ---------- */
@keyframes cellPop {
  0% { transform: scale(1); }
  35% { transform: scale(1.18); }
  100% { transform: scale(1); }
}
@keyframes cellGlow {
  0% { box-shadow: inset 0 0 0 0 var(--correct); }
  45% { box-shadow: inset 0 0 16px 3px var(--correct); }
  100% { box-shadow: inset 0 0 0 0 var(--correct); }
}
@keyframes cellGlowGold {
  0% { box-shadow: inset 0 0 0 0 var(--celebrate-gold); }
  45% { box-shadow: inset 0 0 22px 5px var(--celebrate-gold); }
  100% { box-shadow: inset 0 0 0 0 var(--celebrate-gold); }
}
/* row / column / box completed */
.cell.celebrate {
  animation: cellPop 0.6s ease, cellGlow 0.7s ease;
  z-index: 2;
}
/* all nine of a digit placed */
.cell.celebrate-num {
  animation: cellPop 0.7s ease, cellGlowGold 0.8s ease;
  z-index: 2;
}

@keyframes padPop {
  0% { transform: scale(1); }
  40% { transform: scale(1.32); }
  100% { transform: scale(1); }
}
.pad .num.pop {
  animation: padPop 0.5s ease;
  border-color: var(--celebrate-gold);
  color: var(--celebrate-gold);
}
/* a fully-placed digit is retired from the pad */
.pad .num.depleted {
  opacity: 0.3;
  text-decoration: line-through;
  cursor: default;
  border-color: var(--correct);
}

/* pencil notes */
.notes {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  font-size: calc(var(--board) / 40);
  color: var(--notes);
  pointer-events: none;
}
.notes span {
  display: flex;
  align-items: center;
  justify-content: center;
}

.board.locked {
  opacity: 0.7;
}
.board.locked .cell {
  cursor: not-allowed;
}

/* ---------- Number pad ---------- */
.pad {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 6px;
  width: var(--board);
  margin: 0 auto;
  flex: 0 0 auto;
}
.pad .num {
  width: auto;
  margin: 0;
  padding: 12px 0;
  font-size: 1.1rem;
}
.pad-controls {
  display: flex;
  gap: 8px;
  width: var(--board);
  margin: 0 auto;
  flex: 0 0 auto;
}
.pad-controls button {
  margin: 0;
  flex: 1 1 0;
  min-width: 0;
  white-space: nowrap;
  padding-left: 4px;
  padding-right: 4px;
}
/* Destructive Clear-notes sits on its own line below the Notes/Erase pair —
   compact and muted, so it isn't a same-size twin one mis-tap from Erase. */
.clear-notes-btn {
  display: block;
  width: auto;
  margin: 8px auto 0;
  padding: 6px 18px;
  font-size: 0.8rem;
  color: var(--muted);
  background: transparent;
}
.clear-notes-btn:hover {
  color: var(--wrong);
  border-color: var(--wrong);
}
#notesToggle.on {
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}

/* ---------- Scoreboard ---------- */
.scoreboard {
  list-style: none;
  padding: 0;
  margin: 0 0 16px;
}
/* Bar offering to settle a game whose opponents have gone away. */
.claim-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  background: var(--peer);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 8px 10px;
  margin: 0 0 12px;
  font-size: 0.85rem;
  color: var(--text);
}
.claim-bar #claimText {
  flex: 1 1 auto;
  min-width: 0;
}
.claim-btn {
  flex: 0 0 auto;
  background: var(--accent);
  color: var(--on-accent);
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  min-height: 40px;
  font-weight: 600;
  cursor: pointer;
}
.claim-btn:hover {
  filter: brightness(1.06);
}
.scoreboard li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer; /* rows are clickable (view stats / watch) */
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  margin-bottom: 6px;
}
.scoreboard li.me {
  border-color: var(--accent);
}
.scoreboard li.dead {
  opacity: 0.55;
}
/* Spectator watch: once you're locked, other players' chips become watchable. */
.scoreboard li.watchable {
  cursor: pointer;
}
.scoreboard li.watchable .pname::after {
  content: ' 👁';
  opacity: 0.55;
  font-size: 0.85em;
}
.scoreboard li.watch-on {
  border-color: var(--correct);
  box-shadow: 0 0 0 1px var(--correct);
  opacity: 1;
}
/* The watched player's cursor moving around the spectated board. */
.cell.watch-cursor {
  box-shadow: inset 0 0 0 3px var(--accent);
}
.scoreboard .pname {
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex: 0 0 auto;
}
.dot.on {
  background: var(--correct);
  box-shadow: 0 0 6px var(--correct);
}
.dot.off {
  background: var(--muted);
  opacity: 0.5;
}
.scoreboard .meta {
  text-align: right;
  font-size: 0.8rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.35;
}
.scoreboard .rem {
  color: var(--text);
  font-weight: 600;
}
.scoreboard .time {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--muted);
}
.scoreboard .time.running {
  color: var(--accent);
}
.scoreboard .sub {
  font-size: 0.78rem;
}
.tag.paused {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--accent);
}
.tag.win {
  background: color-mix(in srgb, var(--celebrate-gold) 22%, transparent);
  color: var(--celebrate-gold);
  font-weight: 700;
}
.elo-up {
  color: var(--correct);
  font-weight: 600;
}
.elo-down {
  color: var(--wrong);
  font-weight: 600;
}
.tag {
  font-size: 0.65rem;
  padding: 1px 7px;
  border-radius: 999px;
}
.tag.done {
  background: color-mix(in srgb, var(--correct) 18%, transparent);
  color: var(--correct);
}
.tag.out {
  background: color-mix(in srgb, var(--wrong) 18%, transparent);
  color: var(--wrong);
}
.hint {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.5;
}
h2 {
  margin: 0 0 10px;
  font-size: 1.1rem;
}

/* ---------- Stats modal ---------- */
.stats-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow: auto;
  padding: 24px 12px;
}
.stats-card {
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  padding: 20px;
  width: min(560px, 96vw);
}
.stats-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.stats-head h2 {
  margin: 0;
  text-transform: capitalize;
}
.stats-head .link-btn {
  width: auto;
  margin: 0;
}
.stats-overview {
  color: var(--muted);
  margin: 4px 0 16px;
}
.stats-card label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin: 12px 0 4px;
}
.stats-card input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--text);
  font-size: 1rem;
}
.stats-card input:focus {
  outline: 2px solid var(--accent);
}
.recent-games {
  margin: 4px 0 16px;
}
.recent-games h3 {
  margin: 0 0 6px;
  font-size: 0.95rem;
}
.recent-games td:nth-child(2) {
  text-transform: capitalize;
}
.rg-win {
  color: var(--correct);
  font-weight: 600;
}
.rg-loss {
  color: var(--muted);
}
/* Solo win recap (results modal reused for a solo finish). */
.solo-time {
  font-size: 1.1rem;
  margin: 0 0 6px;
}
.solo-time b {
  text-transform: capitalize;
}
.solo-note {
  color: var(--accent);
  font-weight: 600;
  margin: 0 0 12px;
}
.solo-stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0 0 14px;
}
.solo-stats span {
  flex: 1 1 auto;
  text-align: center;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  color: var(--muted);
  font-size: 0.85rem;
}
.solo-stats b {
  display: block;
  color: var(--text);
  font-size: 1.05rem;
}
.stats-diff {
  border-top: 1px solid var(--line);
  padding-top: 12px;
  margin-top: 12px;
}
.stats-diff h3 {
  margin: 0 0 2px;
  text-transform: capitalize;
  color: var(--given);
}
.stats-summary {
  color: var(--muted);
  font-size: 0.88rem;
  margin-bottom: 10px;
}
.hist {
  margin: 10px 0;
}
.hist-title {
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 4px;
}
.hist-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 3px;
}
.hist-label {
  flex: 0 0 56px;
  font-size: 0.8rem;
  color: var(--text);
  text-align: right;
}
.hist-bar {
  flex: 1 1 auto;
  background: var(--panel2);
  border-radius: 4px;
  height: 14px;
  overflow: hidden;
}
.hist-bar > span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.3s;
}
.hist-count {
  flex: 0 0 24px;
  font-size: 0.78rem;
  color: var(--muted);
}

/* ---------- Stats page ---------- */
.link-back {
  color: var(--accent);
  text-decoration: none;
}
.stats-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 16px 0;
}
.stats-tab {
  width: auto;
  margin: 0;
  text-transform: capitalize;
  padding: 8px 14px;
}
.stats-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}
table.lb {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
table.lb th,
table.lb td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}
table.lb th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.8rem;
}
table.lb td:first-child,
table.lb th:first-child {
  color: var(--muted);
  width: 2.5em;
}
.lb-row {
  cursor: pointer;
}
.lb-row:hover td {
  background: var(--panel2);
}
.lb-detail td {
  background: var(--panel);
}
/* ---------- Lobby (in-progress games) ---------- */
.games-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.games-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
}
.games-head .link-btn {
  width: auto;
  margin: 0;
  padding: 4px 10px;
  font-size: 0.8rem;
}
.games-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.game-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
}
.game-info {
  min-width: 0;
}
.game-line1 {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.game-code {
  font-weight: 700;
  letter-spacing: 1px;
}
.game-meta {
  font-size: 0.78rem;
  color: var(--muted);
}
.game-names {
  font-size: 0.8rem;
  color: var(--text);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.game-join {
  width: auto;
  margin: 0;
  padding: 8px 16px;
  flex: 0 0 auto;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}

/* ---------- Compare + timeline ---------- */
.cmp-pick {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
}
.cmp-pick select {
  flex: 1 1 auto;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--text);
}
.cmp-pick span {
  color: var(--muted);
}
td.cmp-win {
  color: var(--correct);
  font-weight: 700;
}
.tl-games {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 4px 0 8px;
}
.tl-game {
  width: auto;
  margin: 0;
  padding: 6px 10px;
  font-size: 0.82rem;
}
.tl-chart {
  width: 100%;
  height: 120px;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.tl-track-wrap {
  margin-top: 10px;
}
.tl-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0;
}
.tl-label {
  flex: 0 0 64px;
  font-size: 0.75rem;
  color: var(--muted);
  text-align: right;
}
.tl-track {
  position: relative;
  flex: 1 1 auto;
  height: 14px;
  background: var(--panel2);
  border-radius: 4px;
}
.tl-tick {
  position: absolute;
  top: 1px;
  width: 2px;
  height: 12px;
  border-radius: 1px;
}
.tl-tick.wrong { background: var(--wrong); }
.tl-tick.note { background: var(--accent); }
.tl-tick.sel { background: var(--muted); opacity: 0.5; width: 1px; }

.home-stats-link {
  text-align: center;
  margin: 14px 0 0;
}
.home-stats-link a {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.9rem;
}

/* On narrow screens the sidebar would wrap below the board + pad and players
   never scroll to it — so move the scoreboard ABOVE the board as compact chips. */
@media (max-width: 859px) {
  /* Give the board (nearly) the full width on phones. */
  #game.screen {
    padding: calc(6px + env(safe-area-inset-top)) calc(4px + env(safe-area-inset-right))
      calc(4px + env(safe-area-inset-bottom)) calc(4px + env(safe-area-inset-left));
    gap: 6px;
  }
  #game .topbar {
    margin-bottom: 0;
  }
  #game .layout {
    flex-direction: column;
    gap: 6px;
  }
  /* Scoreboard becomes a compact, horizontally-scrollable strip above the board. */
  .side {
    order: -1;
    flex: 0 0 auto;
    width: 100%;
    overflow: visible;
  }
  .side h2 {
    display: none; /* reclaim vertical space on phones */
  }
  /* Keep a compact how-to-play line on phones (new players need it most). */
  .side .hint {
    margin: 6px 2px 0;
    font-size: 0.72rem;
    text-align: center;
  }
  .scoreboard {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 6px;
    margin: 0;
    padding-bottom: 2px;
  }
  .scoreboard li {
    margin-bottom: 0;
    padding: 5px 9px;
    gap: 6px;
    flex: 0 0 auto;
  }
  .scoreboard .pname {
    font-size: 0.82rem;
  }
  /* keep each chip short: time + remaining inline rather than stacked */
  .scoreboard .meta {
    flex-direction: row;
    align-items: center;
    gap: 6px;
    font-size: 0.72rem;
  }
  /* Few items now (Room + pills on one line; Pause/Leave/⋯ on the next) — no
     more cramped horizontal scroll. */
  .topbar {
    flex-wrap: wrap;
    gap: 6px;
  }
  .topbar-actions {
    margin-right: 0; /* toggle sits on the room-info line, not the actions line */
    flex-wrap: wrap;
  }
  .link-btn {
    white-space: nowrap;
  }
  /* Board up top, number pad in the bottom thumb-zone (slack falls between). */
  #game .board-area {
    justify-content: flex-start;
  }
  #game .pad {
    margin-top: auto;
  }
}

/* ---------- In-DOM dialogs (ui.js — WKWebView-safe confirm / copy) ---------- */
.ui-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.5);
}
.ui-dialog {
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  padding: 20px;
  max-width: 380px;
  width: 100%;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}
.ui-msg {
  margin: 0 0 16px;
  font-size: 1rem;
  line-height: 1.4;
}
.ui-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}
.ui-btn {
  width: auto;
  margin: 0;
  padding: 9px 16px;
}
.ui-copy-input {
  width: 100%;
  margin: 0 0 16px;
  padding: 10px;
  font-size: 0.9rem;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: var(--panel2);
  color: var(--text);
}

/* Short viewports (landscape phones): reclaim the how-to hint's vertical space
   so the board isn't squeezed to a sliver. */
@media (max-height: 520px) {
  .side .hint {
    display: none;
  }
}
