/* ============================================
   ETHER RESONANCE — DESIGN SYSTEM v2
   Dark-first, one accent, restrained glass.
   Tokens: off-black bg, off-white text, cyan accent.
   ============================================ */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    /* Surfaces — warm off-blacks, no pure #000 */
    --bg: #0A0C10;
    --bg-deep: #07080C;
    --surface: rgba(20, 23, 30, 0.82);
    --surface-solid: #161A22;
    --surface-hover: rgba(30, 34, 44, 0.9);

    /* Text */
    --text: #F5F5F7;
    --text-dim: rgba(245, 245, 247, 0.56);
    --text-faint: rgba(245, 245, 247, 0.34);

    /* Lines */
    --border: rgba(255, 255, 255, 0.07);
    --border-strong: rgba(255, 255, 255, 0.16);

    /* Accent — the ONLY saturated color */
    --accent: #00E5FF;
    --accent-soft: rgba(0, 229, 255, 0.12);
    --accent-text: #04121A;
    --ok: #37F5A0;
    --danger: #FF5C7A;

    /* Type */
    --font-ui: 'Space Grotesk', 'Segoe UI', system-ui, sans-serif;
    --font-mono: 'IBM Plex Mono', 'Consolas', monospace;

    /* Rhythm */
    --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px; --sp-7: 48px;

    --radius: 14px;
    --radius-sm: 8px;
    --shadow-panel: 0 24px 64px rgba(0, 0, 0, 0.45), 0 2px 8px rgba(0, 0, 0, 0.3);
}

html, body {
    overflow: hidden;
    height: 100%;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-ui);
    font-size: 13px;
    -webkit-font-smoothing: antialiased;
}

canvas {
    display: block;
    outline: none;
}

button {
    font-family: inherit;
}

/* ============================================
   PANELS — restrained glass
   ============================================ */
#hud, #controls, #drawing-pad, #guide, #drop-overlay .drop-content {
    background: var(--surface);
    border: 1px solid var(--border);
    backdrop-filter: blur(12px) saturate(140%);
    -webkit-backdrop-filter: blur(12px) saturate(140%);
    box-shadow: var(--shadow-panel);
    border-radius: var(--radius);
}

/* ============================================
   HUD
   ============================================ */
#hud {
    position: absolute;
    top: var(--sp-3);
    right: var(--sp-3);
    width: 264px;
    max-width: calc(100vw - 88px);
    padding: var(--sp-4) var(--sp-4);
    z-index: 100;
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.35s ease;
}

#hud.hidden {
    transform: translateX(360px);
    opacity: 0;
    pointer-events: none;
}

#hud h1 {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 2.5px;
    text-transform: uppercase;
    color: var(--text);
    margin-bottom: var(--sp-3);
    padding-bottom: var(--sp-2);
    border-bottom: 1px solid var(--border);
}

#hud h1 .author {
    font-size: 8px;
    font-weight: 500;
    color: var(--text-faint);
    letter-spacing: 1.2px;
}

#hud .stats {
    font-size: 10px;
}

#hud .stat-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: var(--sp-3);
    padding: 2px 0 3px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

#hud .stat-row:last-child { border-bottom: none; }

#hud .stat-label {
    font-size: 8.5px;
    font-weight: 600;
    letter-spacing: 1.4px;
    text-transform: uppercase;
    color: var(--text-faint);
}

#hud .stat-value {
    font-family: var(--font-mono);
    font-size: 10.5px;
    font-weight: 500;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

#hud .stat-value.accent { color: var(--accent); }

#hud .calibration {
    margin-top: var(--sp-2);
    padding-top: var(--sp-2);
    border-top: 1px solid var(--border);
    font-size: 8px;
    letter-spacing: 1.6px;
    text-transform: uppercase;
    color: var(--text-faint);
}

#hud .credits {
    margin-top: var(--sp-3);
    padding-top: var(--sp-2);
    border-top: 1px solid var(--border);
    font-size: 9px;
    color: var(--text-dim);
}

#hud .credits a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
    letter-spacing: 0.8px;
    font-size: 8.5px;
    text-transform: uppercase;
}

/* ============================================
   TOGGLE BUTTONS (corners)
   ============================================ */
