/* =========================================================================
   Atlante demografico mondiale — theme/default/main.css
   Palette: carta chiara + inchiostro blu notte + ottone (brass) + scala
   termica ambra/cremisi per l'aspettativa di vita e scala teal/oceano per
   la popolazione. Tipografia: Fraunces (display) / Inter (testo) /
   JetBrains Mono (numeri e dati).
   ========================================================================= */

:root {
  /* --- palette --- */
  --ink:        #1B2430;
  --ink-soft:   #3A4657;
  --paper:      #EEEAdd;
  --paper-2:    #E4DEC9;
  --navy:       #12213B;
  --navy-2:     #1B3358;
  --navy-3:     #24406E;
  --brass:      #C9972B;
  --brass-soft: #E6C878;
  --muted:      #6B7280;
  --line:       rgba(27, 36, 48, 0.12);
  --line-strong:rgba(27, 36, 48, 0.24);

  /* --- scala popolazione (oceano, chiaro -> profondo) --- */
  --scale-pop-0: #EAF3EF;
  --scale-pop-1: #9CC7BE;
  --scale-pop-2: #4C8F8B;
  --scale-pop-3: #1F5C63;
  --scale-pop-4: #0B3B45;

  /* --- scala aspettativa di vita (ambra -> cremisi) --- */
  --scale-life-0: #FBF1D9;
  --scale-life-1: #EFC26E;
  --scale-life-2: #CC7A3E;
  --scale-life-3: #A03D33;
  --scale-life-4: #6E1E22;

  /* --- tipografia --- */
  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;

  --radius: 10px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

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

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--ink);
  color: var(--paper);
  padding: 0.6rem 1rem;
  z-index: 2000;
}
.skip-link:focus {
  left: 0.5rem;
  top: 0.5rem;
}

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

h1, h2, h3, h4 {
  font-family: var(--font-display);
  color: var(--ink);
  margin: 0;
}

/* ---------------------------------------------------------------------- */
/* Topbar                                                                  */
/* ---------------------------------------------------------------------- */
.topbar {
  background: var(--navy);
  color: var(--paper);
  padding: 0.55rem 0;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  display: flex;
}
.topbar .container-fluid {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.topbar-eyebrow { color: var(--brass-soft); font-weight: 600; }
.topbar-sources { color: rgba(238, 234, 221, 0.6); font-size: 0.68rem; }

/* ---------------------------------------------------------------------- */
/* Hero                                                                    */
/* ---------------------------------------------------------------------- */
.hero {
  padding: 2.75rem 0 2rem;
  background:
    radial-gradient(ellipse at top right, rgba(201,151,43,0.10), transparent 55%),
    var(--paper);
}
.hero-title {
  font-size: clamp(1.9rem, 3.4vw, 3rem);
  font-weight: 600;
  line-height: 1.08;
  letter-spacing: -0.01em;
}
.hero-lede {
  margin-top: 1rem;
  max-width: 46ch;
  color: var(--ink-soft);
  font-size: 1.02rem;
}

/* --- metric toggle (segmented control) --- */
.metric-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}
.metric-btn {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.9rem 1.1rem;
  border-radius: var(--radius);
  border: 1.5px solid var(--line-strong);
  background: #fff;
  cursor: pointer;
  transition: border-color .15s ease, background-color .15s ease, transform .1s ease;
}
.metric-btn:hover { border-color: var(--brass); }
.metric-btn-label {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.05rem;
}
.metric-btn-hint {
  font-size: 0.78rem;
  color: var(--muted);
  font-family: var(--font-mono);
}
.btn-check:checked + .metric-btn {
  background: var(--navy);
  border-color: var(--navy);
  transform: translateY(-1px);
}
.btn-check:checked + .metric-btn .metric-btn-label { color: var(--brass-soft); }
.btn-check:checked + .metric-btn .metric-btn-hint { color: rgba(238,234,221,0.65); }
.btn-check:focus-visible + .metric-btn { outline: 2.5px solid var(--brass); outline-offset: 2px; }

