/* ---------- Paleta única (claro + oscuro) ---------- */
:root {
  color-scheme: light;
  --paper: #f4f1e8;
  --card: #faf7ee;
  --thbg: #eae4d3;
  --navbg: rgba(244, 241, 232, 0.92);
  --ink: #202020;
  --body: #35322c;
  --muted: #6b655a;
  --faint: #8f877a;
  --line: #d8d5cc;
  --accent: #345c9c;
  --accent2: #58745d;
  --terra: #b84732;
  --ochre: #c69a46;
  --accent-soft: #d8e1f0;
  --codebg: #e7e1d1;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #1e1a14;
  --card: #2a231b;
  --thbg: #251f18;
  --navbg: rgba(30, 26, 20, 0.92);
  --ink: #ece3d2;
  --body: #cfc2ac;
  --muted: #a89a85;
  --faint: #7c7160;
  --line: #3b3226;
  --accent: #7fa0d4;
  --accent2: #8aa78f;
  --terra: #d97b5f;
  --ochre: #d4af5e;
  --accent-soft: #2b3245;
  --codebg: #332b20;
}

:root {
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

::selection { background: var(--ochre); color: var(--ink); }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  transition: background 0.25s ease, color 0.25s ease;
}

.wrap {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ---------- Nav ---------- */
.site-nav {
  border-bottom: 1px solid var(--line);
  background: var(--navbg);
  backdrop-filter: blur(6px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 60px;
  padding-top: 8px;
  padding-bottom: 8px;
}
.brand { font-family: var(--serif); font-size: 18px; white-space: nowrap; }
.brand em { color: var(--accent); font-style: italic; }
.site-nav nav.links a {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  margin-left: 18px;
}
.site-nav nav.links a:hover { color: var(--terra); }

/* ---------- Controles de apariencia ---------- */
.controls { display: flex; align-items: center; gap: 10px; }
.lang-switch {
  display: flex;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}
.lang-switch button {
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--sans);
  line-height: 1.2;
}
.lang-switch button:hover { color: var(--ink); }
.lang-switch button.active { background: var(--accent-soft); color: var(--ink); }
#theme-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 999px;
  padding: 6px 12px 6px 9px;
  cursor: pointer;
  font-size: 12px;
  font-family: var(--sans);
}
#theme-toggle:hover { border-color: var(--ochre); }
#theme-toggle .theme-state { color: var(--muted); min-width: 34px; text-align: left; }
:root[data-theme="light"] #theme-toggle .ic-sun { display: none; }
:root[data-theme="dark"] #theme-toggle .ic-moon { display: none; }

/* ---------- Hero ---------- */
.hero { padding: 72px 0 40px; }
.kicker {
  font-size: 13px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 18px;
}
.hero h1 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(34px, 5.4vw, 52px);
  line-height: 1.12;
  letter-spacing: -0.01em;
  margin: 0 0 20px;
}
.hero h1 span { font-style: italic; color: var(--terra); }
.lede {
  font-family: var(--serif);
  font-size: 21px;
  line-height: 1.55;
  color: var(--body);
  margin: 0 0 32px;
}
.hero-figure { margin: 0 0 24px; }
.hero-figure img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 14px;
  border: 1px solid var(--line);
}
.hero-figure figcaption {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  font-style: italic;
  margin-top: 8px;
}
.meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  margin: 0;
}
.meta > div { background: var(--card); padding: 14px 18px; }
.meta dt {
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 4px;
}
.meta dd { margin: 0; font-size: 15px; }

/* ---------- Sections ---------- */
section { padding: 44px 0; border-top: 1px solid var(--line); scroll-margin-top: 70px; }
section:first-of-type { border-top: none; }
.jump { display: block; height: 0; overflow: hidden; }
.section-kicker {
  font-size: 13px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 10px;
}
h2 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 30px;
  line-height: 1.25;
  margin: 0 0 20px;
}
h3 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 21px;
  margin: 0 0 6px;
}
code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: var(--codebg);
  padding: 2px 6px;
  border-radius: 6px;
}

/* ---------- Stats ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin: 24px 0;
}
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.stat-num {
  font-family: var(--serif);
  font-size: 30px;
  color: var(--terra);
}
.stat-label { font-size: 13.5px; color: var(--muted); line-height: 1.45; }

/* ---------- Steps / findings ---------- */
.steps { padding-left: 22px; margin: 0 0 18px; }
.steps li { margin-bottom: 12px; }
.caveat {
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  padding: 14px 18px;
  border-radius: 0 10px 10px 0;
  font-size: 15.5px;
}
.finding {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px 22px;
  margin-bottom: 14px;
}
.finding p { margin: 0; color: var(--body); }

