/* The DOM GUI's scale (src/app/uiScale.js sets --ui-scale and the
   html.ui-* layout classes from the window). The menus and modals take it
   as `zoom`; inside them a viewport unit is zoomed too, so their sizes
   from the window use --ui-vw / --ui-dvh (the window in the zoomed GUI's
   px) instead of 100vw / 100dvh. The HUD and the relic results aren't
   zoomed: their 512 × 240 box is sized so their text is the menus' size,
   never past the window; the debug text overlay sizes itself from the
   window. --hud-px, a HUD pixel: the menu font's 2 CSS px (× --ui-scale)
   times the sprite font's CRT ratio (spriteSheetTextRenderer.js crtAspect,
   8 / 5) — the menus' glyphs are drawn that much taller, and the HUD's
   (spriteHudText.js) keep native line heights with the menus' proportions. */
:root {
    --ui-scale: 1;
    --hud-px: calc(2px * 8 / 5 * var(--ui-scale));
    --ui-vw: calc(100vw / var(--ui-scale));
    --ui-dvh: calc(100dvh / var(--ui-scale));
}

#appLoaderCard,
#debugMenu,
#raceSetupModal,
#changelogModal,
#mcsTutorialModal,
#creditsModal,
.race-end-menu,
.race-results-panel {
    zoom: var(--ui-scale);
}

body {
    margin: 0;
    overflow: hidden;
    background: #000000;
}

canvas {
    display: block;
}

#appLoaderOverlay {
    position: fixed;
    inset: 0;
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    color: #f6f6f6;
    background: rgba(0, 0, 0, 0.72);
    /* Takes the pointer so the menus under it can't be clicked while
       loading (the keyboard / gamepad routers skip them too). */
    pointer-events: auto;
}

#appLoaderOverlay.hidden {
    display: none;
}

#appLoaderCard {
    width: min(560px, calc(var(--ui-vw) - 32px));
    padding: 18px 20px;
    box-sizing: border-box;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 12px;
    background: rgba(14, 14, 14, 0.9);
    box-shadow: 0 18px 42px rgba(0, 0, 0, 0.46);
}

#appLoaderTitle {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 8px;
}

#appLoaderText {
    font-size: 0.9rem;
    opacity: 0.9;
    margin-bottom: 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#appLoaderBar {
    width: 100%;
    height: 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.14);
    overflow: hidden;
}

#appLoaderBarFill {
    width: 0%;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #22c55e, #84cc16);
    transition: width 0.16s ease;
}

#appLoaderFooter {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-top: 10px;
}

#appLoaderMeta {
    font-size: 0.8rem;
    opacity: 0.65;
    font-variant-numeric: tabular-nums;
}

#appLoaderPercent {
    text-align: right;
    font-size: 0.9rem;
    font-weight: 700;
}

#appLoaderSteps {
    list-style: none;
    margin: 12px 0 0;
    padding: 8px 0 0;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    max-height: min(calc(var(--ui-dvh) * 0.46), 360px);
    overflow-y: auto;
    font-size: 0.78rem;
    font-variant-numeric: tabular-nums;
}

#appLoaderSteps:empty {
    display: none;
}

/* Without the setup modal's "Debug mode": the bar and the current step only. */
#appLoaderCard.compact #appLoaderSteps,
#appLoaderCard.compact #appLoaderMeta {
    display: none;
}

#appLoaderSteps li {
    display: grid;
    grid-template-columns: 1.1em minmax(0, auto) minmax(0, 1fr) auto;
    align-items: baseline;
    gap: 8px;
    padding: 2px 0;
    opacity: 0.85;
}

#appLoaderSteps li.sub {
    padding-left: 1.4em;
    opacity: 0.7;
}

#appLoaderSteps li.active {
    opacity: 1;
}

#appLoaderSteps .step-icon {
    color: #84cc16;
    text-align: center;
}

#appLoaderSteps li.active .step-icon::before {
    content: '';
    display: inline-block;
    width: 0.7em;
    height: 0.7em;
    border: 2px solid rgba(255, 255, 255, 0.25);
    border-top-color: #84cc16;
    border-radius: 50%;
    animation: appLoaderSpin 0.8s linear infinite;
}

#appLoaderSteps .step-label {
    white-space: nowrap;
}

#appLoaderSteps .step-detail {
    opacity: 0.6;
    overflow-wrap: anywhere;
}

#appLoaderSteps .step-time {
    opacity: 0.5;
    text-align: right;
}

@keyframes appLoaderSpin {
    to { transform: rotate(360deg); }
}

#overlayContainer {
    position: absolute;
    bottom: 10px;
    left: 10px;
    color: rgb(255, 255, 255);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 1.25rem;
    pointer-events: none;
    /* Keyboard play (Ctrl+A, Shift+arrows) never highlights the text. */
    user-select: none;
    -webkit-user-select: none;
    background-color: rgba(17, 17, 17, .5);
    padding: 0.5em;
    z-index: 1000;
}

body.timeline-hidden #overlayContainer {
    bottom: 10px;
}

#overlayContainer kbd {
    display: inline-block;
    margin-right: 0.2em;
    padding: 0.08em 0.45em;
    color: #f8f8f8;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.32);
    border-radius: 4px;
    box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.45), 0 1px 1px rgba(0, 0, 0, 0.35);
    font-family: inherit;
    font-size: 0.78em;
    font-weight: 700;
    line-height: 1.15;
    text-transform: none;
    white-space: nowrap;
    vertical-align: baseline;
}

.glyph {
    display: inline-block;
    height: 1.2em;
    width: 1.2em;
    margin-right: 0.15em;
    vertical-align: -0.3em;
    object-fit: contain;
    image-rendering: -webkit-optimize-contrast;
}

.glyph:last-of-type {
    margin-right: 0.2em;
}

#instanceNameLayer {
    position: fixed;
    inset: 0;
    z-index: 900;
    pointer-events: none;
}

.player-name-label {
    position: absolute;
    left: 0;
    top: 0;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    transform-origin: center bottom;
    will-change: transform;
}

#speedGraphContainer {
    position: absolute;
    right: 10px;
    bottom: 74px;
    width: 460px;
    height: 220px;
    background-color: rgba(17, 17, 17, .5);
    padding: 0.5em;
    box-sizing: border-box;
    resize: none;
    overflow: hidden;
    z-index: 1000;
}

body.timeline-hidden #speedGraphContainer {
    bottom: 10px;
}

#speedGraphContainer.small {
    width: 260px;
    height: 110px;
}

#speedGraphContainer.large {
    width: 680px;
    height: 320px;
    min-width: 360px;
    min-height: 180px;
}

#speedGraphResizeHandle {
    position: absolute;
    top: 0;
    left: 0;
    width: 14px;
    height: 14px;
    cursor: nwse-resize;
    border-top: 2px solid rgba(255, 255, 255, 0.8);
    border-left: 2px solid rgba(255, 255, 255, 0.8);
    border-top-left-radius: 2px;
    z-index: 2;
    display: none;
}

#speedGraphContainer.large #speedGraphResizeHandle {
    display: block;
}

#speedGraphSizeToggle {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 1;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: rgba(0, 0, 0, 0.4);
    color: rgba(255, 255, 255, 0.9);
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 0.7rem;
    cursor: pointer;
}

#selectedKartSpeedGraph {
    display: block;
    width: 100%;
    height: 100%;
}

a {
    font-weight: bolder;
    font-size: 1rem;
    pointer-events: auto;
}

#overlayContainer a {
    color: #99e2ff;
    text-decoration: none;
    border-bottom: 1px solid rgba(153, 226, 255, 0.5);
    transition: color 0.18s ease, border-color 0.18s ease, text-shadow 0.18s ease;
}

#overlayContainer a:hover,
#overlayContainer a:focus-visible {
    color: #d6f4ff;
    border-bottom-color: rgba(214, 244, 255, 0.9);
    text-shadow: 0 0 6px rgba(153, 226, 255, 0.35);
}

#debugMenu {
    position: fixed;
    inset: 0;
    z-index: 2300;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: sepia(1) saturate(0.8) brightness(0.65);
    background: rgba(40, 20, 10, 0.35);
}

#debugMenu[hidden] {
    display: none !important;
}

/* The OPTIONS panel and its legend share the window: the rows shrink (and
   scroll) for the legend when it shows, and grow into its room when it
   doesn't. */
#debugPanel {
    display: flex;
    flex-direction: column;
    max-height: calc(var(--ui-dvh) - 24px);
}

#debugPanel > .menu-border,
#debugPanel > .menu-border > .menu-inner {
    display: flex;
    flex-direction: column;
    flex: 0 1 auto;
    min-height: 0;
    max-height: none;
}

#debugPanel .menu-rows {
    flex: 0 1 auto;
    min-height: 0;
    max-height: none;
}

#debugPanel > .menu-legend {
    flex: none;
}

.ctr-menu {
    position: absolute;
    width: max-content;
    min-width: 260px;
    /* No max-width: rows are fixed-size font canvases that can't wrap, so
       DebugMenuController.fitToViewport scales the whole panel down instead
       of letting it clip. */
    max-height: calc(var(--ui-dvh) - 36px);
    font-family: Arial, sans-serif;
    color: white;
}

.menu-border {
    width: fit-content;
    min-width: 100%;
    max-width: 100%;
    border: 2px solid #00ffff;
    border-radius: 4px;
    box-shadow: 16px 16px 0 rgba(0, 0, 0, 0.5);
}

.menu-legend {
    display: flex;
    justify-content: center;
    gap: 14px;
    flex-wrap: wrap;
    margin-top: 12px;
    padding-left: 8px;
    color: rgba(255, 255, 255, 0.78);
    font-size: 0.82rem;
    line-height: 1.35;
    text-align: center;
    text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.7);
}

.menu-legend kbd {
    display: inline-block;
    padding: 1px 5px;
    border: 1px solid rgba(255, 255, 255, 0.36);
    border-radius: 3px;
    background: rgba(0, 0, 0, 0.46);
    color: #f8f8f8;
    font: inherit;
    font-size: 0.9em;
    font-weight: 700;
    text-shadow: none;
}

