/*
   Sudoku. Same palette as Word Guess, Word Pool and the MAUI app's
   Colors.xaml — if one changes, change the others.

   A cell is either GIVEN, or the player's own. Verdigris is reserved for the
   player's work; the givens are a third colour so the grid never
   congratulates anyone for a digit it supplied itself.
*/
:root {
    --page-top: #F4EBD8;
    --page-mid: #ECE0C4;
    --page-end: #E0D0AE;

    --ink: #3A2E1C;
    --ink-dim: #6B5B42;

    --accent: #7A4E0F;
    --on-accent: #F8F0DC;

    --tray-edge: #C2AE8A;

    --anchor: #4A3A22;
    --on-anchor: #F8F0DC;

    --placed: #2F6E59;
    --on-placed: #FFFFFF;

    --given-fill: #DFCFA8;
    --peer-fill: rgba(122, 78, 15, 0.10);
    --sel-fill: rgba(122, 78, 15, 0.16);
    --bad-fill: rgba(154, 59, 42, 0.12);
    --boxline: #8A7147;
    --cellline: #C2AE8A;

    /* Differs from the accent in LIGHTNESS as well as hue, so a full line
       that is not a word is separable without relying on colour alone. */
    --wrong: #9A3B2A;

    --typed-fill: #FFFCF4;
    --on-typed: #2A1D0A;

    --empty-fill: rgba(255, 255, 255, 0.45);
    --empty-stroke: #B9A179;
    --filled-stroke: #8A7147;

    --key-face: #FDF8EA;
    --key-text: #3A2E1C;
    --key-edge: #C6B694;

    --tile-radius: 7px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --page-top: #2A1D13;
        --page-mid: #1E150D;
        --page-end: #150F08;

        --ink: #E6DAC4;
        --ink-dim: #A3927A;

        --accent: #C9A227;
        --on-accent: #150F08;

        --tray-edge: #3E3226;

        --anchor: #6B5B42;

        --placed: #357A64;
        --wrong: #D08A72;

        --given-fill: #2E2318;
        --peer-fill: rgba(201, 162, 39, 0.08);
        --sel-fill: rgba(201, 162, 39, 0.18);
        --bad-fill: rgba(208, 138, 114, 0.14);
        --boxline: #6B5B42;
        --cellline: #3E3226;

        --typed-fill: #F0E4CC;

        --empty-fill: rgba(230, 218, 196, 0.06);
        --empty-stroke: #3E3226;

        --key-face: #3A2E22;
        --key-text: #E6DAC4;
        --key-edge: #140E07;
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
}

body {
    background: linear-gradient(180deg, var(--page-top) 0%, var(--page-mid) 52%, var(--page-end) 100%);
    background-attachment: fixed;
    color: var(--ink);
    font-family: "Outfit", system-ui, -apple-system, "Segoe UI", sans-serif;
    -webkit-text-size-adjust: 100%;
}

.booting {
    display: grid;
    place-items: center;
    min-height: 100svh;
    color: var(--ink-dim);
}

/*
   HEIGHT, not min-height, on 100svh, so the document can never scroll and the
   keyboard can never slide under iOS Safari's floating address bar. The grid
   is the one region allowed to scroll inside itself, for the short screen
   where four rows plus a keyboard will not quite fit.
*/
.sudoku-page {
    height: 100svh;
    outline: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 14px 12px calc(12px + env(safe-area-inset-bottom));
    max-width: 480px;
    margin: 0 auto;
}

header { text-align: center; flex: none; }

h1 {
    margin: 0;
    font-size: clamp(22px, 6.8vw, 30px);
    font-weight: 700;
    letter-spacing: 0.22em;
    /* Compensates for the trailing letter-space, which would otherwise push
       the words visually off-centre. */
    text-indent: 0.22em;
    color: var(--accent);
}

.puzzle-no {
    margin: 4px 0 0;
    font-size: 11px;
    letter-spacing: 0.24em;
    text-transform: uppercase;
    color: var(--ink-dim);
}

.modes {
    flex: none;
    display: flex;
    gap: 8px;
}