#hud-toggle, #controls-toggle, #drawing-pad-toggle {
    position: fixed;
    z-index: 101;
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-dim);
    font-size: 15px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

#hud-toggle { top: var(--sp-3); right: var(--sp-3); }
#controls-toggle { top: var(--sp-3); left: var(--sp-3); }
#drawing-pad-toggle {
    bottom: var(--sp-3);
    left: 50%;
    transform: translateX(-50%);
}

#hud-toggle:hover, #controls-toggle:hover, #drawing-pad-toggle:hover {
    color: var(--text);
    border-color: var(--border-strong);
    background: var(--surface-hover);
}

#drawing-pad-toggle:active { transform: translateX(-50%) translateY(1px); }

/* ============================================
   VIRTUAL CAMERA JOYSTICK
   ============================================
   Opt-in overlay: hidden until the Joystick checkbox is on. Bottom-left, the
   one corner the control panel (top-left on desktop) and the drawing-pad
   toggle (bottom-centre) both leave free. --joy-bottom is set by place() in
   joystick.js when the mobile bottom sheet covers that corner. */
#joystick {
    position: fixed;
    z-index: 103;
    left: var(--sp-3);
    bottom: var(--joy-bottom, var(--sp-3));
    display: none;
    align-items: center;
    gap: var(--sp-2);
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

#joystick.on {
    display: flex;
}

.joy-base {
    position: relative;
    width: 108px;
    height: 108px;
    border-radius: 50%;
    background: var(--surface);
    border: 1px solid var(--border);
    backdrop-filter: blur(12px) saturate(140%);
    -webkit-backdrop-filter: blur(12px) saturate(140%);
    box-shadow: var(--shadow-panel);
}

.joy-knob {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 46px;
    height: 46px;
    margin: -23px 0 0 -23px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--border-strong);
    transition: background 0.15s ease;
}

#joystick:active .joy-knob {
    background: rgba(122, 162, 247, 0.22);
    border-color: var(--accent);
}

.joy-triggers {
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
}

.joy-trigger {
    flex: none;
    width: 44px;
    height: 44px;
    min-width: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-dim);
    font-size: 17px;
    line-height: 1;
    backdrop-filter: blur(12px) saturate(140%);
    -webkit-backdrop-filter: blur(12px) saturate(140%);
    box-shadow: var(--shadow-panel);
}

.joy-trigger.armed {
    color: var(--text);
    border-color: var(--accent);
    background: rgba(122, 162, 247, 0.18);
}

/* Sensitivity slider: collapsed until the stick is on screen */
.control-row.joy-only {
    display: none;
}

.control-row.joy-only.on {
    display: flex;
}

@media (max-width: 480px) {
    .joy-base { width: 92px; height: 92px; }
    .joy-knob { width: 40px; height: 40px; margin: -20px 0 0 -20px; }
    .joy-trigger { width: 38px; height: 38px; }
}

/* ============================================
   CONTROLS PANEL
   ============================================ */
#controls {
    position: absolute;
    left: var(--sp-3);
    top: calc(var(--sp-3) + 54px);
    bottom: var(--sp-3);
    width: 400px;
    max-height: calc(100vh - 84px);
    padding: var(--sp-5) var(--sp-5);
    z-index: 100;
    overflow-y: auto;
    overflow-x: hidden;
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.35s ease;
}

#controls.hidden {
    transform: translateX(-480px);
    opacity: 0;
    pointer-events: none;
}

#controls h3 {
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: var(--text);
    margin-bottom: var(--sp-4);
    padding-bottom: var(--sp-3);
    border-bottom: 1px solid var(--border);
}

.section { margin-bottom: var(--sp-5); }

#controls h4 {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 2.2px;
    text-transform: uppercase;
    color: var(--text-dim);
    margin: var(--sp-5) 0 var(--sp-3);
    padding-bottom: var(--sp-2);
    border-bottom: 1px solid var(--border);
}

#controls h4::before {
    content: '';
    width: 3px;
    height: 10px;
    border-radius: 2px;
    background: var(--accent);
    opacity: 0.85;
}

/* Rows */
.control-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    margin-bottom: var(--sp-3);
}

