:root {
  color-scheme: light dark;
  --bg: #f7f2e8;
  --bg-2: #efe6d6;
  --panel: rgba(255, 253, 248, 0.78);
  --panel-solid: #fffdf8;
  --ink: #2a2520;
  --muted: #675d50;
  --line: rgba(42, 37, 32, 0.12);
  --accent: #a64b1f; /* white button text on it is 6.0:1 */
  --accent-deep: #853914;
  --accent-ink: #ffffff;
  --pencil: #a3967f; /* lines still to draw */
  --pen: #e0531c; /* the stroke */
  --pen-soft: rgba(224, 83, 28, 0.42); /* a ×2 line drawn once */
  --dot: #2a2520;
  --dot-done: #b9ad99;
  --good: #2b8a57;
  --warn: #e5822e;
  --bad: #d23f3f;
  --shadow: rgba(80, 50, 20, 0.16);
  --display: Fredoka, 'Arial Rounded MT Bold', system-ui, sans-serif;
  --text: Nunito, system-ui, -apple-system, 'Segoe UI', sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1813;
    --bg-2: #221d17;
    --panel: rgba(48, 42, 34, 0.72);
    --panel-solid: #2a251e;
    --ink: #f1eadf;
    --muted: #b8ad9b;
    --line: rgba(241, 234, 223, 0.12);
    --accent: #f08a4b;
    --accent-deep: #c9682c;
    --accent-ink: #1b1006;
    --pencil: #7a6f60;
    --pen: #ff7a3d;
    --pen-soft: rgba(255, 122, 61, 0.45);
    --dot: #f1eadf;
    --dot-done: #5e564b;
    --good: #5bd394;
    --warn: #ffa25c;
    --bad: #ff7a72;
    --shadow: rgba(0, 0, 0, 0.4);
  }
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  font: 600 16px/1.4 var(--text);
  -webkit-font-smoothing: antialiased;
  background-color: var(--bg);
  /* ruled sketchbook paper */
  background-image:
    linear-gradient(transparent 27px, var(--line) 28px),
    linear-gradient(180deg, var(--bg), var(--bg-2));
  background-size: 100% 28px, 100% 100%;
  background-attachment: fixed;
}
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }

