/* ─────────────────────────────────────────────────────────────
   SLAGALICA — editorial print, set in display type
   ───────────────────────────────────────────────────────────── */

:root {
    --paper: #ece4d2;
    --paper-deep: #ddd2bb;
    --ink: #14110d;
    --ink-soft: #2a2520;
    --ink-mute: #6b6253;
    --rule: #14110d;
    --accent: #c8311c; /* stop-press red */
    --accent-deep: #8a1a08;
    --accent-soft: #e6c8a3;
    --ok: #2a5a2a;

    --serif: "Fraunces", "Times New Roman", serif;
    --mono: "JetBrains Mono", "Courier New", monospace;
    --sans: "Manrope", "Helvetica Neue", sans-serif;

    --gutter: clamp(16px, 2.4vw, 36px);
    /* Radii — most chrome is 2px, the legend kbd is the lone 3px. */
    --radius:    2px;
    --radius-lg: 3px;
}

/* ─── mode: HARD / EASY ──────────────────────────────────────
   The palette stays the same. The only visible shift is on
   the wordmark (weight + WONK axis), and the running-sum
   redaction when the player is typing in hard mode. */
body[data-practice="0"] .wordmark {
    font-variation-settings:
        "opsz" 144,
        "SOFT" 0,
        "WONK" 1;
    font-weight: 800;
    letter-spacing: -0.045em;
    text-shadow: 1px 0 0 rgba(184, 32, 15, 0.22);
}
body[data-practice="1"] .wordmark {
    font-variation-settings:
        "opsz" 144,
        "SOFT" 70,
        "WONK" 0;
    font-weight: 600;
    letter-spacing: -0.035em;
}

/* ─── reset ────────────────────────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
}
html,
body {
    margin: 0;
    padding: 0;
}
button {
    font: inherit;
    color: inherit;
    background: none;
    border: 0;
    padding: 0;
    cursor: pointer;
}
input,
kbd {
    font: inherit;
}

::selection {
    background: var(--accent);
    color: var(--paper);
}

html,
body {
    background: var(--paper);
    color: var(--ink);
    font-family: var(--serif);
    font-feature-settings: "ss01", "ss02", "liga", "dlig";
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    min-height: 100vh;
    overflow-x: hidden;
}

body {
    /* off-register ink wash in the corners — printer's bleed */
    background:
        radial-gradient(
            ellipse 60% 50% at 0% 0%,
            rgba(20, 17, 13, 0.08),
            transparent 60%
        ),
        radial-gradient(
            ellipse 70% 60% at 100% 100%,
            rgba(20, 17, 13, 0.07),
            transparent 60%
        ),
        var(--paper);
}

/* faint paper grain — kept off-screen until needed */
.grain {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 100;
    opacity: 0.18;
    mix-blend-mode: multiply;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.07 0 0 0 0 0.06 0 0 0 0 0.05 0 0 0 0.55 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

/* ─── page container ───────────────────────────────────────── */
.page {
    max-width: 1480px;
    margin: 0 auto;
    padding: clamp(20px, 3.4vw, 48px) clamp(20px, 4vw, 64px)
        clamp(20px, 3vw, 40px);
    position: relative;
}

/* ─── rules ─────────────────────────────────────────────────── */
.rule {
    border: 0;
    margin: 0;
    height: 0;
    background: var(--rule);
}
.rule--heavy {
    height: 4px;
}
.rule--hair {
    height: 1px;
    opacity: 0.55;
    margin-top: 18px;
}

/* ─── masthead ──────────────────────────────────────────────── */
.masthead {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 24px;
    align-items: end;
    padding-bottom: 10px;
}

.wordmark {
    font-family: var(--serif);
    font-variation-settings:
        "opsz" 144,
        "SOFT" 30,
        "WONK" 1;
    font-weight: 700;
    font-size: clamp(56px, 11vw, 168px);
    line-height: 0.85;
    letter-spacing: -0.04em;
    margin: 0;
    padding-bottom: 0.14em;
    color: var(--ink);
    font-style: italic;
    position: relative;
    transition:
        font-weight 0.35s ease,
        font-variation-settings 0.35s ease,
        letter-spacing 0.35s ease,
        text-shadow 0.35s ease;
}
.wordmark__dot {
    color: var(--accent);
    font-style: normal;
    display: inline-block;
    transform: translateY(-0.12em);
    margin-left: -0.05em;
    -webkit-user-select: none;
    user-select: none;
    transition:
        color 0.35s ease,
        font-size 0.35s ease,
        text-shadow 0.35s ease;
}
/* Seeded: small flower in accent red — predetermined, planted, not
   recorded. The flower reads as a seed the player has chosen. */
.wordmark__dot[data-mode="seeded"] {
    color: var(--accent);
    font-size: 0.85em;
    text-shadow: 0 0 0 transparent;
}

.masthead__subtitle {
    margin: 8px 0 0;
    font-family: var(--serif);
    font-size: clamp(13px, 1.15vw, 16px);
    color: var(--ink-soft);
    letter-spacing: 0.01em;
    max-width: 36ch;
}
.masthead__subtitle em {
    color: var(--ink);
    font-style: italic;
}
.masthead__subtitle .num {
    font-family: var(--mono);
    font-size: 0.9em;
    text-transform: lowercase;
    border-bottom: 1px solid var(--accent);
    padding: 0 4px;
    letter-spacing: 0;
}
/* Signature: hand-script feel under the wordmark. "by" and the
   trailing period sit in the same italic Fraunces as the name;
   only the name itself is a link. Fraunces with high SOFT and
   WONK axes gives the strokes a hand-drawn quality; italic adds
   the slant. */
.wordmark__byline {
    position: absolute;
    font-family: var(--serif);
    font-variation-settings:
        "opsz" 144,
        "SOFT" 100,
        "WONK" 1;
    font-style: italic;
    font-weight: 300;
    font-size: clamp(18px, 2.4vw, 30px);
    letter-spacing: 0.005em;
    color: var(--ink);
    /* Anchored to the left, slightly inboard of the wordmark. */
    left: 5%;
    bottom: 0;
    white-space: nowrap;
    -webkit-user-select: none;
    user-select: none;
    text-decoration: none;
}
.wordmark__byline__link {
    text-decoration: none;
    color: inherit;
    transition: color 0.25s ease;
}
.wordmark__byline__link:hover,
.wordmark__byline__link:focus-visible {
    color: var(--accent);
}
.wordmark__byline__link:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 4px;
    border-radius: var(--radius);
}
.masthead__meta {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: stretch;
    font-family: var(--mono);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding-bottom: 6px;
    min-width: 280px;
}
.meta-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 16px;
}
.meta-label {
    color: var(--ink-mute);
}
.meta-value {
    color: var(--ink);
    font-weight: 600;
    text-align: right;
}

