:root {
  --bg: #f7f3ec;
  --surface: #ffffff;
  --surface-2: #f0ebe2;
  --border: #e4ddd1;
  --text: #221d16;
  --muted: #776e62;
  --accent: #c9681a;
  --accent-ink: #ffffff;
  --accent-soft: #f6e3cf;
  --danger: #c0392b;
  --ok: #2e8b57;
  --heat-0: #ebe5da;
  --heat-1: #f3d2ad;
  --heat-2: #e9a867;
  --heat-3: #d77b2c;
  --heat-4: #a8520f;
  --c-tecnica: #d9772b;
  --c-ritmo: #3c8dbc;
  --c-repertorio: #8e5bc2;
  --c-improvisacion: #2e9e72;
  --c-teoria: #c2a13a;
  --c-oido: #c75b7a;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16130f;
    --surface: #211d17;
    --surface-2: #2b261f;
    --border: #363027;
    --text: #f1ebe1;
    --muted: #a59c8e;
    --accent: #f0a33a;
    --accent-ink: #1b1409;
    --accent-soft: #3a2c19;
    --danger: #ef6b5b;
    --ok: #5cc98d;
    --heat-0: #2a251e;
    --heat-1: #4d3718;
    --heat-2: #8a5a1c;
    --heat-3: #c77f25;
    --heat-4: #f5ad45;
    --c-tecnica: #f0a33a;
    --c-ritmo: #5fb0e0;
    --c-repertorio: #b58be0;
    --c-improvisacion: #5cc98d;
    --c-teoria: #e0c457;
    --c-oido: #e7839f;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}

a { color: var(--accent); text-decoration: none; }

h1, h2 { line-height: 1.2; margin: 0 0 .5rem; }
h2 { font-size: 1.02rem; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.grow { flex: 1; }

/* ---------- Estructura ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.1rem; color: var(--text); letter-spacing: -.01em; }
.pill {
  background: var(--accent); color: var(--accent-ink);
  padding: 6px 12px; border-radius: 999px; font-weight: 600; font-size: .9rem;
  font-variant-numeric: tabular-nums;
}

.view { max-width: 720px; margin: 0 auto; padding: 8px 16px 24px; }
.page-title { font-size: 1.6rem; letter-spacing: -.02em; margin: 8px 0 14px; }
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.nav a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--muted); font-size: .72rem; padding: 4px 0; border-radius: 10px;
}
.nav a.on { color: var(--accent); }
.nav svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Componentes ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin: 0 0 14px; box-shadow: var(--shadow);
}
.hero { text-align: center; padding: 40px 8px; }
.hero h1 { font-size: 2rem; letter-spacing: -.02em; }
.hero p { color: var(--muted); max-width: 30rem; margin: .5rem auto 1.4rem; }
.hero .row { justify-content: center; }

.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 10px 0; }
.row.end { justify-content: flex-end; }

.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font: inherit; font-weight: 600; font-size: .95rem;
  padding: 10px 16px; border-radius: 12px; cursor: pointer; min-height: 44px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: transform .05s, background .15s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { background: var(--danger); color: #fff; border-color: transparent; }
.btn.danger-outline { color: var(--danger); background: transparent; border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn.small { min-height: 38px; padding: 6px 12px; }
.btn.block { width: 100%; min-height: 52px; font-size: 1.05rem; }
.link { background: none; border: 0; color: var(--accent); font: inherit; cursor: pointer; padding: 6px 0; }
.link.danger { color: var(--danger); }

.chip {
  display: inline-block; font-size: .75rem; font-weight: 600; padding: 2px 9px; border-radius: 999px;
  color: var(--chip); background: color-mix(in srgb, var(--chip) 16%, transparent);
}

label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; font-weight: 600; margin: 10px 0; }
label.check { flex-direction: row; align-items: center; font-weight: 400; gap: 8px; }
.label { font-size: .9rem; font-weight: 600; display: block; margin-bottom: 4px; }
input, select, textarea {
  font: inherit; font-weight: 400; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; min-height: 44px; width: 100%;
}
input[type="checkbox"] { width: 20px; min-height: 20px; accent-color: var(--accent); }
input[type="range"] { padding: 0; border: 0; background: none; accent-color: var(--accent); }
textarea { resize: vertical; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.progress { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin: 8px 0 4px; }
.progress span { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.progress.thin { height: 5px; margin: 6px 0 0; }

.empty { color: var(--muted); font-size: .92rem; margin: 4px 0; }
.notice {
  background: var(--accent-soft); border-radius: 10px; padding: 10px 12px; margin: 8px 0 0;
  overflow-wrap: anywhere;
}
.scroll-x { overflow-x: auto; }

/* ---------- Progreso ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; display: flex; flex-direction: column; min-width: 0; box-shadow: var(--shadow);
}
.stat-label { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat-sub { font-size: .78rem; color: var(--muted); }

.highlights { list-style: none; padding: 0; margin: 0; }
.highlights li + li { border-top: 1px solid var(--border); }
.highlights a { display: flex; flex-direction: column; padding: 10px 0; color: var(--text); }
.up { color: var(--ok); font-style: normal; font-weight: 700; }

.legend { display: flex; align-items: center; gap: 4px; justify-content: flex-end; font-size: .75rem; color: var(--muted); margin-top: 6px; }
.legend i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }

.cat-bars { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.cat-bars li { display: grid; grid-template-columns: 7.5rem 1fr 4.5rem; align-items: center; gap: 8px; font-size: .88rem; }
.cat-track { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.cat-track span { display: block; height: 100%; border-radius: inherit; min-width: 2px; }
.cat-val { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- Gráficas ---------- */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.heatmap { max-width: 560px; }
.chart-label { font-size: 9px; fill: var(--muted); }
.axis, .grid { stroke: var(--border); stroke-width: 1; }
.grid { stroke-dasharray: 2 3; }
.bar { fill: color-mix(in srgb, var(--accent) 45%, var(--surface-2)); }
.bar-met { fill: var(--accent); }
.goal-line { stroke: var(--ok); stroke-width: 1.5; stroke-dasharray: 4 3; }
.goal-label { fill: var(--ok); }
.line { fill: none; stroke: var(--accent); stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.area { fill: color-mix(in srgb, var(--accent) 14%, transparent); }
.dot { fill: var(--surface); stroke: var(--accent); stroke-width: 2; }
.sparkline { width: 90px; height: 28px; }
.sparkline .line { stroke-width: 1.8; }
.heat-0 { fill: var(--heat-0); background: var(--heat-0); }
.heat-1 { fill: var(--heat-1); background: var(--heat-1); }
.heat-2 { fill: var(--heat-2); background: var(--heat-2); }
.heat-3 { fill: var(--heat-3); background: var(--heat-3); }
.heat-4 { fill: var(--heat-4); background: var(--heat-4); }

/* ---------- Práctica ---------- */
.session-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  background: var(--accent-soft); border-radius: var(--radius); padding: 12px 14px; margin: 8px 0 12px;
}
.session-bar > div:first-child { display: flex; flex-direction: column; }
.session-bar .row { margin: 0; }
.clock { font-variant-numeric: tabular-nums; font-weight: 700; }
.clock.big { font-size: 1.9rem; letter-spacing: -.02em; }

.picker { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 12px; scrollbar-width: none; }
.pick {
  flex: 0 0 auto; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-size: .9rem; padding: 8px 14px; border-radius: 999px; cursor: pointer; min-height: 40px;
  display: inline-flex; align-items: center; gap: 6px; max-width: 16rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pick.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.pick.add { color: var(--accent); border-style: dashed; }
.dot-sug { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); flex: none; }

.current-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.current-head h2 { font-size: 1.2rem; margin: 6px 0 2px; }
.current-head .clock { font-size: 1.4rem; }

.metronome { background: var(--surface-2); border-radius: 12px; padding: 12px; margin: 12px 0; }
.beats { display: flex; justify-content: center; gap: 10px; margin-bottom: 8px; }
.beat-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--border); transition: background .05s, transform .05s; }
.beat-dot.on { background: var(--accent); transform: scale(1.25); }
.beat-dot.accent.on { background: var(--ok); }
.metro-row { display: flex; align-items: center; justify-content: center; gap: 6px; flex-wrap: wrap; margin: 6px 0; }
.metro-row select { width: auto; }
.metro-bpm { min-width: 6.5rem; text-align: center; }
.metro-bpm output { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.log-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: end; }
.log-grid label { margin: 0; }
.quality { display: flex; gap: 6px; }
.q {
  flex: 1; min-height: 44px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
}
.q.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }

