  :root {
    --bg: #FAF8F3;            /* crema sutil — área principal */
    --bg-page: #FFFFFF;       /* blanco puro para fondo de página exterior si aplica */
    --bg-soft: #F4F1E8;       /* tono ligeramente más cálido para chips inactivos */
    --ink: #1A1A1A;           /* tinta editorial neutra (pizarra muy oscura) */
    --ink-soft: #4A4A4A;
    --ink-muted: #8A8579;
    --rule: #E0DCC8;
    --rule-strong: #C9C2B2;
    --accent: #BE5D32;        /* terracota */
    --grid: #ECE7D8;
    --regression: #1A1A1A;

    --serif: 'Source Serif 4', Georgia, "Times New Roman", serif;
    --sans:  'Source Sans 3', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  }
  * { box-sizing: border-box; }
  html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--serif);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }
  .wrap {
    max-width: 760px;
    margin: 0 auto;
    padding: 22px 20px 30px;
  }

  /* ================ HEADER ================= */
  header {
    border-bottom: 1px solid var(--rule);
    padding-bottom: 16px;
    margin-bottom: 22px;
    position: relative;
  }
  .top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
  }
  .brand {
    font-family: var(--sans);
    font-size: 10.5px;
    letter-spacing: 1.6px;
    text-transform: uppercase;
    color: var(--ink-soft);
    font-weight: 500;
  }
  .brand-em {
    color: var(--ink);
    font-weight: 600;
  }
  .lang-toggle {
    display: inline-flex;
    gap: 0;
    font-family: var(--sans);
    font-size: 10px;
    letter-spacing: 1px;
    text-transform: uppercase;
  }
  .lang-toggle button {
    background: transparent;
    border: 0;
    border-bottom: 1.5px solid transparent;
    padding: 2px 8px;
    cursor: pointer;
    color: var(--ink-muted);
    font-family: inherit;
    font-size: inherit;
    letter-spacing: inherit;
    text-transform: inherit;
    font-weight: 500;
  }
  .lang-toggle button.active {
    color: var(--ink);
    border-bottom-color: var(--accent);
  }
  h1 {
    font-family: var(--serif);
    font-size: 30px;
    line-height: 1.18;
    margin: 0;
    font-weight: 700;
    letter-spacing: -0.4px;
  }
  .lede {
    font-family: var(--serif);
    font-size: 15.5px;
    color: var(--ink-soft);
    margin: 6px 0 0;
    font-style: italic;
    font-weight: 400;
  }
  .accent-rule {
    width: 36px;
    height: 2.5px;
    background: var(--accent);
    margin: 12px 0 0;
  }

  /* ================ CHART BLOCKS ================= */
  .chart-block {
    margin: 30px 0 4px;
  }
  .chart-title {
    font-family: var(--serif);
    font-size: 19px;
    font-weight: 700;
    margin: 0 0 4px;
    line-height: 1.25;
    letter-spacing: -0.1px;
  }
  .chart-subtitle {
    font-family: var(--serif);
    font-size: 14.5px;
    color: var(--ink-soft);
    margin: 0 0 14px;
    font-weight: 400;
    line-height: 1.5;
  }
  .controls {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    align-items: center;
    margin: 8px 0 10px;
    font-family: var(--sans);
    font-size: 11.5px;
  }
  .ctrl-group {
    display: flex;
    align-items: center;
    gap: 7px;
  }
  .ctrl-label {
    color: var(--ink-muted);
    text-transform: uppercase;
    letter-spacing: 0.9px;
    font-size: 9.5px;
    font-weight: 500;
  }
  .toggle {
    display: inline-flex;
    border: 1px solid var(--rule-strong);
    border-radius: 3px;
    overflow: hidden;
    background: white;
  }
  .toggle button {
    background: transparent;
    border: 0;
    padding: 4px 11px;
    font-family: var(--sans);
    font-size: 10.5px;
    color: var(--ink-soft);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    letter-spacing: 0.3px;
    font-weight: 500;
  }
  .toggle button.active {
    background: var(--ink);
    color: var(--bg);
  }
  .toggle button:not(.active):hover {
    background: var(--bg-soft);
    color: var(--ink);
  }
  .region-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin: 6px 0 6px;
  }
  /* CHIPS: active por default = pintado con color de región */
  .region-chip {
    font-family: var(--sans);
    font-size: 10.5px;
    padding: 3px 11px;
    border: 1px solid transparent;
    border-radius: 11px;
    cursor: pointer;
    transition: all 0.13s;
    user-select: none;
    white-space: nowrap;
    font-weight: 500;
    letter-spacing: 0.1px;
    color: white;
  }
  .region-chip.inactive {
    background: transparent !important;
    color: var(--ink-muted) !important;
    text-decoration: line-through;
    text-decoration-color: var(--ink-muted);
    text-decoration-thickness: 1px;
  }
  .region-chip.hovering {
    box-shadow: 0 0 0 2px var(--ink);
  }

  /* ================ TS LEGEND (chart 3) ================ */
  .ts-legend {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 18px;
    margin: 14px 0 4px;
    padding: 6px 0;
    font-family: var(--sans);
    font-size: 12.5px;
    color: var(--ink);
  }
  .ts-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-weight: 500;
  }
  .ts-swatch {
    display: inline-block;
    width: 18px;
    height: 3px;
    border-radius: 1.5px;
  }
  .ts-legend-hint {
    color: var(--ink-soft);
    font-size: 11.5px;
    font-style: italic;
  }
  /* Líneas de spaghetti (países individuales) */
  .ts-line-bg {
    fill: none;
    stroke-width: 0.9;
    opacity: 0.4;
    pointer-events: stroke;
    transition: opacity 0.15s ease, stroke 0.15s ease, stroke-width 0.15s ease;
    cursor: pointer;
  }
  /* Dos tonos de gris muy sutiles: LATAM cálido, Caribe frío */
  .ts-line-bg.latam {
    stroke: #B5AC9A;
  }
  .ts-line-bg.caribbean {
    stroke: #A6ADAE;
  }
  /* Cuando hay un país hovereado, los demás se atenúan más */
  .ts-line-bg.dimmed {
    opacity: 0.12;
  }
  /* La línea hovereada (transitorio) se ilumina */
  .ts-line-bg.highlight {
    stroke-width: 2;
    opacity: 1;
  }
  .ts-line-bg.highlight.latam {
    stroke: #BE5D32;
  }
  .ts-line-bg.highlight.caribbean {
    stroke: #D89968;
  }
  /* Líneas destacadas (países seleccionados, cualquier región).
     El stroke se setea inline desde JS con SELECTED_PALETTE. */
  .ts-line-highlight {
    fill: none;
    stroke-width: 2;
    opacity: 1;
    pointer-events: stroke;
    cursor: pointer;
  }
  /* Líneas principales (LATAM+Caribe y Mundo) — más gruesas con halo blanco */
  .ts-line-main-halo {
    fill: none;
    stroke: var(--bg);
    stroke-width: 6;
    stroke-linejoin: round;
    stroke-linecap: round;
    pointer-events: none;
  }
  .ts-line-main {
    fill: none;
    stroke-width: 3.2;
    stroke-linejoin: round;
    stroke-linecap: round;
    pointer-events: none;
  }
  .ts-line-main.latam_caribe { stroke: #BE5D32; }
  .ts-line-main.world        { stroke: #3E5A6E; }
  /* Etiqueta inline al final de las líneas principales */
  .ts-end-label {
    font-family: var(--sans);
    font-size: 11.5px;
    font-weight: 600;
    pointer-events: none;
    paint-order: stroke;
    stroke: var(--bg);
    stroke-width: 3px;
    stroke-linejoin: round;
  }
  .ts-end-label.latam_caribe { fill: #8B3F1E; }
  .ts-end-label.world        { fill: #243B4E; }
  /* Etiqueta de país hovereado/seleccionado en el spaghetti */
  .ts-hover-label {
    font-family: var(--sans);
    font-size: 11px;
    font-weight: 600;
    pointer-events: none;
    paint-order: stroke;
    stroke: var(--bg);
    stroke-width: 3px;
    stroke-linejoin: round;
  }
  /* Línea vertical de hover */
  .ts-hover-vline {
    stroke: var(--ink-soft);
    stroke-width: 0.7;
    stroke-dasharray: 3 3;
    pointer-events: none;
    opacity: 0.8;
  }
  /* Markers de hover (puntos sobre las líneas en el año del cursor) */
  .ts-hover-marker {
    pointer-events: none;
    stroke: var(--bg);
    stroke-width: 1.5;
  }
  /* Buscador y chips de selección */
  .ts-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 14px;
    margin: 6px 0 0;
  }
  .ts-search-wrap {
    position: relative;
    display: inline-block;
  }
  .ts-search-input {
    font-family: var(--sans);
    font-size: 12.5px;
    padding: 5px 10px;
    border: 1px solid var(--grid);
    border-radius: 4px;
    background: var(--bg);
    color: var(--ink);
    width: 200px;
    outline: none;
    transition: border-color 0.15s;
  }
  .ts-search-input:focus {
    border-color: var(--ink-soft);
  }
  .ts-search-results {
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 10;
    background: var(--bg);
    border: 1px solid var(--grid);
    border-radius: 4px;
    max-height: 240px;
    overflow-y: auto;
    width: 220px;
    margin-top: 2px;
    display: none;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  }
  .ts-search-results.open {
    display: block;
  }
  .ts-search-result {
    padding: 6px 10px;
    font-family: var(--sans);
    font-size: 12.5px;
    color: var(--ink);
    cursor: pointer;
    border-bottom: 1px solid #EFEAE0;
  }
  .ts-search-result:last-child {
    border-bottom: none;
  }
  .ts-search-result:hover, .ts-search-result.active {
    background: #F0EBDF;
  }
  .ts-search-result .reg {
    font-size: 10.5px;
    color: var(--ink-muted);
    margin-left: 4px;
  }
  .ts-selected-chips {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
  }
  .ts-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 6px 3px 10px;
    border-radius: 12px;
    font-family: var(--sans);
    font-size: 12px;
    font-weight: 500;
    color: var(--bg);
    cursor: default;
  }
  .ts-chip-x {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: rgba(255,255,255,0.25);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    border: none;
    color: inherit;
    padding: 0;
    transition: background 0.15s;
  }
  .ts-chip-x:hover {
    background: rgba(255,255,255,0.45);
  }
  /* Toggle Lineal/Log para chart 3, mismo estilo que los otros */

  /* ================ SVG ================= */
  svg {
    width: 100%;
    height: auto;
    display: block;
    overflow: visible;
  }
  .chart-svg-wrap {
    position: relative;
    margin: 4px 0 0;
    background: var(--bg);
  }
  .axis text, text.axis {
    font-family: var(--sans);
    font-size: 12px;
    fill: var(--ink-soft);
    font-weight: 400;
  }
  .axis-title {
    font-family: var(--sans);
    font-size: 12.5px;
    fill: var(--ink);
    font-weight: 600;
    letter-spacing: 0.1px;
  }
  .axis line, .axis path {
    stroke: var(--ink-muted);
    stroke-width: 0.6;
    fill: none;
  }
  .grid line, line.grid-line {
    stroke: var(--grid);
    stroke-width: 0.6;
  }
  .point {
    cursor: pointer;
    transition: r 0.12s, fill-opacity 0.15s, stroke-opacity 0.15s;
  }
  .point.dimmed {
    fill-opacity: 0.12 !important;
    stroke-opacity: 0.12 !important;
  }
  .point.spotlight {
    fill-opacity: 1 !important;
  }
  .regression {
    stroke: var(--regression);
    stroke-width: 1.3;
    fill: none;
    stroke-dasharray: 4 3;
    opacity: 0.75;
  }
  .country-label {
    font-family: var(--sans);
    font-size: 10.5px;
    pointer-events: none;
    font-weight: 400;
    paint-order: stroke;
    stroke: var(--bg);
    stroke-width: 2.5px;
    stroke-linejoin: round;
    /* fill se setea inline (color de la región oscurecido) */
  }
  .country-label.spotlight-label {
    font-weight: 500;
  }

  /* ================ TOOLTIP ================= */
  .tooltip {
    position: absolute;
    background: var(--ink);
    color: white;
    padding: 9px 12px;
    border-radius: 4px;
    font-family: var(--sans);
    font-size: 11.5px;
    line-height: 1.5;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.12s;
    z-index: 10;
    max-width: 230px;
    box-shadow: 0 4px 14px rgba(0,0,0,0.18);
  }
  .tooltip strong {
    display: block;
    font-size: 13.5px;
    margin-bottom: 3px;
    font-weight: 600;
    font-family: var(--serif);
    letter-spacing: -0.1px;
  }
  .tooltip .tt-region {
    color: #C9C2B2;
    font-size: 9.5px;
    text-transform: uppercase;
    letter-spacing: 0.9px;
    margin-bottom: 6px;
    font-weight: 500;
  }
  .tooltip .tt-row {
    display: flex;
    justify-content: space-between;
    gap: 14px;
  }
  .tooltip .tt-row span:first-child {
    color: #C9C2B2;
  }
  .tooltip .tt-year {
    color: #8A8579;
    font-size: 9.5px;
    margin-top: 5px;
    font-weight: 400;
  }

  /* ================ FOOTER ================= */
  .footer {
    margin-top: 32px;
    padding-top: 16px;
    border-top: 1px solid var(--rule);
    font-family: var(--sans);
    font-size: 11px;
    color: var(--ink-muted);
    line-height: 1.6;
  }
  .footer p {
    margin: 0 0 10px;
  }
  .footer em {
    font-family: var(--serif);
    font-style: italic;
  }
  .download {
    display: inline-block;
    padding: 6px 14px;
    background: var(--ink);
    color: var(--bg);
    text-decoration: none;
    font-family: var(--sans);
    font-size: 11px;
    letter-spacing: 0.5px;
    border-radius: 3px;
    border: 0;
    cursor: pointer;
    font-weight: 500;
    text-transform: uppercase;
  }
  .download:hover {
    background: #000;
  }
  .signature {
    font-family: var(--serif);
    font-style: italic;
    font-size: 12px;
    color: var(--ink-soft);
  }
  /* Última línea del footer: fuente a la izquierda (bloque multi-línea),
     atribución editorial a la derecha (link al Substack).
     align-items: center — la atribución se centra VERTICALMENTE con
     respecto al bloque de fuente, así si hay 3 renglones queda alineada
     con el centro (mitad del segundo renglón). Antes era flex-end y la
     atribución quedaba pegada al bottom, lo que se veía desalineado. */
  .footer-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 24px;
    margin-top: 6px;
  }
  .footer-row .sources {
    flex: 1;
    margin: 0;
  }
  .attribution {
    flex-shrink: 0;
    white-space: nowrap;
    font-family: var(--sans);
    font-size: 11px;
    font-weight: 600;
    color: var(--accent);
    text-decoration: none;
    letter-spacing: 0.1px;
  }
  .attribution:hover {
    text-decoration: underline;
    text-decoration-color: var(--accent);
    text-underline-offset: 2px;
  }

  @media (max-width: 540px) {
    .wrap { padding: 18px 14px 24px; }
    h1 { font-size: 24px; }
    .chart-title { font-size: 17px; }
    .chart-subtitle { font-size: 13.5px; }
    .controls { gap: 10px; }
    .country-label { font-size: 9px; }
    .top-bar { flex-direction: column; align-items: flex-start; gap: 6px; }
  }
