/* ==========================================================================
   Beato Ear Training Program — 2026 Design System
   ========================================================================== */

/* --- Variables --- */
:root {
  --color-bg: #FFFFFF;
  --color-surface: #F9F5F1;
  --color-border: #E8E2DA;
  --color-text: #1A1A1A;
  --color-text-secondary: #6B6560;
  --color-accent: #1266E5;
  --color-accent-hover: #0F52BD;
  --color-accent-light: #EBF1FC;
  --color-success: #16A34A;
  --color-success-light: #DCFCE7;
  --color-error: #DC2626;
  --color-error-light: #FEE2E2;
  --color-practice: #1266E5;
  --color-test: #DC2626;
  --color-listen: #16A34A;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --sidebar-width: 260px;
  --topbar-height: 56px;
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-serif: 'DM Serif Display', Georgia, serif;
}

/* --- Dark Theme --- */
[data-theme="dark"] {
  --color-bg: #1A1816;
  --color-surface: #23201D;
  --color-border: #342F2A;
  --color-text: #E8E2DA;
  --color-text-secondary: #9B9590;
  --color-accent: #4D94FF;
  --color-accent-hover: #3A7FE8;
  --color-accent-light: #1A2A40;
  --color-success: #22C55E;
  --color-success-light: #14301D;
  --color-error: #EF4444;
  --color-error-light: #3B1414;
  --color-practice: #4D94FF;
  --color-test: #EF4444;
  --color-listen: #22C55E;
}

