/* ============ Tokens ============ */
:root {
  --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
  --text-sm: clamp(0.875rem, 0.8rem + 0.35vw, 1rem);
  --text-base: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
  --text-lg: clamp(1.125rem, 1rem + 0.75vw, 1.5rem);
  --text-xl: clamp(1.5rem, 1.2rem + 1.25vw, 2.25rem);
  --text-2xl: clamp(2rem, 1.4rem + 2.5vw, 3.25rem);

  --space-1: 0.25rem; --space-2: 0.5rem; --space-3: 0.75rem; --space-4: 1rem;
  --space-5: 1.25rem; --space-6: 1.5rem; --space-8: 2rem; --space-10: 2.5rem;
  --space-12: 3rem; --space-16: 4rem; --space-20: 5rem; --space-24: 6rem;

  --bg: #f6f5ef;
  --surface: #fffef9;
  --surface-2: #fbfaf4;
  --surface-offset: #efede4;
  --divider: #e2dfd5;
  --border: #d6d2c4;

  --text: #23262d;
  --muted: #666a73;
  --faint: #9aa0a8;

  --accent: #0f5aa8;
  --accent-deep: #0b4079;
  --accent-tint: #e4eef9;
  --accent-tint-2: #d3e4f6;

  --air: #1d6fd6;      /* aire a presión */
  --work: #0e8a5f;     /* utilización */
  --exh: #d97706;      /* escape */
  --blk: #c4342b;      /* bloqueado */
  --pilot: #7c4dbd;    /* pilotaje */

  --radius-sm: 0.375rem; --radius-md: 0.5rem; --radius-lg: 0.75rem; --radius-xl: 1rem;
  --shadow-sm: 0 1px 2px rgb(30 30 25 / 0.06);
  --shadow-md: 0 4px 14px rgb(30 30 25 / 0.09);
  --shadow-lg: 0 12px 32px rgb(30 30 25 / 0.14);

  --font-display: 'Chillax', 'Plus Jakarta Sans', sans-serif;
  --font-body: 'Plus Jakarta Sans', 'Segoe UI', sans-serif;

  --content: 1100px;
  --transition: 200ms cubic-bezier(0.16, 1, 0.3, 1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  -webkit-text-size-adjust: none; text-size-adjust: none;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
  scroll-padding-top: 5rem;
}

body {
  min-height: 100dvh;
  line-height: 1.65;
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--text);
  background-color: var(--bg);
}

img, svg { display: block; max-width: 100%; height: auto; }
p, li, figcaption { text-wrap: pretty; max-width: 72ch; }

h1, h2, h3, h4 { text-wrap: balance; line-height: 1.15; font-family: var(--font-display); }
h1 { font-size: var(--text-2xl); font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: var(--text-xl); font-weight: 600; }
h3 { font-size: var(--text-lg); font-weight: 600; }

a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: var(--radius-sm); }
::selection { background: var(--accent-tint-2); }

/* ============ Header ============ */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: rgb(246 245 239 / 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--divider);
}
.site-header .inner {
  max-width: var(--content); margin: 0 auto;
  padding: var(--space-3) var(--space-5);
  display: flex; align-items: center; gap: var(--space-4); flex-wrap: wrap;
}
.brand {
  font-family: var(--font-display); font-weight: 700; font-size: var(--text-base);
  color: var(--text); text-decoration: none; display: flex; align-items: center; gap: var(--space-2);
  white-space: nowrap;
}
.brand svg { flex: none; }
.site-nav { display: flex; gap: var(--space-1); flex-wrap: wrap; margin-left: auto; }
.site-nav a {
  font-size: var(--text-sm); font-weight: 600; text-decoration: none;
  color: var(--muted); padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full, 999px);
}
.site-nav a:hover { color: var(--accent); background: var(--accent-tint); }

