body { margin: 0; overflow: hidden; background-color: #000; }
canvas { display: block; }
button { touch-action: manipulation; }

#loadingOverlay {
    position: fixed;
    inset: 0;
    z-index: 4;
    display: grid;
    place-items: center;
    pointer-events: none;
    opacity: 1;
    visibility: visible;
    transition: opacity 0.35s ease, visibility 0s linear 0.35s;
    background: #000;
}

#loadingOverlay.is-hidden {
    opacity: 0;
    visibility: hidden;
}

.loader-text {
    font-family: "IBM Plex Mono", "SFMono-Regular", Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    text-transform: uppercase;
    font-size: clamp(18px, 2.4vw, 28px);
    display: inline-flex;
    align-items: center;
}

.loader-word {
    display: inline-flex;
}

.loader-letter {
    display: inline-block;
    text-shadow: 0 0 10px currentColor;
}

.loader-letter:nth-child(1) { color: #44f5ff; }
.loader-letter:nth-child(2) { color: #ff64f3; }
.loader-letter:nth-child(3) { color: #ffe34f; }
.loader-letter:nth-child(4) { color: #5cff94; }
.loader-letter:nth-child(5) { color: #ff9a3d; }
.loader-letter:nth-child(6) { color: #75a6ff; }
.loader-letter:nth-child(7) { color: #ff5f8e; }

.loader-word,
.loader-dots {
    letter-spacing: 0.08em;
}

.loader-dots {
    display: inline-block;
    color: #fff;
    width: 0;
    overflow: hidden;
    vertical-align: bottom;
    animation: loaderDots 1.2s steps(4, end) infinite;
}

@keyframes loaderDots {
    from { width: 0; }
    to { width: 3ch; }
}

@media (hover: none) and (pointer: coarse) {
    body {
        -webkit-user-select: none;
        user-select: none;
    }
    body * {
        -webkit-user-select: none;
        user-select: none;
        -webkit-touch-callout: none;
    }
}

body.touch-ui,
body.touch-ui * {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

/* Top-right controls */
#topControls {
    position: fixed;
    top: max(10px, env(safe-area-inset-top));
    right: max(10px, env(safe-area-inset-right));
    z-index: 9; /* above HUD/detail panels, below settings overlay */
    display: flex;
    gap: 8px;
    transition: opacity 0.25s ease, transform 0.25s ease;
    pointer-events: auto;
}
#topControls[data-auto-hidden="true"] {
    opacity: 0;
    pointer-events: none;
    transform: translateY(-14px);
}
#topControls[data-auto-hidden="true"] ~ #hudStack {
    top: max(10px, env(safe-area-inset-top));
}

#topControls button {
    appearance: none;
    -webkit-appearance: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    border: 1px solid rgba(255,255,255,0.18);
    background: rgba(30,30,30,0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    color: #fff;
    border-radius: 10px;
    padding: 8px 12px;
    line-height: 1;
    cursor: pointer;
    transition: background .15s ease, border-color .15s ease, color .15s ease;
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
}

#topControls button:hover {
    background: rgba(40,40,40,0.65);
}

#topControls button:focus-visible {
    outline: 2px solid rgba(122,202,255,0.9);
    outline-offset: 2px;
}

#pauseBtn {
    font-size: 14px;
    letter-spacing: 0.2px;
    min-width: 80px;
}

#pauseBtn[data-state="paused"] {
    background: rgba(56,132,255,0.18);
    border-color: rgba(122,202,255,0.8);
}

#skipMenu {
    position: relative;
    display: inline-flex;
    align-items: center;
}
#skipMenu[data-visible="false"] {
    display: none;
}
#skipMenuToggle {
    font-size: 14px;
    min-width: 70px;
}
#skipMenuToggle[data-state="skipping"] {
    background: rgba(255, 148, 76, 0.28);
    border-color: rgba(255, 176, 96, 0.85);
    color: #ffd7b3;
    cursor: not-allowed;
    pointer-events: none;
}
#skipMenuToggle:disabled,
#skipLayerBtn:disabled,
#skipToEndBtn:disabled,
#skipNextPassBtn:disabled,
#skipLastPassBtn:disabled {
    background: rgba(255, 148, 76, 0.28);
    border-color: rgba(255, 176, 96, 0.85);
    color: #ffd7b3;
    cursor: not-allowed;
    pointer-events: none;
}
#skipMenuItems {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    display: none;
    flex-direction: column;
    gap: 6px;
    padding: 8px;
    background: rgba(12,12,12,0.7);
    border: 1px solid rgba(255,255,255,0.16);
    border-radius: 12px;
    box-shadow: 0 10px 24px rgba(0,0,0,0.35);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 999;
}
#skipMenu[data-open="true"] #skipMenuItems {
    display: flex;
}
#skipMenuItems button {
    width: 150px;
    text-align: left;
    font-size: 13px;
}

#skipLayerBtn {
    font-size: 14px;
    min-width: 130px;
}
#skipLayerBtn:not([data-visible="true"]) {
    display: none;
}

#skipConveyorBtn {
    font-size: 14px;
    min-width: 130px;
}
#skipConveyorBtn:not([data-visible="true"]) {
    display: none;
}

#skipToEndBtn {
    font-size: 14px;
    min-width: 130px;
}
#skipToEndBtn:not([data-visible="true"]) {
    display: none;
}
#skipNextPassBtn {
    font-size: 14px;
    min-width: 130px;
}
#skipNextPassBtn:not([data-visible="true"]) {
    display: none;
}
#skipLastPassBtn {
    font-size: 14px;
    min-width: 130px;
}
#skipLastPassBtn:not([data-visible="true"]) {
    display: none;
}
#nextTokenBtn:not([data-visible="true"]) {
    display: none;
}
#skipLayerBtn[data-state="skipping"],
#skipToEndBtn[data-state="skipping"],
#skipNextPassBtn[data-state="skipping"],
#skipLastPassBtn[data-state="skipping"] {
    background: rgba(255, 148, 76, 0.28);
    border-color: rgba(255, 176, 96, 0.85);
    color: #ffd7b3;
    cursor: not-allowed;
    pointer-events: none;
}

