/* ============================================
   CELLULAR AUTOMATA - LIQUID GLASS UI
   ============================================ */

/* CSS Variables - Color Palette */
:root {
    /* Background */
    --bg-dark: #0a0a0f;
    --bg-gradient: linear-gradient(135deg, #0a0a0f 0%, #1a1a2e 50%, #0a0a0f 100%);
    
    /* Glass Effect */
    --glass-bg: rgba(255, 255, 255, 0.03);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    --glass-blur: 20px;
    
    /* Accent Colors */
    --accent-primary: #00d4ff;
    --accent-secondary: #7b2cbf;
    --accent-tertiary: #ff006e;
    --accent-glow: 0 0 20px rgba(0, 212, 255, 0.4);
    
    /* Cell State Colors */
    --state-0: #0a0a0f;      /* Dead - Deep black */
    --state-1: #00ffff;      /* Born - Electric cyan */
    --state-2: #00a8ff;      /* Young - Bright blue */
    --state-3: #7b2cbf;      /* Mature - Vivid purple */
    --state-4: #ff00a8;      /* Aging - Hot pink */
    --state-5: #ff4444;      /* Dying - Red ember */
    
    /* Text */
    --text-primary: rgba(255, 255, 255, 0.95);
    --text-secondary: rgba(255, 255, 255, 0.6);
    --text-muted: rgba(255, 255, 255, 0.3);
    
    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-medium: 0.3s ease;
    --transition-slow: 0.5s ease;
    
    /* Spacing */
    --panel-padding: 20px;
    --border-radius: 16px;
    --border-radius-sm: 8px;
}

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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    cursor: crosshair;
    user-select: none;
    -webkit-user-select: none;
    -webkit-user-drag: none;
}

/* Canvas */
#automataCanvas {
    position: fixed;
    z-index: 1;
    background: var(--bg-gradient);
    /* Width/height controlled by JavaScript for aspect ratio support */
}

/* ============================================
   GLASS PANEL SYSTEM
   ============================================ */

.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius);
    box-shadow: var(--glass-shadow);
    padding: var(--panel-padding);
    transition: all var(--transition-medium);
}

.glass-panel:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.12);
}

.glass-panel h3 {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-secondary);
    margin-bottom: 15px;
}

.glass-panel h3 .hint {
    font-weight: 400;
    opacity: 0.5;
    text-transform: none;
    letter-spacing: normal;
}

/* ============================================
   GUI OVERLAY LAYOUT
   ============================================ */

#gui-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

#gui-overlay .glass-panel,
#gui-overlay .glass-btn {
    pointer-events: auto;
}

/* Top Bar */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    margin-bottom: 20px;
}

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

.logo-icon {
    font-size: 1.5rem;
    color: var(--accent-primary);
    text-shadow: var(--accent-glow);
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.logo-text {
    font-weight: 600;
    font-size: 1rem;
    letter-spacing: 0.05em;
}

.controls-group {
    display: flex;
    gap: 8px;
}

.speed-control {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.speed-control input[type="range"] {
    width: 100px;
}

/* Side Panels */
.left-panel, .right-panel {
    position: fixed;
    top: 100px;
    width: 200px;
}

.left-panel {
    left: 20px;
    max-height: calc(100vh - 200px);
    overflow-y: auto;
}

/* Tabbed Left Panel - wider for sound controls */
.left-panel.tabbed-panel {
    width: 260px;
}

/* Panel Tabs */
.panel-tabs {
    display: flex;
    gap: 4px;
    margin: -20px -20px 16px -20px;
    padding: 12px 12px 0 12px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--border-radius) var(--border-radius) 0 0;
}

.panel-tab {
    flex: 1;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 10px 8px;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    border-radius: var(--border-radius-sm) var(--border-radius-sm) 0 0;
}

.panel-tab:hover {
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.03);
}

.panel-tab.active {
    color: var(--accent-primary);
    border-bottom-color: var(--accent-primary);
    background: rgba(0, 212, 255, 0.08);
}

/* Tab Content */
.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.2s ease-out;
}

/* Compact styles for sound tab */
.settings-group.compact {
    gap: 8px;
}

