/* ==========================================================================
   Mousson du Kerala
   Mise en page : récit éditorial. Une colonne de texte décalée (≈ 62 caractères),
   des graphiques larges (jusqu'à 1 180 px) ou pleine largeur, une bande sombre
   pour le climax (août 2018). Atlas de la mousson × typographie malayalam.
   ========================================================================== */

:root {
  color-scheme: light;

  /* Papier de mousson, encre vert-noir, sarcelle de pluie, latérite */
  --bg: #f4f6f2;
  --surface: #fbfcfa;
  --ink: #10221d;
  --ink-2: #3e504a;
  --muted: #66766f;
  --line: #d7dfd9;
  --axis: #aebbb4;
  --accent: #0d6e5f;
  --accent-ink: #ffffff;

  /* Couleurs des données (paires validées pour la vision des couleurs) */
  --rain: #0a83a0;
  --laterite: #b4532a;
  --paddy: #c08a12;
  --rubber: #167d57;
  --built: #46524e;
  --gardens: #d3ddcc;
  --forest: #9bb39f;
  --water: #b9d0d6;
  --other: #e2e6df;
  --context: #c3ccc6;
  --band-trend: rgba(16, 34, 29, 0.1);

  /* Rampe « pluie » (séquentielle, dérivée de ColorBrewer YlGnBu) */
  --rain-ramp: #ffffd9, #edf8b1, #c7e9b4, #7fcdbb, #41b6c4, #1d91c0, #225ea8, #253494, #081d58;
  /* Rampe divergente des anomalies de température (milieu neutre) */
  --diverging-ramp: #1d4f91, #3e75b5, #7ba3d2, #bdd2ea, #ecebe7, #f1c6b4, #e08d70, #c4513a, #8e2416;

  /* Polices : titres Anek Malayalam, mot malayalam Manjari (SMC), texte Literata, interface Mukta */
  --font-display: "Anek Malayalam", "Mukta", system-ui, sans-serif;
  --font-ml: "Manjari", "Anek Malayalam", sans-serif;
  --font-text: "Literata", Georgia, "Times New Roman", serif;
  --font-body: "Mukta", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "Mukta", system-ui, sans-serif;

  --text-col: 40rem;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0b1512;
    --surface: #101d19;
    --ink: #e6eee9;
    --ink-2: #b6c5bf;
    --muted: #84958e;
    --line: #22332e;
    --axis: #3a4c46;
    --accent: #45c2a6;
    --accent-ink: #062019;
    --rain: #2a9bb3;
    --laterite: #d0703f;
    --paddy: #b8861a;
    --rubber: #2f9a74;
    --built: #c9d3cf;
    --gardens: #2c3a33;
    --forest: #3f5a49;
    --water: #2b4650;
    --other: #1d2824;
    --context: #3c4a45;
    --band-trend: rgba(230, 238, 233, 0.12);
    --rain-ramp: #13252b, #15363f, #184a57, #1c5f71, #23768c, #2f8ea8, #47a8c4, #72c2dc, #b4e0f2;
    --diverging-ramp: #8fbdf0, #5f93d0, #3c6aa3, #284769, #26302d, #6a3428, #9c4a35, #d16a4d, #f29a7c;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1512;
  --surface: #101d19;
  --ink: #e6eee9;
  --ink-2: #b6c5bf;
  --muted: #84958e;
  --line: #22332e;
  --axis: #3a4c46;
  --accent: #45c2a6;
  --accent-ink: #062019;
  --rain: #2a9bb3;
  --laterite: #d0703f;
  --paddy: #b8861a;
  --rubber: #2f9a74;
  --built: #c9d3cf;
  --gardens: #2c3a33;
  --forest: #3f5a49;
  --water: #2b4650;
  --other: #1d2824;
  --context: #3c4a45;
  --band-trend: rgba(230, 238, 233, 0.12);
  --rain-ramp: #13252b, #15363f, #184a57, #1c5f71, #23768c, #2f8ea8, #47a8c4, #72c2dc, #b4e0f2;
  --diverging-ramp: #8fbdf0, #5f93d0, #3c6aa3, #284769, #26302d, #6a3428, #9c4a35, #d16a4d, #f29a7c;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
}

