:root {
    --bg-color: #0b0c10;
    --panel-bg: rgba(22, 24, 29, 0.7);
    --panel-border: rgba(255, 255, 255, 0.05);
    --accent-cyan: #45f3ff;
    --accent-magenta: #ff2a6d;
    --text-primary: #e0e6ed;
    --text-secondary: #8c9baf;
    --grid-color: rgba(255, 255, 255, 0.1);
    --btn-hover: #1f2229;
    --header-h: 122px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
}

body {
    font-family: "Rajdhani", "Outfit", "Inter", system-ui, -apple-system, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    overflow: hidden;
    width: 100vw;
    height: 100vh;
}

.app-container {
    display: grid;
    grid-template-columns: 220px 1fr 340px;
    grid-template-rows: var(--header-h) 1fr;
    grid-template-areas:
        "header header header"
        "meter main sidebar";
    height: 100%;
    width: 100%;
    transition: grid-template-columns 0.3s cubic-bezier(0.2, 0.8, 0.2, 1),
                grid-template-rows 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.app-container.header-collapsed {
    --header-h: 0px;
}

.app-container.header-collapsed .top-bar {
    padding-top: 0;
    padding-bottom: 0;
    border-bottom: 0;
    box-shadow: none;
    opacity: 0;
    pointer-events: none;
}

.app-container.focus-layout {
    grid-template-columns: 0px 1fr 0px;
}

.app-container.focus-layout.meter-open {
    grid-template-columns: 220px 1fr 0px;
}

.glass-panel {
    background: var(--panel-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--panel-border);
}

/* Header */
.top-bar {
    grid-area: header;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 10px 24px 8px;
    border-bottom: 1px solid var(--panel-border);
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.5);
    z-index: 10;
    overflow: hidden;
}

/* Header toggle tab — sits at the bottom edge of the header */
.header-toggle-tab {
    position: fixed;
    top: var(--header-h);
    left: 50%;
    transform: translateX(-50%);
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 16px 5px;
    background: var(--panel-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--panel-border);
    border-top: none;
    border-radius: 0 0 10px 10px;
    cursor: pointer;
    transition: top 0.3s cubic-bezier(0.2, 0.8, 0.2, 1),
                background 0.2s, opacity 0.2s;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 1.5px;
    color: var(--text-secondary);
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
    user-select: none;
}

.header-toggle-tab:hover {
    background: rgba(69, 243, 255, 0.1);
    color: var(--accent-cyan);
    border-color: rgba(69, 243, 255, 0.25);
}

.header-toggle-tab .tab-chevron {
    font-size: 9px;
    display: inline-block;
    transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
    line-height: 1;
}

.app-container.header-collapsed .header-toggle-tab .tab-chevron {
    transform: rotate(180deg);
}

