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

:root {
  --bg: #0a0a12;
  --bg-card: #12121e;
  --bg-hover: #1a1a2e;
  --bg-input: #16162a;
  --text: #e8e8f0;
  --text-muted: #7a7a9a;
  --accent: #f0a030;
  --accent-glow: rgba(240, 160, 48, 0.15);
  --green: #30d060;
  --red: #f04040;
  --blue: #4090f0;
  --radius: 12px;
  --radius-sm: 8px;
}

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  line-height: 1.5;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* === Layout === */
#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 16px 32px;
}

/* === Header === */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 100;
}
.header-left { display: flex; align-items: center; gap: 8px; }
.logo { font-size: 1.25rem; font-weight: 700; }
.icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
}
.icon-btn:hover { color: var(--text); background: var(--bg-hover); }

/* === Views === */
.view { display: none; }
.view.active { display: block; }
.hidden { display: none !important; }

/* === Library === */
.library-header { margin-bottom: 20px; }
.library-header h2 { font-size: 1.5rem; margin-bottom: 12px; }
.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; }
.filter-btn {
  background: var(--bg-card);
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
}
.filter-btn:hover { color: var(--text); }
.filter-btn.active {
  background: var(--accent-glow);
  border-color: var(--accent);
  color: var(--accent);
}

.exercise-list { display: flex; flex-direction: column; gap: 8px; }
.exercise-card {
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.04);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: all 0.15s;
}
.exercise-card:hover { background: var(--bg-hover); border-color: rgba(255,255,255,0.08); }
.exercise-card-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.exercise-name { font-weight: 600; font-size: 1rem; }
.exercise-level {
  font-size: 0.75rem;
  padding: 2px 10px;
  border-radius: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.level-beginner { background: rgba(48,208,96,0.12); color: var(--green); }
.level-intermediate { background: rgba(64,144,240,0.12); color: var(--blue); }
.level-advanced { background: rgba(240,64,64,0.12); color: var(--red); }
.exercise-desc { font-size: 0.85rem; color: var(--text-muted); }
.exercise-meta { display: flex; gap: 16px; margin-top: 8px; font-size: 0.8rem; color: var(--text-muted); }
.exercise-best { color: var(--green); font-weight: 500; }

/* === Setup === */
.setup-card { padding: 24px 0; }
.setup-card h2 { font-size: 1.5rem; margin-bottom: 8px; }
.text-muted { color: var(--text-muted); margin-bottom: 20px; }
.setup-notes {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 24px;
  padding: 16px;
  background: var(--bg-card);
  border-radius: var(--radius);
}
.setup-note {
  background: var(--bg-hover);
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.95rem;
  font-family: 'SF Mono', 'Fira Code', monospace;
}
.setup-controls { margin-bottom: 24px; }
.control-group label { display: block; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 8px; }
.bpm-control {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.bpm-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.1);
  background: var(--bg-card);
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.bpm-btn:hover { background: var(--bg-hover); border-color: var(--accent); }
#bpm-value { font-size: 1.5rem; font-weight: 700; min-width: 48px; text-align: center; }
.bpm-label { color: var(--text-muted); font-size: 0.85rem; }
#bpm-slider {
  width: 100%;
  -webkit-appearance: none;
  background: var(--bg-hover);
  height: 4px;
  border-radius: 2px;
  outline: none;
}
#bpm-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

.btn-primary, .btn-secondary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
}
.btn-primary {
  background: var(--accent);
  color: #000;
}
.btn-primary:hover { filter: brightness(1.1); }
.btn-secondary {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.08);
}
.btn-secondary:hover { background: var(--bg-hover); }
.btn-large { padding: 16px; font-size: 1.1rem; }
.mic-hint { text-align: center; font-size: 0.8rem; color: var(--text-muted); margin-top: 12px; }

/* === Play View === */
.play-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
}
.play-title { font-weight: 600; }
.play-bpm { color: var(--text-muted); font-size: 0.85rem; margin-left: 8px; }
.play-progress { color: var(--text-muted); font-size: 0.9rem; font-family: monospace; }

