/* =============================================================
   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-700: #824006;
    --amber-600: #a45a13;
    --amber-500: #d38b4b;   /* legacy brand */
    --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-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);

    /* 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);

        --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 ---------------------------------- */
#fullDisplay {
    display: grid;
    grid-template-columns: minmax(0, 1fr) clamp(260px, 24vw, 340px);
    grid-template-rows: minmax(0, 1fr) auto;
    gap: var(--sp-4);
    width: 100vw;
    height: 100vh;
    padding: var(--sp-4);
    box-sizing: border-box;
}

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

#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);
}

/* ---------- Right panel (primary controls card) ---------------------------------- */
#rightPanel {
    grid-column: 2 / span 1;
    grid-row: 1 / span 1;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: var(--sp-3);
    min-width: 0;
    padding: var(--sp-5);
    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;
}

#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);
    border: 1px solid var(--amber-500);
    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);
        border-color: rgba(211, 139, 75, 0.55);
    }
    .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;
    background: var(--amber-500);
    border: 1px solid var(--amber-600);
    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-600);
    border-color: var(--amber-700);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}
.backNext:active {
    transform: translateY(0);
    background: var(--amber-700);
    box-shadow: var(--shadow-xs);
}
.backNext:focus-visible {
    outline: none;
    box-shadow: var(--ring), var(--shadow-sm);
}
.backNext:disabled,
.backNext[aria-disabled="true"] {
    background: var(--surface-2);
    color: var(--ink-400);
    border-color: var(--line-strong);
    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);
    border-color: var(--line-strong);
    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);
    border-color: var(--amber-500);
}
.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);
        border-color: rgba(211, 139, 75, 0.55);
    }
    .back:hover {
        background: rgba(211, 139, 75, 0.14);
        color: var(--amber-200);
    }
}

/* 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 ---------------------------------- */
#bottomText {
    grid-column: 1 / span 1;
    grid-row: 2 / span 1;
    justify-self: center;
    align-self: end;
    padding: var(--sp-3) var(--sp-5);
    background: var(--surface-1);
    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(90vw, 680px);
}

#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); }
}

/* ---------- Neural-network input + timer preview card ---------------------------------- */
#inputCanvas {
    display: block;
    width: 100%;
    min-height: 110px;
    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);
}

@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;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-3) var(--sp-4);
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
}

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

#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);
    border: 1px solid var(--line-strong);
    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 {
    top: var(--sp-4) !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;
    border: 1px solid var(--line-strong) !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 {
    background: var(--amber-500) !important;
    color: #fff !important;
    border: none !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-600) !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 {
    grid-column: 2 / span 1;
    grid-row: 2 / span 1;
    align-self: start;
    padding: var(--sp-4);
    background: var(--surface-1);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-sm);
    font-family: var(--font-body);
    font-size: 0.82rem;
    color: var(--ink-800);
    min-width: 0;
    max-height: 42vh;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--ink-200) transparent;

    /* a calm violet rim — this is where the ML/vector story lives */
    background-image:
        linear-gradient(180deg, var(--ml-50) 0%, var(--surface-1) 48px);
}

.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-500);
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
}
.rv-info-muted { color: var(--ink-400); font-style: italic; }

/* 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-600);
    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-600);
}
.rv-reranker-mode[hidden] { display: none; }
.rv-reranker-mode-label { color: var(--ink-500); 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-700); }
.rv-reranker-mode-ema  { background: var(--amber-100);   color: var(--amber-700); }
.rv-reranker-mode-none { background: var(--ink-100);     color: var(--ink-600); }

.rv-reranker {
    font-size: 0.75rem;
    color: var(--ink-600);
    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-400); 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-500);
    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-400);
    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;
}

.rv-rank    { color: var(--amber-700); font-weight: 700; font-family: var(--font-mono); font-size: 0.72rem; }
.rv-id      { color: var(--ink-500); 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-700); 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(--info-600); font-size: 0.72rem; font-family: var(--font-mono); }
.rv-gen     { color: var(--ink-600); font-size: 0.72rem; font-family: var(--font-mono); }
.rv-parents { color: var(--ink-400); 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-300); font-size: 0.7rem; line-height: 12px; }
.rv-spark-label {
    font-size: 0.62rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-400);
}

.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-600);
}
.rv-dynamics[hidden],
.rv-sona[hidden] { display: none; }

.rv-lora-label,
.rv-sona-label,
.rv-dynamics-label {
    color: var(--ink-500);
    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-500);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.rv-lineage-toggle {
    background: var(--ml-100);
    color: var(--ml-700);
    border: 1px solid var(--ml-200);
    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-500);
    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-500);
    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);
    border: 1px solid var(--line);
    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 {
    background: var(--amber-500);
    color: #fff;
    font-weight: 700;
    border-color: var(--amber-600);
}
.rv-abbtn-active:hover {
    background: var(--amber-600);
    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);
}

/* =============================================================
   Guided-tour overlay (eli15)
   ============================================================= */
.eli15-tour-fab {
    position: fixed;
    right: var(--sp-4);
    bottom: calc(var(--sp-4) + 48px);
    z-index: 1200;
    width: 46px;
    height: 46px;
    border-radius: var(--r-full);
    border: 2px solid var(--info-600);
    background: var(--surface-1);
    color: var(--info-600);
    font-size: 22px;
    line-height: 40px;
    text-align: center;
    box-shadow: var(--shadow-md);
    cursor: pointer;
    padding: 0;
    transition: transform var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
.eli15-tour-fab:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-lg);
}
.eli15-tour-fab:focus-visible {
    outline: none;
    box-shadow: var(--shadow-md), 0 0 0 3px rgba(47, 95, 180, 0.45);
}

.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-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;
    color: var(--info-600);
    font-size: 1.02rem;
    margin: 0 0 0.25em 0;
    letter-spacing: -0.005em;
}
.eli15-tour-step {
    color: var(--ink-500);
    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 {
    background: var(--info-600);
    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: #1c3f70; }
.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;
    color: var(--info-600);
    border: 1px solid var(--info-600);
}
.eli15-tour-btn-ghost:hover {
    background: var(--info-100);
    color: #1c3f70;
}
.eli15-tour-close {
    background: transparent;
    color: var(--ink-500);
    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
   ============================================================= */
@media (max-aspect-ratio: 1/1) {
    #fullDisplay {
        grid-template-columns: 1fr minmax(240px, 34vw);
        grid-template-rows: auto minmax(0, 1fr) auto;
    }
    #canvasDiv {
        grid-column: 1 / span 2;
    }
    #rightPanel {
        grid-column: 2 / span 1;
        grid-row: 2 / span 1;
    }
    #rv-panel {
        grid-column: 2 / span 1;
        grid-row: 3 / span 1;
    }
    #bottomText {
        grid-column: 1 / span 1;
        grid-row: 3 / span 1;
    }
}

@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: auto auto auto auto;
        padding: var(--sp-3);
        gap: var(--sp-3);
    }
    #canvasDiv, #rightPanel, #rv-panel, #bottomText {
        grid-column: 1 / -1;
    }
    #rightPanel { grid-row: auto; max-height: 60vh; }
    #rv-panel   { grid-row: auto; max-height: 40vh; }
    #bottomText { grid-row: auto; border-radius: var(--r-lg); }
}

/* 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 {
    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: none;
    letter-spacing: 0.01em;
}
#perf-hud:hover { opacity: 1; }
@media (max-width: 900px) {
    #perf-hud { display: none !important; }
}

/* 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;
}
