/* ============================================================
   HARMONIC LABORATORY — Cosmic / Neon / Scientific Theme
   ============================================================ */

/* ---------- RESET & BASE ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    /* Cosmic palette */
    --bg-void:      #06060f;
    --bg-deep:      #0a0a1a;
    --bg-panel:     #0d0d20;
    --bg-surface:   #111128;
    --bg-elevated:  #161638;
    --border-dim:   #1a1a3e;
    --border-glow:  #2a2a5e;

    /* Neon accents */
    --neon-cyan:    #00f5ff;
    --neon-magenta: #ff00ff;
    --neon-amber:   #ffaa00;
    --neon-green:   #00ff88;
    --neon-red:     #ff3355;
    --neon-blue:    #3388ff;
    --neon-purple:  #aa44ff;

    /* Chromatic note hue (set dynamically by viz engine) */
    --active-root-hue: 180;
    --note-hue-0:  0;    /* C  */
    --note-hue-1:  30;   /* C# */
    --note-hue-2:  60;   /* D  */
    --note-hue-3:  90;   /* D# */
    --note-hue-4:  120;  /* E  */
    --note-hue-5:  150;  /* F  */
    --note-hue-6:  180;  /* F# */
    --note-hue-7:  210;  /* G  */
    --note-hue-8:  240;  /* G# */
    --note-hue-9:  270;  /* A  */
    --note-hue-10: 300;  /* A# */
    --note-hue-11: 330;  /* B  */

    /* Scientific text */
    --text-primary:   #e0e0f0;
    --text-secondary: #8888aa;
    --text-dim:       #555570;
    --text-label:     #6666aa;

    /* Glow intensities */
    --glow-soft:   0 0 10px;
    --glow-medium: 0 0 20px;
    --glow-strong: 0 0 40px;

    /* Glass */
    --glass-bg:     rgba(13, 13, 32, 0.85);
    --glass-border: rgba(100, 100, 200, 0.15);
    --glass-blur:   12px;

    /* Spacing */
    --sidebar-w: 280px;
    --header-h:  52px;
    --bottom-h:  84px;
    --panel-gap:  6px;
    --panel-radius: 8px;

    /* Fonts */
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
}

html, body {
    height: 100%;
    overflow: hidden;
    background: var(--bg-void);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 13px;
    line-height: 1.4;
}

/* Background dot grid overlay */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background-image: radial-gradient(circle, rgba(100,100,200,0.04) 1px, transparent 1px);
    background-size: 24px 24px;
    pointer-events: none;
    z-index: 0;
}

/* ---------- SCROLLBAR ---------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: rgba(10, 10, 30, 0.3); }
::-webkit-scrollbar-thumb { background: rgba(100, 100, 200, 0.25); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0, 245, 255, 0.4); }
::-webkit-scrollbar-thumb:active { background: var(--neon-cyan); }

/* ---------- LAYOUT SHELL ---------- */
.app-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: relative;
    z-index: 1;
}

/* Header */
.app-header {
    height: var(--header-h);
    background: var(--glass-bg);
    -webkit-backdrop-filter: blur(var(--glass-blur));
    backdrop-filter: blur(var(--glass-blur));
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    flex-shrink: 0;
    z-index: 100;
}

.app-header .logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.app-header .logo-icon {
    width: 28px;
    height: 28px;
    color: var(--neon-cyan);
    filter: drop-shadow(var(--glow-soft) var(--neon-cyan));
}

.app-header .logo-text h1 {
    font-size: 15px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--neon-cyan), var(--neon-purple));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: 0.05em;
}

.app-header .logo-text small {
    font-size: 9px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Main body */
.app-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ---------- SIDEBAR ---------- */
.sidebar {
    width: var(--sidebar-w);
    min-height: 0;
    background: var(--glass-bg);
    -webkit-backdrop-filter: blur(var(--glass-blur));
    backdrop-filter: blur(var(--glass-blur));
    border-right: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    flex-shrink: 0;
    z-index: 50;
    overscroll-behavior: contain;
    padding-bottom: 24px;
}

.sidebar-right {
    width: 420px;
    min-width: 200px;
    min-height: 0;
    max-width: 60vw;
    background: var(--glass-bg);
    -webkit-backdrop-filter: blur(var(--glass-blur));
    backdrop-filter: blur(var(--glass-blur));
    border-left: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    flex-shrink: 0;
    z-index: 50;
    transition: width 0.25s ease;
    overscroll-behavior: contain;
}
.sidebar-right.resizing {
    transition: none;
}

/* ── Sidebar Resize Handle ── */
.sidebar-resize-handle {
    width: 5px;
    cursor: col-resize;
    background: transparent;
    position: relative;
    flex-shrink: 0;
    z-index: 60;
    transition: background 0.15s;
}
.sidebar-resize-handle::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 1px;
    transform: translateY(-50%);
    width: 3px;
    height: 40px;
    border-radius: 2px;
    background: var(--border-glow);
    opacity: 0;
    transition: opacity 0.2s;
}
.sidebar-resize-handle:hover,
.sidebar-resize-handle.dragging {
    background: rgba(0, 245, 255, 0.08);
}
.sidebar-resize-handle:hover::after,
.sidebar-resize-handle.dragging::after {
    opacity: 1;
    background: var(--neon-cyan);
    box-shadow: 0 0 6px var(--neon-cyan);
}

