/* Capa visual de las herramientas de audio: pantalla con osciloscopio y espectro.
   Clases con prefijo viz- para no chocar con global.css. Los colores salen de las
   variables del sitio; --viz-trace lo fija el JS según la forma de onda. */

:root { --viz-screen: #0b1013; }

.tone-lab [hidden] { display: none !important; }

.viz-screen {
  position: relative;
  background: var(--viz-screen);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin: 0 0 14px;
}
.viz-canvas { display: block; width: 100%; }
.viz-canvas--scope { height: 200px; }
.viz-canvas--spectrum { height: 150px; border-top: 1px solid var(--border); }

/* Lo que solo se ve en pantalla completa */
.viz-readout, .viz-fsbar { display: none; }

.viz-screen.is-fullscreen {
  display: flex;
  flex-direction: column;
  /* El elemento en pantalla completa ya ocupa el área visible. Con 100vw/100vh en celulares el alto
     incluye las barras del sistema y se recorta el borde inferior, justo donde están los botones. */
  width: 100%;
  height: 100%;
  max-height: 100dvh;
  padding: 20px 24px 24px;
  padding: max(20px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right))
           max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
  box-sizing: border-box;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  background: var(--viz-screen);
}
.viz-screen.is-fullscreen .viz-readout {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px 22px;
  margin-bottom: 12px;
}
.viz-readout-freq {
  font-family: var(--font-mono);
  font-size: clamp(2.2rem, 7vw, 5rem);
  line-height: 1;
  color: var(--viz-trace, var(--accent-cyan));
}
.viz-readout-note, .viz-readout-wave {
  font-family: var(--font-mono);
  font-size: clamp(1rem, 2.4vw, 1.5rem);
  color: var(--text-muted);
}
.viz-screen.is-fullscreen .viz-canvas { flex: 1 1 0; min-height: 0; height: auto; border-top: 0; }
.viz-screen.is-fullscreen .viz-canvas--spectrum { display: block; flex: 0.8 1 0; margin-top: 12px; }
.viz-screen.is-fullscreen .viz-fsbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; margin-top: 16px; flex: 0 0 auto; }
.viz-fsbar .btn { white-space: nowrap; }
.viz-readout > * { min-width: 0; overflow-wrap: anywhere; }

/* Celular apaisado: poco alto disponible, se achica todo para que la botonera quede completa */
@media (max-height: 520px) {
  .viz-screen.is-fullscreen { padding-top: 10px; padding-bottom: 10px; }
  .viz-screen.is-fullscreen .viz-readout { margin-bottom: 6px; gap: 4px 16px; }
  .viz-readout-freq { font-size: clamp(1.6rem, 9vh, 3rem); }
  .viz-screen.is-fullscreen .viz-canvas--spectrum { flex: 0.6 1 0; margin-top: 6px; }
  .viz-screen.is-fullscreen .viz-fsbar { margin-top: 8px; }
  .viz-fsbar .btn { min-height: 40px; padding-top: 6px; padding-bottom: 6px; }
}

/* En pantallas angostas solo el osciloscopio: el espectro necesita ancho para ser legible */
@media (max-width: 720px) {
  .viz-canvas--spectrum { display: none; }
  .viz-canvas--scope { height: 170px; }
}

.device-note { font-size: .85rem; color: var(--text-muted); margin: 0 0 18px; text-align: left; }

.viz-note {
  font-family: var(--font-mono);
  font-size: .85rem;
  color: var(--text-muted);
  min-height: 1.3em;
  margin-top: 6px;
}

.viz-slider-wrap { max-width: 460px; margin: 12px auto 4px; }
.viz-scale {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: .72rem;
  color: var(--text-muted);
}

.viz-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px 20px;
  text-align: left;
  margin: 16px 0 8px;
}
.viz-grid label { margin-bottom: 6px; }
.viz-grid select { width: 100%; }
.viz-out { font-family: var(--font-mono); color: var(--text); margin-left: 6px; }

/* Exportar a WAV */
.viz-wav { border-top: 1px solid var(--border); margin-top: 16px; padding-top: 12px; text-align: left; }
.viz-wav > summary { cursor: pointer; color: var(--text); font-size: 1rem; padding: 6px 0; }
.viz-wav[open] > summary { margin-bottom: 8px; }
.viz-wav-intro { color: var(--text-muted); font-size: .9rem; margin: 0 0 8px; }
.viz-wav input[type="number"] { width: 100%; }
.viz-check { display: flex; align-items: center; gap: 8px; margin: 8px 0 4px; }
.viz-check input { margin: 0; }
.viz-wav .controls-row { justify-content: flex-start; align-items: center; }
.viz-wav-status { font-family: var(--font-mono); font-size: .8rem; color: var(--text-muted); min-height: 1.3em; margin: 10px 0 0; overflow-wrap: anywhere; }