.meta-row--btn {
    appearance: none;
    background: transparent;
    border: 0;
    padding: 2px 0 2px;
    cursor: pointer;
    font: inherit;
    color: inherit;
    text-align: left;
    text-transform: inherit;
    letter-spacing: inherit;
    position: relative;
    transition: color 0.15s ease;
}
.meta-row--btn .meta-value {
    color: var(--ok);
    border-bottom: 1px solid currentColor;
    padding-bottom: 1px;
}
.meta-row--btn[aria-pressed="true"] .meta-value {
    color: var(--accent);
}
.meta-row--btn:hover .meta-label,
.meta-row--btn:focus-visible .meta-label {
    color: var(--ink);
}
.meta-row--btn:focus-visible {
    outline: 1px dashed var(--ink);
    outline-offset: 2px;
}

/* ─── seed row ─────────────────────────────────────────────── */
.meta-row--seed {
    display: flex;
    align-items: baseline;
    gap: 6px;
}
.meta-row__value-group {
    display: inline-flex;
    align-items: baseline;
    gap: 8px;
}
.meta-value--input {
    font: inherit;
    font-family: var(--mono);
    font-size: 12px;
    font-weight: 600;
    color: var(--ink);
    background: transparent;
    border: 0;
    border-bottom: 1px solid var(--ink);
    outline: 0;
    padding: 0 0 1px;
    width: 18ch;
    text-transform: lowercase;
    letter-spacing: 0;
}
/* Top-right seed DISPLAY: a button styled like a value. Click (or press E)
   to open the seed editor card. */
.meta-value--seed-btn {
    font: inherit;
    font-family: var(--mono);
    font-size: 12px;
    font-weight: 600;
    color: var(--ink);
    background: transparent;
    border: 0;
    border-bottom: 1px solid transparent;
    padding: 0 0 1px;
    cursor: pointer;
    text-align: right;
    max-width: 22ch;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-transform: lowercase;
    letter-spacing: 0;
    transition:
        border-color 0.15s ease,
        color 0.15s ease;
}
.meta-value--seed-btn:hover {
    border-bottom-color: var(--ink);
    color: var(--accent);
}
.meta-value--seed-btn:focus-visible {
    outline: 1px dashed var(--ink);
    outline-offset: 3px;
}
.meta-value--input::placeholder {
    color: var(--ink-mute);
    font-weight: 500;
}
.meta-value--input:focus {
    border-bottom-color: var(--accent);
    color: var(--accent);
}
.meta-icon {
    font-family: var(--serif);
    font-size: 14px;
    line-height: 1;
    color: var(--ink-mute);
    background: transparent;
    border: 0;
    padding: 0 2px;
    cursor: pointer;
    transition:
        color 0.15s ease,
        transform 0.15s ease;
}
.meta-icon:hover {
    color: var(--ink);
}
.meta-icon:focus-visible {
    outline: 1px dashed var(--ink);
    outline-offset: 2px;
    color: var(--ink);
}
.meta-icon[data-flash="1"] {
    color: var(--ok);
    animation: pop 0.4s ease-out;
}
/* Clear button: red hover (it destroys data). The reveal/shrink keeps
   the row from jumping when the button is shown or hidden. */
.meta-icon--clear {
    color: var(--ink-mute);
    font-size: 16px;
}
.meta-icon--clear:hover {
    color: var(--accent);
}
.meta-icon--clear[hidden] {
    display: none;
}
@keyframes pop {
    0% {
        transform: scale(1);
    }
    40% {
        transform: scale(1.35);
    }
    100% {
        transform: scale(1);
    }
}

/* Seeded indicator — the wordmark's trailing dot morphs into a
   small flower (✿) in accent red, set by JS via data-mode. See
   .wordmark__dot[data-mode="seeded"] above. */

/* ─── main grid ─────────────────────────────────────────────── */
.grid {
    display: grid;
    grid-template-columns: 60px minmax(0, 1fr) 300px;
    gap: clamp(20px, 2.4vw, 40px);
    margin-top: clamp(28px, 4vw, 56px);
    align-items: start;
    min-height: 60vh;
}