#followModeBtn {
    font-size: 13px;
    min-width: 150px;
    letter-spacing: 0.2px;
}

#followModeBtn[data-state="enabled"] {
    background: rgba(56,132,255,0.18);
    border-color: rgba(122,202,255,0.8);
}

#followModeBtn:disabled {
    cursor: default;
    opacity: 0.8;
}

#settingsBtn {
    padding-inline: 10px;
}
#settingsBtn svg {
    width: 18px;
    height: 18px;
    display: block;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Forward-pass auto-advance overlay */
#generationOverlay {
    position: fixed;
    left: 50%;
    bottom: max(18px, env(safe-area-inset-bottom));
    transform: translateX(-50%);
    z-index: 8;
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: min(520px, 94vw);
    padding: 12px 14px;
    color: #fff;
    background: rgba(9,9,9,0.86);
    border: 1px solid rgba(255,255,255,0.14);
    border-radius: 14px;
    box-shadow: 0 12px 28px rgba(0,0,0,0.46);
    backdrop-filter: blur(9px);
    -webkit-backdrop-filter: blur(9px);
    pointer-events: auto;
    font-family: "Inter", "SF Pro Text", "Segoe UI", system-ui, -apple-system, sans-serif;
}
#generationOverlay[data-visible="true"] {
    animation: generationOverlayIn 0.16s ease-out;
}
#generationOverlay[data-visible="false"] {
    display: none;
}
#generationOverlay .generation-header {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
#generationOverlay .generation-title {
    font-size: 13.5px;
    font-weight: 600;
    letter-spacing: 0.01em;
    display: flex;
    gap: 7px;
    align-items: center;
    color: #fff;
}
#generationOverlay [data-role="title-prefix"] {
    opacity: 0.95;
}
#generationOverlay [data-role="countdown-wrap"] {
    display: inline-flex;
    align-items: baseline;
    justify-content: center;
    gap: 1px;
    min-width: 44px;
    padding: 2px 8px 3px;
    border-radius: 999px;
    border: 1px solid rgba(255,255,255,0.25);
    background: rgba(255,255,255,0.07);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}
#generationOverlay [data-role="countdown"] {
    font-size: 15px;
    line-height: 1;
    color: #fff;
}
#generationOverlay .generation-meta {
    margin-top: 3px;
    font-size: 12px;
    color: rgba(255,255,255,0.75);
    line-height: 1.32;
}
#generationOverlay .generation-bar {
    height: 6px;
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 999px;
    overflow: hidden;
}
#generationOverlay .generation-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(
        90deg,
        rgba(44, 238, 255, 0.98) 0%,
        rgba(79, 178, 255, 0.98) 32%,
        rgba(112, 122, 255, 0.98) 66%,
        rgba(34, 92, 255, 0.98) 100%
    );
    box-shadow: 0 0 14px rgba(94, 176, 255, 0.58), 0 0 24px rgba(66, 118, 255, 0.36);
    transition: width 0.2s ease;
}
#generationOverlay[data-paused="true"] .generation-bar-fill {
    background: rgba(220,220,220,0.42);
    box-shadow: none;
}
#generationOverlay .generation-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}
#generationOverlay button {
    appearance: none;
    -webkit-appearance: none;
    border: 1px solid rgba(255,255,255,0.22);
    background: rgba(255,255,255,0.06);
    color: #fff;
    border-radius: 10px;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.01em;
    cursor: pointer;
    transition: transform .12s ease, background .14s ease, border-color .14s ease;
    font-family: inherit;
}
#generationOverlay button:hover:not(:disabled) {
    background: rgba(255,255,255,0.12);
    border-color: rgba(255,255,255,0.34);
    transform: translateY(-1px);
}
#generationOverlay button:focus-visible {
    outline: 2px solid rgba(255,255,255,0.7);
    outline-offset: 2px;
}
#generationOverlay button.primary {
    background: rgba(255,255,255,0.16);
    border-color: rgba(255,255,255,0.42);
}
#generationOverlay button.primary:hover:not(:disabled) {
    background: rgba(255,255,255,0.22);
    border-color: rgba(255,255,255,0.5);
}
#generationOverlay button:disabled {
    opacity: 0.55;
    cursor: default;
    transform: none;
}

@keyframes generationOverlayIn {
    from {
        opacity: 0;
        transform: translate(-50%, 8px);
    }
    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}
@media (max-width: 700px) {
    #generationOverlay {
        left: max(8px, env(safe-area-inset-left));
        right: max(8px, env(safe-area-inset-right));
        width: auto;
        max-width: none;
        bottom: max(8px, calc(env(safe-area-inset-bottom) + 8px));
        transform: none;
        padding: 12px;
        gap: 9px;
        border-radius: 14px;
        background:
            radial-gradient(140% 120% at 50% -10%, rgba(170, 216, 255, 0.15), rgba(10, 12, 16, 0) 52%),
            rgba(8, 10, 14, 0.9);
        box-shadow:
            0 16px 34px rgba(0, 0, 0, 0.46),
            0 0 0 1px rgba(255, 255, 255, 0.06);
    }
    #generationOverlay[data-visible="true"] {
        animation: generationOverlayInMobile 0.16s ease-out;
    }
    #generationOverlay .generation-title {
        font-size: 13px;
        gap: 10px;
        justify-content: space-between;
        align-items: center;
    }
    #generationOverlay [data-role="title-prefix"] {
        line-height: 1.24;
    }
    #generationOverlay [data-role="countdown-wrap"] {
        min-width: 48px;
        padding: 3px 8px 4px;
        font-size: 12px;
        letter-spacing: 0.01em;
    }
    #generationOverlay [data-role="countdown"] {
        font-size: 16px;
    }
    #generationOverlay .generation-meta {
        margin-top: 0;
        font-size: 12px;
        line-height: 1.35;
        overflow-wrap: anywhere;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }
    #generationOverlay .generation-bar {
        height: 7px;
    }
    #generationOverlay .generation-actions {
        gap: 8px;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        justify-content: stretch;
    }
    #generationOverlay button {
        min-height: 42px;
        min-width: 0;
        width: 100%;
        padding: 10px 8px;
        font-size: 13px;
        border-radius: 11px;
    }
}