.recs { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 8px; }
.recs li { display: flex; flex-direction: column; gap: 4px; }
audio { width: 100%; height: 40px; }
.btn.rec-due { border-color: var(--accent); color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* Comparativa A/B */
.ab { background: var(--surface-2); border-radius: 12px; padding: 12px; margin: 8px 0 12px; }
.ab-selects { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ab-selects label { margin: 0; font-size: .8rem; }
.ab-selects select { font-size: .88rem; padding: 8px; }
.ab-diff { margin: 10px 0; text-align: center; }
.ab-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 0; border-radius: 12px; overflow: hidden; border: 1px solid var(--border); }
.ab-side {
  font: inherit; font-weight: 700; border: 0; min-height: 52px; cursor: pointer;
  background: var(--surface); color: var(--muted);
}
.ab-side.on { background: var(--accent); color: var(--accent-ink); }
.ab-transport { display: flex; align-items: center; gap: 10px; margin: 12px 0 6px; }
.ab-transport input { flex: 1; min-height: 0; }
.ab-transport span { font-variant-numeric: tabular-nums; white-space: nowrap; }
.ab-play { width: 52px; min-height: 52px; border-radius: 50%; font-size: 1.1rem; padding: 0; flex: none; }
@media (hover: none) { .kbd-hint { display: none; } }
.suggest .btn { white-space: nowrap; flex: none; }
kbd { font: inherit; font-size: .8em; border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; background: var(--surface); }

.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

.suggest { list-style: none; padding: 0; margin: 0 0 8px; }
.suggest li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; }
.suggest li + li { border-top: 1px solid var(--border); }

