/* Killer Sudoku (js/killer-sudoku.js). A sibling of Sudocu: the same blue selection, given-cell
   greys and number pad, on the newer game-page skeleton. Tokens on :root, redefined under
   body.dark-theme. */
:root {
    --ks-accent: #1d5fd1;
    --ks-accent-2: #2f74e6;
    --ks-accent-soft: #e4eeff;
    --ks-on-accent: #ffffff;
    --ks-page-bg: #f2f5fb;
    --ks-card-bg: #ffffff;
    --ks-card-border: #d8e0ee;
    --ks-muted: #5b6577;
    --ks-shadow: 0 10px 30px rgba(20, 40, 90, .10);
    --ks-cell: #ffffff;
    --ks-line: #cfd7e5;
    --ks-line-strong: #2b3445;
    --ks-cage: #4a5568;
    --ks-peer: #eef3fc;
    --ks-cagehi: #e2ebfb;
    --ks-same: #cfe0fb;
    --ks-sel: #b7d1fa;
    --ks-ring: #3498db;
    --ks-value: #1d5fd1;
    --ks-hinted: #0f766e;
    --ks-note: #6b7280;
    --ks-bad: #dc2626;
    --ks-bad-soft: #fde2e2;
    --ks-good: #15803d;
    --ks-gold: #f59e0b;
    --ks-overlay: rgba(10, 20, 40, .5);
}

body.dark-theme {
    --ks-accent: #7aa7ff;
    --ks-accent-2: #93b8ff;
    --ks-accent-soft: #17233f;
    --ks-on-accent: #0b1430;
    --ks-page-bg: #0d1220;
    --ks-card-bg: #161d2e;
    --ks-card-border: #2a3550;
    --ks-muted: #a2adc4;
    --ks-shadow: 0 10px 30px rgba(0, 0, 0, .45);
    --ks-cell: #141b2b;
    --ks-line: #2c3750;
    --ks-line-strong: #a9b7d3;
    --ks-cage: #9fb0d0;
    --ks-peer: #1a2438;
    --ks-cagehi: #1d2a45;
    --ks-same: #243a63;
    --ks-sel: #2d4a7e;
    --ks-ring: #5dade2;
    --ks-value: #8db8ff;
    --ks-hinted: #5eead4;
    --ks-note: #9aa6bd;
    --ks-bad: #f87171;
    --ks-bad-soft: #3a1c22;
    --ks-good: #4ade80;
    --ks-gold: #fbbf24;
    --ks-overlay: rgba(0, 0, 0, .62);
}

/* clip, not hidden: the site-wide `body { overflow-x: hidden }` makes <body> a scroll container
   that never scrolls, which silently kills any position: sticky inside. */
.ks-body, body.ks-body#page-top {
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--ks-page-bg);
    color: var(--text-color);
    min-height: 100vh;
    overflow-x: clip;
}
.ks-main { padding-top: 92px; padding-bottom: 40px; }
.ks-game .container, .ks-hero .container { max-width: 1000px; }

/* ---- hero ---- */
.ks-hero { text-align: center; padding: 4px 0 8px; }
.ks-hero h1 { font-weight: 800; font-size: clamp(1.6rem, 5vw, 2.2rem); margin-bottom: 4px; }
.ks-hero-icon { color: var(--ks-accent); }
.ks-lead { margin: 0 auto; max-width: 580px; color: var(--ks-muted); font-size: .98rem; line-height: 1.45; }

