/* =============================================================
   Si hubiera invertido · estilos
   1. Tokens  2. Reset  3. Utilidades  4. Tipografía  5. Componentes
   6. Secciones  7. Efectos  8. Responsive  9. Movimiento reducido
   ============================================================= */

/* =============================================================
   1. Tokens
   ============================================================= */
:root {
  --bg: #f6f4ee;
  --surface: #ffffff;
  --surface-2: #f2efe7;
  --ink: #17201c;
  --ink-2: #3b4641;
  --muted: #5f6a64;
  --line: #e3ded2;
  --line-strong: #cdc6b6;

  --accent: #0b6e4f;
  --accent-hover: #08573e;
  --accent-soft: #e2f0e9;
  --accent-ink: #ffffff;

  --contrib: #a7b6c4;
  --interest: #1f9d6b;
  --real: #b7791f;
  --neg: #b42318;
  --pos: #0b6e4f;

  --warn-bg: #fff4dc;
  --warn-line: #efd8a2;

  --a-sp500: #2563eb;
  --a-nasdaq100: #7c3aed;
  --a-msci-world: #0d9488;
  --a-oro: #b8860b;
  --a-bonos: #dc2626;
  --a-cuenta: #db2777;

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(23, 32, 28, .05), 0 10px 30px rgba(23, 32, 28, .07);

  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --container: 1120px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1412;
    --surface: #161d1a;
    --surface-2: #1d2622;
    --ink: #e8eee9;
    --ink-2: #c2ccc6;
    --muted: #97a59e;
    --line: #27312c;
    --line-strong: #3a4640;

    --accent: #3ccf94;
    --accent-hover: #62dcab;
    --accent-soft: #163026;
    --accent-ink: #05130d;

    --contrib: #5d7690;
    --interest: #3ccf94;
    --real: #e3aa4c;
    --neg: #ff8b80;
    --pos: #3ccf94;

    --warn-bg: #2a2414;
    --warn-line: #4b401f;

    --a-sp500: #6b9dff;
    --a-nasdaq100: #b28dff;
    --a-msci-world: #38c7b7;
    --a-oro: #e2b43e;
    --a-bonos: #f87171;
    --a-cuenta: #f472b6;

    --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 10px 30px rgba(0, 0, 0, .28);
  }
}

/* =============================================================
   2. Reset y base
   ============================================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; }

/* Lo oculto con el atributo hidden se queda oculto aunque el componente tenga display propio */
[hidden] { display: none !important; }

html {
  -webkit-text-size-adjust: 100%;
  overflow-x: clip;
  scroll-behavior: smooth;
  color-scheme: light dark;
}

body {
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: clip;
}

img, svg, canvas { display: block; max-width: 100%; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-underline-offset: 3px; }
a:hover { color: var(--accent-hover); }
p { text-wrap: pretty; }
h1, h2, h3 { text-wrap: balance; line-height: 1.12; letter-spacing: -0.015em; }

:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 2px;
  border-radius: 6px;
}

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

/* =============================================================
   3. Utilidades
   ============================================================= */
.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: 16px;
}

.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;
}

.skip-link {
  position: fixed;
  top: -100px; left: 1rem;
  z-index: 100;
  padding: .6rem 1rem;
  background: var(--surface);
  color: var(--ink);
  border-radius: 8px;
  box-shadow: var(--shadow);
  font-weight: 600;
}
.skip-link:focus { top: 1rem; }

.num { font-variant-numeric: tabular-nums; }
.neg { color: var(--neg); }
.pos { color: var(--pos); }
.muted { color: var(--muted); }

/* =============================================================
   4. Tipografía
   ============================================================= */
h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(1.8rem, 1.25rem + 2.5vw, 2.9rem);
}

h2 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(1.45rem, 1.15rem + 1.35vw, 2.1rem);
}

h3 {
  font-size: 1.0625rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.lead {
  color: var(--ink-2);
  font-size: clamp(1rem, .95rem + .3vw, 1.125rem);
  max-width: 64ch;
}

/* =============================================================
   5. Componentes
   ============================================================= */

/* ---- Cabecera ---- */
.site-header {
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 58px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.125rem;
  letter-spacing: -0.01em;
}
.brand:hover { color: var(--ink); }
.brand svg { width: 28px; height: 28px; flex: none; }

.nav { display: none; gap: 20px; }
.nav a {
  color: var(--ink-2);
  text-decoration: none;
  font-size: .9375rem;
  font-weight: 500;
}
.nav a:hover { color: var(--accent); }

/* ---- Tarjeta de herramienta ---- */
.tool-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.tool-grid {
  display: grid;
  gap: 20px;
}

.tool-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  border: 0;
  padding: 0;
}

.field > label,
.field-label {
  font-size: .875rem;
  font-weight: 600;
  color: var(--ink-2);
  padding: 0;
}