.logo h1 {
    font-size: 24px;
    font-weight: 800;
    letter-spacing: 2px;
    background: linear-gradient(90deg, var(--accent-cyan), var(--accent-magenta));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo .subtitle {
    font-size: 11px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.logo .logo-version {
    display: inline-block;
    margin-left: 8px;
    padding: 1px 7px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.05em;
    vertical-align: middle;
    background: rgba(69, 243, 255, 0.10);
    color: var(--accent-cyan);
    border: 1px solid rgba(69, 243, 255, 0.32);
    border-radius: 999px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    -webkit-text-fill-color: var(--accent-cyan);
    background-clip: padding-box;
    line-height: 1.4;
    position: relative;
    top: -2px;
}
.logo .logo-version:empty { display: none; }

.audio-controls {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
}

.panel-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 10px;
}

.panel-toggle-btn {
    margin-top: 0;
}

.panel-toggle-btn.is-active {
    background: rgba(69, 243, 255, 0.14);
    border-color: var(--accent-cyan);
    color: #fff;
}

.btn-secondary.monitor-btn {
    font-size: 22px;
    line-height: 1;
    padding: 0 10px;
}

.btn-secondary.monitor-btn.is-active {
    background: rgba(255, 42, 109, 0.18);
    border: 1px solid #ff2a6d;
    color: #fff;
}

.input-selector {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    justify-content: flex-end;
    gap: 12px;
}

.status-message {
    max-width: 100%;
    min-height: 15px;
    font-size: 12px;
    line-height: 1.2;
    color: var(--text-secondary);
    text-align: right;
}

.status-message:empty {
    display: none;
}

.status-message.success {
    color: #00ffaa;
}

.status-message.error {
    color: #ff6b8f;
}

select {
    background: rgba(0, 0, 0, 0.5) url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2214%22%20height%3D%2210%22%20viewBox%3D%220%200%2014%2010%22%3E%3Cpath%20fill%3D%22%238c9baf%22%20d%3D%22M7%2010L0%200h14z%22%2F%3E%3C%2Fsvg%3E") no-repeat right 12px center;
    background-size: 10px;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    color: var(--text-primary);
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 8px 30px 8px 12px;
    border-radius: 4px;
    outline: none;
    font-family: "Rajdhani", "Outfit", "Inter", system-ui, sans-serif;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

select:focus {
    border-color: var(--accent-cyan);
    box-shadow: 0 0 8px rgba(69, 243, 255, 0.3);
}

.btn-primary, .btn-secondary {
    padding: 8px 16px;
    border-radius: 4px;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
}

.btn-primary {
    background: var(--accent-cyan);
    color: #000;
}

.btn-primary.is-connected {
    background: #00ffaa;
}

.btn-primary.is-error {
    background: #ff6b8f;
    color: #fff;
}

.btn-primary:active,
.btn-secondary:active,
.mode-btn:active {
    transform: scale(0.97);
}

.btn-primary:disabled,
.btn-secondary:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    background: transparent;
    border: 1px solid var(--text-secondary);
    color: var(--text-primary);
    width: 100%;
    margin-top: 10px;
}

.btn-inline {
    width: auto;
    margin-top: 0;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.4);
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.1);
}

/* Classic TT / Pinguin Style Meter Panel */
.classic-meter-panel {
    grid-area: meter;
    border-right: 1px solid var(--panel-border);
    background: #08090a;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 15px 15px;
    box-shadow: inset 20px 0 30px rgba(0,0,0,0.5), 10px 0 20px rgba(0,0,0,0.3);
    overflow: hidden;
    white-space: nowrap;
    z-index: 15;
}

.app-container.focus-layout .classic-meter-panel {
    padding: 15px 0;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s, padding 0.3s;
}

.app-container.focus-layout.meter-open .classic-meter-panel {
    opacity: 1;
    visibility: visible;
    padding: 15px 15px;
}

.panel-backdrop {
    position: fixed;
    top: var(--header-h);
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(1, 3, 8, 0.3);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.24s ease, top 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
    z-index: 18;
}

.app-container.focus-layout.controls-open .panel-backdrop {
    opacity: 1;
    pointer-events: auto;
}