@media (max-width: 420px) {
    #generationOverlay {
        left: max(6px, env(safe-area-inset-left));
        right: max(6px, env(safe-area-inset-right));
        bottom: max(6px, calc(env(safe-area-inset-bottom) + 6px));
        padding: 11px 10px;
        gap: 8px;
    }
    #generationOverlay .generation-title {
        flex-wrap: wrap;
        row-gap: 6px;
    }
    #generationOverlay [data-role="countdown-wrap"] {
        min-width: 44px;
    }
    #generationOverlay button {
        min-height: 40px;
        padding: 9px 8px;
        font-size: 12px;
    }
}

@keyframes generationOverlayInMobile {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Consolidated HUD stack */
#hudStack {
    position: fixed;
    top: 56px;
    right: 10px;
    z-index: 6;
    display: flex;
    flex-direction: column;
    gap: 0;
    width: clamp(320px, 27vw, 560px);
    max-width: min(560px, 92vw);
    --hud-equations-panel-height: clamp(80px, calc(7.5vh + 22px), 132px);
    pointer-events: auto;
    transition: top 0.25s ease;
}

#hudPanel {
    --hud-mono-font: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px 12px;
    padding: 10px 12px 6px;
    color: #fff;
    background: rgba(12,12,12,0.9);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 16px;
    box-shadow: 0 10px 28px rgba(0,0,0,0.32);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}
#hudPanel.detail-open {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    border-bottom: 1px solid rgba(255,255,255,0.12);
}

#statusOverlay {
    position: static;
    padding: 0;
    font-family: var(--hud-mono-font);
    font-size: 12px;
    line-height: 1.15;
    font-weight: 400;
    color: #fff;
    background: transparent;
    white-space: pre-line;
    pointer-events: none;
    font-variant-numeric: tabular-nums;
}

#parameterCounter {
    position: static;
    padding: 0;
    min-width: 0;
    background: transparent;
    text-align: right;
    font-family: var(--hud-mono-font);
    pointer-events: none;
    font-variant-numeric: tabular-nums;
}
#parameterCounter .param-label {
    font-size: 11px;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    color: #b8c0cc;
}
#parameterCounter .param-value {
    margin-top: 4px;
    font-size: 18px;
    letter-spacing: 0.6px;
    transition: transform 0.2s ease, text-shadow 0.2s ease;
}
#parameterCounter[data-animating="true"] .param-value {
    text-shadow: 0 0 14px rgba(255, 180, 120, 0.6);
    transform: translateY(-1px) scale(1.02);
}

/* Fullscreen blurred overlay */
#settingsOverlay {
    position: fixed;
    inset: 0;
    display: none; /* toggled to flex when open */
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(900px 500px at 50% -10%, rgba(255, 255, 255, 0.08), transparent 60%),
        rgba(6, 8, 12, 0.72);
    backdrop-filter: blur(12px) saturate(1.05);
    -webkit-backdrop-filter: blur(12px) saturate(1.05);
    z-index: 10; /* above everything */
}

/* Modal panel */
.settings-modal {
    width: min(92vw, 420px);
    --settings-accent: #e6edf7;
    --settings-surface: rgba(14, 16, 20, 0.92);
    --settings-border: rgba(255, 255, 255, 0.12);
    --settings-muted: #9aa3af;
    background:
        linear-gradient(155deg, rgba(20, 22, 28, 0.96), rgba(10, 12, 16, 0.94));
    border: 1px solid var(--settings-border);
    border-radius: 16px;
    box-shadow:
        0 18px 50px rgba(2, 6, 14, 0.6),
        0 0 0 1px rgba(255, 255, 255, 0.04);
    color: #eef1f6;
    font-family: "Rajdhani", "Space Grotesk", "Segoe UI", system-ui, -apple-system, sans-serif;
    overflow: hidden;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    background:
        linear-gradient(120deg, rgba(255, 255, 255, 0.06), rgba(10, 12, 18, 0.2) 60%),
        rgba(12, 14, 18, 0.6);
}
.settings-title {
    font-size: 15px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.4px;
}
#settingsClose {
    appearance: none;
    -webkit-appearance: none;
    border: none;
    background: rgba(255, 255, 255, 0.06);
    color: #cfd6e1;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    padding: 6px 7px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    transition: border-color .18s ease, background .18s ease, color .18s ease, box-shadow .18s ease;
}
#settingsClose:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.3);
    color: #fff;
    box-shadow: 0 0 12px rgba(255, 255, 255, 0.15);
}

.settings-content { padding: 14px 16px 18px; }
.settings-section { margin-bottom: 14px; }
.settings-section:last-child { margin-bottom: 0; }
.section-label {
    display: block;
    margin-bottom: 8px;
    color: var(--settings-muted);
    font-size: 11px;
    letter-spacing: 1px;
    text-transform: uppercase;
}

