/* FILE: styles.css */

:root{
  --bg:#0f1115;
  --panel:#171b22;
  --panel-2:#1d2330;
  --accent:#4da3ff;
  --accent-2:#ffd166;
  --success:#48bb78;
  --danger:#f56565;
  --text:#e6e6e6;
  --muted:#aab4c3;
  --border:#2a2f3a;
  --radius:14px;
  --shadow:0 10px 30px rgba(0,0,0,.28);
  --bottom-bar-h:78px;
}

*{
  box-sizing:border-box;
}

html{
  -webkit-text-size-adjust:100%;
}

body{
  margin:0;
  font-family:system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial,sans-serif;
  background:linear-gradient(180deg,#0d1015 0%, #121722 100%);
  color:var(--text);
}

button,
select,
input{
  font:inherit;
}

button{
  cursor:pointer;
}

.header{
  padding:14px 14px 10px;
  border-bottom:1px solid var(--border);
  background:rgba(12,15,20,.92);
  backdrop-filter:blur(10px);
  position:sticky;
  top:0;
  z-index:20;
}

.topbar{
  max-width:980px;
  margin:0 auto;
  display:flex;
  gap:12px;
  align-items:flex-start;
  justify-content:space-between;
}

.brand-block{
  min-width:0;
}

.header h1{
  margin:0;
  font-size:1.45rem;
  line-height:1.1;
}

.subtitle{
  margin:4px 0 0;
  color:var(--muted);
  font-size:.92rem;
  line-height:1.35;
}

.topbar-status{
  display:flex;
  gap:8px;
  flex-shrink:0;
}

.status-pill{
  min-width:70px;
  padding:8px 10px;
  border:1px solid var(--border);
  border-radius:12px;
  background:var(--panel);
  text-align:center;
  box-shadow:var(--shadow);
}

.status-label{
  display:block;
  font-size:.7rem;
  color:var(--muted);
  text-transform:uppercase;
  letter-spacing:.06em;
}

.container{
  max-width:980px;
  margin:0 auto;
  padding:12px 12px calc(var(--bottom-bar-h) + 26px);
  display:flex;
  flex-direction:column;
  gap:12px;
}

.lesson-card,
.feedback-strip,
.mini-panel,
.game-panel,
.game-piano-section{
  background:var(--panel);
  border:1px solid var(--border);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
}

.lesson-card,
.feedback-strip,
.mini-panel,
.game-panel,
.game-piano-section{
  padding:14px;
}

.lesson-card-head,
.panel-head,
.feedback-strip-head{
  display:flex;
  gap:10px;
  align-items:flex-start;
  justify-content:space-between;
}

.eyebrow{
  margin:0 0 4px;
  color:var(--accent-2);
  text-transform:uppercase;
  letter-spacing:.08em;
  font-size:.72rem;
  font-weight:700;
}

.lesson-card h2,
.panel-head h2,
.feedback-strip h2{
  margin:0;
  font-size:1.02rem;
}

.panel-subtext,
.mini-hint{
  margin:4px 0 0;
  color:var(--muted);
  font-size:.84rem;
  line-height:1.35;
}

.ghost-button,
.secondary-action{
  background:#11141a;
  color:var(--text);
  border:1px solid var(--border);
}

.lesson-stats-grid{
  display:grid;
  grid-template-columns:repeat(3,1fr);
  gap:10px;
  margin-top:12px;
}

.lesson-stat-card{
  padding:10px 12px;
  border:1px solid var(--border);
  border-radius:12px;
  background:linear-gradient(180deg,rgba(255,255,255,.03),rgba(255,255,255,.01));
  box-shadow:var(--shadow);
}

.lesson-stat-label{
  display:block;
  font-size:.72rem;
  color:var(--muted);
  text-transform:uppercase;
  letter-spacing:.06em;
  margin-bottom:4px;
}

.lesson-stat-card strong{
  display:block;
  font-size:1rem;
  color:var(--text);
}

.is-collapsed{
  display:none;
}

.challenge-subnote{
  margin-top:10px;
  font-size:.84rem;
  color:var(--muted);
  line-height:1.4;
}

.controls.is-locked{
  opacity:.72;
}

.controls.is-locked select{
  background:#0d1117;
  color:#7f8a98;
  border-color:#202631;
}

.controls.is-locked label{
  color:#8893a2;
}

.lesson-progress-wrap{
  margin-top:12px;
}

.lesson-progress-meta{
  display:flex;
  justify-content:space-between;
  gap:10px;
  font-size:.84rem;
  color:var(--muted);
  margin-bottom:8px;
}

.lesson-progress-bar{
  width:100%;
  height:10px;
  background:#0f1319;
  border:1px solid var(--border);
  border-radius:999px;
  overflow:hidden;
}

.lesson-progress-fill{
  width:0%;
  height:100%;
  background:linear-gradient(90deg,var(--accent),#6cb8ff);
  border-radius:999px;
  transition:width .2s ease;
}

.controls{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:10px;
  margin-top:12px;
}

#lessonMastery{
  color:var(--accent-2);
}

#lessonAccuracy,
#lessonRounds,
#lessonMastery{
  word-break:break-word;
}

