/* ===========================================================================
   Detector de notas (/herramientas/detector).
   Built on the Music Lab tokens (music-lab.css), the Practice Lab pieces
   (practice-lab.css: segments, inputs, chips, fretboard; practice-chords.css:
   the instrument pills and the keyboard) and Canta y afina's microphone card
   and fields (practice-sing.css). Nothing here defines a colour of its own,
   so day and night both work. Phone first; large targets for a music stand.
   =========================================================================== */

.ml-dt {
  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));
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.ml-dt [hidden] { display: none !important; }
.ml-dt .ml-sg-card h2 { font-size: 1.02rem; }

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

.ml-dt__head { margin: 0; }
.ml-dt__title { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: flex-start; justify-content: space-between; }
.ml-dt__title-main { min-width: 0; flex: 1 1 320px; }
.ml-dt__title h1 { font-size: clamp(1.7rem, 4.6vw, 2.5rem); margin: 0; }
.ml-dt__grad { background: var(--ml-grad-text); -webkit-background-clip: text; background-clip: text; color: transparent; }
.ml-dt__lead { color: var(--ml-muted); margin: 6px 0 0; }
.ml-dt__title-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.ml-dt__title-actions .ml-btn { min-height: 40px; }

/* ── Instrument ──────────────────────────────────────────────────────── */

.ml-dt__pick { display: grid; gap: 8px; }
.ml-dt__instr { grid-template-columns: repeat(5, minmax(0, 1fr)); max-width: 720px; }
.ml-dt__instr .ml-instr-tab { min-height: 48px; }
.ml-dt__pick-hint { margin: 0; }

/* ── Settings and guide ──────────────────────────────────────────────── */

.ml-dt__settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px 16px; align-items: end; }
.ml-dt__settings-grid .ml-input { width: 100%; }
.ml-dt__settings-grid .ml-seg { display: flex; }
.ml-dt__settings-grid .ml-seg__b { flex: 1 1 auto; min-width: 0; padding: 7px 8px; }
.ml-dt__settings-grid .ml-sg__check { grid-column: 1 / -1; }
.ml-dt__guide ul { margin: 0; padding-left: 18px; color: var(--ml-muted); font-size: 14px; display: flex; flex-direction: column; gap: 6px; }
.ml-dt__guide strong { color: var(--ml-text); }

/* ── Microphone (extends the shared card) ────────────────────────────── */

.ml-dt__mic { margin: 0; }
.ml-dt__mic-actions { display: flex; gap: 8px; align-items: center; }
.ml-dt__mic-actions .ml-btn { min-height: 46px; min-width: 120px; }
.ml-dt__level-row { grid-column: 1 / -1; display: grid; gap: 6px; }
.ml-sg__level span.is-clip { background: var(--ml-rose); }
.ml-dt__mic[data-mic="denied"] .ml-sg__mic-status,
.ml-dt__mic[data-mic="nodevice"] .ml-sg__mic-status,
.ml-dt__mic[data-mic="insecure"] .ml-sg__mic-status,
.ml-dt__mic[data-mic="unsupported"] .ml-sg__mic-status { color: var(--ml-rose); }
.ml-dt__mic[data-mic="prompt"] .ml-sg__mic-status { color: var(--ml-amber); }

/* ── The three panels ────────────────────────────────────────────────── */

.ml-dt__stage { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; align-items: stretch; }
.ml-dt__stage > * { min-width: 0; }