.menu-inner {
    width: fit-content;
    min-width: 100%;
    max-width: 100%;
    max-height: calc(var(--ui-dvh) - 48px);
    background: rgba(0, 0, 0, 0.7);
    padding: 10px;
    border-radius: 2px;
    box-sizing: border-box;
    overflow: hidden;
}

.menu-title {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    text-align: center;
    font-size: 24px;
    font-weight: bold;
    color: #00ffff;
    margin-bottom: 8px;
}

.menu-title canvas,
.menu-row canvas {
    display: block;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

.title-separator {
    height: 2px;
    background: #00ffff;
    margin: 0 0 10px 0;
}

.menu-rows {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: calc(var(--ui-dvh) - 126px);
    overflow-y: auto;
    width: fit-content;
    min-width: 100%;
}

.menu-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 28px;
    width: 100%;
    min-width: max-content;
    border: 0;
    border-radius: 2px;
    padding: 4px 8px;
    color: white;
    background: transparent;
    font: inherit;
    font-size: 16px;
    text-align: left;
    cursor: pointer;
}

.menu-row strong {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    min-width: 86px;
    min-height: 24px;
    text-align: right;
}

.menu-row .menu-value {
    margin-left: auto;
}

.menu-label {
    min-width: 0;
    min-height: 24px;
    display: flex;
    align-items: center;
    flex: 0 0 auto;
}

/* Options volume slider (DISPLAYRECTMENU_MainFreeze_MenuPtrOptions,
   MainFreeze.c:720-790): a wedge ramping from rgb(0,0,32) to
   rgb(128,128,255) (data.Options_VolumeSlider_Colors), with a 3x10 white
   knob inside a 5x12 black outline. Sizes doubled like the 2x menu font. */
.menu-slider {
    position: relative;
    flex: 0 0 160px;
    width: 160px;
    height: 24px;
    margin-left: auto;
    /* Dragged with the mouse / a finger (DebugMenuController). */
    cursor: pointer;
    touch-action: none;
}

.menu-slider::before {
    content: "";
    position: absolute;
    inset: 2px 0 2px 0;
    background: linear-gradient(to right, rgb(0, 0, 32), rgb(128, 128, 255));
    clip-path: polygon(0 100%, 100% 0, 100% 100%);
}

.menu-slider-knob {
    position: absolute;
    top: 0;
    width: 10px;
    height: 24px;
    box-sizing: border-box;
    background: #fff;
    border: 2px solid #000;
}

/* Fixed-width readout, wide enough for "100%" in the 2x small font, so
   the bar never shifts and the text never runs back over it. */
.menu-slider-row strong.menu-value {
    flex: 0 0 112px;
    width: 112px;
    min-width: 112px;
    margin-left: 0;
}

.menu-category-arrow canvas {
    transform: scaleX(-1);
}

.menu-row strong.is-on {
    color: #bbf7d0;
}

.menu-row strong.is-off {
    color: #ff5757;
}

.menu-row:hover,
.menu-row:focus-visible,
.menu-row.selected {
    outline: none;
    animation: selected-menu-row 0.55s ease-in-out infinite alternate;
}

/* Read-only rows (OPTIONS → Data's sizes) don't light up. */
.menu-row.menu-info:hover {
    animation: none;
}

@keyframes selected-menu-row {
    from {
        background: rgba(255, 0, 0, 0.38);
    }

    to {
        background: rgba(255, 255, 0, 0.38);
    }
}

#raceSetupModal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    /* The panel and its legend share the window: the panel shrinks (and
       scrolls) for the legend when it shows, and grows into its room when
       it doesn't. Top and bottom only: the character select's strip
       runs edge to edge (the panels' widths keep their own side margin). */
    padding: 16px 0;
    box-sizing: border-box;
    /* background: rgba(0, 0, 0, 0.3); */
    color: #f6f6f6;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    /* Clicks never drop a text caret or highlight into the menu. */
    user-select: none;
    -webkit-user-select: none;
    caret-color: transparent;
}

#raceSetupPanel {
    position: relative;
    width: min(760px, calc(var(--ui-vw) - 30px));
    min-height: 320px;
    max-height: 100%;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid #00ffff;
    border-radius: 4px;
    padding: 18px;
    box-sizing: border-box;
    box-shadow: 16px 16px 0 rgba(0, 0, 0, 0.5);
}

.race-setup-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    margin-bottom: 8px;
    text-align: center;
}

.race-setup-brand canvas {
    display: block;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

.race-setup-title-separator {
    height: 2px;
    background: #00ffff;
    margin: 0 0 14px 0;
}

#raceSetupPanel h2 {
    margin-top: 0;
    margin-bottom: 14px;
    font-size: 1.65rem;
    line-height: 1;
}

#raceSetupPanel input[type="text"],
#raceSetupPanel select,
#raceSetupPanel button {
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.06);
    color: #f6f6f6;
    border-radius: 8px;
    padding: 8px 10px;
    font: inherit;
}

#raceSetupPanel input[type="text"]:focus,
#raceSetupPanel select:focus,
#raceSetupPanel button:focus {
    outline: none;
    border-color: #ff8800;
    box-shadow: 0 0 0 2px rgba(255, 136, 0, 0.25);
}

#raceSetupPanel button {
    cursor: pointer;
}

#raceSetupPanel .info-icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    padding: 0;
    border: 0;
    background: transparent;
    color: rgba(255, 255, 255, 0.72);
    font-size: 0.68em;
    line-height: 1;
    vertical-align: middle;
}

#raceSetupPanel .info-icon-button:hover,
#raceSetupPanel .info-icon-button:focus-visible {
    outline: none;
    color: #ffbf40;
    box-shadow: none;
    text-shadow: 0 0 6px rgba(255, 191, 64, 0.65);
}

#raceSetupPanel select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, #d0d0d0 50%), linear-gradient(135deg, #d0d0d0 50%, transparent 50%);
    background-position: calc(100% - 16px) calc(1em + 2px), calc(100% - 11px) calc(1em + 2px);
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
    padding-right: 28px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

#raceSetupPanel select:hover {
    background-color: rgba(255, 255, 255, 0.12);
}

#raceSetupPanel select:active,
#raceSetupPanel select:focus-visible {
    border-color: rgba(34, 197, 94, 0.9);
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.25);
    background-color: rgba(255, 255, 255, 0.14);
}

#raceSetupPanel select option {
    background: #161616;
    color: #f6f6f6;
}

/* Options the game mode can't use (Relic Race on a track with no time
   crates): dimmed and struck through, still listed in place. */
#raceSetupPanel select option:disabled {
    background: #101010;
    color: #5f5f5f;
    font-style: italic;
    text-decoration: line-through;
}

/* Level select subtitles ("Official tracks", "projectsaphi.com tracks"):
   the <optgroup> labels, unselectable. Dark like the options, in the
   panel's amber accent so they read as headings. */
#raceSetupPanel select optgroup {
    background: #0c0c0c;
    color: #ffbf40;
    font-style: normal;
    font-weight: 700;
}

#raceSetupPanel select optgroup.level-group-saphi {
    color: #22d3ee;
}

.race-setup-level-picker {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
}

.race-setup-level-picker select {
    width: 100%;
    min-width: 0;
}

#raceSetupPanel .level-step-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    padding: 0;
    color: #ffbf40;
}

#raceSetupPanel .level-step-button:hover:not(:disabled),
#raceSetupPanel .level-step-button:focus-visible:not(:disabled) {
    border-color: #ff8800;
    background: rgba(255, 136, 0, 0.16);
}

#raceSetupPanel .level-step-button:disabled {
    cursor: wait;
    opacity: 0.35;
}

.race-setup-mode-container {
    display: flex;
    flex-direction: column;
    gap: 0;
    margin-bottom: 14px;
}

/* Horizontal segmented control */
.race-setup-mode-switch {
    display: flex;
    flex-direction: row;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 12px;
}

.race-setup-mode-option {
    flex: 1;
    padding: 5px 8px;
    text-align: center;
    cursor: pointer;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: rgba(255, 255, 255, 0.45);
    background: rgba(0, 0, 0, 0.24);
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.15s ease;
    user-select: none;
}

.race-setup-mode-option:last-child {
    border-right: none;
}

.race-setup-mode-option.active {
    background: rgba(0, 255, 255, 0.15);
    color: #00ffff;
}

.race-setup-mode-option:not(.active):hover {
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.8);
}

#raceSetupStep2 {
    display: none;
}

.race-setup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.race-setup-header h2 {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0;
}

.race-setup-kicker {
    margin: 0 0 6px 0;
    color: #ffbf40;
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.race-setup-summary {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
    margin-bottom: 14px;
}

.race-setup-summary>div,
.race-setup-section {
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.24);
}

.race-setup-summary>div {
    padding: 10px 12px;
}

.race-setup-summary span,
.race-setup-field span {
    display: block;
    margin-bottom: 5px;
    color: rgba(255, 255, 255, 0.62);
    font-size: 0.74rem;
    font-weight: 700;
    text-transform: uppercase;
}

.race-setup-summary strong {
    color: #f8f8f8;
    font-size: 1rem;
}

.race-setup-summary select {
    width: 100%;
    min-width: 0;
}

.race-setup-section {
    padding: 12px;
    margin-bottom: 12px;
}

.race-setup-info {
    margin: 0 0 12px 0;
    padding: 12px;
    border: 2px solid rgba(250, 204, 21, 0.7);
    border-radius: 6px;
    background: rgba(250, 204, 21, 0.15);
    color: #fef3c7;
    font-size: 0.9rem;
    line-height: 1.4;
}

.race-setup-info strong {
    color: #fbbf24;
    font-size: 0.95rem;
}

.race-setup-field {
    display: grid;
    gap: 6px;
}

.race-setup-field select {
    width: 100%;
}

.race-setup-debug-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    color: rgba(255, 255, 255, 0.62);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    flex-shrink: 0;
    width: 38px;
    height: 20px;
}

.toggle-switch input {
    position: absolute;
    inset: 0;
    margin: 0;
    opacity: 0;
    cursor: pointer;
    z-index: 1;
}

