:root {
  --bg: #04060b;
  --ink: #eaf0f7;
  --muted: rgba(234, 240, 247, .66);
  --faint: rgba(234, 240, 247, .42);
  --line: rgba(234, 240, 247, .14);
  --line-2: rgba(234, 240, 247, .28);
  --ice: #9fe8ff;
  --sans: "General Sans", "Helvetica Neue", Arial, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --gutter: clamp(16px, 4.5vw, 64px);
  --ease: cubic-bezier(.16, 1, .3, 1);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { overflow-x: clip; scroll-behavior: smooth; -webkit-text-size-adjust: 100%; scrollbar-color: rgba(234,240,247,.25) var(--bg); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.6 var(--sans);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  caret-color: var(--ice);
}
body.is-intro { overflow: hidden; }
a { color: inherit; }
svg { display: block; }
::selection { background: var(--ice); color: #02040a; }
:focus-visible { outline: 1.5px solid var(--ice); outline-offset: 4px; }
::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: rgba(234,240,247,.22); border: 3px solid var(--bg); border-radius: 10px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
  text-transform: none; letter-spacing: normal;
}
.mono { font-family: var(--mono); font-size: 11.5px; letter-spacing: .16em; text-transform: uppercase; }

/* icono flecha (SVG propio vía máscara) */
.arr {
  display: inline-block; width: .95em; height: .95em; flex: none;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.6' stroke-linecap='square'%3E%3Cpath d='M7 17 17 7M9 7h8v8'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.6' stroke-linecap='square'%3E%3Cpath d='M7 17 17 7M9 7h8v8'/%3E%3C/svg%3E") center / contain no-repeat;
  transition: transform .5s var(--ease);
}

/* ================= INTRO ================= */
#intro {
  position: fixed; inset: 0; z-index: 100;
  background: radial-gradient(ellipse at center, #0b1220 0%, #020309 72%);
  transition: opacity 1.1s var(--ease), visibility 1.1s;
}
#intro.is-out { opacity: 0; visibility: hidden; pointer-events: none; }
#intro-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.intro-label {
  position: absolute; bottom: clamp(32px, 9vh, 80px); left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  font: 400 11px/1 var(--mono); letter-spacing: .6em; color: var(--faint); padding-left: .6em;
}
.intro-bar { width: 140px; height: 1px; background: var(--line); overflow: hidden; }
.intro-bar i { display: block; height: 100%; width: 100%; background: var(--ink); transform-origin: left; animation: bar 3s linear forwards; }
@keyframes bar { from { transform: scaleX(0); } to { transform: scaleX(1); } }
.intro-skip {
  position: absolute; top: 16px; right: 16px; min-height: 44px;
  background: none; border: 1px solid var(--line); color: var(--muted);
  font: 400 11px var(--mono); letter-spacing: .14em; text-transform: uppercase;
  padding: 0 18px; cursor: pointer; transition: color .3s, border-color .3s;
}
.intro-skip:hover { color: var(--ink); border-color: var(--line-2); }

