/* ============================================================
   RESET Y VARIABLES
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin:0; padding:0; height:100%; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow: hidden;
}

:root {
  --bg: #0e1420;
  --bg-alt: #141b2b;
  --card: #1b2436;
  --card-border: #2a3550;
  --text: #eef1f8;
  --text-dim: #a7b0c5;
  --accent-green: #4fd1a5;
  --accent-blue: #4f9eff;
  --accent-gold: #f0c356;
  --accent-red: #ff6b6b;
  --white-key: #f7f7fa;
  --white-key-border: #333;
  --black-key: #16181f;
  --key-highlight: #4fd1a5;
  --key-highlight-2: #f0c356;
  --key-press: #4f9eff;
  --shadow: 0 4px 14px rgba(0,0,0,0.35);
}
:root[data-theme="light"] {
  --bg: #f3f5fa;
  --bg-alt: #e8ecf5;
  --card: #ffffff;
  --card-border: #dbe1ee;
  --text: #1c2333;
  --text-dim: #5b6478;
  --accent-green: #1f9d75;
  --accent-blue: #2f6fd6;
  --accent-gold: #b8860b;
  --accent-red: #d1495b;
  --white-key: #ffffff;
  --white-key-border: #9aa3b5;
  --black-key: #23283a;
  --key-highlight: #1f9d75;
  --key-highlight-2: #b8860b;
  --key-press: #2f6fd6;
  --shadow: 0 4px 14px rgba(30,40,70,0.12);
}

body {
  background: var(--bg);
  color: var(--text);
}

/* ============================================================
   LAYOUT GENERAL
   ============================================================ */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

#appHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--card-border);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.header-left { display:flex; align-items:center; gap:10px; }
.header-left .logo { font-size: 1.6rem; }
.header-left h1 { font-size: 1.05rem; margin:0; font-weight:700; letter-spacing:.3px; }
.header-left .subtitle { font-size: .75rem; color: var(--text-dim); border-left:1px solid var(--card-border); padding-left:10px; }
.header-right { display:flex; align-items:center; gap:10px; }

.overall-progress { display:flex; align-items:center; gap:8px; min-width:140px; }
.progress-track {
  width: 120px; height: 10px; border-radius: 6px;
  background: var(--card-border); overflow:hidden;
}
.progress-fill {
  height:100%; width:0%;
  background: linear-gradient(90deg, var(--accent-green), var(--accent-blue));
  transition: width .4s ease;
}
#overallProgressLabel { font-size:.75rem; color:var(--text-dim); min-width:34px; }

.icon-btn {
  background: var(--card);
  border: 1px solid var(--card-border);
  color: var(--text);
  font-size: 1.1rem;
  width: 40px; height:40px;
  border-radius: 10px;
  cursor: pointer;
  display:flex; align-items:center; justify-content:center;
  transition: transform .15s ease, background .15s ease;
}
.icon-btn:hover { transform: translateY(-1px); background: var(--card-border); }
.icon-btn:active { transform: translateY(0); }

#appBody {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* NAV */
#moduleNav {
  width: 250px;
  flex-shrink: 0;
  background: var(--bg-alt);
  border-right: 1px solid var(--card-border);
  overflow-y: auto;
  padding: 10px;
  display:flex;
  flex-direction:column;
  gap:6px;
}
.nav-btn {
  display:flex; align-items:center; gap:10px;
  text-align:left;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  padding: 10px 10px;
  border-radius: 10px;
  cursor: pointer;
  font-size: .85rem;
  line-height:1.25;
}
.nav-btn:hover { background: var(--card); }
.nav-btn.active { background: var(--card); border-color: var(--accent-blue); }
.nav-btn .nav-num {
  flex-shrink:0;
  width:24px; height:24px; border-radius:50%;
  background: var(--card-border);
  display:flex; align-items:center; justify-content:center;
  font-size:.7rem; font-weight:700;
}
.nav-btn.completed .nav-num { background: var(--accent-green); color:#04231a; }
.nav-btn .nav-check { margin-left:auto; color: var(--accent-green); font-weight:700; }

/* MAIN CONTENT */
#moduleContent {
  flex: 1;
  overflow-y: auto;
  padding: 18px 22px 30px;
}

