*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0d1421;
  --card: rgba(255, 255, 255, 0.045);
  --card-border: rgba(255, 255, 255, 0.08);
  --text: #eef2f8;
  --muted: #8b96a8;
  --accent: #4f8cff;
  --good: #3ddc97;
  --warn: #ffb75d;
  --bad: #ff5d73;
  --radius: 20px;
}

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* Fondos animados */
.bg-glow {
  position: fixed;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.35;
  pointer-events: none;
  z-index: 0;
  animation: drift 16s ease-in-out infinite alternate;
}
.bg-glow-1 { width: 420px; height: 420px; background: #2a4d8f; top: -140px; left: -120px; }
.bg-glow-2 { width: 380px; height: 380px; background: #1f6b52; bottom: -120px; right: -110px; animation-delay: -8s; }

@keyframes drift {
  from { transform: translate(0, 0) scale(1); }
  to   { transform: translate(60px, 40px) scale(1.15); }
}

.app {
  position: relative;
  z-index: 1;
  max-width: 480px;
  margin: 0 auto;
  padding: 18px 16px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Header */
.header { display: flex; align-items: center; justify-content: space-between; }
.logo { display: flex; align-items: center; gap: 10px; color: var(--accent); }
.logo h1 { font-size: 1.25rem; font-weight: 700; color: var(--text); letter-spacing: 0.3px; }
.logo h1 span { color: var(--accent); }

.icon-btn {
  background: var(--card);
  border: 1px solid var(--card-border);
  color: var(--muted);
  width: 42px; height: 42px;
  border-radius: 12px;
  display: grid; place-items: center;
  cursor: pointer;
  transition: color 0.2s, transform 0.2s, border-color 0.2s;
}
.icon-btn:hover { color: var(--text); border-color: var(--accent); }
.icon-btn:active { transform: scale(0.92); }

/* Selector de instrumento */
.inst-select {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 10px 12px;
  backdrop-filter: blur(12px);
}
.inst-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.inst-now { display: flex; align-items: center; gap: 12px; min-width: 0; }
.inst-now-icon {
  width: 48px; height: 48px;
  display: grid; place-items: center;
  color: var(--accent);
  background: linear-gradient(145deg, rgba(79, 140, 255, 0.22), rgba(79, 140, 255, 0.06));
  border: 1px solid rgba(79, 140, 255, 0.35);
  border-radius: 14px;
  flex-shrink: 0;
}
.inst-now-icon svg { width: 30px; height: 30px; }
.inst-now-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.inst-now-text strong { font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inst-now-text small { font-size: 0.7rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.change-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(79, 140, 255, 0.14);
  border: 1px solid rgba(79, 140, 255, 0.4);
  color: var(--accent);
  font-weight: 700;
  font-size: 0.8rem;
  border-radius: 999px;
  padding: 9px 14px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.15s;
}
.change-btn:hover { background: rgba(79, 140, 255, 0.22); }
.change-btn:active { transform: scale(0.95); }
.change-btn svg { transition: transform 0.3s cubic-bezier(0.34, 1.3, 0.64, 1); }
.change-btn.open svg { transform: rotate(180deg); }

.inst-panel {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.4s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.3s, margin-top 0.4s;
  margin-top: 0;
}
.inst-panel.open {
  max-height: 600px;
  opacity: 1;
  margin-top: 12px;
}
.inst-btn {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--card-border);
  color: var(--muted);
  border-radius: 14px;
  padding: 10px 4px;
  font-size: 0.7rem;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.inst-btn .inst-icon { display: grid; place-items: center; color: inherit; transition: color 0.25s; }
.inst-btn .inst-icon svg { width: 26px; height: 26px; }
.inst-btn:hover { border-color: var(--accent); color: var(--text); }
.inst-btn.active {
  background: linear-gradient(145deg, rgba(79, 140, 255, 0.22), rgba(79, 140, 255, 0.08));
  border-color: var(--accent);
  color: var(--text);
  box-shadow: 0 8px 20px rgba(79, 140, 255, 0.18);
}
.inst-btn.active .inst-icon { color: var(--accent); }

/* Tarjeta del medidor */
.tuner-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 18px 16px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  backdrop-filter: blur(12px);
}

.ref-pill {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  border: 1px solid var(--card-border);
  border-radius: 999px;
  padding: 4px 12px;
  letter-spacing: 0.5px;
}

.gauge-wrap { position: relative; width: 100%; max-width: 340px; }
#gauge { width: 100%; display: block; overflow: visible; }

.arc-bg { fill: none; stroke: rgba(255,255,255,0.06); stroke-width: 12; stroke-linecap: round; }
.arc-color { fill: none; stroke-width: 12; stroke-linecap: round; opacity: 0.9; }
.zone-good {
  fill: none;
  stroke: var(--good);
  stroke-width: 12;
  stroke-linecap: round;
  opacity: 0.55;
  transition: opacity 0.25s, filter 0.25s;
}
.gauge-wrap.in-tune .zone-good { opacity: 1; filter: url(#softGlow); }
.tick { stroke: rgba(255,255,255,0.22); stroke-width: 2; }
.tick.major { stroke: rgba(255,255,255,0.45); stroke-width: 2.5; }
.tick-label { fill: var(--muted); font-size: 10px; text-anchor: middle; font-weight: 600; }
.center-marker {
  fill: rgba(255,255,255,0.35);
  transition: fill 0.25s, filter 0.25s;
}
.gauge-wrap.in-tune .center-marker { fill: var(--good); filter: drop-shadow(0 0 6px var(--good)); }

#needle { transition: transform 0.1s cubic-bezier(0.34, 1.2, 0.64, 1); }
.needle-line { stroke: var(--text); stroke-width: 3.5; stroke-linecap: round; filter: drop-shadow(0 2px 6px rgba(0,0,0,0.5)); }
.needle-hub { fill: #1c2839; stroke: rgba(255,255,255,0.55); stroke-width: 2; }
.needle-hub-inner { fill: var(--text); }

.gauge-wrap.in-tune .needle-line { stroke: var(--good); filter: drop-shadow(0 0 8px var(--good)); }
.gauge-wrap.in-tune .needle-hub { stroke: var(--good); }
.gauge-wrap.in-tune .needle-hub-inner { fill: var(--good); }

/* La nota vive DENTRO del hueco del arco: nunca se sale de la tarjeta */
.note-display {
  position: absolute;
  left: 50%;
  top: 46%;
  transform: translateX(-50%);
  text-align: center;
  width: 60%;
  pointer-events: none;
}
.note-name {
  font-size: 2.7rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -1px;
  transition: color 0.2s, text-shadow 0.2s;
  font-variant-numeric: tabular-nums;
}
.gauge-wrap.in-tune .note-name { color: var(--good); text-shadow: 0 0 24px rgba(61, 220, 151, 0.5); }
.note-meta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 6px;
  font-size: 0.78rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
#noteFreq { min-width: 64px; text-align: right; }
.cents-badge {
  font-weight: 700;
  border-radius: 8px;
  padding: 2px 8px;
  background: rgba(255,255,255,0.07);
  min-width: 58px;
  text-align: center;
  transition: color 0.2s, background 0.2s;
}
.cents-badge.good { color: var(--good); background: rgba(61,220,151,0.12); }
.cents-badge.warn { color: var(--warn); background: rgba(255,183,93,0.12); }
.cents-badge.bad  { color: var(--bad);  background: rgba(255,93,115,0.12); }

.status-line {
  margin-top: 4px;
  font-size: 0.85rem;
  color: var(--muted);
  min-height: 1.3em;
  text-align: center;
  transition: color 0.25s;
}
.status-line.tuned { color: var(--good); font-weight: 700; animation: pop 0.4s ease; }
@keyframes pop {
  0% { transform: scale(0.85); }
  60% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

.mic-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, #4f8cff, #3ddc97);
  color: #08101c;
  font-weight: 700;
  font-size: 0.9rem;
  border: none;
  border-radius: 999px;
  padding: 12px 22px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s, opacity 0.2s;
  box-shadow: 0 8px 24px rgba(79, 140, 255, 0.3);
}
.mic-btn:hover { transform: translateY(-1px); box-shadow: 0 10px 28px rgba(79, 140, 255, 0.4); }
.mic-btn:active { transform: scale(0.96); }
.mic-btn.listening {
  background: rgba(255, 93, 115, 0.15);
  color: var(--bad);
  box-shadow: none;
  border: 1px solid rgba(255, 93, 115, 0.4);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 93, 115, 0.25); }
  50% { box-shadow: 0 0 0 10px rgba(255, 93, 115, 0); }
}

/* Cuerdas */
.strings-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 16px;
  backdrop-filter: blur(12px);
}
.strings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.strings-head h2 { font-size: 0.9rem; font-weight: 600; color: var(--muted); }

.auto-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.auto-toggle input { display: none; }
.toggle-track {
  width: 38px; height: 22px;
  border-radius: 999px;
  background: rgba(255,255,255,0.12);
  position: relative;
  transition: background 0.25s;
}
.toggle-thumb {
  position: absolute;
  top: 3px; left: 3px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.25s cubic-bezier(0.34, 1.4, 0.64, 1), background 0.25s;
}
.auto-toggle input:checked + .toggle-track { background: rgba(79, 140, 255, 0.4); }
.auto-toggle input:checked + .toggle-track .toggle-thumb { transform: translateX(16px); background: var(--accent); }

/* Transpositor */
.transpose-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 8px 12px;
  margin-bottom: 12px;
}
.transpose-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.4px;
}
.transpose-ctrl {
  display: flex;
  align-items: center;
  gap: 6px;
}
.trans-btn {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  border: 1px solid rgba(79, 140, 255, 0.4);
  background: rgba(79, 140, 255, 0.12);
  color: var(--accent);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.2s, transform 0.12s, opacity 0.2s;
}
.trans-btn:hover:not(:disabled) { background: rgba(79, 140, 255, 0.22); }
.trans-btn:active:not(:disabled) { transform: scale(0.9); }
.trans-btn:disabled { opacity: 0.3; cursor: default; }
.trans-note {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 96px;
}
.trans-note strong {
  font-size: 1.15rem;
  font-weight: 800;
  line-height: 1.1;
  transition: color 0.2s;
}
.trans-note strong.altered { color: var(--warn); }
.trans-note small {
  font-size: 0.62rem;
  color: var(--muted);
  white-space: nowrap;
}

.strings {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(64px, 1fr));
  gap: 8px;
}
.string-btn {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 10px 4px;
  color: var(--text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: all 0.22s;
}
.string-btn .s-note { font-size: 1.05rem; font-weight: 800; }
.string-btn .s-freq { font-size: 0.62rem; color: var(--muted); }
.string-btn .s-num { font-size: 0.58rem; color: var(--muted); opacity: 0.7; }
.string-btn:hover { border-color: var(--accent); }
.string-btn.target {
  border-color: var(--accent);
  background: rgba(79, 140, 255, 0.15);
  box-shadow: 0 0 16px rgba(79, 140, 255, 0.2);
  transform: translateY(-2px);
}
.string-btn.tuned {
  border-color: var(--good);
  background: rgba(61, 220, 151, 0.12);
}
.string-btn.tuned .s-note { color: var(--good); }
.string-btn.tuned::after { content: "✓"; font-size: 0.6rem; color: var(--good); font-weight: 800; }

/* Sheet de ajustes */
.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  z-index: 40;
}
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translate(-50%, 105%);
  width: min(480px, 100%);
  background: #141d2e;
  border: 1px solid var(--card-border);
  border-bottom: none;
  border-radius: 24px 24px 0 0;
  padding: 12px 20px calc(24px + env(safe-area-inset-bottom));
  z-index: 50;
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.sheet.open { transform: translate(-50%, 0); }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: rgba(255,255,255,0.2); margin: 0 auto; }
.sheet h2 { font-size: 1rem; font-weight: 700; text-align: center; }

