/* Retro synthwave look: a sky gradient over the top half, a neon grid floor
   under the bottom half, square neon panels, Fira Mono throughout.

   The colours come from a theme, one file each in themes/ (Sunset is the
   default). A theme sets the role tokens listed under "Theme tokens" below on
   [data-theme="…"]; ts/theme.ts puts the chosen one on <html> and sends its
   --board-* / --tile-* / --glitch-* colours to the canvas (src/render.rs). */

@layer fonts, reset, tokens, themes, scene, layout, components, theme-extras;

@layer fonts {
    /* Vendored by scripts/vendor.sh (SIL OFL 1.1, see fonts/OFL.txt). */
    @font-face {
        font-family: "Fira Mono";
        src: url("fonts/fira-mono-400.woff2") format("woff2");
        font-weight: 400;
        font-style: normal;
        font-display: swap;
    }
    @font-face {
        font-family: "Fira Mono";
        src: url("fonts/fira-mono-700.woff2") format("woff2");
        font-weight: 700;
        font-style: normal;
        font-display: swap;
    }
    /* SF Alien Encounters 2.000 by Derek Vogelpohl, ShyFoundry Fonts: the
       foundry's own web font files (media/fonts/, Git LFS), self-hosted under its
       webfont EULA (media/fonts/ShyFoundry-Webfont-EULA.pdf).
       Each style has one weight; with font-synthesis off, text asking for bold
       gets it as drawn. Fira Mono stands in without the files. */
    @font-face {
        font-family: "Alien Encounters";
        src: url("fonts/alien-encounters.woff2") format("woff2");
        font-weight: 400;
        font-style: normal;
        font-display: swap;
    }
    @font-face {
        font-family: "Alien Encounters Solid";
        src: url("fonts/alien-encounters-solid.woff2") format("woff2");
        font-weight: 400;
        font-style: normal;
        font-display: swap;
    }
}

@layer reset {
    *, *::before, *::after { box-sizing: border-box; }
    body, h1, h2, p, dl, dd { margin: 0; }
    button, output { font: inherit; color: inherit; }
    /* `hidden` always hides: the browser's own rule loses to any author
       `display` (a .btn's inline-flex), which left Continue showing. */
    [hidden] { display: none !important; }
}

@layer tokens {
    :root {
        color-scheme: dark;

        /* Theme tokens: every theme sets these (themes/sunset.css lists them all).
             --ground                  page, board and panel background
             --sky-top/-mid/-low       the sky gradient, top to horizon
             --grid                    the floor's grid lines
             --accent(-hover/-active)  panel edges, button outlines, primary button
             --highlight               focus ring, toggles that are on, new scores, the bolt
             --link                    links
             --ink, --ink-dim          text, secondary text
             --title-glow(-2)          the neon around the title
             --glitch-a, --glitch-b    the title's glitch ghosts (and the tiles')
             --board-ground, --board-grid, --tile-1 to --tile-4   the canvas (plain colours)
           Optional, with defaults here: --primary-bg, --primary-ink, --glow,
           --panel, --font-display(-solid), --scene-overlay, --sun, --sun-opacity. */

        /* Derived from the theme. */
        --ink-08: color-mix(in srgb, var(--ink) 8%, transparent);
        --ground-35: color-mix(in srgb, var(--ground) 35%, transparent);
        --ground-60: color-mix(in srgb, var(--ground) 60%, transparent);
        --ground-70: color-mix(in srgb, var(--ground) 70%, transparent);
        --ground-90: color-mix(in srgb, var(--ground) 90%, transparent);
        --accent-35: color-mix(in srgb, var(--accent) 35%, transparent);

        --panel: color-mix(in srgb, var(--ground) 85%, transparent);
        --panel-edge: var(--accent);
        --glow: 0 0 30px var(--accent-35);
        --primary-bg: linear-gradient(90deg, var(--accent), var(--highlight));
        --primary-ink: var(--ground);

        /* The scene's extras, off unless a theme turns them on. */
        --scene-overlay: none;  /* a background drawn over the scene, under the page */
        --sun: none;            /* a background for the striped sun on the horizon */
        --sun-opacity: 1;

        --font-mono: "Fira Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
        /* Uppercase-only display faces: striped for titles, solid for controls. */
        --font-display: "Alien Encounters", var(--font-mono);
        --font-display-solid: "Alien Encounters Solid", var(--font-mono);

        --space-1: 0.25rem;
        --space-2: 0.5rem;
        --space-3: 0.75rem;
        --space-4: 1rem;
        --space-5: 1.5rem;
        --gutter: clamp(var(--space-3), 3vmin, var(--space-5));
        --touch: 3rem; /* 48px controls, comfortable on a phone */
        --ease: 180ms ease-out;

        font-family: var(--font-mono);
        font-synthesis: none;
        line-height: 1.5;
        color: var(--ink);
        background: var(--ground);
        -webkit-font-smoothing: antialiased;
        text-size-adjust: none;
        -webkit-text-size-adjust: none;
        touch-action: manipulation;     /* no double-tap zoom */
        overscroll-behavior: none;      /* no pull-to-refresh / rubber-banding */
    }

    ::selection { background: var(--accent); color: var(--ground); }
    :focus-visible { outline: 2px solid var(--highlight); outline-offset: 2px; }
}