.chip {
    height: 30px;
    border: 1.5px solid var(--tray-edge);
    border-radius: 8px;
    background: transparent;
    color: var(--ink-dim);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.chip.wide {
    padding: 0 20px;
    font-size: 12px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.chip.on {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--on-accent);
}

.tally {
    flex: none;
    font-size: 13px;
    font-weight: 600;
}

.tally .filled-none { color: var(--ink-dim); }
.tally .filled-some { color: var(--placed); }

/* ---- the grid ---- */

.gridwrap {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: safe center;
    padding: 2px 0;
}

.board {
    display: grid;
    grid-template-columns: repeat(9, minmax(0, 1fr));
    width: min(100%, 360px);
    border: 2px solid var(--boxline);
    border-radius: 4px;
    overflow: hidden;
}

.cell {
    aspect-ratio: 1;
    width: 100%;
    display: grid;
    place-items: center;
    border: 1px solid var(--cellline);
    font: inherit;
    font-size: clamp(15px, 4.6vw, 21px);
    font-weight: 600;
    cursor: pointer;
    user-select: none;
    padding: 0;
}

/*
   The 3x3 boxes. A Sudoku is unreadable without them, and they cannot be
   drawn by the container — each cell on a box edge carries the heavy line
   itself.
*/
.cell.boxleft { border-left: 2px solid var(--boxline); }
.cell.boxtop  { border-top: 2px solid var(--boxline); }

/* Given: supplied by the puzzle, never the player's achievement. */
.cell.given {
    background: var(--given-fill);
    color: var(--ink);
    cursor: default;
}

.cell.placed {
    background: var(--empty-fill);
    color: var(--placed);
}

.cell.empty { background: var(--empty-fill); }

/*
   The row, column and box of the selected cell — the scan a player would
   otherwise do with a finger.

   Laid OVER the cell's own fill with a flooding inset shadow rather than
   replacing the background. Replacing it wipes out whether the cell is a
   given, which is the single most important thing the grid has to show.
*/
.cell.peer { box-shadow: inset 0 0 0 999px var(--peer-fill); }

/* Ring first so it paints above the flood. */
.cell.selected {
    box-shadow: inset 0 0 0 2px var(--accent),
                inset 0 0 0 999px var(--sel-fill);
}

/*
   A digit that duplicates another in its row, column or box. Flagged on
   CONFLICT rather than on disagreeing with the filed answer — a digit can be
   uncontradicted and still not part of the solution, and marking those would
   turn the grid into a guessing game against the computer.
*/
.cell.bad {
    color: var(--wrong);
    box-shadow: inset 0 0 0 999px var(--bad-fill);
}

/* A conflicting digit in the selected cell needs both the ring and the warning. */
.cell.bad.selected {
    box-shadow: inset 0 0 0 2px var(--accent),
                inset 0 0 0 999px var(--bad-fill);
}

/* ---- the tray: pinned, never scrolls ---- */

.tray {
    flex: none;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.done {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.done-note {
    margin: 0;
    font-size: 12px;
    color: var(--ink-dim);
}

.message {
    margin: 0;
    min-height: 1.3em;
    font-size: 13px;
    font-weight: 600;
    text-align: center;
}

.message.warn { color: var(--ink-dim); }
.message.win  { color: var(--placed); }

.keypad {
    width: 100%;
    max-width: 400px;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 6px;
}

.key {
    min-width: 0;
    height: 46px;
    border: none;
    border-radius: 7px;
    background: var(--key-face);
    color: var(--key-text);
    box-shadow: 0 1.5px 0 var(--key-edge);
    font: inherit;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
}

/* All nine placed. Dimmed rather than disabled — one of them may be in the
   wrong cell, and the player needs to be able to re-enter it after erasing. */
.key.done { opacity: 0.35; }

.key.erase { font-size: 18px; }

.actions {
    min-height: 34px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
}

.btn {
    border: 1.5px solid var(--accent);
    border-radius: 18px;
    padding: 7px 16px;
    background: transparent;
    color: var(--accent);
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.btn.ok {
    border-color: var(--placed);
    background: var(--placed);
    color: var(--on-placed);
}

.btn.hint {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn.hint .left {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    opacity: 0.7;
}

/* ---- site line ---- */

.siteline {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    text-align: center;
}

.siteline .home {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    color: var(--ink-dim);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.03em;
}

.siteline .home:hover { color: var(--ink); }

.siteline .home img { display: block; }

/*
   The other games. One line under the keyboard, in the strip that is already
   expendable to iOS Safari's floating address bar — so it costs nothing that
   matters if it gets covered. Each game lists the other three.
*/
.alsoplay {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: baseline;
    gap: 2px 7px;
    font-size: 11px;
    color: var(--ink-dim);
}

.alsoplay .lead { opacity: 0.65; }

.alsoplay .sep { opacity: 0.45; }

.alsoplay a {
    color: var(--ink-dim);
    font-weight: 600;
    text-decoration: none;
    border-bottom: 1px solid transparent;
}

.alsoplay a:hover {
    color: var(--ink);
    border-bottom-color: var(--empty-stroke);
}


.siteline small {
    font-size: 10.5px;
    line-height: 1.35;
    color: var(--ink-dim);
    opacity: 0.7;
    max-width: 420px;
    text-wrap: balance;
}

/*
   On a desktop window the column stops filling the viewport and closes up.
   min-height is 0, not 100svh: filling the viewport is a phone behaviour, and
   on a monitor it strands the keyboard at the bottom with a void above it.
*/
@media (min-width: 520px) and (min-height: 760px) {
    .sudoku-page {
        height: auto;
        min-height: 0;
        padding-top: 28px;
        gap: 14px;
    }

    .gridwrap {
        overflow-y: visible;
        flex: none;
    }
}

.notfound { padding: 40px; text-align: center; }

#blazor-error-ui {
    display: none;
    position: fixed;
    inset: auto 0 0 0;
    padding: 12px 16px;
    background: #7A1F1F;
    color: #fff;
    font-size: 14px;
    z-index: 100;
}

#blazor-error-ui .reload { color: #fff; }
