/* ═══════════════════════════════════════════════════════════════
   Piano Note Reader — Main Stylesheet
   Dark premium theme with glassmorphism, micro-animations
   ═══════════════════════════════════════════════════════════════ */

/* ── Google Fonts ─────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── CSS Custom Properties ────────────────────────────────── */
:root {
  /* Colors — dark theme */
  --bg-primary: #0d0d12;
  --bg-secondary: #15151e;
  --bg-tertiary: #1c1c2a;
  --bg-card: rgba(28, 28, 42, 0.7);
  --bg-glass: rgba(28, 28, 42, 0.5);

  --text-primary: #e8e6e1;
  --text-secondary: #9b97a0;
  --text-muted: #5e5a65;

  --accent-primary: #7c6aef;
  --accent-primary-glow: rgba(124, 106, 239, 0.3);
  --accent-secondary: #60a5fa;
  --accent-success: #34d399;
  --accent-success-glow: rgba(52, 211, 153, 0.25);
  --accent-error: #f87171;
  --accent-error-glow: rgba(248, 113, 113, 0.25);
  --accent-warning: #fbbf24;
  --accent-rest: #a78bfa;

  /* Borders */
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-medium: rgba(255, 255, 255, 0.1);

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px var(--accent-primary-glow);

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', monospace;

  /* Sizing */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  /* Animation */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
  --transition-slow: 400ms ease;
}

/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.5;
}

/* Ambient background gradient */
body::before {
  content: '';
  position: fixed;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(ellipse at 30% 20%, rgba(124, 106, 239, 0.08) 0%, transparent 50%),
              radial-gradient(ellipse at 70% 80%, rgba(96, 165, 250, 0.06) 0%, transparent 50%);
  z-index: -1;
  animation: ambientFloat 20s ease-in-out infinite alternate;
}

@keyframes ambientFloat {
  0% { transform: translate(0, 0) rotate(0deg); }
  100% { transform: translate(-20px, 10px) rotate(2deg); }
}

/* ── Layout ───────────────────────────────────────────────── */
.app-container {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ───────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  margin-bottom: 16px;
}

.app-header__title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.app-header__icon {
  font-size: 1.5rem;
  filter: drop-shadow(0 0 8px var(--accent-primary-glow));
}

.app-header__actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ── MIDI Indicator ──────────────────────────────────────── */

.midi-indicator {
  font-size: 1rem;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  cursor: default;
  transition: all var(--transition-fast);
}

.midi-connected {
  background: rgba(52, 211, 153, 0.15);
  border: 1px solid var(--accent-success);
  animation: midi-pulse 2s ease-in-out infinite;
}

.midi-disconnected {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  opacity: 0.4;
  filter: grayscale(1);
}

.midi-denied,
.midi-unsupported {
  display: none !important;
}

@keyframes midi-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.3); }
  50% { box-shadow: 0 0 8px 2px rgba(52, 211, 153, 0.2); }
}

.icon-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  backdrop-filter: blur(8px);
}

.icon-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--border-medium);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

/* ── Main Content ─────────────────────────────────────────── */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ── Staff Card ───────────────────────────────────────────── */
.staff-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 24px;
  backdrop-filter: blur(12px);
  transition: box-shadow var(--transition-base);
  position: relative;
  overflow: visible;
}

.staff-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
  opacity: 0.5;
}

.staff-card.flash-correct {
  animation: flashCorrect 500ms ease-out;
}

.staff-card.flash-wrong {
  animation: flashWrong 500ms ease-out;
}

@keyframes flashCorrect {
  0% { box-shadow: 0 0 0 0 var(--accent-success-glow); }
  30% { box-shadow: 0 0 30px 4px var(--accent-success-glow); }
  100% { box-shadow: none; }
}

@keyframes flashWrong {
  0% { box-shadow: 0 0 0 0 var(--accent-error-glow); }
  30% { box-shadow: 0 0 30px 4px var(--accent-error-glow); }
  100% { box-shadow: none; }
}

.staff-label {
  font-size: 0.75rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 12px;
}

/* ── Feedback Area ────────────────────────────────────────── */
.feedback-area {
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: translateY(-8px);
  transition: all var(--transition-fast);
}

.feedback-area.show {
  opacity: 1;
  transform: translateY(0);
}

.feedback-correct {
  color: var(--accent-success);
  font-weight: 600;
  font-size: 1.1rem;
  animation: popIn 300ms ease-out;
}

