:root {
    --bg-dark: #0f172a;
    --bg-panel: rgba(30, 41, 59, 0.7);
    --border-color: rgba(255, 255, 255, 0.1);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --accent-primary: #3b82f6;
    --accent-hover: #2563eb;
    --accent-gradient: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
    --danger: #ef4444;
    --success: #10b981;
    --glass-blur: blur(12px);
    
    --sidebar-width: 280px;
    --border-radius-lg: 16px;
    --border-radius-md: 10px;
    --transition: all 0.3s ease;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    overflow: hidden;
    height: 100vh;
    font-size: 14px;
    background-image: 
        radial-gradient(at 0% 0%, rgba(59, 130, 246, 0.15) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(139, 92, 246, 0.15) 0px, transparent 50%);
}

.app-wrapper {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Sidebar Styles */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-panel);
    backdrop-filter: var(--glass-blur);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 24px 16px;
    z-index: 10;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 40px;
    padding: 0 8px;
    color: var(--accent-primary);
}

.nav-links {
    list-style: none;
    flex: 1;
}

.nav-links li {
    padding: 12px 16px;
    margin-bottom: 8px;
    border-radius: var(--border-radius-md);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-muted);
    font-weight: 500;
}

.nav-links li:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}

.nav-links li.active {
    background: var(--accent-gradient);
    color: white;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.audio-control {
    margin-top: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.audio-volume-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
}

.audio-volume-label {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}

.audio-volume-row .volume-slider {
    flex: 1;
    height: 4px;
}

.volume-badge {
    font-size: 11px;
    min-width: 36px;
    text-align: center;
}

.audio-status {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
}

.status-indicator {
    font-weight: 600;
}
.status-indicator.off { color: var(--danger); }
.status-indicator.on { color: var(--success); }

.btn {
    border: none;
    padding: 12px 16px;
    border-radius: var(--border-radius-md);
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: var(--transition);
}

.btn.primary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    border: 1px solid var(--border-color);
}

.btn.primary:hover {
    background: rgba(255, 255, 255, 0.2);
}

.btn.active-play {
    background: var(--success);
    color: white;
    border-color: transparent;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

/* Glassmorphism utility */
.card-glass {
    background: var(--bg-panel);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
}

/* Main Workspace */
.main-workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 24px;
    gap: 24px;
    overflow-y: auto;
}

.top-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

#mode-title {
    font-size: 28px;
    font-weight: 600;
    margin-bottom: 4px;
}

.text-muted {
    color: var(--text-muted);
}

.formula-container {
    padding: 16px 32px;
    font-size: 1.1em;
    min-width: 300px;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.canvas-wrapper {
    flex: 1;
    min-height: 400px;
    position: relative;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

canvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* Controls Panel */
.controls-panel {
    padding: 20px 24px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.controls-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px;
}

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

.label-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 500;
}

.val-badge {
    background: rgba(0, 0, 0, 0.3);
    padding: 4px 8px;
    border-radius: 6px;
    font-family: monospace;
    font-size: 12px;
    color: var(--text-main);
}

/* Custom Sliders */
.custom-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    outline: none;
}

.custom-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent-primary);
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.4);
}

.custom-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    background: #60a5fa;
}

/* Dynamic controls specific utilities */
.radio-group {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.radio-btn {
    flex: 1;
    padding: 8px;
    text-align: center;
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--border-radius-md);
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid transparent;
}

.radio-btn.active {
    background: rgba(59, 130, 246, 0.2);
    border-color: var(--accent-primary);
    color: white;
}

/* Controls Tabs */
.controls-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 12px;
}

.tab-btn {
    flex: 1;
    padding: 10px 16px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--border-radius-md);
    color: var(--text-muted);
    font-weight: 500;
    font-size: 13px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

.tab-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}

.tab-btn.active {
    background: rgba(59, 130, 246, 0.15);
    border-color: var(--accent-primary);
    color: var(--text-main);
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.2);
}

.tab-content {
    display: none;
}

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

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

/* Volume slider accent */
.volume-slider::-webkit-slider-thumb {
    background: var(--success) !important;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.4) !important;
}