/* The scene is decoration, so the root's pseudo-elements draw it behind the
   page; the body is see-through and the root keeps the ground colour. The
   body's pseudo-elements add a theme's extras on top of the scene, still
   behind the page: the sun on the horizon and an overlay (scanlines, say). */
@layer scene {
    :root::before,
    :root::after,
    body::before,
    body::after {
        content: "";
        position: fixed;
        z-index: -2;
        pointer-events: none;
    }
    :root::before {
        inset: 0 0 50% 0;
        background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-mid) 60%, var(--sky-low) 100%);
    }
    :root::after {
        inset: 50% 0 0 0;
        background-color: var(--ground);
        background-image:
            linear-gradient(var(--grid) 2px, transparent 2px),
            linear-gradient(90deg, var(--grid) 2px, transparent 2px);
        background-size: 64px 64px; /* ROW_PX in ts/floor.ts */
        transform-origin: 50% 0;
        transition: inset 0.6s ease-out, transform 0.6s ease-out;
    }
    /* A speedrun: the floor tilts into perspective, a plane running to the
       horizon, wider and deeper than the screen so it fills it, and rolls
       towards the player at their pace (ts/floor.ts). */
    :root[data-speedrun]::after {
        inset: 50% -150% -90% -150%;
        transform: perspective(28vh) rotateX(62deg);
    }
    /* The sun: a disc cut into stripes, its part below the horizon hidden. */
    body::after {
        --size: min(34vmin, 18rem);
        z-index: -1;
        inset-inline-end: 8%;
        inset-block-end: calc(50% - var(--size) * 0.4);
        inline-size: var(--size);
        aspect-ratio: 1;
        border-radius: 50%;
        background: var(--sun);
        opacity: var(--sun-opacity);
        clip-path: inset(0 0 40% 0);
        mask: linear-gradient(#000 40%, transparent 40% 43%, #000 43% 48%, transparent 48% 51%,
                              #000 51% 55%, transparent 55% 58%, #000 58%);
    }
    body::before {
        z-index: -1;
        inset: 0;
        background: var(--scene-overlay);
    }
}