.toggle-switch-track {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.18);
    border: 1px solid rgba(255, 255, 255, 0.32);
    border-radius: 999px;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.toggle-switch-track::before {
    content: '';
    position: absolute;
    top: 1px;
    left: 1px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #f8f8f8;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    transition: transform 0.15s ease;
}

.toggle-switch input:checked + .toggle-switch-track {
    background: rgba(250, 204, 21, 0.75);
    border-color: rgba(250, 204, 21, 0.9);
}

.toggle-switch input:checked + .toggle-switch-track::before {
    transform: translateX(18px);
}

.toggle-switch-sm {
    width: 28px;
    height: 16px;
}

.toggle-switch-sm .toggle-switch-track::before {
    width: 12px;
    height: 12px;
}

.toggle-switch-sm input:checked + .toggle-switch-track::before {
    transform: translateX(12px);
}

/* Character select (CharacterSelectController): a full-width kart strip
   sized to the selected kart, its name between two arrowheads, then the
   engine/stats panel. */
#characterSelect {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
}

#characterSelect[hidden] {
    display: none !important;
}

#characterSelect .ctr-menu {
    position: relative;
}

.cs-strip {
    width: 100%;
    box-sizing: border-box;
}

/* Edge to edge: only the top and bottom cyan borders show. */
.cs-strip .menu-border {
    border-left: 0;
    border-right: 0;
    border-radius: 0;
    box-shadow: 0 16px 0 rgba(0, 0, 0, 0.5);
}

.cs-strip .menu-inner {
    border-radius: 0;
}

.cs-strip .menu-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

/* The strip's title over its own divider, then the karts. */
.cs-title {
    min-height: 40px;
    max-width: 100%;
}

.cs-title canvas {
    max-width: 100%;
    height: auto;
}

.cs-title-separator {
    align-self: stretch;
    margin: 0;
}

.cs-roster {
    display: block;
    width: 100%;
    height: clamp(140px, calc(var(--ui-dvh) * 0.34), 320px);
    cursor: pointer;
}

.cs-name-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    min-height: 40px;
}

.cs-name canvas,
.cs-arrow canvas {
    display: block;
    image-rendering: pixelated;
}

/* Narrow screens: the name shrinks to leave room for the arrows. */
.cs-name {
    min-width: 0;
}

.cs-name canvas {
    max-width: calc(var(--ui-vw) - 140px);
    height: auto;
}

.cs-arrow {
    display: flex;
    align-items: center;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: pointer;
}

.cs-arrow-left canvas {
    transform: scaleX(-1);
}

.cs-stats {
    transform-origin: top center;
}

.cs-stats .menu-row strong {
    min-width: 0;
}

/* Setup main menu (RaceSetupController): .menu-row rows like the OPTIONS
   menu, with big-font labels, in a panel sized to its rows. */
#raceSetupPanel [hidden] {
    display: none !important;
}

#raceSetupPanel.is-main-menu {
    width: max-content;
    min-width: min(360px, calc(var(--ui-vw) - 30px));
    max-width: calc(var(--ui-vw) - 30px);
    min-height: 0;
}

.race-setup-menu {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* Rows are bare: no native button look, no hover/focus/tap highlight. Only
   the .selected row shows the red/yellow pulse (hover moves the selection). */
#raceSetupMainMenu .menu-row,
#raceSetupMainMenu .menu-row:hover,
#raceSetupMainMenu .menu-row:focus,
#raceSetupMainMenu .menu-row:focus-visible,
#raceSetupMainMenu .menu-row:active,
#raceSetupPlayMenu .menu-row,
#raceSetupGhostMenu .menu-row,
#raceSetupPlayMenu .menu-row:hover,
#raceSetupGhostMenu .menu-row:hover,
#raceSetupPlayMenu .menu-row:focus,
#raceSetupGhostMenu .menu-row:focus,
#raceSetupPlayMenu .menu-row:focus-visible,
#raceSetupGhostMenu .menu-row:focus-visible,
#raceSetupPlayMenu .menu-row:active,
#raceSetupGhostMenu .menu-row:active {
    appearance: none;
    -webkit-appearance: none;
    -webkit-tap-highlight-color: transparent;
    justify-content: center;
    min-width: 0;
    min-height: 40px;
    padding: 4px 10px;
    border: 0;
    border-radius: 2px;
    outline: none;
    background: transparent;
    box-shadow: none;
    animation: none;
}

#raceSetupMainMenu .menu-row.selected,
#raceSetupPlayMenu .menu-row.selected,
#raceSetupGhostMenu .menu-row.selected {
    animation: selected-menu-row 0.55s ease-in-out infinite alternate;
}

#raceSetupPanel .menu-row .menu-label {
    min-height: 32px;
}

#raceSetupPanel .menu-row canvas {
    max-width: 100%;
    height: auto;
}

#raceSetupMainMenu .menu-row.is-disabled,
#raceSetupMainMenu .menu-row.is-locked,
#raceSetupPlayMenu .menu-row.is-disabled,
#raceSetupGhostMenu .menu-row.is-disabled {
    cursor: not-allowed;
}

/* Singleplayer page (RaceSetupController): the CTR-style menu in a panel
   sized to it, the title over it with the mouse-only Debug switch on its
   right (Free Roam). */
#raceSetupPanel.is-play-menu {
    width: min(600px, calc(var(--ui-vw) - 30px));
    min-height: 0;
    overflow-x: hidden;
}

/* The Singleplayer / level pages' own title takes the top, in place of
   the brand and release, over the same cyan divider. */
#raceSetupPanel.is-play-menu .race-setup-brand,
#raceSetupPanel.is-play-menu .race-setup-version,
#raceSetupPanel.is-play-menu .race-setup-title-separator,
#raceSetupPanel.is-high-scores .race-setup-brand,
#raceSetupPanel.is-high-scores .race-setup-version,
#raceSetupPanel.is-high-scores .race-setup-title-separator {
    display: none;
}

#raceSetupModeHeader,
.race-setup-level-menu-title {
    padding-bottom: 10px;
    border-bottom: 2px solid #00ffff;
    margin-bottom: 14px;
}

/* Sprite text never wider than the panel (narrow screens). */
#raceSetupPanel .race-setup-brand canvas,
#raceSetupPanel .race-setup-version canvas,
#raceSetupModeTitle canvas {
    max-width: 100%;
    height: auto;
}

#raceSetupModeHeader {
    position: relative;
    justify-content: center;
    min-height: 40px;
}

#raceSetupModeHeader .race-setup-debug-toggle {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
}

/* Level page: the title, then the scrolling track list (the OPTIONS
   menu's cyan scrollbar) with a small orange subtitle per group. */
.race-setup-level-menu-title {
    display: flex;
    justify-content: center;
    min-height: 32px;
}

.race-setup-level-menu-title canvas {
    max-width: 100%;
    height: auto;
}

.race-setup-level-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: min(480px, calc(var(--ui-dvh) - 290px));
    min-height: 160px;
    overflow-y: auto;
    padding-right: 4px;
}

/* The Game mode / Laps lists: a handful of rows, no minimum height. */
.race-setup-option-list {
    min-height: 0;
}

/* The ghost page's saved ghost count and best time, over its list. */
.race-setup-option-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    margin-bottom: 14px;
}

.race-setup-option-info[hidden] {
    display: none;
}

.race-setup-option-info canvas {
    max-width: 100%;
    height: auto;
}

/* The ghosts page's summary above its rows. */
.race-setup-play-menu .race-setup-option-info {
    margin: 4px 0 10px;
}

/* "Saved ghosts:" and its value side by side. */
.race-setup-option-pair {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* The Ghosts list's portraits in one row, centered (scrolling on its own,
   RaceSetupController's marquee, when they don't fit). */
.race-setup-ghost-carousel {
    display: flex;
    justify-content: safe center;
    gap: 10px;
    max-width: 100%;
    overflow-x: hidden;
    padding: 4px 2px 12px;
}

.race-setup-ghost-carousel[hidden] {
    display: none;
}

.race-setup-ghost {
    flex: 0 0 auto;
    transition: opacity 120ms linear;
}

/* Square, like the old ghost portraits (a 43 × 25 icon stretched). */
.race-setup-ghost-portrait {
    display: block;
    width: 56px;
    height: 56px;
    image-rendering: pixelated;
}

/* Left out by the highlighted choice. */
.race-setup-ghost.is-ghost-hidden {
    opacity: 0.3;
}

.race-setup-level-group {
    display: flex;
    justify-content: center;
    padding: 10px 0 4px;
    border-bottom: 1px solid rgba(0, 255, 255, 0.35);
    margin-bottom: 2px;
}

.race-setup-level-group:first-child {
    padding-top: 2px;
}

#raceSetupLevelList .menu-row,
#raceSetupLevelList .menu-row:hover,
#raceSetupOptionList .menu-row,
#raceSetupOptionList .menu-row:hover {
    box-sizing: border-box;
    flex: none;
    justify-content: center;
    min-width: 0;
    min-height: 28px;
    padding: 2px 10px;
    border-radius: 2px;
    background: transparent;
    animation: none;
}

/* A Time Attack row's N. Tropy / N. Oxide stars at its right
   (MM_TrackSelect.c:1083-1104), each as tall as the row's selection box;
   a locked one gray and see-through. The name keeps the row's left space
   and centers in what's left of the stars. */
#raceSetupLevelList .menu-row {
    position: relative;
}

/* A row's gray track number, left-justified at its left edge; the name
   keeps centering in the rest of the row. The column is as wide as the
   longest listed number: --level-number-chars glyphs of the small font at
   2× (22px each), set by RaceSetupController.renderLevelRows. */
#raceSetupLevelList .race-setup-level-row,
#raceSetupLevelList .race-setup-level-row:hover {
    padding-left: calc(10px + var(--level-number-chars, 3) * 22px + 8px);
}

.race-setup-level-number {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 10px;
    display: flex;
    align-items: center;
    pointer-events: none;
}

#raceSetupLevelList .menu-row.has-stars {
    padding-right: 84px;
}

/* A Relic Race row's three relic previews (RaceSetupController
   RELIC_PREVIEW_TYPES), as tall as the row, like the stars. */
