/* ===========================================================================
   Oído — Canta y afina (/ejercicios/oido).
   Built on the Music Lab tokens (music-lab.css) and the Practice Lab pieces
   (practice-lab.css: segments, inputs, fretboard; practice-chords.css: the
   instrument pills and the keyboard; practice-scales.css: the exercise
   field; practice-reading.css: the staff). Nothing here defines a colour of
   its own, so day and night both work. Phone first; the stage is
   touch-first (targets ≥ 44px) and reads from a music stand.
   =========================================================================== */

.ml-sg {
  max-width: var(--ml-max);
  margin: 0 auto;
  padding: 22px 16px calc(64px + env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.ml-sg [hidden] { display: none !important; }

.ml-sg-card { border: 1px solid var(--ml-line); background: var(--ml-surface); border-radius: var(--ml-radius); padding: 16px; min-width: 0; }
.ml-sg-card h2 { font-size: 1.02rem; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
.ml-sg__card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.ml-sg__card-head h2 { margin: 0 0 8px; }
.ml-sg__link {
  appearance: none; border: 0; background: none; padding: 0; cursor: pointer;
  color: var(--ml-coral); font: inherit; font-size: 13.5px; font-weight: 600; text-decoration: underline; text-underline-offset: 3px;
}
.ml-sg__eyebrow { margin: 0; font-size: 11.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--ml-dim); font-weight: 700; }

/* ── Header ──────────────────────────────────────────────────────────── */

.ml-sg__head { margin-bottom: 16px; }
.ml-sg__title { display: flex; flex-wrap: wrap; gap: 14px 24px; align-items: flex-start; justify-content: space-between; }
.ml-sg__title-main { min-width: 0; flex: 1 1 320px; }
.ml-sg__title h1 { font-size: clamp(1.7rem, 4.6vw, 2.5rem); }
.ml-sg__grad { background: var(--ml-grad-text); -webkit-background-clip: text; background-clip: text; color: transparent; }
.ml-sg__lead { color: var(--ml-muted); margin: 6px 0 4px; }
.ml-sg__pick { display: grid; gap: 8px; flex: 0 1 440px; min-width: min(100%, 300px); }

/* ── Choices ─────────────────────────────────────────────────────────── */

.ml-sg__setup {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px 14px; align-items: end;
  padding: 14px 16px; margin-bottom: 14px; border: 1px solid var(--ml-line); border-radius: var(--ml-radius); background: var(--ml-surface);
}
.ml-sg__field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.ml-sg__field--instr { grid-column: 1 / -1; }
.ml-sg__label { font-size: 12px; color: var(--ml-muted); font-weight: 600; }
.ml-sg__label small { color: var(--ml-dim); font-weight: 500; }
.ml-sg__instr { grid-template-columns: repeat(2, minmax(0, 1fr)); max-width: 360px; }
.ml-sg__setup .ml-input { width: 100%; }
.ml-sg__setup .ml-seg { display: flex; max-width: 100%; }
.ml-sg__setup .ml-seg__b { flex: 1 1 auto; min-width: 0; padding: 7px 8px; }
.ml-sg__a4 { display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; color: var(--ml-muted); }
.ml-sg__a4 .ml-input--num { width: 74px; }
.ml-sg__level-sum { grid-column: 1 / -1; }
.ml-sg__check { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; min-height: 32px; }
.ml-sg__check input { width: 20px; height: 20px; accent-color: var(--ml-pink); flex: none; }
.ml-sg__check small { flex-basis: 100%; color: var(--ml-dim); font-size: 12px; margin-left: 28px; }

/* ── Microphone ──────────────────────────────────────────────────────── */

.ml-sg__mic { margin-bottom: 14px; }
.ml-sg__mic-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.ml-sg__mic-text { flex: 1 1 280px; min-width: 0; }
.ml-sg__mic-status { margin: 0; color: var(--ml-muted); font-size: 14px; }
.ml-sg__mic[data-mic="error"] .ml-sg__mic-status { color: var(--ml-rose); }
.ml-sg__mic[data-mic="on"] h2 svg { color: var(--ml-emerald); }
.ml-sg__mic-tools { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px 16px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--ml-line); align-items: end; }
.ml-sg__slider { width: 100%; accent-color: var(--ml-pink); }
.ml-sg__level { grid-column: 1 / -1; height: 6px; border-radius: 999px; background: var(--ml-surface-2); overflow: hidden; }
.ml-sg__level span { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--ml-dim); transition: width .08s linear, background .2s; }
.ml-sg__level span.is-voice { background: var(--ml-emerald); }

/* ── Session bar ─────────────────────────────────────────────────────── */