.settings-group.compact .setting-row {
    gap: 4px;
}

.adsr-grid.compact {
    gap: 4px;
}

.adsr-grid.compact .adsr-control input[type="range"] {
    height: 50px;
}

.filter-controls.compact {
    gap: 6px;
}

.filter-controls.compact .filter-row {
    gap: 6px;
}

.filter-controls.compact label {
    width: 45px;
    font-size: 0.65rem;
}

.filter-controls.compact span {
    width: 45px;
    font-size: 0.65rem;
}

.right-panel {
    right: 20px;
    /* Fixed height to not overlap with output config panel */
    max-height: calc(100vh - 380px);
    display: flex;
    flex-direction: column;
}

/* Bottom Panel */
.bottom-panel {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    max-width: 600px;
    max-height: 280px;
    will-change: transform, opacity;
    transition: transform var(--transition-medium), opacity var(--transition-medium);
    display: flex;
    flex-direction: column;
}

.bottom-panel.hidden {
    transform: translate(-50%, 120%);
    opacity: 0;
    pointer-events: none;
}

.bottom-panel h3 {
    flex-shrink: 0;
}

/* Stats Panel */
.stats-panel {
    position: fixed;
    bottom: 20px;
    left: 20px;
    display: flex;
    gap: 20px;
    padding: 12px 20px;
}

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

.stat-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
}

.stat-value {
    font-size: 1rem;
    font-weight: 600;
    color: var(--accent-primary);
    font-variant-numeric: tabular-nums;
}

/* ============================================
   GLASS BUTTONS
   ============================================ */

.glass-btn {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius-sm);
    padding: 10px 16px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.glass-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--accent-primary);
    box-shadow: 0 0 15px rgba(0, 212, 255, 0.2);
    transform: translateY(-1px);
}

.glass-btn:active {
    transform: translateY(0);
    background: rgba(0, 212, 255, 0.1);
}

.glass-btn .icon {
    font-size: 1rem;
}

.glass-btn.active {
    background: rgba(0, 212, 255, 0.15);
    border-color: var(--accent-primary);
    box-shadow: var(--accent-glow);
}

/* ============================================
   STATE SELECTOR
   ============================================ */

.state-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 20px;
}

.state-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid transparent;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.state-item:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--glass-border);
}

.state-item.active {
    background: rgba(0, 212, 255, 0.1);
    border-color: var(--accent-primary);
}

.state-color {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    box-shadow: 0 0 10px currentColor;
}

.state-name {
    font-size: 0.85rem;
    flex: 1;
}

.state-key {
    font-size: 0.7rem;
    padding: 2px 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    color: var(--text-muted);
}

/* ============================================
   BRUSH SIZE
   ============================================ */

.brush-size {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.brush-size label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-secondary);
}

/* ============================================
   SETTINGS PANEL
   ============================================ */

.section-divider {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid var(--glass-border);
}

.settings-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.setting-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.setting-row label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
}

.toggle-row {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
}

.small-btn {
    padding: 6px 12px;
    font-size: 0.75rem;
}

.glass-select {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius-sm);
    padding: 8px 12px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    outline: none;
}

.glass-select:hover,
.glass-select:focus {
    border-color: var(--accent-primary);
    background: rgba(255, 255, 255, 0.05);
}

.glass-select option {
    background: #1a1a2e;
    color: var(--text-primary);
}

/* ============================================
   RULE SELECTOR
   ============================================ */

.rule-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 20px;
}

.rule-item {
    padding: 12px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid transparent;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.rule-item:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--glass-border);
}

.rule-item.active {
    background: rgba(123, 44, 191, 0.15);
    border-color: var(--accent-secondary);
}

.rule-item .rule-name {
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 4px;
}

.rule-item .rule-states {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.rule-info {
    padding-top: 15px;
    border-top: 1px solid var(--glass-border);
}

.rule-info h4 {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.rule-info p {
    font-size: 0.8rem;
    line-height: 1.5;
    color: var(--text-secondary);
}

/* ============================================
   PATTERN SELECTOR
   ============================================ */

.pattern-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    padding: 5px;
}

.pattern-item {
    width: 80px;
    height: 80px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid transparent;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.pattern-item:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--accent-tertiary);
    transform: scale(1.05);
}

