/*
   Nonogram. Same palette as the other seven games and the MAUI app's
   Colors.xaml — if one changes, change the others.

   The layout problem here is unique in the suite: the clues live OUTSIDE the
   grid, along two edges, so they eat width and height the puzzle itself needs.
   Everything is therefore derived from one number, --board-max, minus a fixed
   clue margin, rather than from percentages.
*/
:root {
    --page-top: #F4EBD8;
    --page-mid: #ECE0C4;
    --page-end: #E0D0AE;

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

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

    --tray-edge: #C2AE8A;

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

    --fill: #3A2E1C;
    --cross: #A3927A;
    --cell-face: rgba(255, 255, 255, 0.4);

    --placed: #2F6E59;

    /*
       Eight or fifteen cells plus the clue margin have to fit inside this.
       The margins are sized to the widest clue lists the picture library
       actually produces — five numbers across a row, four down a column —
       rather than to the theoretical worst case, which no hand-drawn picture
       comes near.
    */
    --board-max: 356px;
    --clue-w: 46px;
    --clue-h: 44px;
}

@media (max-width: 379.98px) {
    :root { --board-max: 318px; --clue-w: 42px; --clue-h: 40px; }
}

@media (min-width: 520px) {
    :root { --board-max: 440px; --clue-w: 54px; --clue-h: 50px; }
}

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

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

        --fill: #E6DAC4;
        --cross: #6B5B42;
        --cell-face: rgba(230, 218, 196, 0.05);

        --placed: #357A64;
    }
}

* { 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);
}

/* Blazor focuses the h1 at load so a screen reader announces the page. This
   game takes no keyboard input, so there is no container to hand focus to and
   the ring would simply sit around the title. The heading is not interactive. */
h1:focus { outline: none; }

/*
   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.
*/
.nono-page {
    height: 100svh;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 12px 10px calc(10px + env(safe-area-inset-bottom));
    max-width: 520px;
    margin: 0 auto;
}

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

h1 {
    margin: 0;
    font-size: clamp(19px, 5.8vw, 26px);
    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: 3px 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;
    padding: 0 14px;
    border: 1.5px solid var(--tray-edge);
    border-radius: 8px;
    background: transparent;
    color: var(--ink-dim);
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.06em;
    cursor: pointer;
}

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

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

.modes.sizes .chip { height: 26px; font-size: 11px; }

/* ---- the rules panel, shown in place of the grid ---- */

.example { margin: 12px 0 14px; }

/* The worked example is inline SVG rather than an image: it scales to any
   width, costs no request, and picks up the game's own cell colours so it
   cannot drift out of step with the board it is describing. */
.exrow {
    display: block;
    width: 100%;
    max-width: 240px;
    height: auto;
}

.example figcaption {
    margin: 3px 0 9px;
    font-size: 11px;
    font-weight: 600;
    color: var(--ink-dim);
}

.ex {
    fill: var(--cell-face);
    stroke: var(--cellline);
    stroke-width: 1;
}

.ex.on { fill: var(--fill); }

.ex.sure { fill: var(--placed); }

/* ---- the puzzle: clues on two edges, grid in the corner ---- */

.gridwrap {
    /*
       0 1 auto, not 1 1 auto: growing to fill the column would leave a band of
       dead space under the grid on the 10x10 puzzles. Shrinking is still
       allowed, so a 15x15 on a short screen still scrolls.
    */
    flex: 0 1 auto;
    min-height: 0;
    width: 100%;
    overflow: auto;
    display: flex;
    justify-content: center;
    /* flex-start, not the default stretch, or the puzzle is stretched to this
       box's height, reports no overflow, and a tall grid has nothing to
       scroll. */
    align-items: flex-start;
    padding: 2px 0 6px;
    touch-action: pan-y;
}

/*
   Do NOT remove. The puzzle is a flex item, so without this it shrinks to
   whatever room is left instead of overflowing — the cells get crushed, the
   wrapper has nothing to scroll, and the bottom rows become unreachable. The
   same bug bit Minesweeper's board and FreeCell's cards.
*/
.puzzle {
    /*
       --cell is declared HERE and not on :root, which matters more than it
       looks. A custom property is substituted against the element it is
       declared on, and --cols only exists here, set inline by the page. Put
       this on :root and it resolves against an undefined --cols, the whole
       declaration is invalid, and the grid collapses to a couple of pixels.
    */
    --cell: calc((var(--board-max) - var(--clue-w)) / var(--cols));

    flex: none;
    display: grid;
    grid-template-columns: var(--clue-w) calc(var(--cell) * var(--cols));
    grid-template-rows: var(--clue-h) calc(var(--cell) * var(--rows));
}

.corner { grid-column: 1; grid-row: 1; }

.colclues {
    grid-column: 2;
    grid-row: 1;
    display: grid;
    grid-template-columns: repeat(var(--cols), var(--cell));
}

.cluecol {
    display: flex;
    flex-direction: column;
    /* Bottom-aligned so the last number of every column sits on the grid edge,
       which is where the run it describes begins. */
    justify-content: flex-end;
    align-items: center;
    gap: 1px;
    padding-bottom: 3px;
    font-size: 10px;
    font-weight: 700;
    line-height: 1.05;
    color: var(--ink-dim);
}

.rowclues {
    grid-column: 1;
    grid-row: 2;
    display: grid;
    grid-template-rows: repeat(var(--rows), var(--cell));
}

