/* România construiește. Dar pentru cine? — semantic tokens, dual theme. */

:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --bg-raised: #fcfaf4;
  --bg-sunken: #e8e2d3;
  --fg: #1a1916;
  --fg-soft: #45403a;
  --fg-faint: #524c43;
  --line: rgba(26, 25, 22, 0.16);
  --line-strong: rgba(26, 25, 22, 0.4);
  --shadow: rgba(26, 25, 22, 0.12);
  --accent: #8a4a2c;
  --accent-soft: #efe0d3;
  --accent-ink: #5f321c;
  --on-accent: #ffffff;
  --link: #7a3f22;
  --focus: #8a4a2c;
  /* quadrants */
  --q-paradox: #b23a2c;    /* housing up, population down */
  --q-paradox-soft: #f0c6bd;
  --q-expansiune: #1f6b4e; /* both up */
  --q-expansiune-soft: #bfe0cf;
  --q-contractie: #4a5568; /* both down */
  --q-contractie-soft: #cfd6e0;
  --q-presiune: #c8781e;   /* population up, housing down */
  --q-presiune-soft: #f0d3a8;
  --nodata: #e9e4d8;
  --map-line: rgba(26, 25, 22, 0.10);
  --county-line: rgba(26, 25, 22, 0.55);
  --h-line: #8a4a2c;   /* housing series */
  --p-line: #23587f;   /* population series */
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --container: 70ch;
  --wide: 1180px;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #16130f; --bg-raised: #201b16; --bg-sunken: #0f0c09;
    --fg: #f0e9de; --fg-soft: #d2c6b6; --fg-faint: #baac98;
    --line: rgba(240, 233, 222, 0.16); --line-strong: rgba(240, 233, 222, 0.42); --shadow: rgba(0, 0, 0, 0.55);
    --accent: #e0a878; --accent-soft: #3a291b; --accent-ink: #f0c9a4; --on-accent: #241407; --link: #e0a878; --focus: #e0a878;
    --q-paradox: #e0685a; --q-paradox-soft: #4a231d; --q-expansiune: #5cbf95; --q-expansiune-soft: #1c3a2c;
    --q-contractie: #8a97ab; --q-contractie-soft: #2a2f3a; --q-presiune: #f0a54a; --q-presiune-soft: #4e3a1c;
    --h-line: #e0a878; --p-line: #7fb3dc;
    --nodata: #241f19; --map-line: rgba(240, 233, 222, 0.10); --county-line: rgba(240, 233, 222, 0.6);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #16130f; --bg-raised: #201b16; --bg-sunken: #0f0c09;
  --fg: #f0e9de; --fg-soft: #d2c6b6; --fg-faint: #baac98;
  --line: rgba(240, 233, 222, 0.16); --line-strong: rgba(240, 233, 222, 0.42); --shadow: rgba(0, 0, 0, 0.55);
  --accent: #e0a878; --accent-soft: #3a291b; --accent-ink: #f0c9a4; --on-accent: #241407; --link: #e0a878; --focus: #e0a878;
  --q-paradox: #e0685a; --q-paradox-soft: #4a231d; --q-expansiune: #5cbf95; --q-expansiune-soft: #1c3a2c;
  --q-contractie: #8a97ab; --q-contractie-soft: #2a2f3a; --q-presiune: #f0a54a; --q-presiune-soft: #4e3a1c;
  --h-line: #e0a878; --p-line: #7fb3dc;
  --nodata: #241f19; --map-line: rgba(240, 233, 222, 0.10); --county-line: rgba(240, 233, 222, 0.6);
}

