/* ==========================================================================
   APEX LINE — Tactical Motorsport Telemetry & Vector Strategy Engine
   Mobile-First High-Density Responsive Architecture
   ========================================================================== */

:root {
    /* Tactical Dark Palette */
    --bg-app: #090d13;
    --bg-surface: #111620;
    --bg-panel: rgba(17, 22, 32, 0.92);
    --bg-elevated: #1a2230;
    --bg-hover: #222c3d;
    --bg-active: #2b384e;

    --border-subtle: #242f42;
    --border-strong: #3b4d6b;
    --border-focus: #58a6ff;

    /* Semantic Precision Colors */
    --text-primary: #e6edf3;
    --text-secondary: #919eb0;
    --text-muted: #5e6d82;

    --color-gain: #2ea043;
    --color-gain-subtle: rgba(46, 160, 67, 0.15);
    --color-loss: #da3633;
    --color-loss-subtle: rgba(218, 54, 51, 0.15);
    --color-sector: #d29922;
    --color-sector-subtle: rgba(210, 153, 34, 0.15);
    --color-vector: #58a6ff;
    --color-vector-subtle: rgba(88, 166, 255, 0.15);
    --color-neutral: #8b949e;

    /* Typography */
    --font-ui: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-mono: "JetBrains Mono", "SF Mono", "Roboto Mono", "Cascadia Code", Menlo, monospace;

    /* Spacing & Radii */
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 10px;
    --radius-xl: 14px;
    --radius-full: 9999px;

    --header-height: 48px;
    --dock-height: 60px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
}

/* ---- Modern Reset & Touch Optimization ---- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    background-color: var(--bg-app);
    color: var(--text-primary);
    font-family: var(--font-ui);
    font-size: 14px;
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overscroll-behavior: none;
}

body {
    display: flex;
    flex-direction: column;
    padding-top: var(--safe-top);
    padding-left: var(--safe-left);
    padding-right: var(--safe-right);
}

/* ==========================================================================
   APP HEADER
   ========================================================================== */
.app-header {
    height: var(--header-height);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    z-index: 20;
    flex-shrink: 0;
    gap: 8px;
}

/* Brand */
.brand-block {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.brand-title {
    font-family: var(--font-mono);
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: var(--text-primary);
}

.brand-accent {
    color: var(--color-vector);
    font-weight: 400;
}

.brand-badge {
    font-family: var(--font-mono);
    font-size: 0.62rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    padding: 2px 5px;
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
}

/* Track Navigation (Horizontal Swipeable Chips) */
.track-nav {
    display: flex;
    gap: 3px;
    background: var(--bg-app);
    padding: 2px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
}

.track-nav::-webkit-scrollbar {
    display: none;
}

.track-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-secondary);
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    font-family: var(--font-ui);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    scroll-snap-align: center;
    transition: background 0.12s ease, color 0.12s ease;
    touch-action: manipulation;
}

.track-btn:hover {
    color: var(--text-primary);
    background: var(--bg-elevated);
}

.track-btn.active {
    background: var(--bg-elevated);
    border-color: var(--border-strong);
    color: var(--text-primary);
}

.track-idx {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    color: var(--text-muted);
    font-weight: 600;
}

.track-btn.active .track-idx {
    color: var(--color-vector);
}

/* Header Actions */
.header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.btn-header {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    padding: 5px 9px;
    min-height: 32px;
    border-radius: var(--radius-md);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
    touch-action: manipulation;
}

.btn-header.btn-icon-only {
    padding: 5px 7px;
    min-width: 32px;
}

.btn-header:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-strong);
}

.btn-header:active {
    background: var(--bg-active);
}

/* ==========================================================================
   MOBILE-OPTIMIZED TELEMETRY STATUS BAR (< 768px)
   ========================================================================== */
.mobile-telemetry-bar {
    display: none;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    padding: 6px 12px;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    gap: 8px;
    z-index: 15;
}

.m-stat-group {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.m-stat-label {
    font-family: var(--font-mono);
    font-size: 0.58rem;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 0.06em;
}

.m-stat-value {
    font-family: var(--font-mono);
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--text-primary);
}

.m-stat-value small {
    font-size: 0.58rem;
    color: var(--text-muted);
}

.m-stat-status {
    align-items: center;
}

/* ==========================================================================
   SIMULATION VIEWPORT & CANVAS
   ========================================================================== */