/* Balance: el deslizante y el botón Centrar van en la misma fila, con el botón apartado y con blanco táctil
   grande (44 px de alto): pegado debajo del deslizante, en un celular un dedo que cae un poco arriba mueve
   el deslizante en vez de apretar el botón. */
.viz-pan-row { display: flex; align-items: center; gap: 14px; }
.viz-pan-row input[type="range"] { flex: 1 1 auto; width: auto; min-width: 0; }
.viz-pan-row .viz-mini { flex: 0 0 auto; margin: 0; }
.tone-lab button { touch-action: manipulation; } /* sin demora ni zoom por doble toque en los botones */

/* Botón chico (Centrar el balance) */
.viz-mini {
  margin-top: 6px;
  min-height: 44px;
  min-width: 84px;
  padding: 8px 14px;
  font-family: var(--font-body);
  font-size: .9rem;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}
.viz-mini:hover { color: var(--text); border-color: var(--accent-cyan); }
.viz-mini:disabled { opacity: .5; cursor: not-allowed; }

/* Medidor de LUFS: tarjetas de valores, gráfico de sonoridad y avisos */
/* 3 + 2: arriba las de sonoridad (LRA, corto plazo, momentáneo), abajo las de picos (true peak, PLR); antes la quinta quedaba sola */
.lm-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; margin: 0 0 14px; text-align: left; }
.lm-grid .lm-card { grid-column: span 2; }
.lm-grid .lm-card:nth-child(n+4) { grid-column: span 3; }
.lm-card { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); }
.lm-label { font-size: .72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.lm-value { font-family: var(--font-mono); font-size: 1.15rem; color: var(--text); }
.lm-hint { font-size: .75rem; color: var(--text-muted); }
.lm-warn { border-color: var(--accent-amber); }
.lm-warn .lm-value { color: var(--accent-amber); }
.lm-chart { display: block; width: 100%; height: 240px; background: var(--viz-screen); border: 1px solid var(--border); border-radius: var(--radius); }
.lm-legend { font-size: .8rem; color: var(--text-muted); margin: 8px 0 12px; text-align: left; }
.lm-notes p { font-size: .85rem; color: var(--text-muted); border-left: 3px solid var(--accent-amber); padding-left: 10px; margin: 8px 0; text-align: left; }
@media (max-width: 560px) {
  .lm-chart { height: 200px; } .lm-value { font-size: 1.05rem; }
  .lm-grid { grid-template-columns: repeat(2, 1fr); }
  .lm-grid .lm-card, .lm-grid .lm-card:nth-child(n+4) { grid-column: span 1; }
  .lm-grid .lm-card:last-child { grid-column: span 2; }
}

/* Medidor de LUFS: lectura con el cursor y botón de escala */
.lm-chart { touch-action: pan-y; cursor: crosshair; }
.lm-tools { display: flex; justify-content: flex-end; margin: 8px 0 0; }
.lm-tools .viz-mini { min-height: 36px; min-width: 0; margin: 0; }

/* Afinador: indicador, fichas de cuerdas, nivel de entrada e historia */
.tn-gauge { display: block; width: 100%; max-width: 360px; aspect-ratio: 11 / 7; margin: 8px auto 4px; }
.tn-strings { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 6px 0 10px; }
.tn-chip { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-width: 54px; min-height: 44px; padding: 0 12px; font-family: var(--font-mono); font-size: 1rem; color: var(--text-muted); background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); }
.tn-chip[data-state="active"] { color: var(--text); border-color: var(--accent-cyan); }
.tn-chip[data-state="done"] { color: var(--accent-cyan); border-color: var(--accent-cyan); }
/* el tilde se dibuja con bordes, no con un carácter: no depende de que la fuente tenga el símbolo */
.tn-chip[data-state="done"]::after { content: ""; display: inline-block; width: 5px; height: 10px; margin: -3px 0 0 2px; border: solid currentColor; border-width: 0 2px 2px 0; transform: rotate(45deg); }
.tn-level { width: 100%; max-width: 360px; height: 6px; margin: 4px auto 12px; background: var(--border); border-radius: 3px; overflow: hidden; }
.tn-level > i { display: block; height: 100%; width: 0; background: var(--accent-cyan); }
.tn-caption { margin: 14px 0 4px; font-size: .75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; text-align: center; }
.tn-history { display: block; width: 100%; max-width: 560px; height: 120px; margin: 0 auto; background: var(--viz-screen); border: 1px solid var(--border); border-radius: var(--radius); }
@media (max-width: 560px) { .tn-history { height: 100px; } }

/* Fichas del afinador como botones: tocar para escuchar la nota de referencia */
button.tn-chip { cursor: pointer; }
.tn-chip:hover { border-color: var(--accent-cyan); }
.tn-chip:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.tn-chip[data-playing="1"] { border-color: var(--accent-amber); color: var(--accent-amber); }