.module-progress-chip {
  display:inline-block;
  font-size:.72rem;
  color: var(--text-dim);
  background: var(--card);
  border:1px solid var(--card-border);
  padding: 4px 10px;
  border-radius: 20px;
  margin-bottom: 8px;
}
.module-panel h2 { margin: 4px 0 14px; font-size:1.4rem; }

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 8px; font-size: .95rem; display:flex; align-items:center; gap:8px; }
.card p { margin: 4px 0; line-height:1.55; font-size:.9rem; color: var(--text); }
.card ul { margin:6px 0; padding-left:20px; font-size:.9rem; line-height:1.6; }
.card.common-error { border-color: var(--accent-red); }
.card.common-error h3 { color: var(--accent-red); }

.module-complete-bar {
  display:flex; align-items:center; gap:12px; flex-wrap:wrap;
  padding: 10px 0 40px;
}

button {
  font-family: inherit;
}
.btn {
  background: var(--card);
  border: 1px solid var(--card-border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform .12s ease, background .12s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.primary { background: linear-gradient(135deg, var(--accent-green), var(--accent-blue)); color:#04101f; border:none; }
.btn.gold { background: var(--accent-gold); color:#241a02; border:none; }
.btn.danger { background: var(--accent-red); color:#2a0505; border:none; }
.btn:disabled { opacity:.45; cursor:not-allowed; transform:none; }
.btn.small { padding:6px 10px; font-size:.75rem; }

#completeModuleBtn.done { background: var(--accent-green); color:#04231a; }

/* EXERCISE / STEP ENGINE */
.step-exercise { display:flex; flex-direction:column; gap:8px; }
.step-info { font-size: .8rem; color: var(--text-dim); font-weight:600; }
.step-instruction { font-size: 1rem; font-weight:700; }
.step-feedback { min-height: 22px; font-size: .85rem; font-weight:600; }
.step-feedback.ok { color: var(--accent-green); }
.step-feedback.bad { color: var(--accent-red); }
.step-feedback.partial { color: var(--accent-gold); }
.step-buttons { display:flex; gap:8px; flex-wrap:wrap; }

.pattern-block {
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 10px;
  background: var(--bg-alt);
}
.pattern-block .pattern-title { font-weight:700; font-size:.85rem; margin-bottom:4px; }
.pattern-block .pattern-notes { font-size:.85rem; color: var(--text-dim); margin-bottom:8px; }
.pattern-block .pattern-btns { display:flex; gap:8px; flex-wrap:wrap; }

/* MCQ */
.mcq-q { font-weight:700; margin-bottom:10px; font-size:.95rem; }
.mcq-opts { display:flex; flex-direction:column; gap:8px; }
.mcq-opt {
  text-align:left; padding:10px 12px; border-radius:10px;
  border:1px solid var(--card-border); background: var(--bg-alt); color:var(--text);
  cursor:pointer; font-size:.85rem;
}
.mcq-opt.correct { background: var(--accent-green); color:#04231a; border-color: var(--accent-green); }
.mcq-opt.wrong { background: var(--accent-red); color:#2a0505; border-color: var(--accent-red); }
.mcq-progress { font-size:.75rem; color:var(--text-dim); margin-bottom:6px; }
.mcq-summary { font-size:.95rem; font-weight:700; }

/* Staff (pentagrama) */
.staff-wrap { display:flex; align-items:center; gap:18px; flex-wrap:wrap; }
.staff {
  position: relative;
  width: 220px;
  height: 130px;
  margin: 10px 6px;
}
.staff .line {
  position:absolute; left:0; right:0; height:2px; background: var(--text-dim);
}
.staff .clef { position:absolute; left:-4px; top:-18px; font-size:3.6rem; color: var(--text); line-height:1; }
.staff-note {
  position:absolute; width:18px; height:14px; border-radius:50%;
  background: var(--accent-blue); left: 110px; transform: translate(-50%,-50%) rotate(-18deg);
  cursor:pointer; border:2px solid var(--bg);
}
.staff-note.active { background: var(--accent-gold); }
.staff-ledger {
  position:absolute; width:34px; height:2px; background: var(--text-dim);
  left: 93px;
}
.staff-note-label { position:absolute; left:170px; font-size:.75rem; color:var(--text-dim); transform: translateY(-50%); }

/* Metronome */
.metronome { display:flex; flex-direction:column; gap:10px; }
.metro-dots { display:flex; gap:8px; }
.metro-dot { width:18px; height:18px; border-radius:50%; background: var(--card-border); }
.metro-dot.on { background: var(--accent-gold); }
.metro-controls { display:flex; align-items:center; gap:10px; flex-wrap:wrap; }
.metro-controls input[type=range] { width:180px; }

/* Timer */
.timer-box { display:flex; flex-direction:column; gap:8px; }
.timer-display { font-size: 2rem; font-weight:800; letter-spacing:1px; }
.timer-controls { display:flex; gap:8px; flex-wrap:wrap; }

/* Ordering quiz */
.order-pool { display:flex; gap:8px; flex-wrap:wrap; margin-bottom:10px; }
.order-chip {
  padding:8px 14px; border-radius:10px; border:1px solid var(--card-border);
  background: var(--bg-alt); cursor:pointer; font-weight:700; font-size:.85rem;
}
.order-chip.used { opacity:.35; cursor:default; }
.order-selected { display:flex; gap:8px; flex-wrap:wrap; min-height:40px; padding:8px; border:1px dashed var(--card-border); border-radius:10px; margin-bottom:10px;}
.order-selected .order-chip { cursor:default; opacity:1; background: var(--accent-blue); color:#04101f; }

/* Daily routine */
.phase-list { display:flex; flex-direction:column; gap:14px; }
.phase-card { border:1px solid var(--card-border); border-radius:12px; padding:12px; background: var(--bg-alt); }
.phase-card h4 { margin:0 0 6px; font-size:.9rem; }
.phase-check { display:flex; align-items:center; gap:8px; margin-top:8px; font-size:.85rem; }
.streak-box { display:flex; gap:14px; align-items:center; flex-wrap:wrap; margin-top:10px; }
.streak-badge { background: var(--accent-gold); color:#241a02; font-weight:800; padding:6px 14px; border-radius:20px; font-size:.85rem; }

/* Final eval */
.eval-progress { font-size:.8rem; color:var(--text-dim); margin-bottom:8px; }
.eval-score { font-size:2rem; font-weight:800; }
.eval-tier { font-size:.95rem; margin:8px 0; }
.eval-recommend { font-size:.85rem; }

/* PIANO DOCK */
#pianoDock {
  flex-shrink:0;
  background: var(--bg-alt);
  border-top: 1px solid var(--card-border);
  display:flex; flex-direction:column;
}
#pianoHeader {
  display:flex; align-items:center; justify-content:space-between;
  padding: 6px 14px;
  font-size:.85rem;
  color: var(--text-dim);
}
#pianoHeader #noteDisplay { font-weight:700; color: var(--text); }
#pianoKeyboardWrap {
  padding: 0 10px 10px;
  overflow-x: auto;
}
#pianoKeyboard {
  position: relative;
  height: 150px;
  display:flex;
  min-width: 640px;
  user-select:none;
}
.white-key {
  position:relative;
  flex: 1;
  background: var(--white-key);
  border: 1px solid var(--white-key-border);
  border-radius: 0 0 6px 6px;
  display:flex; align-items:flex-end; justify-content:center;
  padding-bottom:6px;
  font-size:.65rem;
  color:#555;
  cursor:pointer;
  transition: background .08s ease;
}
.white-key.pressed, .white-key.highlight { background: var(--key-highlight); color:#04231a; }
.white-key.highlight2 { background: var(--key-highlight-2); color:#241a02; }
.white-key.press-anim { background: var(--key-press) !important; }
.black-key {
  position:absolute;
  top:0;
  height: 62%;
  background: var(--black-key);
  border-radius: 0 0 5px 5px;
  z-index: 2;
  cursor:pointer;
  transition: background .08s ease;
}
.black-key.pressed, .black-key.highlight { background: var(--key-highlight); }
.black-key.highlight2 { background: var(--key-highlight-2); }
.black-key.press-anim { background: var(--key-press) !important; }
.finger-badge {
  position:absolute; top:6px; left:50%; transform:translateX(-50%);
  background: var(--accent-blue); color:#04101f;
  font-size:.65rem; font-weight:800;
  width:16px; height:16px; border-radius:50%;
  display:flex; align-items:center; justify-content:center;
  pointer-events:none;
}
#pianoCollapseBtn { background:none; border:none; color:var(--text-dim); font-size:1rem; cursor:pointer; }
#pianoDock.collapsed #pianoKeyboardWrap { display:none; }

/* RESPONSIVE */
@media (max-width: 880px) {
  #appBody { flex-direction: column; }
  #moduleNav {
    width:100%; flex-direction:row; overflow-x:auto; overflow-y:hidden;
    border-right:none; border-bottom:1px solid var(--card-border);
    white-space:nowrap;
  }
  .nav-btn { flex-shrink:0; }
  #pianoKeyboard { height:130px; }
  .header-left .subtitle { display:none; }
}
@media (max-width: 560px) {
  .overall-progress { min-width: 90px; }
  .progress-track { width:70px; }
  #pianoKeyboard { height:110px; }
}

/* ============================================================
   RESPONSIVE ADICIONAL — telefonos pequenos, tablets, notch iPhone
   ============================================================ */

/* Altura real de viewport en móviles (evita recorte por la barra
   de direcciones de Safari/Chrome, que 100vh no contempla). */
#app { height: 100vh; height: 100dvh; }

/* Área segura para notch / home indicator en iPhone. */
#appHeader { padding-top: max(10px, env(safe-area-inset-top)); }
#appHeader { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
#pianoDock { padding-bottom: env(safe-area-inset-bottom); }

/* Evita zoom accidental de iOS en inputs/range y mejora respuesta táctil. */
input[type=range] { touch-action: none; }
.btn, .icon-btn, .white-key, .black-key, .nav-btn, .mcq-opt, .order-chip, .staff-note {
  touch-action: manipulation;
}

@media (max-width: 700px) {
  #appHeader { padding: 8px 12px; gap: 8px; }
  .header-left h1 { font-size: .95rem; }
  .header-left .logo { font-size: 1.35rem; }
  .overall-progress { min-width: auto; }
  .progress-track { width: 60px; }
  #moduleContent { padding: 14px 14px 24px; }
  .module-panel h2 { font-size: 1.2rem; }
}

@media (max-width: 420px) {
  .header-left .logo { font-size: 1.15rem; }
  .header-left h1 { font-size: .82rem; }
  .icon-btn { width: 34px; height: 34px; font-size: .95rem; }
  .progress-track { display:none; }
  #overallProgressLabel { min-width:auto; }
  .card { padding: 12px 12px; }
  .metro-controls input[type=range] { width: 130px; }
}

/* Tablets en modo retrato/paisaje: aprovechar mejor el ancho */
@media (min-width: 700px) and (max-width: 1024px) {
  #moduleNav { width: 210px; }
  #moduleContent { padding: 18px 24px 32px; }
}

::-webkit-scrollbar { width:10px; height:10px; }
::-webkit-scrollbar-thumb { background: var(--card-border); border-radius:6px; }