/* ─── vertical timer rail (left) ────────────────────────────── */
.rail--left {
    position: relative;
    height: 100%;
    min-height: 480px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 6px;
}
.vlabel {
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    font-family: var(--serif);
    font-style: italic;
    font-size: 13px;
    letter-spacing: 0.18em;
    color: var(--ink-mute);
    text-transform: lowercase;
    line-height: 1.3;
    margin-bottom: 14px;
}
.vtime {
    font-family: var(--mono);
    font-weight: 700;
    font-size: clamp(22px, 1.8vw, 30px);
    letter-spacing: 0.04em;
    color: var(--ink);
    writing-mode: horizontal-tb;
    margin-bottom: 18px;
    transition: color 0.2s ease;
}
.vtime[data-warn="1"] {
    color: var(--accent);
    animation: pulse 1s ease-in-out infinite;
}
.vtime[data-warn="2"] {
    color: var(--accent);
    animation: pulse 0.4s ease-in-out infinite;
}
@keyframes pulse {
    0%,
    100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.08);
    }
}

.vfill {
    position: relative;
    width: 6px;
    flex: 1;
    min-height: 200px;
    background: rgba(20, 17, 13, 0.08);
    border: 1px solid var(--ink);
}
.vfill__bar {
    position: absolute;
    inset: 0 0 auto 0;
    height: 100%;
    background: var(--ink);
    transform-origin: top;
    transform: scaleY(1);
    transition:
        transform 0.25s linear,
        background 0.3s ease;
}
.vfill__bar[data-warn="1"] {
    background: var(--accent);
}
.vfill__bar[data-warn="2"] {
    background: var(--accent);
}

/* ─── centre column ─────────────────────────────────────────── */
.centre {
    display: flex;
    flex-direction: column;
    gap: clamp(28px, 3vw, 48px);
    padding-top: 6px;
}

.kicker {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 14px;
    font-family: var(--mono);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    color: var(--ink-soft);
    /* fixed height: the kbd inside the text is ~18px tall (11px font + 4px
     padding + inherited line-height), while plain text is only ~14px. If
     we let the row size to content, the kicker shrinks when the target
     roll replaces a kbd-bearing message, and everything below jumps up. */
    min-height: 22px;
}
.kicker__rule {
    height: 1px;
    background: var(--ink);
    opacity: 0.6;
}
.kicker__text {
    white-space: nowrap;
}
.kicker__text kbd {
    display: inline-block;
    padding: 2px 7px;
    margin: 0 2px;
    background: var(--ink);
    color: var(--paper);
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: 0.04em;
    border-radius: var(--radius);
    text-transform: lowercase;
}
.kicker__text em {
    font-family: var(--serif);
    font-style: italic;
    text-transform: lowercase;
    letter-spacing: 0;
    color: var(--accent);
}
/* "R × 3" entry in the footer legend: the small × between the two
   kbd tags, so the entry reads as one composite symbol rather than
   three siblings. */
.legend__sep {
    font-family: var(--mono);
    font-size: 10px;
    color: var(--ink-mute);
    margin: 0 1px;
}
/* ─── target ────────────────────────────────────────────────── */
.target {
    position: relative;
    padding: 6px 0 18px;
}
.target__caption {
    font-family: var(--mono);
    text-transform: uppercase;
    letter-spacing: 0.32em;
    font-size: 11px;
    color: var(--ink-mute);
    margin-bottom: 8px;
}
.target__num {
    font-family: var(--serif);
    font-variation-settings:
        "opsz" 144,
        "SOFT" 0,
        "WONK" 1;
    font-weight: 800;
    /* Sized to fit 5 digits in the centre column after the materials
     rail was widened to 240px. Single clamp across all three modes —
     the centre column width is stable, so switching modes changes only
     the digit count, not the size (no movement). */
    font-size: clamp(120px, 15vw, 230px);
    line-height: 0.82;
    letter-spacing: -0.06em;
    color: var(--ink);
    display: flex;
    gap: clamp(3px, 0.4vw, 8px);
    font-feature-settings: "lnum", "tnum";
    font-style: italic;
    margin-left: -0.05em;
}
/* Single font-size rule across all three modes — the centre column
   width stays stable, so switching modes only changes the digit
   count, not the size. See .grid for the widened centre track. */
.target__num .digit {
    display: inline-block;
    position: relative;
    min-width: 0.5em;
    text-align: center;
    /* off-register print: cyan/magenta plate misalign */
    text-shadow:
        2px 0 0 rgba(200, 49, 28, 0),
        -1.5px 0 0 rgba(20, 17, 13, 0);
    transition: text-shadow 0.3s ease;
}
.target__num .digit[data-hidden="1"] {
    display: none;
}
.target[data-state="rolling"] .target__num .digit {
    text-shadow:
        1px 0 0 rgba(200, 49, 28, 0.2),
        -0.7px 0 0 rgba(20, 17, 13, 0.15);
}
.target[data-state="locked"] .target__num .digit {
    text-shadow:
        1px 0 0 rgba(200, 49, 28, 0.3),
        -0.7px 0 0 rgba(20, 17, 13, 0.22);
    animation: stamp 0.4s cubic-bezier(0.2, 0.8, 0.3, 1.2);
}

