.hidden {
    display: none !important;
}

.invisible {
    visibility: hidden;
    pointer-events: none;
}

:root {
    --trainer-bg: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    --chord-box-bg: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    --chord-box-border: #f59e0b;
    --key-white: #ffffff;
    --key-black: #1e293b;
    --key-correct: #10b981;
    --key-wrong: #ef4444;
    --key-active: #7c3aed;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

body {
    margin: 0;
    padding: 0;
    font-family: var(--font-family);
    background: #f8fafc;
    color: #1e293b;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header matched to SongDetailModal */
.trainer-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px 40px;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 10;
}

.trainer-title-group {
    display: flex;
    align-items: center;
    gap: 15px;
}

.trainer-title {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 900;
    letter-spacing: -0.02em;
}

.trainer-header-actions {
    display: flex;
    gap: 8px; /* Slightly tighter */
    align-items: center;
    justify-content: flex-end; /* Push right */
    flex: 2;
}

/* Switches & Toggles */
.header-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.1);
    padding: 8px 15px;
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.2s;
    user-select: none;
    min-width: 195px;
    justify-content: center;
}

.header-toggle:hover {
    background: rgba(255, 255, 255, 0.2);
}

.header-toggle.active {
    background: rgba(255, 255, 255, 0.25);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.header-toggle .label {
    font-size: 0.85rem;
    font-weight: 700;
    color: white;
}

/* Visibility Utilities */
.mobile-only { display: none !important; }
.mobile-only-flex { display: none !important; }
.desktop-only { display: block !important; }
.desktop-only-flex { display: flex !important; }

@media (max-width: 600px) {
    .mobile-only { display: block !important; }
    .mobile-only-flex { display: flex !important; }
    .desktop-only { display: none !important; }
    .desktop-only-flex { display: none !important; }
}

/* HUD Row Layout */
.trainer-meta-row {
    padding: 10px 40px;
    background: white;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    gap: 20px;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    justify-content: flex-start;
    width: 100%;
    box-sizing: border-box;
}

.mode-selector {
    display: flex;
    gap: 8px;
    justify-content: center;
}

/* Mode Buttons - More compact tube style */
.mode-btn {
    padding: 8px 20px;
    border-radius: 40px;
    border: 2px solid #e2e8f0;
    background: white;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    font-size: 0.85rem;
    color: #475569;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    text-transform: none;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.mode-btn:hover {
    border-color: #cbd5e1;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.mode-btn.active {
    background: #facc15;
    border-color: #facc15;
    color: #1e293b;
    box-shadow: 0 6px 15px rgba(250, 204, 21, 0.4);
    transform: translateY(-2px);
}
#chordComplexityToggle {
    display: flex;
    align-items: center;
    gap: 8px;
}
.complexity-pill {
    min-width: 120px;
    padding: 6px 16px;
    border-radius: 999px;
    background: rgba(255,255,255,0.2);
    border: 2px solid rgba(255,255,255,0.3);
    color: white;
    font-weight: 800;
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
    justify-content: center;
}

/* Timer & Stats Row */
.trainer-meta-row-content { /* Renamed or adjusted to avoid conflict */
    display: flex;
    gap: 20px;
    align-items: center;
    width: 100%;
    justify-content: space-between;
}

.timer-group {
    display: flex;
    gap: 10px;
    align-items: center;
    background: #f1f5f9;
    padding: 5px;
    border-radius: 12px;
}

.timer-btn {
    padding: 8px 15px;
    border-radius: 8px;
    border: none;
    background: transparent;
    font-weight: 700;
    cursor: pointer;
    font-size: 0.85rem;
    color: #64748b;
    transition: all 0.2s;
}

.timer-btn.active {
    background: white;
    color: #4f46e5;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.countdown-display {
    font-family: 'Monaco', monospace;
    font-size: 1.5rem;
    font-weight: 800;
    color: #4f46e5;
    background: #eef2ff;
    padding: 8px 20px;
    border-radius: 12px;
    min-width: 80px;
    text-align: center;
    border: 2px solid #c7d2fe;
}

/* Main Playing Area */
.trainer-workbench {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 30px 40px;
    background: var(--trainer-bg);
    position: relative;
    overflow: hidden;
}

.chord-box-container {
    margin-bottom: 30px;
}

.workbench-center {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    gap: 20px;
}

#answerOptions {
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Mode 4 note-grid: single horizontal row of 12 note buttons like a keyboard strip */
#answerOptions.note-grid {
    position: relative;
    width: min(820px, 92%);
    flex: 0 0 auto;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.6);
    padding: 20px 16px;
    box-sizing: border-box;
    display: flex !important;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 8px;
    align-items: stretch;
    justify-content: center;
}