/* Dark: piano keys */
/* Dark: piano keeps real-world colors */
[data-theme="dark"] .piano-white { background: #fff; border-color: #ccc; }
[data-theme="dark"] .answer-btn.piano-white:hover { background: #eee; border-color: #aaa; color: #333; }
/* Color only the key itself — labels (.piano-label spans on the inner-note board)
   must inherit, or state colors (shell blue, correct green, wrong red) never reach them. */
[data-theme="dark"] .piano-white { color: #6B6560; }
[data-theme="dark"] .piano-black { background: #1A1A1A; border-color: #000; }
[data-theme="dark"] .answer-btn.piano-black:hover { background: #333; border-color: #333; }
[data-theme="dark"] .piano-white.piano-disabled { background: #EDEDED; border-color: #E0E0E0; }
[data-theme="dark"] .piano-black.piano-disabled { background: #999; border-color: #888; }

/* Dark: alerts */
[data-theme="dark"] .alert-success { border-color: #14301D; }
[data-theme="dark"] .alert-error { border-color: #3B1414; }
[data-theme="dark"] .alert-info { border-color: #1A2A40; }

/* Dark: loading overlay */
[data-theme="dark"] .loading-overlay { background: rgba(26, 24, 22, 0.8); }

/* Dark: listen button hover */
[data-theme="dark"] .btn-listen:hover { background: #16A34A; border-color: #16A34A; }

/* --- Theme Toggle --- */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: none;
  cursor: pointer;
  color: var(--color-text-secondary);
  transition: border-color 0.15s, color 0.15s;
}

.theme-toggle:hover {
  border-color: var(--color-text-secondary);
  color: var(--color-text);
}

.theme-toggle svg { width: 18px; height: 18px; }

/* Show moon in light, sun in dark */
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* --- Reset / Base --- */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  color: var(--color-text);
  background-color: var(--color-bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 { margin: 0 0 0.5em; font-weight: 600; line-height: 1.3; }

h1 { font-family: var(--font-serif); font-size: 2rem; font-weight: 400; }
h2 { font-family: var(--font-serif); font-size: 1.5rem; font-weight: 400; }

a { color: var(--color-accent); text-decoration: none; }
a:hover { color: var(--color-accent-hover); }

p { margin: 0 0 1em; }
img { max-width: 100%; height: auto; }
ul { list-style: none; margin: 0; padding: 0; }

::placeholder { color: var(--color-text-secondary); opacity: 0.6; }

/* --- Layout --- */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  z-index: 100;
  overflow-y: auto;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
}

.sidebar.open { transform: translateX(0); }

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 99;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.sidebar.open ~ .sidebar-backdrop {
  opacity: 1;
  pointer-events: auto;
}

.sidebar-logo {
  display: block;
  padding: 24px 28px 16px;
}

.sidebar-logo img {
  width: 85%;
  display: block;
  margin: 0 auto;
}

/* Lockup colorway follows the theme (dark art = white text) */
.sidebar-logo .logo-dark { display: none; }
[data-theme="dark"] .sidebar-logo .logo-light { display: none; }
[data-theme="dark"] .sidebar-logo .logo-dark { display: block; }

.sidebar-nav { padding: 8px 0; }

.sidebar-nav a {
  display: flex;
  align-items: center;
  padding: 10px 24px;
  color: var(--color-text);
  font-size: 14px;
  font-weight: 500;
  border-radius: 0;
  transition: background 0.15s, color 0.15s;
}

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

.sidebar-nav a.active {
  color: var(--color-accent);
  background: var(--color-accent-light);
}

.sidebar-nav a.disabled {
  opacity: 0.4;
  pointer-events: none;
}

.sidebar-section-label {
  padding: 24px 24px 8px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-secondary);
}

.sidebar-subnav a {
  padding-left: 40px;
  font-size: 13px;
  font-weight: 400;
  color: var(--color-text-secondary);
}

.sidebar-subnav a:hover { color: var(--color-text); }
.sidebar-subnav a.active { color: var(--color-accent); background: var(--color-accent-light); }

.badge-new {
  margin-left: auto;
  padding: 1px 7px;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-accent);
  background: var(--color-accent-light);
  border-radius: 999px;
}

/* Active row is already accent-light; keep the badge legible on it */
.sidebar-subnav a.active .badge-new { background: var(--color-bg); }

/* --- Main Content --- */
.main-content {
  flex: 1;
  min-width: 0;
  margin-left: 0;
  transition: margin-left 0.25s ease;
}

/* --- Topbar --- */
.topbar {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-right { display: flex; align-items: center; gap: 16px; }

.topbar-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
}

.hamburger {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: var(--radius-sm);
  color: var(--color-text);
}

.hamburger:hover { background: var(--color-bg); }

.hamburger svg { width: 20px; height: 20px; }

/* --- Topbar user menu --- */
.user-menu { position: relative; }

.user-menu-trigger {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: none;
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text);
  transition: border-color 0.15s;
}

.user-menu-trigger:hover { border-color: var(--color-text-secondary); }

.user-menu-trigger svg { width: 14px; height: 14px; }

.user-menu-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 160px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 4px;
  z-index: 60;
}

.user-menu-dropdown.open { display: block; }

.user-menu-dropdown a {
  display: block;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--color-text-secondary);
  border-radius: 4px;
}

.user-menu-dropdown a:hover,
.user-menu-logout:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

.user-menu-logout {
  display: block;
  width: 100%;
  padding: 8px 12px;
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--color-text-secondary);
  background: none;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  text-align: left;
}

/* --- Page Content --- */
.page-content {
  padding: 32px 24px;
  max-width: 1100px;
  margin: 0 auto;
}

/* --- Cards --- */
.card-modern {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 24px;
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 24px;
  text-align: center;
  transition: border-color 0.15s;
}

.stat-card:hover { border-color: var(--color-text-secondary); }

.stat-card-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-secondary);
  margin-bottom: 8px;
}

.stat-card-value {
  font-family: var(--font-serif);
  font-size: 2rem;
  font-weight: 400;
  color: var(--color-text);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-top: 24px;
}

/* Quickstart / CTA card */
.cta-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 20px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.cta-card-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-secondary);
  margin-bottom: 4px;
}

.cta-card-text {
  font-size: 15px;
  color: var(--color-text);
  margin: 0;
}

.cta-card-text .accent { color: var(--color-accent); font-weight: 500; }

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 20px;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
  text-decoration: none;
}

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

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

.btn-secondary {
  background: transparent;
  color: var(--color-text);
  border-color: var(--color-border);
}

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

.btn-danger {
  background: transparent;
  color: var(--color-error);
  border-color: var(--color-error);
}