@keyframes stamp {
    0% {
        transform: scale(1.4);
        filter: blur(4px);
    }
    60% {
        transform: scale(0.94);
        filter: blur(0);
    }
    100% {
        transform: scale(1);
    }
}
.target__rule {
    height: 2px;
    background: var(--ink);
    margin-top: 18px;
    max-width: 12em;
}
.target__hint {
    margin-top: 10px;
    font-family: var(--serif);
    font-style: italic;
    color: var(--ink-mute);
    font-size: clamp(13px, 1.1vw, 16px);
    max-width: 36ch;
    line-height: 1.4;
}

/* ─── equation input ────────────────────────────────────────── */
.equation {
    border-top: 2px solid var(--ink);
    border-bottom: 1px solid var(--ink);
    padding: 18px 0 16px;
    margin-top: 8px;
}
.equation[data-flash="1"] {
    animation: shake 0.32s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}
@keyframes shake {
    0%,
    100% {
        transform: translateX(0);
    }
    20% {
        transform: translateX(-5px);
    }
    40% {
        transform: translateX(5px);
    }
    60% {
        transform: translateX(-3px);
    }
    80% {
        transform: translateX(3px);
    }
}
.equation__label {
    display: block;
    font-family: var(--mono);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.32em;
    color: var(--ink-mute);
    margin-bottom: 12px;
}
.equation__row {
    display: flex;
    align-items: baseline;
    gap: 10px;
    font-family: var(--mono);
    font-size: clamp(22px, 2.6vw, 40px);
    line-height: 1.1;
    letter-spacing: -0.01em;
    color: var(--ink);
}
.equation__caret {
    color: var(--accent);
    font-weight: 700;
    animation: blink 1s steps(2) infinite;
    display: inline-block;
    transform: translateY(-0.06em);
}
.equation[data-disabled="1"] .equation__caret {
    opacity: 0;
    animation: none;
}
@keyframes blink {
    50% {
        opacity: 0;
    }
}

.equation__input {
    flex: 1;
    min-width: 0;
    font: inherit;
    color: inherit;
    background: transparent;
    border: 0;
    outline: 0;
    padding: 0;
    caret-color: var(--accent);
    letter-spacing: -0.01em;
}
.equation__input::placeholder {
    color: var(--ink-mute);
    opacity: 0.55;
    font-style: italic;
    font-family: var(--serif);
}
.equation__input:disabled {
    color: var(--ink-mute);
}
.equation__eq {
    color: var(--ink-mute);
    font-weight: 400;
}
.equation__live {
    /* Reserve 4ch so the right edge stays fixed for typical 3–4 digit
     answers (the common case — the target itself is 3 digits). The box
     still grows for 5+ digit values produced by spammed expressions,
     but the shift is far less dramatic than the previous 1.2em, which
     let the `=` jump whenever the running sum got wide. */
    min-width: 4ch;
    flex-shrink: 0;
    text-align: right;
    color: var(--ink);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    font-family: var(--mono);
    transition:
        color 0.2s ease,
        font-style 0.2s ease,
        opacity 0.2s ease,
        font-family 0.2s ease;
}
.equation__live[data-state="ok"] {
    color: var(--ok);
}
.equation__live[data-state="err"] {
    color: var(--accent);
}
.equation__live[data-state="warn"] {
    color: var(--accent-deep);
}

/* idle: matches the input placeholder — italic serif, dim */
.equation__live[data-state="idle"] {
    color: var(--ink-mute);
    opacity: 0.55;
    font-style: italic;
    font-family: var(--serif);
    font-weight: 500;
    letter-spacing: 0;
}

/* HARD: even when the player is typing, the value stays redacted */
body[data-practice="0"] .equation__live[data-state="ok"],
body[data-practice="0"] .equation__live[data-state="warn"],
body[data-practice="0"] .equation__live[data-state="err"] {
    color: var(--accent);
    font-style: italic;
    font-family: var(--serif);
    font-weight: 600;
    opacity: 0.9;
}

.equation__used {
    margin-top: 12px;
    font-family: var(--mono);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    color: var(--ink-mute);
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}
.equation__used em {
    font-style: normal;
    color: var(--ink);
    font-weight: 600;
}
.equation__used .used-chip {
    display: inline-flex;
    align-items: center;
    padding: 2px 7px;
    background: var(--ink);
    color: var(--paper);
    border-radius: var(--radius);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
}
.equation__used .used-chip--missing {
    background: transparent;
    color: var(--accent);
    border: 1px dashed var(--accent);
}

/* ─── materials sidebar ─────────────────────────────────────── */
.rail--right {
    border-left: 1px solid var(--ink);
    padding-left: 22px;
    position: relative;
    /* Fixed height for 8 material rows so the rail never shrinks
     when fewer materials are shown in easier modes. */
    min-height: 500px;
}
.rail--right::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 -3px;
    width: 1px;
    background: var(--ink);
    opacity: 0.4;
}
.rail__title {
    font-family: var(--mono);
    text-transform: uppercase;
    letter-spacing: 0.32em;
    font-size: 11px;
    color: var(--ink-mute);
    margin-bottom: 18px;
}
.materials {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 14px;
    counter-reset: m;
    /* Fixed height for 8 items (54px each) + 7 gaps (14px each) = 530px.
     This keeps the rail height stable regardless of how many materials are visible. */
    height: 530px;
    overflow: hidden;
}
.material {
    display: grid;
    grid-template-columns: 32px 1fr auto;
    align-items: baseline;
    gap: 12px;
    padding: 6px 0 8px;
    border-bottom: 1px solid rgba(20, 17, 13, 0.18);
    position: relative;
    transition:
        background 0.3s ease,
        opacity 0.25s ease;
}
.material:last-child {
    border-bottom: 0;
}
/* Excess materials in 3/4-digit modes stay in the DOM and keep their
   grid slot so the rail's vertical rhythm matches 5-digit exactly;
   they're shown disabled (dim) rather than collapsed. */
