/* ===== CSS VARIABLES ===== */
:root {
    /* Music-inspired color palette - deep blues and golds */
    --primary-color: #1a365d;
    --primary-light: #2c5282;
    --primary-dark: #102a43;
    --accent-color: #d69e2e;
    --accent-light: #ecc94b;
    --accent-dark: #b7791f;
    --background-color: #f7fafc;
    --surface-color: #ffffff;
    --white-color: #ffffff;
    --text-color: #1a202c;
    --text-muted: #718096;
    --error-color: #e53e3e;
    --success-color: #38a169;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 3px rgba(26, 54, 93, 0.08);
    --shadow: 0 4px 20px rgba(26, 54, 93, 0.1);
    --shadow-lg: 0 10px 40px rgba(26, 54, 93, 0.15);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 50px;
}

/* ===== RESET & BASE ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ===== iOS TOUCH OPTIMIZATION ===== */
/* Eliminates 300ms click delay on iOS by disabling double-tap-to-zoom on interactive elements */
button,
select,
input,
label,
a,
[role="button"],
.action-btn,
.icon-btn,
.toggle-piano-btn,
.toggle-sidebar-btn,
.midi-status-btn,
.whats-new-btn,
.rules-link,
.checkbox-label,
.generator-controls select,
.key-range-section,
.range-handle {
    touch-action: manipulation;
}

body {
    font-family: 'Montserrat', sans-serif;
    background: linear-gradient(135deg, var(--background-color) 0%, #edf2f7 100%);
    color: var(--text-color);
    line-height: 1.6;
}

/* ===== APP HEADER ===== */
.app-header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 16px 24px;
    background: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
}

.header-left {
    justify-self: start;
}

.header-center {
    text-align: center;
}

.header-center h1 {
    font-size: 2rem;
    font-weight: 800;
    color: var(--primary-color);
    margin: 0;
    letter-spacing: -0.5px;
}

.header-center h1::after {
    content: '';
    display: block;
    width: 60px;
    height: 3px;
    background: linear-gradient(90deg, var(--accent-color), var(--accent-light));
    margin: 4px auto 0;
    border-radius: 2px;
}

.tagline {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin: 4px 0 0;
}

.header-right {
    justify-self: end;
}

/* MIDI Status Button */
.midi-status-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border: none;
    border-radius: var(--radius-full);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.25s ease;
}

.midi-status-btn i {
    font-size: 1.1rem;
}

.midi-status-btn.midi-disconnected {
    background: var(--primary-color);
    color: var(--white-color);
}

.midi-status-btn.midi-disconnected:hover {
    background: var(--primary-light);
}

.midi-status-btn.midi-connected {
    background: linear-gradient(135deg, rgba(56, 161, 105, 0.15), rgba(56, 161, 105, 0.2));
    color: var(--success-color);
    border: 2px solid var(--success-color);
}

.midi-status-btn.midi-not-supported {
    background: rgba(237, 137, 54, 0.15);
    color: #ed8936;
    border: 2px solid #ed8936;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--background-color);
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s ease;
}

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

/* ===== SETTINGS BAR ===== */
.settings-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 24px;
    padding: 16px 24px;
    margin: 10px 24px;
    max-width: 1352px;
    margin-left: auto;
    margin-right: auto;
    background: var(--surface-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow);
    flex-wrap: wrap;
}

.setting-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Pattern dropdown optgroup styling */
#pattern-select optgroup {
    font-weight: 600;
    color: var(--text-muted);
}

#pattern-select option {
    font-weight: normal;
    color: var(--text-color);
    padding: 4px 8px;
}

.setting-group > label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
}

.setting-group select {
    padding: 8px 12px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    background: var(--surface-color);
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 120px;
}

.setting-group select:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(214, 158, 46, 0.2);
}

.setting-control {
    display: flex;
    align-items: center;
    gap: 6px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-color);
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent-color);
    cursor: pointer;
}

.slider-with-value {
    display: flex;
    align-items: center;
    gap: 10px;
}

.slider-with-value input[type="range"] {
    width: 80px;
    accent-color: var(--accent-color);
    cursor: pointer;
}

.slider-value {
    min-width: 20px;
    font-weight: 700;
    color: var(--primary-color);
    text-align: center;
}

.rules-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    background: rgba(214, 158, 46, 0.1);
    color: var(--accent-color);
    text-decoration: none;
    transition: all 0.25s ease;
}

