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

   The one addition is a set of eight number colours. Classic Minesweeper uses
   saturated primaries on grey, which would be jarring here, so these are
   adapted into the warm scheme while keeping the thing that actually matters:
   eight adjacent digits a player can tell apart at a glance, differing in
   lightness as well as hue.
*/
:root {
    --page-top: #F4EBD8;
    --page-mid: #ECE0C4;
    --page-end: #E0D0AE;

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

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

    --tray-edge: #C2AE8A;

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

    --wrong: #9A3B2A;

    --boxline: #8A7147;
    --cellline: #C2AE8A;

    /* A closed cell is raised, an open one is flat and recessed. */
    --shut-face: #DFCFA8;
    --shut-light: #F2E6C9;
    --shut-dark: #BFA87C;

    --open-face: rgba(255, 255, 255, 0.42);

    --flag-ink: #9A3B2A;
    --mine-ink: #3A2E1C;
    --boom-face: #C7705C;

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

    --n1: #2A5C8A;
    --n2: #2F6E59;
    --n3: #9A3B2A;
    --n4: #5B3E8C;
    --n5: #8A5A1A;
    --n6: #1F7A77;
    --n7: #3A2E1C;
    --n8: #6B5B42;

    /* Twelve columns inside this is a 30px cell, which is the floor for a grid
       where every neighbour is also a live tap target. Raising this without
       raising the column count is safe; raising the column count is not. */
    --board-max: 360px;
}

@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;

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

        --boxline: #6B5B42;
        --cellline: #3E3226;

        --shut-face: #3A2E22;
        --shut-light: #4C3D2E;
        --shut-dark: #241B12;

        --open-face: rgba(230, 218, 196, 0.06);

        --flag-ink: #D08A72;
        --mine-ink: #E6DAC4;
        --boom-face: #8A3A28;

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

        --n1: #7FB2DD;
        --n2: #6ABF9F;
        --n3: #E09078;
        --n4: #AE92DC;
        --n5: #D9AE63;
        --n6: #63C2BE;
        --n7: #E6DAC4;
        --n8: #A3927A;
    }
}

* { 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
   tray can never slide under iOS Safari's floating address bar. The field is
   the one region allowed to scroll inside itself, which it has to be: Expert
   is twenty-four rows tall and will not fit a phone at any usable cell size.
*/
.mines-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(20px, 6.2vw, 28px);
    font-weight: 700;
    letter-spacing: 0.2em;
    /* Compensates for the trailing letter-space, which would otherwise push
       the word visually off-centre. */
    text-indent: 0.2em;
    color: var(--accent);
}

.puzzle-no {
    margin: 4px 0 0;
    font-size: 11px;
    letter-spacing: 0.16em;
    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;
}

/* Three difficulties have to fit a 360px line, so they get less padding than
   the two-chip rows in the other games. */
.modes.three .chip.wide {
    padding: 0 12px;
    letter-spacing: 0.06em;
}

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

/* ---- mine counter, clock, new board ---- */

.status {
    flex: none;
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 15px;
    font-weight: 700;
    /* Tabular figures so neither the clock nor the counter nudges the row
       sideways as the digits change. */
    font-variant-numeric: tabular-nums;
}

.status .counter {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: var(--ink);
}

.status .counter .glyph { color: var(--flag-ink); }

/* Over-flagged. Worth showing rather than clamping at zero: it is the player's
   own bookkeeping telling them something is wrong. */
.status .counter.over { color: var(--wrong); }

.status .clock {
    color: var(--ink-dim);
    min-width: 3.4em;
    text-align: center;
}

.chip.new {
    padding: 0 14px;
    font-size: 11px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

/* ---- the field ---- */

.fieldwrap {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    /* safe center: centres a short board, but falls back to the top for a tall
       one instead of clipping both ends of it. */
    justify-content: safe center;
    padding: 2px 0;
    /* Vertical panning stays with the browser; everything else is ours. Without
       this, iOS steals the gesture for double-tap zoom. */
    touch-action: pan-y;
}

.board {
    display: grid;
    grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
    width: min(100%, var(--board-max));
    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-weight: 700;
    /* Scales with the cell, which is itself a function of the column count, so
       one rule covers nine columns at 40px and twelve at 30px. */
    font-size: clamp(11px, calc(var(--board-max) / var(--cols) * 0.58), 22px);
    line-height: 1;
    cursor: pointer;
    padding: 0;
    /*
       The three properties that stop iOS fighting a long press. Without the
       callout and the selection block, holding a cell pops the system
       selection bubble over the board mid-game.
    */
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    touch-action: manipulation;
}

/* Closed: raised, and the only cell a tap can do anything to. */
.cell.shut {
    background: var(--shut-face);
    box-shadow: inset 1.5px 1.5px 0 var(--shut-light),
                inset -1.5px -1.5px 0 var(--shut-dark);
}

/* Touch-down feedback. The press has to acknowledge itself before the 400ms
   hold resolves, or the player cannot tell whether it registered. */
.cell.shut:active { background: var(--shut-dark); }

.cell.open {
    background: var(--open-face);
    color: var(--ink);
    cursor: default;
}

.cell.flag { color: var(--flag-ink); }

.cell.mine { color: var(--mine-ink); }

/* The one that was hit. Distinct from the mines that were merely never found,
   so a loss is legible instead of mysterious. */
.cell.boom {
    background: var(--boom-face);
    color: #FFFFFF;
    box-shadow: none;
}

/* A flag on a safe cell, shown only after the game ends. The strike is what
   says "this was the mistake" rather than just leaving the flag there. */
.cell.misflag {
    color: var(--ink-dim);
    text-decoration: line-through;
    text-decoration-thickness: 2px;
    text-decoration-color: var(--wrong);
}

/* Once the game is over nothing is clickable, and the field says so. */
.board.over .cell { cursor: default; }

.board.over.lost { border-color: var(--wrong); }

.board.over.won { border-color: var(--placed); }

.cell.n1 { color: var(--n1); }
.cell.n2 { color: var(--n2); }
.cell.n3 { color: var(--n3); }
.cell.n4 { color: var(--n4); }
.cell.n5 { color: var(--n5); }
.cell.n6 { color: var(--n6); }
.cell.n7 { color: var(--n7); }
.cell.n8 { color: var(--n8); }

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

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

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

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

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

.tools {
    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.mode {
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.btn.mode.on {
    background: var(--accent);
    color: var(--on-accent);
}

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

.stats {
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 2px 7px;
    min-height: 1.2em;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--ink-dim);
    text-align: center;
}

.stats .sep { opacity: 0.45; }

/* Shown in place of the record until there is a record to show, so the two
   gestures a new player cannot guess are stated once and then get out of the
   way for good. */
.stats .hint-line { font-weight: 500; opacity: 0.85; }

/* ---- 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; }

.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 tray at the bottom with a void above it.

   The field stops scrolling inside itself here and simply makes the page tall,
   which is the right behaviour for Expert on a monitor.
*/
@media (min-width: 520px) and (min-height: 760px) {
    :root { --board-max: 400px; }

    .mines-page {
        height: auto;
        min-height: 0;
        padding-top: 28px;
        gap: 14px;
    }

    .fieldwrap {
        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; }