/* ============ Hero ============ */
.hero { padding: var(--space-16) 0 var(--space-10); }
.hero .inner {
  max-width: var(--content); margin: 0 auto;
  padding: 0 var(--space-5);
  display: grid; grid-template-columns: 1.1fr 0.9fr; gap: var(--space-12); align-items: center;
}
.kicker {
  display: inline-flex; align-items: center; gap: var(--space-2);
  font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--accent-deep); background: var(--accent-tint);
  padding: var(--space-1) var(--space-3); border-radius: 999px; margin-bottom: var(--space-4);
  width: fit-content;
}
.hero h1 { margin-bottom: var(--space-4); }
.hero .lead { font-size: var(--text-lg); color: var(--muted); max-width: 34ch; margin-bottom: var(--space-6); }
.hero .index-chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.chip {
  font-size: var(--text-sm); font-weight: 600; text-decoration: none;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 999px;
  padding: var(--space-1) var(--space-4);
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.hero-visual { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-xl); padding: var(--space-5); box-shadow: var(--shadow-md); }
.hero-visual figcaption { margin-top: var(--space-3); font-size: var(--text-sm); color: var(--muted); }

/* ============ Sections ============ */
.section { padding: var(--space-16) 0; border-top: 1px solid var(--divider); }
.section .inner { max-width: var(--content); margin: 0 auto; padding: 0 var(--space-5); }
.section-head { margin-bottom: var(--space-8); max-width: 62ch; }
.section-num {
  font-family: var(--font-display); font-weight: 700; font-size: var(--text-sm);
  color: var(--accent); letter-spacing: 0.06em; text-transform: uppercase; display: block; margin-bottom: var(--space-2);
}
.section-head h2 { margin-bottom: var(--space-3); }
.section-head p { color: var(--muted); }

.cols { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-10); align-items: start; }
.cols .text h3 { margin-top: var(--space-6); }
.cols .text h3:first-child { margin-top: 0; }
.cols .text p { margin-bottom: var(--space-3); }

/* ============ Figures & cards ============ */
.figure {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: var(--space-5);
  box-shadow: var(--shadow-sm);
}
.figure svg { margin: 0 auto; }
.figure .fig-caption {
  margin-top: var(--space-4); font-size: var(--text-sm); color: var(--muted);
  border-top: 1px dashed var(--border); padding-top: var(--space-3);
}
.figure .fig-title { font-weight: 700; font-size: var(--text-base); margin-bottom: var(--space-3); font-family: var(--font-display); }

.figure { overflow-x: auto; }

.callout {
  background: var(--accent-tint); border-left: 4px solid var(--accent);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  padding: var(--space-4) var(--space-5); margin: var(--space-6) 0;
}
.callout.warn { background: #fdf0e2; border-left-color: var(--exh); }
.callout p { max-width: none; }
.callout .callout-tag {
  font-weight: 700; font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.06em;
  display: block; margin-bottom: var(--space-1); color: var(--accent-deep);
}
.callout.warn .callout-tag { color: #9a5504; }

.legend { display: flex; flex-wrap: wrap; gap: var(--space-3) var(--space-5); margin: var(--space-4) 0; }
.legend span { display: inline-flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); font-weight: 600; }
.legend i { width: 14px; height: 14px; border-radius: 4px; flex: none; }

/* ============ Interactive demos ============ */
.demo {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md); overflow: hidden;
}
.demo-controls {
  display: flex; gap: var(--space-2); padding: var(--space-4);
  background: var(--surface-2); border-bottom: 1px solid var(--divider);
  align-items: center; flex-wrap: wrap;
}
.demo-controls .hint { font-size: var(--text-sm); color: var(--muted); margin-left: auto; }
.toggle-btn {
  font-family: var(--font-body); font-size: var(--text-sm); font-weight: 700;
  padding: var(--space-2) var(--space-5); border-radius: 999px;
  border: 2px solid var(--accent); color: var(--accent); background: var(--surface);
  cursor: pointer; transition: all var(--transition);
}
.toggle-btn:hover { background: var(--accent-tint); }
.toggle-btn.active { background: var(--accent); color: #fff; }
.demo-body { padding: var(--space-6); overflow-x: auto; }
.demo-readout { padding: var(--space-4) var(--space-6); border-top: 1px dashed var(--border); font-size: var(--text-base); }
.demo-readout strong { font-family: var(--font-display); }

/* ============ Grids ============ */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-6); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-6); }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: var(--space-5); box-shadow: var(--shadow-sm);
}
.card h3 { font-size: var(--text-base); margin-bottom: var(--space-2); }
.card p { font-size: var(--text-sm); color: var(--muted); margin-bottom: var(--space-2); }
.card .tag {
  display: inline-block; font-size: var(--text-xs); font-weight: 700;
  background: var(--accent-tint); color: var(--accent-deep);
  border-radius: 999px; padding: 2px var(--space-3); margin-bottom: var(--space-3);
}
.card svg { margin: 0 auto var(--space-3); }