.rules-link:hover {
    background: rgba(214, 158, 46, 0.2);
    transform: scale(1.1);
}

/* ===== MAIN PLAY AREA ===== */
.main-area {
    display: flex;
    gap: 20px;
    padding: 20px 24px;
    max-width: 1400px;
    margin: 0 auto;
    align-items: stretch;
}

/* Main Content (Staff + Piano stacked) */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-width: 0; /* Prevent flex blowout */
}

/* Staff Section (Hero) */
.staff-section {
    /* No grid positioning needed */
}

/* Stats Sidebar */
.stats-sidebar {
    flex-shrink: 0;
}

#staff-container {
    background: var(--surface-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow);
    padding: 20px;
    border-top: 4px solid var(--accent-color);
    min-height: 200px;
    display: flex;
    justify-content: center;
    align-items: center;
}

#staff-wrapper {
    overflow: hidden;
    position: relative;
}

#active-note-marker {
    position: absolute;
    top: 0;
    width: 78px;
    height: 100%;
    background: rgba(0, 0, 0, 0.08);
    border-radius: 8px;
    pointer-events: none;
    z-index: 1;
    display: none;
    /*transform: translateX(-50%);*/
}

canvas {
    background: var(--surface-color);
}

/* ===== STATS SIDEBAR ===== */
.stats-sidebar {
    display: flex;
    flex-direction: column;
    width: 240px;
    background: var(--surface-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow);
    border-top: 4px solid var(--primary-color);
    overflow: hidden;
    transition: width 0.3s ease, height 0.3s ease;
}

/* Sidebar Header */
.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: var(--background-color);
    border-bottom: 1px solid var(--border-color);
}

.sidebar-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.toggle-sidebar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--surface-color);
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
}

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

.toggle-sidebar-btn i {
    transition: transform 0.3s ease;
}

/* Compact Stats (visible only when collapsed) */
.compact-stats {
    display: none;
    flex-direction: column;
    gap: 8px;
    padding: 16px;
}

.compact-stat {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px;
    border-radius: var(--radius-sm);
    background: var(--background-color);
}

.compact-stat i {
    font-size: 1rem;
}

.compact-stat span {
    font-size: 1.1rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

.compact-stat.correct {
    color: var(--success-color);
}

.compact-stat.wrong {
    color: var(--error-color);
}

.compact-reset-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 8px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--primary-color);
    color: var(--white-color);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1rem;
}

.compact-reset-btn:hover {
    background: var(--primary-light);
    transform: translateY(-1px);
}

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

/* Sidebar Body */
.sidebar-body {
    display: flex;
    flex-direction: column;
    gap: 0;
    transition: opacity 0.3s ease;
}

/* Collapsed Sidebar State */
.stats-sidebar.collapsed {
    width: 80px;
}

.stats-sidebar.collapsed .sidebar-header {
    justify-content: center;
    padding: 12px;
}

.stats-sidebar.collapsed .sidebar-title {
    display: none;
}

.stats-sidebar.collapsed .toggle-sidebar-btn i {
    transform: rotate(180deg);
}

.stats-sidebar.collapsed .compact-stats {
    display: flex;
}

.stats-sidebar.collapsed .sidebar-body {
    display: none;
}

/* Timer Display */
.timer-display {
    padding: 12px 14px;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
}

.timer-label {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 2px;
}

.timer-display .timer-value {
    font-size: 2rem;
    font-weight: 800;
    color: var(--primary-color);
    font-variant-numeric: tabular-nums;
    line-height: 1;
}

.best-time {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border-color);
}

.best-time .best-time-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
}

.best-time .best-time-value {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--accent-dark);
    background: rgba(214, 158, 46, 0.15);
    padding: 4px 10px;
    border-radius: var(--radius-sm);
}

/* Goal Section */
.goal-section {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-color);
}

.goal-section label {
    display: block;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 4px;
}

.goal-section select {
    width: 100%;
    padding: 6px 10px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    background: var(--surface-color);
    color: var(--text-color);
    cursor: pointer;
}

.goal-section select:focus {
    outline: none;
    border-color: var(--accent-color);
}

/* Velocity Section */
.velocity-section {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-color);
}

