/*
 * निहारिका सुडोकू — the board and its controls.
 *
 * Was an inline <style> block in the view. Moved out because the game it dresses is no longer a
 * grid and ten buttons: pencil marks, peer highlighting, a pad that counts itself down and a
 * paused state all have to look right in both themes, on a phone, and on paper.
 *
 * Every colour is a token defined once on :root and redefined for dark. Nothing below states a
 * colour literally, so the two themes cannot drift apart one rule at a time.
 */

.sk {
    --sk-ink: #111;
    --sk-ink-soft: #666;
    --sk-cell: #fff;
    --sk-given: #f2f2f2;
    --sk-line: #c9c9c9;
    --sk-rule: #222;
    --sk-accent: #1d4ed8;
    --sk-accent-soft: #dbeafe;
    --sk-peer: #f1f5fd;
    --sk-same: #cfe0fb;
    --sk-bad: #c0261f;
    --sk-bad-soft: #fdeceb;
    --sk-good: #15803d;
    --sk-good-soft: #f0fdf4;
    --sk-hint: #b45309;
    --sk-hint-soft: #fef3c7;
    --sk-surface: #fafafa;
    --sk-surface-line: #ddd;

    max-width: 34rem;
    margin: 0 auto;
    padding: 1rem 1rem 2rem;
    color: var(--sk-ink);
}

@media (prefers-color-scheme: dark) {
    .sk {
        --sk-ink: #ededed;
        --sk-ink-soft: #a3a3a3;
        --sk-cell: #171717;
        --sk-given: #262626;
        --sk-line: #3f3f3f;
        --sk-rule: #8a8a8a;
        --sk-accent: #60a5fa;
        --sk-accent-soft: #1e3a5f;
        --sk-peer: #1e2530;
        --sk-same: #294061;
        --sk-bad: #f87171;
        --sk-bad-soft: #3a1f1f;
        --sk-good: #4ade80;
        --sk-good-soft: #14301f;
        --sk-hint: #fbbf24;
        --sk-hint-soft: #3a2f14;
        --sk-surface: #1f1f1f;
        --sk-surface-line: #3f3f3f;
    }
}

/* ── heading ─────────────────────────────────────────────────────────────── */

.sk__head h1 { font-size: 1.4rem; margin: 0 0 .15rem; }
.sk__meta { color: var(--sk-ink-soft); font-size: .95rem; margin: 0 0 .3rem; }
.sk__meta a { color: inherit; }

.sk__status {
    display: flex; align-items: center; gap: .5rem;
    margin: 0 0 .7rem; font-variant-numeric: tabular-nums;
}
.sk__clock { font-size: 1.05rem; font-weight: 600; min-width: 3.6em; }
.sk__pause {
    border: 1px solid var(--sk-surface-line); background: var(--sk-surface); color: inherit;
    border-radius: 999px; padding: .2rem .7rem; font: inherit; font-size: .85rem; cursor: pointer;
}
.sk__pause:hover { border-color: var(--sk-accent); }
.sk__errors { margin-left: auto; color: var(--sk-ink-soft); font-size: .85rem; }
.sk__errors[data-has-errors="1"] { color: var(--sk-bad); font-weight: 600; }

/* ── board ───────────────────────────────────────────────────────────────── */

.sk__board { position: relative; }

.sk__grid {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    border: 2px solid var(--sk-rule);
    background: var(--sk-line);
    gap: 1px;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.sk__cell {
    position: relative;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--sk-cell);
    color: var(--sk-accent);
    font-size: clamp(17px, 5.4vw, 27px);
    line-height: 1;
    cursor: pointer;
    /* The cell IS the touch target; nothing inside it should swallow a tap. */
    -webkit-tap-highlight-color: transparent;
}
.sk__cell > * { pointer-events: none; }

/* The three-square rules that make the boxes readable. `gap` draws the thin lines; these draw
   the thick ones, as shadows so they cost no layout and never shift a digit by a pixel. */
.sk__cell[data-c="2"], .sk__cell[data-c="5"] { box-shadow: 1px 0 0 0 var(--sk-rule); }
.sk__cell[data-r="2"], .sk__cell[data-r="5"] { box-shadow: 0 1px 0 0 var(--sk-rule); }
.sk__cell[data-c="2"][data-r="2"], .sk__cell[data-c="2"][data-r="5"],
.sk__cell[data-c="5"][data-r="2"], .sk__cell[data-c="5"][data-r="5"] {
    box-shadow: 1px 0 0 0 var(--sk-rule), 0 1px 0 0 var(--sk-rule);
}

.sk__cell.is-given { background: var(--sk-given); color: var(--sk-ink); font-weight: 700; cursor: default; }
.sk__cell.is-peer { background: var(--sk-peer); }
.sk__cell.is-given.is-peer { background: var(--sk-given); }
.sk__cell.is-same { background: var(--sk-same); }
.sk__cell.is-hinted { color: var(--sk-hint); }
.sk__cell.is-bad { background: var(--sk-bad-soft); color: var(--sk-bad); }
.sk__cell.is-wrong { background: var(--sk-bad-soft); color: var(--sk-bad); text-decoration: line-through; }

.sk__cell.is-sel { background: var(--sk-accent-soft); }
.sk__cell.is-sel::after {
    content: ""; position: absolute; inset: 0;
    outline: 3px solid var(--sk-accent); outline-offset: -3px;
}
.sk__cell:focus-visible { outline: none; }
.sk__cell:focus-visible::after {
    content: ""; position: absolute; inset: 0;
    outline: 3px solid var(--sk-accent); outline-offset: -3px;
}

/* Pencil marks: a 3×3 of the nine digits, each in its own place, so the eye finds "is 5 still
   possible here" without reading a list. */