/* ---------- Grille éditoriale ---------- */

.story {
  display: grid;
  grid-template-columns:
    [full-start] max(16px, env(safe-area-inset-left, 0px))
    [wide-start text-start] minmax(0, 1fr)
    [text-end wide-end] max(16px, env(safe-area-inset-right, 0px))
    [full-end];
}

@media (min-width: 980px) {
  .story {
    grid-template-columns:
      [full-start] minmax(24px, 1fr)
      [wide-start] minmax(0, 9rem)
      [text-start] minmax(0, var(--text-col))
      [text-end] minmax(0, 24rem)
      [wide-end] minmax(24px, 1fr)
      [full-end];
  }
}

.story > *,
.chapter > *,
.band__inner > * {
  grid-column: text;
  min-width: 0;
}

.chapter,
.band,
.band__inner {
  grid-column: full;
  display: grid;
  grid-template-columns: subgrid;
}

/* Navigateurs sans sous-grille : colonne centrée simple */
@supports not (grid-template-columns: subgrid) {
  .chapter,
  .band,
  .band__inner {
    display: block;
  }

  .chapter > *,
  .band__inner > * {
    max-width: var(--text-col);
    margin-inline: auto;
    padding-inline: 16px;
  }

  .chapter > .wide,
  .band__inner > .wide {
    max-width: 1180px;
  }

  .chapter > .full {
    max-width: none;
    padding-inline: 0;
  }
}

.story .wide,
.chapter > .wide,
.band__inner > .wide {
  grid-column: wide;
}

.story .full,
.chapter > .full {
  grid-column: full;
}

.chapter {
  padding-block: 7rem 2rem;
  row-gap: 1.75rem;
}

/* Texte courant */
.text {
  display: grid;
  gap: 1.1rem;
}

.text p,
.standfirst,
.step p,
.more__body > p {
  font-family: var(--font-text);
  font-size: 1.1875rem;
  line-height: 1.62;
  color: var(--ink-2);
  font-optical-sizing: auto;
}

.text p strong,
.step p strong {
  color: var(--ink);
  font-weight: 650;
}

.text a {
  color: var(--ink);
}

.headline,
.chapter__title,
.subhead {
  font-family: var(--font-display);
  font-variation-settings: "wdth" 84;
  font-weight: 760;
  line-height: 1.02;
  letter-spacing: -0.012em;
  color: var(--ink);
}

.headline {
  font-size: clamp(2.6rem, 1.5rem + 4vw, 4.9rem);
}

.chapter__title {
  font-size: clamp(2.1rem, 1.5rem + 2.6vw, 3.6rem);
  max-width: 18ch;
}

.subhead {
  font-size: clamp(1.6rem, 1.3rem + 1.2vw, 2.3rem);
  max-width: 24ch;
  margin-top: 3rem;
}

.standfirst {
  font-size: clamp(1.25rem, 1.12rem + 0.5vw, 1.45rem);
  line-height: 1.5;
  color: var(--ink-2);
}

.byline {
  font-size: 0.9375rem;
  line-height: 1.5;
  color: var(--muted);
}

.source {
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--muted);
  max-width: 70ch;
}

/* ---------- Barre du haut (sobre) ---------- */

.topbar {
  border-bottom: 1px solid var(--line);
}

.brand {
  font-family: var(--font-display);
  font-variation-settings: "wdth" 90;
  font-weight: 700;
  font-size: 1.05rem;
}

/* ---------- En-tête ---------- */

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 2.5rem 3.5rem;
  align-items: center;
  padding-block: 3.5rem 2.5rem;
}

.hero__text {
  display: grid;
  gap: 1.6rem;
  align-content: center;
}

.clock {
  margin: 0;
  display: grid;
  gap: 0.75rem;
  justify-items: center;
}

.clock__plot {
  position: relative;
  width: 100%;
  max-width: 640px;
  aspect-ratio: 1;
}

.clock__plot > svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.clock__plot svg:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 6px;
  border-radius: 50%;
}