.velocity-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.velocity-label {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.velocity-dynamic-level {
    font-size: 1.2rem;
    font-weight: 800;
    font-style: italic;
    color: var(--primary-color);
    font-family: Georgia, serif;
}

.velocity-gauge-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.velocity-gauge-horizontal {
    position: relative;
    flex: 1;
    height: 20px;
    background: linear-gradient(to right, #e2e8f0, #f7fafc);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.velocity-gauge-fill-horizontal {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 0%;
    background: linear-gradient(to right,
        var(--success-color) 0%,
        var(--accent-color) 50%,
        var(--error-color) 100%
    );
    border-radius: 10px;
    transition: width 0.05s ease-out;
    box-shadow: 2px 0 8px rgba(56, 161, 105, 0.3);
}

.velocity-value-number {
    font-weight: 800;
    color: var(--primary-color);
    font-variant-numeric: tabular-nums;
    min-width: 32px;
    text-align: right;
    font-size: 0.9rem;
}

/* Scores Section */
.scores-section {
    padding: 10px 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    border-bottom: 1px solid var(--border-color);
}

.score-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 10px;
    background: var(--background-color);
    border-radius: var(--radius-sm);
}

.score-row .score-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
}

.score-row .score-value {
    font-size: 1.1rem;
    font-weight: 800;
    min-width: 36px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.score-row .played-score {
    color: var(--primary-color);
}

.score-row .correct-score {
    color: var(--success-color);
}

.score-row .wrong-score {
    color: var(--error-color);
}

/* Actions Section */
.actions-section {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px 14px;
}

.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    border: none;
    border-radius: var(--radius-full);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s ease;
    background: var(--primary-color);
    color: var(--white-color);
}

.action-btn:hover {
    background: var(--primary-light);
    transform: translateY(-2px);
}

.action-btn.accent {
    background: var(--accent-color);
    color: var(--primary-dark);
}

.action-btn.accent:hover {
    background: var(--accent-light);
}

/* ===== PIANO SECTION ===== */
.piano-section {
    background: var(--surface-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.piano-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: var(--background-color);
    border-bottom: 1px solid var(--border-color);
}

.piano-controls {
    display: flex;
    align-items: center;
    gap: 24px;
    flex-wrap: wrap;
}

.range-control {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--surface-color);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    transition: opacity 0.2s ease;
}

.range-control label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
}

.range-control label span {
    display: inline-block;
    min-width: 32px;
    text-align: center;
    color: var(--primary-color);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.range-control input[type="range"] {
    width: 100px;
    accent-color: var(--accent-color);
    cursor: pointer;
}

.toggle-piano-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--surface-color);
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
}

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

.toggle-piano-btn i {
    transition: transform 0.3s ease;
}

.piano-body {
    padding: 16px;
    transition: all 0.3s ease;
    overflow: hidden;
}

.piano-section.collapsed .piano-body {
    height: 0;
    padding: 0;
    opacity: 0;
    overflow: hidden;
}

.piano-section.collapsed {
    min-height: 0;
}

/* Piano Container */
#piano-container {
    display: flex;
    justify-content: center;
    width: 100%;
    overflow-x: auto;
}

#piano {
    display: flex;
    position: relative;
    padding: 5px;
    background: #2c3e50;
    border-radius: var(--radius-sm);
    min-width: max-content;
}

/* Piano Keys - PROTECTED, minimal changes */
.piano-key {
    width: 35px;
    height: 110px;
    border: none;
    border-right: 0.5px solid rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    font-weight: 600;
    cursor: pointer;
    background-color: var(--white-color);
    border-radius: 0 0 4px 4px;
    transition: all 0.15s ease;
    color: var(--text-color);
    box-shadow: none;
    font-size: 0.7rem;
    padding-bottom: 6px;
}