.sim-viewport {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    min-height: 0;
}

.canvas-container {
    flex: 1;
    position: relative;
    background: var(--bg-app);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px;
    overflow: hidden;
    touch-action: none;
}

#gameCanvas {
    display: block;
    background: #0d121a;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    max-width: 100%;
    max-height: 100%;
    aspect-ratio: 1200 / 700;
    object-fit: contain;
    touch-action: none;
    cursor: crosshair;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

/* Mobile Quick Helper Hint */
.mobile-touch-hint {
    display: none;
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(17, 22, 32, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-full);
    padding: 3px 12px;
    font-size: 0.65rem;
    color: var(--text-secondary);
    font-family: var(--font-mono);
    pointer-events: none;
    z-index: 12;
    white-space: nowrap;
}

/* ==========================================================================
   PRECISION HUD OVERLAY (Desktop & Tablet mode)
   ========================================================================== */
.hud-overlay {
    position: absolute;
    inset: 12px;
    pointer-events: none;
    z-index: 10;
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto 1fr auto;
    gap: 8px;
}

.hud-panel {
    background: var(--bg-panel);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 8px 12px;
    pointer-events: auto;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

/* Top Left: Sector Timing */
.hud-sectors {
    grid-column: 1;
    grid-row: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 140px;
}

.hud-title {
    font-family: var(--font-mono);
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.sector-grid {
    display: flex;
    gap: 6px;
}

.sector-item {
    display: flex;
    flex-direction: column;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 3px 6px;
    min-width: 44px;
    text-align: center;
}

.sec-tag {
    font-family: var(--font-mono);
    font-size: 0.58rem;
    font-weight: 600;
    color: var(--text-muted);
}

.sec-val {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-primary);
}

.sector-item.gain {
    border-color: var(--color-gain);
    background: var(--color-gain-subtle);
}
.sector-item.gain .sec-val { color: var(--color-gain); }

.sector-item.loss {
    border-color: var(--color-loss);
    background: var(--color-loss-subtle);
}
.sector-item.loss .sec-val { color: var(--color-loss); }

/* Top Center: Main Timing & Status */
.hud-timing {
    grid-column: 2;
    grid-row: 1;
    justify-self: center;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 16px;
}

.hud-timer-wrap {
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.hud-metric-label {
    font-family: var(--font-mono);
    font-size: 0.6rem;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 0.08em;
}

.time-display {
    font-family: var(--font-mono);
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    min-width: 90px;
}

.status-pill {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    padding: 3px 8px;
    border-radius: var(--radius-sm);
    text-transform: uppercase;
    white-space: nowrap;
}

.status-ready {
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
}

.status-simulating {
    background: var(--color-gain-subtle);
    border: 1px solid var(--color-gain);
    color: var(--color-gain);
    animation: pulseSim 1.5s infinite;
}

@keyframes pulseSim {
    0% { box-shadow: 0 0 0 0 rgba(46, 160, 67, 0.4); }
    70% { box-shadow: 0 0 0 6px rgba(46, 160, 67, 0); }
    100% { box-shadow: 0 0 0 0 rgba(46, 160, 67, 0); }
}

.status-finished {
    background: var(--color-sector-subtle);
    border: 1px solid var(--color-sector);
    color: var(--color-sector);
}

.status-crashed {
    background: var(--color-loss-subtle);
    border: 1px solid var(--color-loss);
    color: var(--color-loss);
}

/* Top Right: Reference Benchmarks */
.hud-benchmarks {
    grid-column: 3;
    grid-row: 1;
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 150px;
}

.bench-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    gap: 12px;
}

.bench-label {
    color: var(--text-muted);
    font-size: 0.62rem;
    font-weight: 600;
}

.bench-value {
    font-weight: 600;
    color: var(--text-primary);
}

.bench-value.delta-gain { color: var(--color-gain); }
.bench-value.delta-loss { color: var(--color-loss); }

/* Bottom Left: Vehicle Dynamic Telemetry */
.hud-telemetry {
    grid-column: 1;
    grid-row: 3;
    display: flex;
    gap: 14px;
    align-items: center;
}

.telemetry-unit {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.telemetry-label {
    font-family: var(--font-mono);
    font-size: 0.58rem;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.05em;
}

.telemetry-num-wrap {
    display: flex;
    align-items: baseline;
    gap: 3px;
}

.telemetry-num {
    font-family: var(--font-mono);
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-primary);
}

.telemetry-sub {
    font-family: var(--font-mono);
    font-size: 0.58rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* ==========================================================================
   DOCKED BOTTOM CONTROLS (Thumb-Zone Optimized)
   ========================================================================== */
.controls-dock {
    background: var(--bg-surface);
    border-top: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    padding-bottom: max(8px, var(--safe-bottom));
    gap: 8px;
    z-index: 20;
    flex-shrink: 0;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

.controls-dock::-webkit-scrollbar {
    display: none;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 5px;
    flex-shrink: 0;
}

.control-divider {
    width: 1px;
    height: 22px;
    background: var(--border-subtle);
    margin: 0 3px;
    flex-shrink: 0;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 12px;
    min-height: 38px;
    border-radius: var(--radius-md);
    font-family: var(--font-ui);
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.12s ease;
    touch-action: manipulation;
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    pointer-events: none;
}

.btn-large {
    padding: 10px 18px;
    font-size: 0.88rem;
    min-height: 44px;
}

.btn-primary {
    background: var(--color-vector);
    color: #090d13;
}

.btn-primary:hover {
    background: #79b8ff;
}

.btn-primary:active {
    background: #418de0;
    transform: scale(0.98);
}

.btn-run {
    background: var(--color-gain);
    color: #ffffff;
    padding: 7px 16px;
    min-height: 40px;
    min-width: 110px;
    font-family: var(--font-mono);
    font-weight: 700;
    letter-spacing: 0.04em;
    box-shadow: 0 2px 8px rgba(46, 160, 67, 0.3);
}

.btn-run:hover {
    background: #34b34c;
}

.btn-run:active {
    background: #278c3a;
    transform: scale(0.97);
}

.btn-stop {
    background: var(--color-loss);
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(218, 54, 51, 0.3);
}

.btn-stop:hover {
    background: #ea4a47;
}

.btn-secondary {
    background: var(--bg-elevated);
    border-color: var(--border-subtle);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--bg-hover);
    border-color: var(--border-strong);
}

.btn-secondary:active {
    background: var(--bg-active);
    transform: scale(0.97);
}

.btn-subtle {
    background: transparent;
    color: var(--text-secondary);
}

.btn-subtle:hover {
    color: var(--text-primary);
    background: var(--bg-elevated);
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    min-height: 36px;
    min-width: 36px;
    border-radius: var(--radius-md);
    transition: color 0.12s ease, background 0.12s ease;
    touch-action: manipulation;
}

.btn-icon:hover {
    color: var(--text-primary);
    background: var(--bg-elevated);
}

/* Speed Switcher */
.speed-switcher {
    display: flex;
    background: var(--bg-app);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 2px;
    gap: 2px;
}

.speed-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 0.72rem;
    font-weight: 700;
    padding: 5px 8px;
    min-height: 32px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.12s ease;
    touch-action: manipulation;
}

.speed-btn:hover {
    color: var(--text-primary);
}

.speed-btn.active {
    background: var(--bg-elevated);
    color: var(--color-vector);
}

/* ==========================================================================
   MODALS & RESULTS SUMMARY (Mobile Bottom-Sheet & Desktop Card)
   ========================================================================== */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(5, 8, 12, 0.75);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    padding: 16px;
    opacity: 1;
    transition: opacity 0.2s ease;
}