/* Speed radio group */
.speed-group { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.speed-option {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 12px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    background: linear-gradient(160deg, rgba(18, 24, 34, 0.9), rgba(12, 14, 20, 0.8));
    color: #dfe8f4;
    cursor: pointer;
    user-select: none;
    touch-action: manipulation;
    transition: background .18s ease, border-color .18s ease, box-shadow .18s ease, transform .18s ease;
    text-align: center;
    font-size: 13px;
    letter-spacing: 0.4px;
}
.speed-option:hover {
    border-color: rgba(255, 255, 255, 0.28);
    box-shadow: 0 0 12px rgba(255, 255, 255, 0.12);
    transform: translateY(-1px);
}
.speed-option input { position: absolute; opacity: 0; pointer-events: none; }
.speed-option[data-checked="true"] {
    border-color: rgba(255, 255, 255, 0.6);
    background:
        linear-gradient(160deg, rgba(34, 40, 52, 0.8), rgba(12, 16, 24, 0.7));
    box-shadow: 0 0 14px rgba(255, 255, 255, 0.12);
    color: #f3fbff;
}

.slider-row {
    padding: 10px 12px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 11px;
    background: linear-gradient(160deg, rgba(18, 18, 18, 0.86), rgba(8, 8, 8, 0.9));
    margin-bottom: 8px;
}
.slider-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
}
.slider-value {
    font-size: 12px;
    color: #dce6f5;
    letter-spacing: 0.2px;
}
.settings-range {
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    accent-color: #f0f4ff;
}
.settings-range::-webkit-slider-runnable-track {
    height: 6px;
    border-radius: 999px;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.36), rgba(255, 255, 255, 0.14));
}
.settings-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.35);
    background: radial-gradient(circle at 34% 30%, #ffffff, #ececec 68%, #d4d4d4 100%);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
    margin-top: -5px;
}
.settings-range::-moz-range-track {
    height: 6px;
    border: none;
    border-radius: 999px;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.36), rgba(255, 255, 255, 0.14));
}
.settings-range::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.35);
    background: radial-gradient(circle at 34% 30%, #ffffff, #ececec 68%, #d4d4d4 100%);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
}

/* Simple toggle row */
.toggle-row {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 9px 12px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 11px;
    background: linear-gradient(160deg, rgba(18, 18, 18, 0.86), rgba(8, 8, 8, 0.9));
    color: #f1f1f1;
    user-select: none;
    cursor: pointer;
    touch-action: manipulation;
    transition: border-color .18s ease, background .18s ease, box-shadow .18s ease, transform .18s ease;
}
.toggle-row:hover {
    border-color: rgba(255, 255, 255, 0.34);
    background: linear-gradient(160deg, rgba(24, 24, 24, 0.9), rgba(10, 10, 10, 0.94));
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.06),
        0 10px 24px rgba(0, 0, 0, 0.42);
    transform: translateY(-1px);
}
.toggle-row .toggle-text {
    flex: 1;
    font-size: 12.5px;
    line-height: 1.4;
}
.toggle-row input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
    pointer-events: none;
}
.toggle-row .toggle-track {
    position: relative;
    --toggle-width: 42px;
    --toggle-height: 22px;
    --toggle-padding: 2px;
    --toggle-knob: 16px;
    width: var(--toggle-width);
    height: var(--toggle-height);
    border-radius: 999px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.03));
    border: 1px solid rgba(255, 255, 255, 0.22);
    box-shadow:
        inset 0 0 0 1px rgba(0, 0, 0, 0.48),
        0 0 0 1px rgba(255, 255, 255, 0.03),
        0 6px 14px rgba(0, 0, 0, 0.36);
    transition: background .18s ease, border-color .18s ease, box-shadow .18s ease, transform .18s ease;
    margin-left: auto;
    flex-shrink: 0;
    box-sizing: border-box;
}
.toggle-row .toggle-track::before {
    content: '';
    position: absolute;
    inset: 1px;
    border-radius: inherit;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.16), transparent 62%);
    opacity: 0.62;
    pointer-events: none;
}
.toggle-row .toggle-track::after {
    content: '';
    position: absolute;
    top: 50%;
    left: var(--toggle-padding);
    width: var(--toggle-knob);
    height: var(--toggle-knob);
    border-radius: 50%;
    background: radial-gradient(circle at 34% 30%, #ffffff, #ececec 68%, #d4d4d4 100%);
    border: 1px solid rgba(0, 0, 0, 0.35);
    box-shadow:
        0 2px 7px rgba(0, 0, 0, 0.44),
        0 0 0 1px rgba(255, 255, 255, 0.06);
    transform: translateY(-50%);
    transition: left .18s ease, background .18s ease, transform .18s ease;
}
.toggle-row input:checked + .toggle-track {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.34), rgba(255, 255, 255, 0.12));
    border-color: rgba(255, 255, 255, 0.76);
    box-shadow:
        inset 0 0 0 1px rgba(255, 255, 255, 0.18),
        0 0 12px rgba(255, 255, 255, 0.2),
        0 8px 18px rgba(0, 0, 0, 0.34);
}
.toggle-row input:checked + .toggle-track::after {
    left: calc(100% - var(--toggle-padding) - var(--toggle-knob));
    background: radial-gradient(circle at 34% 30%, #ffffff, #f6f6f6 70%, #e5e5e5 100%);
    box-shadow:
        0 2px 8px rgba(0, 0, 0, 0.42),
        0 0 14px rgba(255, 255, 255, 0.32);
}
.toggle-row input:focus-visible + .toggle-track {
    outline: 2px solid rgba(255, 255, 255, 0.72);
    outline-offset: 2px;
}
.toggle-row input:disabled + .toggle-track {
    opacity: 0.5;
}
.settings-hint {
    margin-top: 8px;
    padding: 8px 10px;
    border-radius: 9px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    background: rgba(255, 255, 255, 0.06);
    color: #d2dbe5;
    font-size: 11.5px;
    line-height: 1.35;
    letter-spacing: 0.2px;
}
.settings-hint[hidden] { display: none !important; }
/* Equations panel (inside HUD) */
#equationsPanel {
    grid-column: 1 / -1;
    position: static;
    min-width: 0;
    margin-top: -6px;
    height: var(--hud-equations-panel-height);
    min-height: var(--hud-equations-panel-height);
    max-height: var(--hud-equations-panel-height);
    overflow: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 0;
    color: #fff;
    background: transparent;
    border-radius: 0;
    pointer-events: auto;
    display: none; /* toggled on when enabled */
}
#equationsPanel .eq-title {
    display: none;
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
    font-size: 11px;
    color: #cfd3dc;
    margin-bottom: 2px;
    letter-spacing: .2px;
}
#equationsPanel .eq-body {
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
    font-size: 14px;
    line-height: 1.3;
    margin-top: 0;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    max-width: 100%;
    overflow: auto;
}
#equationsPanel .eq-body > .katex-display {
    width: 100%;
    display: flex;
    justify-content: center;
}
#equationsPanel .eq-body > .katex-display > .katex {
    margin: 0 auto;
}
/* KaTeX tweaks for dark bg */
.katex { color: #fff; }
.katex-display {
    margin: 0;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 0;
}

/* Detail side panel */
#detailPanel {
    grid-column: 1 / -1;
    position: relative;
    width: 100%;
    height: auto;
    min-height: 0;
    max-height: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 0;
    box-sizing: border-box;
    background: rgba(10,10,12,0.94);
    border: 0 solid transparent;
    border-radius: 16px;
    box-shadow: none;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 7;
    transform: translateY(-8px);
    opacity: 0;
    pointer-events: none;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    transition: transform 0.25s ease, opacity 0.25s ease, max-height 0.25s ease;
}
#detailPanel.is-open {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
    gap: 12px;
    padding-bottom: 12px;
    border: 1px solid rgba(255,255,255,0.12);
    border-top: 0;
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    box-shadow: 0 16px 36px rgba(0,0,0,0.38), inset 0 1px 0 rgba(255,255,255,0.04);
    max-height: 62vh;
}