.material[data-hidden="1"] {
    opacity: 0.28;
    pointer-events: none;
    border-bottom-color: rgba(20, 17, 13, 0.1);
}
.material .roman {
    font-family: var(--serif);
    font-style: italic;
    font-weight: 500;
    font-size: 13px;
    color: var(--ink-mute);
    text-align: right;
    letter-spacing: 0.04em;
}
.material .num {
    font-family: var(--mono);
    font-weight: 700;
    font-size: clamp(28px, 2.4vw, 38px);
    color: var(--ink);
    letter-spacing: -0.02em;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    transition:
        color 0.2s ease,
        transform 0.2s ease;
}
.material .tag {
    font-family: var(--mono);
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--ink-mute);
    white-space: nowrap;
}

.material[data-state="rolling"] {
    background: rgba(200, 49, 28, 0.05);
}
.material[data-state="rolling"] .num {
    color: var(--accent);
    animation: roll 0.07s steps(1) infinite;
}
/* simple drop: fade in only, no bounce, no overshoot */
.material[data-state="locked"] .num {
    color: var(--ink);
    animation: dropIn 0.14s ease-out;
}
@keyframes roll {
    0% {
        transform: translateY(-1px);
    }
    100% {
        transform: translateY(1px);
    }
}
@keyframes dropIn {
    0% {
        opacity: 0;
        transform: translateY(-3px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

.rail__foot {
    margin-top: 18px;
    padding-top: 12px;
    border-top: 1px solid var(--ink);
    font-family: var(--serif);
    font-style: italic;
    font-size: 12px;
    color: var(--ink-mute);
    line-height: 1.45;
}

/* ─── footer / keyboard legend ──────────────────────────────── */
.legend {
    display: flex;
    gap: clamp(18px, 2.4vw, 36px);
    align-items: center;
    padding: 18px 0 8px;
    font-family: var(--mono);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: var(--ink-soft);
    flex-wrap: wrap;
}
.legend__group {
    display: flex;
    align-items: center;
    gap: 8px;
}
.legend__label {
    color: var(--ink-mute);
}
.legend kbd {
    display: inline-block;
    padding: 3px 8px;
    background: var(--paper-deep);
    border: 1px solid var(--ink);
    border-bottom-width: 2px;
    font-family: var(--mono);
    font-size: 10px;
    font-weight: 600;
    text-transform: lowercase;
    color: var(--ink);
    border-radius: var(--radius-lg);
    min-width: 1.8em;
    text-align: center;
}

/* ─── overlay (end of round + help) ─────────────────────────── */
.overlay {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    background: rgba(20, 17, 13, 0.55);
    backdrop-filter: blur(4px) saturate(0.7);
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition:
        opacity 0.25s ease,
        backdrop-filter 0.25s ease,
        background 0.25s ease;
}
.overlay[data-open="1"] {
    opacity: 1;
    pointer-events: auto;
}
.overlay__paper {
    position: relative;
    background: var(--paper);
    border: 1px solid var(--ink);
    width: min(640px, 92vw);
    padding: clamp(28px, 4vw, 48px);
    box-shadow:
        8px 8px 0 var(--ink),
        12px 12px 0 rgba(20, 17, 13, 0.15);
    transform: rotate(-0.4deg);
}
/* Stats overlay has three difficulty sections plus a 20-row history
   table. The paper is a flex column so the non-scrolling children
   (title, intro, sections, headings, footer) get their natural height
   and the history wrap takes the remaining space and scrolls internally.
   The result: 3 stat sections + intro + headings + footer all fit on
   one viewport, with the last-20 list being the only scrollable region. */
.overlay--stats .overlay__paper {
    width: min(960px, 95vw);
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    overflow: visible;
}
.overlay--stats .overlay__paper > * {
    flex-shrink: 0;
}
.stats__history-wrap {
    flex: 1 1 0;
    min-height: 260px;
    overflow-y: auto;
    margin-top: 0;
}
.stats__history {
    display: block;
    border-collapse: collapse;
    width: 100%;
}
.stats__history thead {
    display: block;
    position: sticky;
    top: 0;
    background: var(--paper);
    z-index: 1;
}
.stats__history tbody {
    display: block;
}
.stats__history tr {
    display: flex;
    width: 100%;
}
.stats__history th,
.stats__history td {
    width: 210px;
    flex: 0 0 210px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 18px 30px;
    border-bottom: 1px solid rgba(20, 17, 13, 0.18);
    font-variant-numeric: tabular-nums;
    text-align: left;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-soft);
    font-size: 12px;
}
.stats__history th:first-child,
.stats__history td:first-child {
    width: 210px;
    flex: 0 0 210px;
}
.stats__history th:nth-child(2),
.stats__history td:nth-child(2) {
    width: 120px;
    flex: 0 0 120px;
}
.stats__history th:nth-child(3),
.stats__history td:nth-child(3) {
    width: 120px;
    flex: 0 0 120px;
}
.stats__history th:nth-child(4),
.stats__history td:nth-child(4) {
    width: 150px;
    flex: 0 0 150px;
}
.stats__history th {
    font-weight: 600;
    color: var(--ink-mute);
    border-bottom: 1px solid var(--ink);
}
.stats__history th:last-child,
.stats__history td:last-child {
    flex: 1 1 auto;
    width: auto;
    text-align: right;
    color: var(--ink);
    font-weight: 700;
}
/* Abandoned round (committed but never finished). Render muted with a
   dashed underline so it reads as "incomplete" alongside real 0-score
   finished rounds — same numbers, but a different state. */
.stats__row--pending {
    color: var(--ink-soft);
    font-style: italic;
}
.stats__pending {
    font-size: 0.7em;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-mute);
    border-bottom: 1px dashed var(--ink-mute);
    margin-left: 6px;
    padding-bottom: 1px;
}
/* Seed card — compact, the input is the focus */
.overlay--seed .overlay__paper {
    width: min(520px, 92vw);
}
.seed-card__row {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 16px 0 18px;
}
.seed-card__label {
    font-family: var(--mono);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-mute);
}
.seed-card__input {
    font: inherit;
    font-family: var(--mono);
    font-size: 16px;
    font-weight: 600;
    color: var(--ink);
    background: transparent;
    border: 0;
    border-bottom: 1px solid var(--ink);
    outline: 0;
    padding: 6px 0;
    text-transform: lowercase;
    width: 100%;
}
.seed-card__input::placeholder {
    color: var(--ink-mute);
    font-weight: 500;
}
.seed-card__input:focus {
    border-bottom-color: var(--accent);
    color: var(--accent);
}
.seed-card__actions {
    display: flex;
    gap: 18px;
    flex-wrap: wrap;
    padding-top: 6px;
    border-top: 1px dashed rgba(20, 17, 13, 0.25);
    padding-top: 14px;
}
.seed-card__btn {
    font-family: var(--mono);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-mute);
    background: transparent;
    border: 0;
    padding: 4px 0;
    cursor: pointer;
    transition: color 0.15s ease;
}
.seed-card__btn:hover {
    color: var(--ink);
}
.seed-card__btn:focus-visible {
    outline: 1px dashed var(--ink);
    outline-offset: 3px;
}
.seed-card__btn[data-flash="1"] {
    color: var(--ok);
    animation: pop 0.4s ease-out;
}
.overlay__stamp {
    position: absolute;
    top: -22px;
    right: -18px;
    background: var(--accent);
    color: var(--paper);
    font-family: var(--mono);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    font-size: 12px;
    padding: 8px 14px;
    transform: rotate(6deg);
    border: 2px solid var(--ink);
    box-shadow: 3px 3px 0 var(--ink);
}
.overlay__stamp--alt {
    background: var(--ink);
}
.overlay__title {
    font-family: var(--serif);
    font-variation-settings:
        "opsz" 144,
        "WONK" 1;
    font-weight: 800;
    font-style: italic;
    font-size: clamp(40px, 5vw, 64px);
    line-height: 1;
    letter-spacing: -0.03em;
    margin: 0 0 24px;
    color: var(--ink);
}