#answerOptions.note-grid .mode-btn {
    flex: 1;
    min-width: 0;
    font-size: 0.85rem;
    font-weight: 800;
    padding: 16px 4px;
    border-radius: 12px;
    min-height: 60px;
    background: rgba(255, 255, 255, 0.95);
    border: 2px solid rgba(255, 255, 255, 0.4);
    color: #1e293b;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    transition: all 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}

#answerOptions.note-grid .mode-btn:hover {
    background: white;
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
    border-color: white;
}

#answerOptions.note-grid .mode-btn.active {
    background: #4f46e5;
    color: white;
    border-color: #4f46e5;
    box-shadow: 0 6px 15px rgba(79, 70, 229, 0.5);
    transform: translateY(-2px);
}

#answerOptions.note-grid .mode-btn.correct {
    background: #10b981;
    color: white;
    border-color: #059669;
}

#answerOptions.note-grid .mode-btn.wrong {
    background: #ef4444;
    color: white;
    border-color: #dc2626;
}

.action-buttons {
    margin-top: auto;
    padding: 20px 0;
}

/* Chord Tip Bar */
.chord-tip-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.13);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 50px;
    padding: 9px 22px;
    width: fit-content;
    max-width: 92vw;
    box-sizing: border-box;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    opacity: 0;
    transform: translateY(6px);
    animation: tipFadeIn 0.45s cubic-bezier(0.22, 1, 0.36, 1) forwards;
    z-index: 6;
    justify-content: center;
}

.chord-tip-bar:not(.hidden) {
    display: flex;
}

@keyframes tipFadeIn {
    to { opacity: 1; transform: translateY(0); }
}

.chord-tip-icon {
    font-size: 1rem;
    flex-shrink: 0;
    line-height: 1;
}

.chord-tip-text {
    font-size: 0.82rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.92);
    line-height: 1.4;
    text-align: center;
}

@media (max-width: 600px) {
    .chord-tip-bar {
        padding: 7px 15px;
        border-radius: 14px;
    }
    .chord-tip-text {
        font-size: 0.75rem;
    }
}


/* Background Decoration */
.trainer-workbench::before {
    content: '';
    position: absolute;
    width: 150%;
    height: 150%;
    background: radial-gradient(circle at center, rgba(255, 255, 255, 0.1) 0%, transparent 70%);
    pointer-events: none;
}

/* The BIG Chord Box */
.chord-box-container {
    perspective: 1000px;
    z-index: 5;
}

.chord-box {
    width: 420px;
    height: 180px;
    background: var(--chord-box-bg);
    border: 5px solid var(--chord-box-border);
    border-radius: 28px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4), 0 0 0 8px rgba(255, 255, 255, 0.1);
    position: relative;
    transform: rotateX(10deg);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.chord-box:hover {
    transform: rotateX(0deg) scale(1.05);
}

.chord-name {
    font-size: 5rem;
    font-weight: 900;
    color: #92400e;
    margin: 0;
    text-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
    line-height: 1;
    text-align: center;
}

.chord-notes {
    font-size: 1.4rem;
    font-weight: 800;
    color: #d97706;
    margin-top: 5px;
    letter-spacing: 2px;
    text-align: center;
    max-width: 90%;
}


/* Keyboard Area */
.keyboard-section {
    position: relative;
    padding: 20px;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.6);
    z-index: 5;
}

.piano {
    display: flex;
    justify-content: center;
    position: relative;
    height: clamp(140px, 25vh, 200px);
    background: #111;
    padding: 3px;
    border-radius: 10px;
    user-select: none;
    overflow: hidden;
    --wk-width: clamp(32px, 5.5vw, 60px);
    --bk-width: calc(var(--wk-width) * 0.5);
}

@media (min-width: 1080px) {
    .piano {
        --wk-width: clamp(32px, calc((100vw - 420px) / 15), 60px);
    }
}

