/* ===== Tokens de tema ===== */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --text: #1a1d21;
  --text-soft: #5b6573;
  --border: #d9dee5;
  --accent: #1f6feb;
  --accent-contrast: #ffffff;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
  --radius: 14px;
  --maxw: 680px;
}

html[data-theme="dark"] {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1c232d;
  --text: #e6edf3;
  --text-soft: #9aa7b4;
  --border: #2a323c;
  --accent: #4b95ff;
  --accent-contrast: #06101f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.55;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ===== Accesibilidad ===== */
.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: -999px; top: 0;
  background: var(--accent); color: var(--accent-contrast);
  padding: 10px 14px; border-radius: 0 0 8px 0; z-index: 10;
}
.skip-link:focus { left: 0; }

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 8px;
}

/* ===== Cabecera / pie ===== */
.site-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  max-width: var(--maxw); width: 100%;
  margin: 0 auto; padding: 16px 18px 8px;
}
.logo {
  margin: 0; font-size: 1.5rem; letter-spacing: -.01em; font-weight: 700;
}
.header-actions { display: flex; align-items: center; gap: 10px; }
.install-btn {
  background: var(--accent); color: var(--accent-contrast);
  border: none; border-radius: 999px;
  padding: 9px 16px; font-size: .9rem; font-weight: 600;
  white-space: nowrap;
  touch-action: manipulation;
  transition: filter .15s ease;
}
.install-btn:hover { filter: brightness(1.05); }

.site-footer {
  margin-top: auto;
  text-align: center; color: var(--text-soft);
  font-size: .8rem; padding: 24px 18px;
}
.site-footer a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}
.site-footer a:hover { text-decoration: underline; }

/* ===== Contenedor ===== */
.container {
  max-width: var(--maxw); width: 100%;
  margin: 0 auto; padding: 8px 18px 24px;
  display: flex; flex-direction: column; gap: 16px;
}

/* ===== Buscadores ===== */
.buscador { display: flex; flex-direction: column; gap: 8px; }

.numero-row {
  display: flex; gap: 8px; align-items: stretch;
}

.numero-input {
  flex: 1 1 auto; min-width: 0;
  text-align: center;
  font-size: 1.5rem; font-weight: 600;
}

/* Oculta las flechas nativas del input number */
.numero-input::-webkit-outer-spin-button,
.numero-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.numero-input { -moz-appearance: textfield; }

input[type="number"],
input[type="search"] {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 1rem;
  width: 100%;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input::placeholder { color: var(--text-soft); }
input[type="number"]:focus,
input[type="search"]:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}

.ayuda { margin: 0; color: var(--text-soft); font-size: .8rem; padding-left: 4px; }

/* ===== Botones ===== */
button {
  font: inherit; cursor: pointer; border: none;
  -webkit-tap-highlight-color: transparent;
}
.primary-btn {
  background: var(--accent); color: var(--accent-contrast);
  border-radius: var(--radius);
  padding: 0 22px; font-weight: 600; font-size: 1rem;
  transition: filter .15s ease, transform .05s ease;
}
.primary-btn:hover { filter: brightness(1.05); }
.primary-btn:active { transform: translateY(1px); }

.nav-btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 52px; flex: 0 0 52px;
  font-size: 1.7rem; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s ease;
}
.nav-btn:hover { background: var(--surface-2); }
.nav-btn:disabled { opacity: .4; cursor: not-allowed; }

.icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 44px; height: 44px;
  font-size: 1.2rem;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--surface-2); }

/* ===== Indice completo (toggle "Ver todos") ===== */
.indice-toggle {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 1rem; font-weight: 600;
  transition: background .15s ease;
  touch-action: manipulation;
}
.indice-toggle:hover { background: var(--surface-2); }
.indice-chevron {
  color: var(--text-soft);
  transition: transform .2s ease;
}
.indice-toggle[aria-expanded="true"] .indice-chevron { transform: rotate(180deg); }

.indice-lista {
  max-height: 60vh; margin-top: 8px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
/* En movil la lista fluye en la pagina (sin scroll interno): asi los toques
   se registran como tap y no como intento de scroll. */
@media (max-width: 539px) {
  .indice-lista { max-height: none; overflow: visible; }
}

/* ===== Resultados de busqueda ===== */
.resultados {
  list-style: none; margin: 0; padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-height: 320px; overflow-y: auto;
}
.resultados li { margin: 0; }
.resultados button {
  width: 100%; text-align: left;
  background: transparent; color: var(--text);
  padding: 12px; border-radius: 10px;
  display: flex; gap: 10px; align-items: baseline;
  min-height: 44px;
  touch-action: manipulation;
}
.resultados button:hover,
.resultados button:focus-visible { background: var(--surface-2); }
.resultados .r-num {
  color: var(--accent); font-weight: 700;
  min-width: 2.6em; flex: 0 0 auto;
}
.resultados .r-titulo { color: var(--text); }
.resultados .vacio { padding: 12px; color: var(--text-soft); text-align: center; }

/* ===== Himno ===== */
.himno {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px 26px;
}
.himno-cabecera {
  display: flex; gap: 12px; align-items: baseline;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px; margin-bottom: 14px;
}
.himno-numero {
  font-size: 2rem; font-weight: 800; color: var(--accent);
  line-height: 1; flex: 0 0 auto;
}
.himno-titulo {
  margin: 0; font-size: 1.12rem; font-weight: 600;
  color: var(--text); letter-spacing: -.005em;
}
.himno-cuerpo {
  word-wrap: break-word;
  font-size: 1.06rem;
  line-height: 1.7;
}

/* Estrofas */
.estrofa {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 22px;
}
.estrofa:last-child { margin-bottom: 0; }

/* El número de estrofa es un marcador, NO parte de la letra: se muestra como
   una insignia discreta en su propia columna, separada del texto cantado. */
.estrofa-num {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.7rem;
  height: 1.7rem;
  margin-top: .15rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--accent);
  font-weight: 700;
  font-size: .82rem;
  line-height: 1;
  user-select: none;
}

/* Estrofas sin número (intros, coros sueltos): alinear con las numeradas */
.estrofa.sin-num { padding-left: calc(1.7rem + 14px); }

.estrofa-cuerpo {
  flex: 1 1 auto;
  min-width: 0;
}

.coro-label {
  display: inline-block;
  font-size: .72em;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-soft);
}

.refran {
  font-style: italic;
  color: var(--text-soft);
}

.mensaje {
  text-align: center; color: var(--text-soft);
  padding: 18px; margin: 0;
}
.mensaje.error { color: #c0392b; }
html[data-theme="dark"] .mensaje.error { color: #ff7b72; }

/* ===== Pantallas grandes ===== */
@media (min-width: 540px) {
  .himno-cuerpo { font-size: 1.1rem; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