.clock__caption {
  display: grid;
  gap: 0.6rem;
  justify-items: center;
  max-width: 30rem;
  font-size: 0.875rem;
  line-height: 1.45;
  color: var(--ink-2);
  text-align: center;
}

.clock-cells path {
  transition: opacity 0.2s;
}

.clock-cells.is-filling path {
  animation: cell-in 0.45s ease-out both;
  animation-delay: calc(var(--d) * 1ms);
}

@keyframes cell-in {
  from {
    opacity: 0;
  }
}

.clock-month {
  fill: var(--ink-2);
  font: 500 13px/1 var(--font-body);
}

.clock-month--monsoon {
  fill: var(--ink);
  font-weight: 700;
}

.clock-year {
  fill: var(--muted);
  font: 500 11px/1 var(--font-body);
  paint-order: stroke;
  stroke: var(--bg);
  stroke-width: 3px;
}

.clock-word {
  fill: var(--accent);
  font-family: var(--font-ml);
  font-weight: 700;
}

.clock-gloss {
  fill: var(--muted);
  font-family: var(--font-body);
  font-weight: 500;
}

.clock-read__year {
  fill: var(--ink);
  font-family: var(--font-display);
  font-weight: 760;
}

.clock-read__line {
  fill: var(--ink-2);
  font-family: var(--font-body);
  font-weight: 500;
}

.clock-focus {
  fill: none;
  stroke: var(--ink);
  stroke-width: 2;
  pointer-events: none;
}

.clock-ring {
  fill: none;
  stroke: var(--ink);
  stroke-opacity: 0.35;
  pointer-events: none;
}

.ramp {
  width: min(100%, 22rem);
}

/* ---------- Défilement (scrollytelling) ---------- */

.scrolly {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(0, 0.75fr);
  gap: 0 3.5rem;
  margin-top: 1.5rem;
}

.scrolly__graphic {
  position: sticky;
  top: calc(var(--topbar-h) + 2vh);
  height: calc(100vh - var(--topbar-h) - 4vh);
  margin: 0;
  display: flex;
  align-items: center;
}

.scrolly__plot {
  width: 100%;
}

.scrolly__steps {
  padding-block: 18vh 30vh;
}

.step {
  min-height: 72vh;
  display: flex;
  align-items: center;
}

.step p {
  margin: 0;
  padding-block: 1rem;
  border-top: 2px solid var(--line);
  transition: color 0.4s, border-color 0.4s;
}

.step.is-active p {
  border-top-color: var(--accent);
}

.step:not(.is-active) p {
  color: var(--muted);
}

.step:not(.is-active) p strong {
  color: var(--muted);
}

/* États du graphique de la mousson */
.monsoon .mbar {
  fill: var(--rain);
  transition: fill 0.5s;
}

.monsoon[data-step="1"] .mbar:not(.is-monsoon) {
  fill: var(--context);
}

.monsoon .ybar {
  fill: var(--rain);
  transform-box: fill-box;
  transform-origin: 50% 100%;
  transform: scaleY(0);
  transition: transform 0.6s cubic-bezier(0.2, 0.7, 0.2, 1);
  transition-delay: calc(var(--i) * 5ms);
}

.monsoon .ybar.is-dry {
  fill: var(--laterite);
}

.monsoon[data-step="2"] .ybar,
.monsoon[data-step="3"] .ybar {
  transform: scaleY(1);
}

.monsoon .layer {
  transition: opacity 0.5s;
}

.monsoon .layer--months,
.monsoon .note--july {
  opacity: 1;
}

.monsoon .layer--years,
.monsoon .note--bracket,
.monsoon .note--dry,
.monsoon .note--trend,
.monsoon .threshold {
  opacity: 0;
}

.monsoon[data-step="1"] .note--bracket {
  opacity: 1;
}

.monsoon[data-step="1"] .note--july,
.monsoon[data-step="2"] .note--july,
.monsoon[data-step="3"] .note--july,
.monsoon[data-step="2"] .layer--months,
.monsoon[data-step="3"] .layer--months {
  opacity: 0;
}