.app-container.focus-layout .control-panel {
    position: fixed;
    top: var(--header-h);
    bottom: 0;
    transition: transform 0.28s ease, box-shadow 0.28s ease, top 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* Control Panel animations */

.meter-title {
    width: 90%;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 9px;
    font-size: 11px;
    font-weight: 800;
    color: #a9b4c4;
    letter-spacing: 1px;
}

.meter-title-detail {
    font-size: 7px;
    font-weight: 600;
    color: #4e5a69;
    letter-spacing: 0.7px;
}

.meter-readouts {
    display: flex;
    justify-content: space-between;
    width: 90%;
    gap: 6px;
}

.meter-readout-channel {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.readout-kind {
    font-size: 8px;
    font-weight: 700;
    color: #586372;
    letter-spacing: 0.7px;
    text-align: center;
}

.val-box {
    background: linear-gradient(180deg, rgba(18, 22, 28, 0.92), rgba(7, 9, 12, 0.96));
    border: 1px solid #29313b;
    border-radius: 4px;
    padding: 6px 0 5px;
    width: 100%;
    text-align: center;
    font-family: monospace;
    font-size: 13px;
    color: #45f3ff;
    box-shadow: inset 0 1px rgba(255, 255, 255, 0.025);
}

.channel-left .peak-val {
    color: #62eaff;
    border-color: rgba(69, 243, 255, 0.2);
}

.channel-right .peak-val {
    color: #ffc45f;
    border-color: rgba(255, 184, 77, 0.2);
}

.channel-left .rms-val { color: #27e5bd; }
.channel-right .rms-val { color: #90e36d; }

.readout-labels {
    display: flex;
    justify-content: space-between;
    width: 90%;
    margin-top: 5px;
    font-size: 9px;
    color: #555;
    font-weight: bold;
}

.meter-dr-display {
    position: relative;
    background:
        radial-gradient(circle at 50% 100%, rgba(0, 255, 170, 0.11), transparent 68%),
        rgba(2, 5, 8, 0.88);
    border: 1px solid rgba(69, 243, 255, 0.14);
    margin: 12px 0;
    padding: 7px 10px 8px;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 80%;
    box-shadow: inset 0 1px rgba(255, 255, 255, 0.035), 0 8px 20px rgba(0, 0, 0, 0.24);
}

.dr-label {
    font-size: 8px;
    font-weight: 700;
    color: #718092;
    letter-spacing: 1px;
}

.dr-value-row {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 4px;
}

.dr-value {
    font-size: 22px;
    font-weight: 800;
    color: #00ffaa;
    text-shadow: 0 0 10px rgba(0,255,170,0.4);
}

.dr-unit {
    font: 700 8px monospace;
    color: #526171;
}

.meter-dr-status {
    width: 88%;
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 10px;
}

.dr-status-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 6px 8px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.03);
}

.dr-status-resettable {
    cursor: pointer;
}

.dr-status-resettable:hover {
    border-color: rgba(69, 243, 255, 0.28);
    background: rgba(69, 243, 255, 0.06);
}

.dr-status-label {
    font-size: 10px;
    color: #7f8a97;
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

.dr-status-value {
    font-family: monospace;
    font-size: 11px;
    color: #ffcf6b;
}

.dr-status-mode {
    color: #45f3ff;
    font-weight: 700;
}

.dr-scale-wrapper {
    flex: 1;
    display: flex;
    width: 100%;
    justify-content: center;
    margin: 8px 0 10px;
    min-height: 200px;
}

.dr-scale-labels {
    position: relative;
    flex: 0 0 23px;
    font-size: 9px;
    color: #596370;
    font-weight: 600;
}

.dr-scale-labels span {
    position: absolute;
    right: 4px;
    bottom: var(--db-pos);
    line-height: 1;
    transform: translateY(50%);
}

.dr-scale-labels.right span {
    right: auto;
    left: 4px;
}

.dr-bar-container {
    width: 120px;
    background: linear-gradient(180deg, #0b0e13, #07090c);
    border: 1px solid #252c35;
    border-radius: 5px;
    position: relative;
    box-shadow: inset 0 0 16px #000, 0 10px 30px rgba(0, 0, 0, 0.28);
    overflow: hidden;
}

.dr-bar-container::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 200%;
    height: 100%;
    background: linear-gradient(105deg, transparent 20%, rgba(255, 255, 255, 0.015) 25%, rgba(255, 255, 255, 0.045) 50%, transparent 55%);
    pointer-events: none;
    transform: translateX(-50%);
    z-index: 4;
}

.dr-meter-grid {
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
}

.dr-meter-grid i {
    position: absolute;
    left: 0;
    right: 0;
    bottom: var(--db-pos);
    border-top: 1px solid rgba(135, 151, 170, 0.075);
}

.dr-bar-bg {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: space-between;
    padding: 3px;
    z-index: 2;
}

.dr-channel {
    width: 45%;
    height: 100%;
    background: rgba(255,255,255,0.018);
    position: relative;
    border-radius: 2px;
    overflow: hidden;
}

/* Meter channel-mode layouts — driven by a class on .classic-meter-panel.
   stereo = default (both channels at 45%). mono/left collapse to L only,
   right collapses to R only. */
.classic-meter-panel.meter-mode-mono #drChR,
.classic-meter-panel.meter-mode-left #drChR,
.classic-meter-panel.meter-mode-right #drChL {
    display: none;
}

.classic-meter-panel.meter-mode-mono #drChL,
.classic-meter-panel.meter-mode-left #drChL,
.classic-meter-panel.meter-mode-right #drChR {
    width: 100%;
}

.classic-meter-panel.meter-mode-mono .meter-readout-channel.channel-right,
.classic-meter-panel.meter-mode-left .meter-readout-channel.channel-right,
.classic-meter-panel.meter-mode-right .meter-readout-channel.channel-left {
    visibility: hidden;
}

.dr-rms-fill {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 0%;
    background: linear-gradient(to top, #00c997 0%, #0cdb9d 58%, #d6dc2b 78%, #ffad43 88%, #f14d72 100%);
    background-position: center bottom;
    background-repeat: no-repeat;
    transition: height 0.13s cubic-bezier(0.2, 0.75, 0.25, 1); /* RMS Ballistics visual */
    opacity: 0.88;
    box-shadow: inset 1px 0 rgba(255, 255, 255, 0.08), 0 -3px 10px rgba(0, 255, 170, 0.12);
}

#drChR .dr-rms-fill {
    filter: hue-rotate(-8deg) saturate(0.94);
}

.dr-crest-span {
    position: absolute;
    left: 50%;
    width: 1px;
    height: 0;
    background: linear-gradient(to top, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.42));
    transform: translateX(-50%);
    transition: bottom 0.13s cubic-bezier(0.2, 0.75, 0.25, 1), height 0.08s ease-out;
    opacity: 0.7;
    z-index: 2;
}