/* ============ Steps ============ */
.steps { counter-reset: step; display: grid; gap: var(--space-4); }
.step {
  display: grid; grid-template-columns: 56px 1fr; gap: var(--space-4); align-items: start;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
}
.step::before {
  counter-increment: step; content: counter(step);
  font-family: var(--font-display); font-weight: 700; font-size: var(--text-lg);
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--accent); color: #fff; display: grid; place-items: center;
}
.step h3 { font-size: var(--text-base); margin-bottom: var(--space-1); }
.step p { font-size: var(--text-sm); color: var(--muted); }

/* ============ Exercises ============ */
.exercise {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: var(--space-5); margin-bottom: var(--space-5); box-shadow: var(--shadow-sm);
}
.exercise .ex-num {
  font-family: var(--font-display); font-weight: 700; color: var(--accent);
  font-size: var(--text-sm); letter-spacing: 0.06em; text-transform: uppercase; display: block; margin-bottom: var(--space-2);
}
.exercise .ex-body { display: grid; grid-template-columns: 200px 1fr; gap: var(--space-5); align-items: center; }
.exercise p { margin-bottom: var(--space-2); }
.solution-btn {
  margin-top: var(--space-3); font-size: var(--text-sm); font-weight: 700;
  color: var(--accent); background: none; border: none; cursor: pointer;
  text-decoration: underline; text-underline-offset: 3px; padding: 0;
}
.solution-btn:hover { color: var(--accent-deep); }
.solution {
  display: none; margin-top: var(--space-4);
  background: #eef6f0; border: 1px solid #cbe3d3; border-radius: var(--radius-md);
  padding: var(--space-4) var(--space-5); font-size: var(--text-sm);
}
.solution.open { display: block; }
.solution strong { font-family: var(--font-display); }

/* ============ Cheat sheet ============ */
.cheatsheet { overflow-x: auto; }
.cheatsheet table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.cheatsheet th, .cheatsheet td { text-align: left; padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--divider); font-size: var(--text-sm); vertical-align: top; }
.cheatsheet th { background: var(--surface-offset); font-family: var(--font-display); }
.cheatsheet tr:last-child td { border-bottom: none; }
.cheatsheet td:first-child { white-space: nowrap; font-weight: 700; }

/* ============ Sources / footer ============ */
.sources ul { list-style: none; display: grid; gap: var(--space-3); }
.sources li { font-size: var(--text-sm); padding-left: var(--space-6); position: relative; color: var(--muted); }
.sources li::before { content: '↗'; position: absolute; left: 0; color: var(--accent); font-weight: 700; }
.site-footer { padding: var(--space-10) 0; border-top: 1px solid var(--divider); color: var(--muted); font-size: var(--text-sm); }
.site-footer .inner { max-width: var(--content); margin: 0 auto; padding: 0 var(--space-5); }

/* ============ SVG text ============ */
svg .lbl { font-family: var(--font-body); font-weight: 700; fill: var(--text); }
svg .lbl-sm { font-family: var(--font-body); font-weight: 600; fill: var(--muted); }
svg .note { font-family: var(--font-body); fill: var(--muted); }

/* ============ Responsive ============ */
@media (max-width: 900px) {
  .hero .inner { grid-template-columns: 1fr; gap: var(--space-8); }
  .cols { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .exercise .ex-body { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
  .figure svg { min-width: 700px; }
  .demo-body svg { min-width: 780px; }
  .hero-visual svg { min-width: 0; }
}

@media (max-width: 560px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .site-nav { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}