.app {
  width: 100%;
  max-width: 540px;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ---------------------------------------------------------------- header */
.logo { margin: 0; font: 700 2.1rem/1 var(--display); color: var(--accent-deep); letter-spacing: 0.01em; }
@media (prefers-color-scheme: dark) { .logo { color: var(--accent); } }
.day { margin: 4px 0 0; font-size: 0.78rem; color: var(--muted); }

/* ---------------------------------------------------------------- figure tabs */
.play { display: flex; flex-direction: column; gap: 12px; }
.rounds { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.round {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 7px 4px 6px;
  border-radius: 14px;
  border: 1.5px solid var(--line);
  background: var(--panel);
  transition: background 0.15s, border-color 0.15s, transform 0.12s;
}
.round:active { transform: scale(0.97); }
.round small { font-size: 0.68rem; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.round b { font: 600 1.05rem/1.2 var(--display); font-variant-numeric: tabular-nums; }
.round .mark { position: absolute; top: 4px; right: 6px; font-size: 0.75rem; line-height: 1; color: var(--muted); }
.round.on { border-color: var(--accent); background: var(--panel-solid); box-shadow: 0 4px 14px -6px var(--shadow); }

/* ---------------------------------------------------------------- board */
.board {
  padding: 10px 10px 12px;
  border-radius: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 14px 40px -24px var(--shadow);
}
.twist { margin: 0; text-align: center; font-size: 0.78rem; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.figure {
  width: 100%;
  height: auto;
  max-height: min(62vh, 560px);
  margin: 4px auto 0;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  cursor: crosshair;
}
.figure:focus { outline: none; }
.figure:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 12px; }
.figure .pencil { stroke: var(--pencil); stroke-width: 7; stroke-linecap: round; fill: none; }
.figure .ink { stroke: var(--pen); stroke-width: 13; stroke-linecap: round; fill: none; }
.figure .ink.half { stroke: var(--pen-soft); }
.figure .ink.fresh { stroke-dasharray: var(--len) var(--len); animation: draw 0.14s ease-out both; }
@keyframes draw { from { stroke-dashoffset: var(--len); } }
.figure .ink.ghost { stroke-dasharray: 2 18; stroke-width: 7; opacity: 0.8; }
.figure .ink.flash { stroke: var(--bad); stroke-width: 9; opacity: 0; animation: flash 0.5s ease-out; }
@keyframes flash { 0%, 40% { opacity: 0.9; } }
.figure .band { stroke: var(--pen); stroke-width: 5; stroke-dasharray: 10 10; stroke-linecap: round; opacity: 0.55; pointer-events: none; }
.figure .arrow { fill: none; stroke: var(--pencil); stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; }
.figure .arrow.on { stroke: var(--panel-solid); stroke-width: 5; }
.figure .badge circle { fill: var(--panel-solid); stroke: var(--pencil); stroke-width: 5; }
.figure .badge text { font: 700 22px/1 var(--display); fill: var(--ink); text-anchor: middle; dominant-baseline: central; }
.figure .badge.half circle { stroke: var(--pen); }
.figure .dot { fill: var(--dot); transition: fill 0.2s; }
.figure .dot.spent { fill: var(--dot-done); }
.figure .ring { fill: none; stroke: var(--pen); stroke-width: 5; opacity: 0; }
.figure .ring.cur { opacity: 1; }
.figure .ring.cur.pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { stroke-width: 8; } }
.figure .ring.opt { opacity: 0.35; stroke-dasharray: 6 6; }
.figure .ring.kb { opacity: 1; stroke: var(--accent); stroke-dasharray: none; stroke-width: 6; }
.figure .kbline { stroke: var(--accent); stroke-width: 15; stroke-linecap: round; opacity: 0.35; }
.figure.solved .ink { animation: glow 0.9s ease-out; }
@keyframes glow { 30% { stroke-width: 19; } }
.figure.shake { animation: shake 0.36s ease; }
@keyframes shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }

.status { margin: 6px 0 0; min-height: 1.4em; text-align: center; font-size: 0.9rem; color: var(--muted); }
.status b { color: var(--ink); }
.status.stuck { color: var(--bad); }

/* the finished figure */
.outcome { margin-top: 10px; padding-top: 12px; border-top: 1px dashed var(--line); text-align: center; animation: rise 0.3s ease; }
.outcome[hidden] { display: none; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.oc-head { margin: 0; font: 600 1.45rem/1.2 var(--display); }
.oc-mark { margin-right: 8px; }
.oc-sub { margin: 2px 0 0; color: var(--muted); }
.oc-btns { margin-top: 12px; display: flex; justify-content: center; }

/* ---------------------------------------------------------------- tools */
.tools { display: grid; grid-template-columns: auto auto 1fr; gap: 8px; }
.tools[hidden] { display: none; }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.btn.wide { margin-top: 16px; }
.btn.armed { background: var(--warn); border-color: transparent; color: #2a1200; }
.count { min-width: 1.6em; padding: 1px 6px; border-radius: 99px; background: var(--line); font-variant-numeric: tabular-nums; }
.count.some { background: var(--warn); color: #2a1200; }
.btn.reveal { font-size: 0.88rem; }
.foot { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------------------------------------------------------------- dialogs */
@keyframes dlg { from { opacity: 0; transform: scale(0.95); } }
.lead { margin: 0 0 10px; }
.example { width: 100%; max-width: 320px; height: auto; margin: 4px auto 12px; }
.ex-pencil { fill: none; stroke: var(--pencil); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.ex-ink { fill: none; stroke: var(--pen); stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; }
.ex-dots { fill: var(--dot); }
.ex-cur { fill: none; stroke: var(--pen); stroke-width: 3; }
.ex-arrow { fill: none; stroke: var(--pencil); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.ex-badge circle { fill: var(--panel-solid); stroke: var(--pencil); stroke-width: 3; }
.ex-badge text { font: 700 15px/1 var(--display); fill: var(--ink); }
.rules { margin: 0; padding-left: 20px; display: grid; gap: 6px; font-size: 0.95rem; font-weight: 600; }
.week-plan { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 0.92rem; }
.week-plan li { display: grid; grid-template-columns: 5.2em 1fr; gap: 6px; }
.pill { display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 5px; border-radius: 99px; border: 2px solid var(--pencil); font: 700 0.8rem/1 var(--display); vertical-align: -2px; }
.section-h { margin: 14px 0 8px; font-size: 0.72rem; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.rule-note { margin: 10px 0 0; font-size: 0.9rem; }
.keys { margin: 10px 0 0; font-size: 0.82rem; color: var(--muted); line-height: 1.9; }
@media (hover: none) { .keys { display: none; } }
.kicker { color: var(--muted); }
.res-row { margin: 6px 0 10px; text-align: center; font-size: 2rem; letter-spacing: 6px; }
.res-row span { display: inline-block; animation: dlg 0.35s cubic-bezier(0.2, 1.6, 0.4, 1) both; }
.res-table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.res-table th { text-align: left; font-weight: 700; color: var(--muted); padding: 6px 0; }
.res-table td { text-align: right; padding: 6px 0 6px 10px; font-variant-numeric: tabular-nums; }
.res-table td.m { text-align: center; }
.res-table tr + tr { border-top: 1px solid var(--line); }
.res-table tfoot td, .res-table tfoot th { font-weight: 800; color: var(--ink); border-top: 2px solid var(--line); }
.wd.today i { outline: 2px dashed var(--accent); outline-offset: -2px; }
.wd.clean i { background: var(--good); color: #fff; }
.wd.s3 i { background: var(--pen); color: #fff; }
.wd.s2 i { background: color-mix(in srgb, var(--pen) 50%, transparent); }
.wd.s1 i { background: color-mix(in srgb, var(--pen) 25%, transparent); }

.toast { z-index: 10; }

@media (max-width: 380px) {
  .app { padding-left: 12px; padding-right: 12px; }
  .board { padding: 8px 6px 10px; }
  .tools { grid-template-columns: 1fr 1fr; }
  .tools .reveal { grid-column: 1 / -1; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
/* the same for the site-wide Reduce motion setting (hub/prefs.js) */