.feedback-wrong {
  color: var(--accent-error);
  font-weight: 500;
  font-size: 0.95rem;
  animation: popIn 300ms ease-out;
}

.feedback-rest {
  color: var(--accent-rest);
  font-weight: 500;
  font-size: 0.9rem;
}

@keyframes popIn {
  0% { transform: scale(0.8); opacity: 0; }
  60% { transform: scale(1.05); }
  100% { transform: scale(1); opacity: 1; }
}

/* ── Answer Buttons ───────────────────────────────────────── */
.answer-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.answer-section__label {
  font-size: 0.75rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.answer-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
}

.answer-grid--interval {
  grid-template-columns: repeat(5, 1fr);
}

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

.answer-btn--sm {
  padding: 10px 0;
  font-size: 0.85rem;
}

.replay-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 8px;
  padding: 3px 10px;
  background: var(--accent-primary-glow);
  border: 1px solid var(--accent-primary);
  border-radius: var(--radius-sm);
  color: var(--accent-primary);
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  vertical-align: middle;
}

.replay-btn:hover {
  background: var(--accent-primary);
  color: #fff;
}

.answer-btn {
  position: relative;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  padding: 14px 0;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 1rem;
  transition: all var(--transition-fast);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.answer-btn__vi {
  font-size: 1rem;
  font-weight: 600;
}

.answer-btn__int {
  font-size: 0.65rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  font-weight: 400;
}

.answer-btn:hover:not(.disabled) {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: white;
  transform: translateY(-2px);
  box-shadow: var(--shadow-glow);
}

.answer-btn:hover:not(.disabled) .answer-btn__int {
  color: rgba(255, 255, 255, 0.7);
}

.answer-btn:active:not(.disabled) {
  transform: translateY(0);
  box-shadow: none;
}

.answer-btn.disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── Stats Bar ────────────────────────────────────────────── */
/* ── XP / Level / Streak Bar ────────────────────────────── */

.xp-bar-container {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}

.level-badge {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent-primary);
  background: var(--accent-primary-glow);
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;
}

.xp-bar {
  flex: 1;
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
}

.xp-bar__fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
  border-radius: 3px;
  transition: width 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.xp-text {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.daily-streak {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent-warning);
  white-space: nowrap;
}

/* ── Gamification Toasts ─────────────────────────────────── */

.gamification-toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  padding: 10px 24px;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 600;
  z-index: 10000;
  pointer-events: none;
  opacity: 0;
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
}

.gamification-toast.toast-visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast-level-up {
  background: linear-gradient(135deg, var(--accent-primary), #9333ea);
  color: #fff;
  box-shadow: 0 4px 20px rgba(124, 106, 239, 0.4);
}

.toast-achievement {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #fff;
  box-shadow: 0 4px 20px rgba(245, 158, 11, 0.4);
}

.stats-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.stat-item {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 10px;
  text-align: center;
  backdrop-filter: blur(8px);
}

.stat-item__icon {
  font-size: 0.9rem;
  margin-bottom: 2px;
}

.stat-item__value {
  font-size: 1rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-primary);
}

.stat-item__label {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 2px;
}

/* ── Settings Panel (Slide-in Sidebar) ────────────────────── */
.settings-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-base);
}

.settings-backdrop.open {
  opacity: 1;
  pointer-events: all;
}

.settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 340px;
  max-width: 90vw;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border-subtle);
  z-index: 100;
  transform: translateX(100%);
  transition: transform var(--transition-slow);
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.settings-panel.open {
  transform: translateX(0);
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.settings-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
}

.settings-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 4px;
}

.settings-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settings-section__title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.settings-section__title span {
  font-size: 1rem;
}

/* Toggle Switch */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
}

.toggle-row__label {
  font-size: 0.875rem;
  color: var(--text-primary);
}

.toggle-switch {
  position: relative;
  width: 40px;
  height: 22px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-medium);
  border-radius: 22px;
  transition: all var(--transition-fast);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  height: 16px;
  width: 16px;
  left: 2px;
  bottom: 2px;
  background: var(--text-secondary);
  border-radius: 50%;
  transition: all var(--transition-fast);
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(18px);
  background: white;
}

/* Radio Group */
.radio-group {
  display: flex;
  gap: 6px;
}

.radio-btn {
  flex: 1;
  padding: 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  transition: all var(--transition-fast);
}

.radio-btn input {
  display: none;
}

