/* ===== CSS RESET & VARIABLES ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg-dark: #0f0f1a;
    --bg-card: #1a1a2e;
    --bg-hover: #252540;
    --accent: #6366f1;
    --accent-light: #818cf8;
    --accent-glow: rgba(99, 102, 241, 0.3);
    --gold: #f59e0b;
    --green: #10b981;
    --red: #ef4444;
    --text: #f1f5f9;
    --text-dim: #94a3b8;
    --border: #334155;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 20px rgba(0,0,0,0.3);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --mono: 'JetBrains Mono', monospace;
}

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

body {
    font-family: var(--font);
    background: var(--bg-dark);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

/* ===== LOADING SCREEN ===== */
#loading-screen {
    position: fixed;
    inset: 0;
    background: var(--bg-dark);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.5s, visibility 0.5s;
}

#loading-screen.hidden {
    opacity: 0;
    visibility: hidden;
}

.loader {
    position: relative;
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pulse-ring {
    position: absolute;
    width: 100%;
    height: 100%;
    border: 3px solid var(--accent);
    border-radius: 50%;
    animation: pulse 1.5s ease-out infinite;
}

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

.loader-icon {
    font-size: 2.5rem;
    animation: bounce 1s ease infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

#loading-screen h2 {
    margin-top: 1.5rem;
    font-size: 1.5rem;
    font-weight: 600;
}

#loading-screen p {
    color: var(--text-dim);
    font-size: 0.9rem;
}

/* ===== HEADER ===== */
.header {
    position: sticky;
    top: 0;
    background: rgba(15, 15, 26, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    z-index: 100;
}

.header-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 2rem;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    color: inherit;
}

.logo-icon {
    font-size: 1.75rem;
}

.logo-text {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.logo-text .accent {
    color: var(--accent);
}

.nav {
    display: flex;
    gap: 0.5rem;
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-dim);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

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

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

.menu-btn {
    display: none;
    flex-direction: column;
    gap: 5px;
    padding: 0.5rem;
    background: none;
    border: none;
    cursor: pointer;
}

.menu-btn span {
    width: 24px;
    height: 2px;
    background: var(--text);
    border-radius: 2px;
    transition: 0.3s;
}

/* Mobile Nav */
.mobile-nav {
    display: none;
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    background: var(--bg-card);
    padding: 1rem;
    flex-direction: column;
    gap: 0.5rem;
    border-bottom: 1px solid var(--border);
    z-index: 99;
    transform: translateY(-100%);
    opacity: 0;
    transition: all 0.3s;
}

.mobile-nav.open {
    transform: translateY(0);
    opacity: 1;
}

@media (max-width: 768px) {
    .nav { display: none; }
    .menu-btn { display: flex; }
    .mobile-nav { display: flex; }
}

/* ===== MAIN CONTENT ===== */
.main {
    max-width: 1000px;
    margin: 0 auto;
    padding: 2rem 1.5rem 4rem;
}

.section {
    display: none;
}

.section.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

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

.section-header {
    text-align: center;
    margin-bottom: 2rem;
}

.section-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.section-header p {
    color: var(--text-dim);
}

/* ===== CARDS ===== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.card-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

/* ===== UPLOAD AREA ===== */
.upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
}

.upload-area:hover,
.upload-area.dragover {
    border-color: var(--accent);
    background: var(--accent-glow);
}

.upload-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.upload-area h3 {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

.upload-area p {
    color: var(--text-dim);
    font-size: 0.9rem;
}

.formats {
    display: inline-block;
    margin-top: 1rem;
    padding: 0.4rem 0.8rem;
    background: var(--bg-hover);
    border-radius: 20px;
    font-size: 0.75rem;
    color: var(--text-dim);
}

/* ===== WAVEFORM ===== */
.waveform-wrap {
    background: var(--bg-dark);
    border-radius: var(--radius-sm);
    padding: 1rem;
    margin-bottom: 1rem;
}

#waveform {
    width: 100%;
    display: block;
}

/* ===== PLAYER CONTROLS ===== */
.player-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.btn-round {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-round:hover {
    background: var(--accent-light);
    transform: scale(1.05);
}

.btn-round.large {
    width: 60px;
    height: 60px;
    font-size: 1.5rem;
}

.btn-round.playing {
    background: var(--gold);
}

.time {
    font-family: var(--mono);
    font-size: 0.9rem;
    color: var(--text-dim);
    min-width: 100px;
}

.slider {
    flex: 1;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg-hover);
    border-radius: 3px;
    cursor: pointer;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s;
}

.slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

/* ===== SETTINGS ===== */
.settings-panel {
    background: var(--bg-dark);
    border-radius: var(--radius-sm);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}

.settings-panel h4,
.playback-panel h4,
.export-section h4 {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-dim);
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
}