@layer layout {
    body {
        display: grid;
        grid-template-rows: auto minmax(0, 1fr);
        gap: var(--gutter);
        block-size: 100dvh;
        overflow: hidden;
        background: transparent;
        padding:
            max(var(--gutter), env(safe-area-inset-top))
            max(var(--gutter), env(safe-area-inset-right))
            max(var(--gutter), env(safe-area-inset-bottom))
            max(var(--gutter), env(safe-area-inset-left));
        -webkit-user-select: none;
        user-select: none;
        -webkit-touch-callout: none;
        -webkit-tap-highlight-color: transparent;
    }

    .sign-band {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: space-between;
        gap: var(--space-3) var(--space-5);
        text-shadow: 0 2px 8px var(--ground-60);
    }

    /* The board is the largest square that fits the stage; the canvas fills
       it, and macroquad reads its clientWidth/Height x devicePixelRatio. */
    .stage {
        container-type: size;
        display: grid;
        place-items: center;
    }
    .board {
        position: relative;
        inline-size: min(100cqi, 100cqb);
        aspect-ratio: 1;
        border: 2px solid var(--panel-edge);
        box-shadow: var(--glow);
        background: var(--ground);
    }
    #glcanvas {
        position: absolute;
        inset: 0;
        inline-size: 100%;
        block-size: 100%;
        touch-action: none;
        outline: none;
    }
    /* The canvas holds focus whenever the game takes keys, so instead of a
       permanent focus ring the board dims while focus is elsewhere. */
    #glcanvas:focus-visible { outline: none; }
    .board { transition: border-color var(--ease), box-shadow var(--ease); }
    .board:not(:focus-within) { border-color: var(--ink-dim); box-shadow: none; }

    /* The speedrun badge sits in the board's top-right corner, inside the board's
       padding, and lets every touch through to the game. */
    .speedrun {
        position: absolute;
        z-index: 1;
        inset-block-start: 0.6%;
        inset-inline-end: 1.2%;
        display: flex;
        align-items: center;
        gap: var(--space-2);
        pointer-events: none;
        &[hidden] { display: none; }
    }
}

