:root {
  --paper: #f3eee4;
  --ink: #1c1814;
  --muted: #6a6258;
  --rule: #d4cbbd;
  --warm: #c24a2e;
  --cool: #2f5f86;
  --card: #faf6ee;
  --shadow: 0 18px 40px rgba(28, 24, 20, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(194, 74, 46, 0.08), transparent 50%),
    radial-gradient(900px 400px at 100% 0%, rgba(47, 95, 134, 0.08), transparent 45%),
    var(--paper);
  color: var(--ink);
  font-family: "IBM Plex Sans", sans-serif;
}

.page {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 72px;
  transition: width 160ms ease;
}

body.is-compare .page {
  width: min(1400px, calc(100% - 32px));
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--rule);
}

.brand {
  font-family: Fraunces, serif;
  font-size: 1.7rem;
  font-weight: 640;
  letter-spacing: -0.03em;
  color: inherit;
  text-decoration: none;
}

.search {
  display: flex;
  gap: 8px;
  width: min(460px, 100%);
}

.search.search-compare {
  width: min(720px, 100%);
  flex-wrap: wrap;
  justify-content: flex-end;
}

.search-field {
  position: relative;
  flex: 1;
}

.clear-city2 {
  position: absolute;
  top: 50%;
  right: 10px;
  z-index: 2;
  width: 28px;
  height: 28px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  transform: translateY(-50%);
}

.clear-city2:hover {
  color: var(--ink);
  background: #efe8db;
}

#city2 {
  padding-right: 40px;
}