.controls{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:10px;
  margin-top:12px;
}

.control-group{
  display:flex;
  flex-direction:column;
  gap:6px;
}

.control-group label{
  font-size:.82rem;
  color:var(--muted);
}

select,
button,
input{
  min-height:46px;
  padding:10px 12px;
  border-radius:10px;
  border:1px solid var(--border);
  background:#11141a;
  color:var(--text);
}

button{
  background:var(--accent);
  color:#07111f;
  border:none;
  font-weight:700;
}

button:hover{
  filter:brightness(1.04);
}

.challenge-card{
  margin-top:12px;
  padding:12px;
  border-radius:12px;
  border:1px solid #33465f;
  background:linear-gradient(180deg,rgba(77,163,255,.12),rgba(77,163,255,.05));
  line-height:1.45;
}

.challenge-card strong,
#persistentFeedback strong,
.builder-feedback strong,
.quiz-feedback strong{
  color:#ffffff;
}

.feedback-strip.success-state,
.challenge-card.success-state,
.builder-feedback.correct,
.quiz-feedback.correct{
  border-color:#2f855a;
  background:rgba(72,187,120,.12);
  animation:panelPop .28s ease;
}

.builder-feedback.wrong,
.quiz-feedback.wrong{
  border-color:#c53030;
  background:rgba(245,101,101,.12);
  animation:panelPop .22s ease;
}

@keyframes successPulse{
  0%{ transform:scale(1); }
  50%{ transform:scale(1.02); }
  100%{ transform:scale(1); }
}

@keyframes wrongShake{
  0%{ transform:translateX(0); }
  25%{ transform:translateX(-2px); }
  50%{ transform:translateX(2px); }
  75%{ transform:translateX(-1px); }
  100%{ transform:translateX(0); }
}

@keyframes badgePulse{
  0%{ transform:scale(.98); opacity:.9; }
  100%{ transform:scale(1); opacity:1; }
}

@keyframes panelPop{
  0%{ transform:translateY(2px); opacity:.88; }
  100%{ transform:translateY(0); opacity:1; }
}

.bottom-action-bar{
  position:fixed;
  left:0;
  right:0;
  bottom:0;
  z-index:30;
  display:grid;
  grid-template-columns:1.2fr 1fr 1fr .9fr;
  gap:8px;
  padding:10px 12px calc(10px + env(safe-area-inset-bottom));
  background:rgba(12,15,20,.96);
  border-top:1px solid var(--border);
  backdrop-filter:blur(12px);
}

.mobile-only-action{
  display:none;
}

#primaryAction{
  background:linear-gradient(180deg,#71bbff 0%, #4da3ff 100%);
  color:#07111f;
}

#secondaryAction,
.mobile-only-action,
.secondary-action{
  background:#11141a;
  color:var(--text);
  border:1px solid var(--border);
}

.bottom-action-bar button{
  min-height:50px;
  padding:10px 8px;
}

/* Piano layout */
.piano-scroll-shell{
  margin-top:10px;
  overflow-x:auto;
  overflow-y:hidden;
  -webkit-overflow-scrolling:touch;
  padding-bottom:2px;
}

.piano{
  min-height:230px;
  height:230px;
  min-width:740px;
  position:relative;
}

.pianoKey{
  position:absolute;
  border:none;
  margin:0;
  padding:0;
  cursor:pointer;
  transition:transform .08s ease, box-shadow .12s ease, opacity .12s ease, filter .12s ease;
  touch-action:manipulation;
}

.pianoKey:focus-visible{
  outline:2px solid var(--accent);
  outline-offset:2px;
}

.pianoKey:active{
  transform:translateY(1px);
}

