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

   Names describe the role, not the colour, because the role survives a theme
   change and the colour does not.

   Found is verdigris, the same green a correct letter gets in Word Guess, so
   the two games mean the same thing by the same colour.
*/
:root {
    --page-top: #F4EBD8;
    --page-mid: #ECE0C4;
    --page-end: #E0D0AE;

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

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

    --tray-edge: #C2AE8A;

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

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

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

        --found: #357A64;

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

/*
   The lesson from Word Guess, applied up front rather than retrofitted.

   iOS Safari's address bar collapses to a pill that floats OVER the page, and
   env(safe-area-inset-bottom) covers only the home indicator, not that pill.
   In Word Guess the page was taller than the screen, so the bottom keyboard
   row scrolled under the pill and became untappable.

   Two things prevent that here. HEIGHT, not min-height, on 100svh: svh is the
   viewport with the browser chrome fully expanded, so the page can never grow
   past what is certainly visible, and the document never scrolls. And the slot
   list — the only part whose size varies, because a rack yields anywhere from
   ten to twenty-one answers — is the one thing allowed to scroll, inside
   itself. The tray below it is pinned and cannot move whatever the rack holds.

   The footer is the last line of defence: it sits below the buttons so that if
   anything is covered, it is a credit line rather than the Enter key.
*/
.pool {
    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(24px, 7.5vw, 32px);
    font-weight: 700;
    letter-spacing: 0.22em;
    /* Compensates for the trailing letter-space, which would otherwise push
       the word 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);
}

/* Shown only once the slots are all filled. The tray stays live underneath —
   the bonus hunt outlives the board. */
.done {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

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

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

.tally {
    flex: none;
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 13px;
    font-weight: 600;
}

.tally .slots-none { color: var(--ink-dim); }
.tally .slots-found { color: var(--found); }
.tally .bonus-none { color: var(--ink-dim); opacity: 0.6; }
.tally .bonus-some { color: var(--ink-dim); }
.tally .sep { color: var(--empty-stroke); }

/* ---- the answer slots ---- */

.slots {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
    /* Room for the last row's descender against the fade of the scroll edge. */
    padding-bottom: 2px;
}

.slots section {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.slots h2 {
    margin: 0;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--ink-dim);
}

.slot-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.slot {
    display: flex;
    gap: 3px;
}

.cell {
    width: 20px;
    height: 20px;
    display: grid;
    place-items: center;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    user-select: none;
}

.cell.blank {
    background: var(--empty-fill);
    border: 1.5px solid var(--empty-stroke);
}

.cell.filled {
    background: var(--found);
    border: 1.5px solid var(--found);
    color: var(--on-found);
}

/*
   A revealed letter is NOT a found one, and must not be mistaken for one.
   Verdigris means "you got this"; a hint is the page's accent on a pale
   ground — legible, clearly a letter, and clearly not an achievement.
*/
.cell.hinted {
    background: var(--typed-fill);
    border: 1.5px dashed var(--accent);
    color: var(--accent);
}

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

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

/* Holds its height when the button is gone, so the tray does not jump as the
   last press is spent. */
.hint-row {
    min-height: 34px;
    display: flex;
    align-items: center;
}

.btn.hint {
    padding: 6px 16px;
    font-size: 12px;
    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;
}

.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(--found); }

.entry {
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
}

.entry-hint {
    font-size: 13px;
    color: var(--ink-dim);
    opacity: 0.75;
}

.typed {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: 7px;
    background: var(--typed-fill);
    border: 2px solid var(--filled-stroke);
    color: var(--on-typed);
    font-size: 18px;
    font-weight: 600;
    user-select: none;
}

/* The bonus confirmation. Shown in place of nothing, cleared on the next key. */
.typed.bonus {
    background: var(--found);
    border-color: var(--found);
    color: var(--on-found);
}

.rack {
    display: flex;
    gap: 6px;
}

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

.key.spent {
    opacity: 0.3;
    cursor: default;
}

.actions {
    display: flex;
    gap: 8px;
}

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

.btn.primary {
    background: var(--accent);
    color: var(--on-accent);
    padding: 8px 26px;
}

/* ---- 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,
   at the same breakpoint Word Guess uses. The slot list gets its natural
   height back and the page scrolls normally if a rack is unusually dense.

   min-height is 0, NOT 100svh. Filling the viewport is a phone behaviour: it
   exists so the tray sits under the thumb. In a tall desktop window the same
   rule strands the tray at the bottom of the screen with several hundred
   pixels of nothing above it, because a fourteen-word rack does not come
   close to filling a monitor. Let the column be as tall as its contents.
*/
@media (min-width: 520px) and (min-height: 760px) {
    .pool {
        height: auto;
        min-height: 0;
        padding-top: 28px;
        gap: 14px;
    }

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