/* Moiré bench knobs: collapsed until the 'moire' shape is active */
.control-row.moire-only {
    display: none;
}

.control-row.moire-only.on {
    display: flex;
}

/* Lattice pitch: collapsed outside the grid forms */
.control-row.pitch-only {
    display: none;
}

.control-row.pitch-only.on {
    display: flex;
}

.control-row label {
    font-size: 9.5px;
    font-weight: 600;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--text-dim);
    min-width: 110px;
}

.control-row .value {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 500;
    color: var(--text);
    min-width: 44px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* High particle counts are a deliberate stress knob: flag them in amber so
   the number itself tells you the frame budget is being spent */
.control-row .value.warn {
    color: #ffb347;
}

/* Range inputs */
.control-row input[type="range"] {
    flex: 1;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.1);
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
}

.control-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: var(--text);
    border: none;
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.5);
    transition: all 0.15s;
}

.control-row input[type="range"]::-webkit-slider-thumb:hover {
    background: var(--accent);
    box-shadow: 0 0 10px rgba(0, 229, 255, 0.5);
}

.control-row input[type="range"]:focus-visible::-webkit-slider-thumb {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.control-row input[type="range"]::-moz-range-thumb {
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: var(--text);
    border: none;
}

/* Selects */
.control-row select {
    flex: 1;
    background: var(--surface-solid);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 7px 10px;
    border-radius: var(--radius-sm);
    font-size: 10.5px;
    font-weight: 500;
    cursor: pointer;
    letter-spacing: 0.6px;
    text-transform: uppercase;
    transition: border-color 0.2s;
}

.control-row select:hover { border-color: var(--border-strong); }
.control-row select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.control-row select option {
    background: var(--surface-solid);
    color: var(--text);
}

/* Checkboxes */
.control-row input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
    cursor: pointer;
}

/* ============================================
   BUTTONS — contrast hierarchy:
   ghost (default) / primary (one accent) / danger
   ============================================ */
.btn-row {
    display: flex;
    gap: var(--sp-2);
    flex-wrap: wrap;
    margin-top: var(--sp-2);
}

button {
    flex: 1;
    min-width: 84px;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 9px 12px;
    cursor: pointer;
    font-size: 9.5px;
    font-weight: 600;
    border-radius: var(--radius-sm);
    letter-spacing: 1px;
    text-transform: uppercase;
    transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
}

button:hover {
    color: var(--text);
    border-color: var(--border-strong);
    background: rgba(255, 255, 255, 0.04);
}

button:active { transform: translateY(1px); }

button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

/* Primary — the accent is spent here only */
button.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-text);
    font-weight: 700;
    box-shadow: 0 0 20px rgba(0, 229, 255, 0.22);
}

button.primary:hover {
    background: #4FF0FF;
    border-color: #4FF0FF;
    color: var(--accent-text);
    box-shadow: 0 0 28px rgba(0, 229, 255, 0.35);
}

button.danger {
    border-color: rgba(255, 92, 122, 0.35);
    color: var(--danger);
}

button.danger:hover {
    border-color: var(--danger);
    color: #FF8CA3;
    background: rgba(255, 92, 122, 0.08);
}

button.active {
    background: var(--accent-soft);
    border-color: rgba(0, 229, 255, 0.4);
    color: var(--accent);
}

button:disabled {
    opacity: 0.35;
    pointer-events: none;
}

/* ============================================
   AUDIO PANEL
   ============================================ */
.audio-meter {
    width: 100%;
    height: 5px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: var(--sp-3);
}

.audio-meter-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, rgba(0, 229, 255, 0.55), var(--accent));
    box-shadow: 0 0 14px rgba(0, 229, 255, 0.4);
    transition: width 0.06s linear;
}