.setting {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.setting label {
    font-size: 0.8rem;
    color: var(--text-dim);
    font-weight: 500;
}

.setting input[type="number"],
.setting select {
    padding: 0.6rem 0.8rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: inherit;
    font-size: 0.9rem;
}

.setting input[type="number"]:focus,
.setting select:focus {
    outline: none;
    border-color: var(--accent);
}

.settings-row {
    display: flex;
    gap: 2rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.settings-row .setting {
    flex: 1;
    min-width: 150px;
}

/* ===== BUTTONS ===== */
.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.9rem 1.5rem;
    background: linear-gradient(135deg, var(--accent), var(--accent-light));
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px var(--accent-glow);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.btn-full {
    width: 100%;
}

.btn-secondary {
    padding: 0.6rem 1rem;
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: inherit;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

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

.btn-small {
    padding: 0.4rem 0.8rem;
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-small:hover {
    background: var(--border);
}

.btn-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text-dim);
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-icon:hover {
    background: var(--bg-hover);
    color: var(--red);
}

.btn-group {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.btn-record {
    padding: 0.6rem 1.2rem;
    background: var(--bg-hover);
    border: 2px solid var(--red);
    border-radius: var(--radius-sm);
    color: var(--red);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-record:hover,
.btn-record.active {
    background: var(--red);
    color: white;
}

.btn-record.active {
    animation: pulse-record 1s infinite;
}

@keyframes pulse-record {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
    50% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
}

/* ===== EXPORT BUTTONS ===== */
.export-section {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

.export-btns {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.btn-export {
    flex: 1;
    min-width: 100px;
    padding: 0.8rem 1rem;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: inherit;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-export:hover {
    border-color: var(--accent);
    background: var(--accent-glow);
}

/* ===== SHEET MUSIC ===== */
.sheet-scroll {
    background: white;
    border-radius: var(--radius-sm);
    padding: 1rem;
    overflow-x: auto;
    margin-bottom: 1rem;
}

#sheet-render,
#notes-sheet-render {
    min-height: 200px;
}

#sheet-render svg,
#notes-sheet-render svg {
    display: block;
    margin: 0 auto;
}

#zoom-level {
    font-family: var(--mono);
    font-size: 0.85rem;
    min-width: 50px;
    text-align: center;
}

/* ===== CODE INPUT ===== */
.code-input {
    width: 100%;
    min-height: 150px;
    padding: 1rem;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--mono);
    font-size: 0.9rem;
    resize: vertical;
    margin-bottom: 1rem;
}

.code-input:focus {
    outline: none;
    border-color: var(--accent);
}

/* ===== PLAYBACK PANEL ===== */
.playback-panel {
    background: var(--bg-dark);
    border-radius: var(--radius-sm);
    padding: 1.25rem;
}

.playback-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

/* ===== PIANO ===== */
.piano-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.octave-control {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.piano-container {
    overflow-x: auto;
    padding: 1rem 0;
}

.piano {
    display: flex;
    position: relative;
    min-width: fit-content;
    margin: 0 auto;
}

.piano-key {
    position: relative;
    cursor: pointer;
    transition: all 0.1s;
    user-select: none;
}

.piano-key.white {
    width: 50px;
    height: 180px;
    background: linear-gradient(to bottom, #fff 0%, #f5f5f5 100%);
    border: 1px solid #ccc;
    border-radius: 0 0 6px 6px;
    z-index: 1;
}

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

.piano-key.white.active {
    background: linear-gradient(to bottom, #ddd 0%, #ccc 100%);
    transform: translateY(2px);
}

.piano-key.black {
    position: absolute;
    width: 32px;
    height: 110px;
    background: linear-gradient(to bottom, #333 0%, #000 100%);
    border-radius: 0 0 4px 4px;
    z-index: 2;
    margin-left: -16px;
}

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

.piano-key.black.active {
    background: linear-gradient(to bottom, #555 0%, #333 100%);
    height: 108px;
}

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

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

.hint {
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-top: 1rem;
}

/* Recording */
.recording-time {
    font-family: var(--mono);
    color: var(--red);
    font-weight: 600;
}

.recorded-notes {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    min-height: 50px;
    padding: 1rem;
    background: var(--bg-dark);
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
}

.note-tag {
    padding: 0.3rem 0.6rem;
    background: var(--accent-glow);
    border: 1px solid var(--accent);
    border-radius: 4px;
    font-family: var(--mono);
    font-size: 0.8rem;
}

/* ===== TOAST ===== */
#toast-container {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.toast {
    padding: 1rem 1.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    animation: slideIn 0.3s ease;
    max-width: 350px;
}

.toast.success { border-left: 4px solid var(--green); }
.toast.error { border-left: 4px solid var(--red); }
.toast.info { border-left: 4px solid var(--accent); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.toast.hide {
    animation: slideOut 0.3s ease forwards;
}

@keyframes slideOut {
    to { transform: translateX(100%); opacity: 0; }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 600px) {
    .main {
        padding: 1.5rem 1rem 3rem;
    }
    
    .card {
        padding: 1rem;
    }
    
    .upload-area {
        padding: 2rem 1rem;
    }
    
    .piano-key.white {
        width: 40px;
        height: 150px;
    }
    
    .piano-key.black {
        width: 26px;
        height: 90px;
        margin-left: -13px;
    }
    
    .export-btns {
        flex-direction: column;
    }
    
    .btn-export {
        width: 100%;
    }
    
    #toast-container {
        left: 1rem;
        right: 1rem;
        bottom: 1rem;
    }
    
    .toast {
        max-width: none;
    }
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-dark);
}

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

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