/* ── Sidebar Toolbar ── */
.sidebar-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    background: rgba(10, 10, 30, 0.6);
    border-bottom: 1px solid var(--border-dim);
    flex-shrink: 0;
}
.sidebar-toolbar-title {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-label);
}
.view-mode-group {
    display: flex;
    gap: 2px;
}
.view-mode-btn {
    background: transparent;
    border: 1px solid var(--border-dim);
    color: var(--text-dim);
    font-family: var(--font-mono);
    font-size: 9px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.15s;
    line-height: 1.2;
}
.view-mode-btn:hover {
    border-color: var(--border-glow);
    color: var(--text-secondary);
}
.view-mode-btn.active {
    border-color: var(--neon-cyan);
    color: var(--neon-cyan);
    background: rgba(0, 245, 255, 0.08);
}

/* ── Panel Focus Mode (double-click header to expand) ── */
.analysis-panel.focused .analysis-panel-body {
    height: auto !important;
    flex: 1;
}
.analysis-panel.focused {
    flex: 1;
    display: flex;
    flex-direction: column;
}
.sidebar-right.has-focused .analysis-panel:not(.focused) {
    display: none;
}
.analysis-panel-header {
    position: relative;
}
.analysis-panel-header .panel-focus-hint {
    display: none;
    font-size: 7px;
    color: var(--text-dim);
    margin-left: 6px;
}
.analysis-panel-header:hover .panel-focus-hint {
    display: inline;
}

.sidebar-section {
    border-bottom: 1px solid var(--border-dim);
    overflow: hidden;
    flex-shrink: 0;
}

.sidebar-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
    transition: background 0.2s;
}

.sidebar-section-header:hover {
    background: rgba(100, 100, 200, 0.05);
}

.sidebar-section-header:active {
    background: rgba(100, 100, 200, 0.08);
}

/* Scroll shadow hints */
.sidebar::after {
    content: '';
    position: sticky;
    bottom: 0;
    left: 0;
    right: 0;
    height: 24px;
    background: linear-gradient(transparent, rgba(6, 6, 15, 0.8));
    pointer-events: none;
    flex-shrink: 0;
    margin-top: -24px;
}

.sidebar-section-title {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-label);
    display: flex;
    align-items: center;
    gap: 6px;
}

.sidebar-section-title .icon {
    font-size: 11px;
}

.sidebar-section-chevron {
    font-size: 10px;
    color: var(--text-dim);
    transition: transform 0.25s, color 0.2s;
}

.sidebar-section-header:hover .sidebar-section-chevron {
    color: var(--text-secondary);
}

.sidebar-section.collapsed .sidebar-section-chevron {
    transform: rotate(-90deg);
}

.sidebar-section.collapsed .sidebar-section-header {
    opacity: 0.7;
}

.sidebar-section.collapsed .sidebar-section-body {
    display: none;
}

.sidebar-section-body {
    padding: 0 12px 10px 12px;
}

/* ---------- CENTER AREA ---------- */
.center-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
    background: var(--bg-void);
}

.center-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

/* 3D canvas container */
.viz-3d-container {
    flex: 2.5;
    position: relative;
    min-height: 180px;
    border-bottom: 1px solid var(--border-dim);
    background: radial-gradient(
        ellipse at 50% 50%,
        hsla(var(--active-root-hue), 40%, 8%, 0.3) 0%,
        var(--bg-void) 70%
    );
    transition: background 0.8s ease;
}

.viz-3d-container canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

/* Quality toggle */
.btn-quality {
    position: absolute;
    top: 6px;
    right: 6px;
    z-index: 10;
    background: rgba(13, 13, 32, 0.7);
    border: 1px solid rgba(100, 100, 200, 0.2);
    color: var(--text-secondary);
    font: 700 8px/1 monospace;
    letter-spacing: 0.08em;
    padding: 3px 7px;
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
}
.btn-quality:hover {
    background: rgba(20, 20, 60, 0.8);
    border-color: hsla(var(--active-root-hue), 60%, 50%, 0.4);
    color: var(--text-primary);
}

/* Spectrogram container */
.viz-spectrogram-container {
    flex: 2;
    position: relative;
    min-height: 90px;
}

.viz-spectrogram-container canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* ---------- RIGHT PANELS ---------- */
.analysis-panel {
    border-bottom: 1px solid var(--border-dim);
    position: relative;
    border-left: 2px solid hsla(var(--active-root-hue), 60%, 40%, 0.15);
    transition: border-left-color 0.6s ease;
}