@layer components {
    .brand {
        font-family: var(--font-display);
        font-size: 1.75rem;
        font-weight: 700;
        line-height: 1;
        white-space: nowrap;
    }

    .stats { display: flex; gap: var(--space-5); }
    .stats div { display: grid; }
    .stats dt {
        font-size: 0.75rem;
        letter-spacing: 0.14em;
        text-transform: uppercase;
        color: var(--ink);
        text-shadow: 0 1px 2px var(--ground-90), 0 0 6px var(--ground-70);
    }
    .stats dd {
        font-family: var(--font-display-solid);
        font-size: 1.5rem;
        font-weight: 700;
        line-height: 1.2;
        font-variant-numeric: tabular-nums;
    }

    /* Portrait: two rows of two (New game, Give up / Rules, Scores); one row
       of four once there is room. */
    .actions {
        flex-basis: 100%;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: var(--space-2);
    }
    @media (width >= 34rem) {
        .actions { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    }
    /* Music and theme: a row of square icon buttons at the header's far end. */
    .tools {
        display: flex;
        gap: var(--space-2);
        margin-inline-start: auto;
    }

    .btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-block-size: var(--touch);
        padding-inline: var(--space-5);
        border: 1px solid transparent;
        border-radius: 0;
        font-family: var(--font-display-solid);
        font-size: 1.125rem;
        font-weight: 700;
        letter-spacing: 0.04em;
        white-space: nowrap;
        cursor: pointer;
        text-shadow: none;
        transition: background var(--ease), border-color var(--ease);
    }
    .actions .btn { padding-inline: var(--space-2); }
    /* Smaller labels while four buttons share a narrow row. */
    @media (34rem <= width < 44rem) {
        .actions .btn { font-size: 0.875rem; letter-spacing: 0.02em; }
    }
    /* A square button holding just an icon (its name is in aria-label). */
    .btn-icon {
        inline-size: var(--touch);
        padding: 0;
        svg { inline-size: 1.4rem; block-size: 1.4rem; fill: currentColor; }
    }
    /* The music button shows the action: pause while playing, play when off. */
    #music-toggle[aria-pressed="true"] .icon-play,
    #music-toggle:not([aria-pressed="true"]) .icon-pause { display: none; }
    .btn-primary { background: var(--primary-bg); color: var(--primary-ink); }
    .btn-ghost {
        background: var(--ground-35);
        border-color: var(--panel-edge);
        color: var(--ink);
    }
    @media (hover: hover) {
        .btn-primary:hover { background: var(--accent-hover); }
        .btn-ghost:hover:enabled { background: var(--ink-08); border-color: var(--accent-hover); }
    }
    .btn-primary:active { background: var(--accent-active); }
    .btn:disabled { opacity: 0.45; cursor: default; }
    /* A toggle that is on (music playing) lights up like the board's neon. */
    .btn-ghost[aria-pressed="true"] {
        border-color: var(--highlight);
        color: var(--highlight);
        box-shadow: inset 0 0 0 1px var(--highlight);
    }

    /* Dialogs are the neon panel. */
    /* A dialog that takes focus itself (game over) shows no ring for it. */
    dialog:focus { outline: none; }
    dialog {
        inline-size: min(28rem, 100% - 2 * var(--gutter));
        padding: var(--space-5);
        border: 2px solid var(--panel-edge);
        border-radius: 0;
        background: var(--panel);
        color: var(--ink);
        box-shadow: var(--glow);
        backdrop-filter: blur(6px);
        user-select: text;
        -webkit-user-select: text;

        opacity: 0;
        translate: 0 0.5rem;
        transition: opacity var(--ease), translate var(--ease),
                    overlay var(--ease) allow-discrete, display var(--ease) allow-discrete;

        &[open] {
            display: grid;
            gap: var(--space-4);
            opacity: 1;
            translate: 0 0;
            @starting-style { opacity: 0; translate: 0 0.5rem; }
        }
        &::backdrop { background: var(--ground-60); }

        h2 { font-family: var(--font-display); font-size: 2rem; font-weight: 700; line-height: 1.1; }
        p, li { color: var(--ink-dim); }
        strong, em { color: var(--highlight); font-style: normal; }
        ul { padding-inline-start: 1.25em; margin: 0; }
        .dialog-body { display: grid; gap: var(--space-3); }
        .dialog-actions { display: flex; flex-wrap: wrap; gap: var(--space-3); }
        form.dialog-body { justify-self: stretch; }
        h3 { font-family: var(--font-display); font-size: 1.25rem; font-weight: 700; margin: 0; color: var(--highlight); }
    }

    .final-score { font-family: var(--font-display-solid); font-weight: 700; font-size: 1.5rem; color: var(--ink); }
    .form-error { margin: 0; color: var(--accent); }
    .form-error:empty { display: none; }
    .scores-message {
        grid-column: 1 / -1;
        margin: 0;
        font-family: var(--font-display-solid);
        font-weight: 700;
        font-size: 1.25rem;
        color: var(--highlight);
    }

    /* Arcade initials: three big characters in the solid display face. */
    .field { display: grid; gap: var(--space-2); justify-items: start; }
    .field-label { font-size: 0.75rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-dim); }
    /* Room for exactly three of the widest letters (WWW), centred. */
    .initials {
        box-sizing: content-box;
        inline-size: 4.6em;
        padding: var(--space-2) var(--space-3);
        text-align: center;
        text-indent: 0.3em; /* balances the letter-spacing after the last letter */
        border: 1px solid var(--panel-edge);
        border-radius: 0;
        background: var(--ground-70);
        color: var(--highlight);
        caret-color: var(--highlight);
        font-family: var(--font-display-solid);
        font-size: 1.75rem; /* >= 16px, so iOS does not zoom in */
        font-weight: 700;
        letter-spacing: 0.3em;
        text-transform: uppercase;
    }

    /* High-score lists: side by side when there is room; the dialog scrolls
       when three lists of ten do not fit (a phone). */
    /* The scores dialog's footer: the small Credits link, then Close. */
    .dialog-footer {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: var(--space-3);
        form { justify-self: auto; }
    }
    .text-link {
        min-block-size: var(--touch);
        padding: 0 var(--space-2);
        margin-inline: calc(-1 * var(--space-2));
        border: 0;
        background: none;
        color: var(--ink-dim);
        font-size: 0.8rem;
        letter-spacing: 0.14em;
        text-transform: uppercase;
        text-decoration: underline;
        text-underline-offset: 0.25em;
        cursor: pointer;
    }
    @media (hover: hover) {
        .text-link:hover { color: var(--highlight); }
    }

    /* Credits: one column of short sections; scrolls on a small screen. */
    /* Credits, Open source and the licence viewer: small type, tight spacing,
       so the pages stay short; they scroll on a small screen. */
    dialog.credits {
        inline-size: min(38rem, 100% - 2 * var(--gutter));
        max-block-size: calc(100dvh - 2 * var(--gutter));
        overflow-y: auto;
        overscroll-behavior: contain;
        gap: var(--space-3);
        font-size: 0.8rem;
        line-height: 1.35;
        h2 { font-size: 1.5rem; }
        h3 { font-size: 0.95rem; }
    }
    .credits-body {
        gap: var(--space-3);
        section { display: grid; gap: var(--space-1); }
        .credits-list { display: grid; gap: 0.15rem; padding-inline-start: 1.1em; }
        .credits-licence { margin: 0; font-size: 0.72rem; }
        .oss-intro { margin: 0; color: var(--ink); }
        /* Open source: a numbered list, most important first. */
        .oss-list {
            display: grid;
            gap: var(--space-2);
            margin: 0;
            padding-inline-start: 1.6em;
            li::marker { color: var(--accent); font-variant-numeric: tabular-nums; }
        }
        /* The copyright notice under each project, with its licence links. */
        .oss-notice { display: block; font-size: 0.72rem; color: color-mix(in srgb, var(--ink-dim) 75%, transparent); }
        .oss-foundation {
            display: grid;
            gap: var(--space-1);
            padding: var(--space-2) var(--space-3);
            border: 1px solid var(--panel-edge);
            p { margin: 0; }
        }
        a { color: var(--link); text-underline-offset: 0.2em; }
        @media (hover: hover) {
            a:hover { color: var(--highlight); }
        }
    }
    .license-text {
        margin: 0;
        font-family: var(--font-mono);
        font-size: 0.72rem;
        white-space: pre-wrap;
        overflow-wrap: anywhere;
        color: var(--ink-dim);
    }
    }

    dialog.scores {
        inline-size: min(64rem, 100% - 2 * var(--gutter));
        max-block-size: calc(100dvh - 2 * var(--gutter));
        overflow-y: auto;
        overscroll-behavior: contain;
    }
    .boards {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 1fr));
        gap: var(--space-4) var(--space-5);
        > .scores-message, > .periods, > .period-note { grid-column: 1 / -1; }
        .period-note { margin: 0; font-size: 0.8rem; }
        /* The period tabs: a segmented control; the current one is lit. */
        .periods { display: flex; }
        .periods .period { flex: 1 1 auto; padding-inline: var(--space-3); }
        @media (width < 30rem) {
            .periods:not(.milestones) .period { padding-inline: var(--space-1); font-size: 0.75rem; }
        }
        .period {
            min-block-size: var(--touch);
            padding-inline: var(--space-4);
            border: 1px solid var(--panel-edge);
            margin-inline-start: -1px;
            background: var(--ground-35);
            color: var(--ink);
            font-family: var(--font-display-solid);
            font-weight: 700;
            letter-spacing: 0.04em;
            cursor: pointer;
        }
        .period[aria-current="true"] { background: var(--primary-bg); color: var(--primary-ink); }
        /* The five milestone tabs share one row of the Speedrun column. */
        .milestones { flex-wrap: nowrap; }
        .milestones .period {
            flex: 1;
            min-inline-size: 0;
            padding-inline: var(--space-1);
            font-size: 0.85rem;
        }
        @media (hover: hover) {
            .period:not([aria-current="true"]):hover { background: var(--ink-08); }
        }
        section { display: grid; gap: var(--space-2); align-content: start; }
        .hint { font-size: 0.8rem; margin: 0; }
        table { inline-size: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
        th, td { padding: var(--space-1) var(--space-2); text-align: start; }
        thead th {
            font-size: 0.7rem;
            font-weight: 400;
            letter-spacing: 0.14em;
            text-transform: uppercase;
            color: var(--ink-dim);
            border-block-end: 1px solid var(--accent-35);
        }
        tbody th, td:nth-child(3), td:nth-child(4), thead th:nth-child(n + 3) { text-align: end; }
        tbody th { color: var(--ink-dim); font-weight: 400; }
        td:nth-child(2) { font-family: var(--font-display-solid); font-weight: 700; letter-spacing: 0.1em; color: var(--ink); }
        tbody tr + tr { border-block-start: 1px solid color-mix(in srgb, var(--ink) 6%, transparent); }
        tr.is-new { background: color-mix(in srgb, var(--highlight) 12%, transparent); }
        /* A given-up game's flag, beside the name. */
        .gave-up {
            inline-size: 0.9em;
            block-size: 0.9em;
            margin-inline-start: 0.35em;
            vertical-align: -0.1em;
            color: var(--ink-dim);
        }
        tr.is-new td, tr.is-new th { color: var(--highlight); }
        .empty { color: var(--ink-dim); text-align: center; padding-block: var(--space-3); }
        form { justify-self: end; }
    }

    /* Themes: a picker for normal play and one for speedruns (ts/theme.ts).
       Each swatch carries its theme's data-theme, so it shows that theme's own
       sky, ground and accent. */
    dialog.themes {
        inline-size: min(34rem, 100% - 2 * var(--gutter));
        max-block-size: calc(100dvh - 2 * var(--gutter));
        overflow-y: auto;
        overscroll-behavior: contain;
        fieldset { display: grid; gap: var(--space-2); margin: 0; padding: 0; border: 0; min-inline-size: 0; }
        legend { padding: 0; margin-block-end: var(--space-2); }
        .hint { margin: 0; font-size: 0.8rem; }
    }
    .theme-options {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(min(100%, 9.5rem), 1fr));
        gap: var(--space-2);
    }
    .theme-option {
        display: flex;
        align-items: center;
        gap: var(--space-2);
        min-block-size: var(--touch);
        padding: var(--space-1) var(--space-2);
        border: 1px solid color-mix(in srgb, var(--ink-dim) 40%, transparent);
        background: var(--ground-35);
        color: var(--ink);
        cursor: pointer;
        input { position: absolute; opacity: 0; pointer-events: none; }
        &:has(input:checked) {
            border-color: var(--highlight);
            color: var(--highlight);
            box-shadow: inset 0 0 0 1px var(--highlight);
        }
        &:has(input:focus-visible) { outline: 2px solid var(--highlight); outline-offset: 2px; }
    }
    @media (hover: hover) {
        .theme-option:hover { background: var(--ink-08); }
    }
    .theme-swatch {
        flex: none;
        inline-size: 2.75rem;
        aspect-ratio: 16 / 10;
        border: 1px solid var(--accent);
        background:
            linear-gradient(90deg, transparent 62%, var(--accent) 62% 78%, transparent 78%) bottom / 100% 30% no-repeat,
            linear-gradient(var(--sky-top), var(--sky-mid) 30%, var(--sky-low) 50%, var(--ground) 50%);
        /* "Same as above": no swatch of its own. */
        &:not([data-theme]) {
            border-style: dashed;
            border-color: var(--ink-dim);
            background: none;
        }
    }

    /* Title screen: only the scene and the title while it is open. */
    html:has(#title[open]) body > :not(#title) { visibility: hidden; }

    dialog.title-screen {
        position: fixed;
        inset: 0;
        inline-size: 100%;
        block-size: 100%;
        max-inline-size: none;
        max-block-size: none;
        margin: 0;
        padding: var(--gutter);
        border: 0;
        background: transparent;
        box-shadow: none;
        backdrop-filter: none;
        user-select: none;
        -webkit-user-select: none;
        text-align: center;
        opacity: 1;
        translate: none;

        &[open] { display: grid; place-content: center; justify-items: center; gap: var(--space-5); }
        form { justify-self: center; }
    }

    .title-logo {
        position: relative;
        margin: 0;
        font-family: var(--font-display);
        font-size: clamp(2.5rem, min(15vw, 22dvh), 9.5rem);
        font-weight: 700;
        line-height: 1;
        white-space: nowrap;
        color: var(--ink);
        text-shadow:
            0 0.03em 0.06em var(--ground-60),
            0 0 0.04em var(--ink),
            0 0 0.12em var(--title-glow),
            0 0 0.3em var(--title-glow),
            0 0 0.6em var(--title-glow-2);
        animation: neon-breathe 3.2s ease-in-out infinite, title-jitter 5.3s steps(1) infinite;
    }
    /* Glitch ghosts: cyan and pink copies that flash in as sliced, offset strips. */
    .title-logo::before,
    .title-logo::after {
        content: attr(data-text);
        position: absolute;
        inset: 0;
        text-shadow: none;
        opacity: 0;
        pointer-events: none;
    }
    .title-logo::before { color: var(--glitch-a); animation: glitch-cyan 5.3s steps(1) infinite; }
    .title-logo::after { color: var(--glitch-b); animation: glitch-pink 5.3s steps(1) infinite; }

    .title-tagline { margin: 0; color: var(--ink); }
    /* The title screen's small text sits wherever the screen's shape puts it,
       on an iPad right in the sky's palest band just above the horizon: a tight
       dark outline keeps it readable on any sky. */
    .title-tagline, .title-hint, .install-hint {
        text-shadow: 0 0 1px var(--ground), 0 0 3px var(--ground), 0 1px 4px var(--ground-90),
                     0 0 12px var(--ground-60);
    }
    .title-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--space-3); }
    .title-start, .title-continue { font-size: 1.25rem; padding-inline: var(--space-5); }
    .title-start { animation: blink 1.2s steps(1) infinite; }
    /* Offered a saved game, the player's eye goes to Continue: Start stops blinking. */
    .title-actions:has(.title-continue:not([hidden])) .title-start { animation: none; }
    .title-start:focus-visible { animation: none; }
    .title-hint { margin: 0; font-size: 0.8rem; color: var(--ink-dim); }
    /* The version sits at the title screen's foot, out of the way. */
    .title-version {
        position: absolute;
        inset-inline: 0;
        inset-block-end: calc(var(--space-2) + env(safe-area-inset-bottom, 0px));
        text-align: center;
        @media (height < 34rem) { position: static; }
    }
    .title-version, .credits .version {
        margin: 0;
        font-family: var(--font-mono);
        font-size: 0.7rem;
        color: var(--ink-dim);
        letter-spacing: 0.02em;
    }
    .install-hint {
        margin: 0;
        font-size: 0.9rem;
        color: var(--ink);
        strong { color: var(--highlight); }
    }
    /* A newer release (ts/update.ts): the neon panel, floating over the foot of
       the page, clear of the iPhone's home indicator. */
    .update-notice {
        position: fixed;
        z-index: 10;
        inset-inline: var(--gutter);
        inset-block-end: calc(var(--gutter) + env(safe-area-inset-bottom, 0px));
        max-inline-size: 28rem;
        margin-inline: auto;
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: space-between;
        gap: var(--space-3);
        padding: var(--space-3) var(--space-4);
        border: 2px solid var(--panel-edge);
        background: var(--panel);
        box-shadow: var(--glow);
        backdrop-filter: blur(6px);
        p { margin: 0; color: var(--ink); }
        &[hidden] { display: none; }
    }
    .share-icon { inline-size: 1.25em; block-size: 1.25em; vertical-align: -0.25em; color: var(--highlight); }

    @keyframes neon-breathe {
        0%, 100% { opacity: 1; }
        50% {
            opacity: 0.92;
            text-shadow: 0 0.03em 0.06em var(--ground-60), 0 0 0.03em var(--ink), 0 0 0.1em var(--title-glow),
                0 0 0.22em var(--title-glow), 0 0 0.45em var(--title-glow-2);
        }
    }
    @keyframes title-jitter {
        0%, 86%, 100% { transform: none; filter: none; }
        87% { transform: skewX(-8deg) translateX(-0.03em); }
        88% { transform: translateX(0.04em); filter: brightness(1.6); }
        89% { transform: none; filter: none; }
        93% { transform: skewX(5deg); }
        94% { transform: none; }
    }
    @keyframes glitch-cyan {
        0%, 86%, 100% { opacity: 0; translate: 0; clip-path: inset(0); }
        87% { opacity: 0.85; translate: -0.06em 0; clip-path: inset(18% 0 55% 0); }
        88% { opacity: 0.85; translate: 0.05em 0; clip-path: inset(62% 0 10% 0); }
        89% { opacity: 0; }
        93% { opacity: 0.7; translate: -0.04em 0; clip-path: inset(40% 0 35% 0); }
        94% { opacity: 0; }
    }
    @keyframes glitch-pink {
        0%, 86%, 100% { opacity: 0; translate: 0; clip-path: inset(0); }
        87% { opacity: 0.85; translate: 0.06em 0; clip-path: inset(48% 0 25% 0); }
        88% { opacity: 0.85; translate: -0.05em 0; clip-path: inset(5% 0 70% 0); }
        89% { opacity: 0; }
        93% { opacity: 0.7; translate: 0.04em 0; clip-path: inset(70% 0 5% 0); }
        94% { opacity: 0; }
    }
    .speedrun .bolt {
        inline-size: 1.25rem;
        block-size: 1.25rem;
        fill: var(--highlight);
        filter: drop-shadow(0 0 4px var(--highlight))
                drop-shadow(0 0 10px color-mix(in srgb, var(--accent) 70%, transparent));
        /* Keeps glowing while the speedrun lasts (steady under reduced motion). */
        animation: bolt-glow 2.4s ease-in-out infinite;
    }
    @keyframes bolt-glow {
        50% {
            filter: drop-shadow(0 0 7px var(--highlight))
                    drop-shadow(0 0 18px color-mix(in srgb, var(--accent) 95%, transparent));
        }
    }
    .speedrun .split {
        font-family: var(--font-display-solid);
        font-weight: 700;
        font-size: 0.9rem;
        letter-spacing: 0.04em;
        color: color-mix(in srgb, var(--highlight) 70%, transparent);
        font-variant-numeric: tabular-nums;
        /* The flash grows the text away from the bolt, not into it. */
        transform-origin: right center;
    }
    /* A new split flares, then settles to the dimmer yellow above. */
    .speedrun.flash .split { animation: split-flash 1.6s ease-out; }
    .speedrun.flash .bolt { animation: bolt-flash 1.6s ease-out, bolt-glow 2.4s ease-in-out infinite; }
    @keyframes split-flash {
        0%, 30% { color: var(--ink); text-shadow: 0 0 6px var(--highlight), 0 0 18px var(--accent); scale: 1.15; }
        10%, 20% { color: var(--highlight); }
        100% { color: color-mix(in srgb, var(--highlight) 70%, transparent); text-shadow: none; scale: 1; }
    }
    @keyframes bolt-flash {
        0%, 20% { scale: 1.4; }
        10% { scale: 1.1; }
        100% { scale: 1; }
    }

    @keyframes blink {
        0%, 100% { opacity: 1; }
        50% { opacity: 0.35; }
    }

    /* Landscape: the header becomes a sidebar beside the board, so the board
       gets the full height (the dimension that limits it when the screen is
       wider than tall). Portrait keeps the header on top. */
    @media (min-aspect-ratio: 6/5) {
        body {
            /* The board column grows only as wide as the board can be tall. */
            grid-template-columns: minmax(12rem, 17rem) minmax(0, calc(100dvh - 2 * var(--gutter)));
            grid-template-rows: minmax(0, 1fr);
            justify-content: center;
        }
        .sign-band {
            flex-direction: column;
            flex-wrap: nowrap;
            align-items: stretch;
            justify-content: center;
            gap: var(--space-4);
            inline-size: auto;
            margin: 0;
        }
        /* In pairs: New game and Give up, Rules and Scores. */
        .actions {
            flex-basis: auto;
            grid-template-columns: repeat(2, minmax(0, 1fr));
        }
        .actions .btn { font-size: 1rem; }
        .tools { margin-inline-start: 0; }
    }

    @media (prefers-reduced-motion: reduce) {
        *, *::before, *::after { transition-duration: 0s !important; animation: none !important; }
    }
}
