:root {
  --bg: #f7f5f0;
  --paper: #ffffff;
  --ink: #1d2433;
  --muted: #6b7280;
  --line: #d6d3cb;
  --thick: #1d2433;
  --accent: #1f3a5f;
  --accent-ink: #ffffff;
  --sel: #cfe0f5;
  --peer: #eef3f9;
  --same: #e3edf9;
  --given: #1d2433;
  --entry: #2457a6;
  --bad: #c62828;
  --bad-bg: #fde7e7;
  --pattern: #fff1b8;
  --target: #c8efd0;
  --good: #1b7f3b;
  --freeze: #2f74b5;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14181f; --paper: #1c222c; --ink: #e8eaee; --muted: #9aa3b2; --line: #343c49;
    --thick: #c9ced8; --accent: #8fb4e6; --accent-ink: #10151c; --sel: #2c4467; --peer: #222a36;
    --same: #26354b; --given: #e8eaee; --entry: #8fb4e6; --bad: #ff8a80; --bad-bg: #4a2323;
    --pattern: #5a4c17; --target: #1f4a2b; --good: #7fd69b; --freeze: #7fb8ec;
  }
}
:root[data-theme="dark"] {
  --bg: #14181f; --paper: #1c222c; --ink: #e8eaee; --muted: #9aa3b2; --line: #343c49;
  --thick: #c9ced8; --accent: #8fb4e6; --accent-ink: #10151c; --sel: #2c4467; --peer: #222a36;
  --same: #26354b; --given: #e8eaee; --entry: #8fb4e6; --bad: #ff8a80; --bad-bg: #4a2323;
  --pattern: #5a4c17; --target: #1f4a2b; --good: #7fd69b; --freeze: #7fb8ec;
}

* { box-sizing: border-box; }
html { scrollbar-gutter: stable; }
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 18px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
main { max-width: 720px; margin: 0 auto; padding: 8px 16px 32px; }
h1 { font-size: 1.6rem; line-height: 1.2; margin: 0 0 8px; }
h2 { font-size: 1.2rem; margin: 28px 0 10px; }
.muted { color: var(--muted); }
.center { text-align: center; }

.top {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 720px; margin: 0 auto; padding: 12px 16px;
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); font-weight: 700; font-size: 1.15rem; }
.logo { width: 36px; height: 18px; color: var(--accent); }
.top nav { display: flex; align-items: center; gap: 16px; }
.top nav a { text-decoration: none; }
.streak { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; color: var(--accent); }
.streak .logo { width: 24px; height: 12px; }
.freeze { display: inline-flex; align-items: center; gap: 3px; font-weight: 700; color: var(--freeze); cursor: help; }
.flake { width: 16px; height: 16px; flex: none; }
.note.saved { display: flex; gap: 8px; align-items: flex-start; }
.note.saved .flake { color: var(--freeze); margin-top: 4px; }
.foot { text-align: center; color: var(--muted); font-size: .85rem; padding: 24px 16px; }

.btn {
  display: inline-block; border: 0; border-radius: 10px; padding: 10px 18px; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); font: inherit; font-weight: 600; text-decoration: none;
}
.btn.ghost { background: transparent; color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent); }
button.link, a.link { background: none; border: 0; color: var(--accent); font: inherit; font-size: .95rem; cursor: pointer; padding: 0; text-decoration: none; }

/* home */
.hero { padding: 12px 0 4px; }
.date { color: var(--muted); margin: 0 0 4px; font-size: .95rem; }
.lead { color: var(--muted); margin: 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-top: 20px; }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.card h2 { margin: 0; }
.card .done { margin: 0; color: var(--good); font-weight: 600; }
.more { margin-top: 24px; }

