:root {
  --bg: #b8cab0;        /* medium-light sage — soothing backdrop */
  --panel: #f3f6ee;     /* near-white pale-sage card */
  --panel-2: #e6ecdd;   /* cell wells */
  --line: #c7d4bd;
  --text: #232b22;
  --muted: #5d6b56;
  --accent: #4a8159;
  --accent-dim: #3c6b49;
  --bad: #c14f3c;
  --gold: #a8731a;
  --tent: #d98a3c;
  --radius: 14px;
  --mono: "SF Mono", "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 20px 18px 64px;
}

/* Top bar ----------------------------------------------------------------- */
.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  margin-bottom: 28px;
}
.logo {
  margin: 0;
  text-align: center;
  font-size: 26px;
  letter-spacing: 1px;
  font-weight: 800;
}
.date {
  text-align: right;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.home-btn {
  justify-self: start;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  padding: 6px 4px;
}
.home-btn:hover { color: var(--text); }
.topbar-left { justify-self: start; display: inline-flex; align-items: center; }
.hub-btn { text-decoration: none; }

.view { animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Menu -------------------------------------------------------------------- */
.tagline { text-align: center; color: var(--muted); margin: 0 0 18px; }
.menu-cards { display: grid; gap: 16px; }

.who { text-align: center; color: var(--muted); margin: 0 0 8px; font-size: 13px; }
.name-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text);
  font: inherit;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 6px;
}
.name-btn:hover { background: rgba(0,0,0,.05); }
.name-btn .pencil { color: var(--muted); font-size: 12px; margin-left: 2px; }
.anonymous-toggle { display: inline-flex; align-items: center; gap: 4px; margin-left: 8px; color: var(--muted); font-size: 12px; cursor: pointer; white-space: nowrap; }
.anonymous-toggle input { accent-color: var(--accent); margin: 0; }
.streak {
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(232, 196, 95, .18);
  color: var(--text);
  font-weight: 600;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.menu-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 22px;
  flex-wrap: wrap;
}
.menu-actions .primary-btn, .menu-actions .ghost-btn { margin: 0; }