.overlay__grid {
    display: grid;
    gap: 10px;
}
.overlay__row {
    display: grid;
    grid-template-columns: 200px 1fr;
    align-items: baseline;
    gap: 14px;
    padding: 10px 0;
    border-bottom: 1px solid rgba(20, 17, 13, 0.18);
}
.overlay__row--big {
    padding: 16px 0;
}
.overlay__label {
    font-family: var(--mono);
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.18em;
    color: var(--ink-mute);
}
.overlay__val {
    font-family: var(--mono);
    font-size: clamp(18px, 1.8vw, 22px);
    font-weight: 600;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
    word-break: break-all;
}
.overlay__val--expr {
    font-family: var(--mono);
    font-size: clamp(16px, 1.6vw, 20px);
}
.overlay__val--score {
    font-family: var(--serif);
    font-weight: 800;
    font-style: italic;
    font-size: clamp(40px, 5vw, 64px);
    color: var(--accent);
    line-height: 1;
}

.overlay__foot {
    flex-shrink: 0;
    margin-top: 0;
    padding-top: 18px;
    border-top: 2px solid var(--ink);
    font-family: var(--mono);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    color: var(--ink-soft);
}
.overlay__foot kbd {
    display: inline-block;
    padding: 2px 6px;
    background: var(--paper-deep);
    border: 1px solid var(--ink);
    font-family: var(--mono);
    font-size: 10px;
    font-weight: 600;
    color: var(--ink);
    border-radius: var(--radius);
    text-transform: lowercase;
}
/* Result-overlay action buttons (dismiss / play again). Sized to sit
   on the same line as the kbd hint in the footer. The primary
   variant uses the accent red so the destructive/forward intent
   reads at a glance — matches the typographic weight of the
   "stop press" stamp above. */
