:root {
  --bg: #0a0e12;
  --bg-soft: #10161c;
  --panel: #131a21;
  --line: #22303a;
  --text: #e6edf3;
  --muted: #93a4b3;
  --accent: #6ee7a8;
  --accent-2: #f0b429;
  --danger: #f87171;
  --code: #0d1319;
  --radius: 12px;
  --max: 1180px;
  --content: 820px;
  --toc: 220px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background:
    radial-gradient(900px 480px at 12% -8%, rgba(110, 231, 168, 0.1), transparent 60%),
    radial-gradient(760px 420px at 92% 0%, rgba(240, 180, 41, 0.05), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.7;
  font-size: 17px;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.progress {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 30;
  height: 2px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: 0 50%;
  pointer-events: none;
}

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px 32px;
  background: rgba(10, 14, 18, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { color: var(--text); font-weight: 650; letter-spacing: 0.2px; white-space: nowrap; }
.brand em { color: var(--muted); font-style: normal; font-weight: 450; }
.brand .mark { color: var(--accent); }
.top nav { display: flex; align-items: center; gap: 22px; margin-left: auto; flex-wrap: wrap; }
.top nav a { color: var(--muted); font-size: 15px; white-space: nowrap; }
.top nav a:hover, .top nav a.active { color: var(--text); text-decoration: none; }
.top nav a.active { border-bottom: 2px solid var(--accent); padding-bottom: 2px; }
.top nav a.star {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border: 1px solid rgba(110, 231, 168, 0.28);
  border-radius: 999px;
  background: rgba(110, 231, 168, 0.06);
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}
.top nav a.star:hover {
  background: rgba(110, 231, 168, 0.12);
  border-color: rgba(110, 231, 168, 0.6);
  color: var(--accent);
  text-decoration: none;
  transform: translateY(-1px);
  box-shadow: 0 8px 24px -14px rgba(110, 231, 168, 0.7);
}
.top nav a.star svg { width: 14px; height: 14px; margin: 0; fill: currentColor; }
.star-count {
  min-width: 18px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(110, 231, 168, 0.14);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.4;
  text-align: center;
}
.star-count[hidden] { display: none; }
.lang {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}
.lang:hover { color: var(--text); border-color: var(--accent); text-decoration: none; }

.shell {
  display: grid;
  grid-template-columns: minmax(0, var(--content)) var(--toc);
  justify-content: center;
  gap: 64px;
  max-width: var(--max);
  margin: 0 auto;
  padding: 56px 32px 90px;
}
main { min-width: 0; }

h1 { font-size: clamp(34px, 5vw, 50px); line-height: 1.1; letter-spacing: -0.8px; margin: 0 0 20px; }
h2 {
  font-size: 28px;
  line-height: 1.25;
  letter-spacing: -0.3px;
  margin: 64px 0 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
  scroll-margin-top: 92px;
}
h2::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 10px;
  border-radius: 2px;
  background: var(--accent);
  box-shadow: 0 0 12px rgba(110, 231, 168, 0.45);
  vertical-align: 0.12em;
}
main > h2:first-of-type { margin-top: 44px; }
h3 { font-size: 20px; line-height: 1.35; margin: 36px 0 10px; scroll-margin-top: 92px; }
h4 { font-size: 17px; line-height: 1.4; margin: 26px 0 8px; color: #f4f8fb; }
h2 code, h3 code, h4 code { font-size: inherit; background: none; border: 0; padding: 0; color: inherit; }
p { margin: 0 0 16px; }
strong { color: #f4f8fb; }
em { color: var(--muted); }
ul, ol { padding-left: 24px; margin: 0 0 18px; }
li { margin: 7px 0; }

code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--code);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px 6px;
}
pre {
  position: relative;
  background: linear-gradient(180deg, rgba(110, 231, 168, 0.045), transparent 90px), var(--code);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 42px 20px 18px;
  overflow-x: auto;
  line-height: 1.55;
  margin: 22px 0;
}
pre::before {
  content: "";
  position: absolute;
  top: 17px;
  left: 20px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #f87171;
  box-shadow: 16px 0 #f0b429, 32px 0 #6ee7a8;
  opacity: 0.85;
}
pre code { background: none; border: 0; padding: 0; font-size: 14px; }

blockquote {
  position: relative;
  margin: 26px 0;
  padding: 14px 20px 14px 54px;
  border-left: 3px solid var(--accent-2);
  background: var(--bg-soft);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--muted);
}
blockquote::before {
  content: "“";
  position: absolute;
  top: 4px;
  left: 16px;
  color: rgba(240, 180, 41, 0.4);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 46px;
  line-height: 1;
}
blockquote p { margin: 0; }

.table-wrap { overflow-x: auto; margin: 24px 0; border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--bg-soft); color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
tbody tr { transition: background-color 0.2s ease; }
tbody tr:hover { background: rgba(110, 231, 168, 0.045); }

svg { max-width: 100%; height: auto; display: block; margin: 28px auto; }
.diagram-wrap { overflow-x: auto; margin: 28px 0; -webkit-overflow-scrolling: touch; }
.diagram-wrap > svg { margin: 0 auto; }

.cta {
  position: relative;
  overflow: hidden;
  display: inline-block;
  margin: 8px 0 4px;
  background: var(--accent);
  color: #062017;
  font-weight: 700;
  padding: 11px 20px;
  border-radius: 999px;
  transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
}
.cta:hover { text-decoration: none; filter: brightness(1.05); transform: translateY(-1px); }
.cta:not(.ghost):hover { box-shadow: 0 12px 32px -14px rgba(110, 231, 168, 0.65); }
.cta:not(.ghost)::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, transparent 30%, rgba(255, 255, 255, 0.35) 50%, transparent 70%);
  transform: translateX(-140%);
  transition: transform 0.6s ease;
  pointer-events: none;
}
.cta:not(.ghost):hover::after { transform: translateX(140%); }

