/* ==========================================================================
   MusicLab AI — Design Tokens
   "Harmonic Color Language": gold = bright/stable (major), violet = soft/
   melancholic (minor), coral = tension/energy — the same three accents
   that will later color chord qualities are seeded here in Phase 1 so the
   whole app teaches the association from day one.
   ========================================================================== */

:root{
  /* surfaces */
  --bg: #0B0E17;
  --bg-soft: #10141F;
  --glass: rgba(255,255,255,0.045);
  --glass-border: rgba(255,255,255,0.09);
  --glass-hi: rgba(255,255,255,0.08);

  /* text */
  --text-1: #EDEFF7;
  --text-2: #9198AD;
  --text-3: #5C6377;

  /* harmonic color language */
  --major: #F2B84B;      /* bright / stable */
  --major-glow: rgba(242,184,75,0.28);
  --minor: #7C83FD;      /* soft / melancholic */
  --minor-glow: rgba(124,131,253,0.28);
  --tension: #FF6B5C;    /* tension / energy */
  --tension-glow: rgba(255,107,92,0.28);

  --radius-lg: 28px;
  --radius-md: 20px;
  --radius-sm: 14px;

  --font-display: 'Sora', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

@media (prefers-reduced-motion: reduce){
  *{ animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

*{ box-sizing: border-box; }

html, body{
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text-1);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

body{
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(120% 60% at 50% 0%, rgba(124,131,253,0.10) 0%, rgba(11,14,23,0) 55%),
    var(--bg);
}

button{
  font-family: inherit;
  border: none;
  background: none;
  color: inherit;
  cursor: pointer;
}

h1,h2,h3{ font-family: var(--font-display); margin: 0; }

.glass{
  background: var(--glass);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

/* ==========================================================================
   App shell — phone-first, centered on wide viewports
   ========================================================================== */

.app{
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
  display: flex;
  flex-direction: column;
}

/* ==========================================================================
   Top bar
   ========================================================================== */

.top-bar{
  position: relative;
  padding: calc(env(safe-area-inset-top, 0px) + 18px) 20px 14px;
  overflow: hidden;
}

.pulse-line{
  position: absolute;
  inset: 0;
  opacity: 0.35;
  pointer-events: none;
}
.pulse-line svg{ width: 100%; height: 100%; }
.pulse-path{
  fill: none;
  stroke: var(--minor);
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 0 6px var(--minor-glow));
  animation: pulse-drift 6s ease-in-out infinite;
}
@keyframes pulse-drift{
  0%, 100%{ transform: translateX(0); opacity: 0.5; }
  50%{ transform: translateX(6px); opacity: 0.85; }
}

.top-bar-row{
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand{ display: flex; align-items: center; gap: 10px; }
.brand-mark{
  width: 34px; height: 34px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 17px;
  color: #0B0E17;
  background: linear-gradient(135deg, var(--major), #FFD98A);
  box-shadow: 0 4px 16px var(--major-glow);
}
.brand-name{
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.01em;
}
.brand-name em{ font-style: normal; color: var(--minor); }

.streak-chip{
  display: flex; align-items: center; gap: 6px;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 14px;
}
.streak-flame{ font-size: 14px; filter: saturate(1.3); }

/* ==========================================================================
   Views
   ========================================================================== */

.views{
  flex: 1;
  padding: 4px 20px 110px;
}

.view{ display: none; animation: view-in 0.42s cubic-bezier(.2,.7,.2,1) both; }
.view.active{ display: block; }

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

.eyebrow{
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--text-2);
  text-transform: uppercase;
}

/* ---------- status card ---------- */

.status-card{
  border-radius: var(--radius-lg);
  padding: 20px 22px 22px;
  margin: 14px 0 16px;
}
.status-top{
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.level-block{ display: flex; flex-direction: column; gap: 4px; }
.level-name{ font-family: var(--font-display); font-weight: 700; font-size: 19px; }
.level-badge{
  width: 44px; height: 44px;
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 18px;
  background: linear-gradient(160deg, rgba(242,184,75,0.22), rgba(242,184,75,0.06));
  border: 1px solid rgba(242,184,75,0.35);
  color: var(--major);
}
.xp-track{
  height: 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.06);
  overflow: hidden;
}
.xp-fill{
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--minor), var(--major));
  transition: width 0.6s cubic-bezier(.2,.7,.2,1);
}
.xp-label{
  margin-top: 8px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-2);
}

/* ---------- mission card ---------- */

.mission-card{
  border-radius: var(--radius-lg);
  padding: 20px 22px 10px;
  margin-bottom: 26px;
  border-left: 3px solid var(--major);
}
.mission-head{
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.mission-count{
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 13px;
  color: var(--major);
}
.mission-list{ list-style: none; margin: 0; padding: 0; }
.mission-item{
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.mission-item:first-child{ border-top: none; }
.mission-check{
  flex-shrink: 0;
  width: 24px; height: 24px;
  border-radius: 8px;
  border: 1.5px solid var(--glass-border);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  transition: all 0.2s ease;
}
.mission-item.done .mission-check{
  background: var(--major);
  border-color: var(--major);
  color: #0B0E17;
}
.mission-text{ font-size: 14.5px; color: var(--text-1); }
.mission-item.done .mission-text{ color: var(--text-3); text-decoration: line-through; }

/* ---------- section title ---------- */

.section-title{
  font-size: 16px;
  font-weight: 700;
  color: var(--text-1);
  margin: 0 0 14px 2px;
}

/* ---------- module grid ---------- */

.module-grid{
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.module-card{
  border-radius: var(--radius-md);
  padding: 18px 16px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 26px;
  min-height: 108px;
  transition: transform 0.15s ease, background 0.15s ease;
}
.module-card:active{ transform: scale(0.96); }
.module-card .m-icon{ font-size: 24px; }
.module-card .m-name{
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14.5px;
  color: var(--text-1);
}
.module-card .m-sub{
  font-size: 11.5px;
  color: var(--text-2);
  margin-top: 2px;
}
.module-card.wide{ grid-column: 1 / -1; flex-direction: row; align-items: center; min-height: auto; padding: 16px 18px; }
.module-card.wide .m-icon{ font-size: 26px; }
.module-card.wide .m-text{ display: flex; flex-direction: column; gap: 2px; }

.accent-major{ border-left: 3px solid var(--major); }
.accent-minor{ border-left: 3px solid var(--minor); }
.accent-tension{ border-left: 3px solid var(--tension); }

.module-card.accent-major{ box-shadow: inset 0 0 40px -30px var(--major-glow); }
.module-card.accent-minor{ box-shadow: inset 0 0 40px -30px var(--minor-glow); }
.module-card.accent-tension{ box-shadow: inset 0 0 40px -30px var(--tension-glow); }

/* ---------- Piano Lab ---------- */

.back-btn{
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 14px 0 6px;
  padding: 7px 14px 7px 10px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}
.back-btn span{ font-size: 15px; }

.lab-title{ font-size: 21px; margin-top: 10px; }
.lab-sub{ color: var(--text-2); font-size: 13.5px; margin: 6px 0 18px; }

.readout{
  border-radius: var(--radius-lg);
  padding: 22px 20px;
  text-align: center;
  margin-bottom: 20px;
  border: 1px solid var(--glass-border);
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}
.readout-notes{
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-2);
  letter-spacing: 0.03em;
  margin-bottom: 8px;
}
.readout-chord{
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 26px;
  color: var(--text-1);
}
/* harmonic color language reacts live to what's being played */
.readout[data-quality="major"]{
  border-color: rgba(242,184,75,0.5);
  box-shadow: 0 0 32px -12px var(--major-glow);
}
.readout[data-quality="major"] .readout-chord{ color: var(--major); }
.readout[data-quality="minor"]{
  border-color: rgba(124,131,253,0.5);
  box-shadow: 0 0 32px -12px var(--minor-glow);
}
.readout[data-quality="minor"] .readout-chord{ color: var(--minor); }
.readout[data-quality="tension"]{
  border-color: rgba(255,107,92,0.5);
  box-shadow: 0 0 32px -12px var(--tension-glow);
}
.readout[data-quality="tension"] .readout-chord{ color: var(--tension); }

.keyboard-scroll{
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-md);
  background: var(--bg-soft);
  padding: 14px 10px 16px;
  border: 1px solid var(--glass-border);
}
.keyboard{
  position: relative;
  height: 176px;
  touch-action: none;
}
.key{
  position: absolute;
  top: 0;
  border-radius: 0 0 8px 8px;
  user-select: none;
  touch-action: none;
}
.white-key{
  width: 42px;
  height: 100%;
  background: linear-gradient(180deg, #F4F1EC, #E4E1DA);
  border: 1px solid rgba(0,0,0,0.35);
  border-top: none;
  z-index: 1;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 10px;
  transition: background 0.1s ease;
}
.white-key.pressed{
  background: linear-gradient(180deg, #FFE7B3, #F2B84B);
}
.key-label{
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  color: #33322E;
  pointer-events: none;
}
.key-label sub{ font-size: 8px; }

.black-key{
  width: 27px;
  height: 62%;
  background: linear-gradient(180deg, #2B2E38, #14161C);
  border: 1px solid #000;
  border-top: none;
  border-radius: 0 0 6px 6px;
  z-index: 2;
  box-shadow: 0 3px 6px rgba(0,0,0,0.4);
}
.black-key.pressed{
  background: linear-gradient(180deg, #7C83FD, #4A50C4);
}

.lab-hint{
  margin-top: 16px;
  font-size: 12.5px;
  color: var(--text-2);
  text-align: center;
  line-height: 1.6;
}
.lab-hint strong{ color: var(--text-1); font-family: var(--font-mono); }

/* ---------- Chord Lab ---------- */

.tab-row{
  display: flex;
  gap: 6px;
  margin: 18px 0 18px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  padding: 4px;
}
.tab-btn{
  flex: 1;
  padding: 9px 4px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-2);
  transition: background 0.2s ease, color 0.2s ease;
}
.tab-btn.active{ background: rgba(255,255,255,0.09); color: var(--text-1); }

.tab-panel{ display: none; }
.tab-panel.active{ display: block; animation: view-in 0.3s ease both; }

.chip-row{
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 10px;
  -webkit-overflow-scrolling: touch;
}
.chip-row::-webkit-scrollbar{ display: none; }
.chip{
  flex-shrink: 0;
  padding: 8px 15px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}
.chip.active{
  background: rgba(242,184,75,0.16);
  border-color: rgba(242,184,75,0.5);
  color: var(--major);
}

.chord-card{
  border-radius: var(--radius-lg);
  padding: 20px 20px 18px;
  margin-top: 4px;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}
.chord-card[data-quality="major"]{ border-color: rgba(242,184,75,0.45); box-shadow: 0 0 30px -14px var(--major-glow); }
.chord-card[data-quality="minor"]{ border-color: rgba(124,131,253,0.45); box-shadow: 0 0 30px -14px var(--minor-glow); }
.chord-card[data-quality="tension"]{ border-color: rgba(255,107,92,0.45); box-shadow: 0 0 30px -14px var(--tension-glow); }

.chord-card-top{
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.chord-name{ font-family: var(--font-display); font-weight: 700; font-size: 19px; }
.play-btn{
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--glass-border);
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-1);
}
.play-btn:active{ transform: scale(0.96); }
.wide-btn{ width: 100%; margin-top: 14px; padding: 12px 0; }

.chord-notes{
  font-family: var(--font-mono);
  font-size: 13.5px;
  color: var(--text-2);
  margin-bottom: 14px;
}

.mini-keyboard{
  position: relative;
  height: 78px;
  margin: 4px auto 14px;
}
.mini-key{ position: absolute; top: 0; border-radius: 0 0 5px 5px; }
.mini-key.white{ width: 28px; height: 100%; background: #3A3E4B; border: 1px solid rgba(0,0,0,0.4); z-index: 1; }
.mini-key.black{ width: 17px; height: 60%; background: #14161C; border: 1px solid #000; z-index: 2; }
.mini-key.on[data-quality="major"]{ background: var(--major); }
.mini-key.on[data-quality="minor"]{ background: var(--minor); }
.mini-key.on[data-quality="tension"]{ background: var(--tension); }

.mood-tag{
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-1);
  background: rgba(255,255,255,0.07);
  padding: 5px 12px;
  border-radius: 999px;
  margin-bottom: 10px;
}
.chord-desc{ margin: 0; font-size: 13px; line-height: 1.6; color: var(--text-2); }

.compare-grid{
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.compare-grid .chord-card{ padding: 16px 14px; }
.compare-grid .chord-name{ font-size: 15px; }

.progression-slots{
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}
.prog-slot{
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}
.prog-index{
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-3);
  flex-shrink: 0;
}
.prog-slot select{
  flex: 1;
  min-width: 0;
  background: rgba(255,255,255,0.06);
  color: var(--text-1);
  border: none;
  border-radius: 8px;
  padding: 6px 4px;
  font-family: var(--font-mono);
  font-size: 12.5px;
}
.progression-actions{
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}
.progression-actions .play-btn{ flex: 1; }

.roman-row{ display: flex; gap: 8px; margin-bottom: 10px; }
.roman{
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 14px;
  color: var(--major);
  background: rgba(242,184,75,0.12);
  border: 1px solid rgba(242,184,75,0.3);
  border-radius: 8px;
  padding: 4px 10px;
}

/* ---------- Melody Lab ---------- */

.melody-slots{
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 16px 0;
}
.melody-slot{
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 4px 12px;
  border-radius: var(--radius-sm);
  background: var(--glass);
  border: 1px solid var(--glass-border);
  transition: border-color 0.2s ease, background 0.2s ease;
}
.melody-slot.armed{ border-color: rgba(242,184,75,0.55); background: rgba(242,184,75,0.08); }
.melody-slot.filled .slot-note{ color: var(--text-1); }
.slot-roman{ font-family: var(--font-mono); font-weight: 700; font-size: 13px; color: var(--major); }
.slot-chord{ font-size: 10px; color: var(--text-2); text-align: center; line-height: 1.3; }
.slot-note{ font-family: var(--font-mono); font-size: 12px; color: var(--text-3); margin-top: 2px; }

.mini-keyboard-wrap{
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-md);
  background: var(--bg-soft);
  padding: 12px 8px 14px;
  border: 1px solid var(--glass-border);
  margin-bottom: 16px;
}
.mini-keyboard-lg{ position: relative; height: 150px; touch-action: none; }

.white-key.small{ width: 38px; }
.black-key.small{ width: 24px; }
.mini-keyboard-lg .key-label{ font-size: 10px; }

.role-legend{ display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.role-chip{
  font-size: 11px;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.06);
}
.role-chip[data-role="chord"]{ color: var(--major); border: 1px solid rgba(242,184,75,0.35); }
.role-chip[data-role="passing"]{ color: var(--minor); border: 1px solid rgba(124,131,253,0.35); }
.role-chip[data-role="tension"]{ color: var(--tension); border: 1px solid rgba(255,107,92,0.35); }

/* ---------- Ear Training ---------- */

.ear-score{
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  color: var(--text-2);
  text-align: center;
  margin-bottom: 14px;
}

.ear-options{
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 16px 0;
}
.ear-option{
  padding: 14px 8px;
  border-radius: var(--radius-sm);
  background: var(--glass);
  border: 1px solid var(--glass-border);
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 13.5px;
  color: var(--text-1);
  text-align: center;
  transition: transform 0.1s ease, border-color 0.2s ease, background 0.2s ease;
}
.ear-option:active{ transform: scale(0.96); }
.ear-option.correct{
  background: rgba(242,184,75,0.16);
  border-color: rgba(242,184,75,0.6);
  color: var(--major);
}
.ear-option.wrong{
  background: rgba(255,107,92,0.14);
  border-color: rgba(255,107,92,0.55);
  color: var(--tension);
}

/* ---------- placeholder views ---------- */

.placeholder{
  margin-top: 40px;
  border-radius: var(--radius-lg);
  padding: 40px 26px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.placeholder-icon{ font-size: 34px; margin-bottom: 6px; }
.placeholder h3{ font-size: 18px; }
.placeholder p{ margin: 0; color: var(--text-2); font-size: 13.5px; }
.phase-tag{
  margin-top: 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-3);
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
}

.profile-stats{
  display: flex;
  gap: 22px;
  margin-top: 18px;
}
.pstat{ display: flex; flex-direction: column; align-items: center; }
.pstat span{ font-family: var(--font-mono); font-weight: 700; font-size: 20px; color: var(--text-1); }
.pstat small{ font-size: 10.5px; color: var(--text-2); margin-top: 2px; }

/* ==========================================================================
   Bottom nav
   ========================================================================== */

.bottom-nav{
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  padding: 10px 10px calc(env(safe-area-inset-bottom, 0px) + 10px);
  background: rgba(11,14,23,0.72);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--glass-border);
  z-index: 10;
}

.nav-btn{
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 0;
  border-radius: var(--radius-sm);
  color: var(--text-3);
  transition: color 0.2s ease;
}
.nav-icon{ font-size: 19px; opacity: 0.7; transition: opacity 0.2s ease, transform 0.2s ease; }
.nav-label{ font-size: 10.5px; font-weight: 600; }

.nav-btn.active{ color: var(--text-1); }
.nav-btn.active .nav-icon{ opacity: 1; transform: translateY(-1px); }

/* focus visibility */
button:focus-visible, .mission-check:focus-visible{
  outline: 2px solid var(--minor);
  outline-offset: 2px;
}
