/*
   Vellum by default, Vault when the browser asks for dark. Same values as the
   MAUI app's Colors.xaml — if one changes, change the other.

   Names describe the role, not the colour, because the role survives a theme
   change and the colour does not. "--on-x" is the text drawn on top of x.

   Correct is verdigris and Present is gold. They differ in LIGHTNESS as well
   as hue, which is what makes them separable for red-green colourblind
   players. If you retune them, keep that gap.
*/
:root {
    --page-top: #F4EBD8;
    --page-mid: #ECE0C4;
    --page-end: #E0D0AE;

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

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

    --tray-top: #DCC9A0;
    --tray-end: #E4D4B0;
    --tray-edge: #C2AE8A;

    --correct: #2F6E59;
    --on-correct: #FFFFFF;
    --present: #C89A2C;
    --on-present: #2E2109;
    --absent: #7A6D5A;
    --on-absent: #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-top: #100B05;
        --tray-end: #1A120B;
        --tray-edge: #3E3226;

        --correct: #357A64;
        --present: #D9A838;
        --absent: #554A3E;
        --on-absent: #D4C8B4;

        --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: 100dvh;
    color: var(--ink-dim);
}

/* The wrapper holds keyboard focus, so suppress the outline it would
   otherwise draw around the entire page. Focus is still really there — the
   on-screen keys preventDefault on mousedown so it is never lost. */
.game {
    min-height: 100dvh;
    outline: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 18px 12px calc(16px + env(safe-area-inset-bottom));
    max-width: 480px;
    margin: 0 auto;
}

header { text-align: center; }

h1 {
    margin: 0;
    font-size: clamp(26px, 8vw, 34px);
    font-weight: 700;
    letter-spacing: 0.22em;
    /* The indent 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, .lengths { display: flex; gap: 8px; }

.chip {
    width: 36px;
    height: 32px;
    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 {
    width: auto;
    padding: 0 20px;
    font-size: 12px;
    letter-spacing: 0.12em;
}

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

/*
   The tray. MAUI has no inset shadow so the app fakes the recess with a
   gradient; here the real thing is available, so use it.
*/
.tray {
    padding: 10px;
    border-radius: 13px;
    border: 1px solid var(--tray-edge);
    background: linear-gradient(180deg, var(--tray-top) 0%, var(--tray-end) 100%);
    box-shadow: inset 0 3px 6px rgba(74, 52, 20, 0.3);
}

.board {
    display: grid;
    grid-template-columns: repeat(var(--cols), 1fr);
    gap: 6px;
}

.tile {
    /* Fitted rather than fixed: a six-letter board at a hardcoded size
       overflowed narrow phones in the MAUI build. */
    width: clamp(38px, calc((min(100vw, 480px) - 68px - (var(--cols) - 1) * 6px) / var(--cols)), 66px);
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    border-radius: var(--tile-radius);
    border: 2px solid transparent;
    font-size: clamp(18px, 6vw, 30px);
    font-weight: 600;
    user-select: none;
}

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

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

.tile.correct { background: var(--correct); color: var(--on-correct); }
.tile.present { background: var(--present); color: var(--on-present); }
.tile.absent  { background: var(--absent);  color: var(--on-absent); }

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

.message.warn  { color: var(--ink-dim); }
.message.win   { color: var(--correct); }
.message.lose  { color: var(--accent); }

.hint {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 0.5em;
    text-indent: 0.5em;
    color: var(--accent);
}

.actions {
    min-height: 38px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
}

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

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

/* Next level after a win — green, because it reads as progress rather than
   as the retry it sits in the same place as. */
.btn.ok {
    border-color: var(--correct);
    background: var(--correct);
    color: var(--on-correct);
}

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

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

.key {
    flex: 1 1 0;
    min-width: 0;
    height: 48px;
    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; }

.key.correct { background: var(--correct); color: var(--on-correct); }
.key.present { background: var(--present); color: var(--on-present); }
.key.absent  { background: var(--absent);  color: var(--on-absent); }

/*
   On a phone the keyboard belongs at the bottom of the viewport, under the
   thumb — which is what margin-top:auto inside a 100dvh column gives.

   In a tall desktop window that same rule stretches the gap to something
   absurd. Above phone height, stop filling the viewport and let the layout
   close up. The breakpoint tests height as well as width, so a short wide
   window keeps the pinned keyboard rather than scrolling.
*/
@media (min-width: 520px) and (min-height: 760px) {
    .game {
        min-height: 0;
        padding-top: 32px;
    }

    .keyboard {
        margin-top: 10px;
    }
}

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