/* =============================================================
   VectorVroom · interface stylesheet
   A refined editorial-lab aesthetic: warm paper surfaces, ink
   typography, amber accents carried over from the legacy palette,
   amethyst as a secondary "vector memory" cue. Everything is
   tokenised so components stay modular and themable.
   ============================================================= */

/* ---------- Design tokens ---------------------------------- */
:root {
    /* Typography */
    --font-display: "Fraunces", ui-serif, Georgia, "Times New Roman", serif;
    --font-body: "Plus Jakarta Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
    --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

    /* Paper + ink (warm, low-glare, readable) */
    --paper-0: #fdfaf3;
    --paper-1: #f8f2e4;
    --paper-2: #f1e9d3;
    --paper-3: #e8decb;
    --paper-4: #d7cbb2;

    --ink-900: #1d1a16;
    --ink-800: #2c2823;
    --ink-700: #403a33;
    --ink-600: #5b544a;
    --ink-500: #786f62;
    --ink-400: #9a9083;
    --ink-300: #bbb2a4;
    --ink-200: #d9d2c5;
    --ink-100: #ece6d8;

    /* Accent scales */
    --amber-800: #6a3405;   /* hover for filled CTAs (see --brand-solid) */
    --amber-700: #824006;
    --amber-600: #a45a13;
    --amber-500: #d38b4b;   /* legacy brand — tint / border use */
    --amber-400: #e7a86c;
    --amber-300: #f4c691;
    --amber-200: #fde2bd;
    --amber-100: #fff1d8;
    --amber-50:  #fff8e9;

    --ember:     #c54a16;
    --ink-blue:  #1c3f70;

    --ml-700: #3c2f73;      /* amethyst — vector / ML cue */
    --ml-600: #5a47a6;
    --ml-500: #7a65cc;
    --ml-200: #d6cdf2;
    --ml-100: #ebe4fb;
    --ml-50:  #f5f1fd;

    --success-900: #083820;   /* AAA text on --success-100 chip tint */
    --success-800: #0d5435;   /* AAA-compliant text on paper surfaces */
    --success-700: #1f6e47;
    --success-500: #2f8355;
    --success-100: #d6ecdf;
    --danger-600:  #b23636;
    --danger-100:  #f7d9d9;
    --info-600:    #2f5fb4;
    --info-100:    #dce6f7;

    /* Surfaces */
    --surface-0: var(--paper-0);
    --surface-1: #ffffff;
    --surface-2: var(--paper-1);
    --surface-3: var(--paper-2);

    --line:        #ece2ca;
    --line-strong: #d7c9a9;
    --line-soft:   rgba(94, 75, 39, 0.08);
    /* --line-control: WCAG 1.4.11 (3:1) — essential borders that carry the
       component boundary of form controls (button / select / toggle chips).
       --line / --line-strong sit at ~1.3 / 1.6 on the paper-0 surface which
       is fine for decorative rules but fails for interactive affordances.
       #786f62 is the existing --ink-500; it clears 3:1 on every surface-* tier
       (4.94 on white, 4.08 on paper-2). Alias so the intent reads at sites. */
    --line-control: #786f62;

    /* Radii */
    --r-xs: 4px;
    --r-sm: 8px;
    --r-md: 12px;
    --r-lg: 18px;
    --r-xl: 24px;
    --r-full: 999px;

    /* Shadows — warm & diffuse, not grey */
    --shadow-xs: 0 1px 2px rgba(58, 39, 10, 0.06);
    --shadow-sm: 0 2px 6px rgba(58, 39, 10, 0.07), 0 1px 2px rgba(58, 39, 10, 0.04);
    --shadow-md: 0 8px 20px rgba(58, 39, 10, 0.10), 0 2px 6px rgba(58, 39, 10, 0.06);
    --shadow-lg: 0 20px 44px rgba(58, 39, 10, 0.14), 0 6px 14px rgba(58, 39, 10, 0.08);

    /* Focus ring (WCAG-visible amber halo on both light + dark) */
    --ring: 0 0 0 3px rgba(211, 139, 75, 0.35), 0 0 0 1px var(--amber-600);

    /* Motion */
    --dur-fast: 120ms;
    --dur-med:  220ms;
    --dur-slow: 420ms;
    --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
    --ease-in-out: cubic-bezier(0.45, 0, 0.2, 1);

    /* Spacing scale (4-pt) */
    --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
    --sp-5: 20px; --sp-6: 24px; --sp-7: 32px; --sp-8: 40px;

    /* Atmosphere */
    --grain:
        radial-gradient(circle at 18% 12%, rgba(211, 139, 75, 0.10), transparent 40%),
        radial-gradient(circle at 82% 88%, rgba(122, 101, 204, 0.08), transparent 45%),
        radial-gradient(circle at 50% 50%, rgba(255, 241, 216, 0.5), transparent 60%);
}

@media (prefers-color-scheme: dark) {
    :root {
        --paper-0: #141217;
        --paper-1: #1a1720;
        --paper-2: #211d29;
        --paper-3: #2b2633;
        --paper-4: #3a3443;

        --ink-900: #f5efe4;
        --ink-800: #e8e1d2;
        --ink-700: #ccc2b0;
        --ink-600: #a89f8f;
        --ink-500: #8b8474;
        --ink-400: #726b5f;
        --ink-300: #58524a;
        --ink-200: #403b36;
        --ink-100: #2c2826;

        --surface-0: var(--paper-0);
        --surface-1: #1d1a23;
        --surface-2: #24202c;
        --surface-3: #2d2835;

        --line:        rgba(255, 241, 216, 0.08);
        --line-strong: rgba(255, 241, 216, 0.18);
        --line-soft:   rgba(255, 241, 216, 0.05);
        /* --line-control: 3:1 against every dark surface tier (see light
           definition for rationale). 0.45 alpha composites to a mid-grey
           that clears ~4:1 on surface-1/2 and ~3.8 on surface-3/paper-3. */
        --line-control: rgba(255, 241, 216, 0.45);

        --amber-100: rgba(211, 139, 75, 0.14);
        --amber-50:  rgba(211, 139, 75, 0.08);
        --ml-100:    rgba(122, 101, 204, 0.18);
        --ml-50:     rgba(122, 101, 204, 0.10);

        --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.35), 0 1px 2px rgba(0, 0, 0, 0.25);
        --shadow-md: 0 8px 20px rgba(0, 0, 0, 0.42), 0 2px 6px rgba(0, 0, 0, 0.28);
        --shadow-lg: 0 20px 44px rgba(0, 0, 0, 0.55), 0 6px 14px rgba(0, 0, 0, 0.35);

        --grain:
            radial-gradient(circle at 18% 12%, rgba(211, 139, 75, 0.14), transparent 40%),
            radial-gradient(circle at 82% 88%, rgba(122, 101, 204, 0.12), transparent 45%),
            radial-gradient(circle at 50% 60%, rgba(40, 36, 54, 0.6), transparent 70%);
    }
}

/* ---------- Reset-ish ---------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    min-height: 100vh;
}

body {
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.5;
    color: var(--ink-800);
    background: var(--paper-0);
    background-image: var(--grain);
    background-attachment: fixed;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: "ss01", "cv11";
}

::selection {
    background: var(--amber-200);
    color: var(--amber-700);
}

/* Kill the legacy `p { line-height: .2em }` footgun without relying on each
   sub-component to override it. Anything that really needs compression sets
   it locally. */
p { line-height: 1.5; margin: 0 0 .6em 0; }

/* ---------- Layout ----------------------------------
   Single-row, 2-column grid. The track (left) takes all available vertical
   space; the right column is a collapsible card that can drop to zero width
   via the .panel-collapsed modifier so the canvas can claim the whole
   viewport. The training-phase banner is absolutely positioned over the
   canvas (see #bottomText below) so it no longer steals a grid row.

   Outer padding + gap intentionally smaller than the rest of the card
   system (sp-2 vs sp-4) — the grid gutter is aesthetic, not structural,
   and every pixel given back to the canvas is pixels of track. */
#fullDisplay {
    display: grid;
    grid-template-columns: minmax(0, 1fr) clamp(260px, 24vw, 340px);
    grid-template-rows: minmax(0, 1fr);
    gap: var(--sp-2);
    width: 100vw;
    height: 100vh;
    padding: var(--sp-2);
    box-sizing: border-box;
    transition: grid-template-columns var(--dur-med) var(--ease-out);
}

/* Collapsed state: right column shrinks to 0. overflow: hidden on the panel
   itself so the card contents don't spill out mid-transition. */
#fullDisplay.panel-collapsed {
    grid-template-columns: minmax(0, 1fr) 0;
}

#canvasDiv {
    grid-row: 1 / span 1;
    grid-column: 1 / span 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    min-height: 0;
    /* position: relative so the absolutely-positioned #bottomText banner
       anchors to this cell rather than the viewport. */
    position: relative;
}

#myCanvas {
    /* The underlying bitmap is fixed at 3200×1800 (main.js). Let the browser
       start from that intrinsic size and scale down proportionally inside
       the parent — max-width / max-height without an explicit width keeps
       the 16:9 ratio honest. Forcing width:100% + max-height:100% here
       makes the browser clamp height while keeping width, which stretches
       the scene. */
    max-width: 100%;
    max-height: 100%;
    aspect-ratio: 16 / 9;
    background: #15161a;
    border-radius: var(--r-lg);
    box-shadow:
        var(--shadow-lg),
        inset 0 0 0 1px rgba(255, 255, 255, 0.04);
    outline: none;
    transition: box-shadow var(--dur-med) var(--ease-out);
}

#myCanvas:focus-visible {
    box-shadow: var(--shadow-lg), 0 0 0 3px var(--amber-500);
}

/* P3.E A/B comparison layout. When .ab-on is on #canvasDiv, it switches
   from a single-child flex centre to a vertical stack — A on top, B below,
   both sharing the vertical space. The 16:9 aspect-ratio survives because
   max-height constrains each canvas to half the column. When .ab-on is
   removed, #myCanvasB is hidden again and A reclaims the whole cell. */