.ml-sg__bar {
  position: sticky; top: var(--ml-nav-h); z-index: 5;
  display: grid; grid-template-columns: 1fr auto auto; grid-template-areas: "count clock focus" "progress progress progress";
  align-items: center; gap: 8px 12px; padding: 10px 14px; margin: 0 0 14px;
  border: 1px solid var(--ml-line); border-radius: 16px; background: var(--ml-nav-bg);
  backdrop-filter: saturate(160%) blur(14px); -webkit-backdrop-filter: saturate(160%) blur(14px);
}
.ml-sg__count { grid-area: count; display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; min-width: 0; }
.ml-sg__count strong { font-family: "Space Grotesk", sans-serif; font-size: 1.05rem; white-space: nowrap; }
.ml-sg__kind { font-size: 12px; color: var(--ml-muted); padding: 2px 9px; border: 1px solid var(--ml-line); border-radius: 999px; white-space: nowrap; }
.ml-sg__progress { grid-area: progress; height: 7px; border-radius: 999px; background: var(--ml-surface-2); overflow: hidden; }
.ml-sg__progress span { display: block; height: 100%; width: calc(var(--p, 0) * 100%); border-radius: inherit; background: linear-gradient(90deg, var(--ml-emerald), var(--ml-cyan)); transition: width .4s ease; }
.ml-sg__clock { grid-area: clock; display: inline-flex; align-items: center; gap: 6px; font-family: "Space Grotesk", sans-serif; font-weight: 700; font-variant-numeric: tabular-nums; }
.ml-sg__clock svg { color: var(--ml-coral); }
.ml-sg__icon-btn { grid-area: focus; display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; cursor: pointer; border: 1px solid var(--ml-line); background: var(--ml-surface); color: var(--ml-text); }
.ml-sg__icon-btn:hover { background: var(--ml-surface-2); }
.ml-sg__icon-btn[aria-pressed="true"] { background: var(--ml-grad); color: #fff; border-color: transparent; }

/* ── Stage ───────────────────────────────────────────────────────────── */

.ml-sg__grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
.ml-sg__grid > * { min-width: 0; }
.ml-sg__main { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.ml-sg__stage { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }

.ml-sg__target { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.ml-sg__prompt { margin: 4px 0 0; font-weight: 600; color: var(--ml-muted); }
.ml-sg__note { display: flex; flex-direction: column; align-items: center; line-height: 1; margin: 6px 0 2px; }
.ml-sg__note-main { font-family: "Space Grotesk", sans-serif; font-size: clamp(3rem, 12vw, 4.4rem); font-weight: 700; letter-spacing: -.03em; }
.ml-sg__target[data-hidden="true"] .ml-sg__note-main { color: var(--ml-dim); }
.ml-sg__note-latin { font-size: 1.1rem; color: var(--ml-muted); margin-top: 4px; }
.ml-sg__hz { margin: 0; font-variant-numeric: tabular-nums; color: var(--ml-dim); font-size: 14px; }
.ml-sg__target-steps { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin: 4px 0; }
.ml-sg__step { font-size: 13px; font-weight: 700; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--ml-line); opacity: .55; }
.ml-sg__step.is-now { opacity: 1; border-color: currentColor; box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 18%, transparent); }
.ml-sg__step.is-done { opacity: .85; background: color-mix(in srgb, var(--ml-emerald) 18%, transparent); border-color: color-mix(in srgb, var(--ml-emerald) 50%, transparent); }
.ml-sg__listen { min-height: 48px; min-width: 180px; margin-top: 8px; }

.ml-sg__graph-card { display: flex; flex-direction: column; gap: 10px; padding: 14px; }
.ml-sg__graph-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.ml-sg__state { font-size: 13px; color: var(--ml-muted); }
.ml-sg[data-state="singing"] .ml-sg__state { color: var(--ml-cyan); font-weight: 600; }
.ml-sg[data-state="matched"] .ml-sg__state { color: var(--ml-emerald); font-weight: 600; }
.ml-sg__voice { display: inline-flex; align-items: baseline; gap: 6px; font-variant-numeric: tabular-nums; }
.ml-sg__voice strong { font-family: "Space Grotesk", sans-serif; font-size: 1.15rem; }
.ml-sg__voice small { color: var(--ml-muted); }
.ml-sg__graph { position: relative; height: 240px; border-radius: 12px; overflow: hidden; background: color-mix(in srgb, var(--ml-bg-2) 70%, var(--ml-bg)); border: 1px solid var(--ml-line); }
.ml-sg__graph canvas { display: block; width: 100%; height: 100%; }
.ml-sg__feedback { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; min-height: 32px; }
.ml-sg__fb-text { font-family: "Space Grotesk", sans-serif; font-size: 1.15rem; }
.ml-sg__fb-text.is-perfect, .ml-sg__fb-text.is-good { color: var(--ml-emerald); }
.ml-sg__fb-text.is-ok { color: var(--ml-amber); }
.ml-sg__fb-text.is-out { color: var(--ml-rose); }
.ml-sg__cents { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1rem; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--ml-line); }
.ml-sg__cents:empty { display: none; }
.ml-sg__cents.is-perfect, .ml-sg__cents.is-good { color: var(--ml-emerald); border-color: color-mix(in srgb, var(--ml-emerald) 50%, transparent); }
.ml-sg__cents.is-ok { color: var(--ml-amber); border-color: color-mix(in srgb, var(--ml-amber) 50%, transparent); }
.ml-sg__cents.is-out { color: var(--ml-rose); border-color: color-mix(in srgb, var(--ml-rose) 50%, transparent); }
.ml-sg__hold { height: 6px; border-radius: 999px; background: var(--ml-surface-2); overflow: hidden; }
.ml-sg__hold span { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--ml-emerald); transition: width .1s linear; }

