/* ============================================================
   TUNER — Afinador cromático
   Usa variables y base de style.css. Estética oscura del home.
   ============================================================ */

:root {
  --tune-ok: #55efc4;      /* verde: afinado */
  --tune-close: #fdcb6e;   /* ámbar: cerca */
  --tune-off: #ff7675;     /* rojo: lejos */
  --tune-idle: #888;
}

.tuner-body { overflow: auto; height: auto; min-height: 100vh; }

#tuner-app {
  display: flex; flex-direction: column;
  min-height: 100vh;
}

/* ---- Header (mismo patrón que learn.html) ---- */
#tuner-header {
  display: flex; flex-direction: column; gap: 8px;
  padding: 14px 24px 12px;
  background: var(--bg);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  position: sticky; top: 0; z-index: 100;
  backdrop-filter: blur(12px);
}
#tuner-header #header-top {
  display: flex; align-items: center; justify-content: space-between;
}
#tuner-header h1 {
  font-size: 15px; font-weight: 600; letter-spacing: 0.4px;
  display: flex; align-items: center; gap: 8px;
}
.site-title-link { color: var(--text); text-decoration: none; transition: color 0.2s; }
.site-title-link:hover { color: #fff; }
.title-sep { color: var(--text-muted); font-weight: 400; }
.title-section { color: var(--major); font-weight: 500; }
.header-left { display: flex; align-items: center; gap: 10px; }
.back-link {
  text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 14px; padding: 4px 10px;
  border-color: rgba(232,67,147,0.3);
  color: var(--major);
  min-width: 32px;
}
.back-link:hover {
  background: rgba(232,67,147,0.1);
  border-color: rgba(232,67,147,0.5);
  color: #fff;
}
.header-actions { display: flex; gap: 6px; align-items: center; position: relative; }

/* Control de calibración A4 */
#a4-control {
  display: inline-flex; align-items: center; gap: 6px;
  cursor: default; font-variant-numeric: tabular-nums;
}
#a4-control button {
  background: none; border: none; color: var(--text-muted);
  font-size: 14px; font-family: inherit; cursor: pointer;
  padding: 0 4px; line-height: 1; border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}
#a4-control button:hover { color: #fff; background: rgba(255,255,255,0.1); }
#a4-value { font-size: 11px; min-width: 84px; text-align: center; }

/* Sub-selector de número de cuerdas */
#count-chips { display: inline-flex; gap: 4px; }
#count-chips .chip { font-size: 10px; padding: 3px 8px; }

/* ---- Main ---- */
#tuner-main {
  flex: 1;
  display: flex; flex-direction: column; align-items: center;
  gap: 14px;
  padding: 26px 20px 40px;
  width: 100%; max-width: 560px; margin: 0 auto;
}

/* Nota detectada */
#note-display { text-align: center; min-height: 96px; }
#note-name {
  font-size: 72px; font-weight: 700; line-height: 1;
  color: var(--tune-idle);
  transition: color 0.2s ease, text-shadow 0.3s ease;
  font-variant-numeric: tabular-nums;
}
#note-octave { font-size: 36px; font-weight: 500; opacity: 0.7; margin-left: 2px; }
#freq-readout {
  font-size: 13px; color: var(--text-muted); margin-top: 6px;
  font-variant-numeric: tabular-nums;
}

/* Colores según desviación (se aplican a #tuner-app) */
.tune-ok #note-name    { color: var(--tune-ok); text-shadow: 0 0 24px rgba(85,239,196,0.45); }
.tune-close #note-name { color: var(--tune-close); text-shadow: 0 0 18px rgba(253,203,110,0.3); }
.tune-off #note-name   { color: var(--tune-off); }

/* ---- Galga ---- */
#gauge-wrap {
  position: relative;
  width: 100%; max-width: 420px;
  border-radius: 18px;
  background: var(--bg-light);
  border: 1px solid rgba(255,255,255,0.08);
  padding: 18px 12px 10px;
  transition: box-shadow 0.35s ease, border-color 0.35s ease;
}
.tune-ok #gauge-wrap {
  border-color: rgba(85,239,196,0.45);
  box-shadow: 0 0 28px rgba(85,239,196,0.18), inset 0 0 22px rgba(85,239,196,0.05);
}
.tune-ok.tune-stable #gauge-wrap {
  border-color: rgba(85,239,196,0.75);
  box-shadow: 0 0 40px rgba(85,239,196,0.32), inset 0 0 26px rgba(85,239,196,0.08);
}
.tune-close #gauge-wrap { border-color: rgba(253,203,110,0.35); }

#gauge { width: 100%; height: auto; display: block; }

