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

   The ladder has three kinds of filled cell and they must not be confused:
   the two ANCHOR rows are given, a PLACED rung is the player's own, and a
   HINTED rung was handed over. Verdigris is reserved for the player's work.
*/
: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;

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

        --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
   ladder is the one region allowed to scroll inside itself — it is the only
   part whose size varies, from four rows to seven.
*/
.ladder-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 .rungs-none { color: var(--ink-dim); }
.tally .rungs-done { color: var(--placed); }

/* ---- the ladder ---- */

.ladder {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    /* Centred in whatever room is left, because the ladder is 4 rows on a
       two-rung puzzle and 7 on a five-rung one — pinned to the top, the short
       ones leave a void above the keyboard. "safe" so that an overflowing
       ladder falls back to top-aligned instead of clipping its first rung,
       which is what plain centring does to an overflowing flex column. */
    justify-content: safe center;
    gap: 6px;
    padding: 2px 0;
}

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

/* The given ends are set apart so the climb between them reads as the task. */
.rung.given + .rung { margin-top: 6px; }
.rung:last-child { margin-top: 6px; }

.cell {
    width: 46px;
    height: 46px;
    display: grid;
    place-items: center;
    border-radius: var(--tile-radius);
    border: 2px solid transparent;
    font-size: 22px;
    font-weight: 600;
    user-select: none;
}

/* Given: the two ends of the climb, not anybody's achievement. */
.cell.anchor {
    background: var(--anchor);
    border-color: var(--anchor);
    color: var(--on-anchor);
}

/* The player's own rung. */
.cell.placed {
    background: var(--placed);
    border-color: var(--placed);
    color: var(--on-placed);
}

/* Handed over by a hint — legible, clearly a rung, clearly not earned. */
.cell.hinted {
    background: var(--typed-fill);
    border: 2px dashed var(--accent);
    color: var(--accent);
}

.cell.typed {
    background: var(--typed-fill);
    border-color: var(--filled-stroke);
    color: var(--on-typed);
}

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

/* The row being typed into, so the eye knows where the letters are going. */
.cell.active {
    background: var(--empty-fill);
    border-color: var(--accent);
}

/* ---- 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) {
    .ladder-page {
        height: auto;
        min-height: 0;
        padding-top: 28px;
        gap: 14px;
    }

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