.overlay__btn {
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    color: var(--ink);
    background: transparent;
    border: 0;
    padding: 4px 10px;
    margin-right: 6px;
    cursor: pointer;
    transition:
        color 0.15s ease,
        transform 0.15s ease;
}
.overlay__btn:hover {
    color: var(--accent);
}
.overlay__btn:active {
    transform: translateY(1px);
}
.overlay__btn:focus-visible {
    outline: 1px dashed var(--ink);
    outline-offset: 2px;
}
.overlay__btn--primary {
    color: var(--accent);
}
.overlay__btn--primary:hover {
    color: var(--ink);
}
.overlay__foot-hint {
    margin-left: 12px;
    color: var(--ink-mute);
    font-size: 10px;
}
.rules {
    margin: 0 0 24px;
    padding: 0 0 0 24px;
    font-family: var(--serif);
    font-size: 15px;
    line-height: 1.55;
    color: var(--ink-soft);
}
.rules li {
    margin-bottom: 10px;
}
.rules li::marker {
    color: var(--accent);
    font-weight: 700;
}
.rules em {
    color: var(--ink);
    font-style: italic;
}
.rules code,
.rules kbd {
    font-family: var(--mono);
    font-size: 12px;
    padding: 1px 5px;
    background: var(--paper-deep);
    border: 1px solid var(--ink);
    border-radius: var(--radius);
    color: var(--ink);
    text-transform: lowercase;
}

/* ─── help: scoring chart ─────────────────────────────────── */
.rules__heading {
    font-family: var(--serif);
    font-weight: 700;
    font-style: italic;
    font-size: clamp(18px, 1.9vw, 22px);
    letter-spacing: -0.01em;
    color: var(--ink);
    margin: 24px 0 10px;
}

.scoring-chart {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--mono);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-soft);
    margin: 0 0 12px;
}
.scoring-chart th,
.scoring-chart td {
    text-align: left;
    padding: 9px 12px;
    border-bottom: 1px solid rgba(20, 17, 13, 0.18);
    font-variant-numeric: tabular-nums;
}
.scoring-chart th {
    font-weight: 600;
    color: var(--ink-mute);
    border-bottom: 1px solid var(--ink);
    letter-spacing: 0.14em;
}
.scoring-chart td:last-child {
    color: var(--ink);
    font-weight: 700;
    text-align: right;
    white-space: nowrap;
}
.scoring-chart tbody tr:last-child td {
    border-bottom: 0;
}

.scoring-note {
    font-family: var(--serif);
    font-style: italic;
    font-size: clamp(13px, 1.2vw, 15px);
    color: var(--ink-mute);
    margin: 0;
    line-height: 1.5;
}
.overlay__attribution {
    margin-top: 14px;
}