.modal-backdrop.hidden {
    display: none !important;
}

.summary-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 480px;
    max-height: calc(100dvh - 32px);
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.6);
    animation: modalIn 0.22s cubic-bezier(0.16, 1, 0.3, 1);
    -webkit-overflow-scrolling: touch;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: translateY(16px) scale(0.97);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.summary-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    border-bottom: 1px solid var(--border-subtle);
    padding-bottom: 12px;
}

.summary-kicker {
    font-family: var(--font-mono);
    font-size: 0.62rem;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 0.08em;
}

.summary-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-top: 2px;
}

.summary-badge {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    white-space: nowrap;
}

.summary-badge.record {
    background: var(--color-gain-subtle);
    border: 1px solid var(--color-gain);
    color: var(--color-gain);
}

.summary-badge.slower {
    background: var(--color-loss-subtle);
    border: 1px solid var(--color-loss);
    color: var(--color-loss);
}

.summary-metrics-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.summary-metric {
    background: var(--bg-app);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sm-label {
    font-family: var(--font-mono);
    font-size: 0.58rem;
    font-weight: 600;
    color: var(--text-muted);
}

.sm-value {
    font-family: var(--font-mono);
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
}

.sm-value.highlight {
    color: var(--color-vector);
    font-size: 1.15rem;
}

.sm-value.gain { color: var(--color-gain); }
.sm-value.loss { color: var(--color-loss); }

/* Sector Table Breakdown */
.sector-table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    background: var(--bg-app);
}