/* ---- levels ---- */
.ks-levels { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; max-width: 640px; margin: 6px auto 10px; padding: 5px; border-radius: 16px; background: var(--ks-card-bg); border: 1px solid var(--ks-card-border); box-shadow: var(--ks-shadow); }
.ks-chip { min-height: 52px; padding: 4px; border: 0; border-radius: 12px; background: transparent; color: inherit; font-weight: 800; font-size: .95rem; line-height: 1.15; cursor: pointer; touch-action: manipulation; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.ks-chip small { font-weight: 600; font-size: .72rem; opacity: .75; white-space: nowrap; }
.ks-chip[aria-checked="true"] { background: var(--ks-accent); color: var(--ks-on-accent); }

/* ---- layout ---- */
.ks-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; align-items: start; justify-content: center; }
@media (min-width: 900px) {
    .ks-layout { grid-template-columns: minmax(0, 560px) 330px; gap: 22px; }
    .ks-right { padding-top: 54px; }
}
.ks-left, .ks-right { min-width: 0; display: flex; flex-direction: column; gap: 8px; }
@media (max-width: 899px) {
    /* phone: the pad sits right under the board; the combinations come after the tools */
    .ks-layout { gap: 4px; }
    .ks-combo { order: 3; }
    .ks-switch { order: 4; }
    .ks-actions { order: 5; }
}

/* ---- bar ---- */
.ks-bar { display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; }
.ks-badge { display: inline-flex; align-items: center; gap: 6px; min-height: 42px; padding: 4px 11px; border-radius: 12px; background: var(--ks-card-bg); border: 1px solid var(--ks-card-border); font-weight: 700; font-size: .9rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ks-badge[hidden] { display: none; }
.ks-badge svg, .ks-badge i { color: var(--ks-accent); }
.ks-badge-bad svg, .ks-badge-bad i { color: var(--ks-bad); }
.ks-clock { margin-left: auto; }
.ks-clock b { font-size: 1.05rem; min-width: 3.2ch; text-align: right; }
.ks-round { width: 42px; height: 42px; flex: none; border-radius: 12px; border: 1px solid var(--ks-card-border); background: var(--ks-card-bg); color: inherit; display: grid; place-items: center; cursor: pointer; touch-action: manipulation; }
.ks-round span[hidden], .ks-tool span[hidden] { display: none; }

/* ---- board ---- */
.ks-board-wrap { position: relative; width: 100%; max-width: min(560px, calc(100vh - 140px)); max-width: min(560px, calc(100dvh - 140px)); margin: 0 auto; container-type: inline-size; }
.ks-board { position: relative; display: grid; grid-template-columns: repeat(9, 1fr); grid-template-rows: repeat(9, 1fr); width: 100%; aspect-ratio: 1; border: 3px solid var(--ks-line-strong); border-radius: 10px; overflow: hidden; background: var(--ks-cell); user-select: none; -webkit-user-select: none; touch-action: manipulation; -webkit-tap-highlight-color: transparent; box-shadow: var(--ks-shadow); }
.ks-board:focus { outline: none; }
.ks-board:focus-visible { box-shadow: 0 0 0 3px var(--ks-gold), var(--ks-shadow); }
.ks-c { position: relative; display: grid; place-items: center; min-width: 0; min-height: 0; background: var(--ks-cell); border-right: 1px solid var(--ks-line); border-bottom: 1px solid var(--ks-line); cursor: pointer; font-variant-numeric: tabular-nums; }
.ks-c.bx-r { border-right: 2px solid var(--ks-line-strong); }
.ks-c.bx-b { border-bottom: 2px solid var(--ks-line-strong); }
.ks-c.c8 { border-right: 0; }
.ks-c.r8 { border-bottom: 0; }
.ks-c.is-peer { background: var(--ks-peer); }
.ks-c.is-cage { background: var(--ks-cagehi); }
.ks-c.is-same { background: var(--ks-same); }
.ks-c.is-sel { background: var(--ks-sel); box-shadow: inset 0 0 0 2px var(--ks-ring); }
.ks-c.is-conflict { background: var(--ks-bad-soft); }
.ks-c.is-sel.is-conflict { background: var(--ks-bad-soft); }
.ks-v { font-size: 26px; font-size: 6.4cqw; font-weight: 700; color: var(--ks-value); line-height: 1; position: relative; z-index: 2; }
.ks-c.is-hinted .ks-v { color: var(--ks-hinted); }
.ks-c.is-conflict .ks-v, .ks-c.is-wrong .ks-v { color: var(--ks-bad); }
.ks-c.is-wrong .ks-v { text-decoration: underline wavy; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.ks-c.is-pop .ks-v { animation: ks-pop .2s ease-out; }
@keyframes ks-pop { from { transform: scale(.5); opacity: .2; } }
.ks-c.is-shake { animation: ks-shake .35s ease; }
@keyframes ks-shake { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }
.ks-c.is-flash { animation: ks-flash .9s ease-out 2; }
@keyframes ks-flash { 50% { background: rgba(46, 204, 113, .45); } }
.ks-c.is-win { animation: ks-win .5s ease-out both; animation-delay: var(--d, 0ms); }
@keyframes ks-win { 50% { transform: scale(1.12); background: rgba(46, 204, 113, .35); } 100% { background: rgba(46, 204, 113, .12); } }
.ks-notes { position: absolute; inset: 22% 5% 4% 5%; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); z-index: 2; pointer-events: none; }
.ks-notes[hidden] { display: none; }
.ks-notes span { display: grid; place-items: center; font-size: 9px; font-size: 2.45cqw; font-weight: 700; color: var(--ks-note); line-height: 1; }
.ks-notes span.is-hot { color: var(--ks-accent); }
.ks-sum { position: absolute; top: 1px; left: 2px; z-index: 3; padding: 0 2px 1px 1px; font-size: 10px; font-size: 2.35cqw; font-weight: 800; line-height: 1; color: var(--ks-cage); background: inherit; border-radius: 0 0 4px 0; pointer-events: none; }
.ks-sum.is-bad { color: var(--ks-bad); }
.ks-sum.is-done { color: var(--ks-good); }
.ks-cages { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 1; pointer-events: none; }
.ks-cages path { fill: none; stroke: var(--ks-cage); stroke-width: 1.2px; stroke-dasharray: 3 2.4; vector-effect: non-scaling-stroke; opacity: .85; }
.ks-cages path.is-hot { stroke: var(--ks-accent); stroke-width: 2px; stroke-dasharray: none; opacity: 1; }

.ks-cover { position: absolute; inset: 0; z-index: 5; display: grid; place-content: center; justify-items: center; gap: 12px; border-radius: 10px; background: var(--ks-card-bg); text-align: center; font-weight: 800; font-size: 1.2rem; }
.ks-cover[hidden] { display: none; }
.ks-cover p { margin: 0; display: inline-flex; align-items: center; gap: 10px; }
.ks-spin { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--ks-card-border); border-top-color: var(--ks-accent); animation: ks-rot .8s linear infinite; }
@keyframes ks-rot { to { transform: rotate(360deg); } }