.dr-peak-tick {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: #62eaff;
    box-shadow: 0 0 6px rgba(69, 243, 255, 0.65);
    transition: bottom 0.05s ease-out; /* Peak Ballistics visual */
    z-index: 3;
}

#drChR .dr-peak-tick {
    background: #ffc45f;
    box-shadow: 0 0 6px rgba(255, 184, 77, 0.65);
}

/* Menu right-edge toggle tab */
.menu-toggle-tab {
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 21;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    padding: 20px 4px;
    background: var(--panel-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--panel-border);
    border-right: none;
    border-radius: 10px 0 0 10px;
    cursor: pointer;
    transition: right 0.28s ease, background 0.2s, opacity 0.2s;
    box-shadow: -4px 0 16px rgba(0,0,0,0.4);
    user-select: none;
}

.menu-toggle-tab:hover {
    background: rgba(69, 243, 255, 0.1);
    border-color: rgba(69, 243, 255, 0.25);
}

.menu-toggle-tab:hover .menu-tab-chevron {
    color: var(--accent-cyan);
}

.menu-tab-chevron {
    font-size: 16px;
    color: var(--text-secondary);
    line-height: 1;
    transition: transform 0.28s ease, color 0.2s;
    display: block;
}

.app-container.focus-layout.controls-open .menu-toggle-tab {
    right: min(340px, 90vw);
}

.app-container.focus-layout.controls-open .menu-tab-chevron {
    transform: rotate(180deg);
}

/* Meter left-edge toggle tab (mirror of menu-toggle-tab) */
.meter-toggle-tab {
    position: fixed;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 21;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    padding: 20px 4px;
    background: var(--panel-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--panel-border);
    border-left: none;
    border-radius: 0 10px 10px 0;
    cursor: pointer;
    transition: left 0.28s ease, background 0.2s, opacity 0.2s;
    box-shadow: 4px 0 16px rgba(0,0,0,0.4);
    user-select: none;
}