/* ─── stats overlay ─────────────────────────────────────── */
.stats__intro {
    margin: 0 0 20px;
}
.stats__sections {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 18px;
    margin-bottom: 24px;
}
.stats__section {
    border: 1px solid var(--ink);
    padding: 10px 14px 12px;
    position: relative;
    min-width: 0; /* let the column shrink below its content size */
}
@media (max-width: 1100px) {
    .stats__sections {
        grid-template-columns: 1fr;
    }
}
.stats__section--empty {
    border-style: dashed;
    opacity: 0.55;
}
.stats__section--empty .stats__value {
    color: var(--ink-mute);
}
.stats__heading {
    font-family: var(--serif);
    font-weight: 700;
    font-style: italic;
    font-size: clamp(16px, 1.7vw, 20px);
    letter-spacing: -0.01em;
    color: var(--ink);
    margin: 0 0 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--ink);
}
.stats__grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 16px;
    margin-bottom: 8px;
}
.stats__cell {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.stats__label {
    font-family: var(--mono);
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: var(--ink-mute);
}
.stats__value {
    font-family: var(--serif);
    font-weight: 700;
    font-size: clamp(18px, 2vw, 22px);
    color: var(--ink);
    font-variant-numeric: tabular-nums;
    line-height: 1;
}
.stats__hist {
    display: flex;
    align-items: center;
    gap: 14px;
    padding-top: 12px;
    border-top: 1px dashed rgba(20, 17, 13, 0.25);
}
.stats__hist-label {
    font-family: var(--mono);
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: var(--ink-mute);
    flex-shrink: 0;
    min-width: 9ch;
}
.stats__hist-bars {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    align-items: end;
    gap: 6px;
    height: 50px;
    padding-top: 12px; /* reserves a dedicated row for the count */
    padding-bottom: 10px;
    position: relative;
}
.stats__bar {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    height: 100%;
    position: relative;
    gap: 4px;
}
.stats__bar-track {
    position: absolute;
    inset: 0 0 16px 0;
    border-left: 1px solid rgba(20, 17, 13, 0.18);
    border-bottom: 1px solid rgba(20, 17, 13, 0.18);
}
.stats__bar-fill {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 16px;
    height: 0;
    background: var(--ink);
    transition: height 0.4s ease;
}
.stats__bar[data-zero="1"] .stats__bar-fill {
    background: var(--accent);
}
.stats__bar-label {
    position: absolute;
    bottom: 2px;
    left: 0;
    right: 0;
    text-align: center;
    font-family: var(--mono);
    font-size: 9px;
    font-weight: 600;
    color: var(--ink-mute);
    letter-spacing: 0.04em;
}
.stats__bar-count {
    display: none;
}

.stats__history {
    margin-bottom: 20px;
    width: 100%;
}
.stats__history td:first-child,
.stats__history td:nth-child(2) {
    text-align: right;
    color: var(--ink);
    font-weight: 700;
}
.stats__history td:nth-child(3),
.stats__history td:nth-child(4),
.stats__history td:nth-child(5) {
    color: var(--ink-soft);
    font-weight: 500;
}
.stats__empty td {
    text-align: center;
    color: var(--ink-mute);
    font-style: italic;
    text-transform: lowercase;
    letter-spacing: 0.04em;
}
/* Reset progress — destructive. Two equal-weight entry points: tap R
   five times (within 1.5s gaps) while the stats overlay is open, or
   hold the button for a full second. No progress bar, no fill — the
   action is its own confirmation. Hover hints at the danger with the
   existing accent red, used elsewhere for destructive actions. */
.overlay__foot--split {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.overlay__foot-l,
.overlay__foot-r {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.stats__reset-btn {
    font: inherit;
    color: var(--ink-soft);
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    background: none;
    border: 0;
    padding: 0;
    cursor: pointer;
    transition: color 0.15s ease;
}
.stats__reset-btn:hover {
    color: var(--accent);
}
.stats__reset-btn:focus-visible {
    outline: 1px dashed var(--ink);
    outline-offset: 3px;
}
.stats__reset-hint {
    font-family: var(--mono);
    font-size: 10px;
    color: var(--ink-mute);
    text-transform: lowercase;
    letter-spacing: 0.04em;
}
.stats__reset-hint kbd {
    display: inline-block;
    padding: 1px 5px;
    background: var(--paper-deep);
    border: 1px solid var(--ink);
    font-family: var(--mono);
    font-size: 10px;
    font-weight: 600;
    color: var(--ink);
    border-radius: var(--radius);
    text-transform: lowercase;
    letter-spacing: 0;
}
/* Tap-counter indicator: a row of small circles that fill as the
   player presses the same key repeatedly. Used in two places:
     • the footer legend (R × 3, session wipe)
     • the stats overlay (R × 5, destructive progress wipe)
   Three visual states per dot:
     empty   — 1px ink border, transparent fill
     on      — ink fill (committed, settled)
     just    — accent red, scaled up 1.4× (the dot that was just filled
               by the most recent press; settles to ink over 120ms)
     armed   — accent red, pulsing (the next-to-be-filled dot, after
               N-1 of N presses have been counted; the next press
               will fire the destructive action — visual warning)
   On the final press, all filled dots flash just=red for ~300ms
   before clearing, confirming the gesture fired. */
.tapdots {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    vertical-align: middle;
    margin: 0 4px;
}
.tapdots__dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border: 1px solid var(--ink);
    border-radius: 50%;
    background: transparent;
    transition:
        background-color 0.12s ease,
        transform 0.12s ease;
}
.tapdots__dot[data-on="1"] {
    background: var(--ink);
}
.tapdots__dot[data-just="1"] {
    background: var(--accent);
    transform: scale(1.4);
}
.tapdots__dot[data-armed="1"] {
    background: var(--accent);
    animation: tapdots-pulse 600ms ease-in-out infinite alternate;
}
@keyframes tapdots-pulse {
    from {
        background: var(--paper);
        border-color: var(--accent);
    }
    to {
        background: var(--accent);
        border-color: var(--accent);
    }
}
/* The whole row flashes together when the destructive action fires,
   confirming the gesture completed before the dots drain. */
.tapdots--fired .tapdots__dot {
    background: var(--accent) !important;
    border-color: var(--accent) !important;
    transform: scale(1.4);
}
.tapdots__caption {
    font-family: var(--mono);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: var(--ink-mute);
}
@media (max-width: 920px) {
    .grid {
        grid-template-columns: 1fr;
    }
    .rail--left {
        flex-direction: row;
        min-height: auto;
        height: auto;
        gap: 16px;
        align-items: center;
    }
    .vlabel {
        writing-mode: horizontal-tb;
        transform: none;
        margin: 0;
    }
    .vfill {
        width: auto;
        height: 6px;
        flex: 1;
        min-height: auto;
    }
    .vfill__bar {
        width: 100%;
        height: 100%;
    }
    .rail--right {
        border-left: 0;
        padding-left: 0;
        border-top: 1px solid var(--ink);
        padding-top: 20px;
    }
    .materials {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px 18px;
    }
    .target__num {
        font-size: clamp(100px, 26vw, 195px);
    }
    .masthead__meta {
        min-width: 220px;
    }
}

@media (max-width: 720px) {
    .masthead__meta {
        min-width: 0;
    }
}

@media (max-width: 540px) {
    .wordmark {
        font-size: clamp(48px, 16vw, 96px);
    }
    .target__num {
        font-size: 30vw;
    }
    .equation__row {
        font-size: 22px;
        flex-wrap: wrap;
    }
    .legend {
        font-size: 10px;
        gap: 12px;
    }
    .overlay__row {
        grid-template-columns: 1fr;
        gap: 4px;
    }
}

/* ─── upscale on >1080p displays ─────────────────────────────
   The design is set for 1920×1080. The inline script in
   index.html maps physical monitor width (screen.width — OS-
   scaled, immune to browser zoom) to a zoom factor and adds
   the .scaled class when a factor > 1 is needed. We gate
   every zoom-related rule on that class so 1080p panels (and
   anyone with browser zoom large enough to bring the CSS
   viewport below 1920) hit zero of this — the design renders
   exactly as authored. Above 1920 we scale continuously up
   to 2.5× at 4800-equivalent monitors, and browser zoom now
   stacks normally on top instead of being compensated for. */
html.scaled { zoom: var(--z); }
html.scaled body { min-height: calc(100vh / var(--z)); }
html.scaled .grid { min-height: calc(60vh / var(--z)); }
html.scaled .overlay--stats .overlay__paper { max-height: calc(92vh / var(--z)); }