#raceSetupLevelList .menu-row.has-relics {
    padding-right: 104px;
}

/* Each relic steps through its type's sprite sheet (relicSpinSheets.js):
   RELIC_SPIN_FRAMES (64) frames in a row, the locked copy (pre-grayed, no
   filter) in the second row. steps(64) up to 64/63 lands frame k on
   k / 63 of the sheet; the duration and phase are set inline. */
.race-setup-level-relic {
    display: block;
    aspect-ratio: 1;
    background-repeat: no-repeat;
    background-size: 6400% 200%;
    background-position: 0% 0%;
    image-rendering: auto;
    animation-name: race-setup-relic-spin;
    animation-timing-function: steps(64);
    animation-iteration-count: infinite;
}

/* A Relic Race track without relic times: a gray "-" in the sapphire's and
   the gold's slots (each a relic's width), the platinum relic after them. */
#raceSetupLevelList .race-setup-level-relics-none {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    aspect-ratio: 1;
}

#raceSetupLevelList .race-setup-level-relic {
    height: 100%;
}

.race-setup-level-relic.is-locked {
    background-position-y: 100%;
}

/* Relic Race, under the Level row: the track's sapphire / gold / platinum
   relics in a row, each over the time it takes (RaceSetupController
   renderRelicGoals). */
/* Three equal columns: the same spots whatever the times' widths. */
.race-setup-relic-goals {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    padding: 4px 0 8px;
}

.race-setup-relic-goals[hidden] {
    display: none;
}

/* Crystal Challenge: the arena's one CTR token, centered. */
.race-setup-relic-goals.is-single {
    grid-template-columns: 1fr;
}

.race-setup-relic-goal {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-width: 0;
}

.race-setup-relic-goal .race-setup-level-relic,
.race-setup-relic-goal-none {
    width: 44px;
    height: 44px;
}

.race-setup-relic-goal-none {
    display: flex;
    align-items: center;
    justify-content: center;
}

.race-setup-relic-goal-time {
    display: flex;
    justify-content: center;
    min-height: 16px;
}

.race-setup-relic-goal canvas {
    display: block;
    image-rendering: pixelated;
}

@keyframes race-setup-relic-spin {
    from { background-position-x: 0%; }
    to { background-position-x: calc(100% * 64 / 63); }
}

@media (prefers-reduced-motion: reduce) {
    .race-setup-level-relic {
        animation: none;
    }
}

.race-setup-level-stars {
    position: absolute;
    top: 0;
    right: 6px;
    bottom: 0;
    display: flex;
    gap: 4px;
    align-items: stretch;
    pointer-events: none;
}

.race-setup-level-stars[hidden] {
    display: none;
}

#raceSetupLevelList .race-setup-level-star {
    display: block;
    width: auto;
    height: 100%;
    max-width: none;
    image-rendering: pixelated;
}

#raceSetupLevelList .race-setup-level-star.is-locked {
    filter: grayscale(1);
    opacity: 0.3;
}

/* Long custom track names shrink to the row. */
#raceSetupLevelList .menu-row .menu-label,
#raceSetupOptionList .menu-row .menu-label {
    display: flex;
    justify-content: center;
    width: 100%;
    min-width: 0;
    min-height: 0;
}

#raceSetupLevelList canvas,
#raceSetupOptionList canvas {
    max-width: 100%;
    height: auto;
}

#raceSetupLevelList .menu-row.selected,
#raceSetupOptionList .menu-row.selected {
    animation: selected-menu-row 0.55s ease-in-out infinite alternate;
}

#raceSetupLevelList .menu-row.is-disabled {
    cursor: not-allowed;
}

/* Narrow (html.ui-narrow, the zoomed GUI's width; uiScale.js): the Debug
   switch goes under the title. :where() keeps the media query's
   specificity. */
:where(html.ui-narrow) #raceSetupModeHeader {
    flex-direction: column;
    gap: 4px;
}

:where(html.ui-narrow) #raceSetupModeHeader .race-setup-debug-toggle {
    position: static;
    transform: none;
}

/* Value rows: the small orange label over ‹ value ›. */
#raceSetupPlayMenu .race-setup-value-row,
#raceSetupGhostMenu .race-setup-value-row {
    box-sizing: border-box;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-height: 64px;
    cursor: pointer;
}

#raceSetupPlayMenu .race-setup-value-row .menu-label,
#raceSetupGhostMenu .race-setup-value-row .menu-label {
    min-height: 0;
}

.race-setup-value {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    max-width: 100%;
    min-width: 0;
}

.race-setup-value .menu-value {
    display: flex;
    justify-content: center;
    min-width: 0;
    min-height: 32px;
    align-items: center;
}

#raceSetupLevelRow.is-switching .menu-value {
    opacity: 0.5;
}

/* The garage arrowheads: only on the selected row, red ⇄ orange at
   arrowColor's rate (8 frames of 30 Hz, half each), the left one mirrored.
   Hidden rows keep their space so the value doesn't shift. */
.race-setup-arrow {
    position: relative;
    display: flex;
    flex: none;
    visibility: hidden;
}

.race-setup-value-row.selected .race-setup-arrow {
    visibility: visible;
}

/* Nothing further that way (the game mode stops at its ends). */
.race-setup-value-row.selected .race-setup-arrow.is-end {
    visibility: hidden;
}

.race-setup-arrow canvas {
    display: block;
    max-width: none;
    image-rendering: pixelated;
}

.race-setup-arrow-left canvas {
    transform: scaleX(-1);
}

.race-setup-arrow .arrow-orange {
    position: absolute;
    inset: 0;
    animation: race-setup-arrow-flash 0.26667s steps(1, end) infinite;
}

@keyframes race-setup-arrow-flash {
    0% {
        opacity: 0;
    }

    50% {
        opacity: 1;
    }
}

.race-setup-warning {
    display: flex;
    justify-content: center;
    min-width: 0;
    padding: 2px 0 4px;
}

/* Shrinks to the panel instead of widening it. */
.race-setup-warning canvas {
    max-width: 100%;
    height: auto;
}

#changelogModal,
#mcsTutorialModal,
#creditsModal {
    position: fixed;
    inset: 0;
    z-index: 2200;
    display: flex;
    /* Panel, then its input legend underneath. */
    flex-direction: column;
    gap: 10px;
    align-items: center;
    justify-content: center;
    /* Panel and legend share the window, like the setup modal's. */
    padding: 16px;
    box-sizing: border-box;
    background: rgba(0, 0, 0, 0.3);
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

#changelogModal[hidden],
#mcsTutorialModal[hidden],
#creditsModal[hidden] {
    display: none !important;
}

#changelogPanel,
#mcsTutorialPanel,
#creditsPanel {
    width: min(760px, calc(var(--ui-vw) - 32px));
    max-height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid #00ffff;
    border-radius: 4px;
    padding: 0;
    color: #f8f8f8;
    font-family: inherit;
    box-shadow: 16px 16px 0 rgba(0, 0, 0, 0.5);
}

#changelogHeader,
#mcsTutorialHeader,
#creditsHeader {
    position: relative;
    flex: 0 0 auto;
    padding: 12px 12px 10px 12px;
    background: transparent;
}

#changelogHeader::after,
#mcsTutorialHeader::after,
#creditsHeader::after {
    content: "";
    display: block;
    height: 2px;
    margin-top: 10px;
    background: #00ffff;
}

#changelogBody,
#mcsTutorialBody,
#creditsBody {
    flex: 1 1 auto;
    overflow-y: auto;
    margin: 0 12px 12px 12px;
    padding: 10px 4px 4px 4px;
    scrollbar-width: thin;
    scrollbar-color: rgba(147, 197, 253, 0.55) rgba(255, 255, 255, 0.08);
}

#changelogBody::-webkit-scrollbar,
#creditsBody::-webkit-scrollbar {
    width: 10px;
}

#changelogBody::-webkit-scrollbar-track,
#creditsBody::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 10px;
}

#changelogBody::-webkit-scrollbar-thumb,
#creditsBody::-webkit-scrollbar-thumb {
    background: rgba(147, 197, 253, 0.55);
    border-radius: 10px;
    border: 2px solid rgba(18, 18, 18, 0.94);
}

#changelogBody::-webkit-scrollbar-thumb:hover,
#creditsBody::-webkit-scrollbar-thumb:hover {
    background: rgba(147, 197, 253, 0.75);
}

#changelogPanel h3,
#creditsPanel h3 {
    margin: 0;
}

#mcsTutorialPanel h3 {
    margin: 0;
}

.sprite-panel-title {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
}

.sprite-panel-title canvas {
    display: block;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

#changelogPanel p,
#creditsPanel p {
    margin: 8px 0;
    font-family: inherit;
}

.changelog-day,
.credits-section {
    margin: 12px 0;
    padding: 10px 12px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.04);
}

.changelog-day {
    border-left: 3px solid rgba(255, 191, 64, 0.86);
}

.changelog-development {
    border-left-color: rgba(34, 211, 238, 0.9);
}

.changelog-day>summary {
    cursor: pointer;
    list-style: none;
}

.changelog-day>summary::-webkit-details-marker {
    display: none;
}

.changelog-day>summary:focus-visible {
    border-radius: 4px;
    outline: 2px solid #ffbf40;
    outline-offset: 4px;
}

.changelog-development>summary:focus-visible {
    outline-color: #67e8f9;
}

.changelog-day:not([open])>summary {
    margin-bottom: 0;
}

.changelog-release-head::after {
    flex: 0 0 auto;
    width: 8px;
    height: 8px;
    margin: 4px 3px 0 0;
    border-right: 2px solid #ffbf40;
    border-bottom: 2px solid #ffbf40;
    content: "";
    transform: rotate(45deg);
    transition: transform 120ms ease;
}

.changelog-day[open]>.changelog-release-head::after {
    transform: rotate(225deg);
}

.changelog-development>.changelog-release-head::after {
    display: none;
}

.changelog-development-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.changelog-collapse-icon {
    width: 8px;
    height: 8px;
    border-right: 2px solid #67e8f9;
    border-bottom: 2px solid #67e8f9;
    transform: rotate(45deg);
    transition: transform 120ms ease;
}

