/* Mașinile care nu pleacă — vârsta parcului auto, importul est-vest, golul de transport public. */

:root {
  color-scheme: light;
  --bg: #f2efe9;
  --bg-raised: #fbfaf6;
  --bg-sunken: #e7e2d8;
  --fg: #1b1a17;
  --fg-soft: #4a4740;
  --fg-faint: #524e45;
  --line: rgba(27, 26, 23, 0.16);
  --line-strong: rgba(27, 26, 23, 0.36);
  --shadow: rgba(20, 18, 14, 0.18);

  --road: #2a2822;
  --road-line: rgba(242, 239, 233, 0.22);

  --rust-1: #3f7f5c;   /* <=2 ani   */
  --rust-2: #7f9a4a;   /* 2-5 ani   */
  --rust-3: #c79a3a;   /* 5-10 ani  */
  --rust-4: #b8622f;   /* 10-20 ani */
  --rust-5: #7a3a26;   /* >20 ani   */
  --diesel: #45505c;
  --petrol: #b8622f;
  --electric: #3f7f5c;
  --pm-line: #a13a3a;
  --map-low: #e4dcc8;
  --map-high: #8a3a2c;

  --serif: Iowan Old Style, "Palatino Linotype", Palatino, Georgia, "Noto Serif", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --container: 700px;
  --wide: 1180px;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #14130f;
    --bg-raised: #1c1a15;
    --bg-sunken: #0d0c09;
    --fg: #f1efe8;
    --fg-soft: #c9c4b7;
    --fg-faint: #bdb7aa;
    --line: rgba(241, 239, 232, 0.16);
    --line-strong: rgba(241, 239, 232, 0.34);
    --shadow: rgba(0, 0, 0, 0.55);
    --road: #0c0b08;
    --rust-1: #63c191;
    --rust-2: #a7c469;
    --rust-3: #e0b657;
    --rust-4: #d98146;
    --rust-5: #b25a3c;
    --diesel: #9aa6b4;
    --petrol: #d98146;
    --electric: #63c191;
    --pm-line: #e07a7a;
    --map-low: #2b2820;
    --map-high: #d9724f;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #14130f;
  --bg-raised: #1c1a15;
  --bg-sunken: #0d0c09;
  --fg: #f1efe8;
  --fg-soft: #c9c4b7;
  --fg-faint: #bdb7aa;
  --line: rgba(241, 239, 232, 0.16);
  --line-strong: rgba(241, 239, 232, 0.34);
  --shadow: rgba(0, 0, 0, 0.55);
  --road: #0c0b08;
  --rust-1: #63c191;
  --rust-2: #a7c469;
  --rust-3: #e0b657;
  --rust-4: #d98146;
  --rust-5: #b25a3c;
  --diesel: #9aa6b4;
  --petrol: #d98146;
  --electric: #63c191;
  --pm-line: #e07a7a;
  --map-low: #2b2820;
  --map-high: #d9724f;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
a:not(.btn) { text-decoration-color: var(--line-strong); text-underline-offset: 3px; }
a:not(.btn):hover { text-decoration-color: currentColor; }

img, svg { display: block; max-width: 100%; }

.wrap { max-width: var(--container); margin: 0 auto; padding: 0 20px; }
.wrap-wide { max-width: var(--wide); margin: 0 auto; padding: 0 20px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: 12px; top: -48px; z-index: 50;
  background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 8px;
  transition: top .15s ease;
}
.skip-link:focus { top: 12px; }

/* -- top bar ------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.topbar-brand { font-family: var(--serif); font-size: 0.95rem; font-weight: 600; }
.topbar-controls { display: flex; gap: 8px; align-items: center; }
.icon-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-raised); border: 1px solid var(--line-strong);
  color: var(--fg); border-radius: 999px; padding: 7px 13px;
  font-size: 0.82rem; font-family: var(--sans); cursor: pointer;
}
.icon-btn:hover { border-color: var(--fg); }
.icon-btn:focus-visible, a:focus-visible, button:focus-visible, input:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid var(--pm-line); outline-offset: 2px;
}

/* -- hero ------------------------------------------------------------ */
.hero { padding: 64px 0 40px; }
.kicker {
  font-family: var(--mono); text-transform: uppercase; letter-spacing: 0.08em;
  font-size: 0.78rem; color: var(--fg-faint); margin: 0 0 14px;
}
h1 {
  font-family: var(--serif); font-weight: 600; letter-spacing: -0.01em;
  font-size: clamp(2rem, 5vw, 3rem); line-height: 1.08; margin: 0 0 20px;
}
.deck {
  font-size: 1.2rem; line-height: 1.5; color: var(--fg-soft); max-width: 58ch; margin: 0 0 22px;
}
.byline { font-size: 0.85rem; color: var(--fg-faint); }

/* -- prose ------------------------------------------------------------ */
section { padding: 56px 0; border-top: 1px solid var(--line); }
section:first-of-type { border-top: none; }
h2 {
  font-family: var(--serif); font-weight: 600; font-size: clamp(1.5rem, 3.4vw, 2.05rem);
  line-height: 1.16; margin: 0 0 14px; letter-spacing: -0.005em;
}
h3 { font-family: var(--serif); font-weight: 600; font-size: 1.2rem; margin: 28px 0 10px; }
p { margin: 0 0 16px; }
.lede { font-size: 1.08rem; color: var(--fg-soft); max-width: 62ch; }
.section-note { font-size: 0.92rem; color: var(--fg-faint); max-width: 62ch; }
strong { font-weight: 650; }
.stat {
  font-family: var(--serif); font-weight: 600; font-variant-numeric: oldstyle-nums;
}
figure { margin: 0; }
figcaption { font-size: 0.85rem; color: var(--fg-faint); margin-top: 8px; }

.pull {
  font-family: var(--serif); font-size: 1.5rem; line-height: 1.35;
  color: var(--fg); max-width: 46ch; margin: 34px 0; padding-left: 20px;
  border-left: 3px solid var(--rust-4);
}
.source-line { font-size: 0.78rem; color: var(--fg-faint); margin-top: 6px; }

/* -- level label ------------------------------------------------------ */
.level-tag {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--mono); font-size: 0.78rem; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--fg-faint); margin-bottom: 12px;
}
.level-tag .n {
  width: 22px; height: 22px; border-radius: 50%; display: inline-flex;
  align-items: center; justify-content: center; background: var(--rust-4); color: #fff;
  font-family: var(--sans); font-weight: 700;
}

