/* Siempre oscuro: fondo azul noche con resplandor cálido. El color protagonista es el de la temperatura. */

:root {
  color-scheme: dark;
  --paper: #0a0c15;
  --ink: #eef0f6;
  --ink-2: #9aa1b5;
  --rule: #232840;
  --land: #1c2340;
  --mid: #cfcbc6;          /* centro de la escala divergente: "igual que 1961–1990" */
  --focus: #8fb8ff;
  --card: rgba(18, 22, 34, 0.6);
  --glow-warm: #ff5a36;
  --grad: linear-gradient(90deg, #7fb2ff 0%, #ffd27f 55%, #ff5a36 100%);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background-color: var(--paper);
  background-image:
    radial-gradient(900px 600px at 95% 0%, rgba(90, 26, 18, 0.33), transparent 60%),
    radial-gradient(800px 700px at 0% 45%, rgba(27, 42, 90, 0.27), transparent 60%),
    radial-gradient(900px 700px at 100% 100%, rgba(122, 31, 18, 0.27), transparent 60%);
  background-attachment: fixed;
  color: var(--ink);
  font-family: "Schibsted Grotesk", system-ui, sans-serif;
  font-size: 18px;
  line-height: 1.55;
}

main {
  max-width: 1040px;
  margin: 0 auto;
  padding: 72px 24px 48px;
}

a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* --- Apertura -------------------------------------------------------------- */

.opening { max-width: 760px; }

h1 {
  margin: 0;
  font-size: clamp(32px, 5.4vw, 54px);
  line-height: 1.08;
  font-weight: 800;
  letter-spacing: -0.02em;
  text-wrap: balance;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.dek {
  margin: 20px 0 0;
  max-width: 60ch;
  color: var(--ink-2);
  font-size: 20px;
}

/* --- Franjas del país ------------------------------------------------------ */

.national { margin: 48px 0 0; }

.stripes-wide { border-radius: 14px; overflow: hidden; box-shadow: 0 0 70px rgba(255, 90, 54, 0.25), 0 0 0 1px rgba(255, 255, 255, 0.08); }
.stripes-wide svg { display: block; width: 100%; height: auto; }

.national figcaption {
  display: grid;
  gap: 6px;
  margin-top: 10px;
  color: var(--ink-2);
  font-size: 15px;
}

.ends {
  display: flex;
  justify-content: space-between;
  color: var(--ink);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* --- Secciones ---------------------------------------------------------------- */

section { margin-top: 96px; }

h2 {
  margin: 0;
  font-size: 28px;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.lead { margin: 8px 0 0; max-width: 60ch; color: var(--ink-2); }

/* --- Qué ver ------------------------------------------------------------------------ */

.metric-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 28px;
}

.metric-picker button {
  font: inherit;
  font-size: 16px;
  padding: 6px 14px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--ink);
  cursor: pointer;
}

.metric-picker button:hover { border-color: var(--ink-2); }

.metric-picker button[aria-checked="true"] {
  background: linear-gradient(90deg, #3b6fd4, #e2542b);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 0 24px rgba(226, 84, 43, 0.35);
}

/* --- Puntos / mapa de calor ------------------------------------------------------ */

.view-toggle {
  display: inline-flex;
  margin-bottom: 12px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  overflow: hidden;
}

.view-toggle button {
  font: inherit;
  font-size: 15px;
  padding: 6px 14px;
  border: 0;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
}

.view-toggle button + button { border-left: 1px solid var(--rule); }
.view-toggle button:hover { color: var(--ink); }
.view-toggle button[aria-checked="true"] { color: var(--ink); font-weight: 700; background: var(--land); }

/* --- Escala de color bajo el mapa ---------------------------------------------- */

.scale { margin-top: 12px; max-width: 440px; }
.scale-bar { height: 10px; border-radius: 2px; }
.scale-labels {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 6px;
  color: var(--ink-2);
  font-size: 14px;
}
.scale-labels span:last-child { text-align: right; }
.scale-labels strong { color: var(--ink); font-weight: 500; }

/* --- Mapa y lista ---------------------------------------------------------------- */

.map-and-list {
  display: grid;
  grid-template-columns: minmax(0, 440px) minmax(0, 1fr);
  gap: 56px;
  margin-top: 32px;
  align-items: stretch;
}

/* En escritorio la columna derecha mide lo mismo que la del mapa (height:0 + min-height:100%
   evita que la lista empuje la altura de la fila). */
.list-col { display: flex; flex-direction: column; height: 0; min-height: 100%; }
.list-col .city-list { flex: 1 1 0; min-height: 160px; }
.city-detail { flex: none; }

.map { background: radial-gradient(circle at 50% 40%, #161c33, #0c0f1c); border: 1px solid var(--rule); border-radius: 18px; padding: 8px; }
.map svg { display: block; width: 100%; height: auto; cursor: pointer; }
.map .heat-layer { filter: blur(4px); }

.timeline {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.play {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: none;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, #ffb35a, #e2542b);
  box-shadow: 0 0 20px rgba(226, 84, 43, 0.4);
  color: #fff;
  cursor: pointer;
}

.play:hover { box-shadow: 0 0 28px rgba(226, 84, 43, 0.65); }

.timeline input[type="range"] { flex: 1; min-width: 0; accent-color: #ff8a5c; }

.timeline output {
  min-width: 3ch;
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}


/* La lista se queda de la altura del mapa y se desplaza por dentro, con un degradé al pie. */
.city-list {
  list-style: none;
  margin: 0;
  padding: 0 0 48px;
  border-top: 1px solid var(--rule);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--rule) transparent;
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 56px), transparent);
  mask-image: linear-gradient(to bottom, #000 calc(100% - 56px), transparent);
}

.city-list li { border-bottom: 1px solid var(--rule); }

.city-list button {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 9px 4px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 17px;
  text-align: left;
  cursor: pointer;
}

.city-list button:hover .name,
.city-list li.is-hovered .name { text-decoration: underline; text-underline-offset: 3px; }
.city-list li.is-hovered { background: color-mix(in srgb, var(--rule) 45%, transparent); }

.city-list button[aria-pressed="true"] { font-weight: 700; }
.city-list button[aria-pressed="true"] .swatch { box-shadow: 0 0 0 2px var(--paper), 0 0 0 3.5px var(--ink); }

.city-list .swatch { width: 12px; height: 12px; border-radius: 50%; box-shadow: 0 0 10px currentColor; }
.city-list .region { color: var(--ink-2); font-size: 14px; font-weight: 400; margin-left: 6px; }
.city-list .value { white-space: nowrap; }
.city-list button:disabled { cursor: default; color: var(--ink-2); }

/* --- Ficha de la ciudad ---------------------------------------------------------- */

/* La ficha va en la columna derecha, al lado del mapa y arriba de la lista. */
.city-detail { margin-bottom: 32px; padding: 22px; background: var(--card); border: 1px solid var(--rule); border-radius: 18px; backdrop-filter: blur(6px); }
.city-detail:empty { display: none; }

.city-detail h3 { margin: 0; font-size: 24px; line-height: 1.2; }
.city-detail .where { margin: 2px 0 0; color: var(--ink-2); font-size: 16px; }
.city-detail .story { margin: 14px 0 0; max-width: 62ch; }

/* Todos los indicadores de la ciudad; el que está activo en el mapa va resaltado. */
.indicators {
  margin: 20px 0 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--rule);
}

.indicators li { border-bottom: 1px solid var(--rule); }

.indicators button {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 16px;
  width: 100%;
  padding: 8px 4px;
  border: 0;
  background: transparent;
  color: var(--ink-2);
  font: inherit;
  font-size: 16px;
  text-align: left;
  cursor: pointer;
}

.indicators button:hover { color: var(--ink); }
.indicators button[aria-current="true"] { color: var(--ink); font-weight: 700; }
.indicators .from-to { white-space: nowrap; }
.indicators .delta { min-width: 6.5ch; text-align: right; white-space: nowrap; }
.city-detail .mini-title { margin: 24px 0 0; color: var(--ink-2); font-size: 15px; }
.city-detail .mini { margin-top: 8px; }
.city-detail .mini svg { display: block; width: 100%; height: auto; }
.city-detail .mini-ends {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  color: var(--ink-2);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

/* --- Hallazgos ------------------------------------------------------------------ */

.findings ul {
  margin: 28px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.findings li {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 22px;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 18px;
  backdrop-filter: blur(6px);
}

.f-eyebrow { color: var(--ink-2); font-size: 13px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; }

.f-big {
  font-size: clamp(34px, 4.2vw, 46px);
  line-height: 1.1;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.f-text { margin: 4px 0 0; color: var(--ink); font-size: 16px; line-height: 1.45; }

@media (max-width: 900px) { .findings ul { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) { .findings ul { grid-template-columns: 1fr; } }

.all-numbers { margin-top: 32px; }

.all-numbers summary {
  cursor: pointer;
  font-weight: 500;
  width: fit-content;
}

.table-wrap { overflow-x: auto; margin-top: 16px; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

th, td { padding: 8px 14px; text-align: right; border-bottom: 1px solid var(--rule); }
th:first-child, td:first-child { text-align: left; padding-left: 0; }
th { color: var(--ink-2); font-weight: 500; vertical-align: bottom; }

/* --- Sobre el proyecto ------------------------------------------------------------ */

.about p { max-width: 64ch; margin: 16px 0 0; }
.about .small { color: var(--ink-2); font-size: 15px; }

footer {
  margin-top: 72px;
  padding-top: 20px;
  border-top: 1px solid var(--rule);
  color: var(--ink-2);
  font-size: 14px;
}

footer p { margin: 0; max-width: 80ch; }

/* --- Tooltips de Plot ---------------------------------------------------------- */

svg { --plot-background: var(--paper); }

/* --- Pantallas chicas ----------------------------------------------------------- */

@media (max-width: 820px) {
  .map-and-list { grid-template-columns: 1fr; gap: 32px; }
  .map-col { max-width: 440px; }
  .list-col { height: auto; min-height: 0; }
  .list-col .city-list { flex: none; max-height: 420px; }
}

@media (max-width: 520px) {
  body { font-size: 17px; }
  main { padding: 40px 16px 32px; }
  .national { margin-top: 32px; }
  section { margin-top: 72px; }
  h2 { font-size: 24px; }
  .dek { font-size: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}

/* --- Animaciones de entrada (solo la primera vez) -----------------------------------
   `js-anim` lo pone un script en el <head> y solo si el sistema no pide reducir movimiento.
   Sin esa clase, todo se ve normal desde el principio. */

@media (prefers-reduced-motion: no-preference) {
  .js-anim .reveal {
    opacity: 0;
    transform: translateY(16px);
    transition:
      opacity 0.8s cubic-bezier(0.2, 0.65, 0.25, 1) var(--delay, 0ms),
      transform 0.8s cubic-bezier(0.2, 0.65, 0.25, 1) var(--delay, 0ms);
  }

  .js-anim .reveal.is-in { opacity: 1; transform: none; }

  /* Listas: cada elemento entra un poco después del anterior. */
  .js-anim .stagger > * {
    opacity: 0;
    transform: translateY(10px);
    transition:
      opacity 0.6s cubic-bezier(0.2, 0.65, 0.25, 1) calc(var(--i, 0) * var(--step, 70ms) + 80ms),
      transform 0.6s cubic-bezier(0.2, 0.65, 0.25, 1) calc(var(--i, 0) * var(--step, 70ms) + 80ms);
  }

  .js-anim .stagger.is-in > * { opacity: 1; transform: none; }

  /* Franjas del país: se pintan año por año, de 1940 a hoy. */
  .stripes-intro rect {
    animation: stripe-in 0.55s cubic-bezier(0.2, 0.65, 0.25, 1) both;
    animation-delay: var(--d, 0ms);
    transform-box: fill-box;
    transform-origin: 50% 100%;
  }

  /* Mapa: aparece el territorio y después las ciudades, de norte a sur. */
  .map-intro path { animation: fade-in 0.6s ease both; }
  .map-intro circle {
    animation: dot-in 0.5s cubic-bezier(0.3, 1.4, 0.5, 1) both;
    animation-delay: var(--d, 0ms);
    transform-box: fill-box;
    transform-origin: center;
  }
  .map-intro text { animation: fade-in 0.5s ease both; animation-delay: var(--d, 0ms); }
}

@keyframes stripe-in { from { opacity: 0; transform: scaleY(0.15); } }
@keyframes dot-in { from { opacity: 0; transform: scale(0); } }
@keyframes fade-in { from { opacity: 0; } }
