:root {
  --bg: #f6f7fb; --card: #fff; --fg: #1b1f2a; --muted: #6b7280; --line: #d9dce6;
  --accent: #2f6feb; --good: #1f9d55; --bad: #e5484d; --tile: #fff7e0; --tile-on: #ffd166; --trail: #2f6feb;
  --dl: #8ecae6; --tl: #4895ef; --dw: #f4a261;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12141a; --card: #1c2029; --fg: #eef0f6; --muted: #9aa2b4; --line: #323847;
    --accent: #6ea0ff; --tile: #2a2f3d; --tile-on: #b8860b; --trail: #6ea0ff; --dl: #2a5d77; --tl: #2d5fa8; --dw: #8a4f1d;
  }
}
:root[data-theme="dark"] {
  --bg: #12141a; --card: #1c2029; --fg: #eef0f6; --muted: #9aa2b4; --line: #323847;
  --accent: #6ea0ff; --tile: #2a2f3d; --tile-on: #b8860b; --trail: #6ea0ff; --dl: #2a5d77; --tl: #2d5fa8; --dw: #8a4f1d;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh; background: var(--bg); color: var(--fg);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  display: grid; justify-items: center; align-items: start;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}
main { width: 100%; max-width: 440px; display: grid; gap: 12px; }
header { display: flex; justify-content: space-between; align-items: center; }
h1 { margin: 0; font-size: 1.6rem; }
h2 { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
#theme { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); font-size: 1.2rem; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { border: 0; background: none; padding: 10px; border-radius: 9px; min-height: 44px; }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; font-size: .85rem; color: var(--muted); }
.stats div { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 6px 4px; }
.stats b { display: block; font-size: 1.4rem; color: var(--fg); font-variant-numeric: tabular-nums; }
#current { margin: 0; text-align: center; font-size: 1.4rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; min-height: 1.8em; }
#current.ok { color: var(--good); }
#current.bad { color: var(--bad); }
#stage { position: relative; aspect-ratio: 1; touch-action: none; user-select: none; -webkit-user-select: none; }
#grid { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.tile {
  position: relative; display: grid; place-items: center; border-radius: 14px; background: var(--tile); border: 1px solid var(--line);
  font-size: clamp(1.9rem, 11vw, 3rem); font-weight: 800; text-transform: uppercase; pointer-events: none;
}
.tile.on { background: var(--tile-on); }
.tile small { position: absolute; right: 6px; bottom: 3px; font-size: .75rem; font-weight: 600; color: var(--muted); }
.tile i { position: absolute; left: 6px; top: 4px; font-style: normal; font-size: .7rem; font-weight: 700; padding: 0 5px; border-radius: 6px; color: #111; }
.tile.dl i { background: var(--dl); } .tile.tl i { background: var(--tl); color: #fff; } .tile.dw i { background: var(--dw); }
#trail { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#trail polyline { fill: none; stroke: var(--trail); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; opacity: .75; }
#overlay { position: absolute; inset: 0; display: grid; place-content: center; gap: 14px; text-align: center; padding: 24px; border-radius: 14px; background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(6px); }
#overlay[hidden] { display: none; }
#overlay p { margin: 0; }
.primary { border: 0; background: var(--accent); color: #fff; border-radius: 12px; min-height: 48px; padding: 0 28px; font-weight: 600; }
#found { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
#found li { background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; font-size: .9rem; }
#found li b { color: var(--accent); margin-left: 4px; }
#summary { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: grid; gap: 6px; }
#summary[hidden] { display: none; }
#summary p { margin: 0; }
#missed { text-transform: uppercase; letter-spacing: .04em; font-size: .9rem; }
.muted { color: var(--muted); font-size: .85rem; }
footer { color: var(--muted); font-size: .8rem; }
footer p { margin: 0; }
footer a { color: var(--accent); }
button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