.pattern-item canvas {
    width: 40px;
    height: 40px;
    image-rendering: pixelated;
}

.pattern-item span {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-align: center;
}

.pattern-content {
    display: flex;
    align-items: center;
    justify-content: center;
}

.pattern-content canvas {
    border-radius: 4px;
}

.pattern-item.active {
    background: rgba(255, 0, 110, 0.15);
    border-color: var(--accent-tertiary);
    box-shadow: 0 0 15px rgba(255, 0, 110, 0.3);
    transform: scale(1.05);
}

.pattern-item.faded {
    opacity: 0.35;
}

.pattern-item.faded:hover {
    opacity: 0.6;
}

/* ============================================
   HELP PANEL
   ============================================ */

.help-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 320px;
    z-index: 100;
    transition: opacity var(--transition-medium), transform var(--transition-medium);
    pointer-events: none;
    will-change: transform, opacity;
}

.help-panel:not(.hidden) {
    pointer-events: auto;
}

.help-panel.hidden {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.9);
}

.help-list {
    list-style: none;
    margin-bottom: 20px;
}

.help-list li {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.help-list kbd {
    background: rgba(255, 255, 255, 0.1);
    padding: 4px 8px;
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.75rem;
    min-width: 60px;
    text-align: center;
}

.close-help {
    width: 100%;
}

/* ============================================
   FLOATING BUTTONS
   ============================================ */

.help-toggle, .audio-toggle {
    position: fixed;
    bottom: 20px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    font-size: 1.2rem;
}

.help-toggle {
    right: 240px;
}

.audio-toggle {
    right: 294px;
}

.audio-toggle.muted .icon {
    opacity: 0.4;
}

/* ============================================
   OUTPUT CONFIG ISLAND
   ============================================ */

.output-config-panel {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 200px;
    z-index: 20;
    padding: 16px;
}

.output-config-panel h3 {
    margin-bottom: 12px;
}

.output-config-panel .output-settings {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.output-config-panel .setting-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.output-config-panel .setting-row label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
}

.output-config-panel .output-preview {
    text-align: center;
    padding: 10px 8px;
    background: rgba(0, 212, 255, 0.1);
    border-radius: var(--border-radius-sm);
    font-size: 0.85rem;
    color: var(--accent-primary);
    font-variant-numeric: tabular-nums;
    font-weight: 500;
    border: 1px solid rgba(0, 212, 255, 0.2);
}

/* Make rule list scrollable within fixed height panel */
.right-panel .rule-list {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

/* ============================================
   SOUND ENGINE PANEL
   ============================================ */

.sound-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 320px;
    max-height: 80vh;
    overflow-y: auto;
    z-index: 100;
    padding: 20px;
    transition: opacity var(--transition-medium), transform var(--transition-medium);
    will-change: transform, opacity;
}

.sound-panel.hidden {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.9);
    pointer-events: none;
}

.sound-panel-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--glass-border);
}

.sound-panel-header h3 {
    flex: 1;
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.sound-panel-header .current-preset-label {
    font-size: 0.75rem;
    padding: 4px 10px;
    background: rgba(123, 44, 191, 0.2);
    border-radius: 12px;
    color: var(--accent-secondary);
    font-weight: 500;
}

.sound-panel-close {
    padding: 4px 10px !important;
    font-size: 1.2rem;
}

/* Sound Sections */
.sound-section {
    margin-bottom: 16px;
}

.sound-section .section-label {
    display: block;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: 8px;
}

/* Preset Grid */
.preset-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.preset-btn {
    padding: 8px 6px !important;
    font-size: 0.75rem !important;
    text-transform: capitalize;
}

.preset-btn.active {
    background: rgba(123, 44, 191, 0.25);
    border-color: var(--accent-secondary);
    box-shadow: 0 0 12px rgba(123, 44, 191, 0.4);
}

/* Waveform Grid */
.waveform-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
}