#canvasDiv.ab-on {
    flex-direction: column;
    gap: 6px;
}
#canvasDiv.ab-on > #myCanvas,
#canvasDiv.ab-on > #myCanvasB {
    max-height: calc(50% - 3px);
    width: auto;
}
#myCanvasB {
    max-width: 100%;
    max-height: 100%;
    aspect-ratio: 16 / 9;
    background: #15161a;
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-lg), inset 0 0 0 1px rgba(255, 255, 255, 0.04);
    /* Dim tint signals "this is the baseline (no ruvector)" — amber badge
       on #ab-hud-b reinforces it. */
    outline: 1px solid rgba(148, 163, 184, 0.35);
}
/* Sits at the midline between the stacked A and B canvases (top:50%) and
   anchored to the left so it doesn't collide with the primary "metrics"
   HUD which is fixed at top-center of the viewport.

   IMPORTANT: `display: flex` would otherwise override the HTML `hidden`
   attribute (UA [hidden]{display:none} loses to an author #id rule), which
   left empty #ab-hud-b / #ab-hud-delta chips floating on the track when A/B
   mode was off. Always pair the flex rule with an explicit [hidden] kill. */
#ab-hud {
    position: absolute;
    top: calc(50% - 32px);
    left: 8px;
    z-index: 5;
    display: flex;
    flex-direction: row;
    gap: 6px;
    pointer-events: none;
    font: 11px/1.35 ui-monospace, Menlo, monospace;
    color: #a8c8ff;
}
#ab-hud[hidden] {
    display: none !important;
}
#ab-hud-b, #ab-hud-delta {
    background: rgba(12, 14, 18, .88);
    padding: 6px 9px;
    border-radius: 4px;
    text-align: center;
    min-width: 220px;
}
#ab-hud-b {
    border-left: 3px solid #94a3b8;
}
#ab-hud-delta {
    border-left: 3px solid var(--amber-500, #e38a0f);
    color: #ffd89a;
}

/* ---------- Right panel (primary controls card) ----------------------------------
   Single scroll surface for controls + vector-memory (#rv-panel is nested
   inside this card now, so there's one scroll container instead of two). */
#rightPanel {
    grid-column: 2 / span 1;
    grid-row: 1 / span 1;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: var(--sp-2);
    min-width: 0;
    min-height: 0;
    padding: var(--sp-4);
    background: var(--surface-1);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-sm);
    overflow-y: auto;
    scrollbar-gutter: stable;
    scrollbar-width: thin;
    scrollbar-color: var(--ink-200) transparent;
    transition: opacity var(--dur-med) var(--ease-out), padding var(--dur-med) var(--ease-out);
}

/* When #fullDisplay.panel-collapsed the column width already drops to 0
   via grid-template-columns. Hide the card surface too so stale content
   doesn't leak out during the transition, and stop it from intercepting
   pointer events once it's off-screen. */
#fullDisplay.panel-collapsed #rightPanel {
    opacity: 0;
    padding-inline: 0;
    pointer-events: none;
    overflow: hidden;
}

#rightPanel::-webkit-scrollbar { width: 8px; }
#rightPanel::-webkit-scrollbar-thumb {
    background: var(--ink-200);
    border-radius: 8px;
}
#rightPanel::-webkit-scrollbar-thumb:hover { background: var(--ink-300); }

#verticalButtons {
    /* A 2-column grid so that .back + .next pair up side-by-side without
       touching the markup. Everything else spans both columns. */
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--sp-2);
    width: 100%;
}
#verticalButtons > *:not(.backNext) {
    grid-column: 1 / -1;
}
/* Default: a lone .backNext (phases 1 + 4) spans the full row so it reads
   as prominent instead of orphaned in one column. */
#verticalButtons > .backNext { grid-column: 1 / -1; }
/* When both a Back and a Next are present (phases 2 + 3) they split 50/50. */
#verticalButtons:has(.backNext + .backNext) > .backNext.back { grid-column: 1; }
#verticalButtons:has(.backNext + .backNext) > .backNext.next { grid-column: 2; }

/* ---------- Buttons ---------------------------------- */
.controlButton {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    width: 100%;
    padding: 0.65em 0.9em;
    font-family: var(--font-body);
    font-size: 0.92rem;
    font-weight: 500;
    line-height: 1.2;
    color: var(--amber-700);
    background: var(--surface-1);
    /* WCAG 1.4.11: amber-500 border was 2.78:1 on white — below the 3:1
       threshold for essential control boundaries. amber-600 (#a45a13) clears
       5:1 on every paper tier. Hover shifts back to the same tone; no visible
       change on that state because hover is already carried by the bg tint. */
    border: 1px solid var(--amber-600);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-xs);
    cursor: pointer;
    text-align: center;
    letter-spacing: 0.005em;
    transition:
        background-color var(--dur-fast) var(--ease-out),
        border-color var(--dur-fast) var(--ease-out),
        color var(--dur-fast) var(--ease-out),
        transform var(--dur-fast) var(--ease-out),
        box-shadow var(--dur-fast) var(--ease-out);
    -webkit-appearance: none;
    appearance: none;
}

.controlButton:hover {
    background: var(--amber-50);
    border-color: var(--amber-600);
    color: var(--amber-700);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.controlButton:active {
    transform: translateY(0);
    box-shadow: var(--shadow-xs);
    background: var(--amber-100);
}

.controlButton:focus-visible {
    outline: none;
    box-shadow: var(--ring), var(--shadow-sm);
}

.controlButton:disabled,
.controlButton[aria-disabled="true"] {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}

/* Dark-mode button: the surface flips but the amber accent still reads. */
@media (prefers-color-scheme: dark) {
    .controlButton {
        color: var(--amber-300);
        background: var(--surface-2);
        /* 1.4.11: 0.55 alpha was ~2.9:1 on surface-2 — below the 3:1
           threshold. 0.85 composites to ~4.5:1 and still feels amber-tinted
           rather than pure white. */
        border-color: rgba(211, 139, 75, 0.85);
    }
    .controlButton:hover {
        background: rgba(211, 139, 75, 0.14);
        color: var(--amber-200);
    }
    .controlButton:active {
        background: rgba(211, 139, 75, 0.22);
    }
}

/* Back / Next — primary navigation between phases. Filled, prominent,
   side-by-side (via #verticalButtons grid). */
.backNext {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4em;
    width: 100%;
    padding: 0.75em 0.9em;
    margin: 0;
    font-family: var(--font-body);
    font-size: 0.92rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #ffffff;
    /* Filled primary actions target WCAG AAA (7:1). White text only passes
       against amber-700 or darker; amber-500 (the brand chip color) tops
       out at ~2.8:1 and can't be rescued without the whole button fill
       moving down the ladder. */
    background: var(--amber-700);
    border: 1px solid var(--amber-800);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    float: none;
    transition:
        background-color var(--dur-fast) var(--ease-out),
        border-color var(--dur-fast) var(--ease-out),
        color var(--dur-fast) var(--ease-out),
        transform var(--dur-fast) var(--ease-out),
        box-shadow var(--dur-fast) var(--ease-out);
}

.backNext:hover {
    background: var(--amber-800);
    border-color: var(--amber-800);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}
.backNext:active {
    transform: translateY(0);
    background: var(--amber-800);
    box-shadow: var(--shadow-xs);
}
.backNext:focus-visible {
    outline: none;
    box-shadow: var(--ring), var(--shadow-sm);
}
/* WCAG 2.1 SC 1.4.3 note: inactive UI components are explicitly exempt
   from contrast requirements, so the muted ink-400 here is deliberate —
   the "not available right now" affordance carries meaning that AAA
   text contrast would actively fight. */
.backNext:disabled,
.backNext[aria-disabled="true"] {
    background: var(--surface-2);
    color: var(--ink-400);
    /* 1.4.11: disabled *text* is exempt, but the border that conveys
       "this is a button" still needs 3:1. --line-control clears that. */
    border-color: var(--line-control);
    box-shadow: none;
    cursor: not-allowed;
    transform: none;
    opacity: 0.7;
}
.backNext:disabled:hover,
.backNext[aria-disabled="true"]:hover {
    background: var(--surface-2);
    color: var(--ink-400);
    /* 1.4.11: disabled *text* is exempt, but the border that conveys
       "this is a button" still needs 3:1. --line-control clears that. */
    border-color: var(--line-control);
    transform: none;
    box-shadow: none;
}

.back  { justify-content: center; }
.next  { justify-content: center; }

/* Directional chevrons */
.back::before { content: "←"; margin-right: 0.35em; font-weight: 600; opacity: 0.9; }
.next::after  { content: "→"; margin-left:  0.35em; font-weight: 600; opacity: 0.9; }

/* "Prev" is a secondary action — tint it so Next reads as the primary. */
.back {
    background: var(--surface-1);
    color: var(--amber-700);
    /* 1.4.11: amber-500 was 2.78:1 on white; amber-600 clears 5:1. */
    border-color: var(--amber-600);
}
.back:hover {
    background: var(--amber-50);
    color: var(--amber-700);
    border-color: var(--amber-600);
}
.back:active {
    background: var(--amber-100);
    color: var(--amber-700);
}

@media (prefers-color-scheme: dark) {
    .back {
        background: var(--surface-2);
        color: var(--amber-300);
        /* 1.4.11: see .controlButton dark rule — 0.85 alpha clears 3:1. */
        border-color: rgba(211, 139, 75, 0.85);
    }
    .back:hover {
        background: rgba(211, 139, 75, 0.14);
        color: var(--amber-200);
    }
}

/* ---------- Start-training CTA ----------------------------------
   On page load the Pause button is repurposed as an explicit Start
   Training call-to-action. Filled amber, larger type, centered icon. */
.controlButton.start-cta {
    color: #fff;
    /* AAA: white needs amber-700+ (see .backNext for rationale). */
    background: var(--amber-700);
    border-color: var(--amber-800);
    font-weight: 700;
    font-size: 1.02rem;
    letter-spacing: 0.04em;
    padding: 0.85em 0.9em;
    box-shadow: var(--shadow-md);
    animation: start-cta-pulse 2200ms var(--ease-in-out) infinite;
}
.controlButton.start-cta:hover {
    background: var(--amber-800);
    border-color: var(--amber-800);
    color: #fff;
}
.controlButton.start-cta:active {
    background: var(--amber-800);
    color: #fff;
}
@keyframes start-cta-pulse {
    0%, 100% { box-shadow: var(--shadow-md), 0 0 0 0 rgba(211, 139, 75, 0.45); }
    50%      { box-shadow: var(--shadow-md), 0 0 0 10px rgba(211, 139, 75, 0); }
}
@media (prefers-reduced-motion: reduce) {
    .controlButton.start-cta { animation: none; }
}

/* Canvas-centered Start overlay — reachable when the right panel is
   collapsed. Mirrors the panel Start CTA so the main action is never
   buried behind a hidden sidebar. */
#startOverlay {
    position: absolute;
    inset: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    background:
        radial-gradient(ellipse 55% 45% at 50% 50%,
            rgba(12, 14, 18, 0.55),
            rgba(12, 14, 18, 0.12) 70%,
            transparent 100%);
}
#startOverlay[hidden] { display: none !important; }
.start-overlay-btn {
    pointer-events: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    min-width: min(72vw, 280px);
    padding: 1.15em 1.6em 1em;
    border: 1.5px solid var(--amber-600);
    border-radius: var(--r-xl);
    background: var(--amber-700);
    color: #fff;
    font-family: var(--font-body);
    box-shadow: var(--shadow-lg), 0 0 0 0 rgba(211, 139, 75, 0.4);
    cursor: pointer;
    animation: start-cta-pulse 2200ms var(--ease-in-out) infinite;
    transition: transform var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out);
}
.start-overlay-btn:hover {
    transform: translateY(-2px) scale(1.02);
    background: var(--amber-600);
}
.start-overlay-btn:focus-visible {
    outline: none;
    box-shadow: var(--ring), var(--shadow-lg);
}
.start-overlay-icon {
    font-size: 1.6rem;
    line-height: 1;
}
.start-overlay-label {
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: 0.03em;
}
.start-overlay-hint {
    font-size: 0.72rem;
    font-weight: 500;
    opacity: 0.85;
    letter-spacing: 0.01em;
}
.start-overlay-btn.is-starting {
    opacity: 0.9;
    cursor: progress;
    animation: none;
    transform: none;
}
.start-overlay-btn:disabled {
    cursor: progress;
}
@media (prefers-reduced-motion: reduce) {
    .start-overlay-btn { animation: none; }
}