/* ================= MUNDO ================= */
#world { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; display: block; }
body.no-webgl #world { display: none; }
body.no-webgl { background: radial-gradient(120% 80% at 70% 110%, #12305a 0%, #0a1426 35%, var(--bg) 70%); background-attachment: fixed; }
.vignette {
  position: fixed; inset: 0; z-index: 1; pointer-events: none;
  background: radial-gradient(130% 100% at 50% 45%, transparent 55%, rgba(2,3,8,.7) 100%);
}
#orbit { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 1; pointer-events: none; }
body.no-webgl #orbit { display: none; }
#fx-canvas { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 90; pointer-events: none; }

#site { position: relative; z-index: 2; opacity: 0; visibility: hidden; transition: opacity 1.4s var(--ease); }
body:not(.is-intro) #site { opacity: 1; visibility: visible; }

/* ================= NAV ================= */
.nav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 14px var(--gutter);
  background: linear-gradient(to bottom, rgba(4,6,11,.75), rgba(4,6,11,0));
}
.nav-links { display: flex; gap: clamp(14px, 2.4vw, 32px); }
.nav-links a, .tool {
  display: inline-flex; align-items: center; gap: 10px; min-height: 44px;
  font: 400 11px var(--mono); letter-spacing: .16em; text-transform: uppercase;
  color: var(--muted); text-decoration: none; transition: color .3s;
}
.nav-links a:hover, .tool:hover { color: var(--ink); }
.wordmark {
  justify-self: center; display: inline-flex; align-items: center; min-height: 44px;
  font: 400 clamp(15px, 1.5vw, 19px)/1 var(--sans); letter-spacing: .32em; text-decoration: none;
  padding-left: .32em; white-space: nowrap;
}
.nav-tools { justify-self: end; display: flex; align-items: center; gap: clamp(10px, 2vw, 26px); }
.tool { background: none; border: 0; padding: 0 2px; cursor: pointer; }
.lang { display: flex; gap: 2px; }
.lang .tool { padding: 0 8px; }
.lang .tool[aria-pressed="true"] { color: var(--ink); text-decoration: underline; text-underline-offset: 6px; text-decoration-thickness: 1px; }

@media (max-width: 760px) {
  .nav { grid-template-columns: auto 1fr; }
  .nav-links { display: none; }
  .wordmark { justify-self: start; letter-spacing: .22em; padding-left: 0; font-size: 13px; }
}

/* ================= HUD ================= */
.hud { position: fixed; inset: 0; z-index: 40; pointer-events: none; font: 400 10.5px var(--mono); letter-spacing: .16em; color: var(--faint); text-transform: uppercase; }
.hud-bl, .hud-br { position: absolute; bottom: 22px; transition: opacity .6s var(--ease); }
body.in-lab .hud-bl, body.in-lab .hud-br { opacity: 0; }
.hud-bl { left: var(--gutter); }
.hud-br { right: var(--gutter); font-variant-numeric: tabular-nums; }
.hud-br span:first-child { color: var(--muted); }
.hud-rail {
  position: absolute; right: var(--gutter); top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; align-items: flex-end; gap: 14px;
  opacity: 0; transition: opacity .8s var(--ease);
}
body.in-chapters .hud-rail { opacity: 1; }
.hud-rail ol { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; align-items: flex-end; }
.hud-rail li { display: flex; align-items: center; gap: 10px; transition: color .5s; }
.hud-rail li::after { content: ""; width: 36px; height: 1px; background: currentColor; transform: scaleX(.39); transform-origin: right; transition: transform .6s var(--ease); }
.hud-rail li.on { color: var(--ink); }
.hud-rail li.on::after { transform: none; background: var(--accent, var(--ink)); }
@media (min-width: 1101px) { .chapter.right { padding-right: calc(var(--gutter) + 110px); } }
@media (max-width: 1100px) { .hud-rail { display: none; } }
@media (max-width: 760px) { .hud { display: none; } }

/* ================= TIPOGRAFÍA ================= */
.display {
  margin: 0; font-family: var(--sans); font-weight: 300; text-transform: uppercase;
  font-size: clamp(36px, 7vw, 6rem); line-height: 1; letter-spacing: -.01em;
  text-wrap: balance;
}
.display .line { display: block; }
.display .dim { color: var(--muted); }
.caption {
  max-width: 62ch; margin: 28px auto 0;
  font: 400 clamp(15px, 1.25vw, 17px)/1.7 var(--sans); letter-spacing: .01em; color: var(--muted);
}

/* letras que convergen desde la dispersión */
[data-converge] .w { display: inline-block; white-space: nowrap; }
[data-converge] .c {
  display: inline-block; opacity: 0;
  transform: translate3d(var(--x), var(--y), 0) scale(var(--s));
  filter: blur(var(--b));
  transition: transform 1.9s var(--ease) var(--d), opacity 1.2s var(--ease) var(--d), filter 1.6s var(--ease) var(--d);
  will-change: transform, filter, opacity;
}
[data-converge].in .c { opacity: 1; transform: none; filter: blur(0); }
[data-converge].done .c { will-change: auto; }

.fade { opacity: 0; transform: translateY(18px); filter: blur(6px); transition: opacity 1.2s var(--ease), transform 1.2s var(--ease), filter 1.2s var(--ease); }
.fade.in { opacity: 1; transform: none; filter: none; }

/* ================= BOTONES ================= */
.bracket {
  --tick: var(--ink);
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 12px;
  min-height: 52px; padding: 0 30px; margin-top: 40px;
  background: var(--ink); color: #04060b; text-decoration: none;
  font: 500 11.5px var(--mono); letter-spacing: .16em; text-transform: uppercase;
  transition: background-color .4s var(--ease), color .4s var(--ease);
}
.bracket > span { display: inline-flex; align-items: center; gap: 12px; }
.bracket::before {
  content: ""; position: absolute; inset: -7px; pointer-events: none;
  background:
    linear-gradient(var(--tick), var(--tick)) 0 0 / 3px 3px,
    linear-gradient(var(--tick), var(--tick)) 100% 0 / 3px 3px,
    linear-gradient(var(--tick), var(--tick)) 0 100% / 3px 3px,
    linear-gradient(var(--tick), var(--tick)) 100% 100% / 3px 3px;
  background-repeat: no-repeat;
  transition: inset .5s var(--ease);
}
.bracket:hover::before, .bracket:focus-visible::before { inset: -13px; }
.bracket:hover .arr { transform: translate(3px, -3px); }
.bracket.ghost { background: rgba(4,6,11,.35); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line-2); --tick: var(--accent, var(--ink)); }
.bracket.ghost:hover, .bracket.ghost:focus-visible { background: var(--ink); color: #04060b; }

/* ================= HERO ================= */
.hero {
  min-height: 100vh; min-height: 100svh;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  padding: 120px var(--gutter) 120px; position: relative;
}
.hero .display { font-size: clamp(38px, 7.6vw, 6rem); }
.scroll-hint { position: absolute; bottom: 26px; left: 50%; display: flex; flex-direction: column; align-items: center; gap: 12px; color: var(--faint); }
.scroll-hint.fade { transform: translate(-50%, 18px); }
.scroll-hint.fade.in { transform: translateX(-50%); }
.scroll-hint i { width: 1px; height: 44px; background: var(--line); position: relative; overflow: hidden; }
.scroll-hint i::after { content: ""; position: absolute; left: 0; top: -40%; width: 100%; height: 40%; background: var(--ink); animation: drip 2.2s var(--ease) infinite; }
@keyframes drip { to { top: 100%; } }

/* ================= PROYECTOS ================= */
.chapter-intro {
  min-height: 100vh; min-height: 100svh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 120px var(--gutter);
}

.chapter {
  position: relative; min-height: 100vh; min-height: 100svh;
  display: flex; align-items: center; padding: 120px var(--gutter);
}
.chapter::before {
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: -1;
  background: radial-gradient(55% 75% at 22% 50%, rgba(3,5,10,.78), rgba(3,5,10,0) 72%);
}
.chapter.right { justify-content: flex-end; }
.chapter.right::before { background: radial-gradient(55% 75% at 78% 50%, rgba(3,5,10,.78), rgba(3,5,10,0) 72%); }
.panel { max-width: 540px; }
.meta { margin: 0 0 22px; color: var(--muted); }
.meta .idx { color: var(--accent); }
.chapter h3.display { font-size: clamp(34px, 5vw, 5rem); overflow-wrap: break-word; }
.tagline { margin: 22px 0 0; font-size: clamp(17px, 1.5vw, 20px); font-weight: 400; color: var(--ink); }
.desc { margin: 16px 0 0; font-size: 15px; line-height: 1.75; color: var(--muted); max-width: 62ch; }
.chips { list-style: none; padding: 0; margin: 24px 0 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chips li { font: 400 10.5px var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); padding: 7px 11px; box-shadow: inset 0 0 0 1px var(--line); }
.chapter .bracket { margin-top: 38px; }

@media (max-width: 760px) {
  .chapter, .chapter.right { align-items: flex-end; justify-content: flex-start; padding-bottom: 72px; }
  .chapter::before, .chapter.right::before { background: linear-gradient(to top, rgba(3,5,10,.92) 0%, rgba(3,5,10,.7) 55%, rgba(3,5,10,0) 85%); }
}

/* ================= GITHUB ================= */
.lab { padding: clamp(120px, 16vw, 200px) var(--gutter) clamp(60px, 8vw, 100px); }
.lab-head { text-align: center; max-width: 980px; margin: 0 auto clamp(48px, 6vw, 72px); }
.follow { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 16px; margin-top: 32px; min-height: 44px; }
.follow small { color: var(--faint); font-size: 11.5px; text-transform: none; letter-spacing: .02em; }
.filters { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-bottom: 32px; }
.filter {
  min-height: 44px; padding: 0 18px; cursor: pointer;
  font: 400 11px var(--mono); letter-spacing: .14em; text-transform: uppercase;
  color: var(--muted); background: rgba(4,6,11,.45); border: 0; box-shadow: inset 0 0 0 1px var(--line);
  transition: color .3s, background-color .3s, box-shadow .3s;
}
.filter:hover { color: var(--ink); box-shadow: inset 0 0 0 1px var(--line-2); }
.filter.is-active { background: var(--ink); color: #04060b; box-shadow: none; }

.repos { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 270px), 1fr)); gap: 1px; background: var(--line); box-shadow: 0 0 0 1px var(--line); max-width: 1320px; margin: 0 auto; }
.repo {
  position: relative; display: flex; flex-direction: column; gap: 10px; padding: 24px 22px;
  background: rgba(4,6,11,.82); text-decoration: none; min-height: 170px;
  transition: background-color .4s var(--ease);
  animation: rise .7s var(--ease) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
.repo:hover { background: rgba(14,22,36,.9); }
.repo.is-hidden { display: none; }
.repo-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.repo-name { font: 400 17px/1.25 var(--sans); overflow-wrap: anywhere; }
.repo .arr { color: var(--faint); transition: transform .5s var(--ease), color .3s; }
.repo:hover .arr { color: var(--ice); transform: translate(3px, -3px); }
.repo-desc { color: var(--muted); font-size: 13.5px; line-height: 1.6; margin: 0; flex: 1; }
.repo-lang { display: inline-flex; align-items: center; gap: 8px; font: 400 10.5px var(--mono); letter-spacing: .1em; color: var(--faint); }
.repo-lang i { width: 7px; height: 7px; background: var(--c, #888); }
.all-repos { display: flex; width: max-content; margin: 48px auto 0; }

/* ================= CONTACTO ================= */
.contact {
  min-height: 100vh; min-height: 100svh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 140px var(--gutter) 120px;
}
.contact .display { font-size: clamp(32px, 6.4vw, 6rem); }
.cta-buttons { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; width: min(980px, 100%); margin-top: clamp(48px, 7vw, 80px); }
@media (max-width: 720px) { .cta-buttons { grid-template-columns: 1fr; } }
.mega {
  --mx: 50%; --my: 50%;
  position: relative; overflow: hidden; isolation: isolate;
  display: flex; align-items: center; gap: 22px; min-width: 0;
  padding: clamp(22px, 3vw, 34px); text-align: left; text-decoration: none;
  background: rgba(4,6,11,.5); box-shadow: inset 0 0 0 1px var(--line-2);
  transition: color .4s var(--ease), box-shadow .4s var(--ease);
}
.mega::before {
  content: ""; position: absolute; z-index: -1; left: var(--mx); top: var(--my);
  width: 12px; height: 12px; margin: -6px 0 0 -6px; border-radius: 50%; background: var(--ink);
  transform: scale(0); transition: transform .8s var(--ease);
}
.mega:hover::before, .mega:focus-visible::before { transform: scale(120); }
.mega:hover, .mega:focus-visible { color: #04060b; box-shadow: inset 0 0 0 1px var(--ink); outline: none; }
.mega svg { width: clamp(36px, 4vw, 52px); height: auto; flex: none; }
.mega-text { display: flex; flex-direction: column; min-width: 0; font: 300 clamp(26px, 3vw, 42px)/1 var(--sans); text-transform: uppercase; letter-spacing: .02em; }
.mega-text small { font-size: 10.5px; color: inherit; opacity: .7; margin-bottom: 10px; }
.mega .mega-arrow { margin-left: auto; width: clamp(22px, 2.4vw, 30px); height: clamp(22px, 2.4vw, 30px); }
.mega:hover .mega-arrow { transform: translate(4px, -4px); }

.footer { position: relative; display: flex; justify-content: space-between; flex-wrap: wrap; gap: 10px; padding: 26px var(--gutter) 64px; color: var(--faint); font-size: 10.5px; border-top: 1px solid var(--line); }

/* ================= SALTO A PROYECTO ================= */
#warp {
  position: fixed; inset: 0; z-index: 95; display: grid; place-items: center;
  opacity: 0; visibility: hidden; pointer-events: none;
  background: radial-gradient(70% 70% at 50% 50%, rgba(2,4,9,.25), rgba(2,4,9,.85));
  transition: opacity .5s var(--ease), visibility .5s;
}
body.warping #warp { opacity: 1; visibility: visible; pointer-events: auto; }
#warp-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.warp-box { position: relative; text-align: center; padding: 0 var(--gutter); }
.warp-tx { margin: 0 0 22px; color: var(--faint); font-size: 10.5px; font-variant-numeric: tabular-nums; }
.warp-name {
  margin: 0; font: 300 clamp(34px, 7vw, 6rem)/1 var(--sans); text-transform: uppercase; letter-spacing: .02em;
  color: var(--ink);
  overflow-wrap: anywhere;
}
.warp-bar { width: min(440px, 72vw); height: 1px; margin: 34px auto 18px; background: var(--line); overflow: hidden; }
.warp-bar i { display: block; height: 100%; background: var(--accent, var(--ice)); transform: scaleX(0); transform-origin: left; }
body.warping .warp-bar i { transform: scaleX(1); transition: transform 2.2s cubic-bezier(.45, 0, .2, 1); }
.warp-status { margin: 0; color: var(--accent, var(--ice)); min-height: 1.6em; }
.warp-esc { margin: 26px 0 0; color: var(--faint); font-size: 10px; }
#warp-iris {
  position: fixed; inset: 0; z-index: 96; pointer-events: none;
  background: radial-gradient(circle at 50% 50%, #fff 0%, var(--accent, var(--ice)) 60%, #fff 100%);
  clip-path: circle(0% at 50% 50%); opacity: 1;
}
body.iris #warp-iris { clip-path: circle(150% at 50% 50%); transition: clip-path .45s cubic-bezier(.7, 0, .3, 1); }
body.iris-out #warp-iris { opacity: 0; clip-path: circle(150% at 50% 50%); transition: opacity .7s var(--ease); }
main, .footer, .nav, .hud, #orbit { transition: filter .8s var(--ease), transform .8s var(--ease); }
body.warping main, body.warping .footer, body.warping .nav, body.warping .hud, body.warping #orbit {
  filter: blur(10px) brightness(.45); transform: scale(.94);
  transition: filter 1s var(--ease), transform 1.4s var(--ease);
}

body.shake main { animation: shake .5s cubic-bezier(.36,.07,.19,.97); }
@keyframes shake {
  10%, 90% { transform: translate(-1px, 1px); } 20%, 80% { transform: translate(3px, -2px); }
  30%, 50%, 70% { transform: translate(-5px, 2px); } 40%, 60% { transform: translate(5px, -2px); }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  [data-converge] .c { transform: none; filter: none; transition: opacity .5s ease; }
  .fade { transform: none; filter: none; transition: opacity .5s ease; }
  .scroll-hint i::after, .repo, .intro-bar i { animation: none; }
  .bracket::before, .arr, .mega::before { transition-duration: .2s; }
  body.shake main { animation: none; }
}
