/* Sudoku — redaktor, lahendaja (play.js) ja tööleht (.sds).
   Saidi UI kasutab teemamuutujaid; tööleht on ALATI hele (paber/pilt), lahendaja järgib teemat. */
:root {
    --sd-accent-soft: rgba(0, 209, 178, 0.12);
    --sd-peer: rgba(0, 0, 0, 0.045);
    --sd-sel: rgba(0, 209, 178, 0.28);
    --sd-same: rgba(0, 209, 178, 0.16);
    --sd-entry: #0b6e99;
    --sd-bad: #c81e1e;
    --sd-bad-bg: rgba(220, 38, 38, 0.12);
    --sd-thin: #c3c7cf;
    --sd-thick: #2b2f36;
    --shadow-1: 0 1px 2px rgba(17, 17, 26, .06), 0 4px 12px rgba(17, 17, 26, .08);
}
[data-theme="dark"] {
    --sd-accent-soft: rgba(34, 211, 238, 0.14);
    --sd-peer: rgba(255, 255, 255, 0.05);
    --sd-sel: rgba(34, 211, 238, 0.32);
    --sd-same: rgba(34, 211, 238, 0.16);
    --sd-entry: #7dd3fc;
    --sd-bad: #fca5a5;
    --sd-bad-bg: rgba(248, 113, 113, 0.18);
    --sd-thin: #4b5060;
    --sd-thick: #c9ccd4;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --sd-accent-soft: rgba(34, 211, 238, 0.14);
        --sd-peer: rgba(255, 255, 255, 0.05);
        --sd-sel: rgba(34, 211, 238, 0.32);
        --sd-same: rgba(34, 211, 238, 0.16);
        --sd-entry: #7dd3fc;
        --sd-bad: #fca5a5;
        --sd-bad-bg: rgba(248, 113, 113, 0.18);
        --sd-thin: #4b5060;
        --sd-thick: #c9ccd4;
    }
}

.sd-section { padding: 24px 16px 48px; }
.sd-container { max-width: 1240px; }

/* ---------- Päis ja ehitusplokid ---------- */
.sd-page-head { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; }
.sd-badge {
    width: 56px; height: 56px; border-radius: 14px; flex-shrink: 0;
    background: var(--sd-accent-soft); color: var(--accent-color);
    display: inline-flex; align-items: center; justify-content: center; font-size: 24px;
}
.sd-h1 { font-size: 1.75rem; font-weight: 700; line-height: 1.2; color: var(--text-primary); margin: 0; }
.sd-sub { color: var(--text-secondary); margin: 2px 0 0; }
.sd-h2 { font-size: 1.05rem; font-weight: 700; color: var(--text-primary); margin: 0 0 12px; }
.sd-help { font-size: 13px; color: var(--text-secondary); line-height: 1.4; margin-bottom: 8px; }
.sd-card {
    background: var(--bg-card); border: 1px solid var(--border-light); border-radius: 12px;
    box-shadow: var(--shadow-1); padding: 16px 18px; margin-bottom: 16px;
}
.sd-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.sd-icon-btn {
    width: 40px; height: 40px; flex-shrink: 0; border: 0; border-radius: 8px; margin: -8px -8px 0 0;
    background: transparent; color: var(--text-secondary); cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    transition: background var(--dur-fast, 150ms), color var(--dur-fast, 150ms);
}
.sd-icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.sd-note {
    display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
    padding: 10px 12px; margin-bottom: 12px; border-radius: 8px;
    background: var(--sd-accent-soft); color: var(--text-primary); font-size: 14px; line-height: 1.4;
}
.sd-note > i { color: var(--accent-color); }
.sd-note > span { flex: 1 1 220px; }
/* „Kasuta" nupud: neli tegevust ühtlases ruudustikus — vabalt murdudes jäi „Lahenda ekraanil" orvuna omaette ritta */
.sd-use { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 190px), 1fr)); }
.sd-use .button { margin: 0; justify-content: flex-start; }
.sd-share { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border-light); }

/* Kaheveeruline paigutus: vasakul sätted ja kujundus, paremal eelvaade + „Kasuta". Eelvaade EI kleepu
   (kasutaja otsus 2026-11-30): A4-leht on ekraanist kõrgem, kleepudes jäi selle alumine osa nähtamatuks. */