.analysis-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    background: rgba(20, 20, 50, 0.5);
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
}

.analysis-panel-title {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-label);
}

.analysis-panel-body {
    height: 140px;
    position: relative;
}

.analysis-panel-body canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.analysis-panel.minimized .analysis-panel-body {
    display: none;
}

/* ---------- BOTTOM BAR ---------- */
.bottom-bar {
    height: var(--bottom-h);
    background: var(--glass-bg);
    -webkit-backdrop-filter: blur(var(--glass-blur));
    backdrop-filter: blur(var(--glass-blur));
    border-top: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    flex-shrink: 0;
    z-index: 50;
    overflow: hidden;
}

/* Piano keyboard */
.piano-container {
    flex: 1;
    height: 100%;
    display: flex;
    align-items: flex-start;
    padding: 0 6px;
    overflow-x: auto;
    overflow-y: hidden;
    position: relative;
}

.piano-key {
    position: relative;
    cursor: pointer;
    transition: all 0.08s;
    flex-shrink: 0;
}

.piano-key-white {
    width: 22px;
    height: 64px;
    background: linear-gradient(180deg, #ccccdd, #e8e8f0);
    border: 1px solid #999;
    border-radius: 0 0 4px 4px;
    margin-right: 1px;
    z-index: 1;
}

.piano-key-white:hover {
    background: linear-gradient(180deg, #dddde8, #f0f0ff);
}

.piano-key-white.active {
    background: linear-gradient(180deg,
        rgba(0, 245, 255, 0.5),
        rgba(0, 200, 255, 0.3));
    border-color: var(--neon-cyan);
    box-shadow: var(--glow-soft) var(--neon-cyan);
}

.piano-key-white.root-key {
    border-bottom: 2px solid var(--neon-cyan);
    border-top: 2px solid var(--neon-cyan);
}

.piano-key-white.in-scale {
    background: linear-gradient(180deg, #d0d0f0, #b8b8dd);
}

.piano-key-black {
    position: absolute;
    width: 14px;
    height: 40px;
    background: linear-gradient(180deg, #111, #333);
    border: 1px solid #000;
    border-radius: 0 0 3px 3px;
    z-index: 2;
    top: 0;
}

.piano-key-black:hover {
    background: linear-gradient(180deg, #222, #444);
}

.piano-key-black.active {
    background: linear-gradient(180deg,
        rgba(0, 245, 255, 0.6),
        rgba(0, 100, 200, 0.4));
    border-color: var(--neon-cyan);
    box-shadow: var(--glow-soft) var(--neon-cyan);
}

.piano-key-black.in-scale {
    background: linear-gradient(180deg, #2a2a50, #1a1a40);
}

.piano-key-label {
    position: absolute;
    bottom: 3px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 8px;
    font-weight: 700;
    pointer-events: none;
    color: #666680;
    white-space: nowrap;
    line-height: 1;
    text-shadow: 0 0 2px rgba(6, 6, 15, 0.5);
}

.piano-key.active .piano-key-label {
    color: var(--neon-cyan);
    text-shadow: 0 0 4px var(--neon-cyan);
}

/* Black key labels */
.piano-key-black .piano-key-label {
    color: #888;
    font-size: 6px;
    bottom: 2px;
    text-shadow: none;
}
.piano-key-black.active .piano-key-label {
    color: var(--neon-cyan);
    text-shadow: 0 0 4px var(--neon-cyan);
}

.piano-key.pressed {
    filter: brightness(1.4);
    transform: scaleY(0.97);
    transform-origin: top;
}

/* ── MIDI-held highlighting (green glow, distinct from chord cyan) ── */
.piano-key-white.midi-held {
    background: linear-gradient(180deg,
        rgba(0, 255, 136, 0.55),
        rgba(0, 200, 100, 0.35)) !important;
    border-color: var(--neon-green) !important;
    box-shadow: var(--glow-medium) var(--neon-green) !important;
    z-index: 3;
}

.piano-key-black.midi-held {
    background: linear-gradient(180deg,
        rgba(0, 255, 136, 0.7),
        rgba(0, 180, 80, 0.5)) !important;
    border-color: var(--neon-green) !important;
    box-shadow: var(--glow-medium) var(--neon-green) !important;
    z-index: 3;
}

/* Correct note (matches target chord) — brighter green + pulse */
.piano-key.midi-correct {
    animation: correct-pulse 0.6s ease-out;
}
.piano-key-white.midi-correct {
    background: linear-gradient(180deg,
        rgba(0, 255, 136, 0.7),
        rgba(0, 255, 100, 0.5)) !important;
    box-shadow: var(--glow-strong) var(--neon-green) !important;
}
.piano-key-black.midi-correct {
    background: linear-gradient(180deg,
        rgba(0, 255, 136, 0.85),
        rgba(0, 220, 100, 0.65)) !important;
    box-shadow: var(--glow-strong) var(--neon-green) !important;
}

/* Wrong note (not in target chord) — red flash */
.piano-key-white.midi-wrong {
    background: linear-gradient(180deg,
        rgba(255, 51, 85, 0.5),
        rgba(200, 30, 60, 0.3)) !important;
    border-color: var(--neon-red) !important;
    box-shadow: var(--glow-medium) var(--neon-red) !important;
    animation: wrong-flash 0.4s ease-out;
}
.piano-key-black.midi-wrong {
    background: linear-gradient(180deg,
        rgba(255, 51, 85, 0.65),
        rgba(200, 30, 60, 0.45)) !important;
    border-color: var(--neon-red) !important;
    box-shadow: var(--glow-medium) var(--neon-red) !important;
    animation: wrong-flash 0.4s ease-out;
}

@keyframes correct-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(0,255,136,0.7); }
    50%  { box-shadow: 0 0 20px 4px rgba(0,255,136,0.5); }
    100% { box-shadow: var(--glow-strong) var(--neon-green); }
}
@keyframes wrong-flash {
    0%   { filter: brightness(1.8); }
    100% { filter: brightness(1); }
}

/* ── Floating MIDI note label ── */
.midi-note-label {
    position: absolute;
    top: -18px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 8px;
    font-weight: 700;
    font-family: var(--font-mono);
    color: var(--neon-green);
    background: rgba(6, 6, 15, 0.85);
    padding: 1px 4px;
    border-radius: 3px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 10;
    border: 1px solid rgba(0, 255, 136, 0.3);
    animation: label-pop 0.2s ease-out;
}
.midi-wrong .midi-note-label {
    color: var(--neon-red);
    border-color: rgba(255, 51, 85, 0.3);
}

@keyframes label-pop {
    0%   { transform: translateX(-50%) translateY(4px); opacity: 0; }
    100% { transform: translateX(-50%) translateY(0);   opacity: 1; }
}

/* ── Vocal pitch indicator (magenta) ── */
.piano-key-white.vocal-pitch {
    background: linear-gradient(180deg,
        rgba(255, 0, 255, 0.45),
        rgba(200, 0, 200, 0.25)) !important;
    border-color: var(--neon-magenta) !important;
    box-shadow: var(--glow-medium) var(--neon-magenta) !important;
}
.piano-key-black.vocal-pitch {
    background: linear-gradient(180deg,
        rgba(255, 0, 255, 0.6),
        rgba(200, 0, 200, 0.4)) !important;
    border-color: var(--neon-magenta) !important;
    box-shadow: var(--glow-medium) var(--neon-magenta) !important;
}

.vocal-cents {
    position: absolute;
    top: -16px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 7px;
    font-weight: 700;
    font-family: var(--font-mono);
    background: rgba(6, 6, 15, 0.85);
    padding: 1px 3px;
    border-radius: 3px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 10;
    border: 1px solid rgba(255, 0, 255, 0.3);
}

/* ── Chord guide (pulsing indicator on target notes) ── */
.chord-guide {
    position: absolute;
    top: 3px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 6px;
    font-weight: 700;
    font-family: var(--font-mono);
    color: var(--neon-cyan);
    opacity: 0.5;
    pointer-events: none;
    animation: guide-pulse 2s ease-in-out infinite;
    z-index: 5;
    text-align: center;
}
.piano-key-black .chord-guide {
    color: #fff;
    opacity: 0.4;
    font-size: 5px;
}

.chord-guide.matched {
    opacity: 1;
    color: var(--neon-green);
    animation: none;
}
.chord-guide.matched::after {
    content: ' ✓';
}

@keyframes guide-pulse {
    0%, 100% { opacity: 0.35; }
    50%      { opacity: 0.7; }
}

/* ── Now Playing chord display bar ── */
.piano-chord-display {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 24px;
    padding: 4px 16px;
    background: rgba(10, 10, 26, 0.9);
    border-top: 1px solid var(--glass-border);
    border-bottom: 1px solid var(--border-dim);
    flex-shrink: 0;
    z-index: 50;
}
.piano-chord-display.visible {
    display: flex;
}
.npd-section {
    display: flex;
    align-items: center;
    gap: 6px;
}
.npd-label {
    font-size: 8px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-dim);
}
.npd-notes {
    font-size: 12px;
    font-weight: 600;
    font-family: var(--font-mono);
    color: var(--neon-green);
    letter-spacing: 0.03em;
}
.npd-chord {
    font-size: 13px;
    font-weight: 700;
    font-family: var(--font-mono);
    color: var(--neon-cyan);
}
.npd-progress-section {
    min-width: 100px;
}
.npd-progress {
    width: 80px;
    height: 4px;
    background: var(--border-dim);
    border-radius: 2px;
    overflow: hidden;
}
.npd-progress-fill {
    height: 100%;
    width: 0%;
    border-radius: 2px;
    transition: width 0.15s, background 0.3s;
}

/* Interval builder alongside piano */
.interval-builder-bar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 12px;
    height: 100%;
    border-left: 1px solid var(--border-dim);
    flex-shrink: 0;
    overflow-x: auto;
}

/* ---------- BUTTONS ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 6px;
    border: 1px solid var(--border-glow);
    background: var(--bg-surface);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    font-family: var(--font-sans);
}

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

.btn-play {
    background: linear-gradient(135deg, rgba(0,255,136,0.15), rgba(0,200,100,0.1));
    border-color: rgba(0,255,136,0.4);
    color: var(--neon-green);
}

.btn-play:hover {
    background: linear-gradient(135deg, rgba(0,255,136,0.25), rgba(0,200,100,0.15));
    box-shadow: var(--glow-soft) var(--neon-green);
}

.btn-play.active {
    background: linear-gradient(135deg, rgba(255,51,85,0.2), rgba(200,30,60,0.1));
    border-color: rgba(255,51,85,0.5);
    color: var(--neon-red);
    animation: pulse-glow-red 2s ease-in-out infinite;
}

.btn-mic {
    background: linear-gradient(135deg, rgba(0,245,255,0.15), rgba(0,150,200,0.1));
    border-color: rgba(0,245,255,0.4);
    color: var(--neon-cyan);
}

.btn-mic:hover {
    background: linear-gradient(135deg, rgba(0,245,255,0.25), rgba(0,150,200,0.15));
    box-shadow: var(--glow-soft) var(--neon-cyan);
}

.btn-mic.active {
    background: linear-gradient(135deg, rgba(255,0,255,0.2), rgba(200,0,200,0.1));
    border-color: rgba(255,0,255,0.5);
    color: var(--neon-magenta);
    animation: pulse-glow-magenta 1.5s ease-in-out infinite;
}

/* Grid buttons (note select, chord presets, etc.) */
.grid-btn {
    padding: 5px 8px;
    border-radius: 4px;
    border: 1px solid var(--border-dim);
    background: var(--bg-deep);
    color: var(--text-dim);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    text-align: center;
    font-family: var(--font-mono);
}

.grid-btn:hover {
    border-color: var(--border-glow);
    color: var(--text-secondary);
    background: var(--bg-surface);
}

.grid-btn.active {
    background: rgba(0, 245, 255, 0.1);
    border-color: var(--neon-cyan);
    color: var(--neon-cyan);
    box-shadow: inset 0 0 8px rgba(0, 245, 255, 0.1);
}

/* Interval toggle buttons */
.interval-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid var(--border-dim);
    background: var(--bg-deep);
    color: var(--text-dim);
    font-size: 10px;
    cursor: pointer;
    transition: all 0.15s;
    min-width: 40px;
    font-family: var(--font-mono);
}

.interval-btn .label { font-weight: 700; font-size: 11px; }
.interval-btn .ratio { font-size: 8px; opacity: 0.5; }

.interval-btn.active-perfect {
    background: rgba(0, 245, 255, 0.12);
    border-color: var(--neon-cyan);
    color: var(--neon-cyan);
}

.interval-btn.active-consonant {
    background: rgba(0, 255, 136, 0.1);
    border-color: var(--neon-green);
    color: var(--neon-green);
}

.interval-btn.active-dissonant {
    background: rgba(255, 51, 85, 0.1);
    border-color: var(--neon-red);
    color: var(--neon-red);
}

/* Range sliders */
input[type=range] {
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    cursor: pointer;
    width: 100%;
}

input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 3px;
    background: var(--border-glow);
    border-radius: 2px;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 12px;
    width: 12px;
    border-radius: 50%;
    background: var(--neon-cyan);
    margin-top: -4.5px;
    box-shadow: 0 0 6px var(--neon-cyan);
    transition: box-shadow 0.2s;
}

