/*
   Word Square. 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 given letters are a third colour so the grid never
   congratulates anyone for a letter 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;

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

        --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.
*/
.square-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;
    /* Needed, not decorative: without it this is a shrink-to-fit flex item,
       and the board's min(100%, 272px) then resolves against its own collapsed
       content width instead of the page, halving the grid. */
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    /* "safe" so an overflowing grid falls back to top-aligned rather than
       clipping its first row, which is what plain centring does. */
    justify-content: safe center;
    gap: 10px;
    padding: 2px 0;
}

.board {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    width: min(100%, 272px);
}

.sq {
    aspect-ratio: 1;
    width: 100%;
    display: grid;
    place-items: center;
    border-radius: var(--tile-radius);
    border: 2px solid transparent;
    font: inherit;
    font-size: 24px;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
    padding: 0;
}

/* Given: supplied by the puzzle, never the player's achievement. */
.sq.given {
    background: var(--anchor);
    border-color: var(--anchor);
    color: var(--on-anchor);
    cursor: default;
}

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

.sq.empty {
    background: var(--empty-fill);
    border-color: var(--empty-stroke);
}

/* The cell the keyboard writes into. */
.sq.selected {
    border-color: var(--accent);
    border-width: 3px;
}

/*
   Sits in a line that is full but is not a word. Marked rather than refused:
   a letter can be wrong only in combination, and refusing it as it is typed
   would mean the grid solving itself one keystroke at a time.
*/
.sq.bad {
    background: var(--typed-fill);
    border-color: var(--wrong);
    color: var(--wrong);
}

.badlines {
    margin: 0;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: var(--wrong);
    text-align: center;
}

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

.keyboard {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.krow {
    display: flex;
    gap: 4px;
    justify-content: center;
}

.key {
    flex: 1 1 0;
    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;
}

.key.wide { flex: 1.6 1 0; font-size: 11px; letter-spacing: 0.06em; }

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

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