@media (min-width: 881px) and (min-aspect-ratio: 1/1) {
    #hudStack.detail-open {
        bottom: max(10px, env(safe-area-inset-bottom));
    }
    #hudStack.detail-open #detailPanel.is-open {
        flex: 1 1 auto;
        max-height: none;
    }
}
.detail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 52px 8px 16px;
    border-bottom: none;
}
.detail-title-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.detail-title {
    font-family: monospace;
    font-size: 15px;
    color: #fff;
    white-space: pre-line;
}
.detail-subtitle {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 11px;
    letter-spacing: 0.3px;
    color: #9aa4b2;
    text-transform: none;
}
.detail-subtitle:empty {
    display: none;
}
#detailClose {
    position: absolute;
    top: 10px;
    right: 10px;
    left: auto;
    transform: none;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    appearance: none;
    -webkit-appearance: none;
    border: 1px solid rgba(255,255,255,0.1);
    background: linear-gradient(180deg, rgba(24,24,24,0.95), rgba(16,16,16,0.92));
    color: #d9dee6;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    border-radius: 10px;
    box-shadow: 0 8px 22px rgba(0,0,0,0.32);
    z-index: 12;
    transition: transform 0.18s ease, background 0.18s ease, color 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}
#detailClose:hover {
    background: rgba(255,255,255,0.06);
    color: #fff;
    border-color: rgba(255,255,255,0.16);
    box-shadow: 0 10px 26px rgba(0,0,0,0.36);
}
#detailClose:active {
    transform: scale(0.97);
}
#detailClose:focus-visible {
    outline: 2px solid #7bdcff;
    outline-offset: 3px;
}

.detail-preview {
    padding: 0 16px;
    width: 100%;
    aspect-ratio: 16 / 9;
    min-height: 200px;
    max-height: 42vh;
    box-sizing: border-box;
}
.detail-preview canvas {
    width: 100%;
    height: 100%;
    display: block;
    background: #000;
    border-radius: 14px;
    border: 1px solid rgba(255,255,255,0.1);
    opacity: 1;
    transition: opacity 0.2s ease;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}
#detailPanel.is-preview-hidden .detail-preview {
    display: none;
}
.detail-description {
    padding: 4px 16px 6px;
    font-size: 12px;
    line-height: 1.45;
    color: #cfd3dc;
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
}
.detail-description:empty {
    display: none;
}

.detail-equations {
    margin: 0 12px;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.12);
    background: rgba(255,255,255,0.04);
    display: none;
    flex-direction: column;
    gap: 6px;
}
.detail-equations.is-visible { display: flex; }
.detail-equations-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: #9aa3af;
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
}
.detail-equations-body {
    color: #e7e9ee;
    font-size: 12px;
    line-height: 1.28;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
}
.detail-equations-body:empty {
    display: none;
}
.detail-equations-body .katex-display {
    margin: 0.14em 0;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
}
.detail-equations-body .katex-display > .katex {
    font-size: 1em;
}

.vector-legend {
    margin: 0 12px;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.12);
    background: rgba(255,255,255,0.03);
    display: none;
    flex-direction: column;
    gap: 6px;
}
.vector-legend.is-visible { display: flex; }
.vector-legend-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: #9aa3af;
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
}
.vector-legend-bar {
    height: 10px;
    border-radius: 999px;
    border: 1px solid rgba(255,255,255,0.18);
    background: var(--vector-legend-gradient, linear-gradient(90deg, #d24b2d, #7bdcff, #3a5bff));
    background-clip: padding-box;
    background-origin: padding-box;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.25);
}
.vector-legend-labels {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    color: #9aa3af;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 10px;
}

.detail-attention {
    margin: 0 12px;
    padding: 12px;
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.12);
    background: rgba(255,255,255,0.04);
    display: none;
    flex-direction: column;
    gap: 10px;
}
.detail-attention.is-visible { display: flex; }
.detail-attention-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.detail-attention-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: #9aa3af;
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
}
.detail-attention-toggle {
    padding: 6px 8px;
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.12);
    background: rgba(255,255,255,0.03);
    font-size: 12px;
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
    min-width: 140px;
}
.detail-attention-toggle .toggle-text { font-size: 12px; }

.detail-attention-grid {
    display: grid;
    grid-template-columns: auto max-content max-content;
    grid-template-rows: auto auto 1fr;
    gap: var(--attention-grid-gap, 8px);
    align-items: start;
    justify-content: center;
    width: 100%;
    box-sizing: border-box;
    padding: var(--attention-grid-inset, 0px);
    overflow: visible;
}
.attention-corner {
    width: 6px;
    height: 6px;
    grid-column: 2;
    grid-row: 2;
}
.attention-axis-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: #9aa3af;
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
    line-height: 1;
    white-space: nowrap;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}