.btn-danger:hover {
  background: var(--color-error);
  color: #fff;
}

.btn-success {
  background: transparent;
  color: var(--color-listen);
  border-color: var(--color-listen);
}

.btn-success:hover {
  background: var(--color-listen);
  color: #fff;
}

.btn-sm {
  padding: 5px 14px;
  font-size: 13px;
}

/* Chapter video not published yet: button-shaped, but inert */
.video-soon {
  opacity: 0.55;
  cursor: default;
  pointer-events: none;
  color: var(--color-text-secondary);
}

/* --- Lesson Table --- */
.lesson-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin-top: 32px;
}

.lesson-table thead th {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-secondary);
  padding: 0 16px 12px;
  border-bottom: 1px solid var(--color-border);
  text-align: left;
}

.lesson-table tbody tr {
  transition: background 0.1s;
}

.lesson-table tbody tr:hover {
  background: var(--color-bg);
}

.lesson-table tbody td {
  padding: 14px 16px;
  font-size: 14px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

.lesson-table tbody td:first-child { font-weight: 500; }

.lesson-title-cell { display: flex; align-items: center; gap: 8px; }

.check-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--color-success-light);
  color: var(--color-success);
  flex-shrink: 0;
}

.check-icon svg { width: 12px; height: 12px; }

.lesson-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.lesson-actions a {
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
}

.lesson-actions .practice-link {
  color: var(--color-accent);
  border: 1px solid var(--color-accent);
}

.lesson-actions .practice-link:hover {
  background: var(--color-accent);
  color: #fff;
}

.lesson-actions .test-link {
  color: var(--color-error);
  border: 1px solid var(--color-error);
}

.lesson-actions .test-link:hover {
  background: var(--color-error);
  color: #fff;
}

.lesson-actions .listen-link {
  color: var(--color-listen);
  border: 1px solid var(--color-listen);
}

.lesson-actions .listen-link:hover {
  background: var(--color-listen);
  color: #fff;
}

.video-link-small {
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-left: 4px;
}

.video-link-small:hover { color: var(--color-accent); }

/* Sort dropdown */
.sort-select {
  font-family: var(--font-sans);
  font-size: 13px;
  padding: 4px 8px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text-secondary);
  cursor: pointer;
}

/* --- Progress Bar --- */
.progress-bar-track {
  height: 4px;
  width: 100%;
  background: var(--color-border);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 12px;
}

.progress-bar-fill {
  height: 100%;
  background: var(--color-accent);
  border-radius: 2px;
  transition: width 0.4s ease;
}

/* --- Quiz Mode Bar --- */
.mode-bar {
  padding: 10px 24px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: #fff;
}

.mode-bar-practice { background: var(--color-practice); }
.mode-bar-test { background: var(--color-test); }
.mode-bar-listen { background: var(--color-listen); }

/* --- Quiz Interface --- */
.quiz-layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.quiz-header {
  padding: 16px 24px;
  text-align: center;
  position: relative;
}

.quiz-header h5 {
  font-size: 17px;
  font-weight: 500;
  color: var(--color-text-secondary);
  margin-bottom: 4px;
}

.quiz-header h1 {
  font-family: var(--font-serif);
  font-size: 2.25rem;
  margin-bottom: 0;
}

.quiz-back {
  position: absolute;
  left: 24px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--color-text-secondary);
  font-size: 14px;
}

.quiz-back:hover { color: var(--color-text); }

.quiz-back svg { width: 16px; height: 16px; }

.quiz-action-right {
  position: absolute;
  right: 24px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: 16px;
}

.quiz-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px;
}

/* Reference note (twelve tone harmony) */
.reference-note-container {
  text-align: center;
  margin-bottom: 8px;
}

.reference-note-btn {
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  color: var(--color-accent);
  background: none;
  border: 1.5px solid var(--color-accent);
  border-radius: 100px;
  padding: 8px 20px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

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

.reference-note-hint {
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-top: 6px;
}

.player-container {
  margin: 16px auto 24px;
  max-width: 320px;
  width: 100%;
}

.quiz-description {
  font-size: 14px;
  color: var(--color-text-secondary);
  margin-bottom: 32px;
  text-align: center;
}

/* Answer buttons */
.answer-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
}

