/* ==========================================================================
   KOMAIN · base.css (v2, modo oscuro)
   @font-face, tokens, reset, tipografía, contenedores, secciones,
   utilidades, skip-link, foco, ::selection, reveal y reduced-motion.
   Fuente de verdad: docs/design-system.md (v2). Los colores SOLO se
   definen aquí; components.css y pages.css usan exclusivamente var().
   ========================================================================== */

@font-face {
  font-family: "Outfit";
  src: url("/assets/fonts/outfit-var.woff2") format("woff2-variations"),
       url("/assets/fonts/outfit-var.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: dark;

  /* ---- Paleta base (design-system 2.1) ---- */
  --navy-950: #070D17; --navy-900: #0A1220; --navy-850: #0F1A2B;
  --navy-800: #142236; --navy-700: #1D2E47;
  --gray-100: #F3F6FA; --gray-200: #DCE3EC; --gray-300: #C5CEDA;
  --gray-400: #A3AFBF; --gray-500: #999999; --gray-600: #6B7A8F;
  --teal-700: #39535D; --teal-400: #5E8794; --teal-300: #7FA9B6; --teal-200: #A9CBD5;
  --red-300: #F0868B;
  --white: #FFFFFF;

  /* ---- Roles ---- */
  --color-bg: var(--navy-900);
  --color-bg-deep: var(--navy-950);
  --surface-1: var(--navy-850);
  --surface-2: var(--navy-800);
  --surface-3: var(--navy-700);
  --surface-glass: rgb(10 18 32 / .78);

  --color-heading: var(--gray-100);
  --color-text: var(--gray-300);
  --color-text-strong: var(--gray-100);
  --color-text-muted: var(--gray-400);
  --color-label: var(--gray-500);
  --color-icon: var(--gray-200);
  --color-accent: var(--teal-300);
  --color-link-hover: var(--teal-200);
  --color-error: var(--red-300);
  --color-success: var(--teal-300);

  /* ---- Tintes translúcidos (blanco sobre oscuro) ---- */
  --tint-02: rgb(255 255 255 / .02);
  --tint-04: rgb(255 255 255 / .04);
  --tint-05: rgb(255 255 255 / .05);
  --tint-06: rgb(255 255 255 / .06);
  --tint-10: rgb(255 255 255 / .10);
  --tint-12: rgb(255 255 255 / .12);
  --tint-40: rgb(255 255 255 / .40);
  --teal-halo: rgb(127 169 182 / .18);
  --teal-line: rgb(94 135 148 / .40);
  --red-tint: rgb(240 134 139 / .08);
  --red-line: rgb(240 134 139 / .35);
  --placeholder-tint: rgb(153 153 153 / .14);

  /* ---- Bordes ---- */
  --border-subtle: rgb(255 255 255 / .07);
  --border-default: rgb(255 255 255 / .12);
  --border-strong: rgb(255 255 255 / .24);
  --border-control: var(--gray-600);
  --border-accent: rgb(127 169 182 / .45);

  /* ---- Brillos, halos y texturas (decorativos) ---- */
  --glow-top: radial-gradient(60% 55% at 50% 0%, rgb(57 83 93 / .38), transparent 70%);
  --glow-top-strong: radial-gradient(60% 70% at 50% 0%, rgb(57 83 93 / .45), transparent 72%);
  --glow-corner: radial-gradient(45% 60% at 100% 0%, rgb(57 83 93 / .30), transparent 70%);
  --glow-center: radial-gradient(50% 50% at 50% 50%, rgb(57 83 93 / .40), transparent 70%);
  --glow-navy: radial-gradient(70% 70% at 50% 40%, rgb(29 46 71 / .9), transparent 75%);
  --edge-light: linear-gradient(180deg, rgb(255 255 255 / .06), transparent 40%);
  --texture-hex: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='48'%3E%3Cpath d='M14 0l14 8v16l-14 8L0 24V8zM14 32v16' fill='none' stroke='%23999999' stroke-opacity='.08'/%3E%3C/svg%3E");
  /* Fondo global animado: trama hexagonal base (gris) e iluminada bajo el ratón (teal claro). Celda 56×96 */
  --texture-hex-bg: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='96'%3E%3Cpath d='M28 0l28 16v32L28 64 0 48V16zM28 64v32' fill='none' stroke='%23999999' stroke-opacity='.17'/%3E%3C/svg%3E");
  --texture-hex-lit: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='96'%3E%3Cpath d='M28 0l28 16v32L28 64 0 48V16zM28 64v32' fill='none' stroke='%23A9CBD5' stroke-opacity='.8' stroke-width='1.5'/%3E%3C/svg%3E");
  --hex-lit-tint: rgb(127 169 182 / .10);
  --mask-half: rgb(0 0 0 / .45);
  --surface-1-veil: rgb(15 26 43 / .72);
  /* Marcador hexagonal (sustituye a los puntos): contorno + núcleo. Se usa como máscara, el color lo pone background-color */
  --mask-hex-node: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 1.4l5.7 3.3v6.6L8 14.6l-5.7-3.3V4.7z' fill='none' stroke='black' stroke-width='1.7' stroke-linejoin='round'/%3E%3Cpath d='M8 5.5l2.2 1.25v2.5L8 10.5 5.8 9.25v-2.5z'/%3E%3C/svg%3E");
  --radar-sweep: rgb(127 169 182 / .32);
  --radar-ring: rgb(127 169 182 / .16);
  --texture-mask: radial-gradient(70% 60% at 50% 0%, #000 0%, transparent 75%);
  --fade-mask-bottom: linear-gradient(180deg, #000 70%, transparent);
  --texture-mask-center:radial-gradient(60% 70% at 50% 50%, #000 0%, transparent 75%);
  --icon-select: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23C5CEDA' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");

  /* ---- Sombras ---- */
  --shadow-card: 0 24px 48px -24px rgb(0 0 0 / .55);
  --shadow-pop: 0 16px 40px -12px rgb(0 0 0 / .6), 0 0 0 1px var(--border-default);
  --shadow-btn-glow: 0 0 0 6px rgb(127 169 182 / .12);
  --shadow-icon-halo: 0 0 24px -6px rgb(57 83 93 / .6);
  --shadow-autofill: 0 0 0 100px var(--navy-950) inset;

  /* ---- Tipografía ---- */
  --font-sans: "Outfit", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --fs-display: clamp(2.625rem, 1.6rem + 4.6vw, 5.25rem);
  --fs-h1: clamp(2.25rem, 1.5rem + 3.4vw, 4.25rem);
  --fs-h2: clamp(1.875rem, 1.3rem + 2.6vw, 3.25rem);
  --fs-h3: clamp(1.3125rem, 1.15rem + .8vw, 1.75rem);
  --fs-h4: 1.25rem;
  --fs-lead: clamp(1.125rem, 1.03rem + .45vw, 1.375rem);
  --fs-body: 1.0625rem;
  --fs-small: .9375rem;
  --fs-xs: .8125rem;
  --fs-stat: clamp(2.75rem, 2rem + 3vw, 4.5rem);
  --fw-light: 300; --fw-regular: 400; --fw-medium: 500; --fw-semibold: 600; --fw-bold: 700;
  --lh-display: 1.04; --lh-tight: 1.12; --lh-snug: 1.3; --lh-body: 1.65;
  --ls-display: -.035em; --ls-heading: -.02em; --ls-label: .08em;
  --measure: 62ch;

  /* ---- Espaciado ---- */
  --space-1: .25rem; --space-2: .5rem; --space-3: .75rem; --space-4: 1rem;
  --space-5: 1.5rem; --space-6: 2rem; --space-7: 3rem; --space-8: 4rem;
  --space-9: 6rem;  --space-10: 8rem;
  /* v2.1 (compactación): ~-35 % en escritorio y -50 % en móvil respecto a v2 */
  --section-space: clamp(2.25rem, .75rem + 5.6vw, 5.75rem);
  --section-head-gap: clamp(1.75rem, 1.2rem + 1.6vw, 3rem);
  --card-pad: clamp(1.5rem, 1rem + 2vw, 2.75rem);
  --grid-gap: clamp(1rem, .6rem + 1.4vw, 1.75rem);
  --gutter: 1.25rem;

  /* ---- Radios ---- */
  --radius-xs: 8px;
  --radius-sm: 12px;
  --radius-md: 18px;
  --radius-lg: 28px;
  --radius-xl: 40px;
  --radius-pill: 999px;

  /* ---- Contenedores ---- */
  --container: 76rem;
  --container-narrow: 46rem;
  --container-text: 40rem;
  --header-h: 4rem;

  /* ---- Foco ---- */
  --focus-ring: 2px solid var(--teal-300);
  --focus-offset: 3px;

  /* ---- Animación ---- */
  --dur-fast: 150ms;
  --dur-base: 250ms;
  --dur-slow: 650ms;
  --dur-header: 300ms;
  --ease-out: cubic-bezier(.22, 1, .36, 1);
  --ease-in-out: cubic-bezier(.65, 0, .35, 1);
  --reveal-distance: 16px;
  --reveal-stagger: 80ms;
  --hover-lift: -4px;

  --z-header: 100; --z-dropdown: 110; --z-menu: 120; --z-skip: 1000;
}

@media (min-width: 48em) { :root { --gutter: 2rem; --header-h: 4.5rem; --reveal-distance: 24px; } }
@media (min-width: 80em) { :root { --gutter: 2.5rem; } }

@media (prefers-reduced-motion: reduce) {
  :root { --dur-fast: 0ms; --dur-base: 0ms; --dur-slow: 0ms; --dur-header: 0ms; --reveal-distance: 0px; --hover-lift: 0px; }
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0ms !important;
    scroll-behavior: auto !important;
  }
}

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

* { margin: 0; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: calc(var(--header-h) + var(--space-4));
  background-color: var(--color-bg);
}

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

body {
  min-height: 100vh;
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  font-weight: var(--fw-regular);
  line-height: var(--lh-body);
  color: var(--color-text);
  background-color: transparent; /* el color lo pone html; así el fondo hexagonal fijo queda visible */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: clip;
}

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

img { height: auto; }

input,
button,
textarea,
select { font: inherit; color: inherit; }

button { cursor: pointer; background: none; border: 0; padding: 0; }

ul[class],
ol[class] { list-style: none; padding: 0; }

p,
h1, h2, h3, h4,
li,
dd,
blockquote { overflow-wrap: break-word; }

dd { margin: 0; }

table { border-collapse: collapse; width: 100%; }

::selection { background-color: var(--teal-700); color: var(--white); }

/* ---------- Tipografía ---------- */
h1, h2, h3, h4 {
  color: var(--color-heading);
  font-weight: var(--fw-medium);
  text-wrap: balance;
}

h1 { font-size: var(--fs-h1); line-height: 1.08; letter-spacing: -.03em; }
h2 { font-size: var(--fs-h2); line-height: var(--lh-tight); letter-spacing: var(--ls-heading); }
h3 { font-size: var(--fs-h3); line-height: 1.25; letter-spacing: -.01em; }
h4 { font-size: var(--fs-h4); line-height: var(--lh-snug); font-weight: var(--fw-semibold); }

.display {
  font-size: var(--fs-display);
  line-height: var(--lh-display);
  letter-spacing: var(--ls-display);
}

p { text-wrap: pretty; }

a { color: var(--color-text-strong); }

strong, b { font-weight: var(--fw-medium); color: var(--color-text-strong); }

small { font-size: var(--fs-small); }

.lead {
  max-width: var(--measure);
  font-size: var(--fs-lead);
  line-height: 1.55;
  color: var(--color-text);
  text-wrap: pretty;
}

@media (min-width: 48em) {
  .lead { font-weight: var(--fw-light); }
}

.text-muted { color: var(--color-text-muted); }

.label {
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  line-height: 1.4;
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
  color: var(--color-label);
}

.prose { max-width: var(--measure); }
.prose > * + *,
.prose > section > * + * { margin-top: var(--space-4); }
.prose h2 { margin-top: var(--space-7); }
.prose h3 { margin-top: var(--space-6); }
.prose ul,
.prose ol { padding-left: 1.25rem; }
.prose li + li { margin-top: var(--space-2); }
.prose li::marker { color: var(--gray-500); }

/* ---------- Contenedores ---------- */
.container {
  width: 100%;
  max-width: calc(var(--container) + 2 * var(--gutter));
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.container--narrow { max-width: calc(var(--container-narrow) + 2 * var(--gutter)); }
.container--text { max-width: calc(var(--container-text) + 2 * var(--gutter)); }

/* ---------- Secciones ---------- */
.section {
  position: relative;
  padding-block: var(--section-space);
  background-color: transparent;
}

.section--alt {
  background-color: var(--surface-1-veil);
  border-top: 1px solid var(--border-subtle);
}

.section--alt + .section:not(.section--alt) { border-top: 1px solid var(--border-subtle); }

.section--glow { background-image: var(--glow-top); background-repeat: no-repeat; }

/* .section--hex ya no pinta textura propia: la trama la pone el fondo global .hex-bg
   (dos tramas superpuestas se veían como un "doble fondo"). Se mantiene la clase por compatibilidad. */
.section--hex { isolation: isolate; }

/* ---------- Fondo hexagonal animado (capa .hex-bg inyectada por main.js) ----------
   Fija detrás de todo el contenido. Deriva lenta (CSS), parallax con el scroll
   (JS mueve .hex-bg__move) y trama iluminada alrededor del ratón (capa --lit).
   Sin JS: trama estática en body. Con reduced-motion: sin deriva ni parallax. */
html:not(.js) body { background-image: var(--texture-hex-bg); }

.hex-bg {
  --hex-r: 260px;
  --mx: -9999px;
  --my: -9999px;
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}

.hex-bg__layer { position: absolute; inset: 0; }

.hex-bg__layer--lit {
  /* Los degradados se declaran aquí (no en :root) para que usen --mx/--my de .hex-bg */
  background-image: radial-gradient(circle var(--hex-r) at var(--mx) var(--my), var(--hex-lit-tint), transparent 70%);
  -webkit-mask-image: radial-gradient(circle var(--hex-r) at var(--mx) var(--my), #000 0%, var(--mask-half) 45%, transparent 100%);
  mask-image: radial-gradient(circle var(--hex-r) at var(--mx) var(--my), #000 0%, var(--mask-half) 45%, transparent 100%);
  opacity: 0;
  transition: opacity 400ms ease;
}

.hex-bg.is-pointer .hex-bg__layer--lit { opacity: 1; }

.hex-bg__move {
  position: absolute;
  inset: -200px;
  will-change: transform;
}

.hex-bg__tile {
  position: absolute;
  inset: 0;
  background-image: var(--texture-hex-bg);
  background-position: 0 0;
}

.hex-bg__tile--lit { background-image: var(--texture-hex-lit); }

@media (prefers-reduced-motion: no-preference) {
  .hex-bg__tile {
    animation: hex-drift 70s linear infinite;
    will-change: transform;
  }
}

/* Desplaza exactamente una celda (56×96) para que el bucle no tenga salto */
@keyframes hex-drift {
  from { transform: translate3d(0, 0, 0); }
  to   { transform: translate3d(-56px, -96px, 0); }
}

.section--tight-top { padding-top: var(--space-6); }
.section--tight-bottom { padding-bottom: var(--space-6); }

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

.icon {
  width: 1.5rem;
  height: 1.5rem;
  flex-shrink: 0;
}

.icon--sm { width: 1rem; height: 1rem; }
.icon--md { width: 1.25rem; height: 1.25rem; }

.tabular { font-variant-numeric: tabular-nums; }

.mt-gap { margin-top: var(--grid-gap); }
.mt-head { margin-top: var(--section-head-gap); }
.center { text-align: center; }

/* ---------- Skip-link ---------- */
.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-4);
  z-index: var(--z-skip);
  padding: .75rem 1.25rem;
  background-color: var(--gray-100);
  color: var(--navy-700);
  font-weight: var(--fw-semibold);
  text-decoration: none;
  border-radius: var(--radius-pill);
}

.skip-link:focus {
  top: var(--space-4);
  left: var(--space-4);
}

/* ---------- Foco ---------- */
:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
}

main:focus { outline: none; }

/* ---------- Reveal (design-system 3.21) ----------
   Solo se oculta con .js y sin preferencia de movimiento reducido:
   sin JS o con reduced-motion el contenido es visible siempre. */
@media (prefers-reduced-motion: no-preference) {
  .js [data-reveal]:not(.is-revealed) { opacity: 0; transform: translateY(var(--reveal-distance)); }
  .js [data-reveal="fade"]:not(.is-revealed) { transform: none; }
  .js [data-reveal="scale"]:not(.is-revealed) { transform: scale(.97); }
  .js [data-reveal] {
    transition: opacity var(--dur-slow) var(--ease-out), transform var(--dur-slow) var(--ease-out);
    transition-delay: calc(var(--reveal-i, 0) * var(--reveal-stagger));
  }
  .js [data-reveal-delay="1"] { --reveal-i: 1; }
  .js [data-reveal-delay="2"] { --reveal-i: 2; }
  .js [data-reveal-delay="3"] { --reveal-i: 3; }
}