.sk__notes {
    position: absolute; inset: 0;
    display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
    font-size: clamp(7px, 2.1vw, 11px);
    line-height: 1;
    color: var(--sk-ink-soft);
    font-weight: 400;
}
/* An element with its own `display` beats the browser's `[hidden] { display: none }`, so a filled
   square went on showing the pencil marks it had just replaced — visible on the very first hint. */
.sk__notes[hidden] { display: none; }
.sk__notes span { display: flex; align-items: center; justify-content: center; }
/* A SINGLE MARK HIDES IN PLACE, and by a CLASS rather than the `hidden` attribute.
   The nine positions are how the eye finds "is 5 still possible here"; a mark that vanishes from
   the flow lets the others slide up, and 1-5-8 printed as a row across the top of the square with
   no way to tell which digit was which. The browser's own `[hidden] { display: none }` won that
   fight, so nothing here relies on out-styling it. */
.sk__notes span.is-off { visibility: hidden; }
.sk__cell.is-same .sk__notes span.is-match { color: var(--sk-accent); font-weight: 700; }

/* ── paused ──────────────────────────────────────────────────────────────── */

.sk__board.is-paused .sk__grid { filter: blur(7px); pointer-events: none; }
.sk__veil {
    display: none;
    position: absolute; inset: 0;
    align-items: center; justify-content: center;
    background: color-mix(in srgb, var(--sk-cell) 72%, transparent);
    font-weight: 700; font-size: 1.05rem;
}
.sk__board.is-paused .sk__veil { display: flex; }
.sk__veil button {
    font: inherit; cursor: pointer; color: #fff; background: var(--sk-accent);
    border: 0; border-radius: 999px; padding: .6rem 1.4rem;
}

/* ── pad ─────────────────────────────────────────────────────────────────── */

.sk__pad { display: grid; grid-template-columns: repeat(9, 1fr); gap: .35rem; margin-top: .85rem; }
.sk__digit {
    position: relative;
    padding: .75rem 0 1.05rem;
    font: inherit; font-size: 1.3rem;
    background: var(--sk-surface); color: var(--sk-ink);
    border: 1px solid var(--sk-surface-line); border-radius: 10px;
    cursor: pointer;
}
.sk__digit:hover { border-color: var(--sk-accent); }
.sk__digit:active { background: var(--sk-accent-soft); }
.sk__digit .sk__left {
    position: absolute; left: 0; right: 0; bottom: .28rem;
    font-size: .62rem; color: var(--sk-ink-soft); font-variant-numeric: tabular-nums;
}
/* A digit already placed nine times has nothing left to give. It stays operable — erasing one
   should bring it straight back — but it stops competing for the eye. */
.sk__digit.is-done { opacity: .38; }
.sk__digit.is-done .sk__left { visibility: hidden; }

.sk__tools { display: grid; grid-template-columns: repeat(5, 1fr); gap: .35rem; margin-top: .45rem; }
.sk__tool {
    display: flex; flex-direction: column; align-items: center; gap: .15rem;
    padding: .55rem 0; font: inherit; font-size: .78rem;
    background: var(--sk-surface); color: var(--sk-ink);
    border: 1px solid var(--sk-surface-line); border-radius: 10px; cursor: pointer;
}
.sk__tool b { font-size: 1.15rem; font-weight: 500; line-height: 1; }
.sk__tool:hover { border-color: var(--sk-accent); }
.sk__tool--wide { grid-column: 1 / -1; }
.sk__tool[disabled] { opacity: .38; cursor: default; }
.sk__tool[aria-pressed="true"] { background: var(--sk-accent); border-color: var(--sk-accent); color: #fff; }
.sk__tool[aria-pressed="true"] .sk__badge { background: #fff; color: var(--sk-accent); }
.sk__badge {
    font-size: .6rem; padding: 0 .35rem; border-radius: 999px;
    background: var(--sk-accent); color: #fff;
}

/* ── result ──────────────────────────────────────────────────────────────── */

.sk__won {
    display: none;
    margin-top: 1rem; padding: .9rem 1rem;
    border: 1px solid var(--sk-good); border-radius: 10px;
    background: var(--sk-good-soft); color: var(--sk-good);
}
.sk__won.is-shown { display: block; }
.sk__won h2 { margin: 0 0 .3rem; font-size: 1.1rem; }
.sk__won p { margin: .15rem 0; color: var(--sk-ink); }
.sk__won button {
    margin-top: .6rem; font: inherit; cursor: pointer;
    background: var(--sk-good); color: #fff; border: 0; border-radius: 999px; padding: .45rem 1.1rem;
}

.sk__note { margin-top: 1rem; font-size: .85rem; color: var(--sk-ink-soft); }

.sk__answer { margin-top: 1.6rem; }
.sk__answer h2 { font-size: 1.05rem; }
.sk__answer .sk__cell { cursor: default; }

/* Announcements for a screen reader only — the game says out loud what the colours say. */
.sk__sr {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

@media (max-width: 380px) {
    .sk { padding-left: .5rem; padding-right: .5rem; }
    .sk__digit { font-size: 1.15rem; padding: .6rem 0 .95rem; }
}

@media (prefers-reduced-motion: no-preference) {
    .sk__cell { transition: background-color .12s ease; }
}

/* On paper the reader wants the puzzle, not the machinery. */
@media print {
    .sk__pad, .sk__tools, .sk__won, .sk__pause, .sk__note, .sk__veil { display: none !important; }
    .sk__board.is-paused .sk__grid { filter: none; }
    .sk__cell { background: #fff !important; color: #000 !important; }
    .sk__grid { background: #000; }
}