.meter-toggle-tab:hover {
    background: rgba(69, 243, 255, 0.1);
    border-color: rgba(69, 243, 255, 0.25);
}

.meter-toggle-tab:hover .meter-tab-chevron {
    color: var(--accent-cyan);
}

.meter-tab-chevron {
    font-size: 16px;
    color: var(--text-secondary);
    line-height: 1;
    transition: transform 0.28s ease, color 0.2s;
    display: block;
}

.app-container.focus-layout.meter-open .meter-toggle-tab {
    left: min(220px, 90vw);
}

.app-container.focus-layout.meter-open .meter-tab-chevron {
    transform: rotate(180deg);
}

/* Main Workspace */
.workspace {
    grid-area: main;
    display: flex;
    flex-direction: column; /* Stack vertically for split screen */
    gap: 2px;
    background: #000;
    position: relative;
    min-height: 0;
    transition: opacity 0.28s ease;
}

.app-container.focus-layout.controls-open .workspace {
    opacity: 0.85;
}

/* Auto-layout based on active panel count */

/* 1 panel: fullscreen */
.workspace.panels-1 {
    display: flex;
    flex-direction: column;
}

.workspace.panels-1 .visualizer-container:not(.hidden) {
    flex: 1 1 100%;
}

/* 2 panels: stacked 50/50 */
.workspace.panels-2 {
    display: flex;
    flex-direction: column;
}

.workspace.panels-2 .visualizer-container:not(.hidden) {
    flex: 0 0 calc((100% - 2px) / 2);
    max-height: calc((100% - 2px) / 2);
}

/* 3 panels: top big + 2 bottom side by side */
.workspace.panels-3 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 2px;
}

.workspace.panels-3 .visualizer-container.panel-primary {
    grid-column: 1 / -1;
}

/* 4 panels: 2x2 grid */
.workspace.panels-4 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 2px;
}

.visualizer-container {
    flex: 1 1 auto;
    position: relative;
    width: 100%;
    height: auto;
    min-height: 0;
    overflow: hidden;
}

.visualizer-container.hidden {
    display: none;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: grab;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.03);
    background-color: rgba(5, 6, 8, 0.5);
}

canvas:active {
    cursor: grabbing;
}

.overlay-labels {
    position: absolute;
    top: 10px;
    left: 10px;
    font-size: 10px;
    font-weight: 800;
    color: rgba(255,255,255,0.3);
    pointer-events: none;
    letter-spacing: 2px;
}

.canvas-rotary-controls {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    gap: 8px;
    z-index: 15;
}

.rotary-btn.hidden {
    display: none;
}

.rotary-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: rgba(15, 17, 22, 0.65);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 999px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.5px;
    cursor: pointer;
    backdrop-filter: blur(8px);
    transition: background 0.15s, border-color 0.15s, transform 0.05s;
    user-select: none;
}

.rotary-btn:hover {
    background: rgba(28, 32, 40, 0.85);
    border-color: var(--accent-cyan);
}

.rotary-btn:active {
    transform: scale(0.97);
}

.rotary-btn .rotary-label {
    color: var(--text-secondary);
    font-size: 9px;
    letter-spacing: 1.5px;
    text-transform: uppercase;
}

.rotary-btn .rotary-value {
    color: var(--accent-cyan);
    font-weight: 700;
    min-width: 60px;
    text-align: left;
    white-space: nowrap;
}

.peak-hold-canvas-btn {
    flex: 0 0 auto;
}

.peak-hold-canvas-btn .rotary-value {
    min-width: 24px;
}

.peak-hold-canvas-btn.is-off {
    background: rgba(15, 17, 22, 0.48);
    border-color: rgba(255, 255, 255, 0.06);
}

.peak-hold-canvas-btn.is-off .rotary-value {
    color: var(--text-secondary);
}

.spectrogram-freeze-btn.is-active {
    background: rgba(69, 243, 255, 0.1);
    border-color: rgba(69, 243, 255, 0.38);
    box-shadow: inset 0 0 12px rgba(69, 243, 255, 0.06), 0 0 14px rgba(69, 243, 255, 0.08);
}