.piano-key.black {
    background-color: #333;
    color: var(--white-color);
    height: 70px;
    width: 22px;
    position: relative;
    margin: 0 -11px;
    z-index: 1;
    border: none;
    border-radius: 0 0 3px 3px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.piano-key:hover {
    background-color: #f0f0f0;
}

.piano-key.black:hover {
    background-color: #444;
}

.piano-key.disabled {
    background-color: #5a5a5a;
    pointer-events: none;
}

.piano-key.black.disabled {
    background-color: #3c3b3b;
    pointer-events: none;
}

/* Piano Range Handles - PROTECTED */
.piano-range-handle {
    --handle-hit-area: 30px; /* Adjust this to change clickable area size */
    position: absolute;
    top: 0;
    width: 12px;
    height: 100%;
    background: rgba(26, 54, 93, 0.8);
    cursor: ew-resize;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Invisible extended hit area for easier grabbing */
.piano-range-handle::before {
    content: "";
    position: absolute;
    top: 0;
    width: var(--handle-hit-area);
    height: 100%;
    cursor: ew-resize;
}

.piano-range-handle::after {
    content: "";
    height: 40px;
    width: 2px;
    background: white;
    border-radius: 1px;
}

.piano-range-handle.left {
    left: 0;
    border-top-right-radius: 4px;
    border-bottom-right-radius: 4px;
}

.piano-range-handle.left::before {
    left: 50%;
    transform: translateX(-50%); /* Center hit area on handle */
}

.piano-range-handle.right {
    right: 0;
    border-top-left-radius: 4px;
    border-bottom-left-radius: 4px;
}

.piano-range-handle.right::before {
    right: 50%;
    transform: translateX(50%); /* Center hit area on handle */
}

/* ===== MODALS ===== */
.modal-content {
    border-radius: var(--radius-lg);
    border: none;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.modal-header {
    border-bottom: 2px solid var(--border-color);
    padding: 20px 24px;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
}

.modal-header .btn-close {
    filter: brightness(0) invert(1);
    opacity: 0.8;
}

.modal-header .btn-close:hover {
    opacity: 1;
}

.modal-title {
    color: var(--white-color);
    font-weight: 800;
    font-size: 1.25rem;
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    border-top: 2px solid var(--border-color);
    padding: 16px 24px;
    background: var(--background-color);
}

/* Form controls in modals */
.modal .form-control {
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-size: 0.95rem;
    transition: all 0.25s ease;
}

.modal .form-control:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(214, 158, 46, 0.2);
    outline: none;
}

.modal .btn-primary {
    background-color: var(--primary-color);
    border: none;
    border-radius: var(--radius-full);
    padding: 10px 20px;
    font-weight: 600;
}

.modal .btn-primary:hover {
    background-color: var(--primary-light);
}

.modal .btn-danger {
    background-color: var(--error-color);
    border: none;
    border-radius: var(--radius-full);
}

.modal .btn-secondary {
    background-color: var(--accent-color);
    color: var(--primary-dark);
    border: none;
    border-radius: var(--radius-full);
}

/* Results Stats */
.results-stats {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.result-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--background-color);
    border-radius: var(--radius-sm);
}

.result-label {
    font-weight: 700;
    color: var(--text-color);
}

.result-value {
    font-weight: 600;
    font-size: 1.1rem;
}

#result-correct { color: var(--success-color); }
#result-wrong { color: var(--error-color); }
#result-accuracy { font-weight: 800; color: var(--accent-dark); }

/* History List */
.history-list {
    max-height: 400px;
    overflow-y: auto;
}

.history-list th {
    position: sticky;
    top: 0;
    background: var(--background-color);
    font-weight: 700;
}

.history-list th, .history-list td {
    padding: 12px;
    text-align: center;
}

/* Nav Tabs */
.nav-tabs {
    border-bottom: 2px solid var(--border-color);
}

.nav-tabs .nav-link {
    color: var(--text-muted);
    font-weight: 600;
    border: none;
    border-bottom: 3px solid transparent;
    padding: 10px 16px;
    margin-bottom: -2px;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.nav-tabs .nav-link:hover {
    color: var(--primary-color);
    background: rgba(26, 54, 93, 0.05);
}

.nav-tabs .nav-link.active {
    color: var(--primary-color);
    border-bottom-color: var(--accent-color);
}

/* Sequences List */
.sequences-list {
    max-height: 200px;
    overflow-y: auto;
}

.sequences-list .list-group-item {
    padding: 10px 14px;
    font-size: 0.9rem;
    border-left: 3px solid var(--accent-color);
    margin-bottom: 6px;
    border-radius: var(--radius-sm);
    background: var(--background-color);
}

/* Top Ranking Alert Animation */
.top-ranking-alert {
    animation: glow-pulse 1.5s infinite alternate;
    border-radius: var(--radius-sm);
}

@keyframes glow-pulse {
    0% { box-shadow: 0 0 5px rgba(214, 158, 46, 0.5); }
    100% { box-shadow: 0 0 20px rgba(214, 158, 46, 0.8); }
}

/* Settings Info */
.settings-info {
    background: rgba(26, 54, 93, 0.05);
    padding: 16px;
    border-radius: var(--radius-sm);
    border-left: 4px solid var(--primary-color);
    margin-bottom: 20px;
}

/* ===== UTILITY CLASSES ===== */
.hidden {
    display: none !important;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
    .main-area {
        flex-direction: column;
    }

    .main-content {
        width: 100%;
    }

    .stats-sidebar {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 12px;
        width: 100%;
        order: 1; /* Put sidebar between staff and piano on mobile */
    }

    .main-content {
        order: 0;
    }

    /* Hide sidebar header and compact stats on mobile (no collapse needed) */
    .stats-sidebar .sidebar-header,
    .stats-sidebar .compact-stats {
        display: none;
    }

    /* Show sidebar body always on mobile */
    .stats-sidebar.collapsed .sidebar-body {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 12px;
    }

    .stats-sidebar.collapsed {
        width: 100%;
    }

    .stats-sidebar > *,
    .sidebar-body > * {
        flex: 1 1 auto;
        min-width: 150px;
    }

    .timer-display {
        flex: 2 1 200px;
    }

    .sidebar-body {
        flex-direction: row;
        flex-wrap: wrap;
    }
}

@media (max-width: 600px) {
    .app-header {
        grid-template-columns: 1fr;
        gap: 12px;
        text-align: center;
    }

    .header-left, .header-right {
        justify-self: center;
    }

    .settings-bar {
        gap: 12px;
    }

    .setting-group {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .piano-controls {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
}

/* ===== WHAT'S NEW MODAL ===== */
.changelog-container {
    max-height: 500px;
    overflow-y: auto;
    padding-right: 8px;
}

.changelog-date-section {
    margin-bottom: 24px;
}

.changelog-date-section:last-child {
    margin-bottom: 0;
}

.changelog-date-header {
    font-size: 1rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--border-color);
}

.changelog-changes-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.changelog-item {
    padding: 12px;
    background: var(--background-color);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--accent-color);
}

.changelog-item-title {
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.changelog-item-description {
    font-size: 0.9rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.changelog-badge {
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: uppercase;
}

.changelog-badge-feature {
    background: var(--accent-color);
    color: white;
}

.changelog-badge-improvement {
    background: var(--primary-light);
    color: white;
}

/* What's New button with notification badge */
.whats-new-btn {
    position: relative;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--background-color);
    color: var(--text-color);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.whats-new-btn:hover {
    background: var(--border-color);
    transform: translateY(-1px);
}

.whats-new-btn i {
    font-size: 16px;
    color: var(--accent-color);
}

.whats-new-btn.has-updates::after {
    content: '';
    position: absolute;
    top: 6px;
    right: 6px;
    width: 8px;
    height: 8px;
    background: var(--error-color);
    border: 2px solid var(--surface-color);
    border-radius: 50%;
    animation: pulse-badge 2s ease-in-out infinite;
}

@keyframes pulse-badge {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.2);
        opacity: 0.8;
    }
}

/* ===== PATTERN MODAL STYLES ===== */
.pattern-browser {
  max-height: 400px;
  overflow-y: auto;
  padding-right: 4px;
}

.pattern-list {
  min-height: 200px;
}

.pattern-list .list-group-item-action {
  cursor: pointer;
  padding: 0.75rem 1rem;
  transition: all 0.2s ease;
}

.pattern-list .list-group-item-action:hover {
  background-color: var(--background-color);
  border-left-color: var(--accent-color);
  border-left-width: 3px;
}

.pattern-category-header {
  color: var(--primary-color);
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  margin-top: 1rem;
  margin-bottom: 0.5rem;
  letter-spacing: 0.5px;
}

.pattern-category-header:first-child {
  margin-top: 0;
}

#ai-generator-collapse .card-body {
  background-color: var(--background-color);
  border: 1px solid var(--border-color);
}

#generated-pattern-preview {
  background: white;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
}

