/* ─────────────────────────────────────────────────────────────
   Tema oscuro + botón para cambiar de tema. Se carga el último.
   El tema se activa con <html data-theme="dark"> (lo pone js/theme.js y lo recuerda).
   Casi todo cambia solo porque las secciones usan los colores --cm-*; aquí se redefinen
   y se corrige lo que tenía blancos o negros escritos a mano.
   ───────────────────────────────────────────────────────────── */

:root[data-theme="dark"] {
  color-scheme: dark;
  --cm-paper: #0a0a0a;
  --cm-mist: #121211;
  --cm-sand: #1e1e1d;
  --cm-ink: #f4f4f2;
  --cm-smoke: #a3a3a3;
  --cm-line: rgb(255 255 255 / 0.12);
}

/* Bloques de contraste: en oscuro son una superficie apenas más clara que el fondo */
[data-theme="dark"] .cm-bg-ink,
[data-theme="dark"] .cm-block-dark {
  --fg: var(--cm-ink);
  --muted: var(--cm-ash);
  --line: rgb(255 255 255 / 0.12);
  --surface: #222221;
  background: #171716;
  color: var(--cm-ink);
}

/* El texto sobre el degradado de marca sigue siendo negro */
[data-theme="dark"] .cm-btn,
[data-theme="dark"] ::selection {
  color: #0a0a0a;
}
[data-theme="dark"] .cm-text-fade {
  background-image: linear-gradient(180deg, var(--cm-ink) 45%, #8f8f8c 100%);
}
[data-theme="dark"] .cm-bar {
  background-color: rgb(10 10 10 / 0.8);
}

/* Cristal: mismos brillos, sobre negro */
[data-theme="dark"] .glass {
  border-color: rgb(255 255 255 / 0.1);
  background: linear-gradient(145deg, rgb(255 255 255 / 0.09), rgb(255 255 255 / 0.03) 45%, rgb(255 255 255 / 0.06));
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 0.14),
    0 24px 60px -30px rgb(0 0 0 / 0.8);
}
[data-theme="dark"] .glass::before {
  background: radial-gradient(120% 80% at 0% 0%, rgb(255 255 255 / 0.08), transparent 55%);
}
[data-theme="dark"] .pricing__card--featured {
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 0.14),
    0 0 0 1px rgb(255 140 0 / 0.5),
    0 30px 80px -30px rgb(255 140 0 / 0.45);
}

/* ── Cabecera: botón de tema junto al de compra ── */
.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.header-actions .btn-brand {
  display: none;
}
@media (min-width: 40rem) {
  .header-actions .btn-brand {
    display: inline-flex;
  }
}
/* En móvil el logo va centrado y el botón de tema queda a la derecha */
@media (max-width: 39.99rem) {
  body > header > div {
    position: relative;
  }
  .header-actions {
    position: absolute;
    right: clamp(1.25rem, 4vw, 4.5rem);
  }
}

.theme-toggle {
  position: relative;
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--fg);
  cursor: pointer;
  transition:
    transform 160ms var(--ease-out),
    border-color 200ms ease;
}
/* Sin JS el botón no hace nada: sigue oculto */
.theme-toggle[hidden] {
  display: none;
}
.theme-toggle:active {
  transform: scale(0.94);
}
@media (hover: hover) and (pointer: fine) {
  .theme-toggle:hover {
    border-color: var(--fg);
  }
}
/* Luna en claro, sol en oscuro: una gira y sale mientras la otra entra */
.theme-toggle svg {
  position: absolute;
  width: 1.125rem;
  height: 1.125rem;
  transition:
    opacity 300ms var(--ease-out),
    transform 400ms var(--ease-out);
}
.theme-toggle__sun,
[data-theme="dark"] .theme-toggle__moon {
  opacity: 0;
  transform: rotate(-90deg) scale(0.6);
}
[data-theme="dark"] .theme-toggle__sun {
  opacity: 1;
  transform: none;
}

/* ── Cambio de tema: el tema nuevo se abre en círculo desde el botón (View Transitions) ── */
::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
}
::view-transition-new(root) {
  animation: theme-reveal 650ms var(--ease-in-out-sine);
}
@keyframes theme-reveal {
  from {
    clip-path: circle(0 at var(--theme-x, 100%) var(--theme-y, 0));
  }
  to {
    clip-path: circle(var(--theme-r, 150vmax) at var(--theme-x, 100%) var(--theme-y, 0));
  }
}

@media (prefers-reduced-motion: reduce) {
  .theme-toggle,
  .theme-toggle svg {
    transition: opacity 200ms ease;
  }
  .theme-toggle:active {
    transform: none;
  }
  .theme-toggle__sun,
  [data-theme="dark"] .theme-toggle__moon {
    transform: none;
  }
}