input[type=range]::-webkit-slider-thumb:hover {
    box-shadow: 0 0 12px var(--neon-cyan);
}

input[type=range]::-moz-range-track {
    width: 100%;
    height: 3px;
    background: var(--border-glow);
    border-radius: 2px;
}

input[type=range]::-moz-range-thumb {
    height: 12px;
    width: 12px;
    border-radius: 50%;
    background: var(--neon-cyan);
    border: none;
    box-shadow: 0 0 6px var(--neon-cyan);
}

/* Slider row */
.slider-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 4px 0;
}

.slider-row label {
    font-size: 10px;
    color: var(--text-dim);
    min-width: 48px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.slider-row .value {
    font-size: 10px;
    color: var(--neon-cyan);
    font-family: var(--font-mono);
    min-width: 32px;
    text-align: right;
}

/* ---------- HUD OVERLAY ---------- */
.hud-overlay {
    position: absolute;
    top: 6px;
    left: 8px;
    right: 8px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px 6px;
    z-index: 80;
    pointer-events: none;
}

.hud-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(6,6,15,0.75);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    border: 1px solid var(--glass-border);
    border-radius: 5px;
    padding: 3px 8px;
    min-width: 0;
}

.hud-item .hud-label {
    font-size: 7px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-dim);
    line-height: 1.2;
}