.freq-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.freq-btn {
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  color: var(--text);
  padding: 14px 6px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: all 0.2s;
}
.freq-btn small { font-size: 0.62rem; font-weight: 500; color: var(--muted); }
.freq-btn.active {
  border-color: var(--accent);
  background: rgba(79, 140, 255, 0.15);
  box-shadow: 0 0 16px rgba(79, 140, 255, 0.2);
}

.custom-freq {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.step-btn {
  width: 44px; height: 44px;
  border-radius: 12px;
  border: 1px solid var(--card-border);
  background: rgba(255,255,255,0.06);
  color: var(--text);
  font-size: 1.4rem;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}
.step-btn:active { transform: scale(0.9); background: rgba(79,140,255,0.2); }
#customFreqInput {
  width: 100px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  color: var(--text);
  font-size: 1.2rem;
  font-weight: 700;
  text-align: center;
  padding: 10px 6px;
  -moz-appearance: textfield;
}
#customFreqInput::-webkit-outer-spin-button, #customFreqInput::-webkit-inner-spin-button { -webkit-appearance: none; }
.hz-label { color: var(--muted); font-weight: 600; }

.sheet-close {
  background: var(--accent);
  border: none;
  border-radius: 14px;
  color: #08101c;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 14px;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
}
.sheet-close:active { transform: scale(0.98); }