/* Secondary control button tint — used for Customize Track so it reads as
   subordinate to the Start CTA above it. */
.controlButton.secondary {
    background: var(--surface-2);
    color: var(--ink-700);
    /* 1.4.11: --line-strong is 1.64:1 on paper — below 3:1. --line-control
       (ink-500) clears 4:1 on every surface tier. */
    border-color: var(--line-control);
}
.controlButton.secondary:hover {
    background: var(--surface-3);
    color: var(--ink-800);
    border-color: var(--ink-300);
}

/* ---------- More actions (collapsible secondary buttons) ------- */
.more-actions {
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    background: var(--surface-2);
    overflow: hidden;
}
.more-actions > summary {
    padding: 0.45em 0.75em;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--ink-700); /* AAA: ink-600 tops out at 6.69 on paper-2 */
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.4em;
    user-select: none;
}
.more-actions > summary::-webkit-details-marker { display: none; }
.more-actions > summary::before {
    content: "▸";
    transition: transform var(--dur-fast) var(--ease-out);
    font-size: 0.75em;
    color: var(--ink-500);
}
.more-actions[open] > summary::before { transform: rotate(90deg); }
.more-actions > summary:hover { background: var(--surface-3); color: var(--ink-800); }
.more-actions-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--sp-2);
    padding: var(--sp-2) var(--sp-3) var(--sp-3);
}
.more-actions-body .controlButton {
    font-size: 0.82rem;
    padding: 0.45em 0.55em;
}
.more-actions-body .brain-share {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--sp-2);
}

/* Training-preset cluster (the 🌱 / 🏎️ / ✨ row) — clamp inline-style
   overrides so each button is still a card in the shared language. */
#trainingPresets {
    display: flex !important;
    gap: var(--sp-2) !important;
    flex-wrap: wrap;
    margin: var(--sp-2) 0 !important;
    padding: var(--sp-3);
    background: var(--amber-50);
    border: 1px dashed var(--amber-300);
    border-radius: var(--r-md);
}
#trainingPresets .controlButton {
    font-size: 0.85rem;
    padding: 0.55em 0.6em;
}

/* ---------- Titles & bottom banner ----------------------------------
   Floats over the bottom-center of the canvas rather than occupying its
   own grid row. pointer-events: none is load-bearing: without it the
   banner would eat clicks in phase 1 (track draw) where every pixel of
   the canvas needs to be interactive. Translucent + backdrop-blur so the
   scene behind it stays legible. */
#bottomText {
    position: absolute;
    /* Slightly left of center so the cinema control chips (bottom-right)
       never sit on top of the phase banner. */
    left: 42%;
    bottom: var(--sp-3);
    transform: translateX(-50%);
    padding: var(--sp-2) var(--sp-5);
    background: rgba(255, 255, 255, 0.82);
    -webkit-backdrop-filter: blur(8px) saturate(120%);
    backdrop-filter: blur(8px) saturate(120%);
    border: 1px solid var(--line);
    border-radius: var(--r-full);
    box-shadow: var(--shadow-sm);
    color: var(--ink-900);
    text-align: center;
    max-width: min(48%, 320px);
    pointer-events: none;
    z-index: 5;
}
@media (prefers-color-scheme: dark) {
    #bottomText {
        background: rgba(29, 26, 22, 0.72);
        border-color: var(--line-strong);
    }
}

#bottomText h1,
h1 {
    margin: 0;
    font-family: var(--font-display);
    font-weight: 500;
    font-variation-settings: "opsz" 48, "SOFT" 50;
    font-size: clamp(1.1rem, 2.4vw, 1.6rem);
    letter-spacing: -0.01em;
    line-height: 1.15;
    color: inherit;
}

#bottomText h1 + h1 { margin-top: 0.25em; font-size: 0.95em; color: var(--ink-600); }

/* Accent pill colors for the instructional text (preserve existing class
   names the JS assigns). The "red"/"blue" labels were literal colors; now
   they're proper badges. */
.red, .blue {
    display: inline-block;
    padding: 0.05em 0.45em;
    border-radius: var(--r-full);
    font-family: var(--font-body);
    font-weight: 700;
    font-size: 0.9em;
    letter-spacing: 0.01em;
    line-height: 1.4;
    vertical-align: baseline;
    transform: translateY(-0.05em);
}
.red  { color: #b11c1c; background: #fde3e3; box-shadow: inset 0 0 0 1px #f4b5b5; }
.blue { color: #1c3f8b; background: #e1ebff; box-shadow: inset 0 0 0 1px #b8c8ef; }

@media (prefers-color-scheme: dark) {
    .red  { color: #ff9a9a; background: rgba(255, 120, 120, 0.14); box-shadow: inset 0 0 0 1px rgba(255, 120, 120, 0.35); }
    .blue { color: #9ab8ff; background: rgba(120, 150, 255, 0.14); box-shadow: inset 0 0 0 1px rgba(120, 150, 255, 0.35); }
}

/* ---------- Live-data region (phase 4) ----------------------------------
   A compact vertical stack pinned high in #rightPanel so the training
   signals (fitness curve + NN viz + timer) stay visible without scrolling
   the panel. #liveData is the host for inputCanvas + graphCanvas that
   showInputCanvas/showGraphCanvas append dynamically. */
.live-data {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--sp-2);
    margin: var(--sp-1) 0;
}
.live-data canvas {
    width: 100% !important;
    height: auto !important;
    display: block;
    background: linear-gradient(180deg, #ffffff 0%, #f7efde 100%);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-xs);
}
.live-data #graphCanvas {
    aspect-ratio: 4 / 2;
    max-height: 140px;
}
.live-data #inputCanvas {
    aspect-ratio: 2 / 1;
    max-height: 90px;
}
@media (prefers-color-scheme: dark) {
    .live-data canvas {
        background: linear-gradient(180deg, #1c1924 0%, #24202c 100%);
        border-color: var(--line-strong);
    }
}
/* Legacy selectors (when phase-4 layout falls back to appending onto
   #rightPanel directly rather than into #liveData). */
#inputCanvas {
    display: block;
    width: 100%;
    min-height: 84px;
    max-height: 120px;
    max-width: 100%;
    background: linear-gradient(180deg, #ffffff 0%, #f7efde 100%);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-xs);
    object-fit: contain;
}

.timer-eli15 {
    display: flex;
    gap: 0.25em;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 0.2em;
}
@media (prefers-color-scheme: dark) {
    #graphCanvas {
        background: linear-gradient(180deg, #1c1924 0%, #24202c 100%);
        border-color: var(--line-strong);
    }
}

@media (prefers-color-scheme: dark) {
    #inputCanvas {
        background: linear-gradient(180deg, #1c1924 0%, #24202c 100%);
        border-color: var(--line-strong);
    }
}

label {
    color: var(--ink-700);
    font-size: 0.9em;
    font-weight: 500;
}

#inputsContainer {
    display: flex;
    flex-direction: column;
    /* No uniform gap — we want asymmetric spacing: the output label should
       sit tight against its own slider, and the NEXT slider should sit
       further down. */
    gap: 0;
    padding: var(--sp-2) var(--sp-3) var(--sp-3);
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
}
/* Sliders (all but the first) get a bigger top margin, pushing them away
   from the preceding output so each label visually belongs to its slider
   above. */
#inputsContainer > input[type="range"] { margin-top: var(--sp-3); }
#inputsContainer > input[type="range"]:first-child { margin-top: 0; }
#inputsContainer output {
    font-size: 0.82em;
    color: var(--ink-700);
    /* Small negative margin pulls the label tight under the slider knob. */
    margin-top: -2px;
    line-height: 1.1;
}
/* Sim Speed label sits after the last output — keep it spaced from the
   preceding variance label. */
#inputsContainer > #simSpeedLabel { margin-top: var(--sp-3) !important; }

#timer {
    text-align: center;
    font-family: var(--font-mono);
    font-size: 0.82rem;
    font-variant-numeric: tabular-nums;
    color: var(--ink-700);
    padding: var(--sp-1) 0;
    border-top: 1px dashed var(--line-strong);
    margin-top: var(--sp-1);
}

#timer-eli15 {
    display: flex;
    gap: 0.25em;
    justify-content: center;
    flex-wrap: wrap;
}

#simSpeedLabel {
    color: var(--ink-700);
}

#simSpeedLabel select {
    padding: 0.3em 0.4em;
    background: var(--surface-1);
    color: var(--ink-900);
    /* 1.4.11: native select boundary needs 3:1 so sighted users can find
       the edge of the control. --line-control clears 4:1 across surfaces. */
    border: 1px solid var(--line-control);
    border-radius: var(--r-sm);
    font-family: var(--font-body);
    font-size: 0.9em;
    cursor: pointer;
}
#simSpeedLabel select:focus-visible {
    outline: none;
    box-shadow: var(--ring);
}