.monsoon[data-step="2"] .layer--years,
.monsoon[data-step="3"] .layer--years,
.monsoon[data-step="2"] .note--dry,
.monsoon[data-step="3"] .note--dry,
.monsoon[data-step="2"] .threshold,
.monsoon[data-step="3"] .threshold {
  opacity: 1;
}

.monsoon .trend-line {
  fill: none;
  stroke: var(--ink);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-dasharray: var(--len);
  stroke-dashoffset: var(--len);
  transition: stroke-dashoffset 1.1s ease 0.15s;
}

.monsoon .trend-band {
  fill: var(--band-trend);
  opacity: 0;
  transition: opacity 0.6s 0.5s;
}

.monsoon[data-step="3"] .trend-line {
  stroke-dashoffset: 0;
}

.monsoon[data-step="3"] .trend-band,
.monsoon[data-step="3"] .note--trend {
  opacity: 1;
}

.monsoon .note--trend {
  transition: opacity 0.4s 0.9s;
}

.monsoon .layer--months,
.monsoon[data-step="2"] .layer--months .hit,
.monsoon[data-step="3"] .layer--months .hit {
  pointer-events: none;
}

.monsoon[data-step="0"] .layer--months .hit,
.monsoon[data-step="1"] .layer--months .hit {
  pointer-events: auto;
}

.monsoon .layer--years .hit {
  pointer-events: none;
}

.monsoon[data-step="2"] .layer--years .hit,
.monsoon[data-step="3"] .layer--years .hit {
  pointer-events: auto;
}

.threshold {
  stroke: var(--laterite);
  stroke-width: 1.5;
  stroke-dasharray: 5 4;
  transition: opacity 0.5s;
}

.halo {
  paint-order: stroke;
  stroke: var(--bg);
  stroke-width: 4px;
  stroke-linejoin: round;
}

.note {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  fill: var(--ink);
}

.note--soft {
  font-weight: 500;
  fill: var(--ink-2);
}

.leader {
  stroke: var(--ink-2);
  stroke-width: 1;
  fill: none;
}

.no-anim,
.no-anim * {
  transition: none !important;
  animation: none !important;
}

/* ---------- Bande sombre : août 2018 ---------- */

.band {
  --bg: #0e1c19;
  --surface: #13241f;
  --ink: #eaf1ec;
  --ink-2: #bccbc4;
  --muted: #8a9c94;
  --line: #27392f;
  --axis: #3c5048;
  --accent: #f08a5d;
  --laterite: #e5794a;
  --rain: #3fb3c9;
  --context: #4a5b54;
  --rain-ramp: #16292c, #173a42, #1a4e5a, #1d6474, #237b8f, #2f93aa, #49acc4, #79c5da, #b8e3f1;
  --toll-ramp: #2b1d18, #4d2a1f, #713626, #97452e, #bd5735, #dd7146, #f0956a, #f8bc9b;
  color-scheme: dark;
  background: var(--bg);
  color: var(--ink);
  padding-block: 7rem 6rem;
  margin-top: 6rem;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .band {
    --bg: #132722;
    --surface: #18302a;
  }
}

:root[data-theme="dark"] .band {
  --bg: #132722;
  --surface: #18302a;
}

.band__inner {
  row-gap: 1.75rem;
}

.standfirst--band {
  font-size: clamp(1.2rem, 1.08rem + 0.45vw, 1.38rem);
}

.scrolly--map {
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 0.8fr);
}

.scrolly__plot--map {
  max-width: 560px;
  margin-inline: auto;
}

.district {
  stroke: var(--bg);
  stroke-width: 1.2;
  stroke-linejoin: round;
  cursor: pointer;
  transition: fill 0.6s ease;
}

.district:focus-visible {
  outline: none;
}

.district-outline {
  fill: none;
  stroke: var(--ink);
  stroke-width: 2;
  stroke-linejoin: round;
  pointer-events: none;
}

.map-label {
  transition: opacity 0.4s;
}

.map-label.is-off {
  opacity: 0;
}

.graphic {
  margin: 0;
  display: grid;
  gap: 0.75rem;
}