.changelog-development[open] .changelog-collapse-icon {
    transform: rotate(225deg);
}

.changelog-day p:first-child {
    margin-top: 0;
}

.changelog-day p:last-child {
    margin-bottom: 0;
}

.changelog-day h4,
.credits-section h4 {
    margin: 0;
    color: #ffbf40;
    font-size: 1rem;
}

.changelog-development h4 {
    color: #67e8f9;
}

.changelog-release-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}

.changelog-meta {
    margin: 3px 0 0 0 !important;
    color: rgba(255, 255, 255, 0.66);
    font-size: 0.82rem;
    line-height: 1.35;
}

.changelog-status {
    flex: 0 0 auto;
    border: 1px solid rgba(34, 197, 94, 0.65);
    border-radius: 999px;
    padding: 3px 8px;
    color: #bbf7d0;
    background: rgba(34, 197, 94, 0.16);
    font-size: 0.7rem;
    font-weight: 800;
    line-height: 1.2;
    text-transform: uppercase;
    white-space: nowrap;
}

.changelog-summary {
    margin: 0 0 10px 0 !important;
    color: rgba(255, 255, 255, 0.88);
    line-height: 1.45;
}

.changelog-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 0 0 10px 0;
}

.changelog-tags span {
    display: inline-flex;
    align-items: center;
    min-height: 20px;
    border: 1px solid rgba(147, 197, 253, 0.32);
    border-radius: 4px;
    padding: 2px 7px;
    color: #bfdbfe;
    background: rgba(147, 197, 253, 0.1);
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1.2;
}

.changelog-development .changelog-tags span {
    border-color: rgba(34, 211, 238, 0.34);
    color: #cffafe;
    background: rgba(34, 211, 238, 0.1);
}

.changelog-groups {
    display: grid;
    gap: 10px;
}

.changelog-group {
    padding-top: 2px;
}

.changelog-group+.changelog-group {
    border-top: 1px solid rgba(255, 255, 255, 0.09);
    padding-top: 10px;
}

.changelog-group h5 {
    margin: 0 0 6px 0;
    color: #d6f4ff;
    font-size: 0.86rem;
    letter-spacing: 0;
}

.changelog-group a {
    color: #93c5fd;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.changelog-group kbd {
    display: inline-block;
    padding: 1px 5px;
    border: 1px solid rgba(255, 255, 255, 0.36);
    border-radius: 3px;
    background: rgba(0, 0, 0, 0.46);
    color: #f8f8f8;
    font: inherit;
    font-size: 0.9em;
    font-weight: 700;
    text-shadow: none;
}

.italics-gray {
    font-style: italic;
    color: rgba(255, 255, 255, 0.66);
}

.file-extension {
    display: inline-block;
    padding: 1px 5px;
    border: 1px solid rgba(255, 255, 255, 0.36);
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.08);
    color: #f8f8f8;
    font: inherit;
    font-size: 0.9em;
    font-weight: 700;
    text-shadow: none;
}

.changelog-conventional {
    --accent: #ffbf40;
    --accent-rgb: 255, 191, 64;

    display: inline-flex;
    align-items: center;
    vertical-align: middle;
    border: 1px solid rgba(var(--accent-rgb), 0.86);
    border-radius: 999px;
    gap: 0.375rem;
    margin: 0 0.35rem 0 0;
    padding: 0.25rem 0.5rem;
    background: rgba(var(--accent-rgb), 0.16);
    color: var(--accent);
    font-size: 0.7rem;
    font-weight: 800;
    line-height: 1.2;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
}

.changelog-conventional.feat {
    --accent: #ffbf40;
    --accent-rgb: 255, 191, 64;
}

.changelog-conventional.fix {
    --accent: #f87171;
    --accent-rgb: 248, 113, 113;
}

.changelog-conventional.refactor {
    --accent: #67e8f9;
    --accent-rgb: 103, 232, 249;
}

.changelog-conventional.temp {
    --accent: #a78bfa;
    --accent-rgb: 167, 139, 250;
}



.credits-section a,
.changelog-summary a {
    color: #93c5fd;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.changelog-summary a {
    font-size: inherit;
}

.credits-section a:hover,
.credits-section a:focus-visible,
.changelog-summary a:hover,
.changelog-summary a:focus-visible {
    color: #bfdbfe;
}

.credits-tech-list {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    margin-top: 10px;
}

.credits-tech-list span {
    display: inline-flex;
    align-items: center;
    min-height: 22px;
    border: 1px solid rgba(255, 191, 64, 0.34);
    border-radius: 4px;
    padding: 2px 8px;
    color: #fef3c7;
    background: rgba(255, 191, 64, 0.1);
    font-size: 0.74rem;
    font-weight: 700;
    line-height: 1.2;
}

.changelog-day ul {
    margin: 0;
    padding-left: 18px;
}

.changelog-day li {
    margin: 6px 0;
    line-height: 1.38;
}

.changelog-todo-list {
    padding-left: 0 !important;
    list-style: none;
}

.changelog-todo-list li {
    position: relative;
    padding-left: 24px;
}

.changelog-todo-list li::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0.16em;
    width: 13px;
    height: 13px;
    border: 1px solid rgba(191, 219, 254, 0.72);
    border-radius: 3px;
    background: rgba(147, 197, 253, 0.08);
    box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.28);
}

.changelog-day code {
    color: #93c5fd;
    background: rgba(147, 197, 253, 0.12);
    border: 1px solid rgba(147, 197, 253, 0.32);
    border-radius: 4px;
    padding: 1px 5px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9em;
    font-weight: 700;
}

#changelogCloseButton,
#mcsTutorialCloseButton,
#creditsCloseButton {
    position: absolute;
    top: 12px;
    right: 14px;
    z-index: 3;
    width: 24px;
    height: 24px;
    padding: 0;
    margin: 0;
    border: 0;
    background: transparent;
    color: rgba(255, 255, 255, 0.72);
    font-size: 1rem;
    font-weight: 800;
    line-height: 1;
    cursor: pointer;
    font-family: inherit;
}

#changelogCloseButton:hover,
#changelogCloseButton:focus-visible,
#mcsTutorialCloseButton:hover,
#mcsTutorialCloseButton:focus-visible,
#creditsCloseButton:hover,
#creditsCloseButton:focus-visible {
    outline: none;
    color: #ff5757;
    text-shadow: 0 0 6px rgba(255, 87, 87, 0.65);
}

.tutorial-step {
    margin: 12px 0;
    padding: 8px 10px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.04);
}

.tutorial-step h4 {
    margin: 0 0 8px 0;
    color: #ffbf40;
    font-size: 1rem;
}

.tutorial-step p {
    margin: 8px 0 10px 0;
}

.tutorial-step a {
    color: #93c5fd;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.tutorial-step a:hover,
.tutorial-step a:focus-visible {
    color: #bfdbfe;
}

.tutorial-step img {
    display: block;
    max-width: 100%;
    height: auto;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 6px;
}

.inline-option {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.race-setup-overlays {
    margin-top: 12px;
    margin-bottom: 10px;
    padding: 10px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.04);
    display: grid;
    gap: 8px;
}

#raceSetupPanel details.race-setup-overlays>summary {
    cursor: pointer;
    list-style: none;
    font-size: 0.95rem;
    font-weight: 600;
}

#raceSetupPanel details.race-setup-overlays>summary::-webkit-details-marker {
    display: none;
}

#raceSetupPanel details.race-setup-overlays>summary::after {
    content: "▾";
    float: right;
    opacity: 0.9;
}

#raceSetupPanel details.race-setup-overlays:not([open])>summary::after {
    content: "▸";
}

#raceSetupPanel details.race-setup-overlays>label {
    margin-top: 6px;
}

.race-setup-file-actions {
    margin-top: 12px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

#raceSetupPanel kbd {
    display: inline-block;
    padding: 0.08em 0.45em;
    color: #f8f8f8;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.32);
    border-radius: 4px;
    box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.45), 0 1px 1px rgba(0, 0, 0, 0.35);
    font-family: inherit;
    font-size: 0.78em;
    font-weight: 700;
    line-height: 1.15;
    white-space: nowrap;
}

#raceSetupNext:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    border-color: rgba(34, 197, 94, 0.28) !important;
    background: rgba(34, 197, 94, 0.08) !important;
    color: rgba(220, 252, 231, 0.55) !important;
    box-shadow: none !important;
    pointer-events: none;
}

.race-setup-actions {
    margin-top: 12px;
    display: flex;
    justify-content: space-between;
}

#raceSetupNext {
    border-color: rgba(34, 197, 94, 0.7) !important;
    color: #dcfce7 !important;
    background: rgba(34, 197, 94, 0.2) !important;
}

#raceSetupNext:hover,
#raceSetupNext:focus-visible {
    border-color: rgba(34, 197, 94, 0.95) !important;
    background: rgba(34, 197, 94, 0.32) !important;
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.25) !important;
}

#raceStartButton {
    border-color: rgba(34, 197, 94, 0.7) !important;
    color: #dcfce7 !important;
    background: rgba(34, 197, 94, 0.2) !important;
}

#raceStartButton:hover,
#raceStartButton:focus-visible {
    border-color: rgba(34, 197, 94, 0.95) !important;
    background: rgba(34, 197, 94, 0.32) !important;
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.25) !important;
}

#raceFloatingCountdown {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 2001;
    display: none;
    pointer-events: none;
    image-rendering: pixelated;
}

#timelineSeekContainer {
    position: absolute;
    left: 10px;
    right: 10px;
    bottom: 10px;
    z-index: 1050;
    display: flex;
    align-items: center;
    padding: 0.25em 0.65em;
    box-sizing: border-box;
    background-color: rgba(17, 17, 17, .5);
    pointer-events: auto;
}

#timelineSeek {
    width: 100%;
    margin: 0;
}

#timelineSeekLabel {
    position: absolute;
    left: 50%;
    bottom: calc(100% + 5px);
    transform: translateX(-50%);
    width: max-content;
    padding: 0.3em 0.55em;
    box-sizing: border-box;
    color: #ffffff;
    background-color: rgba(17, 17, 17, .65);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 0.8rem;
    opacity: 0.9;
    text-align: center;
    white-space: nowrap;
    pointer-events: none;
}