.white-key {
    flex-shrink: 0;
    width: var(--wk-width);
    height: 100%;
    background: linear-gradient(to bottom, #fff 0%, #f1f5f9 100%);
    border: 1px solid #94a3b8;
    border-radius: 0 0 8px 8px;
    cursor: pointer;
    box-shadow: inset 0 -8px 0 #e2e8f0, 0 4px 10px rgba(0, 0, 0, 0.3);
    z-index: 1;
    transition: all 0.1s;
    position: relative;
}

.white-key:active, .white-key.active {
    background: #e2e8f0;
    transform: translateY(4px);
    box-shadow: inset 0 -2px 0 #cbd5e1;
}

.black-key {
    flex-shrink: 0;
    width: var(--bk-width);
    height: 72.5%;
    background: linear-gradient(to bottom, #2d3748 0%, #000 100%);
    border-radius: 0 0 6px 6px;
    cursor: pointer;
    margin-left: calc(var(--bk-width) / -2);
    margin-right: calc(var(--bk-width) / -2);
    z-index: 2;
    box-shadow: inset 0 -5px 0 #111, 0 6px 15px rgba(0, 0, 0, 0.5);
    transition: all 0.1s;
    border: 1px solid #000;
    position: relative;
}

.black-key:active, .black-key.active {
    transform: translateY(3px);
    box-shadow: inset 0 -2px 0 #000;
    background: #000;
}

/* Result States */
.white-key.correct {
    background: linear-gradient(to bottom, #10b981 0%, #059669 100%) !important;
    border-color: #047857 !important;
    box-shadow: inset 0 -8px 0 #047857 !important;
}

.black-key.correct {
    background: linear-gradient(to bottom, #059669 0%, #047857 100%) !important;
    border-color: #064e3b !important;
    box-shadow: inset 0 -5px 0 #064e3b !important;
}

.white-key.wrong {
    background: linear-gradient(to bottom, #ef4444 0%, #dc2626 100%) !important;
    border-color: #991b1b !important;
    box-shadow: inset 0 -8px 0 #991b1b !important;
}

.black-key.wrong {
    background: linear-gradient(to bottom, #dc2626 0%, #991b1b 100%) !important;
    border-color: #7f1d1d !important;
    box-shadow: inset 0 -5px 0 #7f1d1d !important;
}

.white-key.selected-key {
    background: linear-gradient(to bottom, #6366f1 0%, #4f46e5 100%) !important;
    border-color: #3730a3 !important;
    box-shadow: inset 0 -8px 0 #3730a3 !important;
}

.black-key.selected-key {
    background: linear-gradient(to bottom, #4f46e5 0%, #3730a3 100%) !important;
    border-color: #1e1b4b !important;
    box-shadow: inset 0 -5px 0 #1e1b4b !important;
}

/* Beginner Guide Styles */
.guide-hint::after {
    content: '';
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 12px;
    height: 12px;
    background: #6366f1; /* Melody Maker Blue */
    border-radius: 50%;
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.8), 0 0 20px rgba(99, 102, 241, 0.4);
    animation: guidePulse 1.5s infinite ease-in-out;
    z-index: 5;
}

.black-key.guide-hint::after {
    bottom: 15px;
    background: #818cf8;
}

.key-note-label {
    position: absolute;
    bottom: 40px; /* Moved down to be consistent with dots */
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.75rem;
    font-weight: 800;
    color: #000;
    background: rgba(255, 255, 255, 0.95);
    padding: 2px 4px;
    border-radius: 4px;
    pointer-events: none;
    z-index: 6;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.black-key .key-note-label {
    bottom: 35px;
    color: #000;
    background: #ffffff;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    padding: 0;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}

/* Global visibility toggle */
.piano.show-labels .key-note-label {
    opacity: 1;
}

/* Specific highlight for chord notes in some modes */
.key-note-label.highlighted {
    opacity: 1 !important;
    background: #6366f1 !important;
    color: white !important;
    transform: translateX(-50%) scale(1.1);
}

@keyframes guidePulse {
    0% { transform: translateX(-50%) scale(1); opacity: 0.8; }
    50% { transform: translateX(-50%) scale(1.4); opacity: 1; }
    100% { transform: translateX(-50%) scale(1); opacity: 0.8; }
}

/* Feedback Overlays */
.result-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    z-index: 100;
    pointer-events: none;
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.result-overlay.show {
    transform: translate(-50%, -50%) scale(1.5);
}

.result-overlay .checkmark, 
.result-overlay .crossmark {
    display: none;
    font-size: 10rem;
}

.result-overlay.correct .checkmark {
    display: block;
    color: #10b981;
    filter: drop-shadow(0 0 30px rgba(16, 185, 129, 0.6));
}

.result-overlay.incorrect .crossmark {
    display: block;
    color: #ef4444;
    filter: drop-shadow(0 0 30px rgba(239, 68, 68, 0.6));
}

/* Animations */
@keyframes pulse-correct {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.correct-pulse {
    animation: pulse-correct 0.3s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.shake {
    animation: shake 0.2s ease-in-out infinite;
}

/* Footer / Stats Bar */
.trainer-footer {
    background: rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 20px 40px;
    display: flex;
    justify-content: center;
}

.stats-panel {
    display: flex;
    gap: 40px;
    background: white;
    padding: 15px 40px;
    border-radius: 50px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-label {
    font-size: 0.75rem;
    font-weight: 800;
    color: #64748b;
    text-transform: uppercase;
}

.stat-value {
    font-size: 1.4rem;
    font-weight: 900;
    color: #1e293b;
}

.stat-value.highlight {
    color: #4f46e5;
}

/* Statistics Button */
.open-stats-btn {
    background: white;
    color: #475569;
    padding: 10px 20px;
    border-radius: 12px;
    font-weight: 800;
    cursor: pointer;
    border: 2px solid #e2e8f0;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}

.open-stats-btn:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
}

/* Modal Styling */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.modal-overlay.show {
    opacity: 1;
    pointer-events: auto;
}

.modal-card {
    background: white;
    width: 600px;
    max-width: 90%;
    max-height: 85vh;
    border-radius: 24px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    transform: translateY(20px);
    transition: transform 0.3s;
}

#leaderboardModal .modal-card {
    max-height: 92vh;
}

.modal-overlay.show .modal-card {
    transform: translateY(0);
}

.modal-header {
    padding: 24px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.3rem;
    font-weight: 900;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #64748b;
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.stats-grid {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.chord-stat-card {
    background: #f1f5f9;
    padding: 15px;
    border-radius: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chord-stat-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chord-mini-box {
    width: 65px;
    height: 32px;
    background: var(--chord-box-bg);
    border: 2px solid var(--chord-box-border);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    font-size: 0.85rem;
    color: #92400e;
}

.progress-container {
    width: 120px;
    height: 10px;
    background: #e2e8f0;
    border-radius: 5px;
    position: relative;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: #4f46e5;
    transition: width 0.5s ease;
}

@media (max-width: 600px) {
    header { 
        padding: 4px 8px !important; 
        gap: 4px !important; 
        min-height: 50px !important;
    }
    .trainer-header {
        display: flex !important; /* Switch from grid to flex to allow push-right */
        justify-content: space-between !important;
        padding: 4px 10px;
        height: 50px;
        grid-template-columns: none !important; /* Disable grid */
    }
    .trainer-header-spacer { display: none !important; }
    .trainer-title { font-size: 0.9rem; flex-shrink: 0; }

    
    #midiStatus { display: none !important; }
    #inversionToggle { display: none !important; }
    #guideToggle .label { display: none !important; }
    #guideToggle .icon { font-size: 1.2rem; }
    
    .header-toggle { 
        min-width: 44px; 
        height: 44px !important;
        padding: 4px 6px; 
        flex: none; /* Don't grow, keep them uniform */
        font-size: 0.75rem;
        display: flex;
        flex-direction: column; /* Stack icon/label */
        justify-content: center;
        gap: 2px;
        margin-left: 5px;
    }
    .header-toggle .label { 
        display: block; 
        font-size: 0.6rem !important; 
        line-height: 1;
        white-space: pre-line; /* Allow stacking */
        text-align: center;
    }
    .header-toggle .icon { font-size: 1.1rem; }
    
    /* Move actions right */
    .trainer-header-actions {
        display: flex !important;
        justify-content: flex-end !important;
        gap: 6px !important;
        flex: 1 !important; /* Grow to push right */
        margin-left: auto;
    }
    
    .trainer-meta-row { 
        padding: 15px 10px 5px 10px; 
        flex-direction: column; 
        gap: 8px; 
        box-shadow: none;
        width: 100%;
        box-sizing: border-box;
    }
    
    /* Mode Selector Refinements */
    .mode-selector { 
        width: 100%; 
        display: block;
        padding: 0;
        box-sizing: border-box;
    }
    .mode-selector .mode-btn[data-mode] { 
        display: none; 
    }
    .mobile-mode-row {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        gap: 8px;
        margin-bottom: 5px; 
        width: 100%;
        box-sizing: border-box;
        padding: 0 5px;
    }
    
    #modeCycleBtn {
        display: flex !important;
        flex: 1;
        margin-bottom: 0;
        background: #facc15;
        border: 2px solid #facc15;
        color: #1e293b;
        font-weight: 900;
        font-size: 0.75rem;
        height: 38px !important; 
        padding: 0 10px;
        align-items: center;
        justify-content: center;
        border-radius: 30px;
        box-shadow: 0 4px 10px rgba(250, 204, 21, 0.4);
        text-transform: none;
        letter-spacing: normal;
        text-shadow: none;
        white-space: nowrap;
        overflow: hidden;
    }

    .mobile-mode-row .open-stats-btn {
        display: flex !important;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        height: 38px !important; 
        width: 38px !important;
        min-width: 38px !important;
        background: white;
        border: 2px solid #e2e8f0;
        font-size: 1.1rem;
        flex: none !important;
        padding: 0 !important;
        text-decoration: none;
    }

    .theory-pill-mobile {
        background: white !important;
        border-color: #e2e8f0 !important;
        color: inherit !important;
    }

    .leaderboard-pill-mobile {
        border-color: #fbbf24 !important;
        color: #92400e !important;
    }
    
    .control-group { 
        width: 100%; 
        justify-content: space-evenly; 
        gap: 6px; 
        display: flex;
        align-items: center;
    }
    #timerCycleBtn { 
        max-width: 120px; 
        min-width: 0 !important;
        flex: 1.5; 
        font-size: 0.7rem; 
        padding: 8px 4px !important;
    }
    #countdown { 
        font-size: 0.9rem; 
        padding: 5px 8px; 
        min-width: 60px;
        text-align: center;
    }

    #startRankedBtn {
        flex: 0.8 !important;
        min-width: 60px !important;
        padding: 8px 4px !important;
        font-size: 0.75rem !important; /* Match RANKED button font size */
        border-radius: 30px;
    }

    /* Tight Answer Row for Modes 2 & 3 */
    #answerOptions {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: wrap !important;
        gap: 6px !important;
        justify-content: center;
        padding: 5px !important;
        width: 100%;
        box-sizing: border-box;
    }
    
    /* Mode 4 Note Selection - compact horizontal glass panel for mobile */
    #answerOptions.note-grid {
        display: grid !important;
        grid-template-columns: repeat(6, 1fr) !important;
        gap: 5px !important;
        padding: 10px !important;
        max-height: none !important;
        border-radius: 14px !important;
        width: 95% !important;
        flex: 0 0 auto !important;
    }
    
    #answerOptions.note-grid .mode-btn {
        font-size: 0.7rem !important;
        padding: 10px 2px !important;
        min-height: 38px !important;
        border-radius: 8px !important;
        min-width: 0 !important;
        flex: none !important;
    }

    
    .chord-box {
        width: min(85vw, 320px);
        height: 70px;
        border-width: 2px;
        border-radius: 12px;
    }
    .chord-name { font-size: 1.4rem !important; }
    .chord-notes { font-size: 0.72rem !important; }
    .chord-box-container { margin-bottom: 8px !important; }
    
    .piano { height: 120px !important; }
    .white-key { width: 22px; height: 110px; }
    .black-key { width: 14px; height: 65px; margin-left: -7px; margin-right: -7px; }
    
    .key-label {
        bottom: 5px;
        font-size: 0.6rem;
    }

    .piano.show-labels .key-label {
        display: none !important;
    }

    .key-note-label {
        bottom: 20px !important;
    }

    .black-key .key-note-label {
        bottom: 12px !important;
    }

    .action-buttons {
        gap: 6px;
        width: 100%;
        padding: 10px 5px;
        box-sizing: border-box;
    }
    .action-buttons .mode-btn {
        min-width: 0 !important;
        flex: 1;
        font-size: 0.65rem !important;
        padding: 12px 4px !important;
        white-space: nowrap;
    }
    #toggleKeyboardBtn {
        flex: 0 0 50px !important;
        font-size: 1.1rem !important;
    }

    /* Horizontal Stat Items on Mobile */
    .trainer-workbench {
        padding: 5px 10px !important;
        gap: 5px !important;
    }
    .trainer-footer { 
        display: none;
    }
    .trainer-footer .stat-item {
        flex-direction: row;
        align-items: baseline;
        gap: 4px;
    }
    .trainer-footer .stat-item .label {
        font-size: 0.6rem !important;
        opacity: 0.7;
    }
    .trainer-footer .stat-item .value {
        font-size: 0.8rem !important;
    }
    .stats-panel { 
        padding: 8px 10px; 
        gap: 3px; 
        width: 100%;
        border-radius: 12px;
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap !important;
        justify-content: space-evenly;
        box-shadow: 0 4px 10px rgba(0,0,0,0.1);
        box-sizing: border-box;
    }
    .stat-item {
        flex-direction: row;
        gap: 3px;
        align-items: baseline;
        padding: 2px 2px;
        flex: none;
        justify-content: center;
    }
    .stat-label { 
        font-size: 0.6rem; 
        margin: 0;
        text-transform: uppercase;
        color: #64748b;
        white-space: nowrap;
    }
    .stat-value { 
        font-size: 0.85rem; 
        font-weight: 900;
        min-width: 20px;
        text-align: right;
    }

    /* Session Results Mobile Overrides */
    .flashy-title {
        font-size: 1.8rem !important;
        margin: 10px 0 !important;
    }
    .session-results {
        display: flex !important;
        flex-wrap: wrap !important;
        justify-content: center !important;
        gap: 12px !important;
        margin: 15px 0 !important;
    }
    .result-stat {
        flex: 1 1 40% !important;
        min-width: 100px !important;
        padding: 12px 8px !important;
        box-sizing: border-box;
    }
    .result-stat .value {
        font-size: 1.6rem !important;
    }
    .result-stat .label {
        font-size: 0.6rem !important;
    }
    .flashy-btn {
        padding: 15px 25px !important;
        font-size: 1.1rem !important;
    }
    .hide-mobile-label { display: none !important; }
}

/* Modal Animations */
@keyframes modalPop {
    0% { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

/* Session Results Modal & Flashy Styles */
.session-modal {
    background: white;
    width: 95%;
    max-width: 500px;
    border-radius: 30px;
    padding: 30px;
    text-align: center;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.2);
    position: relative;
    overflow: hidden;
    animation: modalPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.flashy-card {
    background: white;
    border: none;
    box-shadow: 0 25px 50px -12px rgba(99, 102, 241, 0.5);
    transform: scale(0.95);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    padding: 20px;
    border-radius: 32px;
}

.modal-overlay.show .flashy-card {
    transform: scale(1);
}

.flashy-title {
    font-size: 2.2rem;
    font-weight: 950;
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-align: center;
    width: 100%;
    margin: 15px 0;
}

.session-results {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 15px;
    margin: 25px 0;
}

.result-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: #fdf2f8; 
    padding: 18px 12px;
    border-radius: 24px;
    min-width: 130px;
    flex: 1 1 40%;
    border: 3px solid #fce7f3;
    transition: transform 0.3s;
    box-sizing: border-box;
}

.result-stat:hover {
    transform: translateY(-5px);
}

.result-stat .value {
    font-size: 2rem;
    font-weight: 900;
    color: #db2777; 
    line-height: 1;
}

.result-stat .label {
    font-size: 0.7rem;
    font-weight: 800;
    color: #9d174d;
    margin-top: 6px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.flashy-btn {
    display: block;
    margin: 15px auto 0;
    background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
    border: none;
    font-size: 1.4rem;
    font-weight: 900;
    padding: 18px 36px;
    border-radius: 99px;
    color: white;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(99, 102, 241, 0.3);
    transition: all 0.3s;
    text-transform: uppercase;
}

.flashy-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 15px 35px rgba(99, 102, 241, 0.4);
}

.flashy-btn:active {
    transform: scale(0.98);
}

/* High Score Animations */
@keyframes rainbow-border {
  0% { border-color: #ff0000; box-shadow: 0 0 20px #ff0000; }
  20% { border-color: #ff9900; box-shadow: 0 0 20px #ff9900; }
  40% { border-color: #33cc33; box-shadow: 0 0 20px #33cc33; }
  60% { border-color: #0066ff; box-shadow: 0 0 20px #0066ff; }
  80% { border-color: #9900cc; box-shadow: 0 0 20px #9900cc; }
  100% { border-color: #ff0000; box-shadow: 0 0 20px #ff0000; }
}

.new-high-score-card {
  animation: rainbow-border 2s infinite linear;
  border-width: 4px !important;
  transform: scale(1.05);
}

@keyframes float-up {
  0% { transform: translateY(0) scale(1); opacity: 1; }
  100% { transform: translateY(-100px) scale(1.5); opacity: 0; }
}

.confetti {
  position: absolute;
  font-size: 1.5rem;
  pointer-events: none;
  animation: float-up 1.5s forwards ease-out;
}

/* Song Specific Practice Mode Styles */
.song-practice-pill {
    background: #fde68a; /* Golden color from big box */
    color: #92400e;
    padding: 8px 20px;
    border-radius: 999px;
    font-weight: 900;
    font-size: 1rem;
    box-shadow: 0 4px 12px rgba(251, 191, 36, 0.3);
    border: 3px solid #f59e0b;
    margin: 10px 0;
    display: inline-flex;
    align-items: center;
    text-transform: uppercase;
    flex-shrink: 0;
}

.song-chords-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-left: 15px;
    align-items: center;
    flex: 1; /* Occupy remaining space */
}

.song-chord-pill {
    padding: 4px 12px;
    border-radius: 8px;
    color: white;
    font-size: 0.9rem;
    font-weight: 800;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: transform 0.1s;
}

/* Root-based colors for Chord Timeline look */
.chord-tp-c, .chord-tp-a, .chord-tp-e { background-color: #4338ca; } /* Blue/Purple */
.chord-tp-f, .chord-tp-d { background-color: #c2410c; } /* Orange/Rust */
.chord-tp-g, .chord-tp-b { background-color: #0f766e; } /* Teal/Green */
.chord-tp-db, .chord-tp-eb, .chord-tp-gb, .chord-tp-ab, .chord-tp-bb { background-color: #6d28d9; } /* Violet for sharps/flats */

.song-practice-buttons {
    display: flex;
    gap: 15px;
    margin-top: 20px;
    z-index: 10;
}

.song-practice-btn {
    min-width: 140px;
    padding: 12px 24px;
    font-size: 1.1rem;
    font-weight: 800;
    border: none;
    border-radius: 40px;
    cursor: pointer;
    transition: all 0.2s;
}

.song-practice-btn.help-btn {
    background: #fbbf24;
    color: #92400e;
    box-shadow: 0 4px 12px rgba(251, 191, 36, 0.3);
}

.song-practice-btn.next-btn {
    background: #4f46e5;
    color: white;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.song-practice-btn:hover {
    transform: translateY(-2px);
    filter: brightness(1.1);
}

.song-practice-btn:active {
    transform: translateY(1px);
}

@media (max-width: 600px) {
    .song-practice-pill {
        margin: 5px 0 !important;
        width: 100%;
        box-sizing: border-box;
        padding: 6px 15px 6px 58px !important; /* Extra left padding for thumb */
        align-items: center !important; 
        border-radius: 12px !important;
        background: rgba(254, 243, 199, 0.98) !important; 
        position: relative !important;
        min-height: 50px;
        border-width: 2px !important;
    }

    #practicingSongThumbnail {
        position: absolute !important;
        top: 6px !important; /* Padding from top edge */
        left: 10px !important;
        width: 38px !important;
        height: 38px !important;
        margin-top: 0 !important;
        border-width: 2px !important;
        visibility: visible !important;
        display: block !important;
    }

    .song-name-label {
        font-size: 0.75rem !important; /* Even smaller */
        line-height: 1.2;
        font-weight: 800;
        margin: 0 !important;
        text-align: left !important;
        width: 100%;
        display: block;
    }

    .keyboard-section {
        padding: 10px 10px 5px 10px !important; /* Tighter padding, especially bottom */
    }

    .chord-buttons-container {
        padding: 2px 0 !important;
        gap: 6px 4px !important; /* Tighter vertical gap */
    }

    .chord-toolbar-group {
        gap: 1px !important;
    }

    .chord-toolbar-section-header {
        font-size: 0.45rem !important; /* Even smaller headers */
        margin-bottom: 0px !important;
    }

    .chord-suggestion-btn {
        padding: 0px 8px !important;
        font-size: 0.65rem !important;
        min-width: 32px;
        height: 24px !important; /* Very short buttons */
    }

    .chord-toolbar-inline-marker {
        font-size: 0.65rem !important;
    }

    /* Fixed position for BASIC toggler specifically on mobile */
    #chordComplexityToggle {
        order: 10 !important;
        margin-right: 0 !important;
        margin-left: 5px !important;
    }
    
    .song-practice-buttons {
        gap: 10px;
        width: 100%;
        justify-content: center;
        margin-top: 5px !important; /* Move closer to piano */
    }
    
    .song-practice-btn {
        min-width: 120px;
        font-size: 0.9rem;
        padding: 10px 15px;
    }
}

/* Replicated Chord Toolbar Styles (v2: Meta Row Integration) */
.chord-buttons-container {
    display: flex;
    flex-direction: row;
    gap: 15px;
    padding: 0 15px;
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border: none;
    margin: 0;
    width: auto;
    max-width: none;
    max-height: 80px; /* Limit to one/two rows in header */
    overflow-x: auto;
    overflow-y: hidden;
    box-shadow: none;
    flex: 1; /* Grow to fill space */
    align-items: center;
    scrollbar-width: thin;
}

.chord-buttons-container.hidden {
    display: none !important;
}

.chord-suggestion-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none !important;
    color: white !important;
    padding: 2px 10px !important;
    border-radius: 20px !important; /* Pill style */
    font-weight: 800 !important;
    font-size: 0.8rem !important;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: all 0.2s;
    min-width: 40px;
    text-align: center;
    user-select: none;
    touch-action: manipulation;
}

.chord-suggestion-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 6px rgba(0,0,0,0.15);
}

.chord-type-verse { background: linear-gradient(135deg, #4f46e5 0%, #3730a3 100%) !important; }
.chord-type-chorus { background: linear-gradient(135deg, #d97706 0%, #b45309 100%) !important; }
.chord-type-pre-chorus { background: linear-gradient(135deg, #0891b2 0%, #0e7490 100%) !important; }
.chord-type-bridge { background: linear-gradient(135deg, #e11d48 0%, #be123c 100%) !important; }

.chord-toolbar-inline-marker {
    display: inline-flex;
    align-items: center;
    color: #475569;
    font-weight: 700;
    font-size: 0.8rem;
    font-family: monospace;
    padding: 0 2px;
    user-select: none;
}

.chord-toolbar-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex-shrink: 0;
}

.chord-toolbar-buttons-row {
    display: flex;
    gap: 4px;
    flex-wrap: nowrap;
    align-items: center;
}

.chord-toolbar-section-header {
    display: flex;
    align-items: center;
    color: #475569;
    font-size: 0.55rem;
    font-weight: 900;
    text-transform: uppercase;
    margin-left: 2px;
    letter-spacing: 0.05em;
}

/* Mobile Adjustments for Song Practice */
/* Mobile Adjustments for Song Practice */
@media (max-width: 768px) {
    .chord-box {
        width: 85%;
        max-width: 320px;
        min-width: unset;
        padding: 20px;
    }
    
    .chord-name {
        font-size: 2rem !important;
    }
    
    .chord-notes {
        font-size: 0.85rem !important;
        letter-spacing: 1px;
    }

    .chord-buttons-container {
        padding: 5px;
        gap: 15px 10px; /* Vertical gap 15px, horizontal 10px */
        max-height: none !important;
        overflow-x: visible !important;
        overflow-y: visible !important;
        flex: none;
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap !important;
    }
    
    .chord-toolbar-buttons-row {
        flex-wrap: wrap !important;
        gap: 8px 4px !important;
    }
    
    .chord-toolbar-section-header {
        font-size: 0.5rem;
    }
    
    .chord-suggestion-btn {
        padding: 1px 8px !important;
        font-size: 0.7rem !important;
        min-width: 32px;
    }
    .complexity-pill {
        min-width: 84px !important; /* Fixed width as requested */
        width: 84px !important;
        padding: 4px 10px !important;
        font-size: 0.75rem !important;
        gap: 5px !important;
        height: 32px !important;
        justify-content: center;
    }
}

/* Tablet Compact Landscape Header Scaling */
@media (orientation: landscape) and (max-height: 1000px) and (min-width: 601px) {
    /* Shrink specific header buttons as requested */
    #audioToggle .label, #guideToggle .label {
        display: none !important;
    }

    #audioToggle, #guideToggle, .compact-only-flex {
        padding: 8px 12px !important;
        min-width: 42px !important;
        justify-content: center !important;
        border-radius: 50% !important;
        display: flex !important;
        background: rgba(255,255,255,0.12) !important;
        border: 1px solid rgba(255,255,255,0.15) !important;
    }

    #openLeaderboardBtnCompact, #openStatsBtnCompact {
        display: flex !important;
    }
    
    /* Hide standard buttons when compact header ones are active */
    #openLeaderboardBtn, #openStatsBtn, .trainer-footer {
        display: none !important;
    }
    
    /* Ensure Level button label remains visible */
    #difficultyToggle .label {
        display: block !important;
        font-size: 0.75rem !important;
        white-space: nowrap;
    }

    #difficultyToggle {
        padding: 8px 15px !important;
        min-width: 170px !important;
    }

    /* Squeeze the Yellow Box as requested */
    .chord-box-container {
        padding-top: 10px !important;
        margin-bottom: 5px !important;
    }
    .chord-box {
        padding: 10px 15px !important;
        height: 100px !important;
        min-height: 100px !important;
        min-width: 280px !important;
        border-width: 3px !important;
    }
    .chord-box .chord-name {
        font-size: 2rem !important;
        margin-bottom: 2px !important;
    }
    .chord-box .chord-notes {
        font-size: 1.1rem !important;
    }
    .chord-box::after {
        display: none !important;
    }
}