.waveform-btn {
    padding: 8px 4px !important;
    font-size: 0.7rem !important;
}

.waveform-btn.active {
    background: rgba(0, 212, 255, 0.2);
    border-color: var(--accent-primary);
    box-shadow: 0 0 10px rgba(0, 212, 255, 0.3);
}

/* ADSR Grid */
.adsr-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.adsr-control {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.adsr-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--accent-primary);
    text-shadow: 0 0 8px rgba(0, 212, 255, 0.5);
}

.adsr-control input[type="range"] {
    width: 100%;
    writing-mode: vertical-lr;
    direction: rtl;
    height: 60px;
}

.adsr-value {
    font-size: 0.65rem;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

/* Filter Controls */
.filter-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

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

.filter-row label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    width: 60px;
    flex-shrink: 0;
}

.filter-row input[type="range"] {
    flex: 1;
}

.filter-row span {
    font-size: 0.7rem;
    color: var(--text-secondary);
    width: 60px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.filter-row .glass-select {
    flex: 1;
    font-size: 0.75rem;
    padding: 6px 10px;
}

/* Volume Row */
.volume-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.volume-row label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    width: 50px;
}

.volume-row input[type="range"] {
    flex: 1;
}

.volume-row span {
    font-size: 0.75rem;
    color: var(--accent-primary);
    width: 40px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* Sound Panel Toggle Button */
.sound-panel-toggle {
    position: fixed;
    bottom: 20px;
    right: 128px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    font-size: 1.2rem;
}

/* Octave Control */
.octave-control {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.octave-btn {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 50%;
    font-size: 1.2rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
}

.octave-btn:hover {
    background: rgba(0, 212, 255, 0.15);
    border-color: var(--accent-primary);
}

.octave-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.octave-value {
    min-width: 40px;
    text-align: center;
    font-size: 1rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--accent-primary);
    background: rgba(0, 212, 255, 0.1);
    padding: 6px 12px;
    border-radius: var(--border-radius-sm);
    border: 1px solid rgba(0, 212, 255, 0.2);
}

/* Pitch Section - Grouped controls */
.pitch-section {
    background: rgba(0, 212, 255, 0.05);
    border: 1px solid rgba(0, 212, 255, 0.1);
    border-radius: var(--border-radius-sm);
    padding: 12px;
    margin-bottom: 16px;
}

.pitch-section .section-label {
    margin-bottom: 10px;
}

.pitch-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

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

.pitch-row label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    width: 45px;
    flex-shrink: 0;
}

.pitch-row .glass-select.compact {
    flex: 1;
    font-size: 0.75rem;
    padding: 6px 10px;
}

.pitch-row .octave-control {
    flex: 1;
    justify-content: flex-start;
    gap: 8px;
}

.pitch-row .octave-btn {
    width: 28px;
    height: 28px;
    font-size: 1rem;
}

.pitch-row .octave-value {
    min-width: 32px;
    padding: 4px 8px;
    font-size: 0.85rem;
}

/* Filter Amount Row */
.filter-amount-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.filter-amount-row label {
    font-size: 0.65rem;
    color: var(--text-muted);
    width: 45px;
    flex-shrink: 0;
}

.filter-amount-row input[type="range"] {
    flex: 1;
}

.filter-amount-row span {
    font-size: 0.65rem;
    color: var(--text-secondary);
    width: 40px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* ============================================
   AUDIO MODAL - Premium Design
   ============================================ */

.audio-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    opacity: 1;
    transition: opacity 0.4s ease, visibility 0.4s ease;
}

.audio-modal.hidden {
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
}

/* Semi-transparent backdrop with blur */
.audio-modal-backdrop {
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at center, rgba(10, 10, 20, 0.85) 0%, rgba(5, 5, 15, 0.95) 100%);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