.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 22px 0 14px; }
.actions .cta { margin: 0; }
.actions-note { color: var(--muted); font-size: 14px; margin: -4px 0 14px; }
.cta.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.cta.ghost:hover { border-color: var(--accent); }
.prereqs { color: var(--muted); font-size: 14px; margin: -4px 0 14px; }
.deep-dive { margin: 24px 0; padding: 14px 18px; border: 1px solid var(--line); border-radius: var(--radius); }
.deep-dive summary { cursor: pointer; color: var(--text); font-weight: 600; }
.deep-dive[open] summary { margin-bottom: 8px; }

.story {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 14px;
  margin: 30px 0 26px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(110, 231, 168, 0.035), transparent 55%), var(--bg-soft);
}
.story-step {
  position: relative;
  overflow: hidden;
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: linear-gradient(160deg, rgba(110, 231, 168, 0.06), transparent 42%), var(--panel);
  transition: transform 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}
.story-step > * { position: relative; z-index: 1; }
.story-step::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  border-radius: inherit;
  background: radial-gradient(220px 120px at 50% 0%, rgba(110, 231, 168, 0.14), transparent 70%);
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}
.story-step:hover {
  transform: translateY(-4px);
  border-color: rgba(110, 231, 168, 0.5);
  box-shadow: 0 18px 36px -26px rgba(110, 231, 168, 0.75);
}
.story-step:hover::after { opacity: 1; }
.story-step:hover .story-icon { transform: translateY(-2px) scale(1.06); }
.story-step strong { font-size: 15px; line-height: 1.4; font-weight: 600; color: var(--text); }
.story-icon {
  width: 32px;
  height: 32px;
  margin: 0 0 4px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.25s ease;
}
.story-label { color: var(--accent); font-size: 11px; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase; }
.story-arrow { flex: 0 0 auto; align-self: center; color: var(--muted); font-size: 20px; }
.story-loop {
  width: 100%;
  margin: 2px 0 0;
  padding-top: 14px;
  border-top: 1px dashed var(--line);
  color: var(--muted);
  font-size: 14px;
}
.story-loop span { display: inline-block; color: var(--accent); margin-right: 6px; }