.mode-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 26px 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  transition: border-color .15s, transform .1s;
  text-align: center;
}
.mode-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.mode-title { font-size: 19px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.mode-badge {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .5px;
  color: var(--accent-dim);
  background: rgba(74, 129, 89, .14);
  border-radius: 999px;
  padding: 2px 8px;
  font-family: var(--mono);
}
.mode-art { display: flex; gap: 6px; align-items: center; }
.art-letter {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-family: var(--mono);
  font-weight: 800;
  font-size: 16px;
  color: var(--accent-dim);
}
.mode-desc { color: var(--muted); font-size: 13px; max-width: 26ch; }
.mode-status { font-size: 12px; color: var(--gold); min-height: 16px; }

/* Rules box (How to play) ------------------------------------------------- */
.rules-toggle .caret { display: inline-block; transition: transform .2s; font-size: 11px; }
.rules-toggle.open .caret { transform: rotate(180deg); }

.rules-box {
  margin-top: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  animation: fade .2s ease;
}
.rules-box h4 { margin: 16px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.rules-goal { margin: 0; font-size: 14px; line-height: 1.5; color: var(--text); }
.rules-box ul { margin: 0; padding-left: 18px; color: var(--muted); font-size: 13px; line-height: 1.7; }
.rules-box b { color: var(--text); }
.legend-blank { color: var(--muted); font-weight: 700; }

/* How-to-play example board */
.rules-diagrams {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 14px;
}
.dia { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.dia figcaption { font-size: 11.5px; color: var(--muted); max-width: 30ch; text-align: center; line-height: 1.35; }
.dia.info figcaption { color: var(--muted); }
.mini-rules-board { max-width: 220px; }

/* Game bar (mode + timer) ------------------------------------------------- */
.gamebar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 14px;
}
.gamebar-left { display: flex; flex-direction: column; gap: 2px; }
.game-mode-label { font-size: 13px; font-weight: 700; color: var(--text); }
.progress-pill { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.countdown {
  font-family: var(--mono);
  font-size: 30px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.rules { color: var(--muted); font-size: 13px; text-align: center; margin: 0 0 16px; }

/* Board --------------------------------------------------------------------
 * Clues sit on all four sides, so the grid is (n+2) x (n+2): a corner, the
 * top clues, a corner on the first row; a left clue, n plot cells, a right
 * clue on each of the next n rows; a corner, the bottom clues, a corner on
 * the last row. The board itself is aspect-square with matching column/row
 * fr tracks, so every cell — plot or clue — comes out square without any
 * per-cell aspect-ratio (that fought the 0.7fr clue tracks: aspect-ratio
 * content can grow a track past its fr share, which is what made clue
 * columns render the same width as plot columns instead of narrower). */
.board {
  --n: 5;
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: 0.7fr repeat(var(--n), 1fr) 0.7fr;
  grid-template-rows: 0.7fr repeat(var(--n), 1fr) 0.7fr;
  gap: 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}
.board, .board * { touch-action: none; -webkit-tap-highlight-color: transparent; }

.cell {
  position: relative;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .1s, border-color .1s, opacity .12s;
}
.cell.plot:hover { border-color: var(--accent); }
.cell.is-blank { background: var(--panel-2); cursor: pointer; color: #9bab8c; }
.cell.is-letter { background: #f6e7d3; border-color: var(--tent); }
.cell.is-question { background: #edf0e7; color: var(--tent); }
.question-mark {
  font-family: var(--mono);
  font-size: 24px;
  font-weight: 800;
  line-height: 1;
}
.board.big .question-mark { font-size: 13px; }
.cell.is-letter.conflict { border-color: var(--bad); box-shadow: inset 0 0 0 2px var(--bad); }
.cell.conflict:not(.is-letter) { border-color: var(--bad); }

/* A selected cell (ready for the letter/? action bar) gets a bold accent ring.
 * Lower specificity than .conflict so a conflict warning still wins visually. */
.cell.selected { box-shadow: inset 0 0 0 3px var(--accent-dim); }

.letter {
  font-family: var(--mono);
  font-weight: 800;
  font-size: 26px;
  color: var(--accent-dim);
}
.board.big .letter { font-size: 18px; }
.glyph { width: 60%; height: 60%; display: block; }
.glyph.blank { color: #9bab8c; }
.cell.is-ansatz .letter, .cell.is-ansatz .glyph.blank, .cell.is-ansatz .question-mark { color: var(--tent); }

/* Clue cells (edge letters) — static, not interactive. */
.clue {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 16px;
  color: var(--muted);
}
.clue.corner { background: none; }

.game-actions { display: flex; justify-content: center; gap: 12px; margin-top: 4px; }
.game-actions .ghost-btn { margin: 20px 0 0; }

/* Bottom action bar (letters / ? / Ansatz) --------------------------------- */
.action-bar {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.action-btn {
  background: var(--accent-dim);
  color: #f3f6ee;
  border: none;
  font-family: var(--mono);
  font-weight: 800;
  font-size: 17px;
  min-width: 44px;
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .15s, opacity .15s, transform .1s;
}
.action-btn:hover:not(:disabled) { background: var(--accent); }
.action-btn:active:not(:disabled) { transform: scale(.97); }
.action-btn:disabled { opacity: .35; cursor: default; }
.ansatz-toggle-btn, .verify-ansatz-btn { font-family: var(--sans); font-size: 14px; font-weight: 700; }
.ansatz-toggle-btn { background: var(--tent); color: #3a2410; }
.verify-ansatz-btn { background: var(--tent); color: #3a2410; }
.discard-ansatz-btn { margin: 0; align-self: center; }

/* Buttons ----------------------------------------------------------------- */
.ghost-btn {
  display: block;
  margin: 20px auto 0;
  background: none;
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 9px 18px;
  border-radius: 10px;
  cursor: pointer;
}
.ghost-btn:hover:not(:disabled) { color: var(--text); border-color: var(--muted); }
.ghost-btn:disabled { opacity: .4; cursor: default; }
.primary-btn {
  background: var(--accent);
  border: none;
  color: #fff;
  font-weight: 700;
  padding: 12px 26px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 15px;
}
.primary-btn:hover { background: #6fc488; }

/* Results ----------------------------------------------------------------- */
#view-results { text-align: center; }
#results-title { font-size: 22px; margin: 8px 0 14px; }
.final-score { font-size: 56px; font-weight: 800; color: var(--gold); font-variant-numeric: tabular-nums; line-height: 1; }
.final-score-label { color: var(--muted); margin-bottom: 22px; }
.solved-board { max-width: 360px; margin: 0 auto 22px; }
.solved-board.big { max-width: 460px; }
.solved-board .cell { cursor: default; }
.result-actions { display: flex; gap: 12px; justify-content: center; }
.result-actions .ghost-btn, .result-actions .primary-btn { margin: 0; }
.copied-toast { color: var(--accent); font-size: 13px; margin-top: 12px; text-align: center; }

/* Leaderboard ------------------------------------------------------------- */
.board-title { text-align: center; font-size: 22px; margin: 8px 0 18px; }
.board-content { display: grid; gap: 22px; margin-bottom: 22px; }
.board-empty { color: var(--muted); font-size: 13px; padding: 6px 0; }
.board-empty-big { text-align: center; padding: 30px 16px; font-size: 15px; }
.board-empty-big small { color: var(--muted); font-size: 12px; }

.board-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.board-panel h3 {
  margin: 0 0 10px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  font-weight: 700;
}
.board-list { list-style: none; padding: 0; margin: 0; }
.board-row {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 10px;
  align-items: baseline;
  padding: 7px 4px;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.board-row:last-child { border-bottom: none; }
.board-row.me { background: rgba(74, 129, 89, .1); border-radius: 6px; }
.board-rank { color: var(--muted); font-size: 13px; text-align: right; }
.board-name { color: var(--text); font-weight: 600; word-break: break-word; }
.board-score { color: var(--accent); font-weight: 700; white-space: nowrap; font-family: var(--mono); }

@media (max-width: 430px) {
  .countdown { font-size: 26px; }
  .clue { font-size: 14px; }
  .board { gap: 3px; padding: 10px; }
  .letter { font-size: 22px; }
}