.entries { list-style: none; padding: 0; margin: 0; }
.entries li { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 4px 12px; padding: 8px 0; }
.entries li + li { border-top: 1px solid var(--border); }
.entries li p { flex-basis: 100%; margin: 0; color: var(--muted); }

/* ---------- Ejercicios ---------- */
.ex-list { list-style: none; padding: 0; margin: 0; }
.ex-list li + li { border-top: 1px solid var(--border); }
.ex-item { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; color: var(--text); align-items: center; }
.ex-main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.ex-side { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.bpm { font-weight: 700; font-variant-numeric: tabular-nums; }
.bpm small { color: var(--muted); font-weight: 400; }
.back { display: inline-block; margin: 8px 0 4px; font-size: .9rem; }
details summary { cursor: pointer; font-weight: 600; }
details[open] summary { margin-bottom: 8px; }

.sessions { list-style: none; padding: 0; margin: 0; }
.sessions summary { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-weight: 400; list-style: none; }
.sessions summary::-webkit-details-marker { display: none; }
.sessions strong::first-letter { text-transform: uppercase; }

/* ---------- Diálogo y avisos ---------- */
dialog {
  border: 1px solid var(--border); border-radius: 18px; background: var(--surface); color: var(--text);
  width: min(460px, calc(100vw - 32px)); padding: 20px;
}
dialog::backdrop { background: rgb(0 0 0 / .45); }

.toast {
  position: fixed; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom)); z-index: 20;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: .92rem;
  transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 480px) {
  .stats { gap: 8px; }
  .stat { padding: 10px; }
  .stat-value { font-size: 1.1rem; }
  .log-grid, .ab-selects, .settings-grid { grid-template-columns: 1fr; }
  .cat-bars li { grid-template-columns: 6.2rem 1fr 4rem; font-size: .82rem; }
}

@media (min-width: 900px) {
  .nav { top: 0; bottom: auto; right: auto; width: 88px; height: 100vh; grid-template-columns: 1fr; align-content: start; padding-top: 72px; border-top: 0; border-right: 1px solid var(--border); gap: 6px; }
  body { padding-bottom: 0; padding-left: 88px; }
  .toast { bottom: 24px; }
}