.ks-status { margin: 0 2px; height: 2.7em; display: flex; align-items: center; justify-content: center; overflow: hidden; font-weight: 700; text-align: center; color: var(--ks-muted); line-height: 1.3; font-size: .88rem; }
.ks-status.is-good { color: var(--ks-good); }
.ks-status.is-bad { color: var(--ks-bad); }

/* ---- combinations ---- */
.ks-combo { padding: 8px 10px; border-radius: 14px; background: var(--ks-card-bg); border: 1px solid var(--ks-card-border); height: 92px; overflow-y: auto; }
.ks-combo-head { font-weight: 800; font-size: .86rem; color: var(--ks-muted); margin-bottom: 5px; }
.ks-combo-head b { color: var(--text-color); }
.ks-combo-list { display: flex; flex-wrap: wrap; gap: 4px 5px; }
.ks-combo-empty { color: var(--ks-muted); font-size: .86rem; }
.ks-cmb { display: inline-block; padding: 2px 7px; border-radius: 8px; background: var(--ks-accent-soft); color: var(--text-color); font-weight: 800; font-size: .9rem; letter-spacing: .06em; font-variant-numeric: tabular-nums; }
.ks-cmb.is-off { background: transparent; color: var(--ks-muted); text-decoration: line-through; opacity: .6; font-weight: 600; }