.sector-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    text-align: left;
}

.sector-table th {
    background: var(--bg-elevated);
    color: var(--text-muted);
    font-weight: 600;
    padding: 6px 10px;
    border-bottom: 1px solid var(--border-subtle);
}

.sector-table td {
    padding: 7px 10px;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-primary);
}

.sector-table tr:last-child td {
    border-bottom: none;
}

.summary-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 4px;
}

.summary-actions .btn {
    width: 100%;
}

/* ==========================================================================
   PARAMETERS DRAWER (Desktop Sidebar / Mobile Bottom Sheet)
   ========================================================================== */
.parameters-drawer {
    position: fixed;
    top: var(--header-height);
    right: 0;
    bottom: 0;
    width: 340px;
    background: var(--bg-surface);
    border-left: 1px solid var(--border-subtle);
    z-index: 40;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: -8px 0 24px rgba(0, 0, 0, 0.5);
}

.parameters-drawer.open {
    transform: translateX(0);
}

.drawer-drag-handle {
    display: none;
    width: 36px;
    height: 4px;
    background: var(--border-strong);
    border-radius: var(--radius-full);
    margin: 8px auto 2px auto;
    flex-shrink: 0;
}

.drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.drawer-kicker {
    font-family: var(--font-mono);
    font-size: 0.6rem;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 0.08em;
}

.drawer-title-group h3 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
}

.drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    -webkit-overflow-scrolling: touch;
}

.drawer-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.section-title {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    text-transform: uppercase;
}

.toggles-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
}

.param-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.78rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    background: var(--bg-app);
    border: 1px solid var(--border-subtle);
    transition: color 0.12s ease, border-color 0.12s ease;
    touch-action: manipulation;
}

.param-toggle input[type="checkbox"] {
    position: relative;
    width: 18px;
    height: 18px;
    appearance: none;
    -webkit-appearance: none;
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    cursor: pointer;
    flex-shrink: 0;
    outline: none;
    transition: all 0.12s ease;
}

.param-toggle input[type="checkbox"]:checked {
    background: var(--color-vector);
    border-color: var(--color-vector);
}

.param-toggle input[type="checkbox"]:checked::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 5px;
    width: 4px;
    height: 8px;
    border: solid #090d13;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

/* Sliders */
.slider-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: var(--bg-app);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
}

.slider-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
}

.slider-name {
    color: var(--text-secondary);
    font-weight: 500;
}

.slider-value {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.75rem;
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: var(--border-subtle);
    border-radius: var(--radius-full);
    outline: none;
    touch-action: manipulation;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--text-primary);
    border: 2px solid var(--border-strong);
    cursor: pointer;
    transition: background 0.12s ease, transform 0.12s ease;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

input[type="range"]::-webkit-slider-thumb:active {
    background: var(--color-vector);
    transform: scale(1.15);
}

/* Instructions */
.instructions-card {
    background: var(--bg-app);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.instruction-row {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.instruction-key {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--color-vector);
}

.instruction-desc {
    font-size: 0.72rem;
    color: var(--text-muted);
    line-height: 1.3;
}

.drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    z-index: 35;
}

.drawer-backdrop.hidden {
    display: none !important;
}

/* ==========================================================================
   TOAST FEED
   ========================================================================== */
#toast {
    position: absolute;
    bottom: 14px;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    background: var(--bg-surface);
    border: 1px solid var(--border-strong);
    color: var(--text-primary);
    padding: 6px 14px;
    border-radius: var(--radius-md);
    font-family: var(--font-mono);
    font-size: 0.72rem;
    font-weight: 600;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease;
    z-index: 30;
    white-space: nowrap;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

#toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ==========================================================================
   RESPONSIVE ADAPTATIONS & MOBILE TARGET (< 768px)
   ========================================================================== */