*, *::before, *::after { 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(--serif); font-size: 1.0625rem; line-height: 1.6; text-rendering: optimizeLegibility; }
a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: 0.15em; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; border-radius: 3px; }
img, svg { max-width: 100%; }
button { font: inherit; color: inherit; }
strong { font-weight: 650; }
.visually-hidden, .sr-live { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
[hidden] { display: none !important; }
.wrap { width: min(100% - 2.5rem, var(--container)); margin-inline: auto; }
.wide { width: min(100% - 2.5rem, var(--wide)); margin-inline: auto; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.85rem 1.25rem; border-bottom: 1px solid var(--line); font-family: var(--sans); font-size: 0.9rem; }
.brand { color: var(--fg); text-decoration: none; font-weight: 600; }
.topbar-tools { display: flex; align-items: center; gap: 0.75rem; }
.lang-switch { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 999px; overflow: hidden; }
.lang-switch a { padding: 0.25rem 0.7rem; text-decoration: none; color: var(--fg-soft); }
.lang-switch a[aria-current] { background: var(--fg); color: var(--bg); }
.theme-toggle { border: 1px solid var(--line-strong); background: var(--bg-raised); border-radius: 999px; padding: 0.3rem 0.8rem; cursor: pointer; font-size: 0.85rem; }

.hero { padding: clamp(2rem, 6vw, 4.5rem) 0 1.5rem; }
.kicker { font-family: var(--sans); font-size: 0.78rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--fg-faint); margin: 0 0 0.6rem; }
h1 { font-size: clamp(2.1rem, 6vw, 3.6rem); line-height: 1.05; margin: 0 0 1rem; letter-spacing: -0.01em; font-weight: 600; }
.deck { font-size: clamp(1.15rem, 2.2vw, 1.4rem); line-height: 1.45; color: var(--fg-soft); margin: 0 0 1.25rem; }
.deck strong { color: var(--fg); }
h2 { font-size: clamp(1.5rem, 3.2vw, 2.1rem); line-height: 1.15; margin: 0 0 0.75rem; font-weight: 600; }
h3 { font-size: 1.15rem; margin: 0 0 0.5rem; font-weight: 650; }
section { padding: clamp(2rem, 5vw, 3.5rem) 0; }
section + section { border-top: 1px solid var(--line); }
.lede { font-size: 1.15rem; color: var(--fg-soft); }
.small { font-size: 0.9rem; color: var(--fg-faint); }
p { margin: 0 0 1rem; }
.maxw { max-width: 70ch; }

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; margin: 1.5rem 0 0; font-family: var(--sans); }
.stat { background: var(--bg-raised); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; }
.stat b { display: block; font-size: clamp(1.15rem, 2.2vw, 1.9rem); line-height: 1.1; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; overflow-wrap: break-word; }
.stat span { display: block; font-size: 0.86rem; color: var(--fg-soft); margin-top: 0.35rem; line-height: 1.4; }

/* explorer */
.explorer { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(300px, 1fr); gap: 1.5rem; align-items: start; }
@media (max-width: 900px) { .explorer { grid-template-columns: 1fr; } }
.map-panel { position: relative; }
.map-tools { display: flex; flex-wrap: wrap; gap: 0.6rem 1rem; align-items: center; margin-bottom: 0.75rem; font-family: var(--sans); font-size: 0.9rem; }
.search { position: relative; flex: 1 1 240px; }
.search input { width: 100%; padding: 0.65rem 0.9rem; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--bg-raised); color: var(--fg); font: inherit; font-size: 1rem; }
.search input::placeholder { color: var(--fg-faint); }
.search-list { position: absolute; z-index: 5; inset-inline: 0; top: calc(100% + 4px); margin: 0; padding: 0.25rem; list-style: none; background: var(--bg-raised); border: 1px solid var(--line-strong); border-radius: 10px; box-shadow: 0 10px 30px var(--shadow); max-height: 320px; overflow: auto; }
.search-list li { padding: 0.5rem 0.7rem; border-radius: 7px; cursor: pointer; display: flex; justify-content: space-between; gap: 0.75rem; }
.search-list li[aria-selected="true"], .search-list li:hover { background: var(--accent-soft); }
.search-list .meta { color: var(--fg-faint); font-size: 0.85rem; white-space: nowrap; }
.modes { display: flex; flex-wrap: wrap; gap: 0.35rem; font-family: var(--sans); font-size: 0.86rem; margin-bottom: 0.6rem; }
.modes button { border: 1px solid var(--line-strong); background: var(--bg-raised); border-radius: 999px; padding: 0.32rem 0.75rem; cursor: pointer; color: var(--fg-soft); display: inline-flex; align-items: center; gap: 0.4rem; }
.modes button i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; background: var(--nodata); }
.modes button[data-mode="q"] i { background: var(--q-paradox); }
.modes button[data-mode="dv"] i { background: var(--q-presiune); }
.modes button[aria-pressed="true"] { background: var(--fg); color: var(--bg); border-color: var(--fg); }