.answer-btn {
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text-secondary);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  min-width: 80px;
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s, color 0.1s;
  flex-basis: calc(20% - 10px);
  flex-grow: 1;
  text-align: center;
}

/* A button that lands alone on the grid's last row (11 answers = 5+5+1,
   e.g. the Bitonal "All" capstones) shouldn't stretch full-width: keep it
   column-sized and centered. Inert in the -3col/-4col grid variants
   (display: grid ignores flex-grow) and in -nowrap (already flex-grow: 0). */
.answer-grid > .answer-btn:nth-child(5n+1):last-child {
  flex-grow: 0;
}

.answer-btn:hover {
  border-color: var(--color-text-secondary);
  background: var(--color-bg);
  color: var(--color-text);
}

/* Fixed-column grid (e.g. rhythm: 4 beats per row) */
.answer-grid.answer-grid-4col {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  max-width: 520px;
}

/* Fixed 3-column grid (e.g. Polyrhythm capstone: 6 ratios as 3 + 3) */
.answer-grid.answer-grid-3col {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  max-width: 420px;
}

/* Single-row layout (pentatonic/diatonic note buttons) */
.answer-grid.answer-grid-nowrap {
  flex-wrap: nowrap;
  max-width: 700px;
}

.answer-grid.answer-grid-nowrap .answer-btn {
  flex-basis: auto;
  flex-grow: 0;
  min-width: 60px;
  padding: 10px 14px;
}

.answer-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.answer-btn.correct {
  border-color: var(--color-success);
  background: var(--color-success-light);
  color: var(--color-success);
}

.answer-btn.wrong {
  border-color: var(--color-error);
  background: var(--color-error);
  color: #fff;
}

.answer-btn.show-correct {
  border-color: var(--color-success);
  background: var(--color-success-light);
  color: var(--color-success);
}

/* --- Dictation strip (melodic dictation) --- */
.dictation-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin: 8px 0 4px;
}

.dict-slot {
  min-width: 44px;
  height: 44px;
  padding: 0 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  font-weight: 600;
  font-size: 16px;
}

.dict-slot.filled {
  border-color: var(--color-success);
  background: var(--color-success-light);
  color: var(--color-success);
}

/* Practice-mode reveal after a miss: the rest of the melody, read-only */
.dict-slot.revealed {
  border-style: dashed;
  color: var(--color-text-secondary);
}

.dict-slot.missed {
  border-color: var(--color-error);
  background: var(--color-error-light);
  color: var(--color-error);
}

.dictation-hint {
  text-align: center;
  font-size: 13px;
  color: var(--color-text-secondary);
  margin: 6px 0 0;
}

/* --- Piano Keyboard (scale trainer) --- */
.piano-keyboard {
  position: relative;
  max-width: 700px;
  width: 100%;
  margin: 0 auto;
  height: 200px;
}

.piano-whites {
  display: flex;
  height: 100%;
}

.piano-white {
  flex: 1;
  height: 100%;
  min-width: 0;
  background: #fff;
  border: 1px solid var(--color-border);
  margin-right: -1px;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0 0 14px;
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text-secondary);
}

.piano-white:last-child { margin-right: 0; }

.answer-btn.piano-white:disabled,
.answer-btn.piano-black:disabled {
  opacity: 1;
}

.answer-btn.piano-white:hover {
  background: var(--color-surface);
  border-color: var(--color-text-secondary);
  color: var(--color-text);
  z-index: 1;
}

.piano-blacks {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 60%;
  pointer-events: none;
}

.piano-black {
  position: absolute;
  top: 0;
  width: calc(100% / 7 * 0.56);
  min-width: 0;
  height: 100%;
  background: var(--color-text);
  color: rgba(255, 255, 255, 0.85);
  border: 1px solid #000;
  border-radius: 0 0 5px 5px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0 0 10px;
  font-size: 12px;
  font-weight: 500;
  pointer-events: auto;
  z-index: 2;
}