/* ---------------------------------------------------------------------- */
/* Timeline / scrubber — il pezzo "firma" della pagina                     */
/* ---------------------------------------------------------------------- */
.timeline-strip {
  background: var(--navy);
  padding: 1.35rem 0 1.6rem;
  border-top: 1px solid rgba(230, 200, 120, 0.25);
  border-bottom: 1px solid rgba(230, 200, 120, 0.25);
}
.timeline-grid {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  align-items: center;
  gap: 1.25rem;
}
@media (max-width: 767.98px) {
  .timeline-grid {
    grid-template-columns: auto 1fr;
    grid-template-areas:
      "play readout"
      "slider slider"
      "bounds bounds";
  }
  .play-btn { grid-area: play; }
  .timeline-readout { grid-area: readout; }
  .timeline-slider-wrap { grid-area: slider; }
  .timeline-bounds { grid-area: bounds; }
}

.play-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1.5px solid var(--brass);
  background: transparent;
  color: var(--brass-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color .15s ease, color .15s ease;
  flex-shrink: 0;
}
.play-btn:hover { background: var(--brass); color: var(--navy); }

.timeline-readout {
  display: flex;
  flex-direction: column;
  min-width: 6.5ch;
  line-height: 1.1;
}
.timeline-year {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.9rem;
  color: var(--paper);
  font-variant-numeric: tabular-nums;
}
.timeline-worldval {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--brass-soft);
  white-space: nowrap;
}

.timeline-slider-wrap { position: relative; padding-top: 0.4rem; }

.year-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--brass) 0%, rgba(230,200,120,0.25) 0%);
  outline: none;
  cursor: pointer;
}
.year-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--brass-soft);
  border: 3px solid var(--navy);
  box-shadow: 0 0 0 1.5px var(--brass);
  cursor: grab;
  margin-top: -8px;
}
.year-slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--brass-soft);
  border: 3px solid var(--navy);
  box-shadow: 0 0 0 1.5px var(--brass);
  cursor: grab;
}
.year-slider::-moz-range-track {
  height: 4px;
  background: rgba(230,200,120,0.25);
  border-radius: 2px;
}

.timeline-ticks {
  display: flex;
  justify-content: space-between;
  margin-top: 0.35rem;
  padding: 0 2px;
}
.timeline-ticks span {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: rgba(238,234,221,0.4);
}

.timeline-bounds {
  display: flex;
  gap: 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: rgba(238,234,221,0.45);
  white-space: nowrap;
}

/* ---------------------------------------------------------------------- */
/* Mappa                                                                   */
/* ---------------------------------------------------------------------- */
.map-section { padding: 2.5rem 0; }

.plate {
  background: var(--navy);
  border-radius: 14px;
  padding: 1.5rem 1.5rem 1.75rem;
  box-shadow: 0 18px 40px -18px rgba(18, 33, 59, 0.45);
}
.plate-header {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}
.plate-title {
  color: var(--paper);
  font-size: 1.35rem;
  font-weight: 600;
}
.country-search { width: 240px; max-width: 100%; }
.country-search input {
  background: rgba(238,234,221,0.08);
  border: 1px solid rgba(230,200,120,0.35);
  color: var(--paper);
}
.country-search input::placeholder { color: rgba(238,234,221,0.45); }
.country-search input:focus {
  background: rgba(238,234,221,0.12);
  border-color: var(--brass);
  color: var(--paper);
  box-shadow: none;
}