/* ---------- Charts ---------- */
.chart-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px;
  margin-bottom: 18px;
}
.chart-sub { color: var(--muted); font-size: 15px; margin: 0 0 12px; }
.chart { width: 100%; position: relative; min-height: 380px; }
.chart .js-plotly-plot, .chart .plot-container { width: 100%; }
/* Plotly hereda colores del tema via JS (cssVar); solo ajustes de fondo */
.chart .main-svg, .chart .bg { background: transparent !important; }

/* ---------- Table ---------- */
.table-title { margin-top: 30px; }
.table-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
table { border-collapse: collapse; width: 100%; font-size: 14.5px; min-width: 640px; }
th, td { padding: 10px 14px; text-align: right; border-bottom: 1px solid var(--line); }
th:first-child, td:first-child { text-align: left; }
th:last-child, td:last-child { text-align: left; }
thead th {
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
  background: var(--thbg);
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--thbg); }
td a { color: var(--accent); text-decoration: none; }
td a:hover { text-decoration: underline; color: var(--terra); }
td.num { font-family: var(--mono); font-size: 13.5px; }

/* ---------- Takeaways ---------- */
.takeaways { list-style: none; padding: 0; margin: 0 0 18px; }
.takeaways li {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 12px;
}

/* ---------- Pilares ---------- */
.pillars {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 0 0 28px;
}
.pillar {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 18px;
  text-decoration: none;
  color: inherit;
}
.pillar:hover { border-color: var(--ochre); }
.pillar-title { font-family: var(--serif); font-size: 19px; }
.pillar-desc { font-size: 14px; color: var(--muted); line-height: 1.5; }
.pillar-go { font-size: 13.5px; color: var(--terra); font-weight: 600; margin-top: 4px; }
.pillar.p1 { border-top: 3px solid var(--accent); }
.pillar.p2 { border-top: 3px solid var(--accent2); }
.pillar.p3 { border-top: 3px solid var(--terra); }
.pillars-note {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 18px;
  font-size: 15.5px;
  color: var(--body);
  margin: 0 0 20px;
}
.pillars-note a { color: var(--accent); text-decoration: none; }
.pillars-note a:hover { color: var(--terra); text-decoration: underline; }
.site-nav nav.links a[data-pillar="1"] { color: var(--accent); }
.site-nav nav.links a[data-pillar="2"] { color: var(--accent2); }
.site-nav nav.links a[data-pillar="3"] { color: var(--terra); }

/* ---------- Secciones pilar (color por eje) ---------- */
#pilar1 .section-kicker { color: var(--accent); }
#pilar2 .section-kicker { color: var(--accent2); }
#pilar3 .section-kicker { color: var(--terra); }
.stats .stat:nth-child(1) { border-top: 3px solid var(--accent); }
.stats .stat:nth-child(2) { border-top: 3px solid var(--accent2); }
.stats .stat:nth-child(3) { border-top: 3px solid var(--terra); }

/* ---------- Detalles colapsables (tablas + metodología) ---------- */
details.data-details, details.support-details {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-top: 18px;
}
details.data-details summary, details.support-details summary {
  cursor: pointer;
  padding: 16px 20px;
  font-family: var(--serif);
  font-size: 19px;
  list-style: none;
}
details.data-details summary::-webkit-details-marker,
details.support-details summary::-webkit-details-marker { display: none; }
details.data-details summary::after, details.support-details summary::after {
  content: " ▸";
  color: var(--terra);
}
details.data-details[open] summary::after, details.support-details[open] summary::after {
  content: " ▾";
}
details.data-details summary:hover, details.support-details summary:hover { color: var(--terra); }
details.data-details .table-scroll {
  border: none;
  border-top: 1px solid var(--line);
  border-radius: 0 0 12px 12px;
}
details.support-details .steps { padding: 6px 20px 6px 42px; }
details.support-details .caveat { margin: 0 20px 20px; }
.support-note { color: var(--body); margin: 0 0 4px; }

/* ---------- Footer ---------- */
footer {
  border-top: 1px solid var(--line);
  padding: 28px 0 40px;
  color: var(--faint);
  font-size: 14px;
}

@media (max-width: 640px) {
  .meta { grid-template-columns: 1fr; }
  .site-nav nav.links { display: none; }
  .hero { padding-top: 48px; }
  .pillars { grid-template-columns: 1fr; }
}
