/* ==========================================================================
   Tonedeaf — ear training game (v2)
   base.css handles tokens, reset, body, Inter font, .chip, focus-visible,
   touch-action, .home-btn, .visually-hidden, reduced-motion.
   This stylesheet is mobile-first; tablet/desktop tweaks under media queries.
   ========================================================================== */

[hidden] { display: none !important; }

html, body {
  /* Prevent any element from causing horizontal scroll on iOS Safari */
  overflow-x: hidden;
  max-width: 100%;
}

/* Override the shared home-btn to respect iOS safe areas (notch/Dynamic Island) */
.home-btn {
  top: calc(0.82rem + env(safe-area-inset-top, 0px)) !important;
  left: calc(0.75rem + env(safe-area-inset-left, 0px)) !important;
}

body {
  /* Ambient gradient backdrop — subtle, doesn't fight content */
  background:
    radial-gradient(circle at 80% -10%, rgba(138, 124, 255, 0.10), transparent 55%),
    radial-gradient(circle at 0% 100%, rgba(138, 124, 255, 0.07), transparent 50%),
    var(--bg);
  /* iOS Safari needs the -webkit-fill-available fallback BEFORE dvh */
  min-height: 100vh;
  min-height: -webkit-fill-available;
  min-height: 100dvh;
}

/* --- Guide button (top-right, next to Settings) --- */
.guide-btn {
  position: fixed;
  top: calc(0.82rem + env(safe-area-inset-top, 0px));
  right: calc(3.1rem + env(safe-area-inset-right, 0px));
  z-index: 9999;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 1.7rem;
  width: 2.1rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(6, 11, 26, 0.9);
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.12s ease;
}
.guide-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-1px);
}
.guide-btn svg { width: 14px; height: 14px; }

/* --- Settings button (top-right) --- */
.settings-btn {
  position: fixed;
  top: calc(0.82rem + env(safe-area-inset-top, 0px));
  right: calc(0.75rem + env(safe-area-inset-right, 0px));
  z-index: 9999;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 1.7rem;
  width: 2.1rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(6, 11, 26, 0.9);
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.12s ease;
}

.settings-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-1px) rotate(40deg);
}

.settings-btn svg { width: 14px; height: 14px; }

/* ==========================================================================
   MAIN MENU
   ========================================================================== */
