/* ============================================================
   ACCESIBILIDAD & RENDIMIENTO v5.0 · Academia de Luz
   WCAG 2.2 AA · navegación por teclado · lectores de pantalla
   ============================================================ */

/* ─── 1 · Salto al contenido ────────────────────────────────── */
.skip-link {
  position: fixed;
  top: -100px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100000;
  padding: 13px 26px;
  border-radius: 0 0 16px 16px;
  font-family: 'Outfit', system-ui, sans-serif;
  font-size: .82rem;
  font-weight: 700;
  letter-spacing: .06em;
  color: #04060c;
  background: linear-gradient(120deg, #c084fc, #22d3ee);
  box-shadow: 0 10px 30px rgba(34, 211, 238, .45);
  text-decoration: none;
  transition: top .28s cubic-bezier(.22, 1, .36, 1);
}
.skip-link:focus,
.skip-link:focus-visible,
.skip-link:active {
  top: 0 !important;
  outline: 3px solid #fbbf24;
  outline-offset: 2px;
}
/* El intro cubre la pantalla: ocultar el salto mientras se reproduce */
html.gx-lock .skip-link { display: none; }

/* ─── 2 · Solo para lectores de pantalla ───────────────────── */
.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;
}
.sr-only-focusable:focus,
.sr-only-focusable:focus-visible {
  position: static !important;
  width: auto; height: auto;
  margin: 0; overflow: visible;
  clip: auto; white-space: normal;
}

/* ─── 3 · Foco visible coherente en toda la app ────────────── */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid #22d3ee;
  outline-offset: 3px;
  border-radius: 8px;
}
button:focus-visible,
a:focus-visible,
[role="button"]:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid #22d3ee;
  outline-offset: 3px;
  box-shadow: 0 0 0 5px rgba(34, 211, 238, .18);
}
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid #c084fc;
  outline-offset: 1px;
  box-shadow: 0 0 0 4px rgba(192, 132, 252, .16);
}
/* Área táctil mínima recomendada (WCAG 2.2 · 2.5.8) */
button, a[role="button"], [role="button"] { min-height: 24px; }

/* ─── 4 · Contenido semántico visible sin JavaScript ───────── */
.noscript-seo {
  max-width: 780px;
  margin: 0 auto;
  padding: 56px 24px;
  font-family: 'Outfit', system-ui, sans-serif;
  color: #e9d5ff;
  line-height: 1.75;
}
.noscript-seo h1 {
  font-family: 'Cinzel', Georgia, serif;
  font-size: 2rem;
  margin-bottom: 18px;
  background: linear-gradient(120deg, #c084fc, #22d3ee, #fbbf24);
  -webkit-background-clip: text; background-clip: text;
  color: transparent; -webkit-text-fill-color: transparent;
}
.noscript-seo h2 { font-family: 'Cinzel', Georgia, serif; font-size: 1.25rem; margin: 30px 0 12px; color: #f5f2ff; }
.noscript-seo ul { padding-left: 22px; }
.noscript-seo li { margin-bottom: 8px; color: rgba(201, 189, 240, .9); }
.noscript-seo p { margin-bottom: 14px; color: rgba(201, 189, 240, .85); }

/* ─── 5 · Revelado de la app al terminar el intro ──────────── */
body.app-reveal #app > * {
  animation: appReveal 900ms cubic-bezier(.22, 1, .36, 1) both;
}
@keyframes appReveal {
  0%   { opacity: 0; transform: translateY(22px) scale(.985); filter: blur(7px); }
  100% { opacity: 1; transform: translateY(0) scale(1);       filter: blur(0); }
}
body.app-reveal .cosmos { animation: cosmosReveal 1500ms ease-out both; }
@keyframes cosmosReveal { from { opacity: 0; } to { opacity: 1; } }

/* ─── 6 · Rendimiento: aislar repintados de capas animadas ─── */
.aurora-orb,
.soul-bar-fill,
.gx-nebula { will-change: transform, opacity; }

.cosmos { contain: layout style paint; }
#toast-container { contain: layout style; }
.sanctuary-tile,
.soul-stat,
.card-hover { contain: layout style; }

/* Imágenes: evitar saltos de maquetación (CLS) */
img { max-width: 100%; height: auto; }
img[loading="lazy"] { background: rgba(148, 118, 255, .04); }

/* ─── 7 · Alto contraste ───────────────────────────────────── */
@media (prefers-contrast: more) {
  :root {
    --text-mid: #e5dcff;
    --text-low: #c4b5fd;
    --border-soft: rgba(196, 181, 253, .45);
    --border-strong: rgba(196, 181, 253, .7);
  }
  .glass { background: rgba(14, 19, 29, .92) !important; border-color: rgba(196, 181, 253, .4) !important; }
  .ss-sub, .st-desc { color: rgba(201, 189, 240, .85) !important; }
  :focus-visible { outline-width: 3px; }
}

/* ─── 8 · Movimiento reducido: sin animación decorativa ────── */
@media (prefers-reduced-motion: reduce) {
  body.app-reveal #app > *,
  body.app-reveal .cosmos { animation: none !important; }
  .aurora-orb, .soul-bar-fill { animation: none !important; }
  html { scroll-behavior: auto !important; }
}

/* ─── 9 · Impresión: certificados y lecciones legibles ─────── */
@media print {
  .cosmos, #genesis, #v4-layer, #toast-container,
  .sanctuary-fab, .skip-link, nav, header button { display: none !important; }
  body { background: #fff !important; color: #111 !important; }
  .glass { background: #fff !important; border: 1px solid #ccc !important; box-shadow: none !important; }
  a { color: #111 !important; text-decoration: underline; }
  a[href^="http"]::after { content: " (" attr(href) ")"; font-size: .8em; color: #555; }
}

/* ─── 10 · Desplazamiento suave con anclas y compensación ──── */
html { scroll-behavior: smooth; }
:target { scroll-margin-top: 88px; }

/* ============================================================
   11 · BLINDAJE ANTI-DESBORDAMIENTO
   Los hijos de grid/flex traen min-width:auto, así que un
   contenido ancho (píldoras nowrap, tablas, código) revienta
   el layout en móvil. Aquí se corta de raíz.
   ============================================================ */
html, body { max-width: 100%; overflow-x: hidden; }

/* Contenedores scrollables horizontales: permitir que encojan */
.overflow-x-auto,
.scroll-thin,
[class*="overflow-x"] { min-width: 0; }

/* Columnas de grid y flex-items: encogibles por defecto */
.grid > *,
.flex > * { min-width: 0; }
/* Excepción: elementos marcados explícitamente como no encogibles */
.grid > .shrink-0,
.flex > .shrink-0,
.grid > .flex-shrink-0,
.flex > .flex-shrink-0 { min-width: auto; }

/* Textos largos sin espacios (URLs, correos) no rompen la caja */
p, span, h1, h2, h3, h4, li, td, dd, dt, label { overflow-wrap: break-word; }

/* Media siempre contenida */
img, svg, video, canvas, iframe { max-width: 100%; }

/* Barras de desplazamiento finas y acordes al tema */
.scroll-thin { scrollbar-width: thin; scrollbar-color: rgba(148,118,255,.4) transparent; }
.scroll-thin::-webkit-scrollbar { height: 5px; width: 5px; }
.scroll-thin::-webkit-scrollbar-track { background: transparent; }
.scroll-thin::-webkit-scrollbar-thumb { background: rgba(148,118,255,.35); border-radius: 99px; }
.scroll-thin::-webkit-scrollbar-thumb:hover { background: rgba(34,211,238,.5); }