.hud-item .hud-value {
    font-size: 12px;
    font-weight: 700;
    font-family: var(--font-mono);
    color: var(--text-primary);
    white-space: nowrap;
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.hud-item .hud-value.neon-cyan { color: var(--neon-cyan); }
.hud-item .hud-value.neon-magenta { color: var(--neon-magenta); }
.hud-item .hud-value.neon-green { color: var(--neon-green); }
.hud-item .hud-value.neon-amber { color: var(--neon-amber); }

/* ---------- ERROR TOAST ---------- */
.toast {
    position: fixed;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 51, 85, 0.9);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    color: white;
    padding: 8px 20px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    border: 1px solid rgba(255, 100, 120, 0.5);
}

.toast.visible {
    opacity: 1;
    pointer-events: auto;
}

/* ---------- WAVEFORM SELECT ---------- */
.waveform-group {
    display: flex;
    gap: 2px;
    background: var(--bg-deep);
    border-radius: 4px;
    padding: 2px;
    border: 1px solid var(--border-dim);
}

.waveform-btn {
    padding: 3px 8px;
    border-radius: 3px;
    border: none;
    background: transparent;
    color: var(--text-dim);
    font-size: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    font-family: var(--font-mono);
}

.waveform-btn:hover {
    color: var(--text-secondary);
}