.radio-btn:has(input:checked) {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: white;
}

/* Volume Slider */
.volume-control {
  display: flex;
  align-items: center;
  gap: 10px;
}

.volume-control__label {
  font-size: 0.9rem;
}

.volume-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: 2px;
  outline: none;
}

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

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

/* Reset Button */
.btn-reset {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-medium);
  color: var(--text-secondary);
  padding: 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all var(--transition-fast);
  width: 100%;
}

.btn-reset:hover {
  background: var(--accent-error);
  border-color: var(--accent-error);
  color: white;
}

/* ── Stats Modal ──────────────────────────────────────────── */
.stats-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-base);
}

.stats-modal.open {
  opacity: 1;
  pointer-events: all;
}

.stats-modal__content {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 28px;
  max-width: 480px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  transform: scale(0.95) translateY(10px);
  transition: transform var(--transition-base);
}

.stats-modal.open .stats-modal__content {
  transform: scale(1) translateY(0);
}

.stats-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.stats-modal__header h2 {
  font-size: 1.15rem;
  font-weight: 700;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.stats-grid__item {
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: center;
}

.stats-grid__value {
  font-size: 1.4rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--accent-primary);
}

.stats-grid__label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 4px;
}

/* Per-note table */
.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.stats-table th {
  text-align: left;
  padding: 8px;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-subtle);
  font-weight: 600;
}

.stats-table td {
  padding: 8px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}

.stats-table tr:last-child td {
  border-bottom: none;
}

.accuracy-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 600;
  font-family: var(--font-mono);
}

.accuracy-badge.good { background: rgba(52, 211, 153, 0.15); color: var(--accent-success); }
.accuracy-badge.ok { background: rgba(251, 191, 36, 0.15); color: var(--accent-warning); }
.accuracy-badge.bad { background: rgba(248, 113, 113, 0.15); color: var(--accent-error); }
.accuracy-badge.none { background: var(--bg-tertiary); color: var(--text-muted); }

/* ── Weak Notes Badges (Spaced Repetition) ───────────────── */

.weak-notes-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.weak-note-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 600;
  background: rgba(248, 113, 113, 0.12);
  color: var(--accent-error);
  border: 1px solid rgba(248, 113, 113, 0.2);
}

.weak-note-badge .weak-note-pct {
  font-size: 0.7rem;
  font-family: var(--font-mono);
  opacity: 0.7;
}

.stats-modal__actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.stats-modal__actions button {
  flex: 1;
}

/* ── Staff Fallback ───────────────────────────────────────── */
.staff-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 30px;
  color: var(--text-secondary);
}

.staff-fallback__clef { font-size: 3rem; }
.staff-fallback__note { font-size: 2.5rem; color: var(--accent-primary); }
.staff-fallback__label { font-family: var(--font-mono); font-size: 0.9rem; }

/* ── Keyboard Hints ───────────────────────────────────────── */
.keyboard-hint {
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.keyboard-hint kbd {
  display: inline-block;
  padding: 1px 5px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-medium);
  border-radius: 3px;
  font-size: 0.65rem;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  margin: 0 1px;
}

/* ═══════════════════════════════════════════════════════════════
   Game Mode Tabs
   ═══════════════════════════════════════════════════════════════ */

.mode-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  padding: 4px;
  margin-bottom: 16px;
  border: 1px solid var(--border-subtle);
}

.mode-tab {
  flex: 1;
  cursor: pointer;
}

.mode-tab input { display: none; }

.mode-tab span {
  display: block;
  text-align: center;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: var(--transition-fast);
}

.mode-tab input:checked + span {
  background: var(--accent-primary);
  color: #fff;
  box-shadow: 0 2px 8px var(--accent-primary-glow);
}

.mode-tab:hover span {
  color: var(--text-primary);
}

/* ═══════════════════════════════════════════════════════════════
   Countdown Timer
   ═══════════════════════════════════════════════════════════════ */

.countdown-bar {
  position: relative;
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 8px;
}

.countdown-bar__fill {
  height: 100%;
  border-radius: 3px;
  transition: width 100ms linear;
}

.countdown-bar__fill--ok { background: var(--accent-success); }
.countdown-bar__fill--warn { background: var(--accent-warning); }
.countdown-bar__fill--danger { background: var(--accent-error); animation: pulse-danger 0.4s ease infinite alternate; }

@keyframes pulse-danger {
  from { opacity: 0.7; }
  to { opacity: 1; }
}