.btn-group .btn-check:checked + .btn {
  background-color: var(--primary-color);
  color: white;
}

.btn-group .btn-outline-secondary {
  font-size: 0.75rem;
  padding: 0.25rem 0.5rem;
}

.pattern-item-badge {
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--border-color);
  color: var(--text-muted);
}

/* ===== LEGACY COMPATIBILITY ===== */
/* These ensure old JS references still work */
#enable-midi.midi-connected {
    background: linear-gradient(135deg, rgba(56, 161, 105, 0.15), rgba(56, 161, 105, 0.2));
    color: var(--success-color);
    border: 2px solid var(--success-color);
}

#enable-midi.midi-not-supported {
    background: rgba(237, 137, 54, 0.15);
    color: #ed8936;
    border: 2px solid #ed8936;
}

#toggle-animation.animation-paused {
    background: #ed8936;
    color: white;
}

/* Old score value classes for JS compatibility */
.correct-score { color: var(--success-color) !important; }
.wrong-score { color: var(--error-color) !important; }
.played-score { color: var(--primary-color) !important; }

/* ===== CIRCLE OF FIFTHS KEY PICKER ===== */

/* Trigger button styling - matches select styling */
.key-signature-btn {
    padding: 8px 16px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    background: var(--surface-color);
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 60px;
    text-align: center;
    /* Prevent text selection on mobile */
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    touch-action: manipulation;
}

