/* Kakuro (js/kakuro.js). A sibling of Sudocu and Killer Sudoku: the same selection, number pad
   and tools, on the newer game-page skeleton, in indigo. Tokens on :root, redefined under
   body.dark-theme. */
:root {
    --kk-accent: #4338ca;
    --kk-accent-2: #4f46e5;
    --kk-accent-soft: #e8e7ff;
    --kk-on-accent: #ffffff;
    --kk-page-bg: #f3f3fb;
    --kk-card-bg: #ffffff;
    --kk-card-border: #dcdcf0;
    --kk-muted: #5d5f78;
    --kk-shadow: 0 10px 30px rgba(40, 30, 110, .10);
    --kk-cell: #ffffff;
    --kk-line: #c9cbe0;
    --kk-line-strong: #2a2b45;
    --kk-clue: #33355a;
    --kk-clue-2: #262844;
    --kk-clue-text: #f4f4ff;
    --kk-clue-hot: #4f46e5;
    --kk-clue-diag: rgba(255, 255, 255, .28);
    --kk-peer: #eeeefc;
    --kk-same: #d8d5fb;
    --kk-sel: #c3bdfa;
    --kk-ring: #4f46e5;
    --kk-value: #3730a3;
    --kk-hinted: #0f766e;
    --kk-note: #6b6d85;
    --kk-bad: #dc2626;
    --kk-bad-soft: #fde2e2;
    --kk-good: #15803d;
    --kk-gold: #f59e0b;
    --kk-overlay: rgba(14, 12, 40, .5);
}

body.dark-theme {
    --kk-accent: #a5a1ff;
    --kk-accent-2: #bbb8ff;
    --kk-accent-soft: #24234a;
    --kk-on-accent: #13123a;
    --kk-page-bg: #0e0e1c;
    --kk-card-bg: #17172b;
    --kk-card-border: #2e2e4e;
    --kk-muted: #a7a8c6;
    --kk-shadow: 0 10px 30px rgba(0, 0, 0, .45);
    --kk-cell: #27274a;
    --kk-line: #3d3d68;
    --kk-line-strong: #9c9fd0;
    --kk-clue: #111126;
    --kk-clue-2: #0a0a18;
    --kk-clue-text: #e9e9ff;
    --kk-clue-hot: #5b55e6;
    --kk-clue-diag: rgba(255, 255, 255, .16);
    --kk-peer: #32325f;
    --kk-same: #433f86;
    --kk-sel: #5550aa;
    --kk-ring: #a5a1ff;
    --kk-value: #c3c0ff;
    --kk-hinted: #5eead4;
    --kk-note: #a0a2c2;
    --kk-bad: #f87171;
    --kk-bad-soft: #3d1c27;
    --kk-good: #4ade80;
    --kk-gold: #fbbf24;
    --kk-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. */
.kk-body, body.kk-body#page-top {
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--kk-page-bg);
    color: var(--text-color);
    min-height: 100vh;
    overflow-x: clip;
}
.kk-main { padding-top: 92px; padding-bottom: 40px; }
.kk-game .container, .kk-hero .container { max-width: 1000px; }

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

/* ---- levels ---- */
.kk-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(--kk-card-bg); border: 1px solid var(--kk-card-border); box-shadow: var(--kk-shadow); }
.kk-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; }
.kk-chip small { font-weight: 600; font-size: .72rem; opacity: .75; white-space: nowrap; }
.kk-chip[aria-checked="true"] { background: var(--kk-accent); color: var(--kk-on-accent); }

/* ---- layout ---- */
.kk-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; align-items: start; justify-content: center; }
@media (min-width: 900px) {
    .kk-layout { grid-template-columns: minmax(0, 560px) 330px; gap: 22px; }
    .kk-right { padding-top: 54px; }
}
.kk-left, .kk-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 */
    .kk-layout { gap: 4px; }
    .kk-combo { order: 3; }
    .kk-switch { order: 4; }
    .kk-actions { order: 5; }
}

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

