/* The Sudoku page (S9 of plans/plan-suduku.md).

   The 2020 research project injected its styles from JavaScript, in a
   makeStyles() function. These live here instead, which is where every other
   page on this site keeps them, and which is what lets the board print. */

/* --- controls ----------------------------------------------------------- */
.jl-sudoku-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin: 15px 0;
}

.jl-sudoku-label {
    font-weight: bold;
}

.jl-sudoku-difficulty {
    min-height: 44px;
    padding: 6px 8px;
    /* 16px or iOS zooms the page in when the control takes focus */
    font-size: 16px;
    font-family: inherit;
}

.jl-sudoku-button {
    min-height: 44px;
    padding: 8px 16px;
    border: solid 1px #1f3864;
    border-radius: 4px;
    background-color: #fff;
    color: #1f3864;
    font-family: inherit;
    font-size: 16px;
    cursor: pointer;
}

.jl-sudoku-button:hover {
    background-color: #eef1f8;
}

.jl-sudoku-button:disabled {
    opacity: 0.45;
    cursor: default;
}

.jl-sudoku-timer-label {
    margin-left: auto;
    font-weight: bold;
}

/* tabular-nums so the time does not jiggle as the digits change */
.jl-sudoku-timer {
    min-width: 4.5em;
    font-variant-numeric: tabular-nums;
    font-size: 16px;
}

.jl-sudoku-status {
    min-height: 1.4em;
    margin-bottom: 10px;
    font-size: 14px;
    color: #555;
}

/* A failure reads differently from a count of clues, so the module marks it
   rather than relying on the words alone. */
.jl-sudoku-status-error {
    color: red;
    font-weight: bold;
}

/* Winning should not read like a validation failure. */
.jl-sudoku-status-won {
    color: #1b5e20;
    font-weight: bold;
}

/* --- the board ---------------------------------------------------------- */
/* Nine columns of equal width, so the board is square at any size. The outer
   border is the heavy one; the inner box borders come from the cells. */
.jl-sudoku-board {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    width: min(90vw, 450px);
    border: solid 2px #000;
    background-color: #fff;
}

.jl-sudoku-cell {
    /* square cells whatever the board's width */
    aspect-ratio: 1;
    width: 100%;
    min-width: 0;
    padding: 0;
    border: solid 1px #bbb;
    background-color: transparent;
    font-family: inherit;
    font-size: clamp(14px, 4.2vw, 22px);
    text-align: center;
    color: #1f3864;
}

.jl-sudoku-cell:focus {
    outline: none;
    background-color: #eef2f9;
}

/* The 3x3 boxes, drawn by thickening the third and sixth seams rather than
   wrapping the cells in nine more elements - which would mean the board could
   not be one CSS grid, and the cells could not be addressed by index. */
.jl-sudoku-cell:nth-child(9n + 4),
.jl-sudoku-cell:nth-child(9n + 7) {
    border-left-width: 2px;
    border-left-color: #000;
}

.jl-sudoku-cell:nth-child(n + 28):nth-child(-n + 36),
.jl-sudoku-cell:nth-child(n + 55):nth-child(-n + 63) {
    border-top-width: 2px;
    border-top-color: #000;
}

/* A clue the puzzle came with, as against a digit the player typed. Readonly
   rather than disabled: a disabled input is skipped by tabbing and is read
   out differently, and these are still part of the puzzle. */
.jl-sudoku-given {
    font-weight: bold;
    color: #000;
    background-color: #f2f2f2;
}

/* Set by Check, on a full board that is wrong, for every digit that clashes
   with another in its row, column or box. Never while the puzzle is being
   filled in: S11 decided the check is the only moment anything is marked. */
.jl-sudoku-conflict {
    color: red;
    background-color: #fdeaea;
}

/* Solved. The board is locked at this point, so this is the end state of a
   puzzle rather than a hint about one. */
.jl-sudoku-solved .jl-sudoku-cell {
    color: #1b5e20;
    background-color: #f1f8f2;
}

.jl-sudoku-solved {
    border-color: #1b5e20;
}

/* --- the answer sheet -------------------------------------------------- */
/* Never on screen. It exists so that printing can include it, and nothing
   else, which is what keeps S11's rule - no help while you play - true even
   though the page now knows the answer. */
.jl-sudoku-solution {
    display: none;
}

/* The cells are divs, so they need the centring an input brought with it. */
.jl-sudoku-solution-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

.jl-sudoku-note {
    margin-top: 12px;
    font-size: 13px;
    color: #666;
}

/* --- printing ----------------------------------------------------------- */
/* Half the point of the page: a puzzle to take away. Controls, status and
   notes go; the board stays, in black, at a size that fills a page sensibly. */
@media print {

    .jl-sudoku-controls,
    .jl-sudoku-status,
    .jl-sudoku-note {
        display: none;
    }

    .jl-sudoku-board {
        width: 17cm;
        border-color: #000;
    }

    .jl-sudoku-cell {
        border-color: #666;
        color: #000;
        /* a printer should not be asked to shade 81 cells */
        background-color: transparent;
        font-size: 20pt;
    }

    .jl-sudoku-given {
        background-color: transparent;
        font-weight: bold;
    }

    .jl-sudoku-solved .jl-sudoku-cell,
    .jl-sudoku-conflict {
        color: #000;
        background-color: transparent;
    }

    /* The answer sheet prints only once Print with solution has filled it,
       so a plain Print is still just the puzzle. On its own page: an answer
       beside the puzzle it answers is no use to anybody. */
    .jl-sudoku-solution-ready {
        display: block;
        break-before: page;
        page-break-before: always;
    }

    .jl-sudoku-solution-heading {
        margin: 0 0 10px 0;
        font-size: 18pt;
    }
}