.map-frame { position: relative; background: var(--bg-raised); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; touch-action: none; }
.map-frame svg { display: block; width: 100%; height: auto; }
.map-frame .status { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--sans); color: var(--fg-soft); background: var(--bg-raised); text-align: center; padding: 1rem; }
.u { fill: var(--nodata); stroke: var(--map-line); stroke-width: 0.25; transition: fill 0.35s ease; cursor: pointer; }
@media (prefers-reduced-motion: reduce) { .u { transition: none; } }
.u.q-paradox { fill: var(--q-paradox); } .u.q-expansiune { fill: var(--q-expansiune); } .u.q-contractie { fill: var(--q-contractie); } .u.q-presiune { fill: var(--q-presiune); }
.u.dv0 { fill: var(--q-contractie-soft); } .u.dv1 { fill: var(--q-presiune-soft); } .u.dv2 { fill: var(--q-presiune); } .u.dv3 { fill: var(--q-paradox); } .u.dv4 { fill: var(--q-paradox-soft); filter: brightness(0.72); }
.u:hover, .u.hover { stroke: var(--fg); stroke-width: 1.2; }
.u.sel { stroke: var(--fg); stroke-width: 1.8; }
.counties path { fill: none; stroke: var(--county-line); stroke-width: 0.7; pointer-events: none; }
.map-zoom { position: absolute; right: 0.6rem; top: 0.6rem; display: flex; flex-direction: column; gap: 0.3rem; }
.map-zoom button { width: 2.2rem; height: 2.2rem; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--bg-raised); cursor: pointer; font-family: var(--sans); font-size: 1.1rem; }
.map-tip { position: absolute; pointer-events: none; z-index: 4; background: var(--fg); color: var(--bg); font-family: var(--sans); font-size: 0.85rem; padding: 0.35rem 0.6rem; border-radius: 7px; white-space: nowrap; transform: translate(-50%, calc(-100% - 10px)); }
.map-count { position: absolute; right: 0.9rem; bottom: 0.7rem; font-family: var(--sans); font-size: 0.85rem; color: var(--fg-soft); text-align: right; pointer-events: none; max-width: 60%; background: var(--bg-raised); padding: 0.15rem 0.4rem; border-radius: 6px; }
@media (max-width: 640px) { .map-count { position: static; display: block; max-width: none; text-align: left; padding: 0.4rem 0 0; background: none; } }
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem 0.8rem; margin-top: 0.7rem; font-family: var(--sans); font-size: 0.82rem; color: var(--fg-soft); }
.legend .sw { display: inline-block; width: 22px; height: 12px; border-radius: 3px; border: 1px solid var(--line); vertical-align: middle; margin-right: 0.3rem; }
.sw.q-paradox { background: var(--q-paradox); } .sw.q-expansiune { background: var(--q-expansiune); } .sw.q-contractie { background: var(--q-contractie); } .sw.q-presiune { background: var(--q-presiune); }
.sw.dv0 { background: var(--q-contractie-soft); } .sw.dv1 { background: var(--q-presiune-soft); } .sw.dv2 { background: var(--q-presiune); } .sw.dv3 { background: var(--q-paradox); } .sw.dv4 { background: var(--q-paradox-soft); filter: brightness(0.72); }
.sw.nodata { background: var(--nodata); }