.countdown-bar__label {
  position: absolute;
  right: 4px;
  top: -18px;
  font-size: 0.65rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

/* ═══════════════════════════════════════════════════════════════
   Learning Mode Controls
   ═══════════════════════════════════════════════════════════════ */

.learning-controls {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 12px 0;
}

.learning-btn {
  padding: 10px 20px;
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 0.85rem;
  cursor: pointer;
  transition: var(--transition-fast);
}

.learning-btn:hover {
  background: var(--bg-card);
  border-color: var(--accent-primary);
}

.learning-btn--primary {
  background: var(--accent-primary);
  color: #fff;
  border-color: var(--accent-primary);
}

.learning-btn--primary:hover {
  filter: brightness(1.15);
}

/* ═══════════════════════════════════════════════════════════════
   Settings Sliders & Custom Range
   ═══════════════════════════════════════════════════════════════ */

.slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
}

.settings-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: 2px;
  outline: none;
}

.settings-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent-primary);
  cursor: pointer;
  box-shadow: 0 0 4px var(--accent-primary-glow);
}

.slider-value {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-secondary);
  min-width: 40px;
  text-align: right;
}

.settings-hint {
  font-size: 0.7rem;
  color: var(--text-muted);
  padding: 2px 0 4px;
  font-style: italic;
}

/* ── Octave Presets ────────────────────────────────────────── */

.octave-presets {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 8px 0;
}

.octave-preset {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 4px;
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  cursor: pointer;
  transition: var(--transition-fast);
}

.octave-preset:hover {
  border-color: var(--accent-primary);
  background: var(--bg-card);
}

.octave-preset.active {
  border-color: var(--accent-primary);
  background: rgba(124, 106, 239, 0.12);
  box-shadow: 0 0 0 1px var(--accent-primary);
}

.octave-preset__label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary);
}

.octave-preset.active .octave-preset__label {
  color: var(--accent-primary);
}

.octave-preset__desc {
  font-size: 0.6rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.octave-custom-range {
  display: flex;
  gap: 12px;
  padding: 8px 0;
}

.octave-custom-range label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.octave-custom-range select {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  font-size: 0.8rem;
}

/* ═══════════════════════════════════════════════════════════════
   Stats Tabs
   ═══════════════════════════════════════════════════════════════ */

.stats-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0;
}

.stats-tab {
  flex: 1;
  padding: 8px 12px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: var(--transition-fast);
}

.stats-tab:hover {
  color: var(--text-secondary);
}

.stats-tab.active {
  color: var(--accent-primary);
  border-bottom-color: var(--accent-primary);
}

/* ═══════════════════════════════════════════════════════════════
   History Chart
   ═══════════════════════════════════════════════════════════════ */

.history-chart {
  padding: 8px 0;
}

.history-chart__svg {
  width: 100%;
  height: auto;
}

.history-chart__grid-label {
  font-size: 8px;
  fill: var(--text-muted);
  font-family: var(--font-mono);
}

.history-chart__date-label {
  font-size: 7px;
  fill: var(--text-muted);
  font-family: var(--font-mono);
  text-anchor: middle;
}

.history-chart__bar {
  transition: opacity 150ms ease;
}

.history-chart__bar:hover {
  opacity: 1 !important;
}

.history-summary {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-secondary);
  padding: 8px 0;
}

.history-summary strong {
  color: var(--text-primary);
}

.history-empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.trend-up { color: var(--accent-success); font-weight: 600; }
.trend-down { color: var(--accent-error); font-weight: 600; }
.trend-flat { color: var(--text-muted); }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 600px) {
  .app-container { padding: 12px; }
  .answer-grid { gap: 6px; }
  .answer-btn { padding: 12px 0; font-size: 0.9rem; }
  .stats-bar { grid-template-columns: repeat(2, 1fr); }
  .settings-panel { width: 100%; }
  .staff-card { padding: 16px; }
  .keyboard-hint { display: none; }
  .mode-tabs { gap: 2px; }
  .mode-tab span { padding: 6px 8px; font-size: 0.7rem; }
  .learning-btn { padding: 8px 14px; font-size: 0.8rem; }
}

@media (max-width: 400px) {
  .answer-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* ═══ Analytics Dashboard ════════════════════════════════════ */

.analytics-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.analytics-modal.analytics-visible {
  opacity: 1;
}

.analytics-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}