.attention-axis-label-text {
    display: inline-block;
}
.attention-axis-label--top {
    grid-column: 3;
    grid-row: 1;
    justify-self: center;
    align-self: end;
    padding-bottom: 2px;
    transform: translateY(4px);
}
.attention-axis-label--left {
    grid-column: 1;
    grid-row: 3;
    justify-self: end;
    align-self: stretch;
    padding-right: 4px;
}
.attention-axis-label--left .attention-axis-label-text {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) rotate(180deg);
    transform-origin: 50% 50%;
}
.attention-tokens {
    display: grid;
    align-items: center;
    justify-items: center;
    gap: var(--cell-gap, 4px);
    color: #9aa3af;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}
.attention-tokens-top {
    grid-column: 3;
    grid-row: 2;
    overflow-x: hidden;
    overflow-y: visible;
    padding-bottom: 18px;
    padding-top: 6px;
    min-height: calc(var(--cell-size, 18px) * 2.2);
    align-items: end;
    justify-self: center;
    width: max-content;
    max-width: 100%;
}
.attention-tokens-left {
    grid-column: 2;
    grid-row: 3;
    padding-right: var(--attention-left-padding, 4px);
    overflow: visible;
    width: max-content;
}
.attention-token {
    font-size: 10px;
    line-height: 1.1;
    text-align: center;
    white-space: nowrap;
    overflow: visible;
    text-overflow: clip;
    max-width: none;
    width: var(--cell-size, 18px);
    height: var(--cell-size, 18px);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    transition: color .12s ease, text-shadow .12s ease, transform .12s ease;
}
.attention-token-left {
    width: auto;
    min-width: var(--cell-size, 18px);
    padding-right: var(--attention-left-token-padding, 6px);
    justify-content: flex-end;
    text-align: right;
}
.attention-token-top {
    position: relative;
    text-align: center;
    align-items: center;
    justify-content: center;
}
.attention-token-top-label {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) rotate(180deg);
    transform-origin: 50% 50%;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    white-space: nowrap;
}
.detail-attention[data-attn-mode="post"] .attention-token.is-highlighted {
    color: #8fd2ff;
    text-shadow: 0 0 8px rgba(143,210,255,0.6);
    transform: scale(1.16);
}
.attention-matrix {
    display: grid;
    grid-column: 3;
    grid-row: 3;
    align-items: center;
    justify-items: center;
    gap: var(--cell-gap, 4px);
    justify-self: center;
    width: max-content;
    max-width: 100%;
    overflow: visible;
}
.attention-tokens-top {
    justify-self: center;
}
.attention-legend {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas:
        "bar bar"
        "low high";
    align-items: end;
    gap: 8px;
    margin-top: 10px;
    color: #9aa3af;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 10px;
}
.attention-legend-bar {
    grid-area: bar;
    position: relative;
    height: 10px;
    border-radius: 999px;
    border: 1px solid rgba(255,255,255,0.18);
    background: var(--attention-legend-gradient, linear-gradient(90deg, #0b0b0b, #ffffff));
    background-clip: padding-box;
    background-origin: padding-box;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.25);
}
.attention-legend-bar::before {
    content: '';
    position: absolute;
    left: 50%;
    top: -2px;
    bottom: -2px;
    width: 1px;
    background: rgba(255,255,255,0.45);
    opacity: var(--attention-legend-mid-opacity, 1);
}
.attention-legend-bar::after {
    content: attr(data-mid);
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translate(-50%, 4px);
    color: rgba(154,163,175,0.9);
    font-size: 9px;
    opacity: var(--attention-legend-mid-opacity, 1);
}
.attention-legend-label {
    min-width: 0;
}
#detailAttentionLegendLow {
    grid-area: low;
    justify-self: start;
    text-align: left;
}
#detailAttentionLegendHigh {
    grid-area: high;
    justify-self: end;
    text-align: right;
}
.attention-cell {
    width: var(--cell-size, 18px);
    height: var(--cell-size, 18px);
    border-radius: clamp(1px, calc(var(--cell-size, 18px) * 0.25), 6px);
    background: rgba(255,255,255,0.08);
    transform-origin: center;
    transition: opacity .12s ease, transform .12s cubic-bezier(0.22, 1, 0.36, 1), box-shadow .12s ease, filter .12s ease;
    cursor: pointer;
}
.detail-attention[data-attn-mode="post"] .attention-cell:not(.is-empty) {
    box-shadow: inset 0 0 0 1px rgba(80,80,80,0.7);
}
.attention-cell.post-softmax-reveal {
    animation-name: attentionPostSoftmaxReveal;
    animation-timing-function: ease-out;
    animation-fill-mode: both;
}
.attention-cell.pre-softmax-reveal {
    animation-name: attentionPreSoftmaxReveal;
    animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
    animation-fill-mode: both;
}
.attention-cell.is-empty {
    background: rgba(255,255,255,0.04);
    opacity: 0.35;
    pointer-events: none;
}
.attention-cell.attention-pop-out {
    animation-fill-mode: both;
    pointer-events: none;
}
.detail-attention[data-attn-mode="post"] .attention-cell.attention-pop-out {
    animation-name: attentionPostSoftmaxPopOut;
    animation-timing-function: ease-out;
}
.detail-attention[data-attn-mode="pre"] .attention-cell.attention-pop-out {
    animation-name: attentionPreSoftmaxPopOut;
    animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
}
.attention-cell.is-hidden {
    visibility: hidden;
    pointer-events: none;
    background: transparent;
    box-shadow: none;
}
.attention-matrix.has-focus-cell .attention-cell:not(.is-hovered):not(.is-pinned):not(.is-empty):not(.is-hidden) {
    opacity: var(--attention-cell-rest-opacity, 0.38);
    filter: saturate(0.5) brightness(0.82);
}
.attention-cell.is-hovered {
    transform: scale(var(--attention-cell-hover-scale, 1.28));
    z-index: 3;
    box-shadow: 0 10px 18px rgba(0,0,0,0.5), 0 0 0 1px rgba(143,210,255,0.38);
    filter: brightness(1.2) saturate(1.1);
}
.attention-cell.is-pinned {
    transform: scale(var(--attention-cell-pinned-scale, 1.42));
    z-index: 4;
    box-shadow: 0 14px 24px rgba(0,0,0,0.58), 0 0 0 1px rgba(143,210,255,0.56);
    filter: brightness(1.3) saturate(1.16);
}
.attention-cell:active:not(.is-empty):not(.is-hidden) {
    transform: scale(var(--attention-cell-active-scale, 1.5));
    z-index: 5;
    box-shadow: 0 16px 26px rgba(0,0,0,0.62), 0 0 0 1px rgba(143,210,255,0.6);
    filter: brightness(1.34) saturate(1.18);
}
.detail-attention[data-attn-mode="pre"] .attention-cell.is-hovered:not(.is-empty) {
    box-shadow: 0 10px 18px rgba(0,0,0,0.5), 0 0 0 1px rgba(255,255,255,0.22);
}
.detail-attention[data-attn-mode="pre"] .attention-cell.is-pinned:not(.is-empty) {
    box-shadow: 0 14px 24px rgba(0,0,0,0.58), 0 0 0 1px rgba(255,255,255,0.3);
}
.detail-attention[data-attn-mode="pre"] .attention-cell:active:not(.is-empty):not(.is-hidden) {
    box-shadow: 0 16px 26px rgba(0,0,0,0.62), 0 0 0 1px rgba(255,255,255,0.34);
}
.detail-attention[data-attn-mode="post"] .attention-cell.is-hovered:not(.is-empty) {
    box-shadow:
        inset 0 0 0 1px rgba(80,80,80,0.7),
        0 10px 18px rgba(0,0,0,0.5),
        0 0 0 1.5px rgba(120,204,255,0.72),
        0 0 10px rgba(78,178,255,0.34);
}
.detail-attention[data-attn-mode="post"] .attention-cell.is-pinned:not(.is-empty) {
    box-shadow:
        inset 0 0 0 1px rgba(80,80,80,0.7),
        0 14px 24px rgba(0,0,0,0.58),
        0 0 0 1.5px rgba(130,211,255,0.84),
        0 0 14px rgba(88,185,255,0.42);
}
.detail-attention[data-attn-mode="post"] .attention-cell:active:not(.is-empty):not(.is-hidden) {
    box-shadow:
        inset 0 0 0 1px rgba(80,80,80,0.7),
        0 16px 26px rgba(0,0,0,0.62),
        0 0 0 1.5px rgba(137,216,255,0.9),
        0 0 16px rgba(95,189,255,0.48);
}
@keyframes attentionPostSoftmaxReveal {
    0% {
        opacity: 0;
        transform: scale(0.72);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}
@keyframes attentionPreSoftmaxReveal {
    0% {
        opacity: 0;
        transform: scale(0.6);
    }
    65% {
        opacity: 1;
        transform: scale(1.06);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}
@keyframes attentionPostSoftmaxPopOut {
    0% {
        opacity: 1;
        transform: scale(1);
    }
    100% {
        opacity: 0.35;
        transform: scale(0.72);
    }
}
@keyframes attentionPreSoftmaxPopOut {
    0% {
        opacity: 1;
        transform: scale(1);
    }
    100% {
        opacity: 0.35;
        transform: scale(0.72);
    }
}
.attention-empty {
    font-size: 12px;
    color: #9aa3af;
    display: none;
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
}
.attention-note {
    font-size: 11px;
    color: #7f8794;
    min-height: 12px;
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
    text-align: center;
}
.attention-value {
    display: grid;
    gap: 6px;
}
.attention-value-head {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(70px, 0.8fr);
    color: #93a0b2;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.55px;
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
}
.attention-value-head > span {
    min-width: 0;
    text-align: center;
}
.attention-value-bar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(70px, 0.8fr);
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.16);
    background: rgba(255,255,255,0.04);
    overflow: hidden;
    box-shadow:
        inset 0 0 0 1px rgba(255,255,255,0.05),
        0 8px 16px rgba(0,0,0,0.24);
}
.attention-value-item {
    min-width: 0;
    min-height: 30px;
    padding: 6px 8px;
    color: #e7edf7;
    font-size: 12px;
    line-height: 1.1;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-variant-numeric: tabular-nums;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    justify-content: center;
}
.attention-value-item + .attention-value-item {
    border-left: 1px solid rgba(255,255,255,0.11);
}
.attention-value-item--score {
    color: #e7edf7;
    font-weight: 400;
}
.attention-value[data-empty="true"] .attention-value-bar {
    border-color: rgba(255,255,255,0.14);
    background: rgba(255,255,255,0.04);
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.04);
}
.attention-value[data-empty="true"] .attention-value-item {
    color: #8f98a5;
}
.attention-value[data-empty="true"] .attention-value-item--score {
    color: #8f98a5;
}