.answer-btn.piano-black:hover {
  background: #333;
  border-color: #333;
  color: #fff;
}

/* Black key positions: centered on white key boundaries */
.piano-black:nth-child(1) { left: calc(100% / 7 * 1 - 100% / 7 * 0.28); }
.piano-black:nth-child(2) { left: calc(100% / 7 * 2 - 100% / 7 * 0.28); }
.piano-black:nth-child(3) { left: calc(100% / 7 * 4 - 100% / 7 * 0.28); }
.piano-black:nth-child(4) { left: calc(100% / 7 * 5 - 100% / 7 * 0.28); }
.piano-black:nth-child(5) { left: calc(100% / 7 * 6 - 100% / 7 * 0.28); }

/* Melodic dictation: an absolute 2-octave keyboard (A3-A5) = 15 white keys + 10 blacks.
   The degree labels + answer-ids are placed by JS onto the real pitch positions for the
   current key; only keys C..F play, so every example fits this range. Blacks sit on white
   boundaries 1,3,4,6,7,8,10,11,13,14 (Bb3 Db4 Eb4 Gb4 Ab4 Bb4 Db5 Eb5 Gb5 Ab5). */
/* Two full octaves, so let it use more width on larger screens. width:100% (on the base
   rule) still caps it to the container, so it never overflows. */
.piano-keyboard.two-octave { max-width: 1100px; }
.piano-keyboard.two-octave .piano-black { width: calc(100% / 15 * 0.56); }
.piano-keyboard.two-octave .piano-black:nth-child(1)  { left: calc(100% / 15 * 1 - 100% / 15 * 0.28); }
.piano-keyboard.two-octave .piano-black:nth-child(2)  { left: calc(100% / 15 * 3 - 100% / 15 * 0.28); }
.piano-keyboard.two-octave .piano-black:nth-child(3)  { left: calc(100% / 15 * 4 - 100% / 15 * 0.28); }
.piano-keyboard.two-octave .piano-black:nth-child(4)  { left: calc(100% / 15 * 6 - 100% / 15 * 0.28); }
.piano-keyboard.two-octave .piano-black:nth-child(5)  { left: calc(100% / 15 * 7 - 100% / 15 * 0.28); }
.piano-keyboard.two-octave .piano-black:nth-child(6)  { left: calc(100% / 15 * 8 - 100% / 15 * 0.28); }
.piano-keyboard.two-octave .piano-black:nth-child(7)  { left: calc(100% / 15 * 10 - 100% / 15 * 0.28); }
.piano-keyboard.two-octave .piano-black:nth-child(8)  { left: calc(100% / 15 * 11 - 100% / 15 * 0.28); }
.piano-keyboard.two-octave .piano-black:nth-child(9)  { left: calc(100% / 15 * 13 - 100% / 15 * 0.28); }
.piano-keyboard.two-octave .piano-black:nth-child(10) { left: calc(100% / 15 * 14 - 100% / 15 * 0.28); }

/* Answer states need to override piano hover styles */
.answer-btn.piano-white.correct,
.answer-btn.piano-white.correct:hover,
.answer-btn.piano-white.show-correct,
.answer-btn.piano-white.show-correct:hover {
  background: var(--color-success-light);
  border-color: var(--color-success);
  color: var(--color-success);
}

.answer-btn.piano-white.wrong,
.answer-btn.piano-white.wrong:hover {
  background: var(--color-error);
  border-color: var(--color-error);
  color: #fff;
}

.answer-btn.piano-black.correct,
.answer-btn.piano-black.correct:hover,
.answer-btn.piano-black.show-correct,
.answer-btn.piano-black.show-correct:hover {
  background: var(--color-success-light);
  border-color: var(--color-success);
  color: var(--color-success);
}

.answer-btn.piano-black.wrong,
.answer-btn.piano-black.wrong:hover {
  background: var(--color-error);
  border-color: var(--color-error);
  color: #fff;
}

/* Establishment cue (melodic dictation): highlight the tonic triad, then the root.
   Blue fill matches the app's "reference key" language (piano-shell); a 1px darker-blue
   border delineates each key (no glow). Distinct from the green/red answer states. */
