/* ==========================================================================
   FluteFlow — Playful, Mobile-First AMRO Flute Practice Companion
   ========================================================================== */

:root {
  --bg-canvas: #FAF7F2;
  --bg-surface: #FFFFFF;
  --bg-surface-elevated: #FFFFFF;
  --bg-surface-trans: rgba(255, 255, 255, 0.85);
  --bg-muted: #F3EFE7;
  --bg-dark: #0F172A;
  --border-color: #E5DFD5;
  --border-focus: #0D9488;
  --border-dark: #1E293B;

  --primary: #0D9488;
  --primary-hover: #0F766E;
  --primary-active: #115E59;
  --primary-light: #F0FDFA;
  --primary-ring: rgba(13, 148, 136, 0.25);

  --accent-amber: #D97706;
  --accent-amber-light: #FEF3C7;
  --accent-coral: #EA580C;
  --accent-coral-light: #FFEDD5;
  --accent-emerald: #059669;
  --accent-emerald-light: #ECFDF5;

  --danger: #DC2626;
  --danger-light: #FEF2F2;

  --text-main: #0F172A;
  --text-secondary: #475569;
  --text-muted: #64748B;
  --text-light: #94A3B8;
  --text-white: #FFFFFF;

  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 2px 4px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 10px -1px rgba(15, 23, 42, 0.07), 0 2px 4px -2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 12px 20px -3px rgba(15, 23, 42, 0.09), 0 4px 8px -4px rgba(15, 23, 42, 0.04);
  --shadow-xl: 0 20px 28px -5px rgba(15, 23, 42, 0.12), 0 8px 12px -6px rgba(15, 23, 42, 0.05);

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  --transition-bounce: 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Base Reset & Typography */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  min-height: 100%;
  font-family: var(--font-sans);
  background-color: var(--bg-canvas);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  font-size: 1rem;
}

input, select, textarea {
  font-family: inherit;
  font-size: 1rem;
}

/* App Container */
.app-container {
  max-width: 960px;
  margin: 0 auto;
  padding: 0.75rem 1rem 3rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Top Navigation Bar */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 1rem;
  background: var(--bg-surface-trans);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0.5rem;
  z-index: 40;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  user-select: none;
}

.brand-icon {
  font-size: 1.6rem;
  line-height: 1;
  display: inline-block;
  transform: rotate(-10deg);
  transition: transform var(--transition-bounce);
}

.brand:hover .brand-icon {
  transform: rotate(10deg) scale(1.15);
}

.brand-title {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.02em;
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
}

.brand-badge {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-light);
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border: 1px solid rgba(13, 148, 136, 0.2);
}

.top-bar-stats {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.stat-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.35rem 0.65rem;
  background: var(--bg-muted);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-main);
  box-shadow: var(--shadow-xs);
  transition: transform var(--transition-bounce);
}

.stat-pill.streak {
  background: var(--accent-coral-light);
  border-color: rgba(234, 88, 12, 0.25);
  color: var(--accent-coral);
}

.stat-pill.score {
  background: var(--accent-amber-light);
  border-color: rgba(217, 119, 6, 0.25);
  color: var(--accent-amber);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.btn-icon {
  width: 2.35rem;
  height: 2.35rem;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-muted);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  font-size: 1.05rem;
  transition: all var(--transition-fast);
}

.btn-icon:hover {
  background: var(--bg-surface);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.btn-icon:active {
  transform: translateY(1px);
}

.btn-pill-chart {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.38rem 0.75rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-main);
  box-shadow: var(--shadow-xs);
  transition: all var(--transition-fast);
}

.btn-pill-chart:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
  transform: translateY(-1px);
}

/* Mode Switcher Tabs */
.mode-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.4rem;
  background: var(--bg-muted);
  padding: 0.35rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.mode-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.55rem 0.25rem;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--text-muted);
  transition: all var(--transition-fast);
  text-align: center;
  user-select: none;
}

.mode-tab .tab-icon {
  font-size: 1.15rem;
  margin-bottom: 0.15rem;
}

.mode-tab:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.6);
}

.mode-tab.active {
  background: var(--bg-surface);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

/* Level Preset Selector */
.level-selector-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  overflow-x: auto;
  padding: 0.2rem 0;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.level-selector-wrap::-webkit-scrollbar {
  display: none;
}

.level-label {
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  flex-shrink: 0;
}

.level-pills {
  display: flex;
  gap: 0.35rem;
  flex-wrap: nowrap;
}

.level-pill {
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-xs);
}

