* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: #333;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

.header {
    text-align: center;
    color: white;
    margin-bottom: 24px;
}

.header h1 {
    font-size: 2.8rem;
    margin-bottom: 6px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
    letter-spacing: 1px;
}

.header p {
    font-size: 1.1rem;
    opacity: 0.9;
}

/* Mode selector */
.mode-selector {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 20px;
}

.mode-btn {
    padding: 10px 24px;
    border: 2px solid rgba(255,255,255,0.4);
    border-radius: 24px;
    background: rgba(255,255,255,0.15);
    color: white;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.25s ease;
    font-weight: 500;
}

.mode-btn:hover {
    background: rgba(255,255,255,0.3);
    border-color: rgba(255,255,255,0.7);
}

.mode-btn.active {
    background: white;
    color: #667eea;
    border-color: white;
    font-weight: 600;
}

/* Challenge card */
.challenge-card {
    background: white;
    border-radius: 16px;
    box-shadow: 0 16px 48px rgba(0,0,0,0.12);
    padding: 32px;
    margin-bottom: 24px;
}

.challenge-info {
    text-align: center;
    margin-bottom: 20px;
}

.challenge-title {
    font-size: 1.5rem;
    color: #4a5568;
    margin-bottom: 4px;
}

.segment-meta {
    display: flex;
    justify-content: center;
    gap: 16px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.meta-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 12px;
    background: #f0f4ff;
    border-radius: 16px;
    font-size: 0.85rem;
    color: #4a5568;
}

.difficulty-badge {
    padding: 4px 14px;
    border-radius: 16px;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: capitalize;
}

.difficulty-badge.easy { background: #d4edda; color: #155724; }
.difficulty-badge.intermediate { background: #fff3cd; color: #856404; }
.difficulty-badge.advanced { background: #f8d7da; color: #721c24; }

/* Music display */
.music-container {
    text-align: center;
    margin: 20px -32px;
    padding: 16px;
    background: #f7fafc;
    border-radius: 10px;
    border: 2px dashed #e2e8f0;
    min-height: 120px;
    overflow-x: auto;
}

.music-sheet {
    width: 100%;
    min-width: 700px;
    height: auto;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.08);
    background: white;
    padding: 8px;
}

.osmd-container {
    width: 100%;
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.08);
    min-height: 150px;
}

.loading {
    font-size: 1.1rem;
    color: #718096;
    text-align: center;
    padding: 40px;
}

/* Tempo control */
.tempo-control {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin: 18px 0;
    padding: 14px 20px;
    background: #f0f4ff;
    border-radius: 12px;
    flex-wrap: wrap;
}

.tempo-control label {
    font-weight: 600;
    color: #4a5568;
    font-size: 0.95rem;
}

.tempo-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 200px;
    height: 6px;
    background: #cbd5e0;
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

.tempo-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: #667eea;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(102, 126, 234, 0.4);
    transition: transform 0.15s ease;
}

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

.tempo-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: #667eea;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(102, 126, 234, 0.4);
}

.tempo-display {
    font-size: 1.1rem;
    font-weight: 700;
    color: #4a5568;
    min-width: 110px;
    text-align: center;
}

.btn-small {
    padding: 5px 12px;
    font-size: 0.8rem;
    border-radius: 6px;
}

.btn-metronome {
    background: #edf2f7;
    color: #4a5568;
    border: 2px solid #cbd5e0;
}

.btn-metronome:hover {
    background: #e2e8f0;
    border-color: #a0aec0;
}

.btn-metronome.active {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

/* Controls */
.controls {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 20px;
    flex-wrap: wrap;
}

.btn {
    padding: 10px 22px;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 500;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5a67d8;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #e2e8f0;
    color: #4a5568;
}

.btn-secondary:hover {
    background: #cbd5e0;
    transform: translateY(-1px);
}

.btn-record {
    background: #e53e3e;
    color: white;
    font-size: 1rem;
    padding: 12px 28px;
}

.btn-record:hover {
    background: #c53030;
    box-shadow: 0 4px 12px rgba(229, 62, 62, 0.4);
}

.btn-record.recording {
    animation: pulse-record 1.5s infinite;
}

@keyframes pulse-record {
    0%, 100% { box-shadow: 0 0 0 0 rgba(229, 62, 62, 0.5); }
    50% { box-shadow: 0 0 0 12px rgba(229, 62, 62, 0); }
}

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

/* Recording status */
.recording-status {
    text-align: center;
    padding: 16px;
    margin: 16px 0;
    background: #fff5f5;
    border: 2px solid #fc8181;
    border-radius: 10px;
}

.recording-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    color: #c53030;
}

.recording-dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    background: #e53e3e;
    border-radius: 50%;
    animation: pulse 1s infinite;
}

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

.countdown-display {
    font-size: 3.5rem;
    font-weight: bold;
    color: #e53e3e;
    text-align: center;
    padding: 20px;
}

/* Score results */
.score-results {
    background: #f8f9fa;
    padding: 28px;
    border-radius: 14px;
    margin: 20px 0;
}

.overall-score {
    text-align: center;
    margin-bottom: 24px;
}