.answer-btn.piano-white {
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.answer-btn.piano-white.est-triad,
.answer-btn.piano-white.est-root {
  background: var(--color-accent);
  border-color: var(--color-accent-hover);
  color: #fff;
  z-index: 1;
}
/* On the absolute keyboard the tonic triad can land on black keys (e.g. Eb + Bb in
   the key of Eb), so they highlight too; keep them stacked above the white keys. */
.answer-btn.piano-black {
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.answer-btn.piano-black.est-triad,
.answer-btn.piano-black.est-root {
  background: var(--color-accent);
  border-color: var(--color-accent-hover);
  color: #fff;
  z-index: 3;
}

/* Piano: shell keys (pre-highlighted, not clickable) */
.piano-white.piano-shell {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: #fff;
  cursor: default;
}

.piano-black.piano-shell {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: #fff;
  cursor: default;
}

.piano-shell .piano-label {
  font-weight: 600;
}

/* Piano: disabled keys (outside the shell range) */
.piano-white.piano-disabled {
  background: #EDEDED;
  border-color: #E0E0E0;
  cursor: default;
}

.piano-black.piano-disabled {
  background: #999;
  border-color: #888;
  cursor: default;
}

/* Quiz timer */
.quiz-timer {
  display: block;
  font-family: var(--font-serif);
  font-size: 24px;
  color: var(--color-text-secondary);
  margin-top: 6px;
}

/* Quiz bottom progress */
.quiz-progress {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--color-border);
  z-index: 50;
}

.quiz-progress-fill {
  height: 100%;
  background: var(--color-accent);
  transition: width 0.4s ease;
}

.quiz-progress-label {
  position: fixed;
  bottom: 8px;
  font-size: 12px;
  color: var(--color-text-secondary);
  transition: left 0.4s ease;
}

/* --- Get Started / Pre-Quiz --- */
.get-started-layout {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - var(--topbar-height));
  padding: 32px 24px;
  text-align: center;
}

.play-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 2px solid var(--color-border);
  background: var(--color-surface);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  margin: 40px 0 24px;
}

.play-btn:hover {
  border-color: var(--color-accent);
  background: var(--color-accent-light);
}

.play-btn svg {
  width: 28px;
  height: 28px;
  color: var(--color-accent);
  margin-left: 3px; /* optical center for play triangle */
}

.play-btn-test { border-color: var(--color-error); }
.play-btn-test:hover { background: var(--color-error-light); border-color: var(--color-error); }
.play-btn-test svg { color: var(--color-error); }

.play-btn-listen { border-color: var(--color-listen); }
.play-btn-listen:hover { background: var(--color-success-light); border-color: var(--color-listen); }
.play-btn-listen svg { color: var(--color-listen); }

.speed-selector {
  display: flex;
  gap: 8px;
  margin-top: 40px;
}

.speed-btn {
  font-family: var(--font-sans);
  padding: 8px 24px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text-secondary);
  transition: all 0.15s;
}

.speed-btn:hover { border-color: var(--color-text-secondary); }
.speed-btn.active {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: #fff;
}

/* --- Results --- */
.result-layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - var(--topbar-height));
  padding: 32px 24px;
}

.result-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 48px;
  text-align: center;
  max-width: 420px;
  width: 100%;
}

.result-pass { border-top: 3px solid var(--color-success); }
.result-fail { border-top: 3px solid var(--color-error); }

.result-title {
  font-family: var(--font-serif);
  font-size: 2rem;
  margin-bottom: 16px;
}

.result-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 24px 0;
  text-align: center;
}

.result-stat-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-secondary);
}

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

.result-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 24px;
}

/* --- Settings --- */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
  margin-top: 24px;
}

.settings-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 24px;
}

.settings-card h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.settings-card p {
  font-size: 14px;
  color: var(--color-text-secondary);
}

