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

:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #8b5cf6;
    --accent-color: #06b6d4;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --error-color: #ef4444;
    --background: #0f172a;
    --surface: #1e293b;
    --surface-light: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border-color: #475569;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -2px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -4px rgba(0, 0, 0, 0.2);
    --radius: 12px;
    --radius-sm: 8px;
    --transition: all 0.2s ease;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* App Container */
.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    text-align: center;
    padding: 2rem 1rem;
    margin-bottom: 1rem;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color), var(--accent-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

/* Main Content */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Card Component */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
}

.card h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.card h3 {
    font-size: 1rem;
    font-weight: 500;
    margin-bottom: 0.75rem;
    color: var(--text-secondary);
}

.section-info {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

/* Controls */
.controls-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex: 1;
    min-width: 150px;
}

.control-group label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
}

select, input[type="range"] {
    width: 100%;
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background: var(--surface-light);
    color: var(--text-primary);
    font-size: 1rem;
    transition: var(--transition);
    cursor: pointer;
}

select:hover, select:focus {
    border-color: var(--primary-color);
    outline: none;
}

select:focus {
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    height: 8px;
    padding: 0;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    transition: var(--transition);
}

input[type="range"]::-webkit-slider-thumb:hover {
    background: var(--primary-hover);
    transform: scale(1.1);
}

input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    border: none;
}

/* Notes Display */
.notes-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.note-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 48px;
    padding: 0.5rem 0.75rem;
    background: var(--surface-light);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 0.95rem;
    transition: var(--transition);
}

.note-badge.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.note-badge.root {
    background: var(--secondary-color);
    border-color: var(--secondary-color);
    color: white;
}

.scale-display {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

/* Chord Grid */
.chord-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 1rem;
}

.chord-card {
    background: var(--surface-light);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 1rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
}

.chord-card:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.chord-card.selected {
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.1);
}