/* ===== Anuncios (AdSense) ===== */
.ad-rail, .ad-bottom { display: none; }

/* Marcadores de posición (solo en localhost mientras no hay IDs reales) */
.ad-slot-placeholder {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border: 1px dashed rgba(255, 255, 255, 0.18);
  border-radius: 12px;
  color: rgba(255, 255, 255, 0.3);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  background: rgba(255, 255, 255, 0.02);
}

/* Escritorio: rieles laterales 160x600 + banner inferior en el flujo */
@media (min-width: 900px) {
  body.ads-on .ad-rail {
    display: block;
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    width: 160px;
    height: 600px;
    max-height: 85vh;
    z-index: 5;
  }
  body.ads-on .ad-left  { left: calc(50% - 420px); }
  body.ads-on .ad-right { right: calc(50% - 420px); }
  body.ads-on .ad-bottom {
    display: block;
    width: 100%;
    max-width: 448px;
    height: 90px;
    margin: 6px auto 0;
  }
}

/* Móvil y tablet: solo una barra fija abajo, discreta */
@media (max-width: 899px) {
  body.ads-on .ad-bottom {
    display: block;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: calc(56px + env(safe-area-inset-bottom));
    padding: 3px 8px calc(3px + env(safe-area-inset-bottom));
    background: rgba(13, 20, 33, 0.92);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--card-border);
    z-index: 25;
  }
  body.ads-on .app { padding-bottom: 92px; }
  /* El banner de instalación y el toast suben para no quedar tapados */
  body.ads-on .install-banner { bottom: calc(76px + env(safe-area-inset-bottom)); }
  body.ads-on .toast { bottom: calc(84px + env(safe-area-inset-bottom)); }
}

