/* Sudoku — blue theme, light + dark */
:root {
  --primary: #2563EB;
  --primary-strong: #1D4ED8;
  --primary-soft: #DBE7FF;
  --on-primary-soft: #0B2A6B;
  --bg: #F4F7FC;
  --surface: #FFFFFF;
  --surface-2: #EEF2F9;
  --surface-3: #E2E8F4;
  --text: #0F172A;
  --muted: #5B6478;
  --line: #CBD5E4;
  --line-strong: #334155;
  --given: #0F172A;
  --entered: #2563EB;
  --wrong: #DC2626;
  --wrong-bg: #FDE7E7;
  --ok: #16A34A;
  --ok-bg: #DCFCE7;
  --cell-sel: #BFD3FF;
  --cell-peer: #E8EFFC;
  --cell-same: #C9DAFF;
  --tip: #F59E0B;
  --tip-bg: #FEF3C7;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 6px 20px rgba(15, 23, 42, .06);
  --r: 18px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --primary: #60A5FA; --primary-strong: #3B82F6; --primary-soft: #1E3A6E; --on-primary-soft: #DBE7FF;
    --bg: #0B1120; --surface: #121A2C; --surface-2: #182238; --surface-3: #22304B; --text: #E5ECF8; --muted: #94A3B8;
    --line: #2A3854; --line-strong: #8EA2C4; --given: #E5ECF8; --entered: #7DB4FF; --wrong: #F87171; --wrong-bg: #3B1520;
    --ok: #4ADE80; --ok-bg: #12321F; --cell-sel: #284A86; --cell-peer: #17233B; --cell-same: #1F3A6A; --tip: #FBBF24; --tip-bg: #3A2E10;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --primary: #60A5FA; --primary-strong: #3B82F6; --primary-soft: #1E3A6E; --on-primary-soft: #DBE7FF;
  --bg: #0B1120; --surface: #121A2C; --surface-2: #182238; --surface-3: #22304B; --text: #E5ECF8; --muted: #94A3B8;
  --line: #2A3854; --line-strong: #8EA2C4; --given: #E5ECF8; --entered: #7DB4FF; --wrong: #F87171; --wrong-bg: #3B1520;
  --ok: #4ADE80; --ok-bg: #12321F; --cell-sel: #284A86; --cell-peer: #17233B; --cell-same: #1F3A6A; --tip: #FBBF24; --tip-bg: #3A2E10;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body { font: 16px/1.5 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; min-height: 100dvh; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--primary); }
svg.i { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2.1; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 46px; padding: 0 22px; border-radius: 14px; border: 0; font-weight: 800; cursor: pointer; transition: transform .1s, background .15s, box-shadow .15s; }
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 6px 18px color-mix(in srgb, var(--primary) 30%, transparent); }
.btn-primary:hover { background: var(--primary-strong); }
:root[data-theme="dark"] .btn-primary { color: #07152F; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn-primary { color: #07152F; } }
.btn-soft { background: var(--primary-soft); color: var(--on-primary-soft); }
.btn-ghost { background: transparent; color: var(--primary); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-block { width: 100%; }
.icon-btn { width: 42px; height: 42px; border-radius: 12px; border: 0; background: transparent; display: grid; place-items: center; cursor: pointer; color: var(--text); }
.icon-btn:hover { background: var(--surface-2); }

/* ---------- Home ---------- */
.home { max-width: 980px; margin: 0 auto; padding: 28px 20px 40px; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.topbar { display: flex; justify-content: flex-end; gap: 6px; }
.lang-pill { display: inline-flex; align-items: center; gap: 6px; height: 38px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 700; font-size: .85rem; }
.hero { text-align: center; padding: 24px 0 26px; }
.hero .logo { width: 84px; height: 84px; border-radius: 24px; box-shadow: 0 14px 36px color-mix(in srgb, var(--primary) 35%, transparent); }
.hero h1 { font-size: 2.6rem; font-weight: 900; letter-spacing: -.03em; margin: 16px 0 4px; }
.hero p { color: var(--muted); margin: 0 auto; max-width: 440px; }
.home-grid { display: grid; grid-template-columns: 1.15fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 820px) { .home-grid { grid-template-columns: 1fr; } }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 24px; padding: 22px; box-shadow: var(--shadow); }
.panel h2 { font-size: 1.05rem; margin: 0 0 14px; font-weight: 800; }
.levels { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.level { position: relative; text-align: left; border: 2px solid var(--line); background: var(--surface); border-radius: 16px; padding: 12px 14px; cursor: pointer; transition: border-color .15s, background .15s; }
.level:hover { border-color: color-mix(in srgb, var(--primary) 50%, var(--line)); }
.level.sel { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 8%, var(--surface)); }
.level strong { display: block; font-size: 1rem; }
.level .dots { display: flex; gap: 3px; margin: 6px 0 4px; }
.level .dots i { width: 14px; height: 5px; border-radius: 3px; background: var(--surface-3); }
.level .dots i.on { background: var(--primary); }
.level small { color: var(--muted); font-size: .78rem; }
.resume-card { display: flex; align-items: center; gap: 14px; padding: 14px; border-radius: 16px; background: var(--primary-soft); color: var(--on-primary-soft); margin-bottom: 12px; cursor: pointer; border: 0; width: 100%; text-align: left; }
.resume-card .mini { width: 48px; height: 48px; flex: none; }
.resume-card strong { display: block; }
.resume-card span { font-size: .85rem; opacity: .85; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.howto li { display: flex; gap: 12px; margin-bottom: 14px; }
.howto ol { list-style: none; padding: 0; margin: 0; }
.howto .n { width: 30px; height: 30px; border-radius: 10px; background: var(--primary-soft); color: var(--on-primary-soft); display: grid; place-items: center; font-weight: 900; flex: none; }
.howto p { margin: 2px 0 0; color: var(--muted); font-size: .92rem; }
.links { display: flex; gap: 8px; flex-wrap: wrap; }
.footer { margin-top: auto; padding-top: 28px; display: flex; justify-content: space-between; align-items: center; gap: 12px; color: var(--muted); font-size: .85rem; flex-wrap: wrap; }
.footer a { color: inherit; text-decoration: none; }
.footer a strong { color: var(--text); }
.version-btn { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 4px 12px; cursor: pointer; font-size: .8rem; color: var(--muted); }

/* ---------- Game ---------- */
.game { max-width: 1040px; margin: 0 auto; padding: 10px 14px 24px; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.game-bar { display: flex; align-items: center; gap: 6px; padding: 4px 0 10px; }
.game-bar .title { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; }
.game-bar .title img { width: 30px; height: 30px; border-radius: 9px; }
.game-bar .title strong { font-size: 1.15rem; font-weight: 900; }
.badge { font-size: .74rem; font-weight: 800; padding: 3px 10px; border-radius: 999px; background: var(--primary-soft); color: var(--on-primary-soft); }
.stats { display: flex; gap: 18px; justify-content: center; color: var(--muted); font-size: .85rem; font-weight: 700; margin-bottom: 10px; }
.stats b { color: var(--text); font-variant-numeric: tabular-nums; }
.game-main { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 22px; align-items: start; }
@media (max-width: 860px) { .game-main { grid-template-columns: 1fr; gap: 14px; } }

.board-wrap { position: relative; width: 100%; max-width: min(620px, calc(100dvh - 300px)); min-width: 280px; margin: 0 auto; }
@media (max-width: 860px) { .board-wrap { max-width: min(560px, 100%); } }
.board { display: grid; grid-template-columns: repeat(9, 1fr); aspect-ratio: 1; background: var(--surface); border: 2.5px solid var(--line-strong); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); user-select: none; touch-action: manipulation; }
.cell { position: relative; border: 0; background: var(--surface); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); display: grid; place-items: center; font-size: clamp(1.1rem, 4.6vw, 1.95rem); font-weight: 700; color: var(--entered); cursor: pointer; padding: 0; transition: background .08s; }
.cell:nth-child(9n) { border-right: 0; }
.cell:nth-child(n+73) { border-bottom: 0; }
.cell.c3, .cell.c6 { border-left: 2px solid var(--line-strong); }
.cell.r3, .cell.r6 { border-top: 2px solid var(--line-strong); }
.cell.given { color: var(--given); font-weight: 800; }
.cell.peer { background: var(--cell-peer); }
.cell.same { background: var(--cell-same); }
.cell.sel { background: var(--cell-sel); }
.cell.conflict, .cell.bad { color: var(--wrong); }
.cell.bad { background: var(--wrong-bg); }
.cell.good { background: var(--ok-bg); }
.cell.tip { box-shadow: inset 0 0 0 3px var(--tip); background: var(--tip-bg); }
.cell.flash-ok { animation: flashOk .9s ease; }
.cell.flash-bad { animation: flashBad .9s ease; }
@keyframes flashOk { 0%, 60% { background: var(--ok-bg); color: var(--ok); } }
@keyframes flashBad { 0%, 60% { background: var(--wrong-bg); } }
.notes { position: absolute; inset: 2px; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); font-size: clamp(.5rem, 1.6vw, .72rem); font-weight: 700; color: var(--muted); line-height: 1; }
.notes span { display: grid; place-items: center; }
.notes span.hl { color: var(--primary); font-weight: 900; }
.board.paused .cell { color: transparent !important; }
.board.paused .notes { visibility: hidden; }
.pause-cover { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; background: color-mix(in srgb, var(--surface) 70%, transparent); backdrop-filter: blur(6px); border-radius: 14px; padding: 20px; }
.pause-cover h3 { margin: 0 0 4px; font-size: 1.4rem; }
.pause-cover p { margin: 0 0 14px; color: var(--muted); }

.side { display: flex; flex-direction: column; gap: 12px; }
.tools { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
@media (min-width: 861px) { .tools { grid-template-columns: repeat(3, 1fr); } }
.tool { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 2px 8px; border: 0; border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); cursor: pointer; font-size: .72rem; font-weight: 800; color: var(--muted); position: relative; border: 1px solid var(--line); }
.tool svg.i { width: 22px; height: 22px; color: var(--text); }
.tool:hover { border-color: color-mix(in srgb, var(--primary) 40%, var(--line)); }
.tool:disabled { opacity: .45; cursor: default; }
.tool.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.tool.on svg.i { color: #fff; }
:root[data-theme="dark"] .tool.on, :root[data-theme="dark"] .tool.on svg.i { color: #07152F; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .tool.on, :root:not([data-theme="light"]) .tool.on svg.i { color: #07152F; } }
.tool .pill { position: absolute; top: 5px; right: 6px; font-size: .58rem; font-weight: 900; background: var(--surface-3); color: var(--muted); border-radius: 999px; padding: 0 5px; }
.tool.on .pill { background: rgba(255,255,255,.25); color: inherit; }
.pad { display: grid; grid-template-columns: repeat(9, 1fr); gap: 6px; }
@media (min-width: 861px) { .pad { grid-template-columns: repeat(3, 1fr); gap: 8px; } }
.key { position: relative; aspect-ratio: 1 / 1.15; border: 1px solid var(--line); background: var(--surface); border-radius: 14px; font-size: clamp(1.3rem, 5vw, 1.8rem); font-weight: 800; color: var(--primary); cursor: pointer; box-shadow: var(--shadow); display: grid; place-items: center; padding: 0; }
@media (min-width: 861px) { .key { aspect-ratio: 1.4; } }
.key:hover { border-color: var(--primary); }
.key small { position: absolute; bottom: 3px; left: 0; right: 0; text-align: center; font-size: .6rem; color: var(--muted); font-weight: 700; }
.key.done { opacity: .35; }
.key.pencil { color: var(--muted); }
.key.choice { border: 2px solid var(--tip); color: var(--text); }
.key.notes-mode { font-size: clamp(1rem, 3.6vw, 1.3rem); }

.tip-card { border-radius: 16px; padding: 14px 16px; background: var(--tip-bg); border: 1px solid color-mix(in srgb, var(--tip) 40%, transparent); }
.tip-card h3 { margin: 0 0 4px; font-size: 1rem; display: flex; align-items: center; gap: 8px; }
.tip-card h3 svg.i { color: var(--tip); }
.tip-card p { margin: 0; font-size: .92rem; }
.tip-card .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 10px; }
.tip-card .btn { height: 38px; padding: 0 14px; font-size: .88rem; }
.choose-card { border-radius: 16px; padding: 12px 14px; background: var(--primary-soft); color: var(--on-primary-soft); font-weight: 700; font-size: .9rem; display: flex; align-items: center; gap: 10px; }

/* ---------- Sheets / dialogs ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(2, 6, 23, .45); animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; } }
.modal .box { width: 100%; max-width: 460px; max-height: calc(100dvh - 32px); overflow: auto; background: var(--surface); border-radius: 24px; padding: 22px; box-shadow: 0 24px 64px rgba(0,0,0,.3); animation: pop .18s ease; }
@keyframes pop { from { transform: translateY(10px) scale(.98); opacity: 0; } }
@media (max-width: 560px) { .modal { align-items: flex-end; padding: 0; } .modal .box { border-radius: 24px 24px 0 0; max-height: 90dvh; padding-bottom: calc(22px + env(safe-area-inset-bottom)); } }
.modal h3 { margin: 0 0 8px; font-size: 1.25rem; font-weight: 900; }
.modal p.muted { color: var(--muted); margin: 0 0 14px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.menu-list { display: flex; flex-direction: column; margin: 0 -8px; }
.menu-list button { display: flex; align-items: center; gap: 14px; width: 100%; border: 0; background: transparent; padding: 12px; border-radius: 12px; cursor: pointer; text-align: left; font-weight: 700; }
.menu-list button:hover { background: var(--surface-2); }
.menu-list button svg.i { color: var(--muted); }
.menu-list hr { border: 0; border-top: 1px solid var(--line); margin: 6px 8px; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; font-weight: 700; cursor: pointer; }
.setting + .setting { border-top: 1px solid var(--line); }
.switch { width: 46px; height: 28px; border-radius: 999px; background: var(--surface-3); position: relative; flex: none; transition: background .2s; }
.switch::after { content: ''; position: absolute; top: 4px; left: 4px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: left .2s; }
.switch.on { background: var(--primary); }
.switch.on::after { left: 22px; }
.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 9px; padding: 7px 6px; font-weight: 800; font-size: .82rem; color: var(--muted); cursor: pointer; }
.seg button.sel { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.rules h4 { margin: 14px 0 2px; }
.rules p { margin: 0; color: var(--muted); }
.release h4 { margin: 12px 0 4px; }
.release ul { margin: 0; padding-left: 18px; color: var(--muted); }
.win-box { text-align: center; }
.win-box .trophy { width: 76px; height: 76px; border-radius: 24px; margin: 4px auto 10px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); }
.win-box .trophy svg.i { width: 40px; height: 40px; }
.win-box .record { display: inline-block; margin-top: 8px; font-weight: 900; color: var(--tip); }
.lang-list button { justify-content: space-between; }

.toast { position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0; pointer-events: none; z-index: 90; background: #0F172A; color: #F1F5F9; padding: 11px 18px; border-radius: 14px; font-weight: 700; font-size: .9rem; transition: all .2s; box-shadow: 0 8px 24px rgba(0,0,0,.25); max-width: calc(100vw - 32px); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok { background: var(--ok); color: #fff; }
.toast.bad { background: var(--wrong); color: #fff; }
.loading { display: grid; place-items: center; min-height: 60vh; color: var(--muted); font-weight: 700; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