.sd-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.sd-col { min-width: 0; }
.sd-col-preview .sr-preview-wrap { position: static; margin-bottom: 16px; }
/* A4-kõrgune koht enne JS-i renderdust — mobiilis on eelvaade esimene ja „Kasuta" hüppas muidu alla (CLS 0,44) */
.sd-col-preview .sr-preview { aspect-ratio: 210 / 297; }
/* Üks veerg: eelvaade ja „Kasuta" enne sätteid */
@media (max-width: 900px) {
    .sd-grid { grid-template-columns: minmax(0, 1fr); }
    .sd-col-preview { order: -1; }
}
.sd-busy { margin-top: 8px; font-size: 14px; color: var(--text-secondary); }

/* Valikud (suurus, raskus, arv) segmentidena */
.sd-opt-group { border: 0; padding: 0; margin: 0 0 14px; min-width: 0; }
.sd-opt-group .label { margin-bottom: 6px; }
.sd-opt-group.is-locked { opacity: .6; }
.sd-seg { display: flex; flex-wrap: wrap; gap: 8px; }
.sd-seg-opt { position: relative; margin: 0; flex: 1 1 0; min-width: 56px; cursor: pointer; display: flex; }
.sd-seg-opt input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.sd-seg-opt > span {
    flex: 1 1 auto;   /* sama rea nupud ühekõrgused, ka siis, kui ühe silt murdub kahele reale */
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
    min-height: 44px; padding: 6px 8px; border-radius: 10px; text-align: center;
    border: 1.5px solid var(--border-color); background: var(--bg-card); color: var(--text-primary);
    transition: border-color var(--dur-fast, 150ms), background var(--dur-fast, 150ms);
}
.sd-seg-opt b { font-weight: 600; font-variant-numeric: tabular-nums; }
.sd-seg-opt small { font-size: 12px; color: var(--text-muted); }
.sd-seg-opt input:checked + span { border-color: var(--accent-color); background: var(--sd-accent-soft); }
.sd-seg-opt input:focus-visible + span { outline: 3px solid var(--accent-color); outline-offset: 2px; }
@media (hover: hover) { .sd-seg-opt:hover > span { border-color: var(--accent-color); } }
.sd-opt-group:disabled .sd-seg-opt { cursor: not-allowed; }
/* „Antud lahtrites": näide pisikese sudoku lahtrina */
.sd-mode-cell {
    display: inline-flex; align-items: center; justify-content: center; margin-top: 4px;
    width: 34px; height: 34px; border: 1.5px solid var(--text-secondary); border-radius: 4px;
    background: var(--bg-primary); color: var(--text-primary); font-size: 13px; font-weight: 600;
    font-variant-numeric: tabular-nums; white-space: nowrap;
}
/* Pildikomplekt: 3 näidisikooni + nimi; oma piltide pesad */
.sd-pic-sample { display: flex; gap: 4px; font-size: 15px; }
/* Ühesuurused nupud ka murdunud reas (flex venitaks viimase rea laiemaks) */
#sdPicGroup .sd-seg { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); grid-auto-rows: 1fr; }
#sdPicGroup .sd-seg-opt { min-width: 0; }
.sd-own { margin: -4px 0 14px; }
.sd-own-slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
.sd-own-slot {
    aspect-ratio: 1; border-radius: 10px; border: 1.5px dashed var(--border-color); background: var(--bg-secondary);
    color: var(--text-secondary); cursor: pointer; padding: 0; overflow: hidden;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-weight: 600;
}
.sd-own-slot.is-set { border-style: solid; }
.sd-own-slot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sd-own-slot:disabled { cursor: default; }
@media (hover: hover) { .sd-own-slot:not(:disabled):hover { border-color: var(--accent-color); } }
.sd-own-note { margin: 10px 0 0; }
/* Tehete nimed („korrutamine") ei mahu kitsal ekraanil neljakesi ritta — 2 × 2 */
@media (max-width: 480px) { #sdOpsGroup .sd-seg-opt { flex-basis: calc(50% - 4px); } }

/* Kujunduse valija: 4 stiili ühes reas, kitsal ekraanil 2 × 2 */
.sd-body .sr-style-picker { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 560px) { .sd-body .sr-style-picker { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ---------- Minu sudokud ---------- */
.sd-mine { margin-top: 8px; }
.sd-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.sd-item {
    display: flex; flex-direction: column; gap: 10px; padding: 12px 14px; border-radius: 10px;
    border: 1px solid var(--border-light); background: var(--bg-secondary);
}
.sd-item.is-active { border-color: var(--accent-color); box-shadow: 0 0 0 1px var(--accent-color) inset; }
.sd-item-title { font-weight: 600; color: var(--text-primary); overflow-wrap: anywhere; margin: 0; }
.sd-item-meta { font-size: 13px; color: var(--text-secondary); margin: 2px 0 0; }
.sd-empty { color: var(--text-secondary); }

/* ---------- Lahendusleht ---------- */
.sd-solve-wrap { max-width: 640px; }
.sd-solve-head { text-align: center; margin-bottom: 14px; }
.sd-solve-note { margin: 8px auto 0; max-width: 520px; font-size: 14px; color: var(--text-secondary); }
.sd-panel {
    max-width: 560px; margin: 24px auto; padding: 28px 24px; text-align: center;
    background: var(--bg-card); border: 1px solid var(--border-light); border-radius: 16px; box-shadow: var(--shadow-1);
}
.sd-panel .sd-badge { margin-bottom: 12px; }
.sd-howto { margin: 20px auto 0; max-width: 520px; color: var(--text-secondary); font-size: 14px; }
.sd-howto summary { cursor: pointer; color: var(--text-link); font-weight: 600; }
.sd-howto p { margin-top: 6px; }

/* ---------- Lahendaja (play.js) ---------- */
.sdp { --cell-gap: 0px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.sdp-tabs { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.sdp-tab {
    min-width: 44px; height: 44px; padding: 0 12px; border-radius: 999px; cursor: pointer;
    border: 1.5px solid var(--border-color); background: var(--bg-card); color: var(--text-primary);
    font-weight: 600; display: inline-flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums;
}
.sdp-tab[aria-selected="true"] { border-color: var(--accent-color); background: var(--sd-accent-soft); }
.sdp-tab i { color: var(--accent-color); font-size: 12px; }
.sdp-board {
    width: min(100%, 520px); aspect-ratio: 1; display: grid;
    grid-template-rows: repeat(var(--n), minmax(0, 1fr));
    border: 3px solid var(--sd-thick); border-radius: 6px; overflow: hidden;
    background: var(--bg-card); container-type: inline-size; user-select: none;
}
.sdp-row { display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); min-height: 0; }
.sdp-cell {
    position: relative; min-width: 0; min-height: 0; padding: 0; margin: 0; cursor: pointer;
    border: 0; border-right: 1px solid var(--sd-thin); border-bottom: 1px solid var(--sd-thin);
    background: transparent; color: var(--sd-entry);
    font: 500 calc(62cqw / var(--n)) / 1 'Figtree', 'Inter', system-ui, sans-serif;
    display: flex; align-items: center; justify-content: center; font-variant-numeric: tabular-nums;
    -webkit-tap-highlight-color: transparent;
}
.sdp-row > .sdp-cell:last-child { border-right: 0; }
.sdp-row:last-child > .sdp-cell { border-bottom: 0; }
.sdp-cell.sdp-bx { border-right: 2px solid var(--sd-thick); }
.sdp-cell.sdp-by { border-bottom: 2px solid var(--sd-thick); }
.sdp-cell.is-given { color: var(--text-primary); font-weight: 700; }
.sdp-cell.is-peer { background: var(--sd-peer); }
.sdp-cell.is-same { background: var(--sd-same); }
.sdp-cell.is-sel { background: var(--sd-sel); }
.sdp-cell.is-conflict, .sdp-cell.is-wrong { color: var(--sd-bad); background: var(--sd-bad-bg); }
.sdp-cell.is-sel.is-conflict, .sdp-cell.is-sel.is-wrong { box-shadow: inset 0 0 0 2px var(--sd-bad); }
.sdp-cell:focus-visible { outline: 3px solid var(--accent-color); outline-offset: -3px; z-index: 1; }
.sdp-notes {
    position: absolute; inset: 6%; display: grid;
    grid-template-columns: repeat(var(--bc), 1fr); grid-template-rows: repeat(var(--br), 1fr);
    font-size: calc(var(--fsn, 22cqw) / var(--n)); font-weight: 600; color: var(--text-secondary); line-height: 1;
}
.sdp-notes > span { display: flex; align-items: center; justify-content: center; }
.sdp.is-solved .sdp-board { border-color: var(--accent-color); }
/* Arvutussudoku: tehe lahtris (suurus pikkuse järgi, et „47 − 39" mahuks) + valitud tehe suurelt */
.sdp-expr {
    font-size: calc(var(--xk, 0.4) * 100cqw / var(--n)); font-weight: 700;
    white-space: nowrap; color: var(--text-primary);
}
/* Pildisudoku: värv numbri järgi (sama värv töölehel, lahendajas ja klahvil), et kuju + värv
   eristaksid ka värvipimedale. Tööleht on alati hele → need värvid; lahendaja tume teema → heledamad. */
.sd-c1 { color: #dc2626; } .sd-c2 { color: #2563eb; } .sd-c3 { color: #16a34a; }
.sd-c4 { color: #ea580c; } .sd-c5 { color: #7c3aed; } .sd-c6 { color: #db2777; }
.sd-c7 { color: #0e7490; } .sd-c8 { color: #92400e; } .sd-c9 { color: #334155; }
[data-theme="dark"] .sdp .sd-c1 { color: #f87171; } [data-theme="dark"] .sdp .sd-c2 { color: #60a5fa; }
[data-theme="dark"] .sdp .sd-c3 { color: #4ade80; } [data-theme="dark"] .sdp .sd-c4 { color: #fb923c; }
[data-theme="dark"] .sdp .sd-c5 { color: #a78bfa; } [data-theme="dark"] .sdp .sd-c6 { color: #f472b6; }
[data-theme="dark"] .sdp .sd-c7 { color: #22d3ee; } [data-theme="dark"] .sdp .sd-c8 { color: #fbbf24; }
[data-theme="dark"] .sdp .sd-c9 { color: #cbd5e1; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .sdp .sd-c1 { color: #f87171; } :root:not([data-theme="light"]) .sdp .sd-c2 { color: #60a5fa; }
    :root:not([data-theme="light"]) .sdp .sd-c3 { color: #4ade80; } :root:not([data-theme="light"]) .sdp .sd-c4 { color: #fb923c; }
    :root:not([data-theme="light"]) .sdp .sd-c5 { color: #a78bfa; } :root:not([data-theme="light"]) .sdp .sd-c6 { color: #f472b6; }
    :root:not([data-theme="light"]) .sdp .sd-c7 { color: #22d3ee; } :root:not([data-theme="light"]) .sdp .sd-c8 { color: #fbbf24; }
    :root:not([data-theme="light"]) .sdp .sd-c9 { color: #cbd5e1; }
}
.sd-pic-img { width: 84%; height: 84%; object-fit: cover; border-radius: 12%; display: block; pointer-events: none; }
.sd-pic-miss { color: var(--muted, #9ca3af); }
.sdp.is-pic .sdp-cell { font-size: calc(56cqw / var(--n)); }
.sdp.is-pic .sdp-cell.is-given { background-image: linear-gradient(var(--sd-peer), var(--sd-peer)); }
.sdp.is-pic .sdp-key { height: 56px; font-size: 1.6rem; display: flex; align-items: center; justify-content: center; }
.sdp.is-pic .sdp-key .sd-pic-img { width: 40px; height: 40px; }
.sdp-progress { width: min(100%, 520px); height: 12px; border-radius: 999px; background: var(--sd-peer); overflow: hidden; }
.sdp-progress > span { display: block; height: 100%; width: 0; background: var(--accent-color); border-radius: inherit; transition: width .25s ease-out; }
.sdp.is-solved .sdp-progress > span { background: #16a34a; }
/* Tehte märk: kitsas vahe mõlemal pool (tühik oleks fondi järgi eri laiusega) */
.sdp-expr .sd-op, .sds .sds-x .sd-op { margin: 0 .08em; }
.sdp-focus {
    margin: 0; min-height: 1.6em; font-size: 1.5rem; font-weight: 700; line-height: 1.2;
    color: var(--text-primary); font-variant-numeric: tabular-nums;
}
.sdp-status { font-size: 14px; color: var(--text-secondary); min-height: 1.4em; margin: 0; font-variant-numeric: tabular-nums; }
.sdp.is-solved .sdp-status { color: var(--text-primary); font-weight: 600; }

.sdp-pad { width: min(100%, 520px); display: grid; grid-template-columns: repeat(var(--padcols), minmax(0, 1fr)); gap: 8px; }
.sdp-key {
    height: 52px; border-radius: 10px; cursor: pointer; font-size: 1.35rem; font-weight: 600;
    border: 1.5px solid var(--border-color); background: var(--bg-card); color: var(--text-primary);
    font-variant-numeric: tabular-nums; touch-action: manipulation;
    transition: background var(--dur-fast, 150ms), border-color var(--dur-fast, 150ms);
}
.sdp-key:active { scale: 0.97; }
@media (hover: hover) { .sdp-key:hover { border-color: var(--accent-color); } }
.sdp-key.is-done { opacity: .4; }
.sdp.is-notes .sdp-key { border-style: dashed; color: var(--text-secondary); }
.sdp-key-gap { display: none; }
.sdp-tools { width: min(100%, 520px); display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.sdp-tool.is-active { border-color: var(--accent-color); background: var(--sd-accent-soft); color: var(--text-primary); }
@media (max-width: 420px) {
    .sdp-key { height: 46px; font-size: 1.2rem; }
    .sdp-tools .button { font-size: .85rem; padding-inline: .65em; }
}

/* Ekraanil lahendamise aken */
.sd-play-card { width: min(640px, calc(100vw - 16px)); max-height: calc(100dvh - 16px); }
.sd-play-card .modal-card-body { padding: 14px; }

/* ---------- Tööleht (.sds) — sudoku SISU printimisel, pildil ja eelvaates ----------
   Ühine ümbris, päis ja stiilide põhivärvid: css/tooleht.css (laetakse enne seda faili).
   Märgendi teeb app.js sheetHTML(); jooned on SVG (gridSVG — värvid atribuutides). */
.sds .sds-set { display: grid; justify-content: center; align-items: start; gap: 1.4em 1.6em; margin-block: auto; }
.sds .sds-item { display: flex; flex-direction: column; align-items: center; gap: .3em; }
.sds .sds-num { margin: 0; font-size: .9em; font-weight: 700; color: var(--at, var(--a)); line-height: 1; }
.sds .sds-grid {
    position: relative; display: grid;
    grid-template-columns: repeat(var(--n), var(--cell));
    grid-template-rows: repeat(var(--n), var(--cell));
    margin: calc(var(--cell) * var(--bleed));
}
.sds .sds-lines {
    position: absolute;
    left: calc(var(--cell) * var(--bleed) * -1);
    top: calc(var(--cell) * var(--bleed) * -1);
    width: calc(var(--cell) * (var(--n) + 2 * var(--bleed)));
    height: calc(var(--cell) * (var(--n) + 2 * var(--bleed)));
    overflow: visible;
}
.sds .sds-d {
    position: relative; align-self: center; justify-self: center;
    font-size: calc(var(--cell) * .6); line-height: 1; font-weight: 700; color: var(--ink);
    font-variant-numeric: tabular-nums;
}
.sds .sds-d.sds-a { font-weight: 500; }
.sds .sds-d.sds-x { white-space: nowrap; letter-spacing: -0.01em; }
/* Pildilahter täidab ruudu (protsendid lahtri suhtes — --cell on em-ides ja img-i fondi järgi vale) */
.sds .sds-p { align-self: stretch; justify-self: stretch; display: flex; align-items: center; justify-content: center; }
.sds .sds-p .sd-pic-img { width: 84%; height: 84%; max-width: none; }
.sds.srs--lihtne .sd-pic { color: #000; }   /* must-valge: kuju eristab */
.sds.srs--klassikaline .sds-d, .sds.srs--joonestik .sds-d { font-family: 'Libre Franklin', 'Figtree', sans-serif; }
.sds.srs--joonestik .sds-d.sds-a { font-family: 'JetBrains Mono', monospace; }
.sds.srs--mang .sds-num { color: var(--d); font-size: 1.1em; }
.sds.srs--lihtne .sds-num { color: #000; }
.sr-style-thumb .sds { gap: .6em; }
.sr-style-thumb .sds .sds-set { margin-block: 0; }

/* Printimise konteiner: ekraanil peidus; printimisel ainult see */
#printContent { display: none; }
@media print {
    /* Kaks taset, sest sisu on <main id="sisu"> maamärgi sees (includes/head.php) */
    body > *:not(#printContent):not(main),
    main > *:not(#printContent) { display: none !important; }
    :root { color-scheme: light !important; }
    html, body, main { background: #fff !important; margin: 0 !important; padding: 0 !important; }
    #printContent { display: block !important; }
    #printContent .srs-page > .srs { margin: 0 auto; }
}