/* -- convoy (level 1) --------------------------------------------------- */
.convoy-panel {
  background: var(--road); border-radius: var(--radius); padding: 26px 20px 20px;
  box-shadow: 0 10px 30px var(--shadow); overflow: hidden;
}
.convoy-road {
  position: relative; padding: 18px 0 26px; border-bottom: 2px dashed var(--road-line);
}
.convoy-row {
  display: flex; align-items: flex-end; gap: 4px; overflow-x: auto; padding-bottom: 4px;
  scrollbar-width: thin;
}
.convoy-car { flex: 0 0 auto; width: 34px; transition: filter .25s ease, opacity .25s ease; }
.convoy-car svg { width: 100%; height: auto; display: block; }
.convoy-caption {
  display: flex; justify-content: space-between; align-items: baseline;
  color: #f1efe8; margin-top: 14px; gap: 12px; flex-wrap: wrap;
}
.convoy-year { font-family: var(--serif); font-size: 2rem; font-weight: 600; }
.convoy-headline { font-family: var(--sans); font-size: 0.95rem; color: #cfc9ba; max-width: 34ch; }
.convoy-controls {
  display: flex; align-items: center; gap: 14px; margin-top: 18px; color: #f1efe8;
}
.convoy-controls input[type="range"] { flex: 1; accent-color: var(--rust-4); }
.convoy-controls .icon-btn { background: transparent; border-color: rgba(241,239,232,0.4); color: #f1efe8; }
.convoy-legend {
  display: flex; flex-wrap: wrap; gap: 14px; margin-top: 16px; font-size: 0.78rem; color: #cfc9ba;
}
.convoy-legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

.age-table {
  width: 100%; border-collapse: collapse; margin-top: 18px; font-size: 0.92rem;
}
.age-table caption { text-align: left; font-size: 0.85rem; color: var(--fg-faint); margin-bottom: 8px; }
.age-table th, .age-table td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); }
.age-table th { font-weight: 600; color: var(--fg-soft); }
.age-table td.num, .age-table th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* -- stat grid ---------------------------------------------------------- */
.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 18px; margin: 28px 0;
}
.stat-card {
  background: var(--bg-raised); border: 1px solid var(--line); border-radius: 12px; padding: 18px;
}
.stat-card .num { font-family: var(--serif); font-size: 2rem; font-weight: 600; line-height: 1.05; }
.stat-card .label { font-size: 0.85rem; color: var(--fg-soft); margin-top: 6px; }