.spectrogram-freeze-btn.is-active .rotary-value {
    color: #8cf7ff;
}

/* Sidebar Controls */
.control-panel {
    grid-area: sidebar;
    border-left: 1px solid var(--panel-border);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 30px;
    overflow-y: auto;
}

.app-container.focus-layout .control-panel {
    right: 0;
    width: min(340px, 90vw);
    z-index: 20;
    border-left: 1px solid var(--panel-border);
    box-shadow: -16px 0 32px rgba(0, 0, 0, 0.4);
    transform: translateX(100%);
}

.app-container.focus-layout.controls-open .control-panel {
    transform: translateX(0);
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

h3 {
    font-size: 14px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 8px;
}

.control-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.control-item label {
    font-size: 12px;
    color: var(--text-secondary);
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-primary);
    cursor: pointer;
}

.checkbox-row input[type=checkbox] {
    accent-color: var(--accent-cyan);
    width: 14px;
    height: 14px;
    cursor: pointer;
}

.control-hint {
    margin: 4px 0 0 24px;
    font-size: 11px;
    color: var(--text-secondary);
}

.peak-status-grid {
    gap: 10px;
}

.peak-status-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.28);
}

.peak-status-label {
    font-size: 12px;
    color: var(--text-secondary);
}

.peak-status-value {
    font-family: monospace;
    font-size: 12px;
    color: #ffcf6b;
    text-align: right;
}

.button-row {
    display: flex;
    gap: 10px;
}

.button-row .btn-secondary {
    flex: 1;
    width: auto;
    margin-top: 0;
}

.mode-selector {
    display: flex;
    flex-direction: row;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 6px;
    padding: 4px;
    border: 1px solid rgba(255,255,255,0.1);
}

.mode-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 6px 0;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.3s ease;
}

.mode-btn.active {
    background: var(--accent-magenta);
    color: #fff;
    box-shadow: 0 0 12px rgba(255, 42, 109, 0.4);
}

/* Sliders */
.slider-header {
    display: flex;
    justify-content: space-between;
}

input[type=range] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    background: transparent;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    height: 16px;
    width: 16px;
    border-radius: 50%;
    background: var(--accent-cyan);
    box-shadow: 0 0 10px rgba(69, 243, 255, 0.5);
    cursor: pointer;
    margin-top: -6px;
    transition: transform 0.1s ease, box-shadow 0.1s;
}

input[type=range]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 0 14px rgba(69, 243, 255, 0.8);
}

input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

.info-icon {
    display: inline-block;
    margin-left: 6px;
    font-size: 11px;
    color: var(--accent-cyan);
    cursor: help;
    font-style: normal;
    opacity: 0.7;
    transition: opacity 0.2s, transform 0.2s;
}

.info-icon:hover {
    opacity: 1;
    transform: scale(1.2);
}