.search input {
  width: 100%;
  height: 44px;
  padding: 0 16px;
  border: 1px solid #cfc6b6;
  background: #fffdf8;
  color: var(--ink);
  font: inherit;
  border-radius: 999px;
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

/* Native search clear (blue × on macOS/Safari) — conflicts with our compare clear */
.search input[type="search"]::-webkit-search-decoration,
.search input[type="search"]::-webkit-search-cancel-button,
.search input[type="search"]::-webkit-search-results-button,
.search input[type="search"]::-webkit-search-results-decoration {
  -webkit-appearance: none;
  appearance: none;
  display: none;
}

.search input:focus {
  border-color: #a89a86;
  box-shadow: 0 0 0 3px rgba(28, 24, 20, 0.06);
}

.city-list {
  position: absolute;
  z-index: 20;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 8px;
  list-style: none;
  background: rgba(255, 253, 248, 0.96);
  border: 1px solid var(--rule);
  border-radius: 18px;
  box-shadow:
    0 4px 10px rgba(28, 24, 20, 0.04),
    0 22px 48px rgba(28, 24, 20, 0.12);
  backdrop-filter: blur(10px);
  overflow: hidden;
  animation: suggest-in 140ms ease-out;
}

@keyframes suggest-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.city-list li + li {
  margin-top: 2px;
}

.city-list button {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  column-gap: 12px;
  row-gap: 2px;
  align-items: center;
  width: 100%;
  height: auto;
  padding: 11px 12px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition: background 120ms ease;
}

.city-list button[aria-selected="true"],
.city-list button:hover {
  background: #efe8db;
}

.city-list .city-name {
  grid-column: 1;
  grid-row: 1;
  font-family: Fraunces, serif;
  font-size: 1.05rem;
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.city-list .city-meta {
  grid-column: 1;
  grid-row: 2;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 400;
  line-height: 1.2;
}

.city-list .city-cc {
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: center;
  min-width: 2.1rem;
  padding: 4px 7px;
  border: 1px solid #ddd4c6;
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-align: center;
  background: #f7f1e6;
}

.city-list button[aria-selected="true"] .city-cc,
.city-list button:hover .city-cc {
  border-color: #cfc4b2;
  background: #fffdf8;
  color: var(--ink);
}

.search > button,
.segment button {
  height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}

.btn-export {
  height: 44px;
  padding: 0 18px;
  border: 1px solid var(--ink);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

.btn-export:hover {
  background: #efe8db;
}

.status {
  margin: 28px 0 0;
  color: var(--muted);
}

.status.error {
  color: var(--warm);
}

.hero {
  padding: 48px 0 28px;
}

.kicker {
  margin: 0 0 8px;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.78rem;
}

.hero h1 {
  margin: 0;
  font-family: Fraunces, serif;
  font-size: clamp(3rem, 8vw, 6.4rem);
  font-weight: 500;
  line-height: 0.9;
  letter-spacing: -0.05em;
}

.lede {
  max-width: 38rem;
  margin: 18px 0 0;
  font-family: Fraunces, serif;
  font-size: 1.35rem;
  font-style: italic;
  font-weight: 500;
  line-height: 1.35;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

.stats article {
  padding: 20px 22px;
  background: var(--card);
  border: 1px solid var(--rule);
  box-shadow: var(--shadow);
}

.stat-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.stat-value {
  margin: 10px 0 0;
  font-family: Fraunces, serif;
  font-size: clamp(1.8rem, 3vw, 2.6rem);
  line-height: 1;
}

.stat-value.warm {
  color: var(--warm);
}

.stat-value.cool {
  color: var(--cool);
}

.panel {
  margin-bottom: 22px;
  padding: 22px;
  background: #fffdf8;
  border: 1px solid var(--rule);
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 16px;
}

.panel h2 {
  margin: 0;
  font-family: Fraunces, serif;
  font-size: 1.5rem;
  font-weight: 500;
}

.hint {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.segment {
  display: flex;
  padding: 4px;
  background: #efe8db;
  border-radius: 999px;
}

.segment button {
  height: 36px;
  background: transparent;
  color: var(--ink);
}

.segment button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
}

.chart-wrap {
  position: relative;
}

.chart-wrap > canvas {
  display: block;
  width: 100%;
  height: 320px;
}

.tooltip {
  position: absolute;
  left: 50%;
  top: auto;
  right: auto;
  bottom: 0;
  z-index: 5;
  padding: 6px 10px;
  background: var(--ink);
  color: var(--paper);
  font-size: 0.82rem;
  pointer-events: none;
  white-space: nowrap;
  transform: translateX(-50%);
}

.brush-block {
  margin-top: 10px;
}

.brush-canvas {
  display: block;
  width: 100%;
  height: 56px;
  cursor: ew-resize;
  touch-action: none;
  background: #f7f1e6;
  border: 1px solid var(--rule);
}

.brush-hint {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.stats.hazard-stats {
  margin: 0 0 18px;
}

.stats.hazard-stats .stat-value {
  font-size: clamp(1.4rem, 2.4vw, 2rem);
}

.stat-delta {
  display: inline;
  margin-left: 0.15em;
  color: var(--muted);
  font-family: "IBM Plex Sans", sans-serif;
  font-size: 0.45em;
  font-weight: 400;
  font-style: normal;
  letter-spacing: 0;
  vertical-align: middle;
}

#chart,
#precip-chart,
#hazard-chart,
#cmp-chart,
#cmp-precip-chart,
#cmp-hazard-chart,
.col-temp-chart,
.col-precip-chart,
.col-hazard-chart {
  display: block;
  width: 100%;
  height: auto;
}

.compare-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: flex-end;
  margin: 28px 0 8px;
}

.compare-desktop {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}

.city-col-inner .hero-col {
  padding-top: 36px;
}

.city-col-inner .hero-col h1 {
  font-size: clamp(2.2rem, 4vw, 3.6rem);
}

.city-col-inner .stats {
  grid-template-columns: repeat(3, 1fr);
}

.city-color {
  color: var(--city-color, var(--muted));
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.chart-legend .swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 6px;
  border-radius: 2px;
  vertical-align: -1px;
}

.stats-compare {
  grid-template-columns: repeat(3, 1fr);
}

.compare-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
}

.heatmap {
  display: grid;
  grid-template-columns: 44px repeat(12, minmax(0, 1fr));
  gap: 2px;
  width: 100%;
}

.heatmap .lab,
.heatmap .mh {
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.2;
}

.heatmap .mh {
  text-align: center;
  margin-bottom: 4px;
}

.heatmap button {
  width: 100%;
  height: 12px;
  border: 0;
  padding: 0;
  cursor: pointer;
}

.legend {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.8rem;
}

.legend-bar {
  flex: 1;
  height: 8px;
  background: linear-gradient(90deg, #2f5f86, #f3eee4, #c24a2e);
}

.year-pick {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

.year-pick select {
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--rule);
  background: #fff;
  font: inherit;
}

.month-bars {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 8px;
  align-items: start;
  min-height: 180px;
}

.month-bars figure {
  margin: 0;
  text-align: center;
  display: flex;
  flex-direction: column;
  width: 100%;
}

.month-bars .bar {
  position: relative;
  height: 140px;
  background: #efe8db;
  flex-shrink: 0;
  overflow: hidden;
}

.month-bars .fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
}

.month-bars figcaption {
  margin-top: 8px;
  min-height: 3.4em;
  font-size: 0.75rem;
  color: var(--muted);
}

.month-bars strong {
  display: block;
  margin-top: 2px;
  color: var(--ink);
  font-size: 0.8rem;
}

.month-bars figcaption span {
  display: block;
  margin-top: 2px;
  font-size: 0.68rem;
  color: var(--cool);
}

.colophon {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.85rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

@media (max-width: 899px) {
  .compare-desktop,
  .compare-toolbar {
    display: none;
  }

  .stats-compare {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .top,
  .panel-head,
  .stats {
    display: block;
  }

  .search,
  .search.search-compare,
  .search-field,
  .segment,
  .year-pick,
  .compare-controls {
    margin-top: 14px;
    width: 100%;
  }

  .search.search-compare {
    flex-direction: column;
    align-items: stretch;
  }

  .stats article + article {
    margin-top: 12px;
  }

  .month-bars {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media print {
  html,
  body {
    background: #fff;
    color: #000;
  }

  .page,
  body.is-compare .page {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 0;
  }

  .top {
    border-bottom: 1px solid #ccc;
    padding-bottom: 12px;
    margin-bottom: 12px;
  }

  .search,
  .status,
  .btn-export,
  .clear-city2,
  .city-list,
  .compare-toolbar,
  .brush-block {
    display: none !important;
  }

  #app {
    display: block !important;
  }

  /* En comparaison desktop : empiler les villes (évite la coupure paysage 2 colonnes) */
  .compare-desktop:not([hidden]) {
    display: block !important;
  }

  .compare-desktop .city-col + .city-col {
    break-before: page;
    page-break-before: always;
    margin-top: 0;
  }

  .hero,
  .stats article,
  .panel:not(:has(.heatmap)):not(:has(.col-heatmap)) {
    break-inside: avoid;
    page-break-inside: avoid;
    box-shadow: none;
  }

  .panel {
    border-color: #ccc;
    box-shadow: none;
  }

  /* Calendriers d’anomalies : autoriser la coupure entre années */
  .panel:has(.heatmap),
  .panel:has(.col-heatmap) {
    break-inside: auto;
    page-break-inside: auto;
  }

  .heatmap {
    break-inside: auto;
  }

  .heatmap button {
    height: 8px;
  }

  canvas {
    max-width: 100% !important;
    height: auto !important;
  }

  a {
    color: inherit;
    text-decoration: none;
  }
}