/* game */
.levels { width: min(100%, 480px); display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin-bottom: 12px; }
.levels a { text-align: center; padding: 8px 2px; border-radius: 9px; text-decoration: none; color: var(--ink); font-size: .95rem; }
.levels a.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.levels .tick { color: var(--good); font-weight: 700; }
.levels a.on .tick { color: var(--accent-ink); }
.note { width: min(100%, 480px); margin: 0 0 10px; padding: 8px 12px; border-radius: 10px; background: var(--peer); font-size: .95rem; }
.game { display: flex; flex-direction: column; align-items: center; }
.game-head { width: 100%; max-width: 480px; display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.game-head h1 { flex: 1; font-size: 1.15rem; white-space: nowrap; }
.timer { font-variant-numeric: tabular-nums; color: var(--muted); }
.board {
  width: min(100%, 480px); aspect-ratio: 1; display: grid;
  grid-template-columns: repeat(9, 1fr); grid-template-rows: repeat(9, 1fr);
  border: 3px solid var(--thick); background: var(--paper); user-select: none; touch-action: manipulation;
}
.cell {
  position: relative; display: flex; align-items: center; justify-content: center;
  border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  font-size: clamp(20px, 6.2vw, 32px); color: var(--entry); cursor: pointer; outline: none;
}
.cell:nth-child(9n) { border-right: 0; }
.cell:nth-child(n+73) { border-bottom: 0; }
.cell.br { border-right: 2px solid var(--thick); }
.cell.bb { border-bottom: 2px solid var(--thick); }
.cell.given { color: var(--given); font-weight: 600; }
.cell.peer { background: var(--peer); }
.cell.same { background: var(--same); font-weight: 700; }
.cell.sel { background: var(--sel); }
.cell.bad { color: var(--bad); background: var(--bad-bg); }
.cell.pat { background: var(--pattern); }
.cell.tgt { box-shadow: inset 0 0 0 3px var(--good); }
.notes {
  position: absolute; inset: 2px; display: grid; grid-template-columns: repeat(3, 1fr);
  font-size: clamp(9px, 2.4vw, 13px); color: var(--muted); line-height: 1;
}
.notes span { display: flex; align-items: center; justify-content: center; }
.notes span.el { color: var(--bad); text-decoration: line-through; }
.msg { min-height: 1.5em; max-width: 480px; text-align: center; margin: 10px 0 4px; }
.msg.bad { color: var(--bad); }
.pad { width: min(100%, 480px); display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 5px; }
.pad button {
  aspect-ratio: 1 / 1.25; border: 1px solid var(--line); border-radius: 10px; background: var(--paper);
  color: var(--ink); font: inherit; font-size: clamp(20px, 5.5vw, 28px); cursor: pointer; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 0;
}
.pad button small { font-size: .55em; color: var(--muted); }
.pad button.used { opacity: .35; }
.pad.notes-on button { color: var(--muted); }
.tools { width: min(100%, 480px); display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px; margin-top: 10px; }
.tools button {
  border: 1px solid var(--line); border-radius: 10px; background: var(--paper); color: var(--ink);
  font: inherit; font-size: .85rem; padding: 10px 2px; cursor: pointer;
}
.tools button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.tools .hint { font-weight: 700; color: var(--accent); }
.keys { font-size: .8rem; text-align: center; max-width: 480px; }
@media (max-width: 520px) { .keys { display: none; } }

/* review */
.score { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin: 16px 0 6px; }
.score div { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; }
.score b { font-size: 1.35rem; }
.score span { color: var(--muted); font-size: .85rem; }
.counts { color: var(--muted); font-size: .9rem; }
.clean { color: var(--good); font-weight: 600; }
.praise { color: var(--good); font-size: 1.15rem; font-weight: 600; margin: 0 0 4px; }
.moment { display: grid; grid-template-columns: 180px 1fr; gap: 16px; background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.moment h3 { margin: 0 0 6px; }
.kicker { color: var(--muted); font-size: .9rem; margin: 0 0 4px; }
.moment.good h3 { color: var(--good); }
.moment p { margin: 0 0 6px; }
@media (max-width: 520px) { .moment { grid-template-columns: 1fr; } .mini { max-width: 260px; } }
.mini { aspect-ratio: 1; display: grid; grid-template-columns: repeat(9, 1fr); border: 2px solid var(--thick); font-size: 12px; }
.mc { display: flex; align-items: center; justify-content: center; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.mc:nth-child(3n) { border-right: 1px solid var(--thick); }
.mc:nth-child(n+19):nth-child(-n+27), .mc:nth-child(n+46):nth-child(-n+54) { border-bottom: 1px solid var(--thick); }
.mc.pat { background: var(--pattern); }
.mc.tgt { background: var(--target); font-weight: 700; }
.mc s { color: var(--bad); font-size: 10px; }
.next { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 24px; }

.errpage main { display: grid; place-items: center; min-height: 80vh; text-align: center; }

/* technique pages and trainer */
.learn p { max-width: 640px; }
.techs { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.techs a { display: block; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; text-decoration: none; }
.board.static { margin: 8px 0; }
.board.static .cell { cursor: default; }
.notes span.pl { color: var(--good); font-weight: 700; }
.notes span.x { text-decoration: line-through; opacity: .4; }
.notes span.wr { color: var(--bad); background: var(--bad-bg); text-decoration: line-through; }
.explain { font-weight: 600; }
.legend { font-size: .85rem; display: flex; gap: 4px 16px; flex-wrap: wrap; }
.legend > span { display: inline-flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 14px; height: 14px; border-radius: 3px; border: 1px solid var(--line); }
.sw.pat { background: var(--pattern); }
.sw.tgt { box-shadow: inset 0 0 0 3px var(--good); }
.trainer { margin-top: 28px; padding-top: 4px; border-top: 1px solid var(--line); }
.trainer .game-head h2 { flex: 1; margin: 16px 0 4px; }
.trainer .board { outline: none; }
.task { width: min(100%, 480px); margin: 0 0 10px; color: var(--muted); font-size: .95rem; }
.msg.good { color: var(--good); }
.pad button:disabled { opacity: .3; cursor: default; }
.tools.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.tools.four.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.btn.small { padding: 6px 12px; font-size: .9rem; margin-top: 4px; }
.learn-nav { justify-content: center; }