/* Tablets & Small Desktops (768px - 960px) */
@media (max-width: 960px) {
    .btn-header-label { display: none; }
    .hud-overlay {
        inset: 8px;
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto auto auto;
    }
    .hud-sectors {
        grid-column: 1;
        grid-row: 1;
    }
    .hud-benchmarks {
        grid-column: 2;
        grid-row: 1;
        justify-self: end;
    }
    .hud-timing {
        grid-column: 1 / span 2;
        grid-row: 2;
        justify-self: center;
        margin-top: 4px;
    }
    .hud-telemetry {
        grid-column: 1 / span 2;
        grid-row: 3;
        justify-self: start;
        align-self: end;
    }
}

/* Mobile Devices (< 768px) — Mobile Target Priority */
@media (max-width: 768px) {
    :root {
        --header-height: 44px;
        --dock-height: 58px;
    }

    .app-header {
        padding: 0 8px;
        gap: 6px;
    }

    .brand-badge { display: none; }
    .brand-title { font-size: 0.85rem; }

    .track-btn {
        padding: 4px 7px;
        font-size: 0.72rem;
    }

    .track-label {
        max-width: 65px;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Activate Mobile Telemetry Bar, Hide Occlusive Overlay */
    .mobile-telemetry-bar {
        display: flex;
    }

    .hud-overlay {
        display: none !important;
    }

    .mobile-touch-hint {
        display: block;
    }

    .canvas-container {
        padding: 4px;
    }

    #gameCanvas {
        border-radius: var(--radius-sm);
    }

    /* Mobile Controls Dock */
    .controls-dock {
        padding: 6px 8px;
        padding-bottom: max(6px, var(--safe-bottom));
        gap: 4px;
        justify-content: space-between;
        width: 100%;
    }

    .btn {
        padding: 6px 8px;
        font-size: 0.72rem;
        gap: 4px;
        min-height: 36px;
    }

    .btn-run {
        min-width: 86px;
        padding: 6px 10px;
    }

    .btn-text {
        display: inline-block;
    }

    .control-divider {
        display: none;
    }

    .speed-btn {
        padding: 4px 6px;
        font-size: 0.68rem;
    }

    /* Parameters Drawer in Bottom-Sheet Mode */
    .parameters-drawer {
        width: 100%;
        height: 78vh;
        height: 78dvh;
        top: auto;
        bottom: 0;
        transform: translateY(100%);
        border-left: none;
        border-top: 1px solid var(--border-strong);
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    }

    .parameters-drawer.open {
        transform: translateY(0);
    }

    .drawer-drag-handle {
        display: block;
    }

    .drawer-header {
        padding: 10px 16px;
    }

    /* Results Summary Card on Mobile */
    .summary-card {
        padding: 16px;
        gap: 12px;
        border-radius: var(--radius-lg);
    }

    .summary-metrics-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Very Small Mobile (< 380px) */
@media (max-width: 380px) {
    .brand-title {
        font-size: 0.78rem;
    }
    .track-btn {
        padding: 3px 5px;
        font-size: 0.68rem;
    }
    .track-label {
        max-width: 50px;
    }
    .btn-text {
        display: none;
    }
    .btn-run .btn-run-text {
        display: inline-block;
    }
}

/* Landscape Mode on Small Screens (Phones in Landscape) */
@media (max-height: 520px) and (orientation: landscape) {
    :root {
        --header-height: 38px;
        --dock-height: 48px;
    }

    .app-header {
        padding: 0 12px;
    }

    .mobile-telemetry-bar {
        display: none;
    }

    .mobile-touch-hint {
        display: none;
    }

    .hud-overlay {
        display: grid !important;
        inset: 4px;
        gap: 4px;
    }

    .hud-panel {
        padding: 3px 6px;
    }

    .time-display {
        font-size: 0.95rem;
    }

    .controls-dock {
        padding: 4px 12px;
        padding-bottom: max(4px, var(--safe-bottom));
        gap: 6px;
    }

    .btn {
        min-height: 32px;
        padding: 4px 8px;
        font-size: 0.7rem;
    }

    .parameters-drawer {
        width: 320px;
        height: auto;
        top: 0;
        bottom: 0;
        border-radius: 0;
        transform: translateX(100%);
    }

    .parameters-drawer.open {
        transform: translateX(0);
    }
}