/* ---------- Track preset picker (fixed top-left chip) ---------------------------------- */
#track-preset-picker {
    /* Sits beneath the two learning-tool pills at top-left (≈ drawer FAB
       height + gap + tour FAB height + gap). Phase-1 only, so the stack
       doesn't crowd during normal training. */
    top: calc(var(--sp-4) + 90px) !important;
    left: var(--sp-4) !important;
    padding: var(--sp-3) var(--sp-4) !important;
    background: var(--surface-1) !important;
    color: var(--ink-800) !important;
    border: 1px solid var(--line) !important;
    border-radius: var(--r-md) !important;
    box-shadow: var(--shadow-md) !important;
    font: 0.85rem/1.4 var(--font-body) !important;
}

#track-preset-picker label {
    display: block;
    color: var(--ink-700);
    font-weight: 600;
    font-size: 0.78rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-bottom: var(--sp-2) !important;
    opacity: 1 !important;
}

#track-preset-select {
    background: var(--surface-2) !important;
    color: var(--ink-900) !important;
    /* 1.4.11: see #simSpeedLabel select. */
    border: 1px solid var(--line-control) !important;
    border-radius: var(--r-sm) !important;
    padding: 0.3em 0.5em !important;
    font: inherit;
    cursor: pointer;
}
#track-preset-select:focus-visible {
    outline: none;
    box-shadow: var(--ring);
}

#track-preset-load {
    /* AAA-compliant fill (see .backNext). */
    background: var(--amber-700) !important;
    color: #fff !important;
    /* 1.4.11: the filled amber-700 body is 4.57:1 on paper-0 in light mode
       (passes), but drops to 2.19:1 on dark surface-1, so the button has no
       visible edge in dark mode. amber-800 trim keeps the light-mode feel
       identical; the dark-mode override below lifts it to amber-400. */
    border: 1px solid var(--amber-800) !important;
    border-radius: var(--r-sm) !important;
    padding: 0.35em 0.9em !important;
    font: inherit;
    font-weight: 600 !important;
    cursor: pointer;
    transition: background-color var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}
#track-preset-load:hover {
    background: var(--amber-800) !important;
    transform: translateY(-1px);
}
#track-preset-load:focus-visible {
    outline: none;
    box-shadow: var(--ring);
}

/* =============================================================
   Vector-memory panel (#rv-panel)
   Re-tuned so the chip/text color choices read on a LIGHT
   surface. The legacy CSS used dark-panel text tones (#bcd, #8aa)
   that were nearly invisible over #fafafa.
   ============================================================= */
/* #rv-panel is now a *nested* section inside #rightPanel (not a standalone
   grid cell), so it no longer needs its own scroll container or grid
   placement — the parent card scrolls. We keep the violet rim + subtle
   background so the vector-memory story still reads as a distinct section
   separated from the controls above it. */
#rv-panel {
    margin-top: var(--sp-3);
    padding: var(--sp-3);
    background: var(--ml-50);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    font-family: var(--font-body);
    font-size: 0.82rem;
    color: var(--ink-800);
    min-width: 0;

    /* Violet top-rim carried over from the standalone-card design. */
    background-image:
        linear-gradient(180deg, var(--ml-50) 0%, var(--surface-1) 40px);
}

.rv-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: baseline;
    gap: var(--sp-2);
    border-bottom: 1px solid var(--line);
    padding-bottom: var(--sp-2);
    margin-bottom: var(--sp-3);
}

.rv-title {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1.02rem;
    color: var(--ml-700);
    letter-spacing: -0.005em;
}

.rv-info {
    font-size: 0.75rem;
    color: var(--ink-700); /* AAA */
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
}
.rv-info-muted { color: var(--ink-700); font-style: italic; }

/* P3.F — per-generation seed-source breakdown line. Sits just below the
   info row; same muted typographic weight since it's diagnostic, not a KPI. */
.rv-seed-sources {
    margin-top: 0.25rem;
    font-size: 0.72rem;
    color: var(--ink-600);
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
}
.rv-seed-sources[hidden] { display: none; }

/* Master toggle — custom switch */
.rv-master-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.4em;
    cursor: pointer;
    user-select: none;
    font-size: 0.7rem;
    color: var(--ink-500);
    margin-left: auto;
    padding: 0.2em 0.4em;
    border-radius: var(--r-sm);
    transition: background-color var(--dur-fast) var(--ease-out);
}
.rv-master-toggle:hover { background: var(--ml-50); }
.rv-master-toggle input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}
.rv-master-toggle-track {
    position: relative;
    display: inline-block;
    width: 30px;
    height: 16px;
    background: var(--ink-200);
    border-radius: var(--r-full);
    transition: background-color var(--dur-fast) var(--ease-out);
}
.rv-master-toggle-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 12px;
    height: 12px;
    background: var(--surface-1);
    border-radius: 50%;
    box-shadow: var(--shadow-xs);
    transition: transform var(--dur-med) var(--ease-out);
}
.rv-master-toggle input[type="checkbox"]:checked + .rv-master-toggle-track {
    background: var(--amber-500);
}
.rv-master-toggle input[type="checkbox"]:checked + .rv-master-toggle-track .rv-master-toggle-thumb {
    transform: translateX(14px);
}
.rv-master-toggle input[type="checkbox"]:focus-visible + .rv-master-toggle-track {
    box-shadow: var(--ring);
}
.rv-master-toggle-label {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    letter-spacing: 0.04em;
    min-width: 1.5em;
    color: var(--ink-700); /* AAA */
    text-transform: uppercase;
}

/* Reranker-mode chip */
.rv-reranker-mode {
    display: flex;
    align-items: center;
    gap: 0.4em;
    margin: 0 0 0.4em 0;
    font-size: 0.75rem;
    color: var(--ink-700); /* AAA */
}
.rv-reranker-mode[hidden] { display: none; }
.rv-reranker-mode-label { color: var(--ink-700); letter-spacing: 0.02em; }
.rv-reranker-mode-value {
    font-family: var(--font-mono);
    font-weight: 600;
    padding: 0.1em 0.55em;
    border-radius: var(--r-full);
    background: var(--amber-100);
    color: var(--amber-700);
    font-size: 0.75rem;
}
.rv-reranker-mode-gnn  { background: var(--success-100); color: var(--success-900); /* AAA: success-700 hit only 5.0 on the chip tint */ }
.rv-reranker-mode-ema  { background: var(--amber-100);   color: var(--amber-700); }
.rv-reranker-mode-none { background: var(--ink-100);     color: var(--ink-700); /* AAA */ }

.rv-reranker {
    font-size: 0.75rem;
    color: var(--ink-700); /* AAA: was ink-600 (6.72:1 on ml-50) */
    margin: 0 0 0.5em 0;
    padding: 0 0 0.4em 0;
    border-bottom: 1px dashed var(--line);
    letter-spacing: 0.01em;
}
.rv-reranker[hidden] { display: none; }
.rv-reranker-muted { color: var(--ink-700); font-style: italic; }

.rv-badge-row {
    display: flex;
    align-items: flex-start;
    gap: 0.35em;
}

.rv-badge {
    margin: 0.35em 0 0.6em 0;
    padding: 0.5em 0.65em;
    background: var(--amber-50);
    border-left: 3px solid var(--amber-500);
    border-radius: var(--r-sm);
    line-height: 1.35;
    color: var(--amber-700);
    font-size: 0.8rem;
    opacity: 0;
    transform: translateY(-4px);
}
.rv-badge[hidden] { display: none; }
.rv-badge.rv-badge-showing {
    animation: rv-badge-pulse 4800ms ease-out forwards;
}
@keyframes rv-badge-pulse {
    0%   { opacity: 0; transform: translateY(-6px); }
    8%   { opacity: 1; transform: translateY(0); }
    92%  { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(-2px); }
}
@media (prefers-reduced-motion: reduce) {
    .rv-badge.rv-badge-showing {
        animation: rv-badge-pulse-flat 4800ms linear forwards;
    }
    @keyframes rv-badge-pulse-flat {
        0%,  92%  { opacity: 1; transform: none; }
        100%      { opacity: 0; transform: none; }
    }
}

.rv-list-title {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-700); /* AAA */
    font-weight: 600;
    margin: 0.6em 0 0.3em 0;
}

.rv-list {
    display: flex;
    flex-direction: column;
    gap: 0.3em;
}
.rv-empty {
    color: var(--ink-700); /* AAA: ink-400 hit only 2.8:1 */
    font-style: italic;
    padding: 0.4em 0.3em;
    background: var(--surface-2);
    border-radius: var(--r-sm);
    font-size: 0.78rem;
}

.rv-item {
    display: flex;
    flex-direction: column;
    gap: 0.2em;
    padding: 0.4em 0.55em;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    font-variant-numeric: tabular-nums;
    transition: border-color var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out);
}
.rv-item:hover {
    border-color: var(--amber-400);
    background: var(--amber-50);
}

.rv-item-top {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto auto auto auto;
    gap: 0.45em;
    align-items: baseline;
}
.rv-item-bottom {
    display: flex;
    align-items: center;
    gap: 0.45em;
    padding-left: 0.1em;
}

/* AAA contrast: on #rv-panel surfaces (paper-1 / ml-50) ink-400/500/600
   top out below 7:1. Everything below reads metadata labels — hierarchy
   comes from font-weight, mono-styling, and column placement, not
   contrast reduction, so ink-700 is fine. */
.rv-rank    { color: var(--amber-700); font-weight: 700; font-family: var(--font-mono); font-size: 0.72rem; }
.rv-id      { color: var(--ink-700); font-family: var(--font-mono); font-size: 0.72rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.rv-sim     { color: var(--success-800); font-weight: 700; font-family: var(--font-mono); font-size: 0.72rem; }
.rv-fit     { color: var(--ink-800); font-size: 0.72rem; font-family: var(--font-mono); }
.rv-lap     { color: var(--ink-blue); font-size: 0.72rem; font-family: var(--font-mono); }
.rv-gen     { color: var(--ink-700); font-size: 0.72rem; font-family: var(--font-mono); }
.rv-parents { color: var(--ink-700); font-size: 0.72rem; font-family: var(--font-mono); }

.rv-spark {
    display: inline-flex;
    align-items: center;
    width: 42px;
    height: 12px;
}
.rv-spark-svg { width: 42px; height: 12px; display: block; }
.rv-spark-empty { color: var(--ink-700); font-size: 0.7rem; line-height: 12px; }
.rv-spark-label {
    font-size: 0.62rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-700);
}

