/* ============================================================
   main.css
   Variables, reset, tipografía y layout base.
   Cuento: "Los Hilos del Agua y el Plato de las Preguntas"
   ============================================================ */

/* ---------- Variables (paleta "Hilos del Agua") ---------- */
:root {
  /* ===== PALETA PRINCIPAL ===== */
  --color-primary: #1F4E79;        /* Azul profundo */
  --color-accent: #C9A227;         /* Dorado hilo */
  --color-bg: #F4F1E8;             /* Crema papel */
  --color-warm: #B85C38;           /* Terracota Cali */
  --color-text: #2C2C2C;           /* Negro suave */
  --color-text-muted: #5A5A5A;     /* Gris suave */

  /* ===== NEUTROS ===== */
  --color-bg-alt: #FFFFFF;         /* Blanco para tarjetas */
  --color-bg-soft: #EFEAD8;        /* Crema más profunda */
  --color-border: #E0DCC8;         /* Bordes suaves */

  /* ===== ACENTOS TEMÁTICOS ===== */
  --color-sunrise: #E8B547;        /* Amanecer */
  --color-water: #3D7FB8;          /* Agua */
  --color-field: #7A8B5E;          /* Campo */
  --color-river: #9B6B9E;          /* Río atardecer */
  --color-hope: #5BA66B;           /* Esperanza */

  /* ===== ESTADOS ===== */
  --color-link: #1F4E79;
  --color-link-hover: #C9A227;
  --color-success: #5BA66B;
  --color-error: #B85C38;

  /* ===== Aliases para compatibilidad con CSS heredado =====
     El proyecto ya usaba estos nombres ampliamente; los mantenemos
     mapeados a la nueva paleta para no romper estilos existentes. */
  --color-secondary: var(--color-water);
  --color-leaf: var(--color-field);
  --color-night: #1F2A3A;           /* azul profundo casi-negro para fondos */
  --color-cream: var(--color-bg);
  --color-ink: var(--color-text);
  --color-muted: var(--color-text-muted);
  --color-bubble-bg: var(--color-bg-alt);
  --color-bubble-border: var(--color-text);
  --color-panel-border: var(--color-text);
  --color-shadow: rgba(31, 42, 58, 0.18);
  --color-shadow-strong: rgba(31, 42, 58, 0.30);

  /* Tipografía */
  --font-display: "Fredoka", "Comic Sans MS", system-ui, cursive;
  --font-body: "Patrick Hand", "Comic Sans MS", system-ui, cursive;

  /* Tamaños base (mobile-first) */
  --fs-xs: 0.85rem;
  --fs-sm: 1rem;
  --fs-md: 1.15rem;
  --fs-lg: 1.4rem;
  --fs-xl: 1.8rem;
  --fs-2xl: 2.4rem;
  --fs-display: 2rem;

  /* Espacios */
  --space-xs: 0.4rem;
  --space-sm: 0.75rem;
  --space-md: 1.25rem;
  --space-lg: 2rem;
  --space-xl: 3rem;

  /* Radios */
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-pill: 999px;

  /* Sombras */
  --shadow-soft: 0 6px 18px var(--color-shadow);
  --shadow-card: 0 10px 28px var(--color-shadow);
  --shadow-strong: 0 14px 38px var(--color-shadow-strong);

  /* Layout */
  --header-height: 72px;
  --panel-max-width-desktop: 900px;
  --content-padding: clamp(1rem, 4vw, 2.5rem);

  /* Transiciones */
  --t-fast: 160ms ease;
  --t-base: 280ms cubic-bezier(0.22, 1, 0.36, 1);
  --t-slow: 520ms cubic-bezier(0.22, 1, 0.36, 1);
}

/* ---------- Reset moderno y ligero ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  background: var(--color-night);
}

body {
  min-height: 100dvh;
  font-family: var(--font-body);
  font-size: var(--fs-md);
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

img,
svg,
picture,
video {
  max-width: 100%;
  display: block;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

h1,
h2,
h3,
h4 {
  font-family: var(--font-display);
  color: var(--color-night);
  margin: 0;
  letter-spacing: 0.5px;
  line-height: 1.15;
}

p {
  margin: 0;
}

/* ---------- Accesibilidad: focus visible ---------- */
:focus {
  outline: none;
}

:focus-visible {
  outline: 3px dashed var(--color-accent);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}

/* Respeto a usuarios con sensibilidad al movimiento */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---------- Layout base ---------- */
#app {
  position: relative;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle at 20% 10%, rgba(201, 162, 39, 0.18), transparent 55%),
    radial-gradient(circle at 80% 90%, rgba(61, 127, 184, 0.18), transparent 55%),
    var(--color-cream);
}

/* ---------- Canvas de partículas inmersivas ----------
   El canvas vive detrás de toda la historia. Lo manejará el JS.
   z=0 → encima del fondo del body, debajo de los paneles (z=1). */
#immersion-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

/* ---------- Preloader ---------- */
.preloader {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-night);
  color: var(--color-primary);
  transition: opacity var(--t-slow), visibility var(--t-slow);
}

.preloader.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.preloader__inner {
  text-align: center;
  display: grid;
  gap: var(--space-md);
  justify-items: center;
}

.preloader__star {
  width: 80px;
  height: 80px;
  color: var(--color-primary);
  filter: drop-shadow(0 0 18px rgba(201, 162, 39, 0.7));
}