.ml-sg__stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.ml-sg__stat { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--ml-line); background: var(--ml-surface); }
.ml-sg__stat small { font-size: 12px; color: var(--ml-muted); }
.ml-sg__stat strong { font-family: "Space Grotesk", sans-serif; font-size: 1.2rem; font-variant-numeric: tabular-nums; }

/* Reference views. The keyboard comes from practice-chords.css; the voice
   key is lit by the bundle. */
.ml-sg__tabs { display: inline-flex; margin-bottom: 10px; }
.ml-sg__ref-body { overflow-x: auto; padding: 4px 0; }
.ml-sg__ref-body .ml-kb { min-width: 320px; max-height: 110px; }
.ml-sg__ref-body .ml-fb { min-width: 460px; }
.ml-sg__ref-body .ml-st--mini { max-width: 260px; margin: 0 auto; }
.ml-kb__key.is-voice .ml-kb__white, .ml-kb__key.is-voice .ml-kb__black { fill: color-mix(in srgb, var(--ml-cyan) 45%, var(--ml-key-white)); }
.ml-kb__key.is-voice.is-on .ml-kb__white, .ml-kb__key.is-voice.is-on .ml-kb__black { fill: color-mix(in srgb, var(--ml-emerald) 55%, var(--ml-key-white)); }

/* Transport */
.ml-sg__transport { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px 12px; padding: 6px 0; }
.ml-sg__transport .ml-btn { min-height: 44px; min-width: 44px; }
.ml-sg__play {
  display: grid; place-items: center; width: 72px; height: 72px; border-radius: 50%; border: 0; cursor: pointer;
  color: #fff; background: var(--ml-grad); box-shadow: 0 12px 34px rgba(242, 11, 126, .36); transition: transform .15s;
}
.ml-sg__play svg { margin-left: 3px; }
.ml-sg__play:hover { transform: scale(1.04); }
.ml-sg__play:active { transform: scale(.97); }
.ml-sg[data-state="reference"] .ml-sg__play { animation: ml-sg-pulse 1.1s ease-in-out infinite; }
@keyframes ml-sg-pulse { 0%, 100% { box-shadow: 0 12px 34px rgba(242, 11, 126, .36); } 50% { box-shadow: 0 12px 44px rgba(242, 11, 126, .7); } }
.ml-sg__auto { min-height: 44px; }