.rv-lora,
.rv-dynamics,
.rv-sona {
    display: flex;
    align-items: center;
    gap: 0.45em;
    flex-wrap: wrap;
    margin: 0.3em 0 0.15em 0;
    font-size: 0.72rem;
    color: var(--ink-700); /* AAA */
}
.rv-dynamics[hidden],
.rv-sona[hidden] { display: none; }

.rv-lora-label,
.rv-sona-label,
.rv-dynamics-label {
    color: var(--ink-700); /* AAA */
    text-transform: uppercase;
    font-size: 0.62rem;
    letter-spacing: 0.08em;
    font-weight: 600;
}
.rv-dynamics-label {
    display: flex;
    align-items: center;
    gap: 0.35em;
    cursor: pointer;
}
.rv-dynamics-label input[type="checkbox"] {
    margin: 0;
    accent-color: var(--amber-500);
    cursor: pointer;
}

.rv-lora-drift,
.rv-sona-stats,
.rv-dynamics-status {
    color: var(--ink-800);
    font-family: var(--font-mono);
    font-size: 0.72rem;
}

.rv-circuits {
    padding: 0.4em 0.1em 0.1em;
    margin-top: 0.35em;
    border-top: 1px solid var(--line);
}
.rv-circuits[hidden] { display: none; }
.rv-circuits-title {
    display: flex;
    align-items: center;
    gap: 0.3em;
    color: var(--ink-500);
    text-transform: uppercase;
    font-size: 0.62rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    margin-bottom: 0.3em;
}
.rv-circuit-row {
    display: flex;
    align-items: center;
    gap: 0.5em;
    padding: 0.15em 0.25em;
    font-size: 0.72rem;
    font-family: var(--font-mono);
    color: var(--ink-700);
}
.rv-circuit-members, .rv-circuit-quality { color: var(--ink-700); }