.waveform-btn.active {
    background: var(--bg-elevated);
    color: var(--neon-cyan);
    box-shadow: inset 0 0 6px rgba(0, 245, 255, 0.1);
}

/* ---------- SYNTH PRESET BUTTONS ---------- */
.synth-preset-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3px;
}
.synth-preset-cat {
    grid-column: 1 / -1;
    font-size: 9px;
    font-family: var(--font-mono);
    color: var(--text-secondary);
    opacity: 0.55;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 6px 4px 2px;
    border-bottom: 1px solid rgba(255,255,255,0.04);
}
.synth-preset-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 7px;
    border-radius: 4px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-secondary);
    font-size: 10px;
    cursor: pointer;
    transition: all 0.15s;
    text-align: left;
    font-family: var(--font-sans);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.synth-preset-btn:hover {
    background: rgba(100, 100, 200, 0.08);
    color: var(--text-primary);
}
.synth-preset-btn.active {
    background: rgba(0, 200, 255, 0.10);
    border-color: rgba(0, 200, 255, 0.35);
    color: var(--neon-cyan);
}
.synth-preset-osc {
    font-size: 11px;
    opacity: 0.4;
    min-width: 12px;
    text-align: center;
}
.synth-preset-btn.active .synth-preset-osc {
    opacity: 0.8;
}

/* ---------- CHORD PRESET  ---------- */
.chord-preset-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 10px;
    border-radius: 4px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-secondary);
    font-size: 11px;
    cursor: pointer;
    transition: all 0.15s;
    text-align: left;
    font-family: var(--font-sans);
}

.chord-preset-btn:hover {
    background: rgba(100, 100, 200, 0.06);
    color: var(--text-primary);
}

.chord-preset-btn.active {
    background: rgba(170, 68, 255, 0.1);
    border-color: rgba(170, 68, 255, 0.3);
    color: var(--neon-purple);
}

.chord-preset-btn .voices {
    font-size: 9px;
    opacity: 0.4;
    font-family: var(--font-mono);
}

/* ---------- SCALE MODE BUTTONS ---------- */
.scale-btn {
    width: 100%;
    padding: 4px 10px;
    border-radius: 4px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-dim);
    font-size: 11px;
    cursor: pointer;
    transition: all 0.15s;
    text-align: left;
    font-family: var(--font-sans);
}

.scale-btn:hover {
    background: rgba(100, 100, 200, 0.06);
    color: var(--text-secondary);
}

.scale-btn.active {
    background: rgba(255, 170, 0, 0.08);
    border-color: rgba(255, 170, 0, 0.25);
    color: var(--neon-amber);
}

/* ---------- ANIMATIONS ---------- */
@keyframes pulse-glow-red {
    0%, 100% { box-shadow: 0 0 8px rgba(255,51,85,0.3); }
    50%      { box-shadow: 0 0 20px rgba(255,51,85,0.6); }
}

@keyframes pulse-glow-magenta {
    0%, 100% { box-shadow: 0 0 8px rgba(255,0,255,0.3); }
    50%      { box-shadow: 0 0 20px rgba(255,0,255,0.6); }
}