/* Base key shapes and stacking */
.pianoKey.white{
  background:linear-gradient(to bottom,#ffffff 0%,#eef2f6 100%);
  border:1px solid #9aa3b2;
  border-radius:0 0 10px 10px;
  z-index:1;
}

.pianoKey.black{
  background:linear-gradient(to bottom,#3a4351 0%,#0d1117 100%);
  border:1px solid #050608;
  border-radius:0 0 8px 8px;
  z-index:3;
}

/* Layered piano state system */
.pianoKey.inScale{
  box-shadow:inset 0 -4px 0 rgba(77,163,255,.14);
}

.pianoKey.targetKey,
.pianoKey.questionNote{
  box-shadow:0 0 0 2px rgba(77,163,255,.72);
  z-index:4;
}

.pianoKey.multiTarget{
  box-shadow:0 0 0 2px rgba(77,163,255,.45);
  z-index:4;
}

.pianoKey.completedKey{
  box-shadow:inset 0 -7px 0 rgba(255,209,102,.36), 0 0 0 1px rgba(255,209,102,.42);
  z-index:4;
}

.pianoKey.selectedCorrect{
  box-shadow:0 0 0 2px rgba(72,187,120,.82), inset 0 -7px 0 rgba(72,187,120,.14) !important;
  z-index:5;
  animation:successPulse .32s ease;
}

.pianoKey.selectedWrong{
  box-shadow:0 0 0 2px rgba(245,101,101,.82), inset 0 -7px 0 rgba(245,101,101,.12) !important;
  z-index:5;
  animation:wrongShake .22s ease;
}

.pianoKey.black.completedKey{
  background:linear-gradient(to bottom,#3a4351 0%,#0d1117 100%);
  box-shadow:inset 0 -7px 0 rgba(255,209,102,.36), 0 0 0 1px rgba(255,209,102,.42);
  z-index:4;
}

/* Never recolor keys fully for state changes */
.pianoKey.white.targetKey,
.pianoKey.white.questionNote,
.pianoKey.white.multiTarget,
.pianoKey.white.selectedCorrect,
.pianoKey.white.selectedWrong,
.pianoKey.white.completedKey,
.pianoKey.white.inScale{
  background:linear-gradient(to bottom,#ffffff 0%,#eef2f6 100%);
}

.pianoKey.black.targetKey,
.pianoKey.black.questionNote,
.pianoKey.black.multiTarget,
.pianoKey.black.selectedCorrect,
.pianoKey.black.selectedWrong,
.pianoKey.black.completedKey,
.pianoKey.black.inScale{
  background:linear-gradient(to bottom,#3a4351 0%,#0d1117 100%);
}

/* State priority helpers */
.pianoKey.black.targetKey,
.pianoKey.black.questionNote,
.pianoKey.black.multiTarget,
.pianoKey.black.completedKey{
  z-index:4;
}

.pianoKey.black.selectedCorrect,
.pianoKey.black.selectedWrong{
  z-index:5;
}

.pianoKey.white.targetKey,
.pianoKey.white.questionNote,
.pianoKey.white.multiTarget,
.pianoKey.white.completedKey{
  z-index:2;
}

.pianoKey.white.selectedCorrect,
.pianoKey.white.selectedWrong{
  z-index:2;
}

/* Modal system */
.modal-overlay{
  position:fixed;
  inset:0;
  z-index:60;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:18px;
  background:rgba(4,8,14,.72);
  backdrop-filter:blur(6px);
}

.modal-overlay.is-hidden,
.game-modal.is-hidden{
  display:none;
}

.game-modal{
  width:min(100%, 420px);
  background:linear-gradient(180deg,#1a2029 0%, #141922 100%);
  border:1px solid var(--border);
  border-radius:18px;
  box-shadow:0 24px 60px rgba(0,0,0,.42);
  padding:18px 16px 14px;
  animation:modalPop .2s ease;
}

.feedback-modal{
  border-color:#3d556f;
}

.progress-modal{
  border-color:#2f855a;
}

.game-modal-head h2{
  margin:0;
  font-size:1.15rem;
}

.game-modal-body{
  margin-top:12px;
  line-height:1.55;
  color:var(--text);
}

.game-modal-tap-hint{
  margin-top:14px;
  font-size:.82rem;
  color:var(--muted);
  text-align:center;
}

@keyframes modalPop{
  0%{ transform:translateY(8px) scale(.98); opacity:.86; }
  100%{ transform:translateY(0) scale(1); opacity:1; }
}

.footer{
  text-align:center;
  padding:8px 12px 12px;
  opacity:.6;
  font-size:.8rem;
}

@media (min-width:700px){
  .container{
    padding:16px 16px calc(var(--bottom-bar-h) + 32px);
  }

  .lesson-card,
  .feedback-strip,
  .mini-panel,
  .game-panel,
  .game-piano-section{
    padding:16px;
  }

  .controls{
    grid-template-columns:repeat(2,minmax(160px,220px));
  }
}

@media (max-width:600px){
  .modal-overlay{
    padding:14px;
  }

  .game-modal{
    width:100%;
    max-width:100%;
    padding:16px 14px 12px;
    border-radius:16px;
  }

  .game-modal-head h2{
    font-size:1.02rem;
  }

  .game-modal-body{
    font-size:.96rem;
  }

  .game-modal-tap-hint{
    font-size:.78rem;
  }
  .header{
    padding:12px 12px 10px;
  }

  .topbar{
    flex-direction:column;
    align-items:stretch;
  }

  .topbar-status{
    justify-content:flex-start;
  }

  .container{
    padding:10px 10px calc(var(--bottom-bar-h) + 26px);
    gap:10px;
  }

  .lesson-stats-grid{
    grid-template-columns:1fr;
  }

  .controls{
    grid-template-columns:1fr;
  }

  .lesson-progress-meta,
  .lesson-card-head,
  .feedback-strip-head,
  .panel-head{
    flex-direction:column;
    align-items:flex-start;
  }

  .feedback-strip{
    bottom:calc(var(--bottom-bar-h) + 8px);
  }

  .piano{
    min-height:190px;
    height:190px;
    min-width:620px;
  }

  .quiz-scale{
    font-size:.95rem;
    letter-spacing:.1em;
  }

  .bottom-action-bar{
    grid-template-columns:1fr 1fr;
  }

  .mobile-only-action{
    display:block;
  }
}