.level-pill:hover {
  border-color: var(--primary);
  color: var(--primary);
  transform: translateY(-1px);
}

.level-pill.active {
  background: var(--primary);
  color: var(--text-white);
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(13, 148, 136, 0.35);
}

/* Practice Card Container */
.practice-card {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  position: relative;
  overflow: hidden;
  transition: transform var(--transition-normal);
}

/* Question Header Bar */
.question-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  border-bottom: 1px solid var(--bg-muted);
  padding-bottom: 0.75rem;
}

.question-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.badge-step {
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-full);
  background: var(--primary-light);
  color: var(--primary);
  border: 1px solid rgba(13, 148, 136, 0.2);
}

.badge-register {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-full);
  background: var(--bg-muted);
  color: var(--text-muted);
}

.question-controls {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.38rem 0.75rem;
  background: var(--bg-muted);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}

.btn-secondary:hover {
  background: var(--bg-surface);
  color: var(--text-main);
  border-color: var(--primary);
  transform: translateY(-1px);
}

.btn-secondary.active {
  background: var(--accent-amber-light);
  color: var(--accent-amber);
  border-color: rgba(217, 119, 6, 0.3);
}

/* Staff Presentation Stage */
.staff-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #FFFFFF 0%, #FAF8F5 100%);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem 1rem;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.02);
  position: relative;
  min-height: 140px;
}