@keyframes pulse-glow-cyan {
    0%, 100% { box-shadow: 0 0 8px rgba(0,245,255,0.2); }
    50%      { box-shadow: 0 0 16px rgba(0,245,255,0.5); }
}

@keyframes energy-pulse {
    0%, 100% { border-color: var(--border-dim); }
    50%      { border-color: var(--border-glow); }
}

/* ---------- TOOLTIP ---------- */
[data-tooltip] {
    position: relative;
}

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-deep);
    color: var(--text-secondary);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 10px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
    border: 1px solid var(--border-glow);
    z-index: 999;
}

[data-tooltip]:hover::after {
    opacity: 1;
}

/* ---------- DELTA RIBBON (bottom-center) ---------- */
.delta-ribbon-container {
    height: 36px;
    background: var(--bg-deep);
    border-top: 1px solid var(--border-dim);
    position: relative;
}

.delta-ribbon-container canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* ── Mobile menu button (hidden on desktop, shown at ≤768px) ── */
.mobile-menu-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: 1px solid var(--border-glow);
    background: var(--bg-surface);
    color: var(--text-secondary);
    font-size: 16px;
    cursor: pointer;
    transition: all 0.15s;
    flex-shrink: 0;
}
.mobile-menu-btn:hover {
    background: var(--bg-elevated);
    border-color: var(--neon-cyan);
    color: var(--text-primary);
}

/* ---------- RESPONSIVE SPA ---------- */

/* ── Medium screens: hide right sidebar ── */
@media (max-width: 1100px) {
    .sidebar-right { display: none; }
    .sidebar-resize-handle { display: none; }
    :root { --sidebar-w: 240px; }
}

/* ── Tablet / small laptop ── */
@media (max-width: 900px) {
    :root {
        --sidebar-w: 220px;
        --header-h: 48px;
        --bottom-h: 72px;
    }

    .app-header .logo-text small { display: none; }
    .app-header .logo-text h1 { font-size: 13px; }

    .header-controls { gap: 8px; flex-wrap: wrap; }
    .waveform-group { order: 10; }
    .vol-wrapper { order: 11; }
    .sensitivity-wrapper { order: 9; }
    .input-mode-group { order: 8; }
}

/* ── Mobile: single-column layout ── */
@media (max-width: 768px) {
    :root {
        --sidebar-w: 0px;
        --header-h: auto;
        --bottom-h: 64px;
    }

    html, body {
        overflow: auto;
        overflow-x: hidden;
    }

    .app-shell {
        height: auto;
        min-height: 100vh;
        min-height: 100dvh;
    }

    /* ── Header: stack vertically ── */
    .app-header {
        height: auto;
        flex-wrap: wrap;
        padding: 8px 12px;
        gap: 8px;
    }

    .app-header .logo { flex-basis: 100%; }
    .app-header .logo-text small { display: none; }
    .app-header .logo-text h1 { font-size: 13px; }

    .header-controls {
        flex-wrap: wrap;
        gap: 6px;
        width: 100%;
        justify-content: flex-start;
    }

    .device-group { flex-shrink: 1; min-width: 0; }
    .device-select { max-width: 80px; }
    .vol-wrapper { margin-left: auto; }

    /* ── Sidebar: slide-out overlay ── */
    .sidebar {
        display: none;
    }

    .sidebar.mobile-open {
        display: flex;
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 280px;
        z-index: 200;
        box-shadow: 4px 0 24px rgba(0,0,0,0.5);
    }

    /* Overlay backdrop */
    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 199;
    }
    .sidebar-backdrop.visible { display: block; }

    /* Menu toggle button */
    .mobile-menu-btn {
        display: inline-flex;
    }

    /* ── Body: stack vertically ── */
    .app-body {
        flex-direction: column;
        overflow: visible;
        flex: none;
    }

    /* ── Center area: fixed heights for mobile ── */
    .center-area {
        flex: none;
        height: auto;
    }

    .center-main {
        flex: none;
        height: auto;
    }

    .viz-3d-container {
        flex: none;
        height: 45vw;
        min-height: 200px;
        max-height: 320px;
    }

    .viz-spectrogram-container {
        flex: none;
        height: 120px;
        min-height: 80px;
    }

    .viz-scope-secondary {
        flex: none;
        height: 90px;
    }

    .delta-ribbon-container {
        height: 28px;
    }

    /* ── HUD: smaller on mobile ── */
    .hud-overlay {
        gap: 4px;
        flex-wrap: wrap;
        justify-content: center;
        max-width: 100%;
        padding: 0 4px;
    }
    .hud-item {
        padding: 2px 6px;
    }
    .hud-item .hud-label { font-size: 7px; }
    .hud-item .hud-value { font-size: 11px; }

    /* ── Bottom bar: slimmer piano ── */
    .bottom-bar {
        height: var(--bottom-h);
        flex-shrink: 0;
    }

    .piano-key-white {
        width: 18px;
        height: 52px;
    }
    .piano-key-black {
        width: 12px;
        height: 34px;
    }

    .interval-builder-bar {
        display: none;
    }

    /* Right sidebar never shows on mobile */
    .sidebar-right { display: none; }
    .sidebar-resize-handle { display: none; }
}