/* Portada */
.page { position: relative; isolation: isolate; }
.page::before {
  content: "";
  position: absolute;
  z-index: -1;
  top: -40px;
  right: 0;
  left: 0;
  height: 520px;
  background-image:
    linear-gradient(rgba(110, 231, 168, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(110, 231, 168, 0.04) 1px, transparent 1px);
  background-size: 48px 48px;
  -webkit-mask-image: radial-gradient(ellipse at 50% 0%, black 0%, transparent 70%);
  mask-image: radial-gradient(ellipse at 50% 0%, black 0%, transparent 70%);
  pointer-events: none;
}
.page h1 {
  background: linear-gradient(100deg, #f4f8fb 0%, #e6edf3 52%, #9ff0c6 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  text-wrap: balance;
}
.hero-badge {
  display: inline-flex;
  align-items: center;
  margin: 0 0 18px;
  padding: 6px 13px;
  border: 1px solid rgba(110, 231, 168, 0.22);
  border-radius: 999px;
  background: rgba(110, 231, 168, 0.055);
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
  letter-spacing: 0.04em;
}
.hero-badge a { display: inline-flex; align-items: center; gap: 8px; color: var(--text); }
.hero-badge a:hover { color: var(--accent); text-decoration: none; }
.hero-badge .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(110, 231, 168, 0.12);
}
.page-index .section-kicker {
  margin: 40px 0 6px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.page-index .section-title {
  margin: 0 0 12px;
  font-size: 26px;
  line-height: 1.2;
  letter-spacing: -0.3px;
  color: #f4f8fb;
}
.page-index > ol {
  counter-reset: setup;
  list-style: none;
  padding-left: 0;
  margin: 20px 0 22px;
}
.page-index > ol > li {
  position: relative;
  padding-left: 46px;
  margin: 14px 0;
  counter-increment: setup;
}
.page-index > ol > li::before {
  content: counter(setup);
  position: absolute;
  top: 2px;
  left: 0;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid rgba(110, 231, 168, 0.38);
  border-radius: 50%;
  background: rgba(110, 231, 168, 0.08);
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
}
.toc {
  position: sticky;
  top: 92px;
  align-self: start;
  font-size: 14px;
  color: var(--muted);
  border-left: 1px solid var(--line);
  padding-left: 18px;
}
.toc p {
  margin: 0 0 12px;
  font-size: 11px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}
.toc ol, .toc-mobile ol { list-style: none; padding: 0; margin: 0; }
.toc li { margin: 8px 0; }
.toc a { position: relative; color: var(--muted); }
.toc a:hover { color: var(--text); text-decoration: none; }
.toc a.active, .toc-mobile a.active { color: var(--accent); }
.toc a.active::before {
  content: "";
  position: absolute;
  top: 50%;
  left: -21px;
  width: 6px;
  height: 6px;
  margin-top: -3px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px rgba(110, 231, 168, 0.65);
}

.toc-mobile { display: none; }

footer {
  border-top: 1px solid var(--line);
  padding: 26px 32px 40px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

@media (prefers-reduced-motion: no-preference) {
  .js [data-reveal] { opacity: 0; transform: translateY(10px); }
  .page::before { animation: grid-drift 24s linear infinite; }
  .hero-badge .dot { animation: pulse-dot 2.6s ease-in-out infinite; }
  .page-index .story-loop span { animation: spin 10s linear infinite; }
}

@keyframes grid-drift { to { background-position: 48px 48px, 48px 48px; } }
@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 0 rgba(110, 231, 168, 0.35); }
  50% { box-shadow: 0 0 0 7px rgba(110, 231, 168, 0); }
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1100px) {
  .story { flex-direction: column; gap: 10px; padding: 14px; }
  .story-step { flex: none; }
  .story-arrow { display: none; }
}

@media (max-width: 980px) {
  .shell { grid-template-columns: minmax(0, 1fr); gap: 0; padding: 40px 24px 70px; }
  .toc { display: none; }
  .toc-mobile {
    display: block;
    margin: 0 0 30px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--bg-soft);
    padding: 12px 16px;
  }
  .toc-mobile summary { cursor: pointer; color: var(--muted); font-size: 14px; }
  .toc-mobile ol { margin: 12px 0 0 18px; list-style: disc; }
  .toc-mobile li { margin: 6px 0; }
  .toc-mobile a { color: var(--muted); }
}

@media (max-width: 720px) {
  body { font-size: 16px; }
  .top { flex-wrap: wrap; gap: 10px 16px; padding: 12px 18px; }
  .top nav { order: 3; width: 100%; margin-left: 0; gap: 16px; }
  .top nav a { font-size: 14px; }
  .lang { margin-left: auto; }
  h1 { font-size: clamp(32px, 9vw, 42px); }
  h2 { font-size: 24px; margin-top: 48px; }
  .shell { padding: 32px 18px 60px; }
  .diagram-wrap > svg.diagram { min-width: 680px; }
  .story-step { padding: 14px; }
  pre { padding: 38px 16px 14px; }
  footer { padding: 24px 18px 36px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .cta, .story-step, .story-icon { transition: none; }
  .story-step:hover, .cta:hover { transform: none; }
}