.cluerow {
    display: flex;
    align-items: center;
    /* Right-aligned for the same reason the columns are bottom-aligned. */
    justify-content: flex-end;
    gap: 3px;
    padding-right: 4px;
    font-size: 10px;
    font-weight: 700;
    color: var(--ink-dim);
}

/* A line whose filled cells match its clue exactly. Honest but local: a row
   can satisfy its own clue inside a grid that is still wrong overall. */
.cluecol.done,
.cluerow.done {
    color: var(--placed);
    opacity: 0.55;
}

.grid {
    grid-column: 2;
    grid-row: 2;
    display: grid;
    grid-template-columns: repeat(var(--cols), var(--cell));
    border: 2px solid var(--boxline);
}

.cell {
    width: var(--cell);
    height: var(--cell);
    padding: 0;
    border: 1px solid var(--cellline);
    background: var(--cell-face);
    font: inherit;
    line-height: 1;
    cursor: pointer;
    display: grid;
    place-items: center;
    /*
       The three properties that stop iOS interfering: no selection bubble on
       a held cell, no double-tap zoom, no callout.
    */
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    touch-action: manipulation;
}

/*
   Heavier rules every five cells, drawn as inset shadows rather than borders
   so they cannot shift the grid by a pixel.
*/
.cell.bandleft { box-shadow: inset 2px 0 0 var(--boxline); }
.cell.bandtop { box-shadow: inset 0 2px 0 var(--boxline); }
.cell.bandleft.bandtop {
    box-shadow: inset 2px 0 0 var(--boxline), inset 0 2px 0 var(--boxline);
}

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

.cell .x {
    font-size: calc(var(--cell) * 0.62);
    font-weight: 600;
    color: var(--cross);
}

.cell:active { filter: brightness(0.92); }

/*
   The reveal. Once it is solved the working marks get out of the way — the
   crosses vanish and the rules fade — so what is left is the picture, which is
   the entire point of the game.
*/
.puzzle.solved .cell { border-color: transparent; box-shadow: none; cursor: default; }
.puzzle.solved .cell .x { display: none; }
.puzzle.solved .grid { border-color: var(--placed); }

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

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

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

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

.done-block {
    display: flex;
    justify-content: center;
    gap: 8px;
}

.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: #FFFFFF;
}

.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;
    min-height: 1.2em;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--ink-dim);
    text-align: center;
}

.stats .hint-line { font-weight: 500; opacity: 0.85; }

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

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

.siteline .home-link {
    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-link:hover { color: var(--ink); }

.siteline .home-link 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.
*/
@media (min-width: 520px) and (min-height: 760px) {
    .nono-page {
        height: auto;
        min-height: 0;
        padding-top: 24px;
        gap: 12px;
    }

    .gridwrap {
        overflow: 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; }

/*
    ------------------------------------------------------------------
    How to play panel.

    The same shape in all eight games. It REPLACES the board rather than
    sitting above it, so the page never grows a second scrolling region and
    the tray below stays exactly where it was. The chip that opens it is the
    game's own .chip, so nothing new is needed for the button itself.

    Only variables every game defines are used here — ink, ink-dim,
    tray-edge, key-face, key-edge — so this block is byte-identical in all
    eight projects and can be moved between them without translation. Where a
    game has something more specific to say (a mine, a filled cell, a card),
    it adds its own .exc modifier below this block rather than editing it.
    ------------------------------------------------------------------
*/
.help-wrap {
    display: flex;
    /* Do NOT remove. This class is combined with each game's own board
       wrapper, and some of those are column flex containers. Left implicit,
       justify-content below would mean VERTICAL centring in those — which on
       an overflowing panel clips the top and cannot be scrolled back to. Row
       is stated so the rule means the same thing in all eight games. */
    flex-direction: row;
    justify-content: center;
    width: 100%;
    overflow-y: auto;
    /* Do NOT remove. The panel is a flex item in a column layout, so without
       this it is stretched to the wrapper's height, reports no overflow and
       refuses to scroll — the same failure the boards had. */
    align-items: flex-start;
}

.help {
    /* Do NOT remove. Without it a long panel is crushed into whatever room
       the column has left instead of overflowing and scrolling. */
    flex: none;
    width: 100%;
    max-width: 420px;
    background: var(--key-face);
    border: 1px solid var(--tray-edge);
    border-radius: 14px;
    padding: 16px 16px 18px;
    text-align: left;
}

.help h2 {
    margin: 22px 0 8px;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-dim);
}

.help h2:first-child { margin-top: 0; }

.help p {
    margin: 0 0 9px;
    font-size: 15px;
    line-height: 1.45;
    color: var(--ink);
}

.help p:last-child { margin-bottom: 0; }

.help b { font-weight: 700; }

/*
    Caption under a worked example. Dimmer and smaller than body text so the
    example reads as one unit with its explanation rather than as a picture
    dropped into the middle of a paragraph.
*/
.help .cap {
    font-size: 13.5px;
    line-height: 1.4;
    color: var(--ink-dim);
    margin: 7px 0 2px;
}

/*
    Worked examples use a fixed 30px cell rather than the board's own sizing.
    These are illustrations at a readable size, not a playable board that has
    to fit a phone, so they must not inherit the grid's responsive cell.
*/
.help .exboard {
    display: inline-block;
    margin: 10px 0 0;
}

.help .exline { display: flex; }

.help .exc {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    /* Falls back to the key edge in the games that have no cell rule of their
       own, so this block needs no per-game edit. */
    border: 1px solid var(--cellline, var(--key-edge));
    background: var(--key-face);
    color: var(--ink);
}
