/**
 * Global Styles and CSS Custom Properties (Design System)
 */

:root {
    /* Color Palette - Dark Premium Theme */
    --bg-main: #0B0F19;
    /* Deep Navy/Black */
    --bg-surface: rgba(22, 28, 45, 0.7);
    /* Translucent Surface */
    --bg-surface-hover: rgba(30, 38, 56, 0.9);

    --text-primary: #F8FAFC;
    --text-secondary: #94A3B8;

    --accent-primary: #00E5FF;
    /* Electric Cyan */
    --accent-primary-hover: #00C4DF;
    --accent-secondary: #FF007F;
    /* Magenta */

    --border-color: rgba(255, 255, 255, 0.1);

    --success: #10B981;
    --warning: #F59E0B;
    --error: #EF4444;

    /* Typography */
    --font-ui: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'Space Mono', monospace;

    /* Geometry & Spacing */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-pill: 9999px;

    /* Effects */
    --glass-blur: blur(12px);
    --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.2), 0 4px 6px -2px rgba(0, 0, 0, 0.1);
    --shadow-glow: 0 0 15px rgba(0, 229, 255, 0.3);

    --transition-fast: 0.15s ease-out;
    --transition-base: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Light Theme Variables (Generated dynamically or triggered via class) */
[data-theme="light"] {
    --bg-main: #F1F5F9;
    --bg-surface: rgba(255, 255, 255, 0.8);
    --bg-surface-hover: rgba(255, 255, 255, 1);

    --text-primary: #0F172A;
    --text-secondary: #64748B;

    --border-color: rgba(0, 0, 0, 0.1);
    --shadow-glow: 0 0 15px rgba(0, 229, 255, 0.15);
}

/**
 * Reset & Base
 */
* {
    box-sizing: border-box;
}

.music-tools-wrapper {
    font-family: var(--font-ui);
    background-color: var(--bg-main);
    color: var(--text-primary);
    min-height: 800px;
    height: 90vh;
    overflow: hidden;
    /* App container handles internal scrolling */
    position: relative;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    transition: background-color var(--transition-base), color var(--transition-base);
}

/* Base Theme Switching (Triggered via class on the wrapper instead of body) */
.music-tools-wrapper.light-theme {
    --bg-main: #F1F5F9;
    --bg-surface: rgba(255, 255, 255, 0.8);
    --bg-surface-hover: rgba(255, 255, 255, 1);

    --text-primary: #0F172A;
    --text-secondary: #64748B;

    --border-color: rgba(0, 0, 0, 0.1);
    --shadow-glow: 0 0 15px rgba(0, 229, 255, 0.15);
}

/* Scrollbar scoped */
.music-tools-wrapper ::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.music-tools-wrapper ::-webkit-scrollbar-track {
    background: transparent;
}

.music-tools-wrapper ::-webkit-scrollbar-thumb {
    background: var(--bg-surface-hover);
    border-radius: var(--radius-pill);
}

.music-tools-wrapper ::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/**
 * Utility Classes
 */
.glass-panel {
    background: var(--bg-surface);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

.mono-text {
    font-family: var(--font-mono);
}

/**
 * Typography 
 */
h1,
h2,
h3,
h4,
h5,
h6 {
    font-weight: 600;
    line-height: 1.2;
}

p {
    line-height: 1.6;
    color: var(--text-secondary);
}

/**
 * Buttons & Inputs scoped
 */
.music-tools-wrapper button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    outline: none;
    background: transparent;
    color: inherit;
    transition: all var(--transition-fast);
}

.primary-btn {
    background: var(--accent-primary);
    color: #0B0F19;
    /* Always dark text on cyan */
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-pill);
    font-weight: 600;
    box-shadow: 0 4px 14px rgba(0, 229, 255, 0.4);
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.primary-btn:hover {
    background: var(--accent-primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 229, 255, 0.6);
}

.secondary-btn {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-pill);
    font-weight: 500;
}

.secondary-btn:hover {
    background: var(--bg-surface-hover);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    font-size: 1.2rem;
}

.icon-btn:hover {
    background: var(--bg-surface-hover);
    color: var(--accent-primary);
    box-shadow: var(--shadow-glow);
}

.pulse-glow {
    animation: pulseGlow 2s infinite;
}