.preloader {
  background:
    radial-gradient(ellipse at 50% 30%, rgba(201, 162, 39, 0.12), transparent 60%),
    linear-gradient(180deg, #182030 0%, var(--color-night) 60%, #121826 100%);
}

.preloader__text {
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  color: var(--color-cream);
  letter-spacing: 1px;
  display: inline-flex;
  align-items: baseline;
  gap: 2px;
}

.preloader__text-label {
  display: inline-block;
}

.preloader__dots {
  display: inline-flex;
  gap: 2px;
}

.preloader__dots span {
  display: inline-block;
  opacity: 0.3;
  animation: preloaderDot 1.4s ease-in-out infinite;
}

.preloader__dots span:nth-child(2) { animation-delay: 0.2s; }
.preloader__dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes preloaderDot {
  0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
  40%          { opacity: 1;    transform: translateY(-3px); }
}

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--content-padding);
  background: linear-gradient(
    180deg,
    rgba(244, 241, 232, 0.95) 0%,
    rgba(244, 241, 232, 0.75) 100%
  );
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 2px solid rgba(44, 44, 44, 0.08);
  min-height: var(--header-height);
}

.site-header__inner {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.site-header__title {
  font-size: var(--fs-xl);
  color: var(--color-night);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.site-header__subtitle {
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  color: var(--color-muted);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Indicador de capítulo ---------- */
.chapter-indicator {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  padding: 6px 14px;
  background: var(--color-night);
  color: var(--color-cream);
  border-radius: var(--radius-pill);
  font-family: var(--font-display);
  font-size: var(--fs-sm);
  box-shadow: var(--shadow-soft);
  user-select: none;
}

.chapter-indicator__label {
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 0.7rem;
  color: var(--color-primary);
}

.chapter-indicator__number {
  font-size: var(--fs-md);
  font-weight: 600;
}

.chapter-indicator__divider {
  color: rgba(244, 241, 232, 0.4);
}

.chapter-indicator__total {
  font-size: var(--fs-sm);
  color: rgba(244, 241, 232, 0.7);
}

/* ---------- Botón mute ---------- */
.mute-toggle {
  width: 44px;
  height: 44px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  background: var(--color-primary);
  color: var(--color-night);
  box-shadow: var(--shadow-soft);
  transition: transform var(--t-fast), background var(--t-fast);
}

.mute-toggle:hover {
  transform: scale(1.06);
  background: #E5C04A;
}

.mute-toggle:active {
  transform: scale(0.96);
}

.mute-toggle__icon {
  width: 22px;
  height: 22px;
}

.mute-toggle__icon--off {
  display: none;
}

.mute-toggle[aria-pressed="true"] .mute-toggle__icon--on {
  display: none;
}

.mute-toggle[aria-pressed="true"] .mute-toggle__icon--off {
  display: block;
}

/* ---------- Story container ----------
   Por encima del canvas de partículas (z-index 1) pero por debajo
   del header (50). Lleva un fondo gradient noche -> crema y un sutil
   vignette radial para un look más cinematográfico. */
.story-container {
  flex: 1;
  position: relative;
  width: 100%;
  z-index: 2;
  background: linear-gradient(
    180deg,
    rgba(31, 42, 58, 0.18) 0%,
    rgba(244, 241, 232, 0.0) 18%,
    rgba(244, 241, 232, 0.0) 82%,
    rgba(31, 42, 58, 0.15) 100%
  );
}

.story-container::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(
    ellipse at 50% 50%,
    transparent 50%,
    rgba(31, 42, 58, 0.15) 100%
  );
  opacity: 0.15;
  z-index: 0;
}

.story-container > * {
  position: relative;
  z-index: 1;
}

/* ---------- Header: estado "encogido" tras scroll ----------
   La clase .header-shrunk la aplica el JS cuando scrollY > 80.
   Si no la aplica, no pasa nada. */
.site-header {
  transition:
    padding var(--t-base),
    min-height var(--t-base),
    background var(--t-base),
    box-shadow var(--t-base);
}

.site-header.header-shrunk {
  min-height: 52px;
  padding-top: 4px;
  padding-bottom: 4px;
  background: linear-gradient(
    180deg,
    rgba(244, 241, 232, 0.92) 0%,
    rgba(244, 241, 232, 0.78) 100%
  );
  box-shadow: 0 4px 12px rgba(31, 42, 58, 0.12);
}

.site-header.header-shrunk .site-header__title {
  font-size: var(--fs-lg);
  transition: font-size var(--t-base);
}

.site-header.header-shrunk .site-header__subtitle {
  opacity: 0;
  max-height: 0;
  overflow: hidden;
  transition: opacity var(--t-fast), max-height var(--t-base);
}

.site-header__title,
.site-header__subtitle {
  transition: font-size var(--t-base), opacity var(--t-base), max-height var(--t-base);
}

/* ---------- Footer ---------- */
.site-footer {
  padding: var(--space-lg) var(--content-padding);
  text-align: center;
  color: var(--color-text-muted);
  background: transparent;
}

.site-footer__credits {
  font-family: var(--font-display);
  font-size: var(--fs-md);
  margin-bottom: var(--space-xs);
  color: var(--color-text);
}

.site-footer__credits strong {
  color: var(--color-primary);
}

.site-footer__hint {
  font-size: var(--fs-sm);
  color: var(--color-text-muted);
  font-style: italic;
}

/* ---------- Utilidades ---------- */
.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