.ml-dt__note { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 4px; }
.ml-dt__note-head { align-self: stretch; display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.ml-dt__state { font-size: 12.5px; font-weight: 600; color: var(--ml-muted); padding: 2px 10px; border-radius: 999px; border: 1px solid var(--ml-line); }
.ml-dt[data-state="detected"] .ml-dt__state { color: var(--ml-cyan); border-color: color-mix(in srgb, var(--ml-cyan) 50%, transparent); }
.ml-dt[data-state="tuned"] .ml-dt__state, .ml-dt[data-state="hit"] .ml-dt__state { color: var(--ml-emerald); border-color: color-mix(in srgb, var(--ml-emerald) 50%, transparent); }
.ml-dt[data-state="unstable"] .ml-dt__state, .ml-dt[data-state="reference"] .ml-dt__state, .ml-dt[data-state="calibrating"] .ml-dt__state { color: var(--ml-amber); border-color: color-mix(in srgb, var(--ml-amber) 50%, transparent); }
.ml-dt[data-state="clipped"] .ml-dt__state, .ml-dt[data-state="error"] .ml-dt__state { color: var(--ml-rose); border-color: color-mix(in srgb, var(--ml-rose) 50%, transparent); }
.ml-dt__note-main { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 8px 0 0; line-height: 1; }
.ml-dt__note-name { font-family: "Space Grotesk", sans-serif; font-size: clamp(3.2rem, 13vw, 4.8rem); font-weight: 700; letter-spacing: -.03em; min-height: 1em; }
.ml-dt__note-check { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--ml-emerald); color: var(--ml-on-accent); font-weight: 800; font-size: 20px; }
.ml-dt__note-alt { font-size: 1.05rem; color: var(--ml-muted); min-height: 1.3em; max-width: 30ch; }
.ml-dt__hz { margin: 4px 0 0; font-variant-numeric: tabular-nums; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.ml-dt__hz strong { font-family: "Space Grotesk", sans-serif; font-size: 1.2rem; }
.ml-dt__hz small { color: var(--ml-dim); font-size: 12px; }
.ml-dt__cents { margin: 2px 0 0; font-weight: 700; font-variant-numeric: tabular-nums; padding: 3px 12px; border-radius: 999px; border: 1px solid var(--ml-line); }
.ml-dt__cents:empty { display: none; }
.ml-dt__cents.is-afinado { color: var(--ml-emerald); border-color: color-mix(in srgb, var(--ml-emerald) 50%, transparent); }
.ml-dt__cents.is-bajo, .ml-dt__cents.is-alto { color: var(--ml-amber); border-color: color-mix(in srgb, var(--ml-amber) 50%, transparent); }
.ml-dt__conf { margin: 0; font-size: 12px; color: var(--ml-dim); min-height: 1.2em; }
.ml-dt__target { align-self: stretch; display: grid; gap: 8px; margin-top: 8px; padding-top: 10px; border-top: 1px solid var(--ml-line); text-align: left; }
.ml-dt__target .ml-input { width: 100%; }
.ml-dt__hold-text { margin: 0; font-size: 13px; color: var(--ml-muted); }
.ml-dt__note-actions { display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap; margin-top: 10px; }
.ml-dt__note-actions .ml-btn { min-height: 40px; }
.ml-dt__ref-instr { width: auto; }

.ml-dt__graph-card { display: flex; flex-direction: column; gap: 10px; padding: 14px; }
.ml-dt__graph-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.ml-dt__graph-title { font-weight: 700; font-family: "Space Grotesk", sans-serif; }
.ml-dt__graph-tools { display: flex; gap: 6px; }
.ml-dt__tool {
  appearance: none; cursor: pointer; min-width: 40px; min-height: 36px; padding: 0 10px; border-radius: 10px;
  border: 1px solid var(--ml-line); background: var(--ml-surface); color: var(--ml-text); font: inherit; font-size: 13px; font-weight: 600;
}
.ml-dt__tool:hover { background: var(--ml-surface-2); }
.ml-dt__tool[aria-pressed="true"] { background: var(--ml-grad); color: #fff; border-color: transparent; }
/* The canvas is taken out of flow: its pixel size must never feed the row
   height it is measured from (a resize loop otherwise). */
.ml-dt__graph { position: relative; height: 260px; min-height: 0; 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-dt__graph canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }
.ml-dt__graph-note { margin: 0; font-size: 12px; color: var(--ml-dim); }

.ml-dt__tuner { display: flex; flex-direction: column; gap: 10px; }
.ml-dt__gauge { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.ml-dt__gauge svg { width: min(100%, 260px); height: auto; display: block; }
.ml-dt__gauge-arc { fill: none; stroke: var(--ml-line-strong); stroke-width: 10; stroke-linecap: round; }
.ml-dt__gauge-zone { fill: none; stroke: var(--ml-emerald); stroke-width: 10; stroke-linecap: butt; opacity: .8; }
.ml-dt__gauge-tick { stroke: var(--ml-dim); stroke-width: 2; }
.ml-dt__gauge-label { fill: var(--ml-dim); font-size: 11px; font-family: Inter, sans-serif; }
.ml-dt__gauge-needle { stroke: var(--ml-text); stroke-width: 3; stroke-linecap: round; transition: transform .12s linear; }
.ml-dt__gauge-hub { fill: var(--ml-text); }
.ml-dt__gauge[data-zone="ok"] .ml-dt__gauge-needle, .ml-dt__gauge[data-zone="ok"] .ml-dt__gauge-hub { stroke: var(--ml-emerald); fill: var(--ml-emerald); }
.ml-dt__gauge[data-zone="bajo"] .ml-dt__gauge-needle, .ml-dt__gauge[data-zone="alto"] .ml-dt__gauge-needle { stroke: var(--ml-amber); }
.ml-dt__gauge[data-zone="none"] .ml-dt__gauge-needle { stroke: var(--ml-dim); }
.ml-dt__gauge-cents { font-family: "Space Grotesk", sans-serif; font-size: 1.7rem; font-variant-numeric: tabular-nums; margin-top: -6px; }
.ml-dt__gauge-word { font-size: 14px; font-weight: 600; color: var(--ml-muted); }
.ml-dt__gauge[data-zone="ok"] .ml-dt__gauge-word { color: var(--ml-emerald); }
.ml-dt__meters { margin: 0; display: grid; gap: 8px; }
.ml-dt__meters > div { display: grid; grid-template-columns: minmax(0, 1fr); gap: 3px; }
.ml-dt__meters dt { font-size: 12px; color: var(--ml-muted); font-weight: 600; }
.ml-dt__meters dd { margin: 0; display: grid; grid-template-columns: minmax(0, 1fr) 64px; gap: 8px; align-items: center; font-variant-numeric: tabular-nums; }
.ml-dt__meters strong { text-align: right; font-size: 14px; }
.ml-dt__meter { display: block; height: 7px; border-radius: 999px; background: var(--ml-surface-2); overflow: hidden; }
.ml-dt__meter span { display: block; height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--ml-cyan), var(--ml-emerald)); transition: width .1s linear; }
.ml-dt__meter span.is-clip { background: var(--ml-rose); }

/* ── Instrument view ─────────────────────────────────────────────────── */

.ml-dt__view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px 16px; flex-wrap: wrap; margin-bottom: 10px; }
.ml-dt__view-head h2 { margin: 0; }
.ml-dt__view-tools { display: flex; gap: 10px 14px; flex-wrap: wrap; align-items: flex-end; }
.ml-dt__view-tools .ml-input { min-width: 150px; }
.ml-dt__custom-row { display: flex; gap: 6px; }
.ml-dt__custom-row .ml-input { min-width: 0; width: 200px; }
.ml-dt__view-body { overflow-x: auto; -webkit-overflow-scrolling: touch; padding: 4px 0; scroll-behavior: smooth; }
.ml-dt__view-body .ml-fb { min-width: 520px; }
.ml-dt__view-body .ml-kb { min-width: 420px; max-height: 120px; }
.ml-fb__dot.is-alt .ml-fb__disc { opacity: .55; }
.ml-fb__dot.is-picked .ml-fb__halo { opacity: 1; fill: color-mix(in srgb, currentColor 30%, transparent); }
.ml-fb__dot.is-picked .ml-fb__disc { stroke: var(--ml-text); stroke-width: 2.5; }
.ml-kb__key.is-voice .ml-kb__white, .ml-kb__key.is-voice .ml-kb__black { fill: color-mix(in srgb, var(--ml-emerald) 55%, var(--ml-key-white)); }
.ml-dt__positions { display: grid; gap: 6px; margin-top: 10px; }
.ml-dt__pos-row { display: flex; flex-wrap: wrap; gap: 6px; }
.ml-dt__pos-row .ml-chip { min-height: 40px; }
.ml-dt__amp { display: grid; gap: 4px; margin-top: 10px; }
.ml-dt__amp-label { font-size: 12px; color: var(--ml-dim); }
.ml-dt__amp-bar { display: block; height: 8px; border-radius: 999px; background: var(--ml-surface-2); overflow: hidden; }
.ml-dt__amp-bar span { display: block; height: 100%; width: 0; background: var(--ml-violet); transition: width .08s linear; }
.ml-dt__hits { display: flex; align-items: flex-end; gap: 6px; min-height: 64px; padding: 8px 4px; }
.ml-dt__hit { display: block; width: 10px; height: calc(14px + 44px * var(--s, .5)); border-radius: 5px; background: var(--ml-violet); }
.ml-dt__tempo { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.ml-dt__tempo strong { font-family: "Space Grotesk", sans-serif; font-size: 1.4rem; }
.ml-dt__tempo small { color: var(--ml-dim); }
.ml-dt__tempo-count { font-weight: 600; }

/* ── The record ──────────────────────────────────────────────────────── */

.ml-dt__rec-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.ml-dt__rec-head h2 { margin: 0; }
.ml-dt__rec-body { display: grid; gap: 12px; margin-top: 10px; }
.ml-dt__rec-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.ml-dt__rec-actions .ml-btn { min-height: 40px; }
.ml-btn--danger { background: var(--ml-rose); color: #fff; border-color: transparent; }
.ml-dt__rec-status { font-size: 13px; color: var(--ml-muted); }
.ml-dt__events-wrap { overflow-x: auto; }
.ml-dt__events { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; min-width: 520px; }
.ml-dt__events th { text-align: left; font-size: 12px; color: var(--ml-muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--ml-line); }
.ml-dt__events td { padding: 6px 8px; border-bottom: 1px solid var(--ml-line); }
.ml-dt__events-empty td { color: var(--ml-dim); }
.ml-dt__ev-note { font-family: "Space Grotesk", sans-serif; font-weight: 700; }
.ml-dt__events td.is-suggested small { color: var(--ml-amber); }
.ml-dt__events .ml-input { width: auto; min-width: 170px; }
.ml-dt__tab-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.ml-dt__tab-head small { color: var(--ml-dim); }
.ml-dt__tab { margin: 0; padding: 12px; border-radius: 12px; background: var(--ml-bar-bg); border: 1px solid var(--ml-line); overflow-x: auto; font-size: 13px; line-height: 1.45; }

/* ── Links and diagnostics ───────────────────────────────────────────── */

.ml-dt__links { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.ml-dt__diag { margin: 0; font-size: 12px; color: var(--ml-dim); }

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

@media (min-width: 640px) {
  .ml-dt__meters { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ml-dt__tuner .ml-dt__meters > div { grid-template-columns: minmax(0, 1fr); }
  .ml-dt__graph { height: 300px; }
}

@media (min-width: 900px) {
  .ml-dt__stage { grid-template-columns: minmax(240px, 300px) minmax(0, 1fr); grid-template-areas: "note graph" "tuner tuner"; }
  .ml-dt__note { grid-area: note; }
  .ml-dt__graph-card { grid-area: graph; }
  .ml-dt__tuner { grid-area: tuner; display: grid; grid-template-columns: 260px minmax(0, 1fr); grid-template-areas: "eyebrow eyebrow" "gauge meters" "gauge note"; align-items: center; column-gap: 20px; }
  .ml-dt__tuner > .ml-sg__eyebrow { grid-area: eyebrow; }
  .ml-dt__gauge { grid-area: gauge; }
  .ml-dt__tuner > .ml-dt__meters { grid-area: meters; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ml-dt__tuner > .ml-hint { grid-area: note; margin: 0; }
  .ml-dt__graph { flex: 1 1 auto; height: auto; min-height: 360px; max-height: 560px; }
}

@media (min-width: 1200px) {
  .ml-dt__stage { grid-template-columns: minmax(250px, 300px) minmax(0, 1fr) minmax(240px, 290px); grid-template-areas: "note graph tuner"; }
  .ml-dt__tuner { display: flex; flex-direction: column; align-items: stretch; }
  .ml-dt__tuner > .ml-dt__meters { grid-template-columns: minmax(0, 1fr); }
  .ml-dt__graph { min-height: 420px; max-height: 560px; }
}

@media (max-width: 520px) {
  .ml-dt__instr { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ml-dt__instr .ml-instr-tab { min-height: 44px; font-size: 13px; }
  .ml-dt__graph { height: 220px; }
  .ml-dt__note-name { font-size: 3.4rem; }
  .ml-dt__graph-tools .ml-dt__tool { min-width: 36px; padding: 0 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .ml-dt__gauge-needle, .ml-dt__meter span, .ml-sg__level span, .ml-dt__amp-bar span { transition: none; }
  .ml-dt__view-body { scroll-behavior: auto; }
}
