/* Ledger Sudoku. Calm paper look by default, a soft dark look at night. */
:root {
  --bg: #f5f3ee; --surface: #ffffff; --surface-2: #efece5; --ink: #1d2330; --muted: #6a7180; --line: #e2ded4;
  --accent: #2b5fd9; --accent-ink: #ffffff; --accent-soft: #e6edfd;
  --good: #217a4b; --bad: #c63b3b; --bad-soft: #fde8e6;
  --cell: #ffffff; --grid-thin: #cfcabd; --grid-thick: #3b4150;
  --given: #1d2330; --entry: #2453c7; --mark: #4b5568;
  --sel: #fff1b8; --sel-edge: #e0b52e; --peer: #f1f4f9; --same: #dbe6ff; --cursor: #2b5fd9;
  --cage: #6c7282; --xv-bg: #ffffff;
  --hl-1: #d7d7d7; --hl-2: #f6b6b0; --hl-3: #f7cf9b; --hl-4: #f3e58a; --hl-5: #b9e3a8; --hl-6: #a7ded6; --hl-7: #b3cdf6; --hl-8: #d2bff0; --hl-9: #f2bddb;
  --radius: 14px; --shadow: 0 1px 2px rgba(20, 25, 35, .06), 0 6px 20px rgba(20, 25, 35, .06);
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #16191f; --surface: #1e222a; --surface-2: #262b35; --ink: #e7e5df; --muted: #9aa1ae; --line: #2f3541;
  --accent: #7ea5ff; --accent-ink: #10131a; --accent-soft: #233150;
  --good: #63c48d; --bad: #ff7b72; --bad-soft: #3a2224;
  --cell: #1b1f26; --grid-thin: #363c48; --grid-thick: #aab1c0;
  --given: #e7e5df; --entry: #8db0ff; --mark: #aeb6c4;
  --sel: #4a4120; --sel-edge: #c9a43a; --peer: #222731; --same: #263555; --cursor: #7ea5ff;
  --cage: #9aa1ae; --xv-bg: #1b1f26;
  --hl-1: #4a4d55; --hl-2: #6b3a38; --hl-3: #6e4f2c; --hl-4: #66602c; --hl-5: #3e5d36; --hl-6: #2f5a55; --hl-7: #34496f; --hl-8: #4f3f6b; --hl-9: #6a3b56;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif; -webkit-font-smoothing: antialiased; min-height: 100dvh; }
button, input { font: inherit; color: inherit; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 14px; }
kbd { font: 600 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 2px 5px; background: var(--surface); color: var(--muted); }

/* buttons */
button, .btn, .chip-btn, .icon-btn { cursor: pointer; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 9px 14px; font-weight: 600; text-decoration: none; color: var(--ink); display: inline-flex; align-items: center; justify-content: center; gap: 6px; transition: background .15s, border-color .15s, transform .05s; }
button:hover, .btn:hover, .chip-btn:hover, .icon-btn:hover { border-color: color-mix(in srgb, var(--ink) 25%, var(--line)); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: default; transform: none; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.big { width: 100%; padding: 13px; font-size: 17px; margin-top: 14px; }
button.danger { color: var(--bad); }
button.primary.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
button.quiet { border-color: transparent; color: var(--muted); }
button.link { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 2px; }
.icon-btn { width: 40px; height: 40px; padding: 0; border-radius: 12px; font-size: 18px; text-decoration: none; }
.chip-btn { border-radius: 999px; padding: 7px 12px; font-size: 15px; }
.primary-chip { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.avatar { width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: inline-grid; place-items: center; font-size: 13px; }
.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.row.end { justify-content: flex-end; margin-top: 16px; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 5; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; padding: 10px 16px; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); padding-top: max(10px, env(safe-area-inset-top)); }
.tb-left, .tb-right { display: flex; align-items: center; gap: 8px; }
.tb-title { min-width: 0; }
.gt { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gs { font-size: 13px; }
.brand { display: flex; align-items: center; gap: 9px; text-decoration: none; color: var(--ink); font-weight: 800; font-size: 20px; letter-spacing: .01em; }
.brand img { border-radius: 8px; }
.timer { font-variant-numeric: tabular-nums; min-width: 84px; border-radius: 999px; padding: 7px 12px; }
.timer .pz { font-size: 10px; color: var(--muted); }
.timer.is-paused .pz { color: var(--accent); }

/* home */
.home { max-width: 640px; margin: 0 auto; padding: 18px 16px 40px; display: grid; gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.eyebrow { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.card-title { font-size: 20px; font-weight: 700; }
.continue, .daily-head, .community-card { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.community-card .row { align-items: center; }
.leader { margin-top: 12px; border-top: 1px dashed var(--line); padding-top: 10px; font-size: 15px; }
.leader .mine { font-weight: 700; color: var(--good); margin-bottom: 4px; }
ol.times { margin: 4px 0 0; padding-left: 22px; }
ol.times li { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0; }
ol.times li::marker { color: var(--muted); }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 4px; margin: 6px 0 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 8px 14px; border-radius: 9px; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.seg.small button { padding: 6px 10px; font-size: 14px; }
.blurb { margin: 8px 0 12px; font-size: 15px; }
.pills { display: grid; grid-template-columns: repeat(auto-fit, minmax(72px, 1fr)); gap: 8px; }
.pills button { border-radius: 999px; padding: 8px 16px; }
.pills button.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.stat-row { display: flex; gap: 12px; margin: 8px 0 12px; }
.stat { flex: 1; background: var(--surface-2); border-radius: 12px; padding: 10px 12px; display: grid; }
.stat b { font-size: 24px; line-height: 1.1; }
.stat span { font-size: 13px; color: var(--muted); }
table.best { width: 100%; border-collapse: collapse; font-size: 15px; }
table.best th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 4px 0; }
table.best td { padding: 5px 0; border-top: 1px solid var(--line); }
table.best td:nth-child(n+2), table.best th:nth-child(n+2) { text-align: right; font-variant-numeric: tabular-nums; }
.foot { text-align: center; color: var(--muted); font-size: 14px; padding: 6px 0; }
.foot a { color: var(--muted); }

/* game */
.play { max-width: 1060px; margin: 0 auto; padding: 14px 12px 24px; display: grid; gap: 16px; grid-template-columns: 1fr; justify-items: center; }
@media (min-width: 900px) { .play { grid-template-columns: minmax(0, 1fr) 320px; align-items: start; justify-items: stretch; padding-top: 22px; } }
.board-wrap { width: 100%; max-width: min(92vw, calc(100dvh - 330px), 620px); min-width: min(100%, 300px); }
@media (min-width: 900px) { .board-wrap { max-width: min(640px, calc(100dvh - 140px)); justify-self: end; } }
.info { min-height: 24px; font-size: 14px; color: var(--muted); margin-bottom: 8px; text-align: center; }
.info.status.ok { color: var(--good); font-weight: 600; }
.board-holder { position: relative; }
.board { position: relative; display: grid; grid-template-columns: repeat(9, 1fr); grid-template-rows: repeat(9, 1fr); aspect-ratio: 1; width: 100%; background: var(--cell); border-radius: 6px; container-type: inline-size; touch-action: none; user-select: none; -webkit-user-select: none; outline: none; box-shadow: var(--shadow); }
.board:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 4px; }
.cell { position: relative; cursor: pointer; }
.c-color, .c-value, .c-corner, .c-center { position: absolute; inset: 0; }
.c-color { transition: background .12s; }
.cell.peer .c-color { box-shadow: inset 0 0 0 100cqw var(--peer); }
.cell.same .c-color { box-shadow: inset 0 0 0 100cqw var(--same); }
.cell.sel .c-color { box-shadow: inset 0 0 0 100cqw color-mix(in srgb, var(--sel) 85%, transparent); }
.cell.sel::after { content: ""; position: absolute; inset: 1px; border: 2px solid var(--sel-edge); pointer-events: none; border-radius: 2px; z-index: 3; }
.cell.sel.sel-u::after { border-top-color: transparent; top: -1px; } .cell.sel.sel-d::after { border-bottom-color: transparent; bottom: -1px; }
.cell.sel.sel-l::after { border-left-color: transparent; left: -1px; } .cell.sel.sel-r::after { border-right-color: transparent; right: -1px; }
.cell.cursor::before { content: ""; position: absolute; inset: 3px; border: 2px dashed var(--cursor); border-radius: 3px; z-index: 4; pointer-events: none; opacity: .8; }
.c-value { display: grid; place-items: center; font-size: 6.6cqw; font-weight: 500; color: var(--entry); z-index: 2; font-variant-numeric: tabular-nums; }
.cell.given .c-value { color: var(--given); font-weight: 650; }
.cell.bad .c-value { color: var(--bad); }
.cell.wrong .c-color { box-shadow: inset 0 0 0 100cqw var(--bad-soft); }
.cell.wrong .c-value { color: var(--bad); text-decoration: underline wavy; text-underline-offset: .6cqw; text-decoration-thickness: .25cqw; }
.c-corner { display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); padding: 6% 9%; z-index: 2; }
.c-corner span { font-size: 2.35cqw; line-height: 1; color: var(--mark); font-weight: 600; display: grid; place-items: center; }
.c-center { display: grid; place-items: center; font-size: 2.5cqw; font-weight: 600; color: var(--mark); z-index: 2; letter-spacing: -.02em; text-align: center; padding: 0 4%; word-break: break-all; line-height: 1.05; }
.c-center[data-n="5"], .c-center[data-n="6"] { font-size: 2.05cqw; }
.c-center[data-n="7"], .c-center[data-n="8"], .c-center[data-n="9"] { font-size: 1.7cqw; }
.c-center.hit, .c-corner.hit span { color: var(--accent); }
.has-cages .c-corner { padding-top: 15%; }
svg.lines { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; overflow: visible; }
svg.lines line.thin { stroke: var(--grid-thin); stroke-width: 1; vector-effect: non-scaling-stroke; }
svg.lines line.thick, svg.lines rect.frame { stroke: var(--grid-thick); stroke-width: 2.4; vector-effect: non-scaling-stroke; fill: none; }
svg.lines path.cage { fill: none; stroke: var(--cage); stroke-width: 1.3; stroke-dasharray: 4 3; vector-effect: non-scaling-stroke; }
.overlay { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
.cage-sum { position: absolute; font-size: 2.2cqw; font-weight: 700; line-height: 1; padding: .25cqw .4cqw; margin: .35cqw; background: var(--cell); color: var(--ink); border-radius: 2px; }
.xv-mark { position: absolute; transform: translate(-50%, -50%); width: 3.6cqw; height: 3.6cqw; display: grid; place-items: center; font-size: 2.6cqw; font-weight: 800; color: var(--ink); background: var(--xv-bg); border-radius: 50%; border: 1px solid var(--line); }
.board.solved { animation: glow 1s ease; }
@keyframes glow { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--good) 40%, transparent); } }
.paused { display: none; position: absolute; inset: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 70%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-radius: 6px; place-items: center; text-align: center; font-size: 20px; font-weight: 700; }
.paused.on { display: grid; }

/* controls */
.panel { width: 100%; max-width: min(92vw, 620px); display: grid; gap: 12px; }
@media (min-width: 900px) { .panel { max-width: 320px; position: sticky; top: 90px; } }
.modes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; background: var(--surface-2); border-radius: 14px; padding: 5px; }
.mode { border: 0; background: transparent; padding: 7px 4px 6px; border-radius: 10px; display: grid; justify-items: center; gap: 2px; color: var(--muted); font-size: 13px; }
.mode.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.mode-ico { height: 22px; display: grid; place-items: center; font-weight: 700; }
.mode-ico.normal { font-size: 19px; color: var(--entry); }
.mode-ico.corner { font-size: 11px; letter-spacing: 6px; align-self: start; color: var(--mark); }
.mode-ico.center { font-size: 12px; color: var(--mark); }
.mode-ico.color { width: 20px; height: 20px; border-radius: 6px; background: conic-gradient(var(--hl-2), var(--hl-4), var(--hl-5), var(--hl-7), var(--hl-8), var(--hl-2)); }
.mode kbd { font-size: 10px; padding: 1px 4px; }
.keypad { display: grid; grid-template-columns: repeat(9, 1fr); gap: 6px; }
@media (min-width: 900px) { .keypad { grid-template-columns: repeat(3, 1fr); gap: 8px; } }
.key { aspect-ratio: 1 / 1.08; padding: 0; border-radius: 12px; display: grid; place-items: center; position: relative; }
@media (min-width: 900px) { .key { aspect-ratio: 1.25 / 1; } }
.kd { font-size: 24px; font-weight: 600; line-height: 1; }
@media (min-width: 900px) { .kd { font-size: 30px; } }
.kd.normal { color: var(--entry); }
.kd.corner { font-size: 15px; align-self: start; justify-self: start; margin: 7px 9px; color: var(--mark); }
.kd.center { font-size: 16px; color: var(--mark); }
.key small { position: absolute; bottom: 3px; right: 6px; font-size: 10px; color: var(--muted); font-weight: 600; }
.key.done { opacity: .4; }
.key.swatch { background: var(--sw); border-color: color-mix(in srgb, var(--ink) 12%, transparent); }
.key.swatch span { font-size: 14px; color: color-mix(in srgb, var(--ink) 55%, transparent); }
.actions { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.act { display: grid; justify-items: center; gap: 1px; padding: 8px 2px; font-size: 12px; font-weight: 600; color: var(--muted); }
.act .ico { font-size: 18px; color: var(--ink); line-height: 1.2; }
.tip { font-size: 13px; color: var(--muted); margin: 0; line-height: 1.45; }
.create .panel .actions { grid-template-columns: repeat(4, 1fr); }

/* community */
.community { max-width: 760px; margin: 0 auto; padding: 16px; }
.comm-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.search { flex: 1; min-width: 180px; max-width: 280px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.plist { display: grid; gap: 10px; }
.prow { display: grid; grid-template-columns: 64px 1fr auto; gap: 14px; align-items: center; text-align: left; padding: 12px; font-weight: 400; border-radius: var(--radius); box-shadow: var(--shadow); }
.pinfo { display: grid; min-width: 0; }
.pinfo b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 17px; }
.pinfo .muted { font-size: 14px; }
.rating { font-size: 14px; color: #c48a12; font-weight: 600; }
.badge { font-size: 13px; font-weight: 700; padding: 4px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.badge.good { background: color-mix(in srgb, var(--good) 15%, transparent); color: var(--good); }
.mini { display: grid; grid-template-columns: repeat(9, 1fr); width: 64px; aspect-ratio: 1; gap: 1px; background: var(--grid-thin); border: 2px solid var(--grid-thick); border-radius: 3px; }
.mini i { background: var(--cell); }
.mini i.f { background: var(--ink); opacity: .75; }
.more { width: 100%; margin-top: 12px; }
.empty { text-align: center; padding: 30px 10px; }
.psheet-top { display: grid; grid-template-columns: 110px 1fr; gap: 16px; align-items: start; }
.psheet-top .mini { width: 110px; }
.psheet p { margin: 0 0 6px; }
.psheet h3 { margin: 16px 0 4px; font-size: 15px; }
.good-text { color: var(--good); font-weight: 700; }

/* dialogs */
.backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(10, 14, 22, .42); display: grid; place-items: center; padding: 16px; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.dialog { background: var(--surface); color: var(--ink); border-radius: 18px; width: 100%; max-width: 440px; max-height: calc(100dvh - 32px); overflow: auto; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); animation: pop .18s ease; }
.dialog.wide { max-width: 560px; }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 4px; }
.dialog-head h2 { margin: 0; font-size: 20px; }
.dialog-head .icon-btn { width: 34px; height: 34px; border: 0; font-size: 16px; color: var(--muted); }
.dialog-body { padding: 6px 18px 20px; }
.field { display: grid; gap: 4px; margin-bottom: 12px; font-size: 14px; font-weight: 600; flex: 1; }
.field input { font-weight: 400; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); font-size: 16px; }
.field input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
form > button.primary { width: 100%; padding: 12px; }
.err { color: var(--bad); font-size: 14px; min-height: 1em; margin: 0 0 8px; }
.err:empty { display: none; }
.auth-links { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: 12px; font-size: 14px; }
.or { margin-top: 14px; display: grid; gap: 10px; text-align: center; font-size: 13px; color: var(--muted); }
.google { width: 100%; }
.google b { color: #4285f4; }
.settings { display: grid; gap: 4px; }
.set { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.set span { display: grid; }
.set small { color: var(--muted); font-size: 13px; }
.set input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.help h3 { font-size: 16px; margin: 14px 0 4px; }
.help p, .help ul { margin: 0 0 6px; }
.help ul { padding-left: 20px; }
table.keys { width: 100%; border-collapse: collapse; font-size: 15px; }
table.keys td { padding: 7px 0; border-bottom: 1px solid var(--line); }
table.keys td:first-child { white-space: nowrap; padding-right: 14px; }
.done { text-align: center; }
.done-time { display: grid; margin: 4px 0 10px; }
.done-time span { color: var(--muted); }
.done-time b { font-size: 44px; font-variant-numeric: tabular-nums; line-height: 1.1; }
.big-note { font-size: 22px; font-weight: 800; color: var(--good); margin: 6px 0; }
.stars { display: flex; justify-content: center; gap: 4px; }
.stars button { border: 0; background: none; font-size: 32px; color: var(--line); padding: 0 2px; }
.stars button.on { color: #e3a21a; }
.profile .row { align-items: flex-end; }
.danger-zone { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 10px; }
.danger-zone summary { cursor: pointer; color: var(--muted); font-size: 14px; }

/* toasts and loading */
#toasts { position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60; display: grid; gap: 8px; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 15px; font-weight: 600; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); transition: opacity .4s, transform .4s; text-align: center; }
.toast.good { background: var(--good); color: #fff; }
.toast.bad { background: var(--bad); color: #fff; }
.toast.out { opacity: 0; transform: translateY(8px); }
.loading { min-height: 60dvh; display: grid; place-content: center; justify-items: center; gap: 14px; color: var(--muted); }
.spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.hide-sm { }
@media (max-width: 899px) {
  .key { aspect-ratio: auto; height: 54px; grid-template-rows: 1fr auto; padding: 4px 0 3px; border-radius: 10px; }
  .key small { position: static; line-height: 1; }
  .key.swatch { height: 46px; }
  .kd.corner { margin: 2px 0 0 4px; font-size: 13px; }
}
@media (max-width: 520px) {
  .hide-sm { display: none; }
  .tb-right { gap: 6px; }
  .tb-right .icon-btn { width: 36px; height: 36px; }
  .timer { font-size: 15px; }
  .topbar { padding-left: 10px; padding-right: 10px; gap: 8px; }
  .timer { min-width: 0; padding: 6px 10px; }
  .card { padding: 15px; }
  .prow { grid-template-columns: 52px 1fr; }
  .prow .badge { grid-column: 2; justify-self: start; }
  .mini { width: 52px; }
  .act { font-size: 11px; }
  .modes .mode-label { font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
