:root {
  --bg: #f6f5f2; --fg: #18191b; --muted: #5f6368; --faint: #8a8f96;
  --card: #ffffff; --border: #e4e2dc; --border-strong: #d2cfc7;
  --accent: #2f5bd3; --accent-soft: rgba(47, 91, 211, .09);
  --algo: #d0661f; --algo-soft: rgba(208, 102, 31, .1);
  --win: #1f8a4c; --win-soft: rgba(31, 138, 76, .1); --lose: #c2412d; --star: #e0a100;
  --board: #ffffff; --line: #18191b; --ghost: rgba(24, 25, 27, .16);
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px -12px rgba(0,0,0,.12);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111214; --fg: #ececec; --muted: #a2a6ad; --faint: #757a82;
    --card: #191b1e; --border: #26292d; --border-strong: #353a40;
    --accent: #84a6ff; --accent-soft: rgba(132, 166, 255, .1);
    --algo: #f0965a; --algo-soft: rgba(240, 150, 90, .12);
    --win: #5fcf8e; --win-soft: rgba(95, 207, 142, .12); --lose: #ff8a75; --star: #ffc93c;
    --board: #191b1e; --line: #ececec; --ghost: rgba(236, 236, 236, .16);
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 12px 32px -16px rgba(0,0,0,.6);
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
button { font: inherit; color: inherit; }
main {
  max-width: 560px; margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

.top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
/* Link back to kanealex.com, the same on every app. */
.home {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: .75rem; letter-spacing: .08em; text-transform: uppercase;
  color: var(--faint); text-decoration: none;
}
.home svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; margin-top: -1px; }
.home:hover { color: var(--fg); }
h1 { font-size: clamp(1.6rem, 6vw, 2.1rem); line-height: 1.1; margin: 4px 0 2px; letter-spacing: -0.03em; }
#howToPlayLink { display: inline-block; margin: 2px 0 8px; font-size: .8rem; font-weight: 700; color: var(--accent); text-decoration: none; }
#howToPlayLink:hover { text-decoration: underline; }
.sub { margin: 0; color: var(--muted); font-size: .92rem; }
.top-actions { display: flex; gap: 6px; padding-top: 18px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 11px; border: 1px solid var(--border);
  background: var(--card); display: grid; place-items: center; cursor: pointer; color: inherit;
}
.icon-btn:hover { border-color: var(--border-strong); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Mode buttons, laid out like Semantic Drift's Daily / Practice / Duel tabs. */
.modes { display: flex; gap: 8px; margin-bottom: 14px; }
.modes button {
  flex: 1; padding: 10px; border-radius: 8px; cursor: pointer;
  background: var(--card); border: 1px solid var(--border); color: var(--muted);
  font: inherit; font-size: .95rem; font-weight: 700;
}
.modes button:hover { border-color: var(--border-strong); }
.modes button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .modes button[aria-selected="true"] { color: #0d1020; } }

.mode-bar {
  display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
  margin: -4px 0 14px; padding: 10px 12px; border-radius: 12px; background: var(--card); border: 1px solid var(--border);
}
.mode-bar-main { display: flex; flex-direction: column; min-width: 0; }
.mode-bar-side { display: flex; align-items: center; gap: 10px; }
.level-name { font-weight: 700; }
.goal { color: var(--muted); font-size: .88rem; font-variant-numeric: tabular-nums; }
.goal b { color: var(--fg); }
.goal .over { color: var(--lose); }
.stars { color: var(--star); letter-spacing: 2px; font-size: 1.05rem; }
.stars .off { color: var(--border-strong); }
.btn.small { flex: none; min-height: 34px; padding: 0 12px; font-size: .88rem; border-radius: 10px; }
.segmented { display: inline-flex; gap: 2px; padding: 3px; border: 1px solid var(--border); border-radius: 11px; }
.segmented button { border: 0; background: none; padding: 4px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); font-size: .88rem; font-weight: 600; }
.segmented button[aria-pressed="true"] { background: var(--algo-soft); color: var(--algo); }
.banner {
  margin: 0 0 12px; padding: 12px 14px; border-radius: 12px; background: var(--win-soft); color: var(--fg);
  display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; font-size: .94rem;
}
.banner b { color: var(--win); }
.banner .stars { font-size: 1.15rem; }
.score { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin-bottom: 10px; min-height: 52px; }
.score-main { display: flex; flex-direction: column; }
.score-value { font-size: 2rem; font-weight: 700; letter-spacing: -0.03em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.score-label, .score-side { color: var(--muted); font-size: .85rem; }
.score-side { white-space: nowrap; }
.score-side { text-align: right; font-variant-numeric: tabular-nums; }

.board-wrap { position: relative; }
#board {
  display: block; width: 100%; aspect-ratio: 1; border-radius: 16px;
  background: var(--board); border: 1px solid var(--border); box-shadow: var(--shadow);
  touch-action: none; cursor: crosshair; user-select: none; -webkit-user-select: none;
}
#board.locked { cursor: default; }
.hint { color: var(--faint); font-size: .85rem; margin: 10px 0 14px; text-align: center; min-height: 1.3em; }

.controls { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  flex: 1 1 auto; min-height: 44px; padding: 0 16px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--border); background: var(--card); font-weight: 600;
}
.btn:hover { border-color: var(--border-strong); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; flex-grow: 2; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #0d1020; } }
.btn:disabled { opacity: .45; cursor: default; }

.result {
  margin-top: 14px; padding: 18px; border-radius: 16px;
  background: var(--card); border: 1px solid var(--border); box-shadow: var(--shadow);
}
.result-sub { margin: -6px 0 10px; color: var(--muted); font-size: .92rem; }
.result-sub:empty { display: none; }
.meter { height: 10px; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); overflow: hidden; margin-bottom: 14px; }
.meter-fill { height: 100%; background: var(--win); border-radius: 999px; }
.result h2 { margin: 0 0 12px; font-size: 1.3rem; letter-spacing: -0.02em; }
.result h2.win { color: var(--win); }
.result h2.lose { color: var(--lose); }
.versus { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.side { padding: 10px 12px; border-radius: 12px; display: flex; flex-direction: column; }
.side.you { background: var(--accent-soft); }
.side.other { background: var(--algo-soft); }
.side.other.best { background: var(--win-soft); }
.who { font-size: .8rem; color: var(--muted); font-weight: 600; }
.side .pct { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.side .sub-pct { font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.side.lead { box-shadow: inset 0 0 0 2px currentColor; }
.side.you.lead { color: var(--accent); }
.side.other.lead { color: var(--algo); }
.side.other.best.lead { color: var(--win); }
.side.you .pct { color: var(--accent); }
.side.other .pct { color: var(--algo); }
.side.other.best .pct { color: var(--win); }
#chart { display: block; width: 100%; height: 90px; }
.best { color: var(--muted); font-size: .85rem; margin: 8px 0 12px; }
.views { display: inline-flex; gap: 2px; padding: 3px; border: 1px solid var(--border); border-radius: 11px; margin-bottom: 14px; }
.views button { border: 0; background: none; padding: 4px 14px; border-radius: 8px; cursor: pointer; color: var(--muted); font-size: .88rem; font-weight: 600; }
.views button[aria-pressed="true"] { background: var(--bg); color: var(--fg); }
.next-daily { color: var(--faint); font-size: .85rem; margin: 12px 0 0; text-align: center; }
.next-daily:empty { display: none; }

footer {
  margin-top: 40px; padding-top: 16px; border-top: 1px solid var(--border);
  display: flex; justify-content: space-between; gap: 8px; color: var(--faint); font-size: .88rem;
}
footer a { color: var(--muted); text-decoration: none; }
footer a:hover { color: var(--fg); text-decoration: underline; }

dialog {
  width: min(480px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); overflow: auto;
  border: 1px solid var(--border); border-radius: 16px; padding: 22px;
  background: var(--card); color: var(--fg); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog h2 { margin: 0 0 10px; font-size: 1.25rem; }
dialog h3 { margin: 18px 0 6px; font-size: 1rem; }
dialog p { margin: 0 0 10px; color: var(--muted); font-size: .95rem; }
dialog .btn { width: 100%; margin-top: 8px; }
.levels { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 6px 0 12px; }
.levels button {
  aspect-ratio: 1; border-radius: 12px; border: 1px solid var(--border); background: var(--bg); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-weight: 700; font-size: 1.05rem;
}
.levels button.current { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.levels button:disabled { opacity: .4; cursor: default; }
.levels .stars { font-size: .72rem; letter-spacing: 0; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.dialog-head h2 { margin: 0; }
.close { border: 0; background: none; color: var(--muted); font-size: 1rem; cursor: pointer; padding: 4px 9px; border-radius: 8px; }
.close:hover { color: var(--fg); background: var(--bg); }
.section-label { font-size: .75rem !important; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--faint) !important; margin: 16px 0 8px !important; }
.rank-note { margin: -4px 0 12px; font-size: .92rem; color: var(--fg); }
.rank-note b { color: var(--accent); }
.dist { display: flex; flex-direction: column; gap: 4px; }
.dist-bar { display: grid; grid-template-columns: 7.5em 1fr; align-items: center; gap: 8px; font-size: .8rem; }
.dist-label { color: var(--muted); white-space: nowrap; }
.dist-fill { min-width: 1.6em; height: 20px; border-radius: 4px; display: flex; align-items: center; justify-content: flex-end; padding: 0 6px; box-sizing: border-box; color: #fff; font-weight: 700; font-variant-numeric: tabular-nums; font-size: .75rem; }
.dist-fill.zero { background: var(--border) !important; color: var(--muted); }
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.calendar span { aspect-ratio: 1; border-radius: 4px; background: var(--bg); border: 1px solid var(--border); }
.calendar span.today { outline: 2px solid var(--accent); outline-offset: 1px; }
.cal-legend { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; font-size: .75rem; color: var(--muted); }
.cal-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.name-row { display: flex; gap: 8px; margin: 10px 0; }
.name-row .btn { flex: none; width: auto; margin-top: 0; }
.name-row input {
  flex: 1 1 auto; min-width: 0; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); color: var(--fg); font: inherit; font-size: .9rem;
}
.name-error { color: var(--lose) !important; font-size: .82rem !important; margin: -4px 0 8px !important; }
.board-list { display: flex; flex-direction: column; }
.lb-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 10px; margin: 0 -10px; border-radius: 8px; font-size: .94rem; }
.lb-row.me { background: var(--accent-soft); }
.lb-row .pos { display: inline-block; width: 30px; color: var(--muted); font-weight: 700; font-variant-numeric: tabular-nums; }
.lb-row .pts { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.lb-row .pts span { font-weight: 400; color: var(--muted); font-size: .8rem; }
.lb-row .who-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-divider { border-top: 1px solid var(--border); margin: 6px -10px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 0; text-align: center; }
.stats div { padding: 10px 4px; border-radius: 10px; background: var(--bg); border: 1px solid var(--border); }
.stats b { display: block; font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.stats span { font-size: .75rem; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .82rem; }

.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--fg); color: var(--bg); padding: 8px 16px; border-radius: 999px; font-size: .9rem; font-weight: 600;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* "Today's challenge" row with the streak, Leaderboard and Stats/History,
   shown on Daily only, the same as Semantic Drift. */
.info-row { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 6px 10px; margin: 0 0 12px; }
.info-label { font-size: .8rem; color: var(--muted); }
.info-actions { display: flex; gap: 10px; align-items: center; margin-left: auto; }
.streak { font-size: .85rem; color: var(--muted); white-space: nowrap; }
.toggle-btn {
  background: transparent; border: 0; padding: 0; margin: 0; font-family: inherit;
  font-size: .8rem; font-weight: 700; color: var(--accent); cursor: pointer; white-space: nowrap;
}
.toggle-btn:hover { text-decoration: underline; }