.graphic__plot {
  min-width: 0;
}

.graphic__plot > svg,
.scrolly__plot > svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.graphic__title {
  font-weight: 600;
  font-size: 1rem;
  color: var(--ink);
}

.grow {
  transform-box: fill-box;
  transform-origin: 50% 100%;
  transition: transform 0.7s cubic-bezier(0.2, 0.7, 0.2, 1);
  transition-delay: calc(var(--i) * 6ms);
}

.is-reset .grow {
  transform: scaleY(0);
  transition: none;
}

/* ---------- Bandes de réchauffement ---------- */

.stripes {
  margin: 1rem 0 0;
}

.stripe {
  transition: opacity 0.5s ease;
  transition-delay: calc(var(--i) * 9ms);
}

.is-reset .stripe {
  opacity: 0;
  transition: none;
}

/* ---------- Occupation du sol ---------- */

.years {
  display: flex;
  gap: 1.5rem;
  font-family: var(--font-body);
}

.years button {
  font: 700 1.05rem/1 var(--font-body);
  font-variant-numeric: tabular-nums;
  padding: 0.35rem 0 0.45rem;
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  box-shadow: inset 0 -2px 0 transparent;
}

.years button:hover {
  color: var(--ink);
}

.years button[aria-pressed="true"] {
  color: var(--ink);
  box-shadow: inset 0 -2px 0 var(--ink);
}

.waffle {
  display: grid;
  grid-template-columns: auto minmax(12rem, 1fr);
  gap: 1.5rem 3rem;
  align-items: start;
}

.waffle__plot > svg {
  display: block;
  max-width: 100%;
  height: auto;
}

.cell {
  transition: fill 0.55s ease;
  transition-delay: calc(var(--i) * 1.4ms);
}

.waffle__legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.55rem;
  font-size: 0.95rem;
}

.waffle__legend li {
  display: grid;
  grid-template-columns: 0.9rem 1fr auto;
  gap: 0.6rem;
  align-items: baseline;
  color: var(--ink-2);
}

.waffle__legend li.is-key {
  color: var(--ink);
  font-weight: 600;
}

.waffle__swatch {
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 2px;
  transform: translateY(1px);
}

.waffle__value {
  font-variant-numeric: tabular-nums;
}

/* ---------- Détails ---------- */

.more {
  margin-top: 1.5rem;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.more > summary {
  cursor: pointer;
  padding-block: 1rem;
  font-weight: 600;
  color: var(--ink);
}

.more__body {
  display: grid;
  gap: 2.5rem;
  padding-block: 1rem 2rem;
}

/* Infobulle et vues tableau dans la police d'interface */
.tip {
  font-family: var(--font-body);
  border-radius: 3px;
  box-shadow: 0 2px 10px color-mix(in oklab, var(--ink) 14%, transparent);
}

.dataview {
  font-family: var(--font-body);
}

.axis text,
.chart-label {
  font-family: var(--font-body);
  font-size: 12.5px;
}

/* ---------- Petits écrans ---------- */

@media (max-width: 980px) {
  .hero,
  .waffle {
    grid-template-columns: minmax(0, 1fr);
  }

  .clock {
    order: 2;
  }

  .scrolly,
  .scrolly--map {
    grid-template-columns: minmax(0, 1fr);
  }

  .scrolly__graphic {
    top: var(--topbar-h);
    height: 58vh;
    z-index: 1;
    background: var(--bg);
  }

  .scrolly__steps {
    position: relative;
    z-index: 2;
    padding-block: 10vh 20vh;
  }

  .step {
    min-height: 70vh;
    align-items: flex-end;
  }

  .step p {
    background: var(--bg);
    padding: 1rem 0.25rem;
  }

  .step:not(.is-active) p,
  .step:not(.is-active) p strong {
    color: var(--ink-2);
  }
}

@media (max-width: 560px) {
  .chapter {
    padding-block: 5rem 1.5rem;
  }

  .text p,
  .step p,
  .more__body > p {
    font-size: 1.0625rem;
  }

  .band {
    padding-block: 5rem 4rem;
  }
}