.map-canvas-wrap {
  position: relative;
  background: radial-gradient(ellipse at center, #16294a 0%, #0F1B30 100%);
  border-radius: 8px;
  overflow: hidden;
}
.map-canvas {
  width: 100%;
  aspect-ratio: 2754 / 1398;
  display: block;
}
.map-canvas svg {
  width: 100%;
  height: 100%;
  display: block;
}
.map-canvas svg path,
.map-canvas svg g {
  stroke: #0F1B30;
  stroke-width: 0.5;
  transition: fill .35s ease, opacity .2s ease;
}
.map-canvas svg .country-hit {
  cursor: pointer;
}
.map-canvas svg .country-hit:hover {
  opacity: 0.85;
  stroke: var(--brass-soft);
  stroke-width: 1.2;
}

.map-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--paper);
  color: var(--ink);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  font-size: 0.82rem;
  box-shadow: 0 10px 24px -8px rgba(0,0,0,0.35);
  opacity: 0;
  transform: translate(-50%, calc(-100% - 12px));
  transition: opacity .1s ease;
  white-space: nowrap;
  z-index: 20;
  border: 1px solid var(--line);
}
.map-tooltip.visible { opacity: 1; }
.map-tooltip strong { font-family: var(--font-display); }
.map-tooltip .tt-value {
  display: block;
  font-family: var(--font-mono);
  color: var(--navy-3);
  font-weight: 600;
  margin-top: 0.1rem;
}
.map-tooltip .tt-flag {
  display: block;
  font-size: 0.7rem;
  color: var(--brass);
  margin-top: 0.15rem;
  font-family: var(--font-mono);
}

.legend {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1.1rem;
}
.legend-bar {
  flex: 1;
  height: 10px;
  border-radius: 6px;
}
.legend-label {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: rgba(238,234,221,0.75);
  white-space: nowrap;
}
.plate-hint {
  margin: 0.85rem 0 0;
  color: rgba(238,234,221,0.5);
  font-size: 0.82rem;
}

.side-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.4rem;
  height: 100%;
}
.side-title {
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-family: var(--font-body);
  font-weight: 600;
  margin-bottom: 1rem;
}
.stat-list { margin: 0; }
.stat-row {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.6rem 0;
  border-bottom: 1px dashed var(--line);
}
.stat-row:last-child { border-bottom: none; }
.stat-row dt { color: var(--ink-soft); font-size: 0.88rem; }
.stat-row dd {
  margin: 0;
  font-family: var(--font-mono);
  font-weight: 600;
  text-align: right;
}

/* ---------------------------------------------------------------------- */
/* Classifiche & trend                                                     */
/* ---------------------------------------------------------------------- */
.ranking-section, .trend-section { padding: 0.5rem 0 2.5rem; }

.chart-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.4rem 1.5rem 1.6rem;
  height: 100%;
}
.chart-title {
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 1rem;
}
.chart-title span { color: var(--brass); font-family: var(--font-mono); font-size: 0.85rem; margin-left: 0.4rem; }
.trend-note {
  font-size: 0.78rem;
  color: var(--muted);
  font-family: var(--font-mono);
}
.chart-canvas-wrap { position: relative; height: 280px; }
.chart-canvas-wrap--tall { height: 360px; }

/* ---------------------------------------------------------------------- */
/* Footer                                                                  */
/* ---------------------------------------------------------------------- */
.site-footer {
  padding: 1.5rem 0 2.5rem;
  color: var(--muted);
  font-size: 0.82rem;
}

/* ---------------------------------------------------------------------- */
/* Offcanvas dettaglio paese                                               */
/* ---------------------------------------------------------------------- */
#country-offcanvas { width: min(560px, 100vw); background: var(--paper); }
#country-offcanvas .offcanvas-header {
  border-bottom: 1px solid var(--line);
  background: var(--navy);
}
#country-offcanvas .offcanvas-title {
  color: var(--paper);
  font-size: 1.4rem;
}
#country-offcanvas .btn-close { filter: invert(1) grayscale(1) brightness(2); }

.country-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.country-stat {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
}
.country-stat-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}
.country-stat-value {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--navy);
}

/* ---------------------------------------------------------------------- */
/* Accessibilita' / riduzione movimento                                    */
/* ---------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
  html { scroll-behavior: auto; }
}

@media (max-width: 575.98px) {
  .hero { padding: 1.75rem 0 1.25rem; }
  .plate { padding: 1.1rem; }
}
