/* ==========================================
   VocalStar - Singing Feedback App
   Dark karaoke theme with neon accents
   ========================================== */

:root {
  --bg-dark: #06060f;
  --bg-card: #0d0d1f;
  --bg-card-hover: #12122a;
  --bg-surface: #1a1a3e;
  --cyan: #00d4ff;
  --purple: #7b2fff;
  --pink: #ff2fa8;
  --green: #00ff88;
  --yellow: #ffd700;
  --red: #ff4444;
  --orange: #ff8844;
  --text: #e8e8f0;
  --text-dim: #8888aa;
  --text-muted: #555577;
  --radius: 12px;
  --radius-lg: 20px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-display: 'Space Grotesk', var(--font);
  --glow-cyan: 0 0 20px rgba(0, 212, 255, 0.3), 0 0 60px rgba(0, 212, 255, 0.1);
  --glow-purple: 0 0 20px rgba(123, 47, 255, 0.3), 0 0 60px rgba(123, 47, 255, 0.1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  background: var(--bg-dark);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
}

/* ==========================================
   SCREENS
   ========================================== */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  /* Opacity + transform animate for 0.4s; visibility flips at the end so the
     inactive screen is fully removed from the paint tree and cannot bleed
     through the active one. */
  transition: opacity 0.4s ease, transform 0.4s ease, visibility 0s linear 0.4s;
  transform: translateY(10px);
  background: var(--bg-dark);
  /* Safe areas for notched / Dynamic Island devices */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.screen.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0);
  z-index: 10;
  /* On activation, visibility flips to visible instantly (no delay). */
  transition: opacity 0.4s ease, transform 0.4s ease, visibility 0s linear 0s;
}

/* ==========================================
   BUTTONS
   ========================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 32px;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s ease;
  text-transform: none;
  letter-spacing: 0.01em;
}

.btn-primary {
  background: linear-gradient(135deg, var(--cyan), var(--purple));
  color: #fff;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: var(--glow-cyan);
}

.btn-glow {
  box-shadow: var(--glow-cyan);
}

.btn-secondary {
  background: var(--bg-surface);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.08);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: var(--cyan);
  transform: translateY(-2px);
}

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid rgba(255,255,255,0.06);
}

.btn-ghost:hover {
  color: var(--text);
  border-color: rgba(255,255,255,0.15);
}

.btn-icon {
  font-size: 20px;
}

.btn-back {
  background: none;
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--text);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.btn-back:hover {
  background: var(--bg-surface);
  border-color: var(--cyan);
}

/* ==========================================
   HOME SCREEN
   ========================================== */
.home-bg {
  position: absolute;
  inset: 0;
  overflow: hidden;
  z-index: 0;
}

.bg-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.3;
  animation: float 20s ease-in-out infinite;
}

.orb-1 {
  width: 400px; height: 400px;
  background: var(--cyan);
  top: -100px; right: -100px;
  animation-delay: 0s;
}

.orb-2 {
  width: 350px; height: 350px;
  background: var(--purple);
  bottom: -80px; left: -80px;
  animation-delay: -7s;
}

.orb-3 {
  width: 250px; height: 250px;
  background: var(--pink);
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  animation-delay: -13s;
  opacity: 0.15;
}

@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  25% { transform: translate(30px, -20px) scale(1.05); }
  50% { transform: translate(-20px, 30px) scale(0.95); }
  75% { transform: translate(20px, 20px) scale(1.02); }
}

.home-content {
  position: relative;
  z-index: 1;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  gap: 40px;
}

.logo-section {
  text-align: center;
}

.logo-icon {
  width: 80px;
  height: 80px;
  margin: 0 auto 16px;
}

.logo-icon svg {
  width: 100%;
  height: 100%;
}

