:root {
    /* Color Palette - Premium Dark */
    --bg-app: #0f0f11;
    --bg-panel: #18181b;
    --bg-input: #202024;

    --text-main: #e4e4e7;
    --text-muted: #a1a1aa;

    --accent-primary: #8b5cf6;
    /* Cyber Purple */
    --accent-hover: #7c3aed;
    --accent-secondary: #10b981;
    /* Terminal Green */

    --border-light: #27272a;
    --border-focus: #52525b;

    /* Metrics */
    --header-height: 60px;
    --footer-height: 30px;
    --sidebar-width: 320px;

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

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

body {
    background-color: var(--bg-app);
    color: var(--text-main);
    font-family: var(--font-ui);
    height: 100vh;
    overflow: hidden;
    user-select: none;
}

/* Layout */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Header */
.app-header {
    height: var(--header-height);
    background-color: var(--bg-panel);
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    flex-shrink: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-main);
}

.logo-icon {
    font-size: 1.5rem;
    color: var(--accent-primary);
}

.logo h1 {
    font-size: 1.2rem;
    font-weight: 800;
    letter-spacing: 2px;
}

/* Main Workspace */
.workspace {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Panels */
.panel {
    background-color: var(--bg-panel);
    border-right: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
}

.control-panel {
    width: var(--sidebar-width);
    flex-shrink: 0;
    overflow-y: auto;
}

.panel-header {
    background-color: #1e1e22;
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-header h2 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 1px;
}

.panel-status {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--accent-secondary);
}

