:root{
  --bg:#f4f1ea;--panel:#fff;--ink:#1f2430;--muted:#7b8190;--line:#c9c4b8;--line-strong:#1f2430;
  --accent:#3b6fe0;--accent-soft:#dbe6fb;--peer:#eceae3;--same:#c7d8f7;--sel:#a9c3f5;
  --err:#d93b3b;--err-bg:#fbdcdc;--given:#1f2430;--user:#2f62d0;
  --safe-b:env(safe-area-inset-bottom,0px);
}
@media (prefers-color-scheme:dark){
  :root{--bg:#14161c;--panel:#1d2029;--ink:#e8eaf0;--muted:#8d93a3;--line:#3a3f4d;--line-strong:#c9cdd8;
  --accent:#6b94f0;--accent-soft:#27324f;--peer:#262a36;--same:#33476f;--sel:#3f5a91;
  --err:#ff6b6b;--err-bg:#4a2428;--given:#e8eaf0;--user:#7ea3ff}
}
*{box-sizing:border-box;-webkit-tap-highlight-color:transparent;margin:0;padding:0}
html,body{height:100%}
body{background:var(--bg);color:var(--ink);font:16px/1.2 -apple-system,system-ui,"Segoe UI",Roboto,sans-serif;
  -webkit-user-select:none;user-select:none;touch-action:manipulation;overscroll-behavior:none}
button{font:inherit;color:inherit;border:0;background:none;cursor:pointer;touch-action:manipulation}
.app{max-width:520px;margin:0 auto;min-height:100dvh;display:flex;flex-direction:column;gap:12px;
  padding:max(10px,env(safe-area-inset-top)) 10px calc(10px + var(--safe-b))}
.top{display:flex;align-items:center;justify-content:space-between;gap:8px}
.pill{background:var(--accent);color:#fff;padding:9px 16px;border-radius:999px;font-weight:600}
.stats{display:flex;gap:12px;color:var(--muted);font-size:14px;font-variant-numeric:tabular-nums}
#timer{color:var(--ink);font-weight:600}

.board{display:grid;grid-template-columns:repeat(9,1fr);width:100%;aspect-ratio:1;background:var(--panel);
  border:2px solid var(--line-strong);border-radius:6px;overflow:hidden}
.cell{position:relative;display:flex;align-items:center;justify-content:center;background:var(--panel);
  border-right:1px solid var(--line);border-bottom:1px solid var(--line);
  font-size:clamp(20px,7.2vw,34px);font-weight:500;color:var(--user);contain:layout paint}
.cell.given{color:var(--given);font-weight:700}
.cell:nth-child(9n+3),.cell:nth-child(9n+6){border-right:2px solid var(--line-strong)}
.cell:nth-child(9n){border-right:0}
.cell:nth-child(n+19):nth-child(-n+27),.cell:nth-child(n+46):nth-child(-n+54){border-bottom:2px solid var(--line-strong)}
.cell:nth-child(n+73){border-bottom:0}
.cell.peer{background:var(--peer)}
.cell.same{background:var(--same)}
.cell.sel{background:var(--sel)}
.cell.err{color:var(--err);background:var(--err-bg)}
.notes{position:absolute;inset:0;display:grid;grid-template-columns:repeat(3,1fr);grid-template-rows:repeat(3,1fr);
  font-size:clamp(8px,2.6vw,12px);font-weight:500;color:var(--muted);text-align:center;align-items:center}
.notes b{font-weight:500}
.notes b.hl{color:var(--accent);font-weight:800}

.tools{display:grid;grid-template-columns:repeat(4,1fr);gap:8px}
.tool{display:flex;flex-direction:column;align-items:center;gap:4px;padding:8px 0;border-radius:12px;color:var(--muted);font-size:12px}
.tool i{font-style:normal;font-size:22px;color:var(--ink)}
.tool:active{background:var(--accent-soft)}
.tool[aria-pressed=true]{background:var(--accent-soft);color:var(--accent)}
.tool[aria-pressed=true] i{color:var(--accent)}
.tool:disabled{opacity:.35}

.pad{display:grid;grid-template-columns:repeat(9,1fr);gap:5px}
.num{background:var(--panel);border-radius:10px;padding:10px 0 6px;display:flex;flex-direction:column;align-items:center;gap:2px;
  font-size:clamp(22px,7vw,30px);font-weight:600;color:var(--user);box-shadow:0 1px 0 var(--line)}
.num small{font-size:10px;font-weight:500;color:var(--muted)}
.num:active{background:var(--accent-soft)}
.num.done{opacity:.25;pointer-events:none}

.modal{position:fixed;inset:0;background:rgba(0,0,0,.45);display:flex;align-items:flex-end;justify-content:center;z-index:10}
.modal[hidden]{display:none}
.sheet{background:var(--panel);width:100%;max-width:520px;border-radius:20px 20px 0 0;padding:22px 18px calc(18px + var(--safe-b));
  display:flex;flex-direction:column;gap:12px;text-align:center}
.sheet h2{font-size:22px}
.sheet p{color:var(--muted);min-height:1em}
.levels{display:grid;gap:8px}
.levels button{background:var(--accent);color:#fff;padding:14px;border-radius:12px;font-weight:600;font-size:17px}
.ghost{color:var(--accent);padding:10px;font-weight:600}
.ghost[hidden]{display:none}
@media (max-height:640px){.app{gap:8px}.tool i{font-size:18px}.tool span{display:none}}