.logo-text {
  font-family: var(--font-display);
  font-size: 48px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.logo-text .accent {
  background: linear-gradient(135deg, var(--cyan), var(--purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.tagline {
  color: var(--text-dim);
  font-size: 18px;
  margin-top: 8px;
  font-weight: 300;
  letter-spacing: 0.1em;
}

.home-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 320px;
}

.home-actions .btn {
  width: 100%;
}

.home-stats {
  display: flex;
  gap: 24px;
}

.stat-card {
  text-align: center;
  padding: 16px 24px;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius);
  min-width: 90px;
}

.stat-value {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 700;
  color: var(--cyan);
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.home-methodology {
  margin-top: 32px;
  max-width: 400px;
  padding: 0 20px;
}

.home-methodology .methodology-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.home-methodology p {
  font-size: 11px;
  line-height: 1.6;
  color: var(--text-muted);
}

.home-footer {
  margin-top: 24px;
  padding: 16px 0 32px;
}

.home-footer a {
  font-size: 12px;
  color: var(--text-muted);
  text-decoration: none;
  opacity: 0.6;
  transition: opacity 0.2s;
}

.home-footer a:hover {
  opacity: 1;
  color: var(--accent);
}

/* ==========================================
   SCREEN HEADER
   ========================================== */
.screen-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}

.screen-header h2 {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
}

.header-spacer { width: 40px; }

/* ==========================================
   SONG SELECT
   ========================================== */
.song-filters {
  display: flex;
  gap: 8px;
  padding: 16px 20px 8px;
  flex-shrink: 0;
}

.filter-btn {
  padding: 8px 20px;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 99px;
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.filter-btn.active {
  background: linear-gradient(135deg, var(--cyan), var(--purple));
  color: #fff;
  border-color: transparent;
}

.filter-btn:hover:not(.active) {
  border-color: var(--cyan);
  color: var(--text);
}

.song-grid {
  flex: 1;
  overflow-y: auto;
  /* Center the grid and cap its width so cards don't stretch into a
     giant dead-zone on desktop. 1100px comfortably fits 3 columns. */
  padding: 12px 24px 40px;
  max-width: 1140px;
  width: 100%;
  margin: 0 auto;
  /* auto-fill + minmax gives us a responsive multi-column grid: 1 col
     on mobile, 2 on tablet, 3 on desktop, without media queries. */
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
  align-content: start;
}

.song-card {
  display: flex;
  flex-direction: column;
  gap: 0;
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.04);
  border-radius: var(--radius);
  transition: background 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease, transform 0.25s ease;
  overflow: hidden;
}

.song-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--cyan);
  /* Lift instead of slide — translateX made cards visually "jump sideways"
     in the new grid layout. A small upward lift reads cleaner. */
  transform: translateY(-2px);
  box-shadow: var(--glow-cyan);
}

.song-card-main {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  cursor: pointer;
}

.song-options {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px 14px;
  border-top: 1px solid rgba(255,255,255,0.04);
  flex-wrap: wrap;
}

.karaoke-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px 7px 10px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
  background: rgba(0, 212, 255, 0.08);
  color: var(--cyan);
  border: 1px solid rgba(0, 212, 255, 0.25);
  letter-spacing: 0.02em;
}

.karaoke-toggle:hover {
  background: rgba(0, 212, 255, 0.16);
  border-color: var(--cyan);
  box-shadow: 0 0 16px rgba(0, 212, 255, 0.2);
}

.karaoke-toggle .karaoke-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
}

.karaoke-toggle .karaoke-icon svg {
  width: 16px;
  height: 16px;
}

.karaoke-toggle .karaoke-state {
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 99px;
  background: rgba(0, 212, 255, 0.18);
  letter-spacing: 0.08em;
}

.karaoke-toggle.is-off {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-dim);
  border-color: rgba(255, 255, 255, 0.08);
}

.karaoke-toggle.is-off:hover {
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.18);
  box-shadow: none;
}

.karaoke-toggle.is-off .karaoke-state {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
}