/* ---- number pad ---- */
.ks-pad { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.ks-num { position: relative; min-height: 52px; border-radius: 12px; border: 2px solid var(--ks-card-border); background: var(--ks-card-bg); color: var(--text-color); font-size: 1.45rem; font-weight: 800; cursor: pointer; touch-action: manipulation; display: grid; place-items: center; transition: background .15s, border-color .15s, transform .08s; font-variant-numeric: tabular-nums; }
.ks-num:active { transform: scale(.95); }
.ks-num.is-done { opacity: .32; }
.ks-num-erase { color: var(--ks-muted); font-size: 1.15rem; }
.ks-pad.is-notes .ks-num:not(.ks-num-erase) { font-size: 1.05rem; color: var(--ks-accent); border-style: dashed; }
@media (hover: hover) {
    .ks-num:hover { border-color: var(--ks-ring); background: var(--ks-accent-soft); }
}

/* ---- tools ---- */
.ks-tools { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; }
.ks-tool { min-height: 54px; padding: 4px 2px; border-radius: 12px; border: 1px solid var(--ks-card-border); background: var(--ks-card-bg); color: inherit; font-weight: 700; font-size: .74rem; cursor: pointer; touch-action: manipulation; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; }
.ks-tool[hidden] { display: none; }
.ks-tool svg, .ks-tool i { font-size: 1.05rem; }
.ks-tool:disabled { opacity: .4; cursor: default; }
.ks-tool[aria-pressed="true"]#ks-notes { background: var(--ks-accent); border-color: var(--ks-accent); color: var(--ks-on-accent); }
#ks-hint svg { color: var(--ks-gold); }

.ks-switch { display: flex; align-items: center; justify-content: center; gap: 9px; margin: 2px 0 0; min-height: 40px; font-weight: 700; cursor: pointer; user-select: none; }
.ks-switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.ks-switch-ui { position: relative; width: 44px; height: 26px; border-radius: 13px; background: var(--ks-card-border); transition: background .2s; flex: none; }
.ks-switch-ui::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .2s; }
.ks-switch input:checked + .ks-switch-ui { background: var(--ks-accent); }
.ks-switch input:checked + .ks-switch-ui::after { transform: translateX(18px); }
.ks-switch input:focus-visible + .ks-switch-ui { outline: 3px solid var(--ks-gold); outline-offset: 2px; }