.staff-svg-wrapper {
  width: 100%;
  max-width: 380px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.staff-svg-wrapper svg {
  width: 100%;
  height: auto;
  max-height: 155px;
  overflow: visible;
}

/* Hint Box Callout */
.hint-box {
  width: 100%;
  background: var(--accent-amber-light);
  border: 1px solid rgba(217, 119, 6, 0.3);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: #78350F;
  animation: fadeIn 0.25s ease-out;
}

.hint-title {
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.hint-body {
  font-size: 0.82rem;
  line-height: 1.4;
}

/* Prompt instructions */
.prompt-instruction {
  text-align: center;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
  margin-top: -0.25rem;
}

.prompt-instruction small {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

/* Step 1: Note Name Buttons Grid */
.note-buttons-grid {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.note-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.4rem;
}

.note-row.accidentals {
  grid-template-columns: repeat(5, 1fr);
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

.btn-note {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 0.25rem;
  border-radius: var(--radius-md);
  background: var(--bg-muted);
  border: 2px solid var(--border-color);
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text-main);
  box-shadow: var(--shadow-xs);
  transition: all var(--transition-fast);
  user-select: none;
}

.btn-note:hover:not(:disabled) {
  background: var(--bg-surface);
  border-color: var(--primary);
  color: var(--primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.btn-note:active:not(:disabled) {
  transform: translateY(1px);
}

.btn-note.accidental {
  background: #334155;
  color: #F8FAFC;
  border-color: #1E293B;
  font-size: 0.95rem;
}

.btn-note.accidental:hover:not(:disabled) {
  background: #1E293B;
  border-color: var(--primary);
  color: #FFFFFF;
}

.btn-note.correct {
  background: var(--accent-emerald) !important;
  border-color: var(--accent-emerald) !important;
  color: var(--text-white) !important;
  animation: pulseGreen 0.4s ease;
}

.btn-note.wrong {
  background: var(--danger-light) !important;
  border-color: var(--danger) !important;
  color: var(--danger) !important;
  animation: shake 0.4s ease;
}

/* Step 2: Fingering Choice Cards Grid */
.fingering-options-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.85rem;
}

@media (max-width: 600px) {
  .fingering-options-grid {
    grid-template-columns: 1fr;
  }
}

.fingering-option-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--bg-surface);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem 0.5rem;
  box-shadow: var(--shadow-xs);
  cursor: pointer;
  position: relative;
  transition: all var(--transition-fast);
  user-select: none;
}

.fingering-option-card:hover:not(.disabled) {
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.fingering-option-card:active:not(.disabled) {
  transform: translateY(0);
}

.option-badge {
  position: absolute;
  top: 0.45rem;
  left: 0.55rem;
  width: 1.4rem;
  height: 1.4rem;
  border-radius: var(--radius-full);
  background: var(--bg-muted);
  border: 1px solid var(--border-color);
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.fingering-option-svg {
  width: 100%;
  max-width: 280px;
  margin-top: 0.4rem;
  padding-left: 1.5rem;
  display: flex;
  justify-content: center;
  align-items: center;
}

.fingering-option-svg svg {
  width: 100%;
  height: auto;
  max-height: 72px;
}

.fingering-option-card.correct {
  border-color: var(--accent-emerald) !important;
  background: var(--accent-emerald-light) !important;
  box-shadow: 0 4px 14px rgba(5, 150, 105, 0.25) !important;
  animation: pulseGreen 0.4s ease;
}

.fingering-option-card.correct .option-badge {
  background: var(--accent-emerald);
  color: white;
  border-color: var(--accent-emerald);
}

.fingering-option-card.wrong {
  border-color: var(--danger) !important;
  background: var(--danger-light) !important;
  opacity: 0.7;
  animation: shake 0.4s ease;
}

.fingering-option-card.wrong .option-badge {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}

.wrong-explanation {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--danger);
  margin-top: 0.35rem;
  text-align: center;
}

/* Step 3: Complete Breakdown Card ("See What's Right") */
.breakdown-card {
  background: linear-gradient(180deg, #F0FDFA 0%, #FFFFFF 100%);
  border: 2px solid var(--primary);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: var(--shadow-lg);
  animation: popIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.breakdown-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.breakdown-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--primary-active);
}

.breakdown-title .note-badge {
  background: var(--primary);
  color: white;
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-sm);
  font-size: 1.1rem;
}

.breakdown-grid {
  display: grid;
  grid-template-columns: 1fr 1.3fr;
  gap: 1rem;
  align-items: center;
}

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

.breakdown-staff-pane {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: white;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem;
}

.breakdown-fingering-pane {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  background: white;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem;
}

.breakdown-fingering-pane svg {
  width: 100%;
  max-width: 320px;
  height: auto;
}

.alt-fingering-section {
  width: 100%;
  border-top: 1px dashed var(--border-color);
  padding-top: 0.6rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.alt-fingering-title {
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--accent-amber);
  text-transform: uppercase;
  margin-bottom: 0.25rem;
}

.breakdown-details {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.6rem;
}

.detail-item {
  background: var(--bg-muted);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  font-size: 0.82rem;
}

.detail-label {
  font-weight: 700;
  color: var(--text-muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.15rem;
}

.detail-value {
  color: var(--text-main);
  font-weight: 600;
}

.breakdown-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 0.5rem;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.65rem 1.4rem;
  background: var(--primary);
  color: var(--text-white);
  border-radius: var(--radius-full);
  font-weight: 800;
  font-size: 0.95rem;
  box-shadow: 0 4px 12px rgba(13, 148, 136, 0.35);
  transition: all var(--transition-fast);
}

.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(13, 148, 136, 0.45);
}

.btn-primary:active {
  transform: translateY(1px);
}

/* Ear Quiz Mystery Mode */
.ear-mystery-box {
  width: 100%;
  min-height: 140px;
  background: linear-gradient(135deg, #1E293B 0%, #0F172A 100%);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  color: #F8FAFC;
  padding: 1.5rem;
  cursor: pointer;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
  transition: transform var(--transition-fast);
}

.ear-mystery-box:hover {
  transform: scale(1.01);
}

.ear-wave-icon {
  font-size: 2.2rem;
  animation: pulseSlow 1.5s infinite;
}

/* Interactive Reference Explorer */
.explorer-controls {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.explorer-filter-bar {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  align-items: center;
}

.search-input {
  flex: 1;
  min-width: 180px;
  padding: 0.45rem 0.85rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  background: var(--bg-surface);
  color: var(--text-main);
  outline: none;
  transition: border-color var(--transition-fast);
}

.search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.85rem;
}

.chart-note-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  box-shadow: var(--shadow-xs);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.chart-note-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

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

.chart-card-title {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text-main);
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
}

.chart-card-octave {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
}

.chart-card-body {
  display: grid;
  grid-template-columns: 85px 1fr;
  gap: 0.5rem;
  align-items: center;
}

.chart-card-staff svg {
  width: 100%;
  height: auto;
  max-height: 60px;
}

.chart-card-fingering {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
}

.chart-card-fingering svg {
  width: 100%;
  height: auto;
  max-height: 52px;
}

.chart-card-alt {
  font-size: 0.68rem;
  font-weight: 800;
  color: var(--accent-amber);
  text-transform: uppercase;
}

/* Interactive Virtual Flute Key Finder */
.virtual-flute-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: var(--shadow-sm);
}

.virtual-flute-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.virtual-flute-match {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--primary-light);
  border: 1px solid rgba(13, 148, 136, 0.3);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
}

.match-note-name {
  font-size: 1.4rem;
  font-weight: 900;
  color: var(--primary-active);
}