.detail-meta {
    padding: 0 16px;
    display: grid;
    gap: 10px;
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
}
.detail-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.12);
    background: rgba(255,255,255,0.04);
    color: #e7e9ee;
    font-size: 13px;
}
.detail-label {
    color: #9aa3af;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 11px;
}
.detail-value { color: #fff; }
.detail-row-dims {
    align-items: stretch;
    justify-content: flex-start;
    gap: 0;
    padding: 0;
    overflow: hidden;
    container-type: inline-size;
}
.detail-dim-half {
    flex: 1 1 50%;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 10px 12px;
}
.detail-dim-half + .detail-dim-half {
    border-left: 1px solid rgba(255,255,255,0.12);
}
.detail-row-dims .detail-label {
    display: block;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: clamp(8.5px, 1.2vw, 11px);
    letter-spacing: clamp(0.2px, 0.06vw, 0.5px);
}
@supports (width: 1cqw) {
    .detail-row-dims .detail-label {
        font-size: clamp(8.5px, 4cqw, 11px);
        letter-spacing: clamp(0.2px, 0.15cqw, 0.5px);
    }
}
.detail-row-dims .detail-value {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}
.detail-token-info {
    gap: 6px;
}
.detail-token-info-head,
.detail-token-info-bar {
    grid-template-columns: minmax(0, 1.45fr) minmax(84px, 0.85fr) minmax(84px, 0.85fr);
}
.detail-token-info[data-layout="position"] .detail-token-info-head,
.detail-token-info[data-layout="position"] .detail-token-info-bar {
    grid-template-columns: minmax(84px, 0.85fr) minmax(0, 1.45fr);
}
.detail-token-info[data-layout="position"] #detailTokenInfoHeadTertiary,
.detail-token-info[data-layout="position"] .detail-token-info-item--position {
    display: none;
}
.detail-token-info-item {
    min-height: 30px;
}
.detail-token-info-item--text {
    justify-content: center;
    text-align: center;
}
.detail-token-info-item--id,
.detail-token-info-item--position {
    font-variant-numeric: tabular-nums;
}
.detail-row-token-note {
    align-items: flex-start;
}
.detail-row-token-note .detail-value {
    max-width: 70%;
    text-align: right;
    overflow-wrap: anywhere;
    line-height: 1.35;
}
.detail-row-bias .detail-value {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

.detail-data {
    margin: 2px 16px 0;
    padding: 12px;
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.12);
    background: rgba(255,255,255,0.04);
}
.detail-data-title {
    color: #9aa3af;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 11px;
    margin-bottom: 6px;
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
}
.detail-data-values {
    margin: 0;
    color: #e7e9ee;
    font-size: 12px;
    line-height: 1.45;
    max-height: 30vh;
    overflow: auto;
    white-space: pre-wrap;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

/* Responsive adjustments */
@media (max-width: 900px) {
    #hudStack { width: min(480px, 92vw); gap: 0; }
    #hudPanel { padding: 10px 12px 6px; gap: 8px 12px; }
}
@media (max-width: 600px) {
    #hudStack {
        left: 8px;
        right: 8px;
        width: auto;
        max-width: calc(100vw - 16px);
        --hud-equations-panel-height: clamp(74px, 11vh, 88px);
        gap: 0;
    }
    #hudPanel { padding: 6px 8px 3px; gap: 4px 8px; }
    #statusOverlay { font-size: 12px; line-height: 1.15; }
    #parameterCounter .param-value { font-size: 15px; }
    #equationsPanel .eq-title { font-size: 10px; margin-bottom: 2px; }
    #equationsPanel .eq-body { font-size: 12px; line-height: 1.28; }
    .detail-preview { min-height: 180px; }
    .detail-attention { margin: 0 8px; padding: 10px; }
    .attention-token { font-size: 9px; }
    .attention-tokens-top { min-height: calc(var(--cell-size, 16px) * 2.4); }
    .attention-value-head { font-size: 9px; }
    .attention-value-item { min-height: 26px; font-size: 11px; }
}
@media (max-height: 560px) {
    #hudStack { --hud-equations-panel-height: clamp(68px, 16vh, 84px); }
}
@media (max-aspect-ratio: 1/1), (max-width: 880px) {
    body.detail-mobile-focus #topControls {
        opacity: 0;
        pointer-events: none;
        transform: translateY(-14px);
    }
    body.detail-mobile-focus #hudStack {
        top: max(10px, env(safe-area-inset-top));
    }
    #hudStack {
        left: 8px;
        right: 8px;
        width: auto;
        max-width: calc(100vw - 16px);
        --hud-equations-panel-height: clamp(74px, 11vh, 90px);
        gap: 0;
    }
    #hudPanel { padding: 6px 8px 3px; gap: 4px 8px; }
    #statusOverlay { font-size: 12px; line-height: 1.15; }
    #parameterCounter .param-label { font-size: 10px; }
    #parameterCounter .param-value { font-size: 15px; }
    #equationsPanel .eq-title { font-size: 10px; margin-bottom: 2px; }
    #equationsPanel .eq-body { font-size: 12px; line-height: 1.28; }
    #detailPanel {
        display: flex;
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: 100dvh;
        max-height: 100dvh;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
        background: rgba(12,12,12,0.9);
        border: 1px solid rgba(255,255,255,0.12);
        border-left: none;
        border-right: none;
        border-bottom: none;
        border-radius: 0;
        margin-top: 0;
        padding-top: 0;
        box-shadow: 0 10px 28px rgba(0,0,0,0.32);
        transform: translateY(100%);
    }
    #detailPanel.is-open {
        transform: translateY(0);
        height: 100dvh;
        max-height: 100dvh;
        margin-top: 0;
        padding-top: 0;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
        border-top-left-radius: 0;
        border-top-right-radius: 0;
        border-left: none;
        border-right: none;
        border-bottom: none;
        border-top: 1px solid rgba(255,255,255,0.12);
    }
    #hudPanel.detail-open {
        border-bottom-left-radius: 16px;
        border-bottom-right-radius: 16px;
        border-bottom: 1px solid rgba(255,255,255,0.12);
    }
    #detailClose {
        position: sticky;
        top: max(12px, env(safe-area-inset-top));
        right: max(12px, env(safe-area-inset-right));
        left: auto;
        transform: none;
        align-self: flex-end;
        margin: 10px 12px 0 auto;
        width: 38px;
        height: 42px;
        border-radius: 12px;
        box-shadow: 0 8px 18px rgba(0,0,0,0.32);
        transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
    }
    #detailClose:active {
        transform: none;
    }
}

@media (max-width: 880px) and (orientation: portrait) {
    #hudStack { --hud-equations-panel-height: clamp(72px, 11vh, 84px); }
}