/* Main card container */
.audio-modal-card {
    position: relative;
    background: linear-gradient(165deg, rgba(30, 30, 50, 0.9) 0%, rgba(15, 15, 30, 0.95) 100%);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 24px;
    padding: 48px 40px 40px;
    max-width: 380px;
    width: 90%;
    text-align: center;
    box-shadow: 
        0 25px 50px -12px rgba(0, 0, 0, 0.5),
        0 0 0 1px rgba(255, 255, 255, 0.05),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    overflow: hidden;
    animation: modalSlideIn 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* Animated glow orbs */
.modal-glow {
    position: absolute;
    border-radius: 50%;
    filter: blur(60px);
    pointer-events: none;
    opacity: 0.6;
}

.modal-glow-1 {
    width: 200px;
    height: 200px;
    background: var(--accent-primary);
    top: -80px;
    right: -60px;
    animation: glowFloat1 6s ease-in-out infinite;
}

.modal-glow-2 {
    width: 180px;
    height: 180px;
    background: var(--accent-secondary);
    bottom: -60px;
    left: -40px;
    animation: glowFloat2 5s ease-in-out infinite;
}

@keyframes glowFloat1 {
    0%, 100% { transform: translate(0, 0) scale(1); opacity: 0.5; }
    50% { transform: translate(-15px, 15px) scale(1.1); opacity: 0.7; }
}

@keyframes glowFloat2 {
    0%, 100% { transform: translate(0, 0) scale(1); opacity: 0.5; }
    50% { transform: translate(15px, -10px) scale(1.15); opacity: 0.65; }
}

/* Icon container with sound wave rings */
.modal-icon-container {
    position: relative;
    width: 120px;
    height: 120px;
    margin: 0 auto 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sound-wave-ring {
    position: absolute;
    border-radius: 50%;
    border: 2px solid;
    opacity: 0;
    animation: soundWavePulse 3s ease-out infinite;
}

.sound-wave-ring-1 {
    width: 80px;
    height: 80px;
    border-color: var(--accent-primary);
    animation-delay: 0s;
}

.sound-wave-ring-2 {
    width: 80px;
    height: 80px;
    border-color: rgba(0, 212, 255, 0.6);
    animation-delay: 1s;
}

.sound-wave-ring-3 {
    width: 80px;
    height: 80px;
    border-color: rgba(0, 212, 255, 0.3);
    animation-delay: 2s;
}

@keyframes soundWavePulse {
    0% {
        transform: scale(0.8);
        opacity: 0.8;
    }
    100% {
        transform: scale(1.5);
        opacity: 0;
    }
}

.modal-icon {
    position: relative;
    width: 80px;
    height: 80px;
    background: linear-gradient(165deg, rgba(0, 212, 255, 0.2) 0%, rgba(123, 44, 191, 0.2) 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(0, 212, 255, 0.3);
    box-shadow: 
        0 0 30px rgba(0, 212, 255, 0.2),
        inset 0 0 20px rgba(0, 212, 255, 0.1);
    animation: iconPulse 2s ease-in-out infinite;
}

@keyframes iconPulse {
    0%, 100% { box-shadow: 0 0 30px rgba(0, 212, 255, 0.2), inset 0 0 20px rgba(0, 212, 255, 0.1); }
    50% { box-shadow: 0 0 40px rgba(0, 212, 255, 0.35), inset 0 0 25px rgba(0, 212, 255, 0.15); }
}

.modal-icon svg {
    width: 48px;
    height: 48px;
}

/* Title styling */
.modal-title {
    font-size: 1.75rem;
    font-weight: 600;
    margin-bottom: 12px;
    background: linear-gradient(135deg, #ffffff 0%, rgba(255, 255, 255, 0.8) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
}

/* Description styling */
.modal-description {
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.6;
    margin-bottom: 32px;
    max-width: 300px;
    margin-left: auto;
    margin-right: auto;
}

/* Button container */
.audio-modal .modal-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Base button styling */
.modal-btn {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 16px 28px;
    border-radius: 14px;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    border: none;
}

/* Primary button - Enable Audio */
.modal-btn-primary {
    background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
    color: white;
    box-shadow: 
        0 4px 15px rgba(0, 212, 255, 0.3),
        0 0 0 1px rgba(255, 255, 255, 0.1) inset;
}

.modal-btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 
        0 8px 25px rgba(0, 212, 255, 0.4),
        0 0 0 1px rgba(255, 255, 255, 0.15) inset;
}

.modal-btn-primary:active {
    transform: translateY(0);
}

.modal-btn-primary .btn-icon {
    font-size: 1.2em;
}

/* Button glow effect */
.modal-btn-primary .btn-glow {
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transform: translateX(-100%);
    transition: transform 0.6s ease;
}

.modal-btn-primary:hover .btn-glow {
    transform: translateX(100%);
}

/* Secondary button - Skip */
.modal-btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.2);
}

/* ============================================
   CUSTOM RANGE SLIDER
   ============================================ */

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

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    background: var(--accent-primary);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 10px rgba(0, 212, 255, 0.5);
    transition: all var(--transition-fast);
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 0 15px rgba(0, 212, 255, 0.7);
}

