/* ==========================================================================
   HEADER — Barra fija, navegación y control de tema
   ========================================================================== */

.header {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 200;
  padding: 0.5rem 0;
  background: transparent;
  border-bottom: 1px solid transparent;
  transition: background 0.3s var(--ease), border-color 0.3s var(--ease),
              box-shadow 0.3s var(--ease), padding 0.3s var(--ease);
}

/* Estado al hacer scroll — lo activa script.js */
.header.is-scrolled {
  padding: 0.25rem 0;
  background: rgba(255, 255, 255, 0.85); /* respaldo si no hay color-mix */
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(18px) saturate(1.6);
  border-bottom-color: var(--border);
  box-shadow: 0 1px 24px rgb(13 19 28 / 0.06);
}
:root.dark .header.is-scrolled {
  background: rgba(7, 10, 16, 0.8);
  box-shadow: 0 1px 30px rgb(0 0 0 / 0.5);
}

/* Barra de progreso de lectura */
.header__progress {
  position: absolute;
  bottom: -1px; left: 0;
  height: 2px;
  width: 0;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  box-shadow: 0 0 12px var(--glow);
  transition: width 0.1s linear;
  pointer-events: none;
}

.header__inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

/* ── Logo ─────────────────────────────────────────────── */
.header__brand {
  display: flex;
  align-items: center;
  line-height: 0;
  flex-shrink: 0;
}
.logo {
  height: 64px;
  width: auto;
  transition: height 0.3s var(--ease), filter 0.3s;
}
.header.is-scrolled .logo { height: 52px; }
:root.dark .logo { filter: brightness(0) invert(1); }

@media (max-width: 768px) {
  .logo,
  .header.is-scrolled .logo { height: 48px; }
}

/* ── Navegación ───────────────────────────────────────── */
.nav {
  display: flex;
  gap: 0.25rem;
  align-items: center;
}

.nav a:not(.btn) {
  position: relative;
  padding: 0.5rem 0.8rem;
  border-radius: var(--r-full);
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.92rem;
  transition: color 0.2s, background 0.2s;
}
.nav a:not(.btn):hover {
  color: var(--text);
  background: var(--surface-2);
}
.nav a.nav-active {
  color: var(--primary);
  font-weight: 600;
  background: var(--tint);
}
:root.dark .nav a.nav-active { color: var(--primary-lite); }

.nav .btn { margin-left: 0.5rem; }

/* ── Control de tema ──────────────────────────────────── */
.theme-toggle {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 40px; height: 40px;
  min-width: 40px;
  cursor: pointer;
  display: grid;
  place-items: center;
  color: var(--text-soft);
  margin-left: 0.4rem;
  transition: color 0.2s, border-color 0.2s, transform 0.35s var(--ease-back);
}
.theme-toggle:hover {
  color: var(--primary);
  border-color: var(--primary);
  transform: rotate(-25deg);
}
.theme-toggle svg { width: 17px; height: 17px; }
.icon-sun { display: none; }
:root.dark .icon-sun  { display: block; }
:root.dark .icon-moon { display: none; }

/* ── Botón hamburguesa ────────────────────────────────── */
.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 42px; height: 42px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  cursor: pointer;
  padding: 0 10px;
  z-index: 210;
}
.nav-toggle span {
  display: block;
  width: 100%; height: 2px;
  border-radius: 2px;
  background: var(--text);
  transition: transform 0.3s var(--ease), opacity 0.2s;
}
.nav-toggle.is-open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-toggle.is-open span:nth-child(2) { opacity: 0; }
.nav-toggle.is-open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ── Móvil ────────────────────────────────────────────── */
@media (max-width: 900px) {
  .nav-toggle { display: flex; }

  .nav {
    position: fixed;
    top: 0; right: 0;
    height: 100dvh;
    width: min(320px, 84vw);
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 0.2rem;
    padding: 5.5rem 1.5rem 2rem;
    background: var(--bg);
    border-left: 1px solid var(--border);
    box-shadow: -20px 0 60px rgb(0 0 0 / 0.25);
    transform: translateX(105%);
    /* `visibility` saca el panel cerrado del recorrido del tabulador: solo con
       `transform` los enlaces siguen siendo enfocables fuera de pantalla. */
    visibility: hidden;
    transition: transform 0.38s var(--ease), visibility 0.38s;
    z-index: 190;
    overflow-y: auto;
  }
  :root.dark .nav { background: var(--surface); }

  .nav.show { transform: translateX(0); visibility: visible; }

  .nav a:not(.btn) {
    padding: 0.85rem 1rem;
    border-radius: var(--r-sm);
    font-size: 1rem;
  }
  .nav .btn { margin: 0.85rem 0 0; }
  .theme-toggle { margin: 1.25rem 0 0; align-self: flex-start; }
}

/* Telón detrás del menú móvil */
.nav-backdrop {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 0.45);
  backdrop-filter: blur(3px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
  z-index: 180;
}
.nav-backdrop.show { opacity: 1; visibility: visible; }