.karaoke-hint {
  font-size: 11px;
  color: var(--text-dim);
  flex: 1 1 100%;
  min-width: 0;
  line-height: 1.4;
}

.song-art {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--cyan);
  background:
    radial-gradient(circle at 30% 20%, color-mix(in srgb, var(--song-color, var(--cyan)) 28%, transparent), transparent 70%),
    linear-gradient(135deg, color-mix(in srgb, var(--song-color, var(--cyan)) 18%, #0b1028) 0%, #0b1028 100%);
  border: 1px solid color-mix(in srgb, var(--song-color, var(--cyan)) 30%, rgba(255,255,255,0.04));
  box-shadow: 0 0 0 1px rgba(255,255,255,0.02) inset;
}

.song-art svg {
  width: 26px;
  height: 26px;
  color: color-mix(in srgb, var(--song-color, var(--cyan)) 85%, #ffffff);
  filter: drop-shadow(0 0 6px color-mix(in srgb, var(--song-color, var(--cyan)) 60%, transparent));
}

.song-info {
  flex: 1;
  min-width: 0;
}

.song-title {
  font-weight: 600;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.song-artist {
  color: var(--text-dim);
  font-size: 13px;
  margin-top: 2px;
}

.song-meta {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

.song-tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 99px;
  font-weight: 500;
}

.tag-easy { background: rgba(0,255,136,0.15); color: var(--green); }
.tag-medium { background: rgba(255,215,0,0.15); color: var(--yellow); }
.tag-hard { background: rgba(255,68,68,0.15); color: var(--red); }

.song-tag-key {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 99px;
  background: rgba(255,255,255,0.06);
  color: var(--text-dim);
}

.song-best {
  text-align: right;
  flex-shrink: 0;
}

.song-best-score {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  color: var(--cyan);
}

.song-best-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.song-play-hint {
  color: var(--text-muted);
  font-size: 22px;
}

/* ==========================================
   WARM-UP
   ========================================== */
.warmup-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 30px 20px;
  gap: 24px;
}

.pitch-meter-container {
  width: 100%;
  max-width: 600px;
  position: relative;
}

#warmup-canvas {
  width: 100%;
  height: auto;
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.06);
}

.current-note-display {
  text-align: center;
  margin-top: 16px;
}

.note-name {
  font-family: var(--font-display);
  font-size: 48px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--cyan), var(--purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.note-freq {
  color: var(--text-dim);
  font-size: 14px;
}

.note-cents {
  font-size: 14px;
  font-weight: 600;
  margin-top: 4px;
  min-height: 20px;
}

.cents-sharp { color: var(--orange); }
.cents-flat { color: var(--yellow); }
.cents-perfect { color: var(--green); }

.warmup-info {
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.6;
}

.warmup-hint {
  margin-top: 4px;
  color: var(--text-muted);
}

.guide-tones {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.tone-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 2px solid var(--bg-surface);
  background: var(--bg-card);
  color: var(--text);
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.tone-btn:hover {
  border-color: var(--cyan);
  box-shadow: var(--glow-cyan);
  transform: scale(1.1);
}

.tone-btn:active {
  transform: scale(0.95);
}

/* ==========================================
   COUNTDOWN
   ========================================== */
.countdown-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.countdown-song-title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  color: var(--text-dim);
}

.countdown-number {
  font-family: var(--font-display);
  font-size: 160px;
  font-weight: 900;
  background: linear-gradient(135deg, var(--cyan), var(--purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1;
  animation: countPulse 1s ease-in-out infinite;
}

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

.countdown-subtitle {
  font-size: 18px;
  color: var(--text-dim);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.mic-status {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--green);
  font-size: 14px;
  margin-top: 20px;
}

.mic-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(0,255,136,0.4); }
  50% { opacity: 0.7; box-shadow: 0 0 0 8px rgba(0,255,136,0); }
}

/* ==========================================
   GAME SCREEN
   ========================================== */
.game-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: rgba(6,6,15,0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  z-index: 10;
  flex-shrink: 0;
}

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

.btn-back-game {
  font-size: 24px;
  width: 36px;
  height: 36px;
}

.hud-title {
  font-weight: 600;
  font-size: 14px;
}

.hud-artist {
  font-size: 12px;
  color: var(--text-muted);
}

.hud-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.hud-time {
  font-family: var(--font-display);
  font-size: 16px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.hud-score-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.hud-score {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--cyan), var(--purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-variant-numeric: tabular-nums;
}

.streak-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 99px;
  background: rgba(255,215,0,0.1);
  color: var(--yellow);
  font-size: 14px;
  font-weight: 700;
  opacity: 0;
  transform: scale(0.8);
  transition: all 0.3s ease;
}

.streak-indicator.active {
  opacity: 1;
  transform: scale(1);
}

.streak-fire {
  font-size: 16px;
}

#game-canvas {
  flex: 1;
  width: 100%;
  display: block;
  background: var(--bg-dark);
}