/* Lineage DAG viewer */
.rv-lineage {
    margin-top: 0.4em;
    padding-top: 0.3em;
    border-top: 1px solid var(--line);
}
.rv-lineage[hidden] { display: none; }
.rv-lineage-header {
    display: flex;
    align-items: center;
    gap: 0.45em;
    font-size: 0.72rem;
    color: var(--ink-700); /* AAA */
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.rv-lineage-toggle {
    background: var(--ml-100);
    color: var(--ml-700);
    /* 1.4.11: ml-200 was 1.36:1 on ml-50 — the purple rim barely read. ml-500
       (#7a65cc) hits 4.14:1 on ml-50 and 3.73 on ml-100 (its own fill) while
       keeping the amethyst identity. */
    border: 1px solid var(--ml-500);
    border-radius: var(--r-sm);
    padding: 0.2em 0.7em;
    font: inherit;
    cursor: pointer;
    font-size: 0.7rem;
    letter-spacing: 0.02em;
    text-transform: none;
    font-weight: 600;
    transition: background-color var(--dur-fast) var(--ease-out);
}
.rv-lineage-toggle:hover { background: var(--ml-200); }
.rv-lineage-toggle:disabled { cursor: default; opacity: 0.5; }
.rv-lineage-toggle:focus-visible { outline: none; box-shadow: var(--ring); }
.rv-lineage-status {
    color: var(--ink-700); /* AAA */
    font-family: var(--font-mono);
    font-size: 0.68rem;
    letter-spacing: 0;
    text-transform: none;
    font-weight: 400;
}
.rv-lineage-body {
    margin-top: 0.4em;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    padding: 0.25em;
    position: relative;
}
.rv-lineage-body[hidden] { display: none; }
.rv-lineage-canvas {
    display: block;
    width: 100%;
    height: 140px;
    background: var(--surface-1);
    border-radius: var(--r-xs);
    cursor: pointer;
}
.rv-lineage-tooltip {
    position: fixed;
    background: var(--ink-900);
    color: var(--paper-1);
    padding: 0.25em 0.55em;
    border-radius: var(--r-xs);
    font: 0.7rem var(--font-mono);
    pointer-events: none;
    z-index: 2000;
    white-space: nowrap;
    box-shadow: var(--shadow-md);
}
.rv-lineage-tooltip[hidden] { display: none; }

/* A/B toggle strip */
.rv-abstrip {
    margin-top: 0.5em;
    padding: 0.55em 0.6em;
    border: 1px solid var(--amber-300);
    border-radius: var(--r-md);
    background: var(--amber-50);
    font-size: 0.72rem;
}
.rv-abstrip[hidden] { display: none; }
.rv-abstrip-title {
    color: var(--amber-700);
    font-weight: 700;
    font-size: 0.72rem;
    margin-bottom: 0.45em;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.rv-abstrip-hint {
    display: inline;
    margin-left: 0.45em;
    color: var(--ink-700); /* AAA */
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    font-size: 0.7rem;
    font-style: italic;
}
.rv-abrow {
    display: grid;
    grid-template-columns: 6.5em 1fr auto;
    align-items: center;
    gap: 0.4em;
    padding: 0.2em 0;
}
.rv-ablabel {
    color: var(--ink-700);
    font-size: 0.7rem;
    text-align: right;
    padding-right: 0.4em;
    font-weight: 500;
}
.rv-abseg {
    display: inline-flex;
    gap: 2px;
    background: var(--surface-1);
    padding: 2px;
    border-radius: var(--r-sm);
    /* 1.4.11: the segmented-control wrapper boundary distinguishes the
       cluster of buttons from the surrounding amber-tinted strip; --line was
       1.29:1. --line-control clears 3:1 on every surface tier. */
    border: 1px solid var(--line-control);
    flex-wrap: wrap;
}
.rv-abbtn {
    background: transparent;
    color: var(--ink-700);
    border: 1px solid transparent;
    border-radius: var(--r-xs);
    font: inherit;
    font-size: 0.7rem;
    padding: 0.22em 0.55em;
    cursor: pointer;
    line-height: 1.1;
    transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.rv-abbtn:hover {
    background: var(--amber-100);
    color: var(--amber-700);
}
.rv-abbtn-active {
    /* AAA: white on amber-500 = 2.78, needs amber-700. */
    background: var(--amber-700);
    color: #fff;
    font-weight: 700;
    border-color: var(--amber-800);
}
.rv-abbtn-active:hover {
    background: var(--amber-800);
    color: #fff;
}
.rv-abbtn-unavailable { opacity: 0.5; cursor: help; }
.rv-abbtn-locked      { opacity: 0.45; cursor: not-allowed; }
.rv-abbtn[disabled]   { cursor: not-allowed; }
.rv-abbtn:focus-visible {
    outline: none;
    box-shadow: var(--ring);
}

/* =============================================================
   1C — F4 Consistency-mode selector + tick strip
   A radio row (Fresh / Eventual / Frozen) and a horizontal strip
   of 30 tiny dots beneath. Each dot pulses via a brief CSS
   animation each time recommendSeeds runs a fresh query. On
   cache-hit (eventual mode inside TTL) no pulse fires, so the
   strip visibly slows; on frozen the dots still pulse (the query
   runs, just against a pinned archive), which matches the
   "frozen ≠ skip" pedagogy.
   ============================================================= */
.rv-consistency {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin: 6px 0 4px 0;
    font-size: 11px;
    color: #a8c8ff;
}
.rv-consistency-head {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.rv-consistency-label { font-weight: 600; color: #cbd8ff; }
.rv-consistency-radios {
    display: flex;
    gap: 10px;
    align-items: center;
}
.rv-consistency-radios label {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    cursor: pointer;
    user-select: none;
}
.rv-consistency-radios input[type="radio"] { margin: 0; cursor: pointer; }
.rv-consistency-ticks {
    display: flex;
    gap: 2px;
    padding: 2px 0;
    min-height: 8px;
}
.rv-consistency-tick {
    display: inline-block;
    width: 4px;
    height: 6px;
    border-radius: 1px;
    background: rgba(168, 200, 255, 0.18);
    transition: background-color 200ms ease-out;
}
.rv-consistency-tick-pulse {
    background: #62f0b8;
    animation: rv-consistency-tick-fade 800ms ease-out forwards;
}
@keyframes rv-consistency-tick-fade {
    0%   { background: #62f0b8; transform: scaleY(1.35); }
    100% { background: rgba(168, 200, 255, 0.18); transform: scaleY(1); }
}

/* =============================================================
   Guided-tour overlay (eli15)
   ============================================================= */
/* Tour launcher — stacks directly below the #eli15-fab (drawer) pill at
   top-left. Same pill shape; info-blue accent so it reads as a different
   affordance from the amber drawer pill. On narrow viewports it drops back
   to a 46px circle and stacks above the drawer FAB at bottom-right. */
.eli15-tour-fab {
    position: fixed;
    top: calc(var(--sp-4) + 40px + var(--sp-2)); /* below .eli15-fab */
    left: var(--sp-4);
    right: auto;
    bottom: auto;
    z-index: 1200;
    display: inline-flex;
    align-items: center;
    gap: 0.5em;
    width: auto;
    height: auto;
    padding: 0.5em 0.9em 0.5em 0.7em;
    border-radius: var(--r-full);
    border: 1.5px solid var(--ink-blue);
    background: var(--surface-1);
    /* AAA: info-600 (#2f5fb4) on white is 6.15:1. ink-blue (#1c3f70) hits
       ~9.9:1 so the label and icon both pass at AAA. */
    color: var(--ink-blue);
    font-family: var(--font-body);
    font-size: 0.82rem;
    font-weight: 600;
    line-height: 1.15;
    letter-spacing: 0.01em;
    text-align: left;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: transform var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
.eli15-tour-fab-icon  { font-size: 1.1em; line-height: 1; }
.eli15-tour-fab-label { white-space: nowrap; }
.eli15-tour-fab:hover {
    background: var(--info-100);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}
.eli15-tour-fab:focus-visible {
    outline: none;
    box-shadow: var(--shadow-md), 0 0 0 3px rgba(47, 95, 180, 0.45);
}
@media (prefers-color-scheme: dark) {
    .eli15-tour-fab {
        background: var(--surface-2);
        color: #9ab8ff;
        border-color: rgba(154, 184, 255, 0.6);
    }
    .eli15-tour-fab:hover { background: rgba(154, 184, 255, 0.14); }
}
/* Mobile: revert to emoji-only circle at bottom-right, stacked above the
   drawer FAB (which sits at bottom: var(--sp-4)). */
@media (max-width: 720px) {
    .eli15-tour-fab {
        top: auto;
        left: auto;
        right: var(--sp-4);
        bottom: calc(var(--sp-4) + 56px);
        width: 46px;
        height: 46px;
        padding: 0;
        border-radius: 50%;
        justify-content: center;
        font-size: 22px;
    }
    .eli15-tour-fab-label { display: none; }
}

/* =============================================================
   GitHub link pill — third stack in the left column, below
   Explain anything / Guided tour. Neutral ink color so it reads as
   the "view source" affordance, distinct from the amber drawer pill
   and the blue tour pill.
   ============================================================= */
.github-fab {
    position: fixed;
    /* Stacks below .eli15-tour-fab: sp-4 + 2×(40px + sp-2). */
    top: calc(var(--sp-4) + 2 * (40px + var(--sp-2)));
    left: var(--sp-4);
    right: auto;
    bottom: auto;
    z-index: 1200;
    display: inline-flex;
    align-items: center;
    gap: 0.5em;
    padding: 0.5em 0.9em 0.5em 0.7em;
    border-radius: var(--r-full);
    border: 1.5px solid var(--ink-600, #2a2e35);
    background: var(--surface-1);
    color: var(--ink-900, #1a1c22);
    font-family: var(--font-body);
    font-size: 0.82rem;
    font-weight: 600;
    line-height: 1.15;
    text-decoration: none;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: transform var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
.github-fab-icon  { display: inline-flex; line-height: 1; }
.github-fab-label { white-space: nowrap; }
.github-fab:hover {
    background: var(--surface-2);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}
.github-fab:focus-visible {
    outline: none;
    box-shadow: var(--shadow-md), 0 0 0 3px rgba(42, 46, 53, 0.45);
}
@media (prefers-color-scheme: dark) {
    .github-fab {
        background: var(--surface-2);
        color: #d8dce4;
        border-color: rgba(216, 220, 228, 0.5);
    }
    .github-fab:hover { background: rgba(216, 220, 228, 0.12); }
}
/* Mobile: same collapse pattern as the other fabs — circle at
   bottom-right, stacked above the tour pill. */
@media (max-width: 720px) {
    .github-fab {
        top: auto;
        left: auto;
        right: var(--sp-4);
        bottom: calc(var(--sp-4) + 112px);
        width: 46px;
        height: 46px;
        padding: 0;
        border-radius: 50%;
        justify-content: center;
    }
    .github-fab-label { display: none; }
    .github-fab-icon  { font-size: 22px; }
}

.eli15-tour-ring {
    position: fixed;
    pointer-events: none;
    z-index: 1150;
    border: 3px solid var(--info-600);
    border-radius: var(--r-md);
    box-shadow:
        0 0 0 4px rgba(47, 95, 180, 0.22),
        0 0 28px rgba(47, 95, 180, 0.45);
    transition: all 220ms var(--ease-out);
}

.eli15-tour-card {
    position: fixed;
    z-index: 1400;
    max-width: 340px;
    background: var(--surface-1);
    color: var(--ink-800);
    border: 1px solid var(--info-100);
    border-top: 4px solid var(--info-600);
    border-radius: var(--r-md);
    padding: var(--sp-3) var(--sp-4);
    font: 0.88rem/1.45 var(--font-body);
    box-shadow: var(--shadow-lg);
}
.eli15-tour-card[hidden] { display: none; }

/* ---------- ELI15 anchored popover (single-badge clicks) ---------------
   Progressive-disclosure UI for `?` badges. The guided tour (.eli15-tour-*)
   walks a fixed playlist with Back/Next; this card is the lighter "what is
   this element?" glance — title, one-liner, and a Read-full-chapter button
   that opens the heavier drawer for readers who want depth. Sits above the
   ring (z-index 1150) and the perf HUD (z-index 50). */
.eli15-popover {
    position: fixed;
    z-index: 1400;
    max-width: 300px;
    min-width: 220px;
    background: var(--surface-1);
    color: var(--ink-800);
    border: 1px solid var(--info-100);
    border-top: 4px solid var(--info-600);
    border-radius: var(--r-md);
    padding: var(--sp-3) var(--sp-4) var(--sp-3);
    font: 0.86rem/1.45 var(--font-body);
    box-shadow: var(--shadow-lg);
    animation: eli15-popover-in 140ms var(--ease-out);
}
.eli15-popover[hidden] { display: none; }
@keyframes eli15-popover-in {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}
.eli15-popover-title {
    font-family: var(--font-display);
    font-weight: 600;
    color: var(--ink-blue); /* AAA: info-600 → 6.15 on white */
    font-size: 0.98rem;
    margin: 0 1.8em 0.3em 0;  /* leave room for the close × */
    line-height: 1.25;
}
.eli15-popover-oneliner {
    margin: 0 0 var(--sp-3) 0;
    color: var(--ink-700);
}
.eli15-popover-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--sp-2);
}
.eli15-popover-more {
    /* AAA: white on info-600 = 6.15; ink-blue reaches ~9.9. */
    background: var(--ink-blue);
    color: #fff;
    border: 0;
    padding: 0.4em 0.9em;
    border-radius: var(--r-sm);
    font: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: background 120ms var(--ease-out);
}
.eli15-popover-more:hover { background: #14304f; }
.eli15-popover-close {
    position: absolute;
    top: 6px;
    right: 8px;
    background: transparent;
    border: 0;
    font-size: 1.2rem;
    line-height: 1;
    color: var(--ink-700); /* AAA: was ink-500 */
    cursor: pointer;
    padding: 2px 6px;
    border-radius: var(--r-sm);
}
.eli15-popover-close:hover { background: var(--ink-100); color: var(--ink-800); }

.eli15-tour-progress {
    display: flex;
    gap: 3px;
    margin-bottom: 0.5em;
}
.eli15-tour-dot {
    flex: 1;
    height: 3px;
    background: var(--ink-100);
    border-radius: 2px;
}
.eli15-tour-dot.eli15-tour-dot-done    { background: var(--info-600); }
.eli15-tour-dot.eli15-tour-dot-current { background: var(--info-600); opacity: 0.85; box-shadow: 0 0 0 3px rgba(47, 95, 180, 0.18); }

.eli15-tour-title {
    font-family: var(--font-display);
    font-weight: 600;
    /* AAA: info-600 hits 6.15:1; ink-blue reaches ~9.9:1 on white. */
    color: var(--ink-blue);
    font-size: 1.02rem;
    margin: 0 0 0.25em 0;
    letter-spacing: -0.005em;
}
.eli15-tour-step {
    color: var(--ink-700); /* AAA */
    font-size: 0.68rem;
    margin-bottom: 0.4em;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
}
.eli15-tour-oneliner {
    margin: 0 0 0.7em 0;
    color: var(--ink-800);
    font-size: 0.88rem;
    line-height: 1.5;
}
.eli15-tour-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--sp-2);
}
.eli15-tour-btn {
    /* AAA: white on info-600 = 6.15; ink-blue bg hits ~9.9. */
    background: var(--ink-blue);
    color: #fff;
    border: none;
    border-radius: var(--r-sm);
    padding: 0.4em 0.95em;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.82rem;
    transition: background-color var(--dur-fast) var(--ease-out);
}
.eli15-tour-btn:hover    { background: #14304f; }
.eli15-tour-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(47, 95, 180, 0.45); }
.eli15-tour-btn-ghost {
    background: transparent;
    /* AAA: info-600 ghost text was 6.15 on white. */
    color: var(--ink-blue);
    border: 1px solid var(--ink-blue);
}
.eli15-tour-btn-ghost:hover {
    background: var(--info-100);
    color: #14304f;
}
.eli15-tour-close {
    background: transparent;
    color: var(--ink-700); /* AAA: was ink-500 (4.94 on white) */
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    padding: 0 0.25em;
    line-height: 1;
    border-radius: var(--r-xs);
}
.eli15-tour-close:hover        { color: var(--ink-800); background: var(--ink-100); }
.eli15-tour-close:focus-visible{ outline: none; box-shadow: var(--ring); }

/* =============================================================
   Responsive
   ============================================================= */
/* Portrait / near-square viewports: the canvas + panel stack; the panel
   becomes a shorter bottom strip so the track still dominates. */
@media (max-aspect-ratio: 1/1) {
    #fullDisplay {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(0, 1fr) minmax(200px, 38vh);
    }
    #canvasDiv  { grid-column: 1; grid-row: 1; }
    #rightPanel { grid-column: 1; grid-row: 2; }
    #fullDisplay.panel-collapsed {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(0, 1fr) 0;
    }
}

@media (max-aspect-ratio: 1/1) and (max-height: calc(56.25vw + 18em)) {
    #inputCanvas { display: none; }
    #timer       { display: none; }
}

@media (max-width: 720px) {
    #fullDisplay {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(0, 1fr) minmax(220px, 50vh);
        padding: var(--sp-2);
        gap: var(--sp-2);
    }
    #canvasDiv, #rightPanel {
        grid-column: 1 / -1;
    }
    #rightPanel { grid-row: 2; }
    #bottomText { font-size: 0.9em; }
}

/* ---------- Dark-mode AAA contrast overrides ----------------------------------
   The light-mode tokens for accent text (amber-700, ml-700, success-800,
   info-600, ink-blue) all encode a dark color that reads well on paper
   surfaces but inverts to 1.5–2.2 :1 against the dark-paper backdrop. The
   flips below target ≥7:1 on dark surfaces by swapping in the light-tier
   of each accent ladder. #panelToggle and #perf-hud keep hardcoded
   visible tones because their backgrounds are fixed (the HUD's bg is a
   semi-opaque dark in both themes; light-mode paper-1 text would vanish
   there in dark mode since paper-1 itself flips to dark).
   ========================================================================== */
@media (prefers-color-scheme: dark) {
    .rv-title            { color: #c5b8ff; }
    .rv-rank             { color: #f4c691; }
    .rv-sim              { color: #77d29a; }
    .rv-lap              { color: #9ab8ff; }
    .rv-abstrip-title    { color: #f4c691; }

    /* 1.4.11: filled amber-700 CTAs (.backNext, .start-cta, #track-preset-load,
       .rv-abbtn-active) read 4.57:1 on paper in light mode but drop to
       2.19:1 on dark surface-1 — the button edge disappears against the page.
       Lift the trim to amber-400 (8.3:1 vs dark surface, 3.8:1 vs the fill)
       so the boundary stays visible in both themes. */
    .backNext,
    .backNext:hover,
    .controlButton.start-cta,
    .controlButton.start-cta:hover,
    .rv-abbtn-active,
    .rv-abbtn-active:hover {
        border-color: var(--amber-400);
    }
    #track-preset-load,
    #track-preset-load:hover {
        border-color: var(--amber-400) !important;
    }
    /* 1.4.11: 0.35 alpha purple was 1.52:1 on surface-1 — well below 3:1.
       The light-tier amethyst (#c5b8ff) hits ~9.5:1 on surface-1 and ~7.8
       on the composited tinted fill, matching the .rv-title accent. */
    .rv-lineage-toggle   { color: #c5b8ff; background: rgba(122, 101, 204, 0.18); border-color: #c5b8ff; }
    .rv-lineage-toggle:hover { background: rgba(122, 101, 204, 0.28); }
    .rv-reranker-mode-gnn  { background: rgba(47, 131, 85, 0.22);  color: #9ce5b8; }
    .rv-reranker-mode-ema  { background: rgba(211, 139, 75, 0.18); color: #f4c691; }
    /* Perf HUD: keep a fixed light text tone regardless of theme because
       the HUD's dark-on-dark background is intentional. All descendants
       inherit unless a child rule overrides — span-level !important needed
       because main.js sets child inline styles too. */
    #perf-hud,
    #perf-hud *         { color: #f8f2e4 !important; }

    /* Tour card + popover: the light-mode ink-blue text reads ~10:1 on
       white but inverts to ~1.6:1 on dark surface-1. Flip to the
       light-tier info tone (#9ab8ff) for parity with the .blue badge
       and the tour ring itself. */
    .eli15-tour-title,
    .eli15-tour-btn-ghost,
    .eli15-popover-title { color: #9ab8ff; }
    .eli15-tour-btn-ghost { border-color: #9ab8ff; }
    .eli15-tour-btn-ghost:hover { background: rgba(154, 184, 255, 0.12); color: #cfd9f7; }
    /* Filled buttons stay readable against the light-tier info bg. */
    .eli15-tour-btn,
    .eli15-popover-more { background: #1c3f70; }
}

/* Broad reduced-motion guard */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}

/* ---------- Dev HUD (perf monitor from main.js) ----------
   main.js attaches inline cssText to #perf-hud pinning it to top:8 right:8,
   which sits on top of #rightPanel in the new layout. Re-anchor to the
   bottom-left corner (out of the way of the track-preset chip up top and the
   bottom-text banner in the middle) and re-theme it to match the ink/paper
   palette. Inline cssText loses to !important. */
#perf-hud {
    /* Sit below the ELI15 tour card (z-index 1400) and the rv-panel modal
       (z-index 1100) so the hitches log never occludes learning UI. Inline
       cssText from main.js sets 99998 — override with !important. */
    z-index: 50 !important;
    top: auto !important;
    right: auto !important;
    bottom: var(--sp-4) !important;
    left: var(--sp-4) !important;
    padding: var(--sp-2) var(--sp-3) !important;
    background: rgba(29, 26, 22, 0.88) !important;
    color: var(--paper-1) !important;
    font-family: var(--font-mono) !important;
    font-size: 0.68rem !important;
    line-height: 1.45 !important;
    border: 1px solid rgba(255, 241, 216, 0.14) !important;
    border-radius: var(--r-sm) !important;
    box-shadow: var(--shadow-md) !important;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    opacity: 0.82;
    pointer-events: auto !important; /* re-enable so the collapse toggle works */
    letter-spacing: 0.01em;
    cursor: pointer;
}
#perf-hud:hover { opacity: 1; }
#perf-hud .perf-hitches { display: none; }
#perf-hud.expanded .perf-hitches { display: block; }
@media (max-width: 900px) {
    #perf-hud { display: none !important; }
}

/* ---------- Right-panel collapse toggle ----------------------------------
   Fixed tab on the right edge of the viewport. Lives outside #fullDisplay
   so its position is anchored to the viewport, not the grid — this means
   it stays put whether the panel is open or collapsed, just changes its
   chevron direction. Visual treatment is intentionally quiet so it doesn't
   compete with the Start-training CTA or the track itself. */
#panelToggle {
    position: fixed;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
    width: 22px;
    height: 64px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-1);
    color: var(--ink-700); /* AAA: was ink-600 (6.69:1 on white) */
    /* 1.4.11: --line was 1.29:1 against the paper-0 viewport bg — this tab
       is the only boundary between the pill and the page, so it must clear
       3:1. --line-control (ink-500) hits 4.9:1 on both paper and white. */
    border: 1px solid var(--line-control);
    border-right: none;
    border-radius: var(--r-md) 0 0 var(--r-md);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    z-index: 1000;
    font-family: var(--font-body);
    font-size: 14px;
    line-height: 1;
    transition:
        background-color var(--dur-fast) var(--ease-out),
        color var(--dur-fast) var(--ease-out),
        transform var(--dur-med) var(--ease-out);
}
#panelToggle > span {
    display: inline-block;
    transition: transform var(--dur-med) var(--ease-out);
}
/* aria-expanded is the source of truth — drives the chevron direction so
   collapsed state reads as "open the panel again" (points left = ‹). */
#panelToggle[aria-expanded="false"] > span { transform: rotate(180deg); }
#panelToggle:hover {
    background: var(--surface-2);
    color: var(--ink-900);
}
#panelToggle:focus-visible {
    outline: none;
    box-shadow: var(--ring);
}
@media (prefers-color-scheme: dark) {
    #panelToggle {
        background: var(--surface-2);
        /* AAA: ink-600 in dark mode = #a89f8f, ratio ~6.1 on surface-2.
           ink-800 = #e8e1d2 hits ~11:1 and reads cleanly. */
        color: var(--ink-800);
    }
    #panelToggle:hover {
        background: var(--surface-3);
        color: var(--ink-900);
    }
}
/* On portrait/mobile the panel lives below the canvas rather than beside
   it, so the edge-tab doesn't make spatial sense — rotate it into a pill
   pinned to the bottom-right corner. */
@media (max-aspect-ratio: 1/1), (max-width: 720px) {
    #panelToggle {
        top: auto;
        right: var(--sp-2);
        bottom: var(--sp-2);
        transform: none;
        width: 44px;
        height: 28px;
        border-radius: var(--r-full);
        /* 1.4.11: match the outer border-color set above. */
        border-right: 1px solid var(--line-control);
    }
    #panelToggle > span { transform: rotate(-90deg); }
    #panelToggle[aria-expanded="false"] > span { transform: rotate(90deg); }
}

/* Accessible "visually-hidden" utility for screen-reader-only labels */
.visually-hidden,
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* =============================================================
   Phase 2B (F6) — cross-tab live-training pill
   ============================================================= */
.rv-crosstab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 2px 0;
}
.rv-crosstab-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 10px;
    background: rgba(98, 240, 184, 0.14);
    color: #cbd8ff;
    font-size: 12px;
    user-select: none;
    transition: background-color 200ms ease-out, box-shadow 200ms ease-out;
}
.rv-crosstab-pill-pulse {
    animation: rv-crosstab-pulse 600ms ease-out forwards;
}
@keyframes rv-crosstab-pulse {
    0%   { background: #62f0b8; box-shadow: 0 0 10px rgba(98, 240, 184, 0.65); }
    100% { background: rgba(98, 240, 184, 0.14); box-shadow: 0 0 0 rgba(0, 0, 0, 0); }
}

/* === Phase A — Experiments disclosure panel === */
/* Consolidates RuLake-inspired feature toggles. Native <details> +
 * <summary> for the disclosure — no JS animation, no custom widget. */
.rv-experiments {
    margin-top: 14px;
    padding: 8px 10px;
    background: rgba(20, 28, 48, 0.55);
    border: 1px solid rgba(120, 140, 200, 0.18);
    border-radius: 6px;
}
.rv-experiments[open] {
    background: rgba(20, 28, 48, 0.75);
}
.rv-experiments-summary {
    cursor: pointer;
    font-weight: 600;
    color: #cbd8ff;
    user-select: none;
    list-style: none;
    padding: 2px 0;
}
.rv-experiments-summary::-webkit-details-marker { display: none; }
.rv-experiments-summary::before {
    content: '▸';
    display: inline-block;
    margin-right: 6px;
    transition: transform 120ms ease-out;
}
.rv-experiments[open] .rv-experiments-summary::before {
    transform: rotate(90deg);
}
.rv-experiments-hint {
    font-weight: 400;
    color: #8a98be;
    font-size: 0.85em;
    margin-left: 6px;
}
.rv-experiments-body {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.rv-experiments-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 10px;
    padding: 4px 6px;
    border-radius: 4px;
}
.rv-experiments-row + .rv-experiments-row {
    border-top: 1px solid rgba(120, 140, 200, 0.08);
    padding-top: 8px;
}
.rv-experiments-row > [data-rv]:not(input):not(label) {
    /* migrated rows (consistency, federation, crosstab) keep their own
     * layouts — strip the row's wrap so they read clean inside */
    flex: 1 1 100%;
}
.rv-experiments-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    color: #e6ebfa;
}
.rv-experiments-toggle input[type="checkbox"] { cursor: pointer; }
.rv-experiments-emoji { font-size: 1.05em; }
.rv-experiments-label { font-weight: 500; }
.rv-experiments-hint-inline {
    color: #8a98be;
    font-size: 0.85em;
    font-style: italic;
}
.rv-experiments-subbody {
    flex: 1 1 100%;
    margin-top: 4px;
    padding: 6px 8px;
    background: rgba(10, 16, 32, 0.45);
    border-radius: 4px;
}
.rv-experiments-subbody[hidden] { display: none; }

/* Disabled (library-only) row styling */
.rv-experiments-row-disabled { opacity: 0.55; }
.rv-experiments-toggle-disabled { cursor: not-allowed; }
.rv-experiments-toggle-disabled input { cursor: not-allowed; }
.rv-experiments-badge {
    display: inline-block;
    padding: 1px 6px;
    margin-left: 4px;
    border-radius: 3px;
    background: rgba(180, 140, 90, 0.22);
    color: #d8c39a;
    font-size: 0.75em;
    font-weight: 600;
    letter-spacing: 0.02em;
}
.rv-experiments-status {
    flex: 1 1 100%;
    margin-top: 2px;
    font: 11px/1.35 var(--font-mono);
    color: rgba(168, 200, 255, 0.9);
    opacity: 0.92;
}
.rv-experiments-reset-gates {
    margin-left: auto;
    padding: 2px 8px !important;
    font-size: 0.78em !important;
}

/* === Phase A — Brain saves (named-slot persistence) === */
/* Mounted directly below the legacy Save Best + Restart actions, so the
 * single-slot legacy buttons and the multi-slot named saves are
 * visually adjacent. Native <details>/<summary> for the disclosure. */
.brain-saves {
    margin-top: 10px;
    padding: 8px 10px;
    background: rgba(20, 28, 48, 0.55);
    border: 1px solid rgba(120, 140, 200, 0.18);
    border-radius: 6px;
}
.brain-saves > summary {
    cursor: pointer;
    font-weight: 600;
    color: #cbd8ff;
    user-select: none;
    list-style: none;
    padding: 2px 0;
}
.brain-saves > summary::-webkit-details-marker { display: none; }
.brain-saves > summary::before {
    content: '▸';
    display: inline-block;
    margin-right: 6px;
    transition: transform 120ms ease-out;
}
.brain-saves[open] > summary::before { transform: rotate(90deg); }
.brain-saves-hint {
    font-weight: 400;
    color: #8a98be;
    font-size: 0.85em;
    margin-left: 6px;
}
.brain-saves-body {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.brain-saves-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: stretch;
}
.brain-saves-select {
    flex: 1 1 auto;
    min-width: 0;
    padding: 4px 8px;
    background: rgba(10, 16, 32, 0.85);
    color: #e6ebfa;
    border: 1px solid rgba(120, 140, 200, 0.32);
    border-radius: 4px;
    font: inherit;
}
.brain-saves-fresh {
    /* Make Start Fresh visually distinct so users don't confuse it with
     * the cheaper Reset Brain. Soft amber tint = "destructive but
     * not catastrophic." Confirm dialog still gates execution. */
    background: rgba(180, 110, 60, 0.20) !important;
    border-color: rgba(200, 130, 75, 0.45) !important;
    color: #f0d6b6 !important;
}
.brain-saves-fresh:hover { background: rgba(180, 110, 60, 0.32) !important; }

/* =============================================================
   Cinematic presentation layer (demoPresentation.js)
   Overlay HUD + view toggles on #canvasDiv. Pointer-events none
   on the HUD; controls are clickable chips.
   ============================================================= */
#cinema-hud {
    position: absolute;
    /* Sit below the fixed help stack (Explain / Tour / GitHub) which lives
       at viewport top-left over the canvas. Stack ≈ sp-4 + 3×(pill+gap). */
    top: calc(var(--sp-4) + 3 * (36px + var(--sp-2)) + var(--sp-2));
    left: 12px;
    z-index: 8;
    max-width: min(72%, 420px);
    padding: 8px 12px;
    border-radius: 12px;
    background: rgba(12, 14, 18, 0.72);
    -webkit-backdrop-filter: blur(10px) saturate(130%);
    backdrop-filter: blur(10px) saturate(130%);
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
    color: #f3efe6;
    font-family: var(--font-body);
    font-size: 12px;
    line-height: 1.35;
    pointer-events: none;
}
.cinema-hud-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
    align-items: baseline;
}
.cinema-stat {
    color: rgba(243, 239, 230, 0.78);
    letter-spacing: 0.01em;
}
.cinema-stat b {
    color: #ffe566;
    font-family: var(--font-mono);
    font-weight: 500;
    font-size: 12.5px;
}
.cinema-muted {
    opacity: 0.55;
    font-size: 0.92em;
}
.cinema-story {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    color: rgba(255, 236, 180, 0.92);
    font-size: 12px;
    font-family: var(--font-display);
    font-weight: 500;
    letter-spacing: -0.01em;
}
.cinema-story[hidden] { display: none; }