.audio-status {
    font-family: var(--font-mono);
    font-size: 9px;
    color: var(--text-faint);
    letter-spacing: 1px;
    text-transform: uppercase;
    margin-top: var(--sp-1);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.audio-status.on { color: var(--ok); }
.audio-status.rec { color: var(--danger); }

/* LIVE CAMERA diagnostic overlay — in-page, eye-testable on device */
.camera-status {
    position: fixed;
    left: 8px;
    bottom: 8px;
    z-index: 99;
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 1px;
    color: var(--ok);
    background: rgba(0, 0, 0, 0.55);
    padding: 3px 8px;
    border-radius: 4px;
    display: none;
    pointer-events: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 90vw;
}

.camera-status.err { color: var(--danger); display: block; }

/* Playback controls (file mode) */
.playback-row {
    display: none;
    gap: var(--sp-2);
    align-items: center;
    margin-top: var(--sp-2);
    padding-top: var(--sp-2);
    border-top: 1px dashed var(--border);
}

.playback-row.visible { display: flex; }

.playback-row button {
    flex: 0 0 auto;
    min-width: 0;
    padding: 8px 12px;
}

.playback-row input[type="range"] {
    flex: 1;
    height: 4px;
    -webkit-appearance: none;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    cursor: pointer;
}

.playback-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--text);
}

/* ============================================
   DRAWING PAD
   ============================================ */
.draw-canvas {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 90;
    touch-action: none;
    cursor: crosshair;
    mix-blend-mode: screen;
    opacity: 0.35;
}

.draw-canvas.hidden { display: none; }

#drawing-pad {
    position: fixed;
    bottom: var(--sp-3);
    left: 50%;
    transform: translateX(-50%);
    padding: var(--sp-4) var(--sp-5);
    z-index: 100;
    display: flex;
    gap: var(--sp-2);
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
    max-width: calc(100vw - 24px);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.35s ease;
}

#drawing-pad.hidden {
    transform: translate(-50%, 120px);
    opacity: 0;
    pointer-events: none;
}

#drawing-pad button {
    min-width: auto;
    padding: 10px 14px;
    font-size: 11px;
}

.draw-brush {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    padding: 0 var(--sp-2);
}

.draw-brush label {
    font-size: 8.5px;
    font-weight: 600;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--text-faint);
}

.draw-brush input[type="range"] {
    width: 80px;
    height: 4px;
    -webkit-appearance: none;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

.draw-brush input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--text);
    cursor: pointer;
}

.draw-brush .value {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-dim);
    min-width: 22px;
    text-align: right;
}

/* ============================================
   DROP OVERLAY
   ============================================ */
#drop-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 500;
    background: rgba(6, 8, 12, 0.65);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

#drop-overlay.active {
    opacity: 1;
    pointer-events: all;
}

#drop-overlay .drop-content {
    border: 2px dashed rgba(0, 229, 255, 0.5);
    padding: var(--sp-7) var(--sp-6);
    font-size: 14px;
    letter-spacing: 4px;
    text-transform: uppercase;
    color: var(--accent);
    border-radius: var(--radius);
}

/* ============================================
   NOTIFICATIONS — stacked toasts
   ============================================ */
.notification {
    position: fixed;
    top: var(--sp-4);
    right: var(--sp-4);
    background: var(--surface-solid);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    color: var(--text);
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    z-index: 10000;
    box-shadow: var(--shadow-panel);
    animation: toastIn 0.25s cubic-bezier(0.4, 0, 0.2, 1), toastOut 0.3s ease 1.9s forwards;
    pointer-events: none;
    max-width: min(360px, calc(100vw - 32px));
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(24px); }
    to { opacity: 1; transform: translateX(0); }
}

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

/* ============================================
   LOADING
   ============================================ */
#loading {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.5s;
}

#loading.hidden {
    opacity: 0;
    pointer-events: none;
}

#loading .brand {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 6px;
    text-transform: uppercase;
    color: var(--text);
    margin-bottom: var(--sp-6);
}

#loading .brand span { color: var(--accent); }

#loading .bar {
    width: 340px;
    height: 3px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: var(--sp-4);
}

#loading .progress {
    height: 100%;
    width: 0%;
    background: var(--accent);
    box-shadow: 0 0 16px rgba(0, 229, 255, 0.4);
    transition: width 0.3s;
}

#loading .status {
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 2.5px;
    text-transform: uppercase;
    color: var(--text-dim);
}

/* ============================================
   CALIBRATION
   ============================================ */
#calibration {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: var(--bg-deep);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s;
}

#calibration.active {
    opacity: 1;
    pointer-events: all;
}