@keyframes pulseGlow {
    0% {
        box-shadow: 0 0 0 0 rgba(0, 229, 255, 0.4);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(0, 229, 255, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(0, 229, 255, 0);
    }
}

/**
 * Layout Structure
 */
.music-tools-wrapper .app-container {
    display: flex;
    height: 100%;
}

/* Sidebar */
.sidebar {
    width: 280px;
    height: 100%;
    background: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform var(--transition-base);
}

.logo {
    padding: 2rem 1.5rem;
    font-size: 1.5rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--accent-primary);
    border-bottom: 1px solid var(--border-color);
}

.nav-links {
    list-style: none;
    padding: 1rem 0;
    overflow-y: auto;
    flex: 1;
}

.nav-item {
    padding: 0 1rem;
    margin-bottom: 0.25rem;
}

.nav-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.8rem 1rem;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 0.95rem;
    text-align: left;
}

.nav-btn:hover {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
}

.nav-btn.active {
    background: rgba(0, 229, 255, 0.1);
    color: var(--accent-primary);
    font-weight: 600;
    border-left: 3px solid var(--accent-primary);
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

.nav-btn i {
    width: 20px;
    text-align: center;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.topbar {
    height: 80px;
    padding: 0 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
    background: rgba(11, 15, 25, 0.8);
    backdrop-filter: var(--glass-blur);
    z-index: 50;
}

.mobile-menu-btn {
    display: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.tool-container {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    position: relative;
}

/**
 * Dashboard Grid
 */
.dashboard-view {
    display: none;
}

.dashboard-view.active {
    display: block;
    animation: fadeIn var(--transition-base);
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.hero-section {
    margin-bottom: 3rem;
    text-align: center;
}

.hero-section h2 {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    background: linear-gradient(135deg, var(--text-primary), var(--accent-primary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.tool-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}

.tool-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    cursor: pointer;
    transition: all var(--transition-base);
    display: flex;
    flex-direction: column;
    gap: 1rem;
    position: relative;
    overflow: hidden;
}

.tool-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at 50% 0%, rgba(0, 229, 255, 0.1), transparent 70%);
    opacity: 0;
    transition: opacity var(--transition-base);
}

.tool-card:hover {
    transform: translateY(-5px);
    border-color: rgba(0, 229, 255, 0.3);
    box-shadow: var(--shadow-md), var(--shadow-glow);
}

.tool-card:hover::before {
    opacity: 1;
}

.tool-icon {
    width: 50px;
    height: 50px;
    background: rgba(0, 229, 255, 0.1);
    color: var(--accent-primary);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.tool-info h3 {
    margin-bottom: 0.5rem;
    font-size: 1.2rem;
}

.tool-info p {
    font-size: 0.9rem;
    line-height: 1.4;
}

/**
 * Tool Sections (Common structure)
 */
.tool-section {
    display: none;
    max-width: 1200px;
    margin: 0 auto;
}

.tool-section.active {
    display: block;
    animation: fadeIn var(--transition-base);
}

/* Helper hidden class */
.hidden {
    display: none !important;
}

/**
 * Tool Specific Styles
 */

/* Metronome / Sliders */
.slider {
    -webkit-appearance: none;
    width: 100%;
    max-width: 400px;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-pill);
    outline: none;
    margin: 2rem auto;
    display: block;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--accent-primary);
    cursor: pointer;
    box-shadow: var(--shadow-glow);
}

.metronome-display {
    text-align: center;
}

.bpm-value {
    font-size: 6rem;
    font-weight: 700;
    color: var(--text-primary);
}

.bpm-label {
    font-size: 1.2rem;
    color: var(--text-secondary);
    letter-spacing: 2px;
    text-transform: uppercase;
}

.metronome-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.metronome-settings {
    text-align: center;
    display: flex;
    justify-content: center;
    gap: 1rem;
}

.visual-beats {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 2rem;
}

.beat-dot {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    transition: all 0.1s;
}

.beat-dot.active {
    background: var(--accent-primary);
    box-shadow: var(--shadow-glow);
    transform: scale(1.3);
}

/* Tuner */
.tuner-display {
    text-align: center;
    margin: 3rem 0;
}

.tuner-note {
    font-size: 8rem;
    font-weight: 700;
    color: var(--text-primary);
    transition: color var(--transition-base);
}

.tuner-cents-val {
    font-size: 1.5rem;
    font-family: var(--font-mono);
    color: var(--text-secondary);
}

.tuner-meter {
    width: 100%;
    max-width: 500px;
    height: 30px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-pill);
    margin: 0 auto;
    position: relative;
    overflow: hidden;
}

.tuner-meter::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--success);
    transform: translateX(-50%);
    box-shadow: 0 0 10px var(--success);
}