input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    background: var(--accent-primary);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 10px rgba(0, 212, 255, 0.5);
}

/* ============================================
   SCROLLBAR
   ============================================ */

::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ============================================
   RESPONSIVE - MOBILE STYLES
   ============================================ */

/* Mobile Menu Toggle Button */
.mobile-menu-toggle {
    display: none;
    position: fixed;
    top: 20px;
    left: 20px;
    width: 50px;
    height: 50px;
    z-index: 1000;
    border-radius: 50%;
    font-size: 1.4rem;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.mobile-menu-toggle .hamburger {
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: center;
}

.mobile-menu-toggle .hamburger span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--text-primary);
    transition: all var(--transition-fast);
}

.mobile-menu-toggle.active .hamburger span:nth-child(1) {
    transform: rotate(45deg) translate(4px, 4px);
}

.mobile-menu-toggle.active .hamburger span:nth-child(2) {
    opacity: 0;
}

.mobile-menu-toggle.active .hamburger span:nth-child(3) {
    transform: rotate(-45deg) translate(4px, -4px);
}

/* Mobile Slide-Out Panel */
.mobile-slide-panel {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 85%;
    max-width: 340px;
    height: 100%;
    z-index: 999;
    background: rgba(15, 15, 25, 0.98);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    padding: 80px 20px 100px;
    border-right: 1px solid var(--glass-border);
}

.mobile-slide-panel.open {
    transform: translateX(0);
}

.mobile-slide-panel-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 998;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.mobile-slide-panel-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

/* Mobile Tab Navigation (inside slide panel) */
.mobile-tab-nav {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: var(--border-radius);
    padding: 4px;
}

.mobile-tab-btn {
    flex: 1;
    padding: 12px 8px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    border-radius: var(--border-radius-sm);
    transition: all var(--transition-fast);
}

.mobile-tab-btn.active {
    background: var(--glass-bg);
    color: var(--accent-primary);
}

.mobile-tab-content {
    display: none;
}

.mobile-tab-content.active {
    display: block;
    animation: fadeIn 0.2s ease-out;
}

/* Mobile Quick Actions Bar (bottom) */
.mobile-quick-bar {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    padding: 12px 16px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    background: rgba(10, 10, 15, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--glass-border);
}

.mobile-quick-bar .quick-actions {
    display: flex;
    justify-content: space-around;
    gap: 8px;
}

.mobile-quick-bar .glass-btn {
    flex: 1;
    padding: 14px 8px;
    font-size: 1.1rem;
}

/* Mobile State/Brush Mini Panel */
.mobile-state-indicator {
    display: none;
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 100;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: 25px;
    padding: 8px 14px;
    gap: 10px;
    align-items: center;
}

.mobile-state-indicator .current-state {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    box-shadow: 0 0 10px currentColor;
}

.mobile-state-indicator .brush-info {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Mobile Stats (compact) */
.mobile-stats {
    display: none;
    position: fixed;
    bottom: 80px;
    left: 16px;
    z-index: 50;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius-sm);
    padding: 8px 12px;
    font-size: 0.7rem;
    color: var(--text-secondary);
}

.mobile-stats .stat-row {
    display: flex;
    gap: 12px;
}

.mobile-stats .stat-row span {
    white-space: nowrap;
}

.mobile-stats .stat-value {
    color: var(--accent-primary);
    font-weight: 600;
}