#gauge-ticks line { stroke: rgba(255,255,255,0.28); stroke-width: 1.5; }
#gauge-ticks line.tick-major { stroke: rgba(255,255,255,0.55); stroke-width: 2; }
#gauge-labels text {
  fill: var(--text-muted); font-size: 12px; font-family: 'Inter', sans-serif;
  text-anchor: middle; font-variant-numeric: tabular-nums;
}
#center-mark { stroke: var(--tune-ok); stroke-width: 3; stroke-linecap: round; opacity: 0.9; }

#needle {
  stroke: var(--tune-idle); stroke-width: 3.5; stroke-linecap: round;
  transition: stroke 0.2s ease;
}
#needle-group {
  transform-origin: 200px 205px;
  transition: transform 0.12s ease-out;
}
.tune-ok #needle    { stroke: var(--tune-ok); }
.tune-close #needle { stroke: var(--tune-close); }
.tune-off #needle   { stroke: var(--tune-off); }
#needle-pivot { fill: #2a2a2a; stroke: rgba(255,255,255,0.25); stroke-width: 1.5; }

#cents-readout {
  text-align: center; font-size: 16px; font-weight: 600;
  color: var(--text-muted); padding: 4px 0 6px;
  font-variant-numeric: tabular-nums;
  transition: color 0.2s ease;
}
.tune-ok #cents-readout    { color: var(--tune-ok); }
.tune-close #cents-readout { color: var(--tune-close); }
.tune-off #cents-readout   { color: var(--tune-off); }

/* Estado */
#tuner-status {
  font-size: 13px; color: var(--text-muted); min-height: 20px;
  letter-spacing: 0.3px; transition: color 0.25s ease;
}
.tune-ok.tune-stable #tuner-status { color: var(--tune-ok); font-weight: 600; }

/* ---- Cuerdas del instrumento ---- */
#strings-row {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 8px;
  max-width: 420px;
}
.string-btn {
  background: transparent; color: var(--text-muted);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px; padding: 9px 14px;
  font-size: 14px; font-weight: 600; font-family: inherit;
  cursor: pointer; min-width: 52px;
  transition: all 0.2s ease;
  font-variant-numeric: tabular-nums;
}
.string-btn:hover { border-color: rgba(255,255,255,0.3); color: var(--text); }
.string-btn.near {
  border-color: rgba(116,185,255,0.6);
  color: #74b9ff;
  background: rgba(116,185,255,0.08);
}
.string-btn.locked {
  border-color: var(--major);
  color: #fff;
  background: rgba(232,67,147,0.18);
  box-shadow: 0 0 14px rgba(232,67,147,0.25);
}
.string-btn.auto-btn { font-weight: 500; font-size: 12px; opacity: 0.85; }

#target-readout {
  font-size: 12px; color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ---- Botón de inicio ---- */
#start-btn {
  margin-top: 6px;
  background: linear-gradient(135deg, rgba(232,67,147,0.22), rgba(0,206,201,0.14));
  border: 1px solid rgba(232,67,147,0.45);
  color: #fff; font-family: inherit;
  font-size: 15px; font-weight: 600; letter-spacing: 0.4px;
  padding: 13px 44px; border-radius: 14px;
  cursor: pointer;
  box-shadow: 0 2px 14px rgba(232,67,147,0.15);
  transition: all 0.22s ease;
}
#start-btn:hover {
  background: linear-gradient(135deg, rgba(232,67,147,0.36), rgba(0,206,201,0.24));
  border-color: rgba(232,67,147,0.7);
  box-shadow: 0 4px 22px rgba(232,67,147,0.3);
  transform: translateY(-1px);
}
#start-btn:active { transform: translateY(0); }
#start-btn.running {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.2);
  color: var(--text-muted);
  box-shadow: none;
}
#start-btn.running:hover { color: var(--text); border-color: rgba(255,255,255,0.35); }

#mic-error {
  font-size: 13px; color: var(--tune-off);
  background: rgba(255,118,117,0.08);
  border: 1px solid rgba(255,118,117,0.3);
  border-radius: 10px; padding: 10px 16px;
  max-width: 420px; text-align: center; line-height: 1.5;
}

/* ---- Responsive ---- */
@media (max-width: 600px) {
  #tuner-header { padding: 10px 12px 8px; }
  .chip-label { display: none; }
  #note-name { font-size: 58px; }
  #note-octave { font-size: 28px; }
  #note-display { min-height: 82px; }
  #tuner-main { padding: 18px 14px 30px; gap: 12px; }
  #a4-value { min-width: 72px; font-size: 10px; }
}
@media (max-width: 380px) {
  .title-sep, .site-title-link { display: none; }
}

/* Medidor de nivel de entrada */
#level-meter {
  width: 200px;
  height: 4px;
  margin: 6px auto 0;
  background: rgba(255,255,255,0.08);
  border-radius: 2px;
  overflow: hidden;
}
#level-fill {
  height: 100%;
  width: 0;
  background: #55efc4;
  border-radius: 2px;
  transition: width 0.1s linear;
}
#level-fill.low { background: rgba(255,255,255,0.25); }