.tuner-dial {
    position: absolute;
    left: 50%;
    top: -15px;
    width: 4px;
    height: 60px;
    background: var(--text-primary);
    transform-origin: bottom center;
    transform: translateX(-50%) rotate(0deg);
    transition: transform 0.1s ease-out;
}

.pitch-labels {
    display: flex;
    justify-content: space-between;
    max-width: 520px;
    margin: 0.5rem auto 0;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Forms & Inputs */
.dropdown {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    font-family: inherit;
    outline: none;
}

.text-input {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    font-family: inherit;
    outline: none;
}

.text-input:focus,
.dropdown:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(0, 229, 255, 0.2);
}

/* Theory Tools */
.selectors {
    display: flex;
    justify-content: center;
    gap: 1rem;
    align-items: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

.notes-display {
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.notes-display.small {
    gap: 0.5rem;
}

.note-box {
    background: rgba(0, 229, 255, 0.1);
    border: 1px solid rgba(0, 229, 255, 0.3);
    color: var(--accent-primary);
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 700;
    border-radius: var(--radius-md);
}

.notes-display.small .note-box {
    width: auto;
    height: 30px;
    padding: 0 10px;
    font-size: 1rem;
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
}

.glossary-item {
    padding: 1.5rem;
    margin-bottom: 1rem;
    text-align: left;
}

.glossary-item h4 {
    color: var(--accent-primary);
    margin-bottom: 0.5rem;
    font-size: 1.2rem;
}

.grid-layout {
    display: grid;
    gap: 2rem;
}

.grid-layout.cols-2 {
    grid-template-columns: 1fr 1fr;
}

.badge {
    background: rgba(255, 0, 127, 0.2);
    color: var(--accent-secondary);
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius-pill);
    font-size: 0.85rem;
    font-weight: 600;
}

/* Tables */
.data-table {
    border-collapse: collapse;
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.data-table th,
.data-table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.data-table th {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
    font-weight: 600;
}

.data-table tr:last-child td {
    border-bottom: none;
}

/* Virtual Keyboard */
.keyboard-container {
    display: inline-flex;
    justify-content: center;
    position: relative;
    height: 180px;
    margin-top: 2rem;
}

.piano-key {
    display: inline-flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    border-radius: 0 0 5px 5px;
    border: none;
    outline: none;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.5);
    transition: background 0.1s;
    user-select: none;
    position: relative;
}

.white-key {
    width: 50px;
    height: 180px;
    background: #F8FAFC;
    color: #0B0F19;
    z-index: 1;
    border: 1px solid #ccc;
}

.white-key.active,
.white-key:active {
    background: #E2E8F0;
    height: 178px;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.2);
}

.black-key {
    width: 30px;
    height: 110px;
    background: #0F172A;
    color: #F8FAFC;
    z-index: 2;
    margin-left: -15px;
    margin-right: -15px;
    box-shadow: inset 0 -4px 6px rgba(255, 255, 255, 0.2);
}

.black-key.active,
.black-key:active {
    background: #1E293B;
    height: 108px;
    box-shadow: inset 0 -2px 4px rgba(255, 255, 255, 0.1);
}

.key-label {
    padding-bottom: 10px;
    font-size: 0.8rem;
    font-weight: 700;
    opacity: 0.5;
}

/* Drum Machine */
.drum-pad {
    width: 100%;
    aspect-ratio: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.1s;
}

.drum-pad-beat {
    background: rgba(255, 255, 255, 0.1);
}

.drum-pad:hover {
    background: rgba(255, 255, 255, 0.2);
}

.drum-pad.active {
    background: var(--accent-primary);
    box-shadow: var(--shadow-glow);
}

.drum-pad.playing {
    transform: scale(0.9);
    filter: brightness(1.5);
    border-color: #fff;
}

/* Stats */
.stat-box {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    padding: 1rem;
    border-radius: var(--radius-md);
    text-align: center;
}

.stat-box h4 {
    color: var(--text-secondary);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-primary);
}

/**
 * Responsive
 */
@media (max-width: 1024px) {
    .tool-grid {
        grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    }
}

@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }

    .sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        width: 260px;
        box-shadow: var(--shadow-md);
    }

    .sidebar.open {
        left: 0;
    }

    .mobile-menu-btn {
        display: block;
    }

    .topbar {
        padding: 0 1rem;
    }

    .tool-container {
        padding: 1rem;
    }
}