.chord-card .chord-numeral {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.chord-card .chord-name {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.chord-card .chord-type {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Chord Detail Section */
.chord-detail-content {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.chord-name-display {
    text-align: center;
    padding: 1rem;
    background: var(--surface-light);
    border-radius: var(--radius-sm);
}

#selected-chord-name {
    font-size: 2rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Inversion Buttons */
.inversion-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.inversion-btn {
    flex: 1;
    min-width: 120px;
    padding: 0.75rem 1rem;
    background: var(--surface-light);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.875rem;
    cursor: pointer;
    transition: var(--transition);
}

.inversion-btn:hover {
    border-color: var(--primary-color);
}

.inversion-btn.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

/* Progression Section */
.progression-controls {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    align-items: flex-end;
    margin-bottom: 1.5rem;
}

.progression-display {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    padding: 1rem;
    background: var(--surface-light);
    border-radius: var(--radius-sm);
    min-height: 80px;
    margin-bottom: 1.5rem;
}

.progression-chord {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    min-width: 80px;
    transition: var(--transition);
}

.progression-chord.playing {
    border-color: var(--accent-color);
    background: rgba(6, 182, 212, 0.1);
    box-shadow: 0 0 15px rgba(6, 182, 212, 0.3);
}

.progression-chord .numeral {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.progression-chord .name {
    font-size: 1.1rem;
    font-weight: 600;
}

.progression-arrow {
    display: flex;
    align-items: center;
    color: var(--text-muted);
    font-size: 1.25rem;
}

/* Custom Progression */
.custom-progression {
    border-top: 1px solid var(--border-color);
    padding-top: 1.5rem;
}

.custom-progression-controls {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.progression-slots {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 1rem;
    background: var(--surface-light);
    border-radius: var(--radius-sm);
    min-height: 60px;
    border: 2px dashed var(--border-color);
}

.progression-slot {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-weight: 500;
}

.progression-slot .remove-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem;
    font-size: 1rem;
    line-height: 1;
    transition: var(--transition);
}

.progression-slot .remove-btn:hover {
    color: var(--error-color);
}

.custom-buttons {
    display: flex;
    gap: 0.75rem;
}

.hint {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-top: 0.5rem;
}

/* Buttons */
.play-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.play-btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-lg);
}

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

.play-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.play-btn.playing {
    background: linear-gradient(135deg, var(--accent-color), var(--success-color));
}

.secondary-btn {
    padding: 0.75rem 1.5rem;
    background: var(--surface-light);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 1rem;
    cursor: pointer;
    transition: var(--transition);
}

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

/* Audio Controls */
.audio-controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
}

.audio-controls .control-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

#volume-display, #tempo-display {
    font-size: 0.875rem;
    color: var(--accent-color);
    font-weight: 500;
}

/* Piano Keyboard */
.keyboard-container {
    overflow-x: auto;
    padding: 1rem 0;
}

.piano-keyboard {
    display: flex;
    justify-content: center;
    min-width: 600px;
    height: 150px;
    position: relative;
}

.white-key {
    width: 45px;
    height: 150px;
    background: linear-gradient(to bottom, #f8f8f8, #fff);
    border: 1px solid #ccc;
    border-radius: 0 0 6px 6px;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    z-index: 1;
}

.white-key:hover {
    background: linear-gradient(to bottom, #e8e8e8, #f0f0f0);
}

.white-key.active {
    background: linear-gradient(to bottom, var(--primary-color), var(--secondary-color));
    border-color: var(--primary-color);
}

.black-key {
    width: 30px;
    height: 95px;
    background: linear-gradient(to bottom, #333, #000);
    border: 1px solid #000;
    border-radius: 0 0 4px 4px;
    cursor: pointer;
    transition: var(--transition);
    position: absolute;
    z-index: 2;
    margin-left: -15px;
}

.black-key:hover {
    background: linear-gradient(to bottom, #444, #222);
}

.black-key.active {
    background: linear-gradient(to bottom, var(--secondary-color), var(--primary-color));
}

.key-label {
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.7rem;
    color: #666;
    pointer-events: none;
}

.black-key .key-label {
    color: #aaa;
    bottom: 5px;
    font-size: 0.6rem;
}

/* Footer */
footer {
    margin-top: 2rem;
    padding: 1.5rem;
    text-align: center;
    border-top: 1px solid var(--border-color);
}

footer p {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: var(--transition);
}

footer a:hover {
    color: var(--secondary-color);
    text-decoration: underline;
}

/* Responsive Design */
@media (max-width: 768px) {
    .app-container {
        padding: 0.75rem;
    }

    header h1 {
        font-size: 1.75rem;
    }

    .subtitle {
        font-size: 0.95rem;
    }

    .card {
        padding: 1rem;
    }

    .chord-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 0.75rem;
    }

    .chord-card {
        padding: 0.75rem;
    }

    .chord-card .chord-name {
        font-size: 1rem;
    }

    #selected-chord-name {
        font-size: 1.5rem;
    }

    .progression-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .play-btn {
        width: 100%;
        justify-content: center;
    }

    .inversion-buttons {
        flex-direction: column;
    }

    .inversion-btn {
        min-width: auto;
    }

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

    .white-key {
        width: 35px;
        height: 120px;
    }

    .black-key {
        width: 24px;
        height: 75px;
        margin-left: -12px;
    }

    .piano-keyboard {
        height: 120px;
        min-width: 500px;
    }
}

@media (max-width: 480px) {
    header {
        padding: 1rem;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .controls-row {
        flex-direction: column;
    }

    .control-group {
        min-width: 100%;
    }

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

    .custom-buttons {
        flex-direction: column;
    }

    .white-key {
        width: 28px;
        height: 100px;
    }

    .black-key {
        width: 20px;
        height: 60px;
        margin-left: -10px;
    }

    .piano-keyboard {
        height: 100px;
        min-width: 400px;
    }

    .key-label {
        display: none;
    }
}

/* Animations */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.playing {
    animation: pulse 0.5s ease-in-out;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--surface);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}