.analytics-panel {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(95vw, 540px);
  max-height: 85vh;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-elevated);
  overflow-y: auto;
  padding: 20px;
}

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

.analytics-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.analytics-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}

.analytics-close:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.analytics-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}

.analytics-stat {
  text-align: center;
  padding: 10px 4px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
}

.analytics-stat__value {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent-primary);
  font-family: var(--font-mono);
}

.analytics-stat__label {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.analytics-chart-section {
  margin-bottom: 18px;
}

.analytics-chart-section h3 {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 0 0 8px;
}

.analytics-chart-section canvas {
  width: 100%;
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
}

.note-heatmap {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.heatmap-note {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 4px;
  border-radius: var(--radius-sm);
  gap: 2px;
}

.heatmap-note__name {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-primary);
}

.heatmap-note__pct {
  font-size: 0.8rem;
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--text-primary);
}

.heatmap-note__count {
  font-size: 0.6rem;
  color: var(--text-muted);
}

.activity-grid {
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  gap: 3px;
}

.activity-cell {
  aspect-ratio: 1;
  border-radius: 3px;
  min-width: 0;
}

.activity-level-0 { background: rgba(224, 224, 255, 0.05); }
.activity-level-1 { background: rgba(124, 106, 239, 0.25); }
.activity-level-2 { background: rgba(124, 106, 239, 0.5); }
.activity-level-3 { background: rgba(124, 106, 239, 0.75); }
.activity-level-4 { background: rgba(124, 106, 239, 1.0); }

/* ═══ Lesson Mode ═══════════════════════════════════════════ */

.lesson-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 60vh;
  overflow-y: auto;
  padding: 4px 0;
}

.lesson-unit-header {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent-primary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 12px 0 4px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 4px;
}

.lesson-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  cursor: pointer;
  text-align: left;
  font-family: var(--font-sans);
  transition: all var(--transition-fast);
  width: 100%;
  color: var(--text-primary);
}

.lesson-card:hover:not([disabled]) {
  border-color: var(--accent-primary);
  transform: translateX(4px);
}

.lesson-card--locked {
  opacity: 0.4;
  cursor: not-allowed;
}

.lesson-card--done {
  border-color: rgba(16, 185, 129, 0.3);
  background: rgba(16, 185, 129, 0.05);
}

.lesson-card__icon {
  font-size: 1.3rem;
  flex-shrink: 0;
}

.lesson-card__title {
  font-weight: 600;
  font-size: 0.9rem;
}

.lesson-card__desc {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.lesson-active__header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.lesson-back-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.8rem;
  transition: background var(--transition-fast);
}

.lesson-back-btn:hover {
  background: var(--accent-primary);
  color: #fff;
}

.lesson-active__title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
}

.lesson-progress-bar {
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 4px;
}

.lesson-progress-bar__fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-primary), #10b981);
  border-radius: 3px;
  transition: width 0.4s ease;
}

.lesson-progress-text {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: center;
}

/* ── Song Picker (Grand Staff Sheet Music) ───────────────── */
.song-picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
  padding: 8px 0;
}

.song-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 16px;
  cursor: pointer;
  transition: all 0.25s ease;
  position: relative;
  overflow: hidden;
}
.song-card:hover {
  border-color: var(--accent-primary);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(167, 139, 250, 0.15);
}
.song-card__title {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text-primary);
  margin-bottom: 4px;
}
.song-card__composer {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.song-card__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.song-card__difficulty {
  color: #fbbf24;
  letter-spacing: 2px;
}
.song-card__info {
  font-family: var(--font-mono);
  font-size: 0.7rem;
}

/* Song playing header */
.song-playing__header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
}
.song-playing__title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
  flex: 1;
}
.song-autoplay-btn {
  padding: 6px 14px;
  border-radius: 8px;
  border: 1px solid var(--accent-primary);
  background: rgba(167, 139, 250, 0.15);
  color: var(--accent-primary);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}
.song-autoplay-btn:hover {
  background: rgba(167, 139, 250, 0.3);
}
.song-autoplay-btn.playing {
  background: rgba(239, 68, 68, 0.2);
  border-color: #ef4444;
  color: #ef4444;
}
.song-progress-bar {
  height: 5px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  margin: 6px 0;
  overflow: hidden;
}
.song-progress-bar__fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary, #c084fc));
  border-radius: 3px;
  transition: width 0.4s ease;
  width: 0%;
}
.song-progress-text {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: center;
}