#cinema-controls {
    /* Bottom-right of the track cell so we don't collide with the
       bottom-left perf HUD or the centered #bottomText banner. */
    position: absolute;
    bottom: 14px;
    right: 14px;
    left: auto;
    z-index: 9;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
    max-width: min(56%, 420px);
    pointer-events: auto;
}

#cinema-controls button {
    appearance: none;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(12, 14, 18, 0.72);
    color: rgba(243, 239, 230, 0.88);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    border-radius: 999px;
    padding: 5px 11px;
    font: 600 11px/1.2 var(--font-body);
    letter-spacing: 0.02em;
    cursor: pointer;
    transition: background 120ms ease, border-color 120ms ease, color 120ms ease, transform 120ms ease;
}
#cinema-controls button:hover {
    background: rgba(28, 30, 38, 0.88);
    border-color: rgba(255, 229, 102, 0.35);
    color: #fff;
}
#cinema-controls button:focus-visible {
    outline: 2px solid var(--amber-500);
    outline-offset: 2px;
}
#cinema-controls button.is-on {
    background: #604024;
    border-color: rgba(255, 229, 102, 0.55);
    color: #ffe566;
}
#cinema-controls button.cinema-demo.is-on {
    background: #493c74;
    border-color: rgba(190, 175, 255, 0.55);
    color: #e4dcff;
}