.lyrics-bar {
  padding: 20px 20px;
  text-align: center;
  background: rgba(6,6,15,0.95);
  backdrop-filter: blur(10px);
  border-top: 1px solid rgba(255,255,255,0.06);
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.lyrics-text {
  font-size: 20px;
  font-weight: 500;
  letter-spacing: 0.02em;
  line-height: 1.4;
}

.lyrics-text .lyric-active {
  color: var(--cyan);
  text-shadow: 0 0 20px rgba(0,212,255,0.5);
}

.lyrics-text .lyric-past {
  color: var(--text-muted);
}

.lyrics-text .lyric-future {
  color: var(--text-dim);
}

/* Karaoke-style lyrics for lyricsMode songs */
.karaoke-current {
  font-size: 26px;
  font-weight: 700;
  font-family: var(--font-display);
  color: #fff;
  text-shadow: 0 0 20px rgba(0,212,255,0.5);
  letter-spacing: 0.08em;
  line-height: 1.2;
}

.karaoke-next {
  font-size: 18px;
  color: var(--text-muted);
  margin-top: 4px;
  letter-spacing: 0.05em;
}

.karaoke-wait {
  font-size: 24px;
  color: var(--text-muted);
  letter-spacing: 0.3em;
  animation: pulse 1.5s ease-in-out infinite;
}

/* ==========================================
   RESULTS SCREEN
   ========================================== */
.results-bg {
  position: absolute;
  inset: 0;
  overflow: hidden;
  z-index: 0;
  background: var(--bg-dark);
}

.results-content {
  position: relative;
  z-index: 1;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px 20px;
  gap: 20px;
}

.results-title {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 700;
}

.results-song {
  color: var(--text-dim);
  font-size: 16px;
}

.score-circle-container {
  position: relative;
  width: 180px;
  height: 180px;
}

.score-circle {
  width: 100%;
  height: 100%;
}

.score-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.score-big {
  font-family: var(--font-display);
  font-size: 52px;
  font-weight: 900;
  background: linear-gradient(135deg, var(--cyan), var(--purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.score-label {
  font-size: 14px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.score-rank {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 6px 24px;
  border-radius: 99px;
}

.rank-s { background: linear-gradient(135deg, var(--yellow), #ffaa00); color: #000; }
.rank-a { background: rgba(0,255,136,0.15); color: var(--green); }
.rank-b { background: rgba(0,212,255,0.15); color: var(--cyan); }
.rank-c { background: rgba(255,215,0,0.15); color: var(--yellow); }
.rank-d { background: rgba(255,136,68,0.15); color: var(--orange); }

.score-breakdown {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.breakdown-item {
  display: flex;
  align-items: center;
  gap: 12px;
}

.breakdown-label {
  font-size: 14px;
  color: var(--text-dim);
  width: 120px;
  flex-shrink: 0;
}

.breakdown-bar-bg {
  flex: 1;
  height: 8px;
  background: var(--bg-surface);
  border-radius: 99px;
  overflow: hidden;
}

.breakdown-bar {
  height: 100%;
  border-radius: 99px;
  /* All breakdown bars share the same brand gradient so they read as a coherent
     system. Differentiation comes from the label + the fill width itself, not
     from decorative color variance. */
  background: linear-gradient(90deg, var(--cyan), var(--purple));
  transition: width 1s ease-out;
  box-shadow: 0 0 12px color-mix(in srgb, var(--cyan) 40%, transparent);
}

.breakdown-value {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  width: 44px;
  text-align: right;
  color: var(--cyan);
}

.feedback-box {
  width: 100%;
  max-width: 400px;
  padding: 16px 20px;
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius);
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.feedback-icon {
  font-size: 24px;
  flex-shrink: 0;
  line-height: 1.4;
}

.feedback-text {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-dim);
}

.results-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  padding-top: 8px;
}

.breakdown-details {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
}

.breakdown-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.breakdown-toggle:hover {
  background: rgba(255,255,255,0.04);
  border-color: rgba(0,212,255,0.3);
}

.breakdown-toggle-chevron {
  display: inline-block;
  color: var(--text-muted);
  transition: transform 0.2s ease;
  font-size: 12px;
}

.breakdown-toggle.is-open .breakdown-toggle-chevron {
  transform: rotate(180deg);
}

.breakdown-list {
  margin-top: 10px;
  max-height: 360px;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius);
  padding: 6px;
}

.breakdown-list[hidden] {
  display: none !important;
}

.breakdown-row {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 8px;
  border-left: 3px solid transparent;
  font-size: 13px;
}

.breakdown-row + .breakdown-row {
  margin-top: 4px;
}

.breakdown-row-time {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-size: 11px;
}

.breakdown-row-lyric {
  color: var(--text);
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.breakdown-row-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.breakdown-row-meta {
  color: var(--text-muted);
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  margin-left: 6px;
}

.breakdown-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  background: currentColor;
  box-shadow: 0 0 8px currentColor;
}

.breakdown-row.row-perfect { border-left-color: #00e676; }
.breakdown-row.row-perfect .breakdown-row-status { color: #00e676; }

.breakdown-row.row-good { border-left-color: #00d4ff; }
.breakdown-row.row-good .breakdown-row-status { color: #00d4ff; }

.breakdown-row.row-off {
  border-left-color: #ffb300;
  background: rgba(255,179,0,0.05);
}
.breakdown-row.row-off .breakdown-row-status { color: #ffb300; }

.breakdown-row.row-wrong {
  border-left-color: #ff5252;
  background: rgba(255,82,82,0.07);
}
.breakdown-row.row-wrong .breakdown-row-status { color: #ff5252; }

.breakdown-row.row-missed {
  border-left-color: #555;
  opacity: 0.7;
}
.breakdown-row.row-missed .breakdown-row-status { color: #888; }

@media (max-width: 600px) {
  .breakdown-row {
    grid-template-columns: 40px 1fr;
  }
  .breakdown-row-status {
    grid-column: 2;
    justify-content: flex-start;
  }
}

/* ==========================================
   MODAL
   ========================================== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

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

.modal-content {
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-lg);
  padding: 40px;
  max-width: 400px;
  width: 90%;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
}

.modal-icon {
  font-size: 48px;
}

.modal-icon-svg {
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent, #4fc3f7);
}

.modal-icon-svg svg {
  width: 100%;
  height: 100%;
}

.modal-icon-warn {
  color: #ff6b6b;
}

.modal-content h3 {
  font-family: var(--font-display);
  font-size: 22px;
}

.modal-content p {
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.6;
}

.modal-content .btn {
  width: 100%;
}

/* Mic modal has two states — swap which .modal-content is visible. */
.modal[data-state="ask"] .modal-content[data-when="denied"],
.modal[data-state="denied"] .modal-content[data-when="ask"] {
  display: none;
}

.mic-steps {
  text-align: left;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  padding: 12px 16px;
  line-height: 1.9;
}

/* ==========================================
   TOAST
   ========================================== */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(20, 22, 30, 0.96);
  color: var(--text-main);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 10px;
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 500;
  max-width: 420px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  opacity: 0;
  pointer-events: none;
  z-index: 200;
  transition: opacity 0.25s ease, transform 0.25s ease;
  backdrop-filter: blur(8px);
}

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

.toast.toast-error {
  border-color: rgba(255, 80, 80, 0.4);
}

.toast.toast-warn {
  border-color: rgba(255, 200, 80, 0.4);
}

/* ==========================================
   SCROLLBAR
   ========================================== */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--bg-surface);
  border-radius: 3px;
}

/* ==========================================
   AUTH SCREEN (local profile select)
   ========================================== */
.auth-content {
  position: relative;
  z-index: 1;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  gap: 14px;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  overflow-y: auto;
}

.auth-logo {
  width: 84px;
  height: 84px;
  margin-bottom: 4px;
  filter: drop-shadow(0 0 20px rgba(123, 47, 255, 0.25));
}
.auth-logo svg { width: 100%; height: 100%; }

.auth-title {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.01em;
  text-align: center;
  margin-top: 4px;
}

/* Auth tabs */
.auth-tabs {
  display: flex;
  gap: 4px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 10px;
  padding: 3px;
  width: 100%;
}
.auth-tab {
  flex: 1;
  padding: 10px 16px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}
.auth-tab:hover {
  color: var(--text);
}
.auth-tab.active {
  background: var(--bg-card);
  color: var(--text);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Auth forms */
.auth-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px 0;
}
.auth-form[hidden] { display: none; }
.auth-confirm[hidden] { display: none; }

.auth-field {
  display: block;
}
.auth-field-label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
  font-weight: 600;
}
.auth-field input[type="text"],
.auth-field input[type="email"],
.auth-field input[type="password"] {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-dark);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  font-family: var(--font);
  font-size: 15px;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.auth-field input:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(0, 212, 255, 0.12);
}

/* Email confirmation screen */
.auth-confirm {
  text-align: center;
  padding: 24px 0;
}
.auth-confirm-icon {
  font-size: 48px;
  margin-bottom: 16px;
}
.auth-confirm h3 {
  font-family: var(--font-display);
  font-size: 22px;
  margin-bottom: 10px;
}
.auth-confirm p {
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.6;
  max-width: 340px;
  margin: 0 auto 20px;
}

.auth-form-error {
  color: var(--red);
  font-size: 13px;
  padding: 10px 12px;
  background: rgba(255, 68, 68, 0.08);
  border: 1px solid rgba(255, 68, 68, 0.25);
  border-radius: 8px;
}

.auth-form-actions {
  display: flex;
  gap: 10px;
}
.auth-form-actions .btn { flex: 1; }

.auth-footnote {
  color: var(--text-muted);
  font-size: 11px;
  text-align: center;
  margin-top: 8px;
  max-width: 360px;
  line-height: 1.5;
}

/* ==========================================
   PROFILE CHIP (home screen top-right)
   ========================================== */
.profile-chip {
  position: absolute;
  top: 20px;
  right: 20px;
  z-index: 5;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px 6px 6px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 99px;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s ease;
  backdrop-filter: blur(8px);
}
.profile-chip:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--cyan);
}
.profile-chip-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 13px;
  color: #fff;
  flex-shrink: 0;
}
.profile-chip-name {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}
.profile-chip-chevron {
  font-size: 10px;
  color: var(--text-dim);
}

.profile-menu {
  position: absolute;
  top: 62px;
  right: 20px;
  z-index: 6;
  min-width: 200px;
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  backdrop-filter: blur(12px);
}
.profile-menu-avatar-section {
  display: flex;
  justify-content: center;
  padding: 16px 16px 8px;
}

.profile-menu-avatar-lg {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 24px;
  color: #fff;
  border: 2px solid rgba(255,255,255,0.1);
}

.profile-menu-avatar-lg.has-img,
.profile-chip-avatar.has-img,
.lb-avatar.has-img {
  border: 2px solid rgba(255,255,255,0.15);
}

.profile-menu-header {
  padding: 4px 16px 2px;
  text-align: center;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}
.profile-menu-email {
  padding: 0 16px 10px;
  color: var(--text-dim);
  font-size: 12px;
  text-align: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.profile-menu-item {
  display: block;
  width: 100%;
  padding: 12px 16px;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.profile-menu-item:hover { background: rgba(255, 255, 255, 0.05); }
.profile-menu-danger { color: var(--red); }
.profile-menu-danger:hover { background: rgba(255, 68, 68, 0.08); }

/* ==========================================
   GAME HUD: skip-forward button
   ========================================== */
.btn-skip {
  margin-top: 4px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: rgba(0, 212, 255, 0.08);
  border: 1px solid rgba(0, 212, 255, 0.25);
  color: var(--cyan);
  border-radius: 99px;
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: all 0.2s ease;
}
.btn-skip:hover {
  background: rgba(0, 212, 255, 0.16);
  border-color: var(--cyan);
  box-shadow: 0 0 16px rgba(0, 212, 255, 0.25);
}
.btn-skip:active { transform: scale(0.96); }
.btn-skip svg {
  width: 12px;
  height: 12px;
}

/* ==========================================
   LEADERBOARD
   ========================================== */
.lb-tabs {
  display: flex;
  gap: 4px;
  padding: 12px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}

.lb-tab {
  flex: 1;
  padding: 10px 16px;
  background: transparent;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.lb-tab.active {
  background: linear-gradient(135deg, var(--cyan), var(--purple));
  color: #fff;
  border-color: transparent;
}

.lb-song-picker {
  padding: 12px 20px;
  flex-shrink: 0;
}

.lb-song-picker select {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' fill='none' stroke='%238888aa' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.lb-list-container {
  flex: 1;
  overflow-y: auto;
  padding: 8px 20px 20px;
  -webkit-overflow-scrolling: touch;
}

.lb-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lb-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: rgba(255,255,255,0.02);
  border: 1px solid rgba(255,255,255,0.04);
  transition: background 0.2s;
}

.lb-row.is-me {
  background: rgba(0, 212, 255, 0.08);
  border-color: rgba(0, 212, 255, 0.25);
  box-shadow: 0 0 15px rgba(0, 212, 255, 0.1);
}

.lb-row.lb-top-1 {
  background: rgba(255, 215, 0, 0.06);
  border-color: rgba(255, 215, 0, 0.2);
}

.lb-row.lb-top-2 {
  background: rgba(192, 192, 192, 0.05);
  border-color: rgba(192, 192, 192, 0.15);
}

.lb-row.lb-top-3 {
  background: rgba(205, 127, 50, 0.05);
  border-color: rgba(205, 127, 50, 0.15);
}

.lb-rank {
  width: 32px;
  text-align: center;
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  flex-shrink: 0;
}

.lb-rank-num {
  color: var(--text-dim);
  font-size: 14px;
}

.lb-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  color: #fff;
  flex-shrink: 0;
}

.lb-name {
  flex: 1;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-you {
  font-size: 10px;
  font-weight: 700;
  color: var(--cyan);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-left: 6px;
}

.lb-score {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  color: var(--cyan);
  flex-shrink: 0;
}

.lb-top-1 .lb-score { color: var(--yellow); }
.lb-top-2 .lb-score { color: #c0c0c0; }
.lb-top-3 .lb-score { color: #cd7f32; }

.lb-status {
  padding: 40px 20px;
  text-align: center;
}

.lb-status-text {
  color: var(--text-muted);
  font-size: 14px;
}

.lb-empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.5;
}

/* ==========================================
   RESPONSIVE
   ========================================== */
@media (max-width: 600px) {
  /* ---- Home screen: make scrollable, tighten spacing ---- */
  .home-content {
    justify-content: flex-start;
    padding: 24px 20px 40px;
    gap: 24px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .logo-section { padding-top: 16px; }
  .logo-icon { width: 64px; height: 64px; margin-bottom: 10px; }
  .logo-text { font-size: 36px; }
  .tagline { font-size: 14px; }
  .home-stats { gap: 10px; flex-wrap: wrap; justify-content: center; }
  .stat-card { padding: 10px 14px; min-width: 70px; }
  .stat-value { font-size: 18px; }
  .home-methodology { margin-top: 8px; padding: 0 4px; }
  .home-methodology p { font-size: 10px; }

  /* ---- Song grid: allow cards to fit narrow screens ---- */
  .song-grid {
    grid-template-columns: 1fr;
    padding: 12px 16px 40px;
    gap: 10px;
  }
  .song-title {
    white-space: normal;
    word-break: break-word;
    line-height: 1.3;
  }
  .song-card-main { gap: 12px; padding: 14px; }
  .song-art { width: 48px; height: 48px; border-radius: 10px; }
  .song-options { padding: 8px 14px 12px; }

  /* ---- Results screen: tighter on mobile ---- */
  .results-content { padding: 24px 16px 40px; gap: 16px; }
  .results-title { font-size: 20px; }
  .results-song { font-size: 14px; }
  .score-circle-container { width: 150px; height: 150px; }
  .score-big { font-size: 44px; }
  .score-label { font-size: 12px; }
  .score-rank { font-size: 16px; padding: 5px 18px; }
  .score-breakdown { gap: 10px; }
  .breakdown-label { font-size: 12px; }
  .breakdown-value { font-size: 13px; }
  .feedback-box { padding: 12px 14px; }
  .feedback-text { font-size: 13px; }
  .results-actions { flex-direction: column; width: 100%; max-width: 300px; }
  .results-actions .btn { width: 100%; }

  /* ---- Auth ---- */
  .auth-title { font-size: 26px; }
  .profile-chip-name { max-width: 90px; }

  /* ---- Game / HUD ---- */
  .note-name { font-size: 36px; }
  .countdown-number { font-size: 120px; }
  .hud-song-info { display: none; }
  .game-hud { padding: 8px 12px; }
  .hud-score { font-size: 24px; }
  .lyrics-bar { padding: 14px 16px; font-size: 18px; }

  /* ---- Touch targets — 44px minimum per Apple HIG ---- */
  .auth-tab { min-height: 44px; }
  .filter-btn { min-height: 44px; padding: 10px 20px; }
  .btn-back { width: 44px; height: 44px; }
  .btn-back-game { width: 44px; height: 44px; }
  .btn-skip { min-height: 36px; padding: 8px 14px; }
  .profile-chip { min-height: 44px; padding: 8px 16px 8px 8px; }

  /* Prevent iOS zoom on input focus (needs ≥16px) */
  .auth-field input[type="text"],
  .auth-field input[type="email"],
  .auth-field input[type="password"] { font-size: 16px; }

  /* ---- Leaderboard ---- */
  .lb-tabs { padding: 10px 16px; }
  .lb-tab { min-height: 44px; }
  .lb-song-picker { padding: 10px 16px; }
  .lb-song-picker select { font-size: 16px; min-height: 44px; }
  .lb-list-container { padding: 8px 16px 16px; }
  .lb-row { padding: 10px 12px; gap: 10px; }
  .lb-score { font-size: 18px; }
}