/* History */
.ml-sg__side { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.ml-sg-hist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; max-height: 320px; overflow-y: auto; }
.ml-sg-hist__row { display: grid; grid-template-columns: 26px minmax(0, 1fr) 54px 64px 46px; gap: 6px; align-items: center; padding: 6px 8px; border-radius: 10px; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.ml-sg-hist__row:nth-child(odd) { background: var(--ml-surface); }
.ml-sg-hist__n { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; font-size: 11.5px; font-weight: 700; background: var(--ml-surface-2); color: var(--ml-muted); }
.ml-sg-hist__row.is-ok .ml-sg-hist__n { background: color-mix(in srgb, var(--ml-emerald) 25%, transparent); color: var(--ml-emerald); }
.ml-sg-hist__row.is-bad .ml-sg-hist__n { background: color-mix(in srgb, var(--ml-rose) 22%, transparent); color: var(--ml-rose); }
.ml-sg-hist__note { font-family: "Space Grotesk", sans-serif; font-weight: 700; }
.ml-sg-hist__acc, .ml-sg-hist__cents, .ml-sg-hist__time { text-align: right; color: var(--ml-muted); }
.ml-sg-hist__acc { color: var(--ml-text); font-weight: 600; }
.ml-sg-hist__empty { color: var(--ml-dim); font-size: 13.5px; padding: 6px 0; }
.ml-sg__tips ul { margin: 0; padding-left: 18px; color: var(--ml-muted); font-size: 13.5px; display: flex; flex-direction: column; gap: 5px; }

/* Results */
.ml-sg__results { text-align: center; margin-top: 16px; padding: 22px 18px; }
.ml-sg__results h2 { justify-content: center; font-size: clamp(1.5rem, 4vw, 2rem); margin: 4px 0 14px; }
.ml-sg-res__stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; max-width: 620px; margin: 0 auto 14px; }
.ml-sg-res__stat { display: flex; flex-direction: column; gap: 2px; padding: 10px; border-radius: 12px; background: var(--ml-surface); border: 1px solid var(--ml-line); }
.ml-sg-res__stat strong { font-family: "Space Grotesk", sans-serif; font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.ml-sg-res__stat small { font-size: 12px; color: var(--ml-muted); }
.ml-sg-res__hard { color: var(--ml-muted); margin: 0 0 14px; }
.ml-sg-res__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.ml-sg-res__actions .ml-btn { min-height: 46px; }

/* Progress dialog and heatmap */
.ml-sg-dialog {
  width: min(720px, calc(100vw - 24px)); max-height: calc(100dvh - 32px); padding: 0; border-radius: var(--ml-radius);
  border: 1px solid var(--ml-line-strong); background: var(--ml-popover-bg); color: var(--ml-text); box-shadow: var(--ml-shadow);
}
.ml-sg-dialog::backdrop { background: rgba(0, 0, 0, .55); }
.ml-sg-dialog__in { padding: 18px; }
.ml-sg-dialog__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.ml-sg-dialog__head h2 { font-size: 1.3rem; margin: 0; }
.ml-sg-prog__sum { margin: 8px 0 12px; }
.ml-sg-prog__weak { margin: 12px 0 0; color: var(--ml-muted); }
.ml-sg-heat { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 6px; }
.ml-sg-heat__cell { display: flex; flex-direction: column; align-items: center; padding: 8px 4px; border-radius: 10px; border: 1px solid var(--ml-line); background: var(--ml-surface); }
.ml-sg-heat__cell strong { font-family: "Space Grotesk", sans-serif; }
.ml-sg-heat__cell span { font-weight: 700; font-size: 13px; }
.ml-sg-heat__cell small { font-size: 11px; color: var(--ml-dim); }
.ml-sg-heat__cell.is-good { background: color-mix(in srgb, var(--ml-emerald) 18%, transparent); border-color: color-mix(in srgb, var(--ml-emerald) 40%, transparent); }
.ml-sg-heat__cell.is-mid { background: color-mix(in srgb, var(--ml-amber) 16%, transparent); border-color: color-mix(in srgb, var(--ml-amber) 40%, transparent); }
.ml-sg-heat__cell.is-low { background: color-mix(in srgb, var(--ml-rose) 16%, transparent); border-color: color-mix(in srgb, var(--ml-rose) 40%, transparent); }

/* ── Focus mode: the stage and the transport, nothing else ───────────── */

.ml-sing-focus .ml-nav, .ml-sing-focus .ml-footer, .ml-sing-focus .mlb,
.ml-sing-focus .ml-sg__head, .ml-sing-focus .ml-sg__setup, .ml-sing-focus .ml-sg__mic,
.ml-sing-focus .ml-sg__side, .ml-sing-focus .ml-sg__results { display: none !important; }
.ml-sing-focus .ml-sg { padding-top: 12px; }
.ml-sing-focus .ml-sg__bar { top: 0; }
.ml-sing-focus .ml-sg__graph { height: min(46vh, 420px); }

/* ── Larger screens ──────────────────────────────────────────────────── */

@media (min-width: 640px) {
  .ml-sg__stats { grid-template-columns: repeat(4, 1fr); }
  .ml-sg__graph { height: 280px; }
}

@media (min-width: 760px) {
  .ml-sg__bar { grid-template-columns: auto minmax(120px, 1fr) auto auto; grid-template-areas: "count progress clock focus"; }
  .ml-sg__stage { grid-template-columns: minmax(220px, 300px) minmax(0, 1fr); }
  .ml-sg__graph { height: 300px; }
  .ml-sg__play { width: 80px; height: 80px; }
}

@media (min-width: 1000px) {
  .ml-sg__grid { grid-template-columns: minmax(0, 1fr) 320px; }
  .ml-sg__side { position: sticky; top: calc(var(--ml-nav-h) + 76px); }
  .ml-sg__graph { height: 320px; }
}

@media (max-width: 520px) {
  .ml-sg__kind { display: none; }
  .ml-sg__graph { height: 220px; }
}

@media (prefers-reduced-motion: reduce) {
  .ml-sg[data-state="reference"] .ml-sg__play { animation: none; }
  .ml-sg__progress span, .ml-sg__hold span, .ml-sg__play { transition: none; }
}