.volume-slider::-webkit-slider-thumb:hover {
    background: #34d399 !important;
}

/* ===== Playback Controls Overlay ===== */
.playback-controls {
    position: absolute;
    bottom: 16px;
    right: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    padding: 8px 14px;
    z-index: 5;
}

.pb-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid transparent;
    color: var(--text-muted);
    font-size: 18px;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.pb-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: var(--text-main);
}

.pb-btn-main {
    background: var(--accent-primary);
    color: white;
    font-size: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    box-shadow: 0 2px 10px rgba(59, 130, 246, 0.35);
}

.pb-btn-main:hover {
    background: var(--accent-hover);
    color: white;
}

.pb-btn-main.paused {
    background: var(--success);
    box-shadow: 0 2px 10px rgba(16, 185, 129, 0.35);
}

.pb-speed {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: 6px;
    padding-left: 10px;
    border-left: 1px solid var(--border-color);
}

.pb-speed-label {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
}

.pb-slider {
    -webkit-appearance: none;
    width: 80px;
    height: 4px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 2px;
    outline: none;
}

.pb-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent-primary);
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(59, 130, 246, 0.4);
}

.pb-speed-val {
    font-family: monospace;
    font-size: 12px;
    color: var(--accent-primary);
    min-width: 36px;
    text-align: right;
    font-weight: 600;
}

/* ===== Real-time Calculation Panel ===== */
.calc-panel {
    padding: 16px 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.calc-panel-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-muted);
}

.calc-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 10px;
}

.calc-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0, 0, 0, 0.25);
    border-radius: 8px;
    padding: 10px 14px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    transition: border-color 0.3s ease;
}

.calc-item:hover {
    border-color: rgba(59, 130, 246, 0.3);
}

.calc-label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}

.calc-label .calc-symbol {
    color: var(--accent-primary);
    font-weight: 700;
    font-size: 14px;
    margin-right: 4px;
}

.calc-value {
    font-family: 'Inter', monospace;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-main);
    transition: color 0.3s ease, text-shadow 0.3s ease;
}

.calc-value.flash {
    color: #60a5fa;
    text-shadow: 0 0 8px rgba(96, 165, 250, 0.5);
}

.calc-unit {
    font-size: 11px;
    color: var(--text-muted);
    margin-left: 3px;
    font-weight: 400;
}

/* ===== Responsive Layout (Mobile / Smartphone) ===== */
@media (max-width: 768px) {
    body {
        height: auto;
        overflow-y: auto;
    }

    .app-wrapper {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }

    .sidebar {
        width: 100%;
        padding: 12px 16px;
        flex-direction: column;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .logo {
        margin-bottom: 16px;
        justify-content: center;
    }

    .nav-links {
        display: flex;
        flex-direction: row;
        overflow-x: auto;
        gap: 8px;
        padding-bottom: 8px;
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    }

    .nav-links li {
        margin-bottom: 0;
        flex: 0 0 auto;
        white-space: nowrap;
        padding: 10px 14px;
        font-size: 13px;
    }

    .audio-control {
        margin-top: 12px;
        padding: 12px;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: space-between;
        align-items: center;
        gap: 8px;
    }

    .audio-status {
        width: 100%;
        margin-bottom: 4px;
    }

    .audio-volume-row {
        flex: 1;
        min-width: 150px;
    }

    .btn {
        flex: 1;
        min-width: 120px;
    }

    .main-workspace {
        padding: 16px;
        gap: 16px;
    }

    .top-header {
        flex-direction: column;
        gap: 12px;
    }

    #mode-title {
        font-size: 22px;
    }

    .formula-container {
        width: 100%;
        padding: 12px;
        font-size: 1em;
        overflow-x: auto;
        min-width: auto;
    }

    .canvas-wrapper {
        min-height: 300px;
        max-height: 40vh;
    }

    .playback-controls {
        bottom: 8px;
        right: 8px;
        padding: 6px 10px;
        transform: scale(0.9);
        transform-origin: bottom right;
    }

    .controls-grid {
        grid-template-columns: 1fr;
    }

    .calc-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}