/* Race HUD (features/overlays/hud/HudOverlay.js): native's 512×240 HUD as
   a right-anchored 4:3 box, a HUD pixel the menus' font pixel (--hud-px),
   at most as tall as the window. Each layer is a
   body-level fixed canvas (a shared wrapper would form its own stacking
   context and the additive layer would blend with nothing). */
.hud-layer {
    position: fixed;
    right: 0;
    bottom: 0;
    height: min(100vh, 75vw, calc(var(--hud-px) * 240));
    aspect-ratio: 4 / 3;
    pointer-events: none;
    z-index: 950;
}

.hud-layer[hidden] {
    display: none;
}

/* OnlineCTR's widescreen HUD (USE_16BY9): the same 512×240 over 16:9. */
.hud-layer.hud-wide {
    height: min(100vh, 56.25vw, calc(var(--hud-px) * 240));
    aspect-ratio: 16 / 9;
}

/* HUD elements pinned to the screen whatever its shape: the race clock
   (top-left corner), the lap count (top-right corner), the traffic lights
   (top, centered across) and "FINAL LAP!" / "WRONG WAY" (centered both
   ways). On a window taller than the HUD box they stay put instead of
   following the bottom-anchored box. */
.hud-layer.hud-top-left {
    top: 0;
    bottom: auto;
    left: 0;
    right: auto;
}

.hud-layer.hud-top-right {
    top: 0;
    bottom: auto;
}

.hud-layer.hud-top-centered {
    top: 0;
    bottom: auto;
    right: auto;
    left: 50%;
    transform: translateX(-50%);
}

/* The results' "PRESS A BUTTON TO CONTINUE" (RaceHud's prompt part):
   centered across, its bottom as far from the screen's as the results
   panel's top is from the top (RaceEndController, 10 of 240 rows). */
.hud-layer.hud-bottom-centered {
    bottom: calc(100vh * 10 / 240);
    right: auto;
    left: 50%;
    transform: translateX(-50%);
}

/* HudOverlay fullScreen: the canvases cover the window; the HUD box is
   an unseen element anchored like the layer (its classes), the drawing
   offset to it — what flies past the box's edges stays in view. */
.hud-layer.hud-full-screen {
    top: 0;
    left: 0;
    right: auto;
    bottom: auto;
    width: 100vw;
    height: 100vh;
    aspect-ratio: auto;
    transform: none;
}

.hud-layer.hud-box {
    visibility: hidden;
}

.hud-layer.hud-centered {
    top: 50%;
    bottom: auto;
    right: auto;
    left: 50%;
    transform: translate(-50%, -50%);
}

/* Semi-transparent B+F primitives (tpage ABR 1): added onto the 3D frame. */
.hud-additive {
    mix-blend-mode: plus-lighter;
}

/* Display-only rows under a setting (the Engine stats): not a cursor stop.
   Divs, not buttons, so border-box is set to match the button rows. */
.menu-row.menu-info {
    box-sizing: border-box;
    cursor: default;
    padding-left: 24px;
}

.menu-stat-bar {
    flex: 0 0 auto;
    margin-left: auto;
}

/* The Gameplay page's width is pinned: its Engine value changes length as
   the engine cycles, which re-sized the whole panel. Wide enough for the
   longest value, "ENGINE  CHARACTER". */
.menu-rows[data-path="gameplay"] {
    width: 600px;
}

/* OPTIONS → Data's lists (DataMenu.js): wide enough that a track's name
   and its value ("3 LAPS - 2 GHOSTS", "PRESS AGAIN TO DELETE") keep a gap
   (the zoomed GUI's px: --ui-vw). */
.menu-rows[data-path^="data"] {
    min-width: min(800px, calc(var(--ui-vw) - 60px));
}

.menu-rows[data-path^="data"] .menu-row {
    gap: 24px;
}

/* Pre-release notice at the top of the changelog and credits modals; the
   same amber callout as the setup modal's .race-setup-info. */
.modal-notice {
    margin: 0 0 12px 0;
    padding: 10px 12px;
    border: 2px solid rgba(250, 204, 21, 0.7);
    border-radius: 6px;
    background: rgba(250, 204, 21, 0.15);
    color: #fef3c7;
    font-size: 0.9rem;
    line-height: 1.4;
}

.modal-notice strong {
    color: #fbbf24;
}

.modal-notice a {
    color: #93c5fd;
    font-size: inherit;
}

/* Small viewports (phones, portrait or landscape). */
.race-setup-brand canvas {
    max-width: 100%;
    height: auto;
}

#overlayContainer {
    max-width: calc(100vw - 20px);
    box-sizing: border-box;
}

/* The debug text overlay isn't zoomed: the window's own size. */
@media (max-width: 720px), (max-height: 520px) {
    #overlayContainer {
        left: 6px;
        bottom: 6px;
        font-size: clamp(0.62rem, min(2.6vw, 3.4vh), 1rem);
    }
}

/* Compact / short (html.ui-compact / ui-short): the zoomed GUI's size in
   its own px (uiScale.js), so a scaled-down phone screen doesn't shrink
   the menus twice. :where() keeps the media queries' specificity. */
:where(html.ui-compact) #raceSetupPanel {
    width: calc(var(--ui-vw) - 16px);
    min-height: 0;
    padding: 12px;
    box-shadow: 8px 8px 0 rgba(0, 0, 0, 0.5);
}

:where(html.ui-compact) #raceSetupPanel h2 {
    font-size: 1.35rem;
}

:where(html.ui-compact) .race-setup-header {
    flex-wrap: wrap;
    gap: 8px 12px;
    margin-bottom: 12px;
}

:where(html.ui-compact) #changelogPanel,
:where(html.ui-compact) #mcsTutorialPanel,
:where(html.ui-compact) #creditsPanel {
    width: calc(var(--ui-vw) - 16px);
    box-shadow: 8px 8px 0 rgba(0, 0, 0, 0.5);
}

:where(html.ui-compact) #raceSetupModal {
    padding: 8px 0;
}

:where(html.ui-compact) #changelogModal,
:where(html.ui-compact) #mcsTutorialModal,
:where(html.ui-compact) #creditsModal {
    padding: 8px;
}

:where(html.ui-compact) #changelogBody,
:where(html.ui-compact) #mcsTutorialBody,
:where(html.ui-compact) #creditsBody {
    margin: 0 8px 8px 8px;
}

:where(html.ui-compact) .menu-legend {
    gap: 6px 10px;
    font-size: 0.72rem;
}

:where(html.ui-short) #raceSetupModal {
    gap: 4px;
}

:where(html.ui-short) .race-setup-brand {
    min-height: 0;
    margin-bottom: 4px;
}

:where(html.ui-short) .race-setup-title-separator {
    margin-bottom: 8px;
}

/* CursorAutoHide: driving with the mouse still. */
body.cursor-hidden,
body.cursor-hidden * {
    cursor: none !important;
}

/* RaceEndController: the end-of-race menu (menu224), centered across the
   bottom of the screen (bottom set inline). */
.race-end-menu {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
}

.race-end-menu[hidden] {
    display: none;
}

.race-end-menu .menu-row {
    justify-content: center;
    cursor: pointer;
    /* width: 100% + padding stayed inside the panel (it overflowed right). */
    box-sizing: border-box;
}

/* MenuErrorPopup: native's full-width error box (border + solid black,
   wider than the screen so its sides are off it), over every menu. */
.menu-error-popup {
    position: fixed;
    left: -4px;
    right: -4px;
    z-index: 3200;
    border: 2px solid #00ffff;
    background: #000000;
    pointer-events: none;
    opacity: 1;
    /* MenuErrorPopup FADE_MS. */
    transition: opacity 300ms ease-out;
}

.menu-error-popup.is-fading {
    opacity: 0;
}

/* The online notices: bare text near the top (MenuErrorPopup plain). */
.menu-error-popup.is-plain {
    border: 0;
    background: transparent;
}

.menu-error-popup[hidden] {
    display: none;
}

.menu-error-popup-lines {
    zoom: var(--ui-scale);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 6px 0;
}

.menu-error-popup-line {
    display: flex;
    justify-content: center;
}

/* AudioUnlockOverlay: over everything until the AudioContext runs. */
.audio-unlock-overlay {
    position: fixed;
    inset: 0;
    z-index: 3300;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: rgba(0, 0, 0, 0.75);
    cursor: pointer;
}

.audio-unlock-overlay[hidden] {
    display: none;
}

.audio-unlock-line {
    zoom: var(--ui-scale);
    display: flex;
    justify-content: center;
}

/* Main.showOfflineLock: no server and no downloaded track; centered over
   the loader. */
.offline-lock {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 3100;
    zoom: var(--ui-scale);
}

.offline-lock .menu-inner {
    align-items: center;
}

.offline-lock-line {
    display: flex;
    justify-content: center;
}

/* RaceEndController's results: the ctr-menu panel, no backdrop, centered at
   TT_EndEvent_DisplayTime's place (top set inline). */
.race-results-panel {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
}

.race-results-panel[hidden] {
    display: none;
}

/* The results panels slide down from above the screen each time they show
   (display none → block restarts the animation); not the end menu or the
   "PRESS ✕ TO CONTINUE" prompt. */
.race-results-panel:not([hidden]) {
    animation: race-results-slide-in 0.4s ease-out both;
}

@keyframes race-results-slide-in {
    from { transform: translate(-50%, calc(-100% - 15vh)); }
    to { transform: translate(-50%, 0); }
}

@media (prefers-reduced-motion: reduce) {
    .race-results-panel:not([hidden]) {
        animation: none;
    }
}

/* A Relic Race's clock (RelicResultsView): its rows centered, a row's
   lines side by side. */