/* card */
.card { background: var(--bg-raised); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.15rem 1.25rem; position: sticky; top: 0.75rem; }
@media (max-width: 900px) { .card { position: static; } }
.card .kicker { margin-bottom: 0.25rem; }
.card h3 { font-size: 1.5rem; line-height: 1.15; margin: 0; }
.card .where { font-family: var(--sans); font-size: 0.9rem; color: var(--fg-faint); margin: 0.15rem 0 0.9rem; }
.card .claim { font-size: 1.08rem; line-height: 1.45; margin: 0 0 0.9rem; }
.qtag { display: inline-flex; align-items: center; gap: 0.4rem; font-family: var(--sans); font-size: 0.82rem; font-weight: 700; padding: 0.2rem 0.6rem; border-radius: 999px; margin-bottom: 0.7rem; }
.qtag.q-paradox { background: var(--q-paradox-soft); color: var(--q-paradox); }
.qtag.q-expansiune { background: var(--q-expansiune-soft); color: var(--q-expansiune); }
.qtag.q-contractie { background: var(--q-contractie-soft); color: var(--q-contractie); }
.qtag.q-presiune { background: var(--q-presiune-soft); color: var(--q-presiune); }
.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; font-family: var(--sans); margin: 0 0 0.9rem; }
.metrics div { background: var(--bg-sunken); border-radius: 10px; padding: 0.55rem 0.7rem; }
.metrics b { display: block; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.metrics span { font-size: 0.78rem; color: var(--fg-faint); }
.spark { width: 100%; height: auto; display: block; margin-top: 0.3rem; }
.spark .ln { fill: none; stroke-width: 2; } .spark .ln.h { stroke: var(--h-line); } .spark .ln.p { stroke: var(--p-line); }
.spark text { font-family: var(--sans); font-size: 10px; fill: var(--fg-faint); }
.spark .grid { stroke: var(--line); }
.spark-legend { display: flex; gap: 1rem; font-family: var(--sans); font-size: 0.8rem; color: var(--fg-soft); margin-top: 0.3rem; }
.spark-legend b { display: inline-block; width: 14px; height: 2px; margin-right: 0.35rem; vertical-align: middle; }
.spark-legend b.h { background: var(--h-line); } .spark-legend b.p { background: var(--p-line); }
.card .actions { display: flex; gap: 0.6rem; flex-wrap: wrap; font-family: var(--sans); font-size: 0.85rem; margin-top: 0.5rem; }
.btn { border: 1px solid var(--line-strong); background: var(--bg-raised); border-radius: 999px; padding: 0.35rem 0.85rem; cursor: pointer; font-family: var(--sans); font-size: 0.88rem; color: var(--fg); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.card .empty { color: var(--fg-soft); }
.caveat { font-family: var(--sans); font-size: 0.8rem; color: var(--fg-faint); border-left: 3px solid var(--line-strong); padding-left: 0.6rem; margin: 0.5rem 0 0; line-height: 1.45; }
.linkbtn { border: 0; background: none; padding: 0; color: var(--link); text-decoration: underline; cursor: pointer; font: inherit; }

/* charts */
figure.chart { margin: 1.5rem 0; }
figure.chart figcaption { font-family: var(--sans); font-size: 0.85rem; color: var(--fg-faint); margin-top: 0.5rem; }
.chart-svg { width: 100%; height: auto; display: block; }
.chart-svg text { font-family: var(--sans); font-size: 12px; fill: var(--fg-faint); }
.chart-svg .lbl { fill: var(--fg-soft); font-size: 12.5px; font-weight: 600; }
.chart-svg .grid { stroke: var(--line); stroke-width: 1; }
.chart-svg .grid.ref { stroke: var(--line-strong); stroke-dasharray: 3 3; }
.chart-svg .axis-t { fill: var(--fg-faint); font-size: 11.5px; }
.chart-svg .dot { stroke: var(--bg); stroke-width: 0.6; }
.chart-svg .dot.q-paradox { fill: var(--q-paradox); } .chart-svg .dot.q-expansiune { fill: var(--q-expansiune); } .chart-svg .dot.q-contractie { fill: var(--q-contractie); } .chart-svg .dot.q-presiune { fill: var(--q-presiune); }
.chart-svg .quad-lbl { font-size: 12.5px; font-weight: 700; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
@media (max-width: 760px) { .two-col { grid-template-columns: 1fr; } }
.rank { list-style: none; margin: 0; padding: 0; font-family: var(--sans); font-size: 0.92rem; }
.rank li { display: grid; grid-template-columns: 1.6rem 1fr auto; gap: 0.5rem; align-items: baseline; padding: 0.5rem 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.rank li:hover { background: var(--accent-soft); }
.rank li .n { color: var(--fg-faint); font-variant-numeric: tabular-nums; }
.rank li .where { display: block; color: var(--fg-faint); font-size: 0.8rem; }
.rank li b { font-variant-numeric: tabular-nums; font-size: 1.02rem; white-space: nowrap; }
.rank li small { color: var(--fg-faint); font-size: 0.78rem; display: block; text-align: right; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-family: var(--sans); font-size: 0.9rem; }
th, td { padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--fg-faint); font-weight: 600; font-size: 0.8rem; letter-spacing: 0.03em; text-transform: uppercase; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.callout { background: var(--bg-raised); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: var(--radius); padding: 1rem 1.2rem; margin: 1.25rem 0; }
.callout p:last-child { margin-bottom: 0; }
.method p, .method li { font-size: 0.98rem; }
.method ul { padding-left: 1.2rem; }
footer { border-top: 1px solid var(--line); padding: 2rem 0 3rem; font-family: var(--sans); font-size: 0.88rem; color: var(--fg-soft); }
footer p { margin: 0 0 0.5rem; }
.back-top { position: fixed; right: 1rem; bottom: 1rem; z-index: 10; }
@media (min-width: 901px) { .back-top { display: none; } }