/* ============================================
   MOBILE MEDIA QUERY
   ============================================ */

@media (max-width: 900px) {
    /* Hide desktop elements */
    .top-bar,
    .left-panel,
    .right-panel,
    .stats-panel,
    .output-config-panel,
    .help-toggle,
    .audio-toggle {
        display: none !important;
    }
    
    /* Show mobile elements */
    .mobile-menu-toggle,
    .mobile-slide-panel,
    .mobile-slide-panel-overlay,
    .mobile-quick-bar,
    .mobile-state-indicator,
    .mobile-stats {
        display: flex;
    }
    
    .mobile-slide-panel {
        display: block;
    }
    
    /* Adjust GUI overlay */
    #gui-overlay {
        padding: 0;
    }
    
    /* Bottom panel adjustments for mobile */
    .bottom-panel {
        position: fixed;
        bottom: 70px;
        left: 10px;
        right: 10px;
        max-width: none;
        width: auto;
        transform: none;
        max-height: 200px;
        padding: 12px;
        border-radius: var(--border-radius);
        z-index: 90;
    }
    
    .bottom-panel.hidden {
        transform: translateY(calc(100% + 100px));
    }
    
    .bottom-panel h3 {
        font-size: 0.7rem;
        margin-bottom: 10px;
    }
    
    .pattern-grid {
        gap: 6px;
    }
    
    .pattern-item {
        width: 60px;
        height: 60px;
    }
    
    .pattern-item canvas {
        width: 30px;
        height: 30px;
    }
    
    .pattern-item span {
        font-size: 0.6rem;
    }
    
    /* Help panel mobile */
    .help-panel {
        width: 90%;
        max-width: 320px;
    }
    
    /* Audio modal mobile */
    .audio-modal-card {
        width: 92%;
        padding: 36px 24px 28px;
    }
    
    .modal-icon-container {
        width: 100px;
        height: 100px;
        margin-bottom: 20px;
    }
    
    .modal-icon {
        width: 60px;
        height: 60px;
    }
    
    .modal-icon svg {
        width: 36px;
        height: 36px;
    }
    
    .modal-title {
        font-size: 1.4rem;
    }
    
    .modal-description {
        font-size: 0.9rem;
        margin-bottom: 24px;
    }
    
    .modal-btn {
        padding: 14px 24px;
        font-size: 0.95rem;
    }
    
    /* Touch-friendly control sizes */
    .glass-btn {
        min-height: 44px;
        min-width: 44px;
    }
    
    input[type="range"] {
        height: 6px;
    }
    
    input[type="range"]::-webkit-slider-thumb {
        width: 20px;
        height: 20px;
    }
    
    input[type="range"]::-moz-range-thumb {
        width: 20px;
        height: 20px;
    }
    
    /* State items mobile */
    .state-item {
        padding: 12px 14px;
    }
    
    .state-color {
        width: 24px;
        height: 24px;
    }
    
    /* Rule items mobile */
    .rule-item {
        padding: 14px;
    }
    
    /* Prevent body scroll when panel is open */
    body.mobile-panel-open {
        overflow: hidden;
    }
}

/* Extra small mobile tweaks */
@media (max-width: 400px) {
    .mobile-slide-panel {
        width: 100%;
        max-width: none;
    }
    
    .mobile-quick-bar .glass-btn {
        padding: 12px 6px;
        font-size: 1rem;
    }
    
    .bottom-panel {
        bottom: 65px;
        max-height: 180px;
    }
    
    .pattern-item {
        width: 50px;
        height: 50px;
    }
    
    .pattern-item canvas {
        width: 24px;
        height: 24px;
    }
}

/* ============================================
   ANIMATIONS
   ============================================ */

@keyframes glow {
    0%, 100% {
        box-shadow: 0 0 5px currentColor;
    }
    50% {
        box-shadow: 0 0 20px currentColor, 0 0 30px currentColor;
    }
}

.state-color {
    animation: glow 2s ease-in-out infinite;
}

/* Fade in animation for panels */
.glass-panel:not(.help-panel):not(.audio-modal):not(.bottom-panel) {
    animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