/* Metrónomo: péndulo, fila de tiempos y grilla de patrón en un lienzo */
.mm-tempo-name { min-height: 1.4em; margin: -2px 0 4px; font-size: .85rem; letter-spacing: .08em; text-transform: uppercase; }
.mm-canvas { display: block; width: 100%; max-width: 440px; height: 300px; margin: 6px auto 14px; }
.mm-sync { max-width: 460px; margin: 16px auto 0; font-size: .85rem; color: var(--text-muted); }
.mm-sync summary { cursor: pointer; }
.mm-sync summary:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.mm-sync p { margin: 8px 0; }
@media (max-width: 480px) { .mm-canvas { height: 260px; } }

/* Metrónomo: compás, subdivisión y acentos por tiempo */
.mm-unit { min-height: 1.3em; margin: 4px 0 0; font-size: .8rem; text-align: center; }
.mm-accents-wrap { margin: 12px 0 4px; text-align: center; }
.mm-accents-label { font-size: .8rem; margin-bottom: 6px; }
.mm-accents { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.mm-beat { min-width: 44px; min-height: 44px; padding: 0; border-radius: 50%; border: 2px solid var(--text-muted); background: transparent; color: var(--text); font-family: var(--font-mono); cursor: pointer; }
.mm-beat[data-level="strong"] { border-color: var(--accent-amber); border-width: 3px; }
.mm-beat[data-level="weak"] { border-color: rgba(155, 168, 175, .6); min-width: 40px; min-height: 40px; color: var(--text-muted); }
.mm-beat[data-level="mute"] { border-style: dashed; border-color: rgba(155, 168, 175, .5); color: var(--text-muted); text-decoration: line-through; }
.mm-beat:hover:not(:disabled) { border-color: var(--accent-cyan); }
.mm-beat:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.mm-beat:disabled { opacity: .45; cursor: not-allowed; }
.mm-accents-note { min-height: 1.2em; margin-top: 6px; font-size: .8rem; }

.mm-legend { min-height: 1.2em; margin: 4px 0 0; font-size: .8rem; text-align: center; }

.mm-trainer { max-width: 460px; margin: 14px auto 4px; text-align: center; }
.mm-trainer > summary { cursor: pointer; font-size: .85rem; color: var(--text-muted); padding: 6px 0; }
.mm-trainer[open] > summary { margin-bottom: 6px; }
.mm-trainer-status { min-height: 1.3em; margin-top: 6px; font-size: .8rem; }
.mm-low { margin: 10px 0 0; text-align: center; }
.mm-low[hidden] { display: none; }
.mm-low-note { margin-top: 4px; font-size: .8rem; }

.mm-pulse { margin: 10px 0 0; text-align: center; }
.mm-pulse[hidden] { display: none; }

/* Analizador: datos agrupados, espectro promedio y lecturas con el cursor */
.az-stat-group { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 8px 24px; margin-top: 6px; }
.az-stat-group:first-child { margin-top: 0; }
.az-stat-group-title { grid-column: 1 / -1; margin: 6px 0 0; font-size: .75rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); }
@media (max-width: 560px) { .az-stat-group { grid-template-columns: 1fr; } }
.az-avg-canvas { width: 100%; height: 250px; display: block; background: #0a0d10; border: 1px solid var(--border); border-radius: var(--radius); cursor: crosshair; touch-action: pan-y; }
.az-avg-canvas:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.az-spec-canvas { cursor: crosshair; touch-action: pan-y; }
.az-readout { min-height: 1.4em; margin: 6px 0 0; font-family: var(--font-mono); font-size: .8rem; overflow-wrap: anywhere; }
.az-legend { margin: 2px 0 0; font-size: .8rem; }

/* Analizador: equilibrio por bandas (tabla con barras) y goniómetro */
.az-bands-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.az-bands-table caption { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.az-bands-table thead th { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.az-bands-table th[scope="row"] { width: 5.6em; padding: 4px 8px 4px 0; text-align: left; font-weight: 500; font-family: var(--font-mono); color: var(--text); white-space: nowrap; }
.az-band-bar-cell { padding: 4px 8px; }
.az-band-bar { height: 12px; background: rgba(155, 168, 175, .14); border-radius: 3px; overflow: hidden; }
.az-band-bar i { display: block; height: 100%; background: var(--accent-cyan); border-radius: 3px; }
.az-band-value { width: 11em; padding: 4px 0; font-family: var(--font-mono); font-size: .8rem; color: var(--text-muted); text-align: right; }
@media (max-width: 560px) { .az-band-value { width: auto; font-size: .72rem; } }
.az-gonio-canvas { display: block; width: 100%; max-width: 360px; aspect-ratio: 1 / 1; margin: 0 auto; background: #0a0d10; border: 1px solid var(--border); border-radius: var(--radius); }

/* Analizador: filas de texto largo a ancho completo y curva de sonoridad */
.az-stat-wide { grid-column: 1 / -1; }
.az-loud-canvas { width: 100%; height: 200px; display: block; background: #0a0d10; border: 1px solid var(--border); border-radius: var(--radius); cursor: crosshair; touch-action: pan-y; }
.az-loud-canvas:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