.match-details {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.virtual-flute-svg-wrap {
  width: 100%;
  background: #FAF8F5;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 0.75rem;
  overflow-x: hidden;
}

.virtual-flute-svg-wrap svg {
  width: 100%;
  max-width: 650px;
  height: auto;
}

/* Modal System */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal);
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-xl);
  max-width: 820px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(0.95) translateY(10px);
  transition: transform var(--transition-bounce);
}

.modal-overlay.open .modal-content {
  transform: scale(1) translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-surface);
}

.modal-title {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-close {
  width: 2rem;
  height: 2rem;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  color: var(--text-muted);
  transition: all var(--transition-fast);
}

.btn-close:hover {
  background: var(--bg-muted);
  color: var(--text-main);
}

.modal-body {
  padding: 1.25rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.original-chart-img {
  width: 100%;
  height: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  background: white;
}

/* Key Legend Table */
.legend-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.legend-table th, .legend-table td {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border-color);
  text-align: left;
}

.legend-table th {
  background: var(--bg-muted);
  font-weight: 700;
  color: var(--text-secondary);
}

/* Celebration Confetti */
.celebrate-burst {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 20;
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.92); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes pulseGreen {
  0% { transform: scale(1); }
  50% { transform: scale(1.04); }
  100% { transform: scale(1); }
}

@keyframes pulseSlow {
  0%, 100% { transform: scale(1); opacity: 0.9; }
  50% { transform: scale(1.1); opacity: 1; }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

/* Responsive tweaks */
@media (max-width: 640px) {
  .app-container {
    padding: 0.5rem 0.5rem 2.5rem 0.5rem;
    gap: 0.75rem;
  }
  .brand-title span:last-child {
    display: none;
  }
  .brand-title {
    font-size: 1.1rem;
  }
  .brand-icon {
    font-size: 1.35rem;
  }
  .top-bar {
    padding: 0.45rem 0.6rem;
    gap: 0.35rem;
    flex-wrap: wrap;
  }
  .stat-pill {
    padding: 0.25rem 0.5rem;
    font-size: 0.78rem;
  }
  .btn-icon {
    width: 2.1rem;
    height: 2.1rem;
    font-size: 0.95rem;
  }
  .btn-pill-chart {
    padding: 0.3rem 0.55rem;
    font-size: 0.75rem;
  }
  .mode-tab {
    font-size: 0.7rem;
    padding: 0.4rem 0.1rem;
    line-height: 1.15;
  }
  .mode-tab .tab-icon {
    font-size: 1.05rem;
  }
  .practice-card, .virtual-flute-card {
    padding: 0.85rem;
    gap: 0.9rem;
  }
  .question-header {
    flex-wrap: wrap;
    gap: 0.45rem;
  }
  .question-controls {
    margin-left: auto;
  }
  .btn-secondary {
    padding: 0.32rem 0.6rem;
    font-size: 0.76rem;
  }
  .note-row {
    gap: 0.25rem;
  }
  .btn-note {
    padding: 0.65rem 0.15rem;
    font-size: 1rem;
  }
  /* Stack 5 accidental pills into a roomy 3-column grid on mobile */
  .note-row.accidentals {
    grid-template-columns: repeat(3, 1fr);
    gap: 0.35rem;
  }
  .btn-note.accidental {
    font-size: 0.85rem;
    padding: 0.55rem 0.25rem;
  }
  .fingering-option-svg {
    padding-left: 1.6rem;
  }
  .breakdown-card {
    padding: 0.9rem;
  }
  .breakdown-title {
    font-size: 1.05rem;
    flex-wrap: wrap;
  }
  .breakdown-actions {
    flex-direction: column-reverse;
    width: 100%;
  }
  .breakdown-actions button {
    width: 100%;
    justify-content: center;
  }
  .virtual-flute-match {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }
  .virtual-flute-match button {
    margin-left: 0 !important;
    width: 100%;
  }
  .match-note-name {
    font-size: 1.15rem;
  }
  .chart-grid {
    grid-template-columns: 1fr;
  }
  .modal-overlay {
    padding: 0.5rem;
  }
  .modal-header {
    padding: 0.75rem 1rem;
  }
  .modal-body {
    padding: 0.85rem;
  }
  .legend-table {
    display: block;
    overflow-x: auto;
    font-size: 0.78rem;
  }
}

@media (max-width: 380px) {
  .btn-pill-chart span:last-child {
    display: none;
  }
  .btn-pill-chart {
    padding: 0.35rem 0.5rem;
  }
}