/* -- map (level 2) ------------------------------------------------------ */
.map-panel {
  background: var(--bg-raised); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; box-shadow: 0 8px 24px var(--shadow);
}
.map-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.year-toggle { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 999px; overflow: hidden; }
.year-toggle button {
  background: var(--bg-raised); color: var(--fg); border: none; padding: 7px 16px;
  font-family: var(--sans); font-size: 0.85rem; cursor: pointer;
}
.year-toggle button[aria-pressed="true"] { background: var(--rust-4); color: #fff; }
.map-figure { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(220px, 1fr); gap: 20px; align-items: start; }
@media (max-width: 720px) { .map-figure { grid-template-columns: 1fr; } }
.map-svg-wrap { position: relative; }
.map-svg { width: 100%; height: auto; }
.county-path { stroke: var(--bg-raised); stroke-width: 0.6; cursor: pointer; }
.county-path:hover, .county-path:focus-visible { stroke: var(--fg); stroke-width: 1.4; outline: none; }
.map-legend { display: flex; align-items: center; gap: 10px; margin-top: 10px; font-size: 0.78rem; color: var(--fg-faint); }
.map-legend-bar { width: 120px; height: 10px; border-radius: 6px; background: linear-gradient(90deg, var(--map-low), var(--map-high)); }

.county-detail {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 16px;
  min-height: 180px;
}
.county-detail h4 { font-family: var(--serif); font-size: 1.15rem; margin: 0 0 10px; }
.county-detail dl { margin: 0; }
.county-detail dt { font-size: 0.78rem; color: var(--fg-faint); margin-top: 10px; }
.county-detail dd { margin: 2px 0 0; font-family: var(--serif); font-size: 1.15rem; }
.county-detail .hint { font-size: 0.85rem; color: var(--fg-faint); }

/* -- pm2.5 bars ---------------------------------------------------------- */
.pm-list { list-style: none; margin: 18px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.pm-row { display: grid; grid-template-columns: 11ch 1fr 5ch; align-items: center; gap: 10px; font-size: 0.86rem; }
.pm-row .city { color: var(--fg-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pm-bar-track { position: relative; height: 12px; background: var(--bg-sunken); border-radius: 6px; overflow: visible; }
.pm-bar-fill { position: absolute; inset: 0 auto 0 0; background: var(--pm-line); border-radius: 6px; }
.pm-bar-who { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--fg); opacity: 0.55; }
.pm-row .val { text-align: right; font-variant-numeric: tabular-nums; color: var(--fg); }
.pm-who-note { font-size: 0.78rem; color: var(--fg-faint); margin-top: 10px; }

/* -- euro/diesel chart ---------------------------------------------------- */
.chart-panel { background: var(--bg-raised); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.stack-chart { width: 100%; height: auto; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 14px; font-size: 0.8rem; color: var(--fg-soft); }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }

/* -- data table fallback --------------------------------------------------- */
details.data-table { margin-top: 16px; }
details.data-table summary {
  cursor: pointer; font-size: 0.85rem; color: var(--fg-soft); padding: 6px 0;
}
details.data-table table { width: 100%; border-collapse: collapse; font-size: 0.85rem; margin-top: 8px; }
details.data-table th, details.data-table td { text-align: right; padding: 5px 8px; border-bottom: 1px solid var(--line); }
details.data-table th:first-child, details.data-table td:first-child { text-align: left; }

/* -- js unavailable ----------------------------------------------------- */
/* Revealed per-feature by app.js (removing the `hidden` attribute) only once
   that feature's data has actually loaded — not on a blanket "JS is present"
   assumption. `!important` beats each element's own flex/inline-flex rule,
   which would otherwise win the specificity fight against a plain class. */
[hidden] { display: none !important; }
.no-js-note {
  background: var(--bg-sunken); border: 1px dashed var(--line-strong); border-radius: 10px;
  padding: 14px 16px; font-size: 0.88rem; color: var(--fg-soft);
}

/* -- footer --------------------------------------------------------------- */
footer {
  border-top: 1px solid var(--line); padding: 40px 0 60px; font-size: 0.85rem; color: var(--fg-faint);
}
footer .wrap { display: flex; flex-direction: column; gap: 8px; }
footer a { color: var(--fg-soft); }

@media (max-width: 560px) {
  .hero { padding: 44px 0 28px; }
  section { padding: 40px 0; }
  .convoy-panel { padding: 20px 14px 16px; }
}