.relic-results-panel-rows {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.relic-results-panel-row {
    display: flex;
    align-items: center;
    gap: 16px;
}

.relic-results-panel-row canvas {
    display: block;
    image-rendering: pixelated;
}

.race-results-rows {
    display: grid;
    grid-template-columns: auto auto;
    column-gap: 24px;
    row-gap: 6px;
    align-items: center;
    justify-content: center;
}

.race-results-label {
    justify-self: end;
}

.race-results-total {
    margin-top: 6px;
}

.race-results-flash[hidden] {
    display: none;
}

/* A Crystal Challenge's TIME REMAINING clock (RaceEndController), centered
   under its title. */
.race-results-crystal-time {
    display: flex;
    justify-content: center;
}

.race-results-crystal-time canvas {
    display: block;
    image-rendering: pixelated;
}

.race-results-rows canvas {
    display: block;
    image-rendering: pixelated;
}

/* Two short rows: no scroll container (overflow-y: auto made the rows'
   pulse outline overflow into a horizontal scrollbar). */
.race-end-menu .menu-rows {
    overflow: visible;
    max-height: none;
}

/* The race winner's fade to white (PushBuffer_FadeOneWindow, ABR 1 B+F):
   added onto the 3D view, under the HUD. */
.winner-flash {
    position: fixed;
    inset: 0;
    pointer-events: none;
    mix-blend-mode: plus-lighter;
    z-index: 940;
}

.winner-flash[hidden] {
    display: none;
}

/* A Relic Race's results (RelicResultsView): native's 512 × 240 layout on
   the HUD's 16:9 box, centered on the screen. Lines are sprite-font
   canvases as tall as DecalFont's glyphs (FONT_BIG 15, FONT_SMALL 7 HUD
   units); the panel is the menus' strip, edge to edge of the window
   (RelicResultsView sets only its top and height). */
.relic-results {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    /* The HUD's 16:9 box (.hud-layer.hud-wide). */
    width: min(100vw, calc(100vh * 16 / 9), calc(var(--hud-px) * 240 * 16 / 9));
    aspect-ratio: 16 / 9;
    container-type: size;
    pointer-events: none;
    z-index: 1000;
}

.relic-results[hidden],
.relic-results-line[hidden] {
    display: none;
}

/* The whole window's width (the 512 × 240 HUD box stays centered in it):
   the relic and the crate fly in and out past the box's sides. */
.relic-results-models {
    position: absolute;
    top: 0;
    left: calc(50% - 50vw);
    width: 100vw;
    height: 100%;
}

.relic-results-line {
    position: absolute;
    display: block;
    height: calc(100cqh * 15 / 240);
    white-space: nowrap;
    /* The text fallback until the sprite canvas is in. */
    color: transparent;
    font-size: 0;
    line-height: 0;
}

.relic-results-line.relic-results-line-small {
    height: calc(100cqh * 7 / 240);
}

.relic-results-line canvas {
    display: block;
    height: 100%;
    width: auto;
}

/* OPTIONS → Controls → Gamepad: the live stick display (StickView), to the
   left of the menu panel. */
.menu-stick-view {
    position: absolute;
    right: calc(100% + 16px);
    top: 50%;
    transform: translateY(-50%);
    min-width: 0;
}

.menu-stick-view[hidden] {
    display: none;
}

.menu-stick-view .menu-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.menu-stick-label {
    min-height: 16px;
}

.menu-stick-canvas {
    display: block;
}

/* OPTIONS → Controls → Gamepad: the device row's ‹ name › picker, with the
   garage's arrowheads (the left one mirrored). */
.menu-device {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.menu-device-arrow {
    display: flex;
    align-items: center;
    cursor: pointer;
}

.menu-device-arrow[hidden] {
    display: none;
}

.menu-device-arrow canvas {
    display: block;
    image-rendering: pixelated;
}

.menu-device-arrow-left canvas {
    transform: scaleX(-1);
}

/* The OPTIONS rows' scrollbar (long pages like Controls), in the menus'
   cyan. */
.ctr-menu .menu-rows,
.race-setup-level-list {
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 255, 255, 0.6) rgba(255, 255, 255, 0.06);
}

.ctr-menu .menu-rows::-webkit-scrollbar,
.race-setup-level-list::-webkit-scrollbar {
    width: 10px;
}

.ctr-menu .menu-rows::-webkit-scrollbar-track,
.race-setup-level-list::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.06);
    border-radius: 10px;
}

.ctr-menu .menu-rows::-webkit-scrollbar-thumb,
.race-setup-level-list::-webkit-scrollbar-thumb {
    background: rgba(0, 255, 255, 0.6);
    border-radius: 10px;
    border: 2px solid rgba(0, 0, 0, 0.7);
}

.ctr-menu .menu-rows::-webkit-scrollbar-thumb:hover,
.race-setup-level-list::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 255, 255, 0.85);
}

/* The L2 / R2 bars (StickView), to the right of the menu panel, as big as
   the stick container (StickView sets its size). */
.menu-trigger-view {
    position: absolute;
    left: calc(100% + 16px);
    top: 50%;
    transform: translateY(-50%);
    min-width: 0;
}

.menu-trigger-view[hidden] {
    display: none;
}

.menu-trigger-view .menu-border,
.menu-trigger-view .menu-inner {
    box-sizing: border-box;
    height: 100%;
}

.menu-trigger-row {
    display: flex;
    justify-content: center;
    gap: 16px;
    height: 100%;
}

.menu-trigger-column {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    min-height: 0;
}

.menu-trigger-canvas {
    display: block;
    flex: 1 1 auto;
    min-height: 0;
}

/* `hidden` must win over .menu-legend's display: flex (a legend off its
   page, debugManager.js). */
.menu-legend[hidden] {
    display: none;
}

/* Keyboard hints while the gamepad is the last input (debugManager.js):
   gone, space and all; the menu above takes it. */
.menu-legend.is-input-hidden {
    display: none;
}

/* Main menu: the release under the title, and Changelog / Credits in the
   small font side by side under their own divider. */
.race-setup-version {
    display: flex;
    justify-content: center;
    margin: -2px 0 8px 0;
}

.race-setup-version canvas {
    display: block;
}

.race-setup-menu-separator {
    height: 2px;
    background: #00ffff;
    margin: 6px 0 4px 0;
}

/* The main menu's "Hello, NAME" over LOGOUT (RaceSetupController renderLoginRow). */
.race-setup-hello {
    display: flex;
    justify-content: center;
    min-height: 16px;
}

.race-setup-hello[hidden] {
    display: none;
}

.race-setup-hello canvas {
    display: block;
    max-width: 100%;
    height: auto;
    image-rendering: pixelated;
}

/* The ghosts page's Personal records / Online records headings. */
.race-setup-ghost-section-title {
    display: flex;
    justify-content: center;
    padding: 2px 0 4px;
}

.race-setup-ghost-section-title canvas {
    display: block;
    image-rendering: pixelated;
}

/* INSTALL while the browser offers no install (RaceSetupController syncInstallRow). */
#raceSetupMainMenu .menu-row[hidden] {
    display: none;
}

.race-setup-menu-pair {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
}

#raceSetupMainMenu .menu-row.menu-row-small,
#raceSetupMainMenu .menu-row.menu-row-small:hover,
#raceSetupMainMenu .menu-row.menu-row-small:focus,
#raceSetupPlayMenu .menu-row.menu-row-small,
#raceSetupGhostMenu .menu-row.menu-row-small,
#raceSetupPlayMenu .menu-row.menu-row-small:hover,
#raceSetupGhostMenu .menu-row.menu-row-small:hover,
#raceSetupPlayMenu .menu-row.menu-row-small:focus,
#raceSetupGhostMenu .menu-row.menu-row-small:focus {
    min-height: 30px;
}

#raceSetupPanel .menu-row.menu-row-small .menu-label {
    min-height: 0;
}

/* OPTIONS opened from the main menu: the setup screen's plain dim backdrop,
   not the pause menu's sepia. */
#debugMenu.is-main-menu-options {
    backdrop-filter: none;
    background: rgba(0, 0, 0, 0.0);
}

/* The debug lil-gui's freecam hint (DebugGuiController.setupFreecamHint),
   in lil-gui's own row padding and text color. */
.lil-gui .debug-gui-hint {
    padding: var(--padding) calc(var(--padding) * 2);
    color: var(--text-color);
    font-style: italic;
    opacity: 0.85;
}

/* High scores (main menu, HighScoresView): a wider panel — the game mode /
   laps filters over the tracks with records (name, best) beside the
   selected one's chart of its best time over time and its runs. */
#raceSetupPanel.is-high-scores {
    /* The list's width (HighScoresView buildSizer: the widest track name
       with its arrow, in a list's padding and scrollbar gutter), the
       detail's, the gap and the panel's padding and border. */
    --high-scores-detail-width: 560px;
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    width: min(calc(var(--high-scores-list-width, 400px) + 16px + var(--high-scores-detail-width) + 40px), calc(var(--ui-vw) - 30px));
    min-height: 0;
    overflow: hidden;
}

/* The whole height (the modal's, beside the legend): the track list and
   the runs fill what the filters, title and chart leave, each scrolling. */
#raceSetupPanel.is-high-scores #raceSetupStep1,
#raceSetupHighScores:not([hidden]) {
    display: flex;
    flex: 1 1 0;
    flex-direction: column;
    min-height: 0;
}

/* Scores, Game mode and Laps side by side (a click cycles each). */
.high-scores-filters {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

#raceSetupHighScores .race-setup-value-row {
    box-sizing: border-box;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-height: 56px;
    padding: 4px 16px;
    border: 0;
    background: transparent;
    cursor: pointer;
}

/* Relic Race has no Laps: its slot stays, empty, so Game mode keeps its
   place and width. */
#raceSetupHighScores .race-setup-value-row[hidden] {
    display: flex;
    visibility: hidden;
}

#raceSetupHighScores .race-setup-value-row .menu-label {
    min-height: 0;
}

/* The highlighted filter pulses like the Singleplayer rows. */
#raceSetupHighScores .race-setup-value-row.selected {
    animation: selected-menu-row 0.55s ease-in-out infinite alternate;
}

/* The track shown while a filter has the cursor. */
.high-scores-row.is-current {
    background: rgba(255, 255, 255, 0.08);
}