/* Toggle switch */
.toggle {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

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

.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--color-border);
  border-radius: 12px;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle input:checked + .toggle-slider { background: var(--color-accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* --- Auth Pages (Dark Theme) --- */
.auth-body {
  min-height: 100vh;
  background:
    radial-gradient(ellipse at 25% 20%, hsla(220, 50%, 14%, 0.7) 0%, transparent 50%),
    radial-gradient(ellipse at 75% 80%, hsla(15, 40%, 12%, 0.5) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 50%, hsla(260, 30%, 10%, 0.4) 0%, transparent 70%),
    #111111;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  font-family: var(--font-sans);
  color: #fff;
}

.auth-logo { margin-bottom: 48px; }
.auth-logo img { height: 120px; display: block; }

.auth-card {
  width: 100%;
  max-width: 380px;
}

.auth-input {
  display: block;
  width: 100%;
  padding: 12px 0;
  font-family: var(--font-sans);
  font-size: 15px;
  color: #fff;
  background: transparent;
  border: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.3);
  outline: none;
  transition: border-color 0.15s;
  margin-bottom: 24px;
}

.auth-input:focus { border-bottom-color: #fff; }

.auth-input::placeholder { color: rgba(255, 255, 255, 0.5); }

.auth-btn {
  display: block;
  width: 160px;
  margin: 32px auto 0;
  padding: 10px 0;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 24px;
  background: transparent;
  color: #fff;
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.auth-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: #fff;
}

.auth-links {
  text-align: center;
  margin-top: 24px;
}

.auth-links a {
  display: block;
  color: rgba(255, 255, 255, 0.7);
  font-size: 13px;
  margin-top: 12px;
}

.auth-links a:hover { color: #fff; }

.auth-error {
  background: rgba(220, 38, 38, 0.15);
  border: 1px solid rgba(220, 38, 38, 0.3);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  color: #fca5a5;
  margin-bottom: 16px;
}

.auth-field-error {
  font-size: 12px;
  color: #fca5a5;
  margin-top: -20px;
  margin-bottom: 16px;
}

.license-field {
  width: 100%;
  padding: 10px;
  font-family: var(--font-sans);
  font-size: 14px;
  color: #fff;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-sm);
  resize: none;
  outline: none;
  margin-bottom: 16px;
}

.license-field:focus { border-color: rgba(255, 255, 255, 0.5); }

#license_label {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.7);
  margin-bottom: 8px;
  display: block;
}

/* --- Video Overlay --- */
.video-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  background: rgba(0, 0, 0, 0.7);
  align-items: center;
  justify-content: center;
}

.video-overlay .plyr {
  width: 100%;
  max-width: 800px;
  border-radius: var(--radius-md);
}

/* --- Alert / Toast --- */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 16px;
}

.alert-success {
  background: var(--color-success-light);
  color: var(--color-success);
  border: 1px solid #bbf7d0;
}

.alert-error {
  background: var(--color-error-light);
  color: var(--color-error);
  border: 1px solid #fecaca;
}

.alert-info {
  background: var(--color-accent-light);
  color: var(--color-accent);
  border: 1px solid #bfdbfe;
}

/* --- Tooltip (leaderboard) --- */
.tooltip-wrapper {
  position: relative;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 3px;
  cursor: help;
  outline: none;
}

/* Hover/focus popover with the top-10 times; real markup so it renders
   as a list (the old title-attribute tooltip showed literal <br> text) */
.leaderboard-pop {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 100;
  min-width: 240px;
  padding: 6px 0;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14);
}

.tooltip-wrapper:hover .leaderboard-pop,
.tooltip-wrapper:focus-within .leaderboard-pop { display: block; }

.lb-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 4px 14px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--color-text);
  white-space: nowrap;
}

.lb-rank {
  width: 16px;
  text-align: right;
  color: var(--color-text-secondary);
  font-variant-numeric: tabular-nums;
}

.lb-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lb-time {
  color: var(--color-text-secondary);
  font-variant-numeric: tabular-nums;
}

/* --- Loading --- */
.loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(249, 245, 241, 0.8);
  align-items: center;
  justify-content: center;
}

