:root {
  --bg: #b8cab0;
  --panel: #f3f6ee;
  --panel-2: #e6ecdd;
  --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: 24px; }
.logo { margin: 0; text-align: center; font-size: 25px; letter-spacing: 1px; font-weight: 800; }
.date { text-align: right; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.home-btn { 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 */
.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; }
.tagline { text-align: center; color: var(--muted); margin: 0 0 18px; }
.menu-cards { display: grid; gap: 16px; }
.mode-card { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 24px 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; }
.mode-desc { color: var(--muted); font-size: 13px; max-width: 30ch; }
.mode-status { font-size: 12px; color: var(--gold); min-height: 16px; }
.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; }

/* Rules */
.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-goal { margin: 0 0 12px; font-size: 14px; line-height: 1.5; }
.rules-box ul { margin: 12px 0 0; padding-left: 18px; color: var(--muted); font-size: 13px; line-height: 1.7; }
.rules-box b { color: var(--text); }
.rules-diagram { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.rules-cap { font-size: 12px; color: var(--muted); text-align: center; line-height: 1.4; max-width: 34ch; }

/* Mini staircase (menu art + rules) */
.mini-grid { display: grid; grid-template-columns: repeat(6, 22px); gap: 3px; }
.mini-cell { width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; font-family: var(--mono); font-size: 11px; font-weight: 700; color: var(--muted); }
.mini-cell.b { background: #f2e2cb; border-color: var(--tent); }

/* Game bar */
.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: 18px; }
.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; }
.countdown.urgent { color: var(--bad); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .55; } }

/* Puzzle grid */
.grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; max-width: 380px; margin: 0 auto 18px; }
.gcell { aspect-ratio: 1 / 1; display: flex; align-items: center; justify-content: center; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; font-family: var(--mono); font-weight: 700; font-size: clamp(16px, 5.2vw, 24px); color: var(--text); }
.gcell.blank { background: #f2e2cb; border-color: var(--tent); color: var(--accent-dim); }
.gcell.blank.filled { color: var(--tent); }
.gcell.blank.solved { background: #cfe6c0; border-color: var(--accent); color: var(--accent-dim); }
.gcell.blank.timeout { background: #ecdcc6; border-color: var(--gold); color: var(--gold); }

/* Guess input */
.guess { display: flex; gap: 10px; justify-content: center; align-items: stretch; margin: 0 auto 6px; max-width: 380px; }
.guess-input {
  flex: 1; max-width: 160px; text-align: center; font-family: var(--mono); font-weight: 800;
  font-size: 24px; letter-spacing: 8px; text-transform: uppercase; padding: 8px 10px 8px 18px;
  border: 2px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--text);
}
.guess-input:focus { outline: none; border-color: var(--accent); }
.guess-input.shake { animation: shake .35s; }
@keyframes shake { 0%,100%{transform:translateX(0)} 20%{transform:translateX(-6px)} 40%{transform:translateX(6px)} 60%{transform:translateX(-4px)} 80%{transform:translateX(4px)} }
.guess .primary-btn { margin: 0; }
.guess-msg { text-align: center; font-size: 13px; min-height: 18px; margin: 0 0 8px; color: var(--muted); }
.guess-msg.good { color: var(--accent); font-weight: 700; }
.guess-msg.warn { color: var(--bad); }
.guess-msg.reveal { color: var(--gold); font-weight: 700; }
.game-actions { display: flex; justify-content: center; }

/* Buttons */
.ghost-btn { display: block; margin: 6px 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 22px; border-radius: 10px; cursor: pointer; font-size: 15px; }
.primary-btn:hover { background: #6fc488; }
#next-btn:not([hidden]) { display: block; margin: 10px auto 0; }

/* 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: 20px; font-size: 14px; }
.result-rows { list-style: none; padding: 0; margin: 0 auto 22px; max-width: 260px; }
.result-row { display: flex; justify-content: space-between; align-items: baseline; padding: 8px 6px; border-bottom: 1px solid var(--line); }
.result-row:last-child { border-bottom: none; }
.r-word { font-family: var(--mono); font-weight: 800; letter-spacing: 3px; }
.r-tag { font-size: 12px; }
.r-tag.solved { color: var(--accent); font-weight: 700; }
.r-tag.timeout { color: var(--gold); }
.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: 14px; 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; }
  .grid { gap: 5px; }
  .mini-grid { grid-template-columns: repeat(6, 20px); }
  .mini-cell { width: 20px; height: 20px; }
}