.high-scores-body {
    display: grid;
    flex: 1 1 0;
    grid-template-columns: minmax(0, var(--high-scores-list-width, 400px)) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    gap: 16px;
    min-height: 0;
    margin-top: 10px;
}

.high-scores-body[hidden],
.high-scores-empty[hidden] {
    display: none;
}

.high-scores-list {
    max-height: none;
    min-height: 0;
    /* The rows keep their width whether or not the list scrolls. */
    scrollbar-gutter: stable;
}

.high-scores-row {
    min-height: 30px !important;
}

/* Every possible track name laid out unseen (HighScoresView buildSizer):
   its width is the list's. */
.high-scores-sizer {
    position: absolute;
    top: 0;
    left: 0;
    width: max-content;
    height: 0;
    min-height: 0;
    overflow: hidden;
    visibility: hidden;
    pointer-events: none;
}

.high-scores-row {
    justify-content: space-between !important;
    gap: 8px;
    /* Room right of the garage arrow, inside the highlight. */
    padding-right: 10px !important;
    /* Its padding inside the list's width (a full-width row). */
    box-sizing: border-box;
}

/* The garage arrow is the keyboard / pad cursor's: not with the mouse. */
html.input-pointer .high-scores-row.selected .high-scores-row-arrow {
    visibility: hidden;
}

.high-scores-row-name {
    min-width: 0;
    max-width: 100%;
}

/* The selected track's garage →: into its runs. */
.high-scores-row.selected .high-scores-row-arrow {
    visibility: visible;
}

.high-scores-detail {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
    min-height: 0;
}

.high-scores-chart {
    position: relative;
    flex: none;
    height: clamp(150px, 32%, 260px);
    padding: 6px;
    border: 1px solid rgba(0, 255, 255, 0.35);
    background: rgba(0, 0, 0, 0.35);
}

.high-scores-runs {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1 1 0;
    min-height: 60px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 255, 255, 0.6) rgba(255, 255, 255, 0.06);
}

.high-scores-run {
    display: grid;
    grid-template-areas: "portrait time gain arrow" "portrait date status arrow";
    grid-template-columns: 32px auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 2px 10px;
    /* Room left of the portrait for the highlighted run's bar. */
    padding: 2px 6px 2px 10px;
}

.high-scores-run-portrait {
    grid-area: portrait;
}

/* The run whose point is hovered on the chart (or hovered here). */
.high-scores-run.is-highlighted {
    background: rgba(255, 200, 0, 0.16);
    box-shadow: inset 3px 0 0 #ffc800;
}

.high-scores-run-time {
    grid-area: time;
}

.high-scores-run-date {
    grid-area: date;
}

.high-scores-run-portrait canvas {
    display: block;
    width: 28px;
    height: 28px;
    image-rendering: pixelated;
}

.high-scores-run-gain {
    grid-area: gain;
    justify-self: end;
}

/* A high score's upload state (PENDING), under its gain. */
.high-scores-run-status {
    grid-area: status;
    justify-self: end;
}

/* A run's garage →: it has a replay (Accept / a click plays it). Always
   shown, flashing on the highlighted run; unseen on a run without one. */
.high-scores-run-arrow {
    grid-area: arrow;
    visibility: visible;
}

.high-scores-run-arrow.is-unplayable {
    visibility: hidden;
}

/* Scores: Online — the player's own run (HighScoresView renderOnlineEntries). */
.high-scores-run.is-me {
    background: rgba(0, 255, 255, 0.10);
}

.high-scores-run.is-me.is-highlighted {
    background: rgba(255, 200, 0, 0.16);
}

.high-scores-runs-message {
    display: flex;
    justify-content: center;
    padding: 12px 0;
}

.high-scores-chart[hidden] {
    display: none;
}

.high-scores-run:not(.is-highlighted) .high-scores-run-arrow .arrow-orange {
    display: none;
}

.high-scores-empty {
    display: flex;
    flex: 1 1 0;
    align-items: center;
    justify-content: center;
    padding: 40px 0;
}

:where(html.ui-compact) .high-scores-body {
    grid-template-columns: 1fr;
}

/* "PLEASE ENTER YOUR NAME" (NameEntryController, SubmitName.c): over the
   menus on startup and from OPTIONS → Data, under the audio unlock
   prompt. */
.name-entry-overlay {
    position: fixed;
    inset: 0;
    z-index: 3250;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.7);
}

.name-entry-overlay[hidden] {
    display: none;
}

.name-entry {
    zoom: var(--ui-scale);
    max-width: calc(var(--ui-vw) / var(--ui-scale) - 20px);
}

.name-entry .menu-inner {
    background: rgba(0, 0, 0, 0.92);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 14px 18px;
}

/* The typed name over its underline (SubmitName's 2-pixel edge rect): a
   click puts the keyboard in the input over it. */
.name-entry-field {
    position: relative;
    display: flex;
    align-items: center;
    min-height: 40px;
    padding: 0 6px 4px;
    border-bottom: 2px solid #00ffff;
    cursor: text;
}

.name-entry-field:focus-within {
    border-bottom-color: #ffc800;
}

.name-entry-text canvas,
.name-entry-face canvas {
    display: block;
    image-rendering: pixelated;
}

/* A long name (up to 32 characters) shrinks to fit the box. */
.name-entry-text {
    min-width: 0;
    max-width: 100%;
}

.name-entry-text canvas {
    max-width: 100%;
    height: auto;
}

.name-entry-input {
    position: absolute;
    inset: 0;
    width: 100%;
    opacity: 0;
    caret-color: transparent;
    border: 0;
    padding: 0;
    font: inherit;
    cursor: text;
}

.name-entry-grid {
    display: grid;
    grid-template-columns: repeat(13, 44px);
    gap: 4px;
    justify-content: center;
}

.name-entry-key {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 0;
    border: 0;
    border-radius: 2px;
    background: transparent;
    cursor: pointer;
}

.name-entry-face-white {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    visibility: hidden;
}

/* The selected key (or button) flashes white every other frame
   (blinkWhite = (typeTimer & 1) << 2). */
.name-entry-key.selected .name-entry-face-white {
    visibility: visible;
    animation: name-entry-blink 0.06667s steps(1, end) infinite;
}

.name-entry-key:hover {
    background: rgba(255, 255, 255, 0.08);
}

@keyframes name-entry-blink {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }
}

.name-entry-actions {
    display: flex;
    justify-content: space-between;
}

.name-entry-action {
    padding: 0 8px;
}

:where(html.ui-compact) .name-entry-grid {
    grid-template-columns: repeat(13, 30px);
}

/* Game data gate (src/gamedata/GameDataGate.js): asks for the player's own
   disc image before the viewer starts — the main menu's ctr-menu panel
   over the RaceFlag. Above the loading overlay, under the audio unlock. */
#gameDataGate {
    position: fixed;
    inset: 0;
    z-index: 3100;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px;
    box-sizing: border-box;
    overflow-y: auto;
    font-family: Roboto, Arial, sans-serif;
    color: #f6f6f6;
    background: #000;
    user-select: none;
    -webkit-user-select: none;
}

#gameDataGate .game-data-flag {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
}

#gameDataGate .game-data-panel {
    position: relative;
    width: min(620px, 100%);
    margin: auto;
}

#gameDataGate .game-data-brand {
    gap: 0.4em;
}

#gameDataGate .menu-inner {
    max-height: none;
    padding: 14px 18px 16px;
    font-size: 0.9rem;
    line-height: 1.45;
}

/* The menu's text without its sprite font (game data, not available yet):
   Roboto, for the gate's text and its audio unlock prompt. */
.game-data-text {
    display: inline-block;
    font-family: Roboto, Arial, sans-serif;
    font-weight: 700;
    font-size: 1.3rem;
    line-height: 1.2;
}

.game-data-text.small {
    font-size: 0.9rem;
    font-weight: 500;
}

.game-data-text.brand {
    font-size: 2rem;
}

.game-data-text.orange {
    color: #ffa31a;
}

.game-data-text.white {
    color: #fff;
}

.game-data-text.blue {
    color: #1aa3ff;
}

#gameDataGate .game-data-heading {
    margin: 2px 0 10px;
    text-align: center;
    font-size: inherit;
}

#gameDataGate h2 {
    margin: 0 0 6px;
    font-size: inherit;
}

#gameDataGate p {
    margin: 0 0 10px;
    opacity: 0.9;
}

#gameDataGate .game-data-notice {
    margin: 12px 0 14px;
    padding: 10px 12px;
    border: 1px solid rgba(0, 255, 255, 0.35);
    border-radius: 2px;
    background: rgba(0, 0, 0, 0.45);
}

#gameDataGate .game-data-notice p:last-child {
    margin-bottom: 0;
}

#gameDataGate code {
    display: block;
    margin: 0 0 10px;
    font-family: ui-monospace, Consolas, monospace;
    font-size: 0.95rem;
    color: #00ffff;
    letter-spacing: 0.02em;
    overflow-wrap: anywhere;
    user-select: all;
    -webkit-user-select: all;
}

#gameDataGate .game-data-drop {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 10px;
    border: 2px dashed transparent;
    border-radius: 2px;
}

#gameDataGate .game-data-drop.over {
    border-color: #00ffff;
    background: rgba(0, 255, 255, 0.08);
}

#gameDataGate .game-data-drop.busy {
    opacity: 0.5;
}

#gameDataGate .game-data-choose {
    justify-content: center;
    width: auto;
    min-width: 0;
    padding: 6px 18px;
}

#gameDataGate .game-data-choose:disabled {
    cursor: default;
    animation: none;
}

#gameDataGate .game-data-status {
    margin-top: 10px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

#gameDataGate .game-data-bar {
    height: 10px;
    margin-top: 8px;
    border: 2px solid #00ffff;
    border-radius: 2px;
    background: rgba(0, 0, 0, 0.6);
    overflow: hidden;
}

#gameDataGate .game-data-bar-fill {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, #e8380d, #ffe066);
    transition: width 0.16s ease;
}

#gameDataGate .game-data-error {
    margin-top: 12px;
    padding: 8px 10px;
    border: 1px solid #ff5757;
    border-radius: 2px;
    color: #ffd0d0;
    background: rgba(120, 0, 0, 0.45);
}