.adsbygoogle { display: block; width: 100%; height: 100%; }

/* Banner de instalación */
.install-banner {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(448px, calc(100% - 24px));
  display: flex;
  align-items: center;
  gap: 12px;
  background: linear-gradient(145deg, #1a2740, #141d2e);
  border: 1px solid rgba(79, 140, 255, 0.35);
  border-radius: 18px;
  padding: 12px 14px;
  z-index: 30;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  animation: banner-in 0.5s cubic-bezier(0.34, 1.3, 0.64, 1);
}
.install-banner[hidden] { display: none; }
@keyframes banner-in {
  from { transform: translate(-50%, 90px); opacity: 0; }
  to   { transform: translate(-50%, 0); opacity: 1; }
}
.ib-icon { width: 44px; height: 44px; border-radius: 12px; flex-shrink: 0; }
.ib-text { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.ib-text strong { font-size: 0.88rem; }
.ib-text span { font-size: 0.72rem; color: var(--muted); line-height: 1.35; }
.ib-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.ib-install {
  background: linear-gradient(135deg, #4f8cff, #3ddc97);
  color: #08101c;
  border: none;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.82rem;
  padding: 9px 16px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s;
  box-shadow: 0 6px 16px rgba(79, 140, 255, 0.3);
}
.ib-install:active { transform: scale(0.94); }
.ib-dismiss {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.9rem;
  width: 32px; height: 32px;
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.ib-dismiss:hover { background: rgba(255,255,255,0.08); color: var(--text); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 80px);
  background: #1c2839;
  border: 1px solid var(--card-border);
  color: var(--text);
  font-size: 0.82rem;
  padding: 10px 18px;
  border-radius: 999px;
  opacity: 0;
  transition: transform 0.3s, opacity 0.3s;
  z-index: 60;
  pointer-events: none;
  max-width: 90vw;
  text-align: center;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

@media (max-width: 380px) {
  .note-name { font-size: 2.6rem; }
  .inst-btn { font-size: 0.65rem; }
}