.menu {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(64px + env(safe-area-inset-top, 0px)) 16px calc(96px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.menu-head {
  text-align: center;
  padding: 12px 0 4px;
}

.menu-head h1 {
  font-size: clamp(36px, 9vw, 56px);
  font-weight: 800;
  letter-spacing: -0.025em;
  background: linear-gradient(180deg, var(--text) 0%, #9085d8 130%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

.tagline {
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
}

/* --- Rank pill (overall progress across modes) --- */
.menu-rank {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  padding: 6px 14px 6px 11px;
  background: linear-gradient(135deg, rgba(138, 124, 255, 0.18), rgba(138, 124, 255, 0.05));
  border: 1px solid rgba(138, 124, 255, 0.35);
  border-radius: var(--radius-pill);
  font-size: 12px;
  box-shadow: 0 6px 20px rgba(138, 124, 255, 0.18);
}

.menu-rank .rank-icon {
  display: inline-flex;
  color: var(--accent);
  width: 14px;
  height: 14px;
}
.menu-rank .rank-icon svg { width: 14px; height: 14px; }

.rank-label {
  color: var(--muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 10px;
  font-weight: 700;
}
.rank-tier {
  color: var(--text);
  font-weight: 800;
  letter-spacing: 0.01em;
  background: linear-gradient(180deg, #fff 0%, #b8a8ff 130%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}
.rank-divider { color: var(--muted); opacity: 0.4; }
.rank-sub { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }

/* ==========================================================================
   DAILY CHALLENGE — hero card at top of menu
   ========================================================================== */
.daily-card {
  padding: 16px 18px 18px;
  background:
    radial-gradient(circle at 0% 0%, rgba(138, 124, 255, 0.18), transparent 55%),
    radial-gradient(circle at 100% 100%, rgba(255, 198, 64, 0.14), transparent 55%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.01));
  border: 1px solid rgba(138, 124, 255, 0.35);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  position: relative;
  overflow: hidden;
}

.daily-card.played {
  border-color: rgba(39, 209, 122, 0.4);
}

.daily-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.daily-head-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.daily-icon {
  width: 22px;
  height: 22px;
  color: var(--accent);
  flex-shrink: 0;
}

.daily-title {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.005em;
  background: linear-gradient(180deg, #fff 0%, #b8a8ff 130%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

.daily-date {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.daily-body {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.daily-prompt {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.45;
  flex: 1;
  min-width: 0;
}
.daily-prompt strong { color: var(--text); }

.daily-result-grid {
  display: inline-flex;
  gap: 4px;
  flex-wrap: wrap;
}

.daily-result-grid span {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  display: inline-block;
}
.daily-result-grid span.ok    { background: #27d17a; }
.daily-result-grid span.miss  { background: #ff5d7a; }
.daily-result-grid span.empty { background: rgba(255, 255, 255, 0.08); }

.daily-cta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  border: 1px solid rgba(138, 124, 255, 0.6);
  background: var(--accent-soft);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.18s ease;
  min-height: 40px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.daily-cta:hover {
  background: rgba(138, 124, 255, 0.3);
  transform: translateY(-1px);
}
.daily-cta:disabled {
  background: rgba(39, 209, 122, 0.12);
  border-color: rgba(39, 209, 122, 0.4);
  color: #6ddc9d;
  cursor: default;
  pointer-events: none;
}
.daily-cta svg { width: 14px; height: 14px; flex-shrink: 0; }

.daily-stats {
  display: flex;
  gap: 16px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.daily-stat {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.daily-stat .d-label {
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--muted);
}

.daily-stat .d-val {
  font-size: 17px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

/* ==========================================================================
   PITCH ANCHOR — elevated hero card (above the regular mode grid)
   ========================================================================== */
.anchor-hero {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 16px 18px;
  background:
    radial-gradient(circle at 0% 0%, rgba(255, 198, 64, 0.16), transparent 55%),
    radial-gradient(circle at 100% 100%, rgba(138, 124, 255, 0.16), transparent 55%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.01));
  border: 1px solid rgba(255, 198, 64, 0.35);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.18s ease;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.32);
  position: relative;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.anchor-hero:hover {
  border-color: rgba(255, 198, 64, 0.6);
  transform: translateY(-1px);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 198, 64, 0.18);
}

.anchor-hero-glyph {
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, rgba(255, 198, 64, 0.25), rgba(138, 124, 255, 0.18));
  color: #ffd97a;
  flex-shrink: 0;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.anchor-hero-glyph svg { width: 28px; height: 28px; }
.anchor-hero:hover .anchor-hero-glyph {
  transform: scale(1.06) rotate(-4deg);
}

.anchor-hero-body { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.anchor-hero-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.anchor-hero-title {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.01em;
  background: linear-gradient(180deg, #fff 0%, #ffd97a 130%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

.anchor-hero-tag {
  display: inline-flex;
  padding: 2px 9px;
  border-radius: 999px;
  background: rgba(255, 198, 64, 0.16);
  border: 1px solid rgba(255, 198, 64, 0.4);
  color: #ffd97a;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 700;
}

.anchor-hero-desc {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.anchor-hero-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.anchor-hero-cta {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 18px;
  border-radius: var(--radius-pill);
  border: 1px solid rgba(255, 198, 64, 0.55);
  background: rgba(255, 198, 64, 0.16);
  color: #ffd97a;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.18s ease;
  min-height: 42px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.anchor-hero-cta:hover {
  background: rgba(255, 198, 64, 0.26);
  border-color: rgba(255, 198, 64, 0.8);
  color: #fff0c8;
  transform: translateY(-1px);
}
.anchor-hero-cta svg { width: 14px; height: 14px; flex-shrink: 0; color: #ffc640; }

@media (max-width: 540px) {
  .anchor-hero {
    grid-template-columns: auto 1fr;
    padding: 14px;
  }
  .anchor-hero-cta {
    grid-column: 1 / -1;
    justify-content: center;
    margin-top: 6px;
  }
}

/* ==========================================================================
   GUIDE PANEL
   ========================================================================== */
.guide-panel {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.guide-sheet {
  position: relative;
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  max-height: 90dvh;
  background: radial-gradient(circle at 30% 0%, #1c1832, #0a0814);
  border: 1px solid rgba(138, 124, 255, 0.22);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  display: flex;
  flex-direction: column;
  box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.6);
  animation: settings-up 0.32s cubic-bezier(0.32, 0.72, 0, 1);
  -webkit-overflow-scrolling: touch;
}

/* The settings-head row inside the guide should stick to the top while the
   body scrolls */
.guide-sheet > .settings-head {
  position: sticky;
  top: 0;
  background: linear-gradient(180deg, #1c1832 75%, transparent);
  padding: 18px 20px 12px;
  z-index: 2;
}

.guide-body {
  overflow-y: auto;
  padding: 4px 20px calc(28px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 22px;
  font-size: 14.5px;
  line-height: 1.6;
  color: var(--text);
}

.guide-section h3 {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 8px;
}

.guide-section p {
  color: var(--text);
  margin-bottom: 6px;
}
.guide-section p:last-child { margin-bottom: 0; }
.guide-section p strong { color: #fff; }
.guide-section p em { color: var(--muted); font-style: italic; }

.guide-section ol, .guide-section ul {
  padding-left: 22px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.guide-section li {
  color: var(--text);
}
.guide-section li strong { color: #fff; }

.guide-callout {
  margin-top: 10px;
  padding: 10px 14px;
  background: rgba(138, 124, 255, 0.1);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 13.5px;
  color: var(--text);
}

.guide-modes {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px 14px;
  margin: 4px 0;
}
@media (min-width: 540px) {
  .guide-modes {
    grid-template-columns: auto 1fr;
  }
}

.guide-modes dt {
  font-weight: 800;
  color: var(--accent);
  font-size: 13px;
  padding-top: 4px;
}
.guide-modes dd {
  color: var(--text);
  font-size: 13.5px;
  margin-bottom: 4px;
}

.guide-footer {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  font-style: italic;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  margin-top: 4px;
}

/* ==========================================================================
   DAILY COMPLETE OVERLAY
   ========================================================================== */
.daily-complete {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 9500;
  padding: 20px;
  animation: lvl-fade 0.3s ease-out;
}

.daily-complete-card {
  width: 100%;
  max-width: 380px;
  padding: 28px 24px 22px;
  text-align: center;
  background: radial-gradient(circle at 30% 0%, #251a4a, #0a0814);
  border: 1px solid rgba(138, 124, 255, 0.5);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.65),
              0 0 60px rgba(138, 124, 255, 0.22);
  animation: go-pop 0.55s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.daily-complete-spark {
  font-size: 28px;
  color: var(--accent);
  text-shadow: 0 0 24px rgba(138, 124, 255, 0.7);
}

.daily-complete-title {
  margin-top: 4px;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.01em;
  background: linear-gradient(180deg, #ffffff 0%, #b8a8ff 130%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

.daily-complete-date {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 700;
  margin-top: 2px;
}

.daily-complete-score {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
  margin: 16px 0 4px;
}

.dc-score-num {
  font-size: 60px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
  background: linear-gradient(180deg, #b8a8ff 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  font-variant-numeric: tabular-nums;
}

.dc-score-out {
  font-size: 18px;
  color: var(--muted);
  font-weight: 700;
}

.daily-complete-grid {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin: 12px 0 16px;
  flex-wrap: wrap;
}

.daily-complete-grid span {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.9);
}
.daily-complete-grid span.ok   { background: #27d17a; }
.daily-complete-grid span.miss { background: #ff5d7a; }

.daily-complete-meta {
  display: flex;
  justify-content: center;
  gap: 22px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 20px;
}
.daily-complete-meta strong {
  color: var(--text);
  font-weight: 700;
}

.daily-complete-actions {
  display: flex;
  gap: 10px;
}

.daily-complete-actions .btn {
  flex: 1;
  justify-content: center;
  padding: 12px 14px;
}

/* Mode card grid — single column on mobile, two columns on wider */
.mode-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.mode-card {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: start;
  gap: 14px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  color: var(--text);
  text-align: left;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.18s ease, box-shadow 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  overflow: hidden;
}

.mode-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 0% 0%, rgba(138, 124, 255, 0.08), transparent 60%);
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.mode-card:hover {
  border-color: rgba(138, 124, 255, 0.45);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45),
              0 0 0 1px rgba(138, 124, 255, 0.15);
}

.mode-card:hover::before { opacity: 1; }

.mode-card-icon {
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, rgba(138, 124, 255, 0.22), rgba(138, 124, 255, 0.08));
  border-radius: var(--radius-md);
  color: var(--accent);
  flex-shrink: 0;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.mode-card:hover .mode-card-icon {
  transform: scale(1.06) rotate(-3deg);
}

.mode-card-icon svg {
  width: 28px;
  height: 28px;
}

.mode-card-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.mode-card-title {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}

.mode-card-desc {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.45;
}

.mode-card-meta {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.meta-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  font-size: 11px;
}

.meta-label {
  color: var(--muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-size: 10px;
  font-weight: 600;
}

.meta-val {
  color: var(--text);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.meta-pill-endless {
  background: rgba(255, 198, 64, 0.08);
  border-color: rgba(255, 198, 64, 0.3);
}
.meta-pill-endless .meta-label { color: #ffc640; }
.meta-pill-endless .meta-val   { color: #ffd97a; }

/* --- Mode card actions --- */
.mode-card-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.card-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.12s ease, color 0.18s ease;
  min-height: 42px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.card-btn svg { width: 13px; height: 13px; flex-shrink: 0; }

.card-btn:hover,
.card-btn:focus-visible {
  transform: translateY(-1px);
}

.card-btn-play {
  background: var(--accent-soft);
  border-color: rgba(138, 124, 255, 0.5);
  color: var(--text);
}
.card-btn-play:hover {
  background: rgba(138, 124, 255, 0.28);
  border-color: var(--accent);
}

.card-btn-endless {
  background: rgba(255, 198, 64, 0.08);
  border-color: rgba(255, 198, 64, 0.3);
  color: #ffd97a;
}
.card-btn-endless:hover {
  background: rgba(255, 198, 64, 0.18);
  border-color: rgba(255, 198, 64, 0.6);
  color: #ffe699;
}
.card-btn-endless svg { color: #ffc640; }

/* --- Random card: rainbow-y icon tint --- */
.mode-card-random .mode-card-icon {
  background: linear-gradient(135deg, rgba(255, 93, 122, 0.18), rgba(138, 124, 255, 0.18) 50%, rgba(39, 209, 122, 0.18));
  color: #d6c7ff;
}

/* --- Endless difficulty picker (shown on endless start screen) --- */
.diff-pickr {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  padding: 8px 12px;
  border: 1px dashed rgba(255, 198, 64, 0.35);
  border-radius: var(--radius-md);
  background: rgba(255, 198, 64, 0.05);
}

.diff-label {
  font-size: 10px;
  color: #ffc640;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 700;
}

.diff-chip {
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.18s ease;
  min-height: 36px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.diff-chip:hover {
  color: var(--text);
  border-color: rgba(255, 198, 64, 0.5);
}

.diff-chip.active {
  background: rgba(255, 198, 64, 0.18);
  border-color: rgba(255, 198, 64, 0.65);
  color: #ffe699;
  box-shadow: 0 0 0 1px rgba(255, 198, 64, 0.2);
}

.diff-chip-sub {
  display: block;
  font-size: 10px;
  font-weight: 500;
  opacity: 0.7;
  margin-top: 1px;
  letter-spacing: 0.02em;
  text-transform: none;
}

/* --- Random mode: sub-mode badge shown above the board --- */
.submode-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px 4px 10px;
  border-radius: var(--radius-pill);
  background: linear-gradient(135deg, rgba(255, 93, 122, 0.15), rgba(138, 124, 255, 0.15) 50%, rgba(39, 209, 122, 0.15));
  border: 1px solid rgba(138, 124, 255, 0.35);
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--text);
  animation: submode-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.submode-badge .submode-label {
  color: var(--muted);
  font-size: 10px;
}

@keyframes submode-pop {
  0%   { transform: scale(0.85); opacity: 0; }
  60%  { transform: scale(1.05); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.menu-footer {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  opacity: 0.7;
  margin-top: 8px;
}

.menu-footer kbd {
  display: inline-block;
  padding: 1px 6px;
  font: 600 11px var(--font-mono);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text);
  margin: 0 1px;
}

@media (hover: none) and (pointer: coarse) {
  .menu-footer { display: none; }
}

/* ==========================================================================
   GAME VIEW
   ========================================================================== */
.game {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(58px + env(safe-area-inset-top, 0px)) 14px calc(110px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.game-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
}

.back-btn {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, transform 0.12s ease, border-color 0.15s ease;
}

.back-btn:hover {
  background: var(--surface-hover);
  color: var(--accent);
  border-color: var(--accent);
  transform: translateX(-2px);
}

.back-btn svg { width: 18px; height: 18px; }

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

.game-head-info h1 {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.01em;
  line-height: 1.15;
}

.mode-desc {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
  line-height: 1.4;
}

.mode-desc strong {
  color: var(--text);
  font-weight: 600;
}

/* --- Stats row --- */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.stat-label {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.stat-value {
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  transition: color 0.3s ease, transform 0.3s ease;
}

.stat-value.bump {
  animation: stat-bump 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
  color: var(--accent);
}

@keyframes stat-bump {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.4); }
  100% { transform: scale(1); }
}

.stat-progress {
  grid-column: 1 / -1;
  grid-row: 2;
}

.progress {
  height: 6px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #b8a8ff);
  border-radius: 999px;
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Board (mode-specific content area) --- */
.board {
  min-height: 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 20px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  position: relative;
}

/* ---- SORT MODE ---- */
.sort-stage,
.identify-stage,
.intervals-stage,
.chords-stage,
.memory-stage {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  align-items: center;
}

.stage-instructions {
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  line-height: 1.45;
}
.stage-instructions strong { color: var(--text); }

.sort-tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.note-tile {
  position: relative;
  width: 68px;
  height: 82px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s ease, transform 0.15s ease, border-color 0.18s ease, box-shadow 0.18s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.note-tile:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
  transform: translateY(-2px);
}

.note-tile.playing {
  animation: tile-pulse 0.45s ease-out;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 0 24px rgba(138, 124, 255, 0.4);
}

@keyframes tile-pulse {
  0%   { transform: translateY(0) scale(1); }
  35%  { transform: translateY(-4px) scale(1.08); box-shadow: 0 0 0 2px var(--accent), 0 0 30px rgba(138, 124, 255, 0.6); }
  100% { transform: translateY(0) scale(1); }
}

.note-tile .tile-wave {
  width: 32px;
  height: 14px;
  color: var(--muted);
  transition: color 0.2s ease;
}

.note-tile:hover .tile-wave,
.note-tile.playing .tile-wave {
  color: var(--accent);
}

.note-tile .tile-label {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.note-tile .rank-badge {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(138, 124, 255, 0.5);
  transform: scale(0);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.note-tile.ranked .rank-badge { transform: scale(1); }

.note-tile.ranked {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.note-tile.correct {
  background: rgba(39, 209, 122, 0.18);
  border-color: #27d17a;
}
.note-tile.correct .rank-badge {
  background: #27d17a;
  box-shadow: 0 4px 12px rgba(39, 209, 122, 0.5);
}

.note-tile.wrong {
  background: rgba(255, 93, 122, 0.15);
  border-color: #ff5d7a;
}
.note-tile.wrong .rank-badge {
  background: #ff5d7a;
  box-shadow: 0 4px 12px rgba(255, 93, 122, 0.5);
}

.note-tile.reveal-name .tile-name {
  font-size: 15px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: 0.02em;
}

.sort-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  min-height: 30px;
}

.sort-action-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s ease;
}

.sort-action-btn:hover {
  color: var(--text);
  border-color: var(--accent);
  background: var(--surface);
}

/* ---- Choice grid (Identify / Chords / Intervals) ---- */
.choice-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 540px;
}

.note-btn,
.chord-btn {
  min-width: 60px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.18s ease;
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.chord-btn {
  font-size: 14px;
  min-width: 90px;
  padding: 12px 14px;
}

.note-btn:hover,
.chord-btn:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
  transform: translateY(-2px);
}

.note-btn.correct,
.chord-btn.correct {
  background: rgba(39, 209, 122, 0.2);
  border-color: #27d17a;
  color: #27d17a;
  animation: btn-correct 0.5s ease-out;
}

.note-btn.wrong,
.chord-btn.wrong {
  background: rgba(255, 93, 122, 0.15);
  border-color: #ff5d7a;
  color: #ff5d7a;
  animation: btn-shake 0.42s ease-out;
}

.note-btn.reveal,
.chord-btn.reveal,
.interval-btn.reveal {
  background: rgba(39, 209, 122, 0.1);
  border-color: rgba(39, 209, 122, 0.5);
  color: #6ddc9d;
}

.note-btn:disabled,
.chord-btn:disabled,
.interval-btn:disabled {
  cursor: default;
  pointer-events: none;
}

@keyframes btn-correct {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.12); }
  100% { transform: scale(1); }
}

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

/* ---- Intervals ---- */
.intervals-meta {
  display: flex;
  gap: 16px;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.intervals-meta .dir-up::before  { content: "↑ "; color: var(--accent); }
.intervals-meta .dir-dn::before  { content: "↓ "; color: var(--accent); }

.intervals-choices {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
  width: 100%;
  max-width: 520px;
}

.interval-btn {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: all 0.18s ease;
  display: flex;
  flex-direction: column;
  gap: 2px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.interval-btn:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
  transform: translateY(-1px);
}

.interval-btn .iv-name { font-size: 14px; }
.interval-btn .iv-sub { font-size: 10px; color: var(--muted); letter-spacing: 0.05em; text-transform: uppercase; }

.interval-btn.correct {
  background: rgba(39, 209, 122, 0.2);
  border-color: #27d17a;
  color: #27d17a;
  animation: btn-correct 0.5s ease-out;
}
.interval-btn.correct .iv-sub { color: rgba(39, 209, 122, 0.7); }

.interval-btn.wrong {
  background: rgba(255, 93, 122, 0.15);
  border-color: #ff5d7a;
  color: #ff5d7a;
  animation: btn-shake 0.42s ease-out;
}

/* ---- Memory mode ---- */
.memory-status {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  border: 1px solid rgba(138, 124, 255, 0.4);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.memory-status.listening { background: rgba(255, 207, 64, 0.1); border-color: rgba(255, 207, 64, 0.4); }
.memory-status.echo      { background: rgba(39, 209, 122, 0.12); border-color: rgba(39, 209, 122, 0.45); }

.memory-status .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  color: var(--accent);
}
.memory-status.listening .dot { color: #ffcf40; animation: dot-pulse 0.9s ease-in-out infinite; }
.memory-status.echo .dot      { color: #27d17a; }

@keyframes dot-pulse {
  0%, 100% { transform: scale(1); opacity: 0.7; }
  50%      { transform: scale(1.4); opacity: 1; }
}

.memory-progress {
  display: flex;
  gap: 5px;
  margin: 4px 0 2px;
}

.memory-progress span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  transition: background 0.2s ease, transform 0.2s ease;
}

.memory-progress span.done {
  background: var(--accent);
  transform: scale(1.2);
}

.memory-keys {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  width: 100%;
  max-width: 480px;
}
.memory-keys.chrom {
  grid-template-columns: repeat(12, 1fr);
}
/* Chromatic (12) memory keys: drop to 6-col on narrow phones so tap targets stay usable */
@media (max-width: 540px) {
  .memory-keys.chrom { grid-template-columns: repeat(6, 1fr); }
  .memory-key { aspect-ratio: 5 / 7; }
}

.memory-key {
  aspect-ratio: 3 / 5;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, #f5f5f8 0%, #d8d8e0 100%);
  color: #222;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 6px 0;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.15s ease, filter 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  position: relative;
}

.memory-key.black {
  background: linear-gradient(180deg, #2a2a3a 0%, #14141d 100%);
  color: #fff;
  border-color: #000;
}

.memory-key:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.memory-key:active,
.memory-key.flash {
  transform: translateY(2px);
  box-shadow: inset 0 0 0 2px var(--accent), 0 0 18px rgba(138, 124, 255, 0.5);
  filter: brightness(1.15);
}

.memory-key.flash-correct { box-shadow: inset 0 0 0 2px #27d17a, 0 0 18px rgba(39, 209, 122, 0.5); }
.memory-key.flash-wrong   { box-shadow: inset 0 0 0 2px #ff5d7a, 0 0 18px rgba(255, 93, 122, 0.5); }

.memory-key:disabled {
  pointer-events: none;
  opacity: 0.7;
}

/* --- Big play button (initial state for each round) --- */
.big-play {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
  animation: big-play-breathe 2.4s ease-in-out infinite;
  -webkit-tap-highlight-color: transparent;
}

.big-play:hover {
  background: rgba(138, 124, 255, 0.25);
  transform: scale(1.06);
}

.big-play:active { transform: scale(0.96); }

.big-play svg {
  width: 36px;
  height: 36px;
  transform: translateX(3px);
}

@keyframes big-play-breathe {
  0%, 100% { box-shadow: 0 0 0 0 rgba(138, 124, 255, 0.5); }
  50%      { box-shadow: 0 0 0 18px rgba(138, 124, 255, 0); }
}

.big-play-label {
  font-size: 13px;
  color: var(--muted);
  letter-spacing: 0.06em;
}

/* --- Controls --- */
.controls {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 22px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.12s ease;
  min-height: 44px;
}

.btn:hover {
  background: var(--surface-hover);
  transform: translateY(-1px);
  border-color: var(--accent);
}

.btn-primary {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text);
}

.btn-primary:hover {
  background: rgba(138, 124, 255, 0.25);
}

.btn-ghost { background: transparent; }

.btn svg { flex-shrink: 0; }

/* --- Feedback --- */
.feedback {
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  min-height: 22px;
  letter-spacing: 0.01em;
  color: var(--muted);
  transition: color 0.2s ease;
}

.feedback.good   { color: #27d17a; }
.feedback.bad    { color: #ff5d7a; }

/* --- Hint --- */
.hint {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  opacity: 0.7;
}

.hint kbd {
  display: inline-block;
  padding: 1px 6px;
  font: 600 10px var(--font-mono);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text);
  margin: 0 1px;
}

/* Hide keyboard hints on touch devices AND narrow viewports */
@media (hover: none) and (pointer: coarse),
       (max-width: 720px) {
  .hint, .menu-footer { display: none !important; }
}

/* ==========================================================================
   ENDLESS MODE — game header badge + game-over overlay
   ========================================================================== */
.game-head-info .endless-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 8px;
  padding: 2px 9px 2px 7px;
  border-radius: 999px;
  background: rgba(255, 198, 64, 0.14);
  border: 1px solid rgba(255, 198, 64, 0.45);
  color: #ffd97a;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  vertical-align: 4px;
}

.game-head-info .endless-badge svg {
  width: 11px;
  height: 11px;
  fill: #ffc640;
}

.stat-value.endless { color: #ffd97a; }
.stat-progress.hidden { visibility: hidden; }

/* --- Game over overlay --- */
.game-over {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 9500;
  padding: 20px;
  animation: lvl-fade 0.32s ease-out;
}

.game-over-card {
  width: 100%;
  max-width: 360px;
  padding: 28px 24px 22px;
  text-align: center;
  background: radial-gradient(circle at 30% 0%, #2a1f10, #0a0814);
  border: 1px solid rgba(255, 198, 64, 0.4);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.65),
              0 0 60px rgba(255, 198, 64, 0.18);
  animation: go-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes go-pop {
  0%   { transform: scale(0.8) translateY(16px); opacity: 0; }
  60%  { transform: scale(1.03) translateY(-2px); opacity: 1; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

.game-over-title {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 14px;
}

.game-over-rounds {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  margin-bottom: 10px;
}

.game-over-num {
  font-size: 64px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
  background: linear-gradient(180deg, #ffe699 0%, #ffc640 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  font-variant-numeric: tabular-nums;
}

.game-over-label {
  font-size: 13px;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.game-over-best {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 20px;
}

.game-over-best strong {
  color: #ffd97a;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.game-over-best.new-best::after {
  content: " · new best!";
  color: #27d17a;
  font-weight: 700;
}

.game-over-actions {
  display: flex;
  gap: 10px;
}

.game-over-actions .btn {
  flex: 1;
  justify-content: center;
  padding: 12px 14px;
}

.game-over-actions .btn-primary {
  background: rgba(255, 198, 64, 0.16);
  border-color: rgba(255, 198, 64, 0.6);
  color: #ffd97a;
}

.game-over-actions .btn-primary:hover {
  background: rgba(255, 198, 64, 0.28);
  border-color: #ffc640;
  color: #fff0c8;
}

.game-over-actions .btn-primary svg { color: #ffc640; }

/* ==========================================================================
   PITCH ANCHOR — dedicated long-term pitch training page
   ========================================================================== */
.anchor {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(58px + env(safe-area-inset-top, 0px)) 14px calc(110px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: view-fade 0.32s cubic-bezier(0.32, 0.72, 0, 1);
}

.mode-card-anchor .mode-card-icon {
  background: linear-gradient(135deg, rgba(255, 198, 64, 0.15), rgba(138, 124, 255, 0.18));
  color: #ffd97a;
}

/* --- Anchor picker (12-note chromatic grid) --- */
.anchor-picker {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}

.anchor-picker-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.anchor-picker-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 4px;
}

.anchor-key {
  position: relative;
  padding: 8px 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.18s ease;
  min-height: 38px;
  -webkit-tap-highlight-color: transparent;
  font-variant-numeric: tabular-nums;
}
.anchor-key.black {
  background: linear-gradient(180deg, #1c1c2a, #0e0e16);
  color: rgba(255, 255, 255, 0.85);
}
.anchor-key:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}
.anchor-key.active {
  background: linear-gradient(180deg, rgba(255, 198, 64, 0.4), rgba(255, 198, 64, 0.18));
  border-color: rgba(255, 198, 64, 0.7);
  color: #fff;
  box-shadow: 0 0 0 1px rgba(255, 198, 64, 0.45), 0 6px 14px rgba(255, 198, 64, 0.2);
}
.anchor-key .accuracy-dot {
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  width: 16px;
  height: 3px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.1);
}
.anchor-key .accuracy-dot.lv1 { background: #4a3a8a; }
.anchor-key .accuracy-dot.lv2 { background: #8a7cff; }
.anchor-key .accuracy-dot.lv3 { background: #27d17a; }

/* --- Anchor tabs --- */
.anchor-tabs {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  padding: 4px;
  gap: 2px;
  align-self: center;
}

.anchor-tab {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease;
  min-height: 36px;
}
.anchor-tab:hover { color: var(--text); }
.anchor-tab.active {
  background: var(--accent-soft);
  color: var(--text);
  box-shadow: inset 0 0 0 1px rgba(138, 124, 255, 0.4);
}

/* --- Anchor panel (main content area) --- */
.anchor-panel {
  min-height: 240px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 22px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}

/* Listen panel */
.listen-explainer {
  text-align: center;
  font-size: 14px;
  color: var(--muted);
  max-width: 460px;
  line-height: 1.55;
}
.listen-explainer strong { color: var(--text); }

.listen-cycle {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}
.listen-cycle-chip {
  padding: 5px 12px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 700;
  transition: all 0.2s ease;
}
.listen-cycle-chip.active {
  background: rgba(255, 198, 64, 0.18);
  border-color: rgba(255, 198, 64, 0.5);
  color: #ffe699;
}

/* Drill panel */
.drill-status {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 700;
}
.drill-status .anchor-streak { color: #ffd97a; }

.drill-choice-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  width: 100%;
  max-width: 480px;
}
.drill-choice-grid .note-btn {
  min-width: 0;
  padding: 12px 0;
  font-size: 14px;
}

.drill-progress {
  display: flex;
  gap: 4px;
  margin-top: 4px;
}
.drill-progress span {
  width: 14px;
  height: 6px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.08);
}
.drill-progress span.ok   { background: #27d17a; }
.drill-progress span.miss { background: #ff5d7a; }

.drill-summary {
  text-align: center;
}
.drill-summary-num {
  font-size: 44px;
  font-weight: 800;
  background: linear-gradient(180deg, #ffe699 0%, #ffc640 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.drill-summary-label {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 700;
  margin-top: 4px;
}

/* Stats panel */
.anchor-stats-explainer {
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  max-width: 460px;
}

.anchor-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  width: 100%;
  max-width: 480px;
}
@media (min-width: 600px) {
  .anchor-stats-grid { grid-template-columns: repeat(6, 1fr); }
}

.anchor-stat-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 4px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg);
  font-variant-numeric: tabular-nums;
}
.anchor-stat-cell .as-note {
  font-size: 14px;
  font-weight: 800;
  color: var(--text);
}
.anchor-stat-cell .as-pct {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}
.anchor-stat-cell .as-bar {
  width: 80%;
  height: 4px;
  margin-top: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 2px;
  overflow: hidden;
}
.anchor-stat-cell .as-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #ff5d7a 0%, #ffd97a 50%, #27d17a 100%);
  transition: width 0.4s ease;
}
.anchor-stat-cell.focused {
  border-color: rgba(255, 198, 64, 0.6);
  background: rgba(255, 198, 64, 0.06);
}

/* Reusable: a bigger Listen button */
.listen-play {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 14px 24px;
  border-radius: var(--radius-pill);
  border: 1px solid rgba(255, 198, 64, 0.5);
  background: rgba(255, 198, 64, 0.12);
  color: #ffe699;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.18s ease;
  min-height: 46px;
}
.listen-play:hover {
  background: rgba(255, 198, 64, 0.22);
  border-color: rgba(255, 198, 64, 0.8);
}
.listen-play:disabled {
  opacity: 0.6;
  pointer-events: none;
}
.listen-play svg { width: 16px; height: 16px; }

/* Anchor picker + drill grid: wrap to a roomier 6-col layout at iPhone widths */
@media (max-width: 540px) {
  .anchor-picker-grid { grid-template-columns: repeat(6, 1fr); gap: 6px; }
  .drill-choice-grid { grid-template-columns: repeat(4, 1fr); }
  .anchor-key { font-size: 13px; min-height: 42px; }
}

@media (max-width: 380px) {
  .anchor { padding: calc(54px + env(safe-area-inset-top, 0px)) 10px calc(90px + env(safe-area-inset-bottom, 0px)); }
  .anchor-stats-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ==========================================================================
   SETTINGS PANEL (slide-up sheet on mobile, side drawer on wider)
   ========================================================================== */
.settings-panel {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.settings-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: settings-fade 0.25s ease-out;
}

.settings-sheet {
  position: relative;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  max-height: 90dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: radial-gradient(circle at 30% 0%, #1c1832, #0a0814);
  border: 1px solid rgba(138, 124, 255, 0.18);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 18px 18px calc(20px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 18px;
  box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.6);
  animation: settings-up 0.32s cubic-bezier(0.32, 0.72, 0, 1);
}

@keyframes settings-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes settings-up {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

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

.settings-head h2 {
  font-size: 18px;
  font-weight: 700;
}

.settings-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.settings-close:hover { color: var(--text); border-color: var(--accent); }
.settings-close svg { width: 14px; height: 14px; }

.setting {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.setting-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

/* --- Segmented control (used in settings + originally in header) --- */
.seg {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  padding: 4px;
  gap: 2px;
  flex-wrap: nowrap;
  align-self: flex-start;
  max-width: 100%;
  overflow: hidden;
}

.seg-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 9px 18px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, transform 0.12s ease;
  white-space: nowrap;
  min-height: 36px;
}

.seg-btn:hover { color: var(--text); }

.seg-btn.active {
  background: var(--accent-soft);
  color: var(--text);
  box-shadow: inset 0 0 0 1px rgba(138, 124, 255, 0.4);
}

/* --- Volume slider --- */
.slider-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.slider-row input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  height: 32px;
  cursor: pointer;
}

.slider-row input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  background: var(--surface-hover);
  border-radius: 999px;
  border: 1px solid var(--line);
}

.slider-row input[type="range"]::-moz-range-track {
  height: 6px;
  background: var(--surface-hover);
  border-radius: 999px;
  border: 1px solid var(--line);
}

.slider-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #1a1530;
  margin-top: -8px;
  box-shadow: 0 4px 10px rgba(138, 124, 255, 0.5);
  cursor: pointer;
}

.slider-row input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #1a1530;
  box-shadow: 0 4px 10px rgba(138, 124, 255, 0.5);
  cursor: pointer;
}

.slider-val {
  min-width: 38px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

/* --- Toggle switch --- */
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
}

.toggle input { display: none; }

.toggle-track {
  width: 44px;
  height: 26px;
  background: var(--surface-hover);
  border: 1px solid var(--line);
  border-radius: 999px;
  position: relative;
  transition: background 0.2s ease, border-color 0.2s ease;
  flex-shrink: 0;
}

.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--text);
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.2s ease;
}

.toggle input:checked + .toggle-track {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.toggle input:checked + .toggle-track .toggle-thumb {
  transform: translateX(18px);
  background: var(--accent);
}

.toggle-text {
  font-size: 13px;
  color: var(--muted);
}

.reset-btn {
  width: 100%;
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 93, 122, 0.4);
  background: rgba(255, 93, 122, 0.08);
  color: #ff5d7a;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease;
  min-height: 44px;
}

.reset-btn:hover {
  background: rgba(255, 93, 122, 0.15);
  border-color: #ff5d7a;
}

.reset-btn.confirm {
  background: rgba(255, 93, 122, 0.25);
  color: #fff;
  border-color: #ff5d7a;
}

/* ==========================================================================
   LEVEL UP TOAST
   ========================================================================== */
.level-up {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 9500;
  animation: lvl-fade 0.3s ease-out;
}

@keyframes lvl-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.level-up-card {
  padding: 28px 36px;
  text-align: center;
  background: radial-gradient(circle at 30% 0, #251a4a, #0a0814);
  border: 1px solid rgba(138, 124, 255, 0.5);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6),
              0 0 60px rgba(138, 124, 255, 0.35);
  animation: lvl-pop 0.55s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes lvl-pop {
  0%   { transform: scale(0.7) translateY(20px); opacity: 0; }
  60%  { transform: scale(1.05) translateY(-4px); opacity: 1; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

.level-up-spark {
  font-size: 36px;
  color: var(--accent);
  text-shadow: 0 0 24px rgba(138, 124, 255, 0.7);
  animation: spark-spin 1.5s linear infinite;
}

@keyframes spark-spin {
  from { transform: rotate(0); }
  to   { transform: rotate(360deg); }
}

.level-up-title {
  margin-top: 8px;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.01em;
  background: linear-gradient(180deg, #ffffff 0%, #b8a8ff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

.level-up-sub {
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
}

/* ==========================================================================
   View transitions
   ========================================================================== */
.menu, .game {
  animation: view-fade 0.32s cubic-bezier(0.32, 0.72, 0, 1);
}

@keyframes view-fade {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   Larger viewports
   ========================================================================== */
@media (min-width: 600px) {
  .menu {
    padding: 80px 28px 60px;
    gap: 36px;
  }
  .mode-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
  }
  .mode-card { min-height: 104px; padding: 18px; }
  .mode-card-icon { width: 60px; height: 60px; }
  .mode-card-icon svg { width: 30px; height: 30px; }
  .mode-card-title { font-size: 20px; }
  .mode-card-desc { font-size: 13.5px; }

  .game {
    padding: 76px 22px 48px;
    gap: 20px;
  }
  .game-head-info h1 { font-size: 26px; }

  .stats {
    grid-template-columns: repeat(3, auto) 1fr;
    gap: 22px;
    padding: 14px 20px;
  }
  .stat-progress { grid-column: 4; grid-row: 1; }
  .stat-value { font-size: 24px; }
  .stat-label { font-size: 10px; }

  .board { min-height: 260px; padding: 26px 18px; }

  .note-tile { width: 76px; height: 92px; }
  .note-btn { min-width: 64px; font-size: 17px; padding: 14px 18px; }

  .big-play { width: 96px; height: 96px; }
  .big-play svg { width: 40px; height: 40px; }
}

/* Very small phones — give content room */
@media (max-width: 380px) {
  .menu { padding: 56px 12px 80px; gap: 22px; }
  .mode-card { padding: 12px; gap: 12px; }
  .mode-card-icon { width: 44px; height: 44px; }
  .mode-card-icon svg { width: 22px; height: 22px; }
  .mode-card-title { font-size: 17px; }
  .mode-card-desc { font-size: 12px; }
  .meta-pill { padding: 2px 8px; font-size: 10px; }
  .card-btn { padding: 9px 10px; font-size: 12px; }
  .card-btn span { white-space: nowrap; }
  .game-over-num { font-size: 52px; }

  .game { padding: 54px 10px 90px; }
  .stats { padding: 10px 12px; gap: 8px; }
  .stat-value { font-size: 18px; }

  .note-tile { width: 60px; height: 76px; }
  .note-btn { min-width: 54px; padding: 12px 14px; font-size: 15px; }
  .chord-btn { min-width: 78px; padding: 11px 12px; font-size: 13px; }
  .interval-btn { padding: 9px 10px; }

  .intervals-choices { grid-template-columns: repeat(2, 1fr); }
}