/* Modules Rack */
.modules-rack {
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.empty-state-rack {
    padding: 40px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-style: italic;
    opacity: 0.5;
}

/* Preview Area */
.preview-area {
    flex: 1;
    background-color: #0b0b0c;
    /* Slightly darker for contrast */
    background-image:
        radial-gradient(#1f1f23 1px, transparent 1px);
    background-size: 20px 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.preview-container {
    max-width: 90%;
    max-height: 90%;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Upload Prompt */
.upload-prompt {
    text-align: center;
    border: 2px dashed var(--border-light);
    padding: 60px;
    border-radius: 12px;
    transition: all 0.2s ease;
}

.preview-area.drag-over .upload-prompt {
    border-color: var(--accent-primary);
    background-color: rgba(139, 92, 246, 0.05);
}

.icon-upload {
    font-size: 3rem;
    color: var(--text-muted);
    margin-bottom: 20px;
}

.upload-prompt h3 {
    font-family: var(--font-mono);
    margin-bottom: 10px;
    letter-spacing: 1px;
}

.upload-prompt p {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-bottom: 20px;
}

/* Canvas */
#main-canvas {
    max-width: 100%;
    max-height: 100%;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
    background-color: #000;
    /* Checkerboard later? */
}

/* Footer */
.app-footer {
    height: var(--footer-height);
    background-color: var(--bg-panel);
    border-top: 1px solid var(--border-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    font-size: 0.7rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

/* Components: Buttons */
.btn {
    border: none;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    font-weight: 700;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
}

.btn-primary {
    background-color: var(--accent-primary);
    color: white;
}

.btn-primary:not(:disabled):hover {
    background-color: var(--accent-hover);
    box-shadow: 0 0 10px rgba(139, 92, 246, 0.4);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: var(--border-light);
}

.btn-secondary {
    background-color: transparent;
    border: 1px solid var(--border-focus);
    color: var(--text-main);
}

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

/* UI Builder Components */
.module-group {
    background-color: #232326;
    border: 1px solid var(--border-light);
    border-radius: 6px;
    margin-bottom: 12px;
    overflow: hidden;
}

.module-header {
    background-color: #2a2a2e;
    padding: 10px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #1a1a1c;
}

.module-header h3 {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 1px;
    color: var(--accent-primary);
}

.module-content {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

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

.control-info {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    color: var(--text-muted);
}

.control-value {
    font-family: var(--font-mono);
    color: var(--text-main);
}

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

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 14px;
    width: 14px;
    border-radius: 50%;
    background: var(--text-main);
    cursor: pointer;
    margin-top: -6px;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
}

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

input[type=range]:focus::-webkit-slider-runnable-track {
    background: var(--accent-primary);
}

/* Selects */
select {
    background-color: var(--bg-input);
    color: var(--text-main);
    border: 1px solid var(--border-light);
    padding: 6px;
    font-size: 0.8rem;
    border-radius: 4px;
    font-family: var(--font-ui);
    outline: none;
}

select:focus {
    border-color: var(--accent-primary);
}

/* Mobile Optimization */
@media (max-width: 768px) {

    /* Layout Switch: Stacked */
    .app-container {
        height: 100vh;
        /* Ensure full viewport */
        overflow: hidden;
    }

    .workspace {
        flex-direction: column;
        overflow: hidden;
    }

    /* 1. Header */
    .app-header {
        padding: 0 10px;
        height: 50px;
    }

    .logo h1 {
        font-size: 1rem;
    }

    .header-controls .btn {
        font-size: 0.7rem;
        padding: 6px 10px;
    }

    /* 2. Preview Area (Top Half) */
    .preview-area {
        flex: 0 0 50%;
        /* Fixed height ratio */
        border-bottom: 1px solid var(--border-light);
    }

    /* 3. Controls (Bottom Half) */
    .panel.control-panel {
        width: 100%;
        flex: 1;
        /* Take remaining space */
        border-right: none;
        overflow-y: auto;
    }

    .modules-rack {
        padding-bottom: 40px;
        /* Space for scroll */
    }

    /* Touch Targets */
    input[type=range]::-webkit-slider-thumb {
        width: 24px;
        height: 24px;
        margin-top: -11px;
        /* Center on 2px track */
    }

    .control-item {
        margin-bottom: 15px;
        /* More spacing */
    }

    .panel-header {
        position: sticky;
        top: 0;
        z-index: 10;
    }

    .module-header {
        padding: 15px;
        /* Bigger tap area */
    }

    .module-group {
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    /* Batch Drop Zone */
    .batch-drop-zone {
        padding: 15px;
    }

    .batch-drop-zone h3 {
        font-size: 0.9rem;
    }
}

/* Audio Player Styles */
/* ... (Existing) ... */
.visualizer-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    width: 100%;
}

/* Tooltips */
.tooltip-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    background-color: #ef4444;
    /* Red */
    border-radius: 50%;
    color: white;
    font-size: 10px;
    font-weight: bold;
    margin-left: 8px;
    cursor: help;
    position: relative;
}

.tooltip-icon:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    /* Top of icon */
    left: 50%;
    transform: translateX(-50%);
    background-color: #333;
    color: #fff;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 0.75rem;
    white-space: nowrap;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    pointer-events: none;
    z-index: 1000;
    margin-bottom: 5px;
}

.tooltip-icon:hover::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: #333;
    margin-bottom: -5px;
    /* Arrow */
    z-index: 1000;
}

/* Audio Player Styles - Standard Clean */
.audio-player-container {
    display: flex;
    align-items: center;
    background: #27272a;
    /* Standard Dark Grey */
    border: 1px solid var(--border-dim);
    border-radius: 8px;
    /* Standard Rounding */
    padding: 10px 15px;
    width: 100%;
    margin-top: 15px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.player-btn {
    background: transparent;
    border: none;
    color: #e4e4e7;
    cursor: pointer;
    font-size: 1.2rem;
    padding: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s;
}

.player-btn:hover {
    color: white;
}

.btn-main-play {
    font-size: 1.5rem;
    /* Slightly larger play button */
    margin-right: 15px;
    background: transparent;
    border: none;
    color: #e4e4e7;
    cursor: pointer;
}

.btn-main-play:hover {
    color: var(--accent-primary);
    transform: none;
    /* No scale, keep it standard */
}

.player-time {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    color: #a1a1aa;
    /* Light Grey text */
    margin-right: 15px;
    white-space: nowrap;
    min-width: 90px;
    text-align: center;
}

.player-slider-container {
    flex: 1;
    /* Take remaining space */
    display: flex;
    align-items: center;
    margin-right: 15px;
}

.player-controls-right {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 120px;
}

.volume-icon {
    font-size: 1rem;
    color: #a1a1aa;
}

/* Range Inputs - Standard Look */
.player-range {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    background: #52525b;
    /* Darker track */
    border-radius: 2px;
    outline: none;
}

.player-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #e4e4e7;
    /* Standard grey thumb */
    cursor: pointer;
    transition: background 0.15s;
}

.player-range::-webkit-slider-thumb:hover {
    background: white;
}

.visualizer-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    width: 100%;
}

/* --- GLOBAL JS TOOLTIP --- */
#global-tooltip {
    position: fixed;
    display: none;
    background: #18181b;
    /* Zinc-900 */
    color: #e4e4e7;
    /* Zinc-200 */
    border: 1px solid #3f3f46;
    /* Zinc-700 */
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-family: var(--font-main);
    line-height: 1.4;
    max-width: 250px;
    z-index: 10000;
    pointer-events: none;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
}

/* --- TOOLTIP STYLES --- */
/* Icon Style */
.tooltip-icon {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 16px;
    height: 16px;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-muted);
    border: 1px solid var(--border-light);
    border-radius: 50%;
    font-size: 0.65rem;
    cursor: help;
    margin-left: 8px;
    vertical-align: middle;
    font-family: var(--font-mono);
    transition: all 0.2s ease;
}

.tooltip-icon:hover {
    color: var(--text-main);
    border-color: var(--text-main);
    background: rgba(255, 255, 255, 0.2);
}

/* Remove old CSS hover effects since we use JS global tooltip now */
.tooltip-icon:hover::after,
.tooltip-icon:hover::before {
    display: none !important;
}

/* Mobile Adjustments for Tooltips */
@media (max-width: 768px) {
    .tooltip-icon:hover::after {
        left: auto;
        right: 0;
        top: 100%;
        /* Below */
        transform: translateY(5px);
        margin-left: 0;
        max-width: 180px;
        z-index: 2000;
    }

    .tooltip-icon:hover::before {
        display: none;
        /* Hide arrow on mobile */
    }
}