.note-track {
  position: relative;
  height: 120px;
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 24px;
  border: 1px solid rgba(255,255,255,0.04);
}
.playhead {
  position: absolute;
  left: 15%;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--accent);
  z-index: 10;
  box-shadow: 0 0 12px var(--accent), 0 0 4px var(--accent);
}
.notes-container {
  position: absolute;
  top: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  transition: transform 0.05s linear;
  will-change: transform;
}
.note-block {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 80px;
  height: 64px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 1.3rem;
  font-family: 'SF Mono', 'Fira Code', monospace;
  flex-shrink: 0;
  margin: 0 6px;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
  border: 2px solid rgba(255,255,255,0.08);
  background: var(--bg-hover);
}
.note-block.active {
  border-color: var(--accent);
  background: var(--accent-glow);
  transform: scale(1.08);
}
.note-block.correct {
  border-color: var(--green);
  background: rgba(48,208,96,0.15);
  color: var(--green);
}
.note-block.wrong {
  border-color: var(--red);
  background: rgba(240,64,64,0.15);
  color: var(--red);
}
.note-block.passed {
  opacity: 0.4;
}

/* === Pitch Display === */
.pitch-display {
  text-align: center;
  padding: 16px;
  background: var(--bg-card);
  border-radius: var(--radius);
  margin-bottom: 16px;
}
.detected-note {
  font-size: 2.5rem;
  font-weight: 700;
  font-family: 'SF Mono', 'Fira Code', monospace;
  line-height: 1.2;
}
.detected-freq { color: var(--text-muted); font-size: 0.85rem; margin-top: 2px; }
.cents-meter {
  position: relative;
  height: 6px;
  background: var(--bg-hover);
  border-radius: 3px;
  margin-top: 12px;
  overflow: hidden;
}
.cents-meter::before {
  content: '';
  position: absolute;
  left: 50%;
  top: -2px;
  width: 2px;
  height: 10px;
  background: var(--text-muted);
  transform: translateX(-50%);
  z-index: 1;
}
.cents-indicator {
  position: absolute;
  top: 0;
  width: 12px;
  height: 6px;
  background: var(--accent);
  border-radius: 3px;
  left: 50%;
  transform: translateX(-50%);
  transition: left 0.08s;
}

/* === Results === */
.results-card { padding: 24px 0; text-align: center; }
.results-card h2 { font-size: 1.5rem; margin-bottom: 24px; }
.score-circle {
  position: relative;
  width: 140px;
  height: 140px;
  margin: 0 auto 24px;
}
.score-circle svg { width: 100%; height: 100%; }
.score-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
#score-percent { font-size: 2.5rem; font-weight: 700; }
.score-unit { font-size: 1.2rem; color: var(--text-muted); }
.results-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}
.stat-item {
  background: var(--bg-card);
  padding: 12px;
  border-radius: var(--radius-sm);
}
.stat-value { font-size: 1.3rem; font-weight: 700; }
.stat-label { font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; }
.stat-value.green { color: var(--green); }
.stat-value.red { color: var(--red); }

.results-notes {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-bottom: 24px;
}
.result-note {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.85rem;
  font-family: 'SF Mono', 'Fira Code', monospace;
}
.result-note.correct { background: rgba(48,208,96,0.15); color: var(--green); border: 1px solid rgba(48,208,96,0.3); }
.result-note.wrong { background: rgba(240,64,64,0.15); color: var(--red); border: 1px solid rgba(240,64,64,0.3); }

.results-actions { display: flex; gap: 12px; }
.results-actions .btn-primary,
.results-actions .btn-secondary { flex: 1; }

/* === History === */
.history-header { margin-bottom: 20px; }
.history-header h2 { font-size: 1.5rem; }
.history-chart {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 20px;
  min-height: 200px;
}
.history-chart canvas { width: 100%; height: 180px; }
.history-list { display: flex; flex-direction: column; gap: 8px; }
.history-item {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.history-item-left { display: flex; flex-direction: column; }
.history-item-name { font-weight: 600; font-size: 0.95rem; }
.history-item-date { font-size: 0.8rem; color: var(--text-muted); }
.history-item-score { font-weight: 700; font-size: 1.1rem; }
.history-item-score.good { color: var(--green); }
.history-item-score.ok { color: var(--accent); }
.history-item-score.bad { color: var(--red); }
.history-empty { text-align: center; padding: 60px 20px; color: var(--text-muted); }

/* === Countdown overlay === */
.countdown-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10,10,18,0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.countdown-number {
  font-size: 6rem;
  font-weight: 700;
  color: var(--accent);
  animation: countPulse 0.6s ease-out;
}
@keyframes countPulse {
  0% { transform: scale(1.5); opacity: 0; }
  50% { opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* === Responsive === */
@media (max-width: 400px) {
  .note-block { width: 64px; height: 52px; font-size: 1.1rem; }
  .results-stats { grid-template-columns: repeat(2, 1fr); }
}