#calibration h2 {
    font-size: 26px;
    font-weight: 700;
    letter-spacing: 8px;
    text-transform: uppercase;
    color: var(--accent);
    margin-bottom: var(--sp-6);
    text-shadow: 0 0 40px rgba(0, 229, 255, 0.45);
}

#calibration .spinner {
    width: 56px;
    height: 56px;
    border: 3px solid rgba(0, 229, 255, 0.15);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

#calibration .status {
    margin-top: var(--sp-5);
    font-family: var(--font-mono);
    font-size: 12px;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: var(--text-dim);
}

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

/* ============================================
   GUIDE
   ============================================ */
#guide {
    position: fixed;
    bottom: 76px;
    left: 50%;
    transform: translateX(-50%);
    padding: var(--sp-4) var(--sp-5);
    z-index: 102;
    min-width: 300px;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

#guide.hidden {
    transform: translateX(-50%) translateY(20px);
    opacity: 0;
    pointer-events: none;
}

#guide h3 {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 3px;
    text-transform: uppercase;
    margin-bottom: var(--sp-3);
    padding-bottom: var(--sp-2);
    border-bottom: 1px solid var(--border);
}

.guide-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--sp-5);
    font-size: 10px;
    color: var(--text-dim);
    padding: 4px 0;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.guide-row span {
    color: var(--accent);
    font-family: var(--font-mono);
    font-weight: 600;
    font-size: 9.5px;
}

/* ============================================
   WEBGL ERROR
   ============================================ */
#webgl-error {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: var(--bg);
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: var(--sp-6);
    gap: var(--sp-3);
}

#webgl-error.visible { display: flex; }

#webgl-error h2 {
    font-size: 15px;
    letter-spacing: 4px;
    text-transform: uppercase;
    color: var(--danger);
}

#webgl-error p {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-dim);
    max-width: 420px;
    line-height: 1.7;
}

/* ============================================
   SCROLLBAR
   ============================================ */
#controls::-webkit-scrollbar { width: 5px; }
#controls::-webkit-scrollbar-track { background: transparent; }
#controls::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.12);
    border-radius: 3px;
}
#controls::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.22); }

/* ============================================
   MOBILE — controls become a bottom sheet
   ============================================ */
@media (max-width: 768px) {
    #controls {
        position: fixed;
        left: 0;
        right: 0;
        top: auto;
        bottom: 0;
        width: 100%;
        max-height: 76vh;
        padding: var(--sp-5) var(--sp-4) calc(var(--sp-5) + 24px);
        border-radius: var(--radius) var(--radius) 0 0;
        border-left: none;
        border-right: none;
        border-bottom: none;
        transform: translateY(110%);
        transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.35s ease;
    }

    #controls.hidden {
        transform: translateY(110%);
        opacity: 0;
        pointer-events: none;
    }

    #controls:not(.hidden) { transform: translateY(0); }

    /* grab handle */
    #controls::before {
        content: '';
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 4px;
        border-radius: 2px;
        background: rgba(255, 255, 255, 0.14);
    }

    #hud {
        top: 60px;
        right: var(--sp-2);
        left: var(--sp-2);
        width: auto;
        max-width: none;
        padding: var(--sp-3) var(--sp-4);
    }

    #hud.hidden { transform: translateY(-340px); }

    #drawing-pad {
        bottom: 14px;
        padding: var(--sp-3) var(--sp-3);
        gap: var(--sp-1);
    }

    #drawing-pad button { padding: 8px 10px; font-size: 9px; }

    button, input[type="range"], select { min-height: 40px; }

    #controls h3 { font-size: 12px; }

    .control-row label { min-width: 88px; font-size: 8.5px; }

    body { touch-action: none; }

    #loading .bar { width: 240px; }

    #calibration h2 { font-size: 20px; letter-spacing: 5px; }
}

@media (max-width: 480px) {
    #hud { padding: var(--sp-2) var(--sp-3); }
    #hud h1 .author { display: none; }
    #guide {
        min-width: 0;
        width: calc(100vw - 32px);
        bottom: 64px;
        padding: var(--sp-4);
    }
}

/* ============================================
   ACCESSIBILITY — reduced motion
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}