/* Keep overlays clear of the A/B dual stack */
#canvasDiv.ab-on #cinema-hud {
    max-width: min(48%, 360px);
}
#canvasDiv.ab-on #cinema-controls {
    bottom: auto;
    top: calc(50% + 8px);
    right: 8px;
}

@media (max-width: 720px) {
    #cinema-hud {
        font-size: 11px;
        padding: 6px 9px;
        /* On mobile the help FABs move to bottom-right, so reclaim top-left. */
        top: 8px;
        left: 8px;
        max-width: min(92%, 360px);
    }
    #cinema-controls {
        bottom: 8px;
        right: 8px;
        max-width: min(88%, 360px);
    }
    #cinema-controls button {
        padding: 4px 9px;
        font-size: 10px;
    }
    #bottomText {
        left: 50%;
        max-width: min(70%, 280px);
        bottom: calc(var(--sp-3) + 36px); /* clear cinema chips */
    }
    .start-overlay-btn {
        min-width: min(84vw, 260px);
        padding: 1em 1.2em 0.85em;
    }
}

/* ---------- Phone / very narrow (≈320–480px) -------------------------------
   Track was buried under stacked HUDs: metrics (fixed center), cinema stats,
   story line, phase banner, view chips, and help FABs. On narrow screens we
   hide redundant chrome, collapse view chips behind "Views", and park FABs
   in a top-right stack so the canvas keeps the middle of the screen. */
.cinema-views-toggle {
    display: none; /* desktop: unused — all chips stay visible */
}
@media (max-width: 480px) {
    /* Redundant with #cinema-hud — was stacked on top of Gen/Alive at z 99998. */
    #metrics-hud {
        display: none !important;
    }

    #cinema-hud {
        top: 6px;
        left: 6px;
        right: auto;
        /* Leave a column for the top-right FAB stack. */
        max-width: calc(100% - 52px);
        padding: 4px 8px;
        font-size: 10px;
        line-height: 1.3;
        z-index: 10;
    }
    #cinema-hud .cinema-hud-row {
        gap: 4px 8px;
    }
    /* Story wraps into a multi-line block that covers the track. */
    #cinema-hud .cinema-story {
        display: none !important;
    }
    /* Keep the densest three stats; drop the rest on phone. */
    #cinema-hud [data-c="laps"],
    #cinema-hud [data-c="speed"] {
        display: none;
    }

    #bottomText {
        display: none !important;
    }

    /* View chips collapsed by default — only the Views toggle shows. */
    .cinema-views-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        appearance: none;
        border: 1px solid rgba(255, 255, 255, 0.22);
        background: rgba(12, 14, 18, 0.82);
        color: rgba(243, 239, 230, 0.95);
        -webkit-backdrop-filter: blur(8px);
        backdrop-filter: blur(8px);
        border-radius: 999px;
        padding: 6px 12px;
        font: 600 11px/1.2 var(--font-body);
        letter-spacing: 0.02em;
        cursor: pointer;
    }
    #cinema-controls {
        bottom: 8px;
        left: 8px;
        right: auto;
        max-width: calc(100% - 56px); /* clear panelToggle / FAB column */
        justify-content: flex-start;
        gap: 4px;
    }
    #cinema-controls:not(.is-expanded) > [data-act] {
        display: none !important;
    }
    #cinema-controls.is-expanded {
        max-width: calc(100% - 16px);
        flex-wrap: wrap;
    }
    #cinema-controls.is-expanded > [data-act] {
        display: inline-flex;
    }
    #cinema-controls button {
        padding: 5px 8px;
        font-size: 10px;
    }

    /* Help FABs: top-right stack, smaller — free the bottom track edge. */
    .eli15-fab {
        top: 6px !important;
        right: 6px !important;
        bottom: auto !important;
        left: auto !important;
        width: 36px !important;
        height: 36px !important;
        font-size: 16px !important;
    }
    .eli15-tour-fab {
        top: 46px !important;
        right: 6px !important;
        bottom: auto !important;
        left: auto !important;
        width: 36px !important;
        height: 36px !important;
        font-size: 16px !important;
        padding: 0 !important;
    }
    .github-fab {
        top: 86px !important;
        right: 6px !important;
        bottom: auto !important;
        left: auto !important;
        width: 36px !important;
        height: 36px !important;
    }
    .github-fab-icon { font-size: 16px !important; }

    /* Panel edge pill sits bottom-right without covering Views. */
    #panelToggle {
        bottom: 8px;
        right: 6px;
        width: 36px;
        height: 28px;
    }

    #fullDisplay {
        padding: 4px;
        gap: 4px;
    }
    /* Pin the 16:9 track to the top of the cell so HUDs sit on the frame
       instead of floating in a large empty band above a vertically-centered
       canvas (read as "data covering the track" on phones). */
    #canvasDiv {
        align-items: flex-start;
        justify-content: center;
    }
    #cinema-hud {
        /* Sit just inside the track frame once canvas is top-aligned. */
        top: 8px;
        left: 8px;
    }
    .start-overlay-btn {
        min-width: min(88vw, 240px);
        padding: 0.85em 1em 0.75em;
    }
    .start-overlay-hint {
        font-size: 0.65rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    #cinema-controls button { transition: none; }
}