.overall-score .score-number {
    font-size: 3.5rem;
    font-weight: 800;
    background: linear-gradient(135deg, #667eea, #764ba2);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.overall-score .score-label {
    font-size: 1rem;
    color: #718096;
    display: block;
}

.score-breakdown {
    max-width: 420px;
    margin: 0 auto 20px;
}

.score-item {
    display: flex;
    align-items: center;
    margin: 12px 0;
    gap: 12px;
}

.score-category {
    min-width: 110px;
    text-align: left;
    font-weight: 500;
    font-size: 0.95rem;
}

.score-bar {
    flex: 1;
    height: 18px;
    background: #e2e8f0;
    border-radius: 9px;
    overflow: hidden;
}

.score-fill {
    height: 100%;
    background: linear-gradient(90deg, #667eea, #764ba2);
    border-radius: 9px;
    transition: width 1s ease-in-out;
    width: 0%;
}

.score-value {
    min-width: 42px;
    font-weight: 700;
    color: #4a5568;
    text-align: right;
    font-size: 0.95rem;
}

/* Score summary */
#score-summary {
    text-align: center;
    margin: 16px 0;
    font-size: 1.05rem;
    line-height: 1.8;
}

#score-summary .correct { color: #2d8a4e; font-weight: 600; }
#score-summary .wrong { color: #d63031; font-weight: 600; }
#score-summary .octave { color: #b8860b; font-weight: 600; }
#score-summary .missed { color: #888; font-weight: 600; }
#score-summary .extra { color: #e67e22; font-weight: 600; }

/* Per-note feedback table */
.note-details-container {
    margin-top: 20px;
    max-height: 320px;
    overflow-y: auto;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
}

.note-details-container table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.note-details-container thead {
    position: sticky;
    top: 0;
    z-index: 1;
}

.note-details-container th {
    padding: 10px 12px;
    background: #edf2f7;
    text-align: left;
    font-weight: 600;
    color: #4a5568;
    border-bottom: 2px solid #cbd5e0;
}

.note-details-container td {
    padding: 8px 12px;
    border-bottom: 1px solid #edf2f7;
}

.note-correct td { color: #2d8a4e; }
.note-wrong_octave td { color: #e67e22; }
.note-wrong_pitch td { color: #d63031; }
.note-missed td { color: #888; font-style: italic; }
.note-extra td { color: #e67e22; }

.status-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
}

.status-badge.correct { background: #d4edda; color: #155724; }
.status-badge.wrong_octave { background: #ffeaa7; color: #6c5500; }
.status-badge.wrong_pitch { background: #f8d7da; color: #721c24; }
.status-badge.missed { background: #e2e3e5; color: #383d41; }
.status-badge.extra { background: #fff3cd; color: #856404; }

/* Feedback text */
.feedback {
    margin: 20px 0;
    padding: 16px;
    background: white;
    border-radius: 10px;
    border-left: 4px solid #667eea;
}

.feedback-item {
    margin: 8px 0;
    font-size: 1rem;
}

/* Loading overlay */
.loading-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-spinner {
    background: white;
    padding: 36px 48px;
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.spinner-ring {
    width: 48px;
    height: 48px;
    border: 4px solid #e2e8f0;
    border-top-color: #667eea;
    border-radius: 50%;
    margin: 0 auto 16px;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-spinner p {
    font-size: 1.1rem;
    color: #4a5568;
    font-weight: 500;
}

/* Stats (kept minimal) */

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

.error {
    background: #fed7d7;
    color: #c53030;
    padding: 15px;
    border-radius: 8px;
    text-align: center;
    margin: 20px 0;
}

/* Audio playback section */
.playback-section {
    margin: 16px 0;
    padding: 14px;
    background: #f0f8ff;
    border-radius: 8px;
    border-left: 4px solid #667eea;
}

.playback-section h4 {
    margin-bottom: 8px;
    color: #4a5568;
    font-size: 0.95rem;
}

.playback-section audio {
    width: 100%;
}

/* Challenge meta */
.challenge-meta {
    color: #718096;
    font-size: 0.95rem;
    margin-top: 4px;
}

/* Leaderboard */
.leaderboard-section {
    margin-top: 24px;
    padding: 20px;
    background: white;
    border-radius: 12px;
    border: 2px solid #e2e8f0;
    text-align: center;
}

.leaderboard-section h3 {
    color: #4a5568;
    margin-bottom: 12px;
    font-size: 1.15rem;
}

.leaderboard-message {
    font-size: 1.2rem;
    font-weight: 700;
    color: #2d8a4e;
    margin-bottom: 8px;
}

.leaderboard-stats {
    color: #718096;
    font-size: 0.95rem;
    margin-bottom: 12px;
}

.leaderboard-stats strong {
    color: #4a5568;
}

#distribution-chart {
    margin: 10px auto;
    display: block;
}

/* Responsive */
@media (max-width: 768px) {
    .header h1 {
        font-size: 2rem;
    }

    .challenge-card {
        padding: 16px;
    }

    .music-container {
        margin: 20px -16px;
    }

    .music-sheet {
        min-width: 500px;
    }

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

    .controls .btn {
        justify-content: center;
    }

    .score-item {
        flex-direction: column;
        gap: 4px;
    }

    .score-category {
        text-align: center;
    }

    .mode-selector {
        gap: 6px;
    }

    .mode-btn {
        padding: 8px 16px;
        font-size: 0.9rem;
    }

    .note-details-container {
        font-size: 0.82rem;
    }
}
