:root {
  --bg: #f2f3f5; --surface: #ffffff; --ink: #23272e; --muted: #6a7280; --line: #cfd4db; --box: #4a4f57;
  --accent: #1f6fd0; --accent-soft: #cfe0f8; --accent-strong: #a9c7f2; --same: #fbe6a2; --cage: #6f7783;
  --bad: #d33a48; --good: #1f8a52; --pad: #ffffff;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #14171c; --surface: #1c2027; --ink: #e8ebf0; --muted: #98a1ae; --line: #343a44; --box: #aeb6c2;
    --accent: #6ea3f2; --accent-soft: #263a5c; --accent-strong: #35527f; --same: #5a4a17; --cage: #8b95a3;
    --bad: #ff7b87; --good: #5fd497; --pad: #232831; color-scheme: dark; }
}
* { box-sizing: border-box; }
html, body { margin: 0; touch-action: manipulation; }  /* matikan zoom ketuk-dua-kali, pinch tetap boleh */
button, .board { touch-action: manipulation; }
body { background: var(--bg); color: var(--ink); font-family: system-ui, -apple-system, "Segoe UI", sans-serif; -webkit-tap-highlight-color: transparent;
  padding: max(12px, env(safe-area-inset-top)) 12px max(16px, env(safe-area-inset-bottom)); }
button { font: inherit; color: inherit; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.app { max-width: 480px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }
.head { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; }
.streak { text-align: center; font-size: 22px; font-weight: 500; color: var(--muted); }
.streak b { color: var(--accent); font-weight: 600; }
.iconbtn { width: 44px; height: 44px; border-radius: 50%; border: 2px solid var(--ink); background: transparent; display: grid; place-items: center; cursor: pointer; padding: 0; }
.iconbtn svg { width: 22px; height: 22px; fill: none; stroke: var(--ink); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.score { text-align: center; color: var(--accent); font-size: 24px; font-weight: 600; margin-top: 4px; }
.meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }

.boardwrap { position: relative; }
.board { position: relative; width: 100%; aspect-ratio: 1; container-type: inline-size; background: var(--surface); user-select: none; -webkit-user-select: none; touch-action: manipulation; cursor: pointer; }
.cells { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(9, 1fr); grid-template-rows: repeat(9, 1fr); }
.cell { position: relative; overflow: hidden; }
.cell .sum { position: absolute; top: 1.1cqw; left: 1.4cqw; font: 600 2.5cqw/1 system-ui, sans-serif; color: var(--ink); z-index: 1; }
.cell .val { position: absolute; inset: 0; display: grid; place-items: center; padding-top: 1.4cqw; font: 400 6.4cqw/1 system-ui, sans-serif; color: var(--accent); }
.cell.wrong .val { color: var(--bad); }
.cell .notes { position: absolute; left: 1.2cqw; right: 1.2cqw; top: 1.7cqw; bottom: 1.8cqw; display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); font: 500 2.4cqw/1 system-ui, sans-serif; color: var(--muted); }
.cell .notes.withsum { top: 3.3cqw; }
.cell .notes i { font-style: normal; display: grid; place-items: center; }
.cell.cagehl { background: var(--accent-soft); }
.cell.same { background: var(--same); }
.cell.sel { background: var(--accent-strong); }
svg.ov { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
svg.ov .gl { stroke: var(--line); stroke-width: 1.5; }
svg.ov .gb { stroke: var(--box); stroke-width: 4; }
svg.ov rect.frame { fill: none; stroke: var(--box); stroke-width: 5; }
svg.ov .cagel { fill: none; stroke: var(--cage); stroke-width: 2; stroke-dasharray: 5 5; }
.cover { position: absolute; inset: 0; z-index: 5; background: var(--surface); display: flex; flex-direction: column; gap: 14px; align-items: center; justify-content: center; text-align: center; padding: 16px; }
.cover p { margin: 0; font-size: 18px; color: var(--muted); }
.idrow { color: var(--muted); font-size: 14px; }

.tools { display: grid; grid-template-columns: repeat(4, 1fr); margin-top: 6px; }
.tools button { position: relative; background: transparent; border: 0; padding: 8px 0; display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; color: var(--ink); font-size: 14px; }
.tools button:disabled { opacity: 0.4; cursor: default; }
.tools svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tools button[aria-pressed="true"] { color: var(--accent); }
.badge { position: absolute; top: 2px; left: calc(50% + 10px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: #fff; font: 600 11px/18px system-ui, sans-serif; font-style: normal; text-align: center; }

.numpad { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 5px; }
.numpad button { background: var(--pad); border: 0; border-radius: 10px; padding: 8px 0 6px; cursor: pointer; display: flex; flex-direction: column; align-items: center; box-shadow: 0 1px 2px rgba(0,0,0,.12); color: var(--muted); }
.numpad button b { font: 400 min(9vw, 40px)/1.1 system-ui, sans-serif; }
.numpad button small { color: var(--muted); font-size: 13px; }
.numpad button:disabled { opacity: 0.3; cursor: default; }
.numpad button.on { color: var(--ink); background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
.numpad button.blocked { opacity: 0.3; }
.numpad button.on small { color: var(--ink); }

.btn { border: 1px solid var(--line); background: var(--surface); padding: 10px 18px; border-radius: 10px; cursor: pointer; font-weight: 500; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; padding: 16px; z-index: 10; }
.card { background: var(--surface); border-radius: 16px; padding: 22px; width: min(100%, 380px); display: flex; flex-direction: column; gap: 14px; }
.card h2 { margin: 0; font-size: 22px; text-align: center; }
.card p { margin: 0; color: var(--muted); line-height: 1.45; }
.card label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.card input { font: inherit; font-size: 20px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); width: 100%; }
.card .stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; text-align: center; }
.card .stats div { background: var(--bg); border-radius: 10px; padding: 10px 6px; }
.card .stats b { display: block; font-size: 20px; color: var(--ink); }
.card .stats span { font-size: 12px; color: var(--muted); }
.btns { display: flex; gap: 8px; }
.btns .btn { flex: 1; }