.input-unit {
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s;
}
.input-unit:hover { border-color: var(--muted); }
.input-unit:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.input-unit.is-invalid {
  border-color: var(--neg);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--neg) 18%, transparent);
}

.input-unit input {
  flex: 1;
  min-width: 0;
  width: 100%;
  border: 0;
  background: transparent;
  padding: 11px 0 11px 12px;
  font-size: 1.0625rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  outline: none;
}

.input-unit .unit {
  padding: 0 12px 0 6px;
  color: var(--muted);
  font-size: .9375rem;
  white-space: nowrap;
}

.select-wrap { position: relative; }
.select-wrap select {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 11px 34px 11px 12px;
  font-size: 1.0625rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}
.select-wrap select:hover { border-color: var(--muted); }
.select-wrap select:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.select-wrap::after {
  content: "";
  position: absolute;
  right: 14px;
  top: 50%;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}

/* Interruptor */
.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: .9375rem;
  font-weight: 500;
  color: var(--ink);
  user-select: none;
}
.switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}
.switch-track {
  position: relative;
  flex: none;
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: var(--line-strong);
  transition: background .2s var(--ease-out);
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .25);
  transition: transform .2s var(--ease-out);
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-track {
  outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 2px;
}

.infl-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
}
.infl-row .field { width: 9.5rem; }

.form-error {
  color: var(--neg);
  font-size: .875rem;
  font-weight: 500;
}

.form-hint {
  font-size: .8125rem;
  color: var(--muted);
  line-height: 1.45;
}

/* Botones segmentados */
.seg {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}
.seg button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 6px 10px;
  text-align: center;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink-2);
  font-size: .9375rem;
  font-weight: 600;
  line-height: 1.2;
  transition: border-color .15s, background-color .15s, color .15s;
}
.seg button:hover { border-color: var(--muted); color: var(--ink); }
.seg button[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.seg--currency {
  grid-template-columns: repeat(2, auto);
  justify-content: start;
}
.seg--currency button { min-height: 38px; padding: 6px 16px; }

.asset-dot {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--c, var(--accent));
}

/* ---- Resultados ---- */
.tool-result {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
  transition: opacity .2s;
}
.tool-result.is-stale { opacity: .45; }

.stat-main { display: flex; flex-direction: column; gap: 2px; }

.stat-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: .875rem;
  font-weight: 500;
  color: var(--muted);
}