/* ---- board ---- */
.kk-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; }
.kk-board { --kk-n: 9; --kk-cw: calc(100cqw / var(--kk-n)); position: relative; display: grid; grid-template-columns: repeat(var(--kk-n), 1fr); grid-template-rows: repeat(var(--kk-n), 1fr); width: 100%; aspect-ratio: 1; border: 3px solid var(--kk-line-strong); border-radius: 10px; overflow: hidden; background: var(--kk-line); gap: 1px; user-select: none; -webkit-user-select: none; touch-action: manipulation; -webkit-tap-highlight-color: transparent; box-shadow: var(--kk-shadow); }
.kk-board:focus { outline: none; }
.kk-board:focus-visible { box-shadow: 0 0 0 3px var(--kk-gold), var(--kk-shadow); }
.kk-c { position: relative; display: grid; place-items: center; min-width: 0; min-height: 0; background: var(--kk-cell); cursor: pointer; font-variant-numeric: tabular-nums; }
.kk-k { position: relative; min-width: 0; min-height: 0; background: linear-gradient(160deg, var(--kk-clue) 0%, var(--kk-clue-2) 100%); color: var(--kk-clue-text); font-weight: 800; line-height: 1; }
.kk-k.has-a, .kk-k.has-d { background: linear-gradient(to top right, transparent calc(50% - .6px), var(--kk-clue-diag) calc(50% - .6px), var(--kk-clue-diag) calc(50% + .6px), transparent calc(50% + .6px)), linear-gradient(160deg, var(--kk-clue) 0%, var(--kk-clue-2) 100%); }
.kk-k span { position: absolute; font-size: 11px; font-size: calc(var(--kk-cw) * .3); border-radius: 4px; padding: 0 1px; }
.kk-k .kk-a { top: 7%; right: 8%; }
.kk-k .kk-d { bottom: 7%; left: 8%; }
.kk-k span.is-hot { background: var(--kk-clue-hot); color: #fff; box-shadow: 0 0 0 2px var(--kk-clue-hot); }
.kk-k span.is-bad { background: var(--kk-bad); color: #fff; box-shadow: 0 0 0 2px var(--kk-bad); }
.kk-k span.is-done { color: #86efac; }
.kk-k span.is-hot.is-done { color: #d1fae5; }
.kk-c.is-peer { background: var(--kk-peer); }
.kk-c.is-same { background: var(--kk-same); }
.kk-c.is-sel { background: var(--kk-sel); box-shadow: inset 0 0 0 2px var(--kk-ring); }
.kk-c.is-conflict { background: var(--kk-bad-soft); }
.kk-v { font-size: 26px; font-size: calc(var(--kk-cw) * .6); font-weight: 700; color: var(--kk-value); line-height: 1; position: relative; z-index: 2; }
.kk-c.is-hinted .kk-v { color: var(--kk-hinted); }
.kk-c.is-conflict .kk-v, .kk-c.is-wrong .kk-v { color: var(--kk-bad); }
.kk-c.is-wrong .kk-v { text-decoration: underline wavy; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.kk-c.is-pop .kk-v { animation: kk-pop .2s ease-out; }
@keyframes kk-pop { from { transform: scale(.5); opacity: .2; } }
.kk-c.is-shake { animation: kk-shake .35s ease; }
@keyframes kk-shake { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }
.kk-c.is-flash { animation: kk-flash .9s ease-out 2; }
@keyframes kk-flash { 50% { background: rgba(46, 204, 113, .45); } }
.kk-c.is-win { animation: kk-win .5s ease-out both; animation-delay: var(--d, 0ms); }
@keyframes kk-win { 50% { transform: scale(1.12); background: rgba(46, 204, 113, .35); } 100% { background: rgba(46, 204, 113, .12); } }
.kk-notes { position: absolute; inset: 6%; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); z-index: 2; pointer-events: none; }
.kk-notes[hidden] { display: none; }
.kk-notes span { display: grid; place-items: center; font-size: 9px; font-size: calc(var(--kk-cw) * .25); font-weight: 700; color: var(--kk-note); line-height: 1; }
.kk-notes span.is-hot { color: var(--kk-accent); }

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

.kk-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(--kk-muted); line-height: 1.3; font-size: .88rem; }
.kk-status.is-good { color: var(--kk-good); }
.kk-status.is-bad { color: var(--kk-bad); }

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

/* ---- number pad ---- */
.kk-pad { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.kk-num { position: relative; min-height: 52px; border-radius: 12px; border: 2px solid var(--kk-card-border); background: var(--kk-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; }
.kk-num:active { transform: scale(.95); }
.kk-num.is-done { opacity: .32; }
.kk-num-erase { color: var(--kk-muted); font-size: 1.15rem; }
.kk-pad.is-notes .kk-num:not(.kk-num-erase) { font-size: 1.05rem; color: var(--kk-accent); border-style: dashed; }
@media (hover: hover) {
    .kk-num:hover { border-color: var(--kk-ring); background: var(--kk-accent-soft); }
}

/* ---- tools ---- */
.kk-tools { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; }
.kk-tool { min-height: 54px; padding: 4px 2px; border-radius: 12px; border: 1px solid var(--kk-card-border); background: var(--kk-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; }
.kk-tool[hidden] { display: none; }
.kk-tool svg, .kk-tool i { font-size: 1.05rem; }
.kk-tool:disabled { opacity: .4; cursor: default; }
.kk-tool[aria-pressed="true"]#kk-notes { background: var(--kk-accent); border-color: var(--kk-accent); color: var(--kk-on-accent); }
#kk-hint svg { color: var(--kk-gold); }

.kk-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; }
.kk-switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.kk-switch-ui { position: relative; width: 44px; height: 26px; border-radius: 13px; background: var(--kk-card-border); transition: background .2s; flex: none; }
.kk-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; }
.kk-switch input:checked + .kk-switch-ui { background: var(--kk-accent); }
.kk-switch input:checked + .kk-switch-ui::after { transform: translateX(18px); }
.kk-switch input:focus-visible + .kk-switch-ui { outline: 3px solid var(--kk-gold); outline-offset: 2px; }

.kk-actions { display: grid; grid-template-columns: 1fr 1.3fr; gap: 8px; }
.kk-btn { min-height: 48px; padding: 8px 14px; border: 1px solid var(--kk-card-border); border-radius: 14px; background: var(--kk-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; }
.kk-btn:hover:not(:disabled) { border-color: var(--kk-accent); }
.kk-btn-primary { background: var(--kk-accent); border-color: var(--kk-accent); color: var(--kk-on-accent); }
.kk-btn-primary:hover:not(:disabled) { background: var(--kk-accent-2); }
.kk-chip:focus-visible, .kk-btn:focus-visible, .kk-round:focus-visible, .kk-tool:focus-visible, .kk-num:focus-visible, .kk-x:focus-visible, .kk-link:focus-visible { outline: 3px solid var(--kk-gold); outline-offset: 2px; }

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

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

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

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

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