/* ===== MODAL OVERLAY (HELP / ABOUT) ===== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal-overlay.hidden {
    display: none;
    opacity: 0;
}

.modal-content {
    position: relative;
    width: 90%;
    max-width: 500px;
    padding: 32px;
    border-radius: 16px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
    animation: modalPop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes modalPop {
    0% { transform: scale(0.9); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.modal-close-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    transition: color 0.2s, transform 0.2s;
    width: 32px;
    height: 32px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
}

.modal-close-btn:hover {
    color: var(--accent-magenta);
    background: rgba(255, 255, 255, 0.05);
    transform: rotate(90deg);
}

.modal-header {
    display: flex;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 8px;
}

.modal-header h2 {
    font-size: 24px;
    color: var(--text-primary);
    margin: 0;
}

.modal-version {
    font-size: 12px;
    color: var(--accent-cyan);
    font-family: monospace;
    font-weight: 600;
}

.modal-desc {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 24px;
    line-height: 1.5;
}

.modal-section h3 {
    margin-top: 0;
    margin-bottom: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 8px;
    color: var(--text-primary);
}

.shortcuts-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.shortcuts-list li {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255,255,255,0.03);
}

.shortcuts-list li:last-child {
    border-bottom: none;
}

.shortcuts-list kbd {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    padding: 2px 8px;
    font-size: 12px;
    font-family: monospace;
    color: var(--accent-cyan);
    min-width: 30px;
    text-align: center;
    box-shadow: 0 2px 0 rgba(0,0,0,0.3);
}

.shortcuts-list span {
    font-size: 13px;
    color: var(--text-secondary);
}

.modal-footer {
    margin-top: 32px;
    text-align: center;
    font-size: 11px;
    color: var(--text-secondary);
    opacity: 0.6;
}

/* ===== MOBILE RESPONSIVE (<768px) ===== */
@media (max-width: 768px) {
    :root {
        --header-h: auto;
    }

    body {
        overflow-y: auto;
        overflow-x: hidden;
    }

    .app-container,
    .app-container.focus-layout,
    .app-container.focus-layout.meter-open {
        display: flex;
        flex-direction: column;
        grid-template-columns: none;
        grid-template-rows: none;
        height: 100vh;
        height: 100dvh;
    }

    /* --- Header: compact, vertical stack --- */
    .top-bar {
        flex-direction: column;
        align-items: stretch;
        padding: 10px 12px;
        gap: 8px;
        min-height: 0;
        overflow: visible;
    }

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

    .logo h1 {
        font-size: 18px;
    }

    .logo .subtitle {
        font-size: 9px;
    }

    .audio-controls {
        align-items: stretch;
        gap: 6px;
    }

    .input-selector {
        justify-content: stretch;
        gap: 6px;
    }

    .input-selector label {
        display: none;
    }

    .input-selector select {
        flex: 1;
        min-width: 0;
        font-size: 12px;
        padding: 10px 8px;
    }

    .input-selector .btn-primary,
    .input-selector .btn-secondary {
        padding: 10px 12px;
        font-size: 12px;
    }

    .input-selector .btn-secondary.monitor-btn {
        font-size: 22px;
        padding: 0 10px;
    }

    .status-message {
        text-align: center;
        font-size: 11px;
        max-width: none;
    }

    /* --- Panel toggle buttons: scrollable row, 44px touch targets --- */
    .panel-actions {
        justify-content: flex-start;
        overflow-x: auto;
        flex-wrap: nowrap;
        gap: 6px;
        padding-bottom: 2px;
        -webkit-overflow-scrolling: touch;
    }

    .panel-toggle-btn {
        min-height: 44px;
        min-width: 44px;
        padding: 8px 12px;
        font-size: 11px;
        flex-shrink: 0;
        white-space: nowrap;
    }

    /* --- Header toggle tab --- */
    .header-toggle-tab {
        position: relative;
        top: 0;
        left: 0;
        transform: none;
        align-self: center;
        margin: -4px 0 0;
        padding: 4px 24px;
        z-index: 10;
    }

    /* --- Workspace: takes remaining space --- */
    .workspace {
        flex: 1 1 0;
        min-height: 200px;
    }

    /* On mobile, force max 2 panels stacked */
    .workspace.panels-3,
    .workspace.panels-4 {
        display: flex;
        flex-direction: column;
    }

    .workspace.panels-3 .visualizer-container:not(.hidden),
    .workspace.panels-4 .visualizer-container:not(.hidden) {
        flex: 1 1 0;
        max-height: none;
        width: 100%;
    }

    .workspace.panels-3 .visualizer-container.panel-primary {
        grid-column: unset;
    }

    /* --- Meter panel: horizontal bar at bottom instead of side tower --- */
    .classic-meter-panel,
    .app-container.focus-layout .classic-meter-panel,
    .app-container.focus-layout.meter-open .classic-meter-panel {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        top: auto;
        flex-direction: row;
        align-items: center;
        padding: 8px 12px;
        gap: 10px;
        border-right: none;
        border-top: 1px solid var(--panel-border);
        z-index: 25;
        max-height: 120px;
        overflow-x: auto;
        overflow-y: hidden;
        white-space: nowrap;
        opacity: 1;
        visibility: visible;
        transition: transform 0.28s ease;
    }

    .app-container.focus-layout .classic-meter-panel {
        transform: translateY(100%);
    }

    .app-container.focus-layout.meter-open .classic-meter-panel {
        transform: translateY(0);
    }

    .meter-title {
        width: auto;
        flex: 0 0 auto;
        flex-direction: column;
        gap: 2px;
        margin-bottom: 0;
        font-size: 10px;
    }
    .meter-title-detail { display: none; }
    .meter-readouts { width: auto; flex-direction: column; gap: 2px; }
    .meter-dr-display { margin: 0; width: auto; padding: 4px 8px; }
    .dr-value { font-size: 16px; }
    .meter-dr-status { width: auto; margin-bottom: 0; gap: 4px; }

    .dr-scale-wrapper {
        min-height: 80px;
        height: 80px;
        width: 80px;
        flex-shrink: 0;
        margin: 0;
    }

    .dr-bar-container { width: 60px; }

    .readout-labels { width: auto; margin-top: 2px; }

    /* --- Sidebar: bottom sheet overlay --- */
    .control-panel,
    .app-container.focus-layout .control-panel {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-height: 70vh;
        border-left: none;
        border-top: 1px solid var(--panel-border);
        border-radius: 16px 16px 0 0;
        transform: translateY(100%);
        z-index: 30;
        box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.5);
        padding: 20px 16px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .app-container.focus-layout.controls-open .control-panel {
        transform: translateY(0);
    }

    /* --- Menu toggle tab: bottom-center on mobile --- */
    .menu-toggle-tab {
        position: fixed;
        right: auto;
        left: 50%;
        bottom: 0;
        top: auto;
        transform: translateX(-50%);
        width: auto;
        padding: 6px 24px;
        border-radius: 10px 10px 0 0;
        border-right: 1px solid var(--panel-border);
        border-bottom: none;
        box-shadow: 0 -4px 16px rgba(0,0,0,0.4);
    }

    .menu-tab-chevron {
        transform: rotate(-90deg);
    }

    .app-container.focus-layout.controls-open .menu-toggle-tab {
        right: auto;
        bottom: 70vh;
    }

    .app-container.focus-layout.controls-open .menu-tab-chevron {
        transform: rotate(90deg);
    }

    /* --- Meter toggle tab: bottom-left on mobile --- */
    .meter-toggle-tab {
        position: fixed;
        left: 12px;
        bottom: 0;
        top: auto;
        transform: none;
        width: auto;
        padding: 6px 24px;
        border-radius: 10px 10px 0 0;
        border-left: 1px solid var(--panel-border);
        border-bottom: none;
        box-shadow: 0 -4px 16px rgba(0,0,0,0.4);
    }

    .meter-tab-chevron {
        transform: rotate(90deg);
    }

    .app-container.focus-layout.meter-open .meter-toggle-tab {
        left: 12px;
        bottom: 70vh;
    }

    .app-container.focus-layout.meter-open .meter-tab-chevron {
        transform: rotate(-90deg);
    }

    /* --- Backdrop --- */
    .panel-backdrop {
        top: 0;
    }

    /* --- General touch targets --- */
    .btn-primary, .btn-secondary {
        min-height: 44px;
        font-size: 13px;
    }

    select {
        min-height: 44px;
        font-size: 13px;
    }

    .mode-btn {
        min-height: 40px;
        font-size: 11px;
    }

    input[type=range] {
        height: 44px;
    }

    input[type=range]::-webkit-slider-thumb {
        height: 24px;
        width: 24px;
        margin-top: -10px;
    }

    .checkbox-row input[type=checkbox] {
        width: 20px;
        height: 20px;
    }
}