.key-signature-btn:hover {
    border-color: var(--accent-color);
    background: linear-gradient(135deg, rgba(214, 158, 46, 0.05), rgba(214, 158, 46, 0.1));
}

.key-signature-btn:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(214, 158, 46, 0.2);
}

.key-signature-btn.active {
    border-color: var(--accent-color);
    background: linear-gradient(135deg, rgba(214, 158, 46, 0.1), rgba(214, 158, 46, 0.15));
    box-shadow: 0 0 0 3px rgba(214, 158, 46, 0.2);
}

/* Circle overlay container */
.cof-overlay {
    position: fixed;
    z-index: 1100;
    pointer-events: none;
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.cof-overlay.open {
    opacity: 1;
    transform: scale(1);
    pointer-events: auto;
}

/* SVG circle styling */
.cof-circle {
    filter: drop-shadow(0 4px 20px rgba(26, 54, 93, 0.25));
}

/* Center circle */
.cof-center {
    cursor: pointer;
    touch-action: manipulation;
}

.cof-center-bg {
    fill: var(--surface-color);
    stroke: var(--border-color);
    stroke-width: 2;
}

.cof-center-label {
    font-family: 'Montserrat', sans-serif;
    font-size: 12px;
    font-weight: 500;
    fill: var(--text-muted);
}

/* Key circles - base styling */
.cof-key {
    cursor: pointer;
    touch-action: manipulation;
}

.cof-key-bg {
    fill: var(--surface-color);
    stroke: var(--border-color);
    stroke-width: 2;
    transition: all 0.15s ease, r 0.15s ease;
}

.cof-key-label {
    font-family: 'Montserrat', sans-serif;
    font-size: 14px;
    font-weight: 700;
    fill: var(--text-color);
    pointer-events: none;
}

.cof-key-secondary {
    font-family: 'Montserrat', sans-serif;
    font-size: 9px;
    font-weight: 500;
    fill: var(--text-muted);
    pointer-events: none;
}

/* Relative minor label */
.cof-key-minor {
    font-family: 'Montserrat', sans-serif;
    font-size: 10px;
    font-weight: 500;
    fill: var(--text-muted);
    pointer-events: none;
}

/* Sharp keys - warm tint (right side) */
.cof-key.sharp .cof-key-bg {
    fill: #fef9eb;
}

/* Flat keys - cool tint (left side) */
.cof-key.flat .cof-key-bg {
    fill: #f0f4f8;
}

/* Natural key (C) - same as sharp side */
.cof-key.natural .cof-key-bg {
    fill: #fef9eb;
}

/* Hover state */
.cof-key:hover .cof-key-bg,
.cof-key.hovered .cof-key-bg {
    fill: #fef3d0;
    stroke: var(--accent-color);
    stroke-width: 3;
}

/* Selected state */
.cof-key.selected .cof-key-bg {
    fill: var(--accent-color);
    stroke: var(--accent-dark);
    stroke-width: 3;
}

.cof-key.selected .cof-key-label {
    fill: var(--primary-dark);
}

.cof-key.selected .cof-key-secondary {
    fill: var(--primary-color);
}

/* Combined hover + selected */
.cof-key.selected:hover .cof-key-bg,
.cof-key.selected.hovered .cof-key-bg {
    fill: var(--accent-light);
}