.stat-value {
  display: block;
  font-weight: 700;
  font-size: clamp(2.1rem, 1.55rem + 2.4vw, 3.1rem);
  line-height: 1.08;
  letter-spacing: -0.025em;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.stat-sub { color: var(--ink-2); font-size: .9375rem; }
.stat-sub strong { color: var(--ink); font-variant-numeric: tabular-nums; }

.stat-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.stat .stat-label { align-items: flex-start; line-height: 1.35; }
.stat .stat-label .dot { margin-top: .3em; }

.stat-num {
  font-weight: 700;
  font-size: 1.125rem;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.dot {
  display: inline-block;
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 3px;
}
.dot--contrib { background: var(--contrib); }
.dot--interest { background: var(--interest); }
.dot--real { background: var(--real); }
.dot--value { background: var(--c, var(--accent)); }

/* Gráfico */
.chart {
  position: relative;
  height: 240px;
}
.chart canvas {
  width: 100%;
  height: 100%;
  touch-action: pan-y;
}
.chart-tip {
  position: absolute;
  top: 6px;
  left: 0;
  z-index: 2;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: .8125rem;
  line-height: 1.5;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.chart-tip strong { display: block; font-size: .875rem; }
.chart-tip .tip-row { display: flex; align-items: center; gap: 6px; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  font-size: .8125rem;
  color: var(--muted);
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .line-dash {
  width: 16px;
  height: 0;
  border-top: 2px dashed var(--real);
}

/* Tabla año a año */
.year-table summary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  list-style: none;
  font-weight: 600;
  font-size: .9375rem;
  color: var(--accent);
}
.year-table summary::-webkit-details-marker { display: none; }
.year-table summary::before {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform .2s var(--ease-out);
}
.year-table[open] summary::before { transform: rotate(45deg); }

.table-wrap {
  margin-top: 10px;
  max-height: 360px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
  font-variant-numeric: tabular-nums;
}
th, td {
  padding: 8px 10px;
  text-align: right;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
th:first-child, td:first-child { text-align: left; }
thead th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  color: var(--ink-2);
  font-weight: 600;
}
tbody tr:last-child td { border-bottom: 0; }

.tool-note {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: .875rem;
  color: var(--muted);
}

.noscript-note {
  padding: 12px 14px;
  margin-bottom: 14px;
  border-radius: var(--radius-sm);
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
}

/* Backtest */
.bt-sentence {
  font-size: 1.0625rem;
  color: var(--ink-2);
  line-height: 1.45;
}
.bt-sentence strong { color: var(--ink); font-weight: 650; }

.bt-facts {
  font-size: .9375rem;
  color: var(--ink-2);
}

.bt-flag {
  font-size: .875rem;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--ink-2);
}

.compare h3 { margin-bottom: 8px; }
.compare .table-wrap { max-height: none; margin-top: 0; }
.compare th,
.compare td { padding-inline: 8px; }
.compare th,
.compare td:first-child { white-space: normal; }
.compare .asset-name {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.compare .tipo {
  display: block;
  padding-left: 18px;
  font-size: .8125rem;
  font-weight: 400;
  color: var(--muted);
}
.compare tr.is-current td {
  background: var(--accent-soft);
  font-weight: 700;
}
.compare .sin-datos { color: var(--muted); font-weight: 400; }

/* Aviso obligatorio */
.aviso {
  display: grid;
  gap: 6px;
  margin-top: 18px;
  padding: 14px 16px;
  border: 1px solid var(--warn-line);
  border-radius: var(--radius-sm);
  background: var(--warn-bg);
  color: var(--ink);
  font-size: .9375rem;
  line-height: 1.5;
}
.aviso strong { font-weight: 700; }

/* Huecos de anuncios (vacíos hasta activar AdSense) */
.ad-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 280px;
  margin-block: 28px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
}
.ad-slot.ad-top {
  min-height: 50px;
  margin-block: 12px 0;
}
.ad-slot.ad-lateral { display: none; }

/* Mientras AdSense no esté aprobado, los huecos no se ven (class="sin-anuncios" en <html>).
   Al pegar los anuncios, quita esa clase de index.html. */
.sin-anuncios .ad-slot { display: none !important; }
.sin-anuncios .content-grid { display: block; }

.ad-label {
  font-size: .6875rem;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}

/* =============================================================
   6. Secciones
   ============================================================= */
.hero {
  display: grid;
  gap: 8px;
  padding-top: 20px;
  padding-bottom: 16px;
}

.section-head {
  display: grid;
  gap: 6px;
  margin-bottom: 16px;
}
.section-head p { color: var(--ink-2); max-width: 66ch; }

.content {
  padding-top: 8px;
  padding-bottom: 24px;
}

.prose { max-width: 760px; }
.prose > * + * { margin-top: 1em; }
.prose h2 { margin-top: 2.4em; }
.prose h3 { margin-top: 1.7em; }
.prose h2 + *, .prose h3 + * { margin-top: .7em; }
.prose ul, .prose ol { padding-left: 1.3em; }
.prose li + li { margin-top: .4em; }
.prose .table-wrap { max-height: none; }
.prose .fuente { font-size: .875rem; color: var(--muted); }

.faq details {
  border-bottom: 1px solid var(--line);
  padding-block: 14px;
}
.faq details:first-of-type { border-top: 1px solid var(--line); }
.faq summary {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  cursor: pointer;
  list-style: none;
  font-weight: 600;
  font-size: 1.0625rem;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after {
  content: "+";
  flex: none;
  font-size: 1.4rem;
  font-weight: 400;
  line-height: 1;
  color: var(--accent);
  transition: transform .2s var(--ease-out);
}
.faq details[open] summary::after { transform: rotate(45deg); }
.faq details > p { margin-top: 10px; color: var(--ink-2); }

.site-footer {
  margin-top: 24px;
  padding-block: 28px 40px;
  border-top: 1px solid var(--line);
  font-size: .875rem;
  color: var(--muted);
}
.footer-inner { display: grid; gap: 14px; }
.footer-links { display: flex; flex-wrap: wrap; gap: 8px 20px; }
.footer-links a { color: var(--ink-2); }

/* Páginas legales */
.legal { padding-block: 28px 16px; }
.legal h1 { margin-bottom: .4em; }
.todo {
  padding: 0 4px;
  border-radius: 4px;
  background: var(--warn-bg);
  outline: 1px dashed var(--warn-line);
}

/* =============================================================
   7. Efectos
   ============================================================= */
.seg button:active,
.switch:active .switch-track { transform: scale(.98); }

/* =============================================================
   8. Responsive
   ============================================================= */
@media (min-width: 540px) {
  .container { padding-inline: 20px; }
}

@media (min-width: 720px) {
  .nav { display: flex; }
  .hero { padding-top: 40px; padding-bottom: 24px; }
  .tool-card { padding: 24px; }
  .chart { height: 280px; }
  .ad-leaderboard { min-height: 120px; }
  .ad-slot.ad-top { min-height: 90px; }
}

@media (min-width: 960px) {
  .tool-grid {
    grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
    gap: 32px;
    align-items: start;
  }
  .tool-card { padding: 28px; }
}

@media (min-width: 1280px) {
  .container { padding-inline: 24px; }
  .content-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: 40px;
    align-items: start;
  }
  .ad-slot.ad-lateral {
    display: flex;
    min-height: 600px;
    margin-block: 48px 0;
  }
}

/* =============================================================
   9. Movimiento reducido (solo lo intrusivo)
   ============================================================= */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}