/* ── Very small phones ── */
@media (max-width: 480px) {
    .app-header .logo-icon { display: none; }
    .waveform-group { display: none; }

    .piano-key-white {
        width: 14px;
        height: 44px;
    }
    .piano-key-black {
        width: 10px;
        height: 28px;
    }
    .piano-key-label { font-size: 6px; }
    .sensitivity-wrapper { display: none; }
    .input-mode-group { display: none; }

    .hud-overlay { display: none; }
}

/* --- Utility classes used in audio.html --- */

/* Device group (button + dropdown pair) */
.device-group {
    display: flex;
    align-items: center;
    gap: 0;
    position: relative;
}

.device-select {
    -webkit-appearance: none;
    appearance: none;
    background: rgba(20, 20, 40, 0.6);
    color: var(--text-dim);
    border: 1px solid var(--border-dim);
    border-left: none;
    border-radius: 0 4px 4px 0;
    font-size: 9px;
    font-family: var(--font-mono);
    padding: 4px 16px 4px 6px;
    height: 28px;
    max-width: 120px;
    cursor: pointer;
    outline: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='5'%3E%3Cpath d='M0 0l4 5 4-5z' fill='%23888'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 5px center;
    text-overflow: ellipsis;
}
.device-select:hover {
    border-color: var(--glass-border);
    color: var(--text-primary);
}
.device-select:focus {
    border-color: var(--neon-cyan);
}
.device-select option {
    background: #1a1a2e;
    color: #ccc;
}
.device-group .btn {
    border-radius: 4px 0 0 4px;
}

/* MIDI button */
.btn-midi {
    position: relative;
    font-size: 11px;
    opacity: 0.7;
}
.btn-midi.active {
    opacity: 1;
    border-color: var(--neon-green);
    color: var(--neon-green);
    box-shadow: var(--glow-soft) var(--neon-green);
}
.btn-midi.active::after {
    content: '';
    position: absolute;
    top: 4px;
    right: 4px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--neon-green);
    box-shadow: 0 0 6px var(--neon-green);
}

.vol-wrapper { display: flex; align-items: center; gap: 6px; }
.vol-icon { font-size: 12px; color: #555570; }
.vol-slider { width: 70px; }
.vol-value { font-size: 9px; color: #555570; font-family: var(--font-mono); min-width: 36px; }

/* Sensitivity threshold slider */
.sensitivity-wrapper {
    display: flex;
    align-items: center;
    gap: 4px;
}
.sensitivity-label {
    font-size: 9px;
    font-family: var(--font-mono);
    color: #555570;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}
.sensitivity-slider {
    width: 56px;
    accent-color: var(--neon-magenta);
}
.sensitivity-value {
    font-size: 9px;
    color: #555570;
    font-family: var(--font-mono);
    min-width: 36px;
}

/* Input mode selector (VOC / INST / BAND) */
.input-mode-group {
    display: flex;
    gap: 0;
    border: 1px solid var(--border-dim);
    border-radius: 6px;
    overflow: hidden;
}
.input-mode-btn {
    background: transparent;
    color: var(--text-dim);
    border: none;
    padding: 3px 8px;
    font-size: 9px;
    font-family: var(--font-mono);
    font-weight: 700;
    letter-spacing: 0.8px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    text-transform: uppercase;
}
.input-mode-btn:not(:last-child) {
    border-right: 1px solid var(--border-dim);
}
.input-mode-btn:hover {
    background: rgba(255,255,255,0.05);
    color: var(--text-secondary);
}
/* Active state: magenta for VOC, amber for INST, cyan for BAND */
.input-mode-btn.active[data-mode="vocal"] {
    background: var(--neon-magenta);
    color: #0a0a12;
}
.input-mode-btn.active[data-mode="instrument"] {
    background: #f0a030;
    color: #0a0a12;
}
.input-mode-btn.active[data-mode="band"] {
    background: var(--neon-cyan);
    color: #0a0a12;
}
.list-col { display: flex; flex-direction: column; gap: 1px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 3px; }
.list-col-gap3 { display: flex; flex-direction: column; gap: 3px; }
.viz-scope-secondary { flex: 1.5; border-top: 1px solid var(--border-dim); }
.panel-chevron-sm { font-size: 8px; color: var(--text-dim); }
.panel-h160 { height: 200px; transition: height 0.25s ease; }
.panel-h180 { height: 220px; transition: height 0.25s ease; }
.panel-h120 { height: 160px; transition: height 0.25s ease; }
.panel-h200 { height: 240px; transition: height 0.25s ease; }