body.loading .loading-overlay { display: flex; }

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* --- Utilities --- */
.text-secondary { color: var(--color-text-secondary); }
.text-success { color: var(--color-success); }
.text-error { color: var(--color-error); }
.text-accent { color: var(--color-accent); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.font-serif { font-family: var(--font-serif); }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mt-4 { margin-top: 32px; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.d-none { display: none; }
.d-inline { display: inline; }
.d-block { display: block; }
.d-flex { display: flex; }
.gap-2 { gap: 16px; }
.flex-1 { flex: 1; }

/* --- Responsive --- */
@media (min-width: 768px) {
  .sidebar {
    transform: translateX(0);
    transition: none;
  }

  .sidebar-backdrop { display: none; }

  .main-content { margin-left: var(--sidebar-width); }

  .hamburger { display: none; }

  /* Hide sidebar on full-screen (quiz) pages */
  .app-layout.fullscreen .sidebar { display: none; }
  .app-layout.fullscreen .main-content { margin-left: 0; }
}

@media (max-width: 767px) {
  .stat-grid { grid-template-columns: 1fr; }

  .cta-card { flex-direction: column; align-items: stretch; text-align: center; }

  .page-content { padding: 20px 16px; }

  /* Lesson table becomes card layout on mobile */
  .lesson-table,
  .lesson-table thead,
  .lesson-table tbody,
  .lesson-table tr,
  .lesson-table td,
  .lesson-table th {
    display: block;
  }

  .lesson-table thead { display: none; }

  .lesson-table tbody tr {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 12px;
  }

  .lesson-table tbody td {
    padding: 4px 0;
    border-bottom: none;
  }

  .lesson-table tbody td:first-child { font-size: 15px; margin-bottom: 8px; }

  .lesson-actions {
    margin-top: 12px;
    justify-content: stretch;
  }
  .lesson-actions a {
    flex: 1;
    text-align: center;
    padding: 10px 8px;
    font-size: 14px;
  }

  .lesson-title-cell {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
  }

  .video-link-small {
    padding: 6px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    white-space: nowrap;
    flex-shrink: 0;
    margin-left: 12px;
  }

  .answer-grid { max-width: 100%; }

  .answer-btn {
    flex-basis: calc(50% - 10px);
    padding: 12px 8px;
  }

  .quiz-header h1 { font-size: 1.2rem; }

  .quiz-back { position: static; transform: none; margin-bottom: 8px; }

  .quiz-action-right { position: static; transform: none; margin-top: 8px; }

  .quiz-timer {
    position: static;
    transform: none;
    text-align: center;
    margin-top: 8px;
  }

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

  .result-card { padding: 32px 24px; }

  .settings-grid { grid-template-columns: 1fr; }

  .speed-selector { flex-direction: column; align-items: center; }

  .piano-keyboard { height: 150px; }
  .piano-white { font-size: 12px; padding-bottom: 10px; }
  .piano-black { font-size: 10px; padding-bottom: 6px; }

  .auth-logo img { height: 100px; }
  .auth-card { max-width: 100%; }
}

/* --- Listen Mode --- */
.listen-answer {
  font-family: var(--font-serif);
  font-size: 3rem;
  color: var(--color-text);
  margin: 4px 0 32px;
  text-align: center;
}

.btn-listen {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 28px;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 500;
  background: var(--color-listen);
  color: #fff;
  border: 1px solid var(--color-listen);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn-listen:hover {
  background: #15803D;
  border-color: #15803D;
}

.btn-listen:disabled {
  opacity: 0.5;
  cursor: default;
}

kbd {
  display: inline-block;
  padding: 2px 6px;
  font-family: var(--font-sans);
  font-size: 12px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 4px;
}

/* --- Plyr overrides --- */
.plyr.plyr--audio .plyr__controls {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  color: var(--color-text);
}

.plyr.plyr--audio .plyr__control,
.plyr.plyr--audio .plyr__time {
  color: var(--color-text);
}

[data-theme="dark"] .plyr--audio .plyr__control.plyr__tab-focus,
[data-theme="dark"] .plyr--audio .plyr__control:hover,
[data-theme="dark"] .plyr--audio .plyr__control[aria-expanded=true] {
  background: var(--color-accent);
  color: #fff;
}