.ks-actions { display: grid; grid-template-columns: 1fr 1.3fr; gap: 8px; }
.ks-btn { min-height: 48px; padding: 8px 14px; border: 1px solid var(--ks-card-border); border-radius: 14px; background: var(--ks-card-bg); color: inherit; font-weight: 700; font-size: .95rem; cursor: pointer; touch-action: manipulation; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.ks-btn:hover:not(:disabled) { border-color: var(--ks-accent); }
.ks-btn-primary { background: var(--ks-accent); border-color: var(--ks-accent); color: var(--ks-on-accent); }
.ks-btn-primary:hover:not(:disabled) { background: var(--ks-accent-2); }
.ks-chip:focus-visible, .ks-btn:focus-visible, .ks-round:focus-visible, .ks-tool:focus-visible, .ks-num:focus-visible, .ks-x:focus-visible, .ks-link:focus-visible { outline: 3px solid var(--ks-gold); outline-offset: 2px; }

.ks-record { text-align: center; color: var(--ks-muted); font-size: .88rem; margin: 12px 0 0; min-height: 1.3em; }
.ks-record b { color: var(--text-color); }

.ks-help { max-width: 760px; margin: 14px auto 0; padding: 12px 16px; border-radius: 14px; background: var(--ks-card-bg); border: 1px solid var(--ks-card-border); }
.ks-help summary { cursor: pointer; font-weight: 700; }
.ks-help ul { margin: 10px 0 0; padding-left: 20px; color: var(--ks-muted); line-height: 1.55; }
.ks-help li { margin-bottom: 4px; }
.ks-help strong { color: var(--text-color); }
.ks-help p { color: var(--ks-muted); margin: 10px 0 0; line-height: 1.55; font-size: .93rem; }
.ks-help p.ks-credit { font-size: .8rem; }
.ks-help a { color: var(--ks-accent); }
.ks-powered { text-align: center; color: var(--ks-muted); font-size: .85rem; margin: 26px 0 0; }
.ks-powered a { color: var(--ks-accent); }

/* ---- dialogs ---- */
.ks-overlay { position: fixed; inset: 0; z-index: 2000; display: grid; place-items: center; padding: 16px; background: var(--ks-overlay); animation: ks-fade .2s ease-out; }
.ks-overlay[hidden] { display: none; }
@keyframes ks-fade { from { opacity: 0; } }
.ks-dialog { width: 100%; max-width: 400px; max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow: auto; padding: 20px 16px 16px; border-radius: 22px; background: var(--ks-card-bg); color: var(--text-color); text-align: center; box-shadow: 0 20px 50px rgba(0, 0, 0, .35); animation: ks-rise .25s ease-out; }
@keyframes ks-rise { from { transform: translateY(16px) scale(.97); opacity: 0; } }
.ks-dialog h2 { font-weight: 800; font-size: 1.4rem; margin: 2px 0 6px; }
.ks-dialog-icon { font-size: 34px; color: var(--ks-gold); }
.ks-dialog-sub { color: var(--ks-muted); margin: 0 0 6px; line-height: 1.5; }
.ks-dialog-sub b { color: var(--text-color); }
.ks-dialog-sub .ks-new-rec { display: inline-block; margin-top: 4px; padding: 2px 10px; border-radius: 999px; background: var(--ks-gold); color: #3b2300; font-weight: 800; }
.ks-dialog-actions { display: grid; grid-template-columns: 1fr 1.3fr; gap: 8px; margin-top: 14px; }
.ks-recs-card { max-width: 520px; text-align: left; }
.ks-recs-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ks-x { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--ks-card-border); background: var(--ks-card-bg); color: inherit; font-size: 1.1rem; cursor: pointer; }
.ks-rec-wrap { overflow-x: auto; margin-top: 8px; }
.ks-rec-table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.ks-rec-table th, .ks-rec-table td { padding: 8px 6px; border-top: 1px solid var(--ks-card-border); white-space: nowrap; }
.ks-rec-table thead th { border-top: 0; font-size: .72rem; text-transform: uppercase; letter-spacing: .03em; color: var(--ks-muted); }
.ks-rec-table td { font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.ks-rec-table thead th:not(:first-child) { text-align: right; }
.ks-rec-note { color: var(--ks-muted); font-size: .84rem; margin: 10px 0 4px; line-height: 1.4; }
.ks-link { border: 0; background: none; padding: 6px 0; color: var(--ks-bad); font-weight: 700; text-decoration: underline; cursor: pointer; }

@media (max-width: 600px) {
    /* <main> already starts below the fixed navbar's spacer here; 92px would leave a blank band */
    .ks-main { padding-top: 22px; }
    .ks-lead { display: none; }
    .ks-hero h1 { font-size: 1.55rem; margin-bottom: 0; }
    .ks-board-wrap { max-width: none; }
}

@media (max-width: 420px) {
    .ks-chip { font-size: .86rem; min-height: 48px; }
    .ks-chip small { font-size: .66rem; }
    .ks-badge { padding: 4px 8px; font-size: .84rem; gap: 5px; min-height: 40px; }
    .ks-round { width: 40px; height: 40px; }
    .ks-num { min-height: 50px; }
    .ks-tool span:last-child { font-size: .68rem; }
}

@media (prefers-reduced-motion: reduce) {
    .ks-c, .ks-v, .ks-dialog, .ks-overlay, .ks-spin { animation: none !important; transition: none !important; }
}
