/* Ce vârstă are localitatea ta? — semantic tokens, dual theme. */

:root {
  color-scheme: light;
  --bg: #f5f2ea;
  --bg-raised: #fdfbf6;
  --bg-sunken: #e9e3d4;
  --fg: #1b1915;
  --fg-soft: #453f37;
  --fg-faint: #524b41;
  --line: rgba(27, 25, 21, 0.16);
  --line-strong: rgba(27, 25, 21, 0.4);
  --shadow: rgba(27, 25, 21, 0.12);
  --accent: #1f5f8b;
  --accent-soft: #dbe8f2;
  --accent-ink: #163f5c;
  --on-accent: #ffffff;
  --link: #1a4f77;
  --focus: #1f5f8b;
  /* diverging map scale: young (teal) <- neutral gray -> old (sienna); 7 steps */
  --y3: #0f6b63;
  --y2: #3f948a;
  --y1: #8fc2ba;
  --mid: #d9d4c7;
  --o1: #e0b08c;
  --o2: #c6784a;
  --o3: #8d3f1a;
  --nodata: #ece7dc;
  --map-line: rgba(27, 25, 21, 0.10);
  --county-line: rgba(27, 25, 21, 0.55);
  --male: #2f6b9a;
  --female: #a8532e;
  /* fingerprint bands */
  --b0: #7fb8ae;
  --b1: #4a8f86;
  --b2: #2c6b64;
  --b3: #b98a63;
  --b4: #c0693b;
  --b5: #7d3616;
  --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: #14161a;
    --bg-raised: #1c1f25;
    --bg-sunken: #0d0f12;
    --fg: #eeeae1;
    --fg-soft: #cbc5b9;
    --fg-faint: #b7afa0;
    --line: rgba(238, 234, 225, 0.16);
    --line-strong: rgba(238, 234, 225, 0.42);
    --shadow: rgba(0, 0, 0, 0.55);
    --accent: #7fb3dc;
    --accent-soft: #1d2f3f;
    --accent-ink: #a9cfeb;
    --on-accent: #0b1a26;
    --link: #98c2e4;
    --focus: #98c2e4;
    --y3: #63c9bd;
    --y2: #3d9a8f;
    --y1: #256c64;
    --mid: #3a3d43;
    --o1: #7a4b2c;
    --o2: #b8693d;
    --o3: #e7a179;
    --nodata: #22252b;
    --map-line: rgba(238, 234, 225, 0.10);
    --county-line: rgba(238, 234, 225, 0.6);
    --male: #7fb3dc;
    --female: #e29a72;
    --b0: #3f9a8e;
    --b1: #5fb7ab;
    --b2: #8fd0c6;
    --b3: #c9a27a;
    --b4: #d98a5c;
    --b5: #f0b48e;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #14161a;
  --bg-raised: #1c1f25;
  --bg-sunken: #0d0f12;
  --fg: #eeeae1;
  --fg-soft: #cbc5b9;
  --fg-faint: #b7afa0;
  --line: rgba(238, 234, 225, 0.16);
  --line-strong: rgba(238, 234, 225, 0.42);
  --shadow: rgba(0, 0, 0, 0.55);
  --accent: #7fb3dc;
  --accent-soft: #1d2f3f;
  --accent-ink: #a9cfeb;
  --on-accent: #0b1a26;
  --link: #98c2e4;
  --focus: #98c2e4;
  --y3: #63c9bd;
  --y2: #3d9a8f;
  --y1: #256c64;
  --mid: #3a3d43;
  --o1: #7a4b2c;
  --o2: #b8693d;
  --o3: #e7a179;
  --nodata: #22252b;
  --map-line: rgba(238, 234, 225, 0.10);
  --county-line: rgba(238, 234, 225, 0.6);
  --male: #7fb3dc;
  --female: #e29a72;
  --b0: #3f9a8e;
  --b1: #5fb7ab;
  --b2: #8fd0c6;
  --b3: #c9a27a;
  --b4: #d98a5c;
  --b5: #f0b48e;
}

*, *::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 { 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 */
.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; letter-spacing: 0.01em; 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 */
.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; letter-spacing: -0.005em; }
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; }

/* headline stat row */
.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; }

/* map 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 260px; }
.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; }
.search-list .med { font-variant-numeric: tabular-nums; font-weight: 600; }
.years { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 999px; overflow: hidden; }
.years button { border: 0; background: transparent; padding: 0.35rem 0.7rem; cursor: pointer; color: var(--fg-soft); }
.years button[aria-pressed="true"] { background: var(--fg); color: var(--bg); }
.play { border: 1px solid var(--line-strong); background: var(--bg-raised); border-radius: 999px; padding: 0.35rem 0.8rem; cursor: pointer; }

.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); }
.u { fill: var(--nodata); stroke: var(--map-line); stroke-width: 0.25; transition: fill 0.5s ease; cursor: pointer; }
@media (prefers-reduced-motion: reduce) { .u { transition: none; } }
.u.c0 { fill: var(--y3); } .u.c1 { fill: var(--y2); } .u.c2 { fill: var(--y1); } .u.c3 { fill: var(--mid); }
.u.c4 { fill: var(--o1); } .u.c5 { fill: var(--o2); } .u.c6 { fill: var(--o3); }
.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));
}
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem 0.6rem; margin-top: 0.7rem; font-family: var(--sans); font-size: 0.82rem; color: var(--fg-soft); }
.legend .sw { display: inline-block; width: 26px; height: 12px; border-radius: 3px; border: 1px solid var(--line); vertical-align: middle; margin-right: 0.25rem; }
.legend .c0 { background: var(--y3); } .legend .c1 { background: var(--y2); } .legend .c2 { background: var(--y1); } .legend .c3 { background: var(--mid); }
.legend .c4 { background: var(--o1); } .legend .c5 { background: var(--o2); } .legend .c6 { background: var(--o3); }
.map-year { position: absolute; left: 0.9rem; bottom: 0.6rem; font-family: var(--sans); font-size: clamp(1.4rem, 3vw, 2.2rem); font-weight: 700; color: var(--fg-faint); letter-spacing: -0.02em; pointer-events: none; }

/* locality 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.15rem; line-height: 1.4; margin: 0 0 0.9rem; }
.card .claim b { font-size: 1.3rem; font-family: var(--sans); font-weight: 700; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.fp { display: grid; grid-template-columns: repeat(20, 1fr); gap: 3px; margin: 0.25rem 0 0.5rem; }
.fp i { display: block; aspect-ratio: 1; border-radius: 2px; background: var(--bg-sunken); }
.fp .b0 { background: var(--b0); } .fp .b1 { background: var(--b1); } .fp .b2 { background: var(--b2); }
.fp .b3 { background: var(--b3); } .fp .b4 { background: var(--b4); } .fp .b5 { background: var(--b5); }
.fp-legend { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.2rem 0.6rem; font-family: var(--sans); font-size: 0.8rem; color: var(--fg-soft); margin: 0 0 1rem; padding: 0; list-style: none; }
.fp-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 0.3rem; vertical-align: -1px; }
.fp-legend .b0 { background: var(--b0); } .fp-legend .b1 { background: var(--b1); } .fp-legend .b2 { background: var(--b2); }
.fp-legend .b3 { background: var(--b3); } .fp-legend .b4 { background: var(--b4); } .fp-legend .b5 { background: var(--b5); }
.fp-legend b { font-variant-numeric: tabular-nums; color: var(--fg); }
.ind { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.6rem; margin: 0 0 1rem; font-family: var(--sans); }
.ind div { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 0.6rem 0.65rem; }
.ind b { display: block; font-size: 1.35rem; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.ind span { display: block; font-size: 0.74rem; color: var(--fg-soft); line-height: 1.3; margin-top: 0.25rem; }
.ind small { display: block; font-size: 0.72rem; color: var(--fg-faint); margin-top: 0.2rem; font-variant-numeric: tabular-nums; }
.card figure { margin: 0 0 0.9rem; }
.card figcaption { font-family: var(--sans); font-size: 0.8rem; color: var(--fg-faint); margin-top: 0.3rem; }
.pyr { width: 100%; height: auto; display: block; }
.pyr .m { fill: var(--male); } .pyr .f { fill: var(--female); } .pyr .open { opacity: 0.45; }
.pyr .axis { stroke: var(--line-strong); stroke-width: 1; }
.pyr text { font-family: var(--sans); font-size: 10px; fill: var(--fg-faint); }
.trend { width: 100%; height: auto; display: block; }
.trend .nat { stroke: var(--fg-faint); stroke-width: 1.5; fill: none; stroke-dasharray: 4 3; }
.trend .loc { stroke: var(--accent); stroke-width: 2.5; fill: none; }
.trend .grid { stroke: var(--line); stroke-width: 1; }
.trend text { font-family: var(--sans); font-size: 10px; fill: var(--fg-faint); }
.trend .lbl { fill: var(--fg-soft); font-size: 10.5px; }
.card .actions { display: flex; gap: 0.6rem; flex-wrap: wrap; font-family: var(--sans); font-size: 0.85rem; }
.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; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.card .empty { color: var(--fg-soft); }
.card .empty ul { padding-left: 1.1rem; margin: 0.5rem 0 0; }
.card .empty button { border: 0; background: none; padding: 0; color: var(--link); text-decoration: underline; cursor: pointer; font: inherit; }
.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.25rem 0 0; line-height: 1.45; }

/* histogram */
.hist { width: 100%; height: auto; display: block; }
.hist rect { fill: var(--accent); }
.hist rect.c0 { fill: var(--y3); } .hist rect.c1 { fill: var(--y2); } .hist rect.c2 { fill: var(--y1); } .hist rect.c3 { fill: var(--mid); }
.hist rect.c4 { fill: var(--o1); } .hist rect.c5 { fill: var(--o2); } .hist rect.c6 { fill: var(--o3); }
.hist rect.mine { stroke: var(--fg); stroke-width: 2; }
.hist .axis { stroke: var(--line-strong); }
.hist text { font-family: var(--sans); font-size: 13px; fill: var(--fg-faint); }
.hist .mark { stroke: var(--fg); stroke-width: 1.5; stroke-dasharray: 4 3; }
.hist .mark-lbl { fill: var(--fg); font-weight: 600; }
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; }

/* extremes */
.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); }
.rank li .n { color: var(--fg-faint); font-variant-numeric: tabular-nums; }
.rank li button { border: 0; background: none; padding: 0; text-align: left; color: var(--link); text-decoration: underline; cursor: pointer; font: inherit; }
.rank li .where { display: block; color: var(--fg-faint); font-size: 0.8rem; }
.rank li b { font-variant-numeric: tabular-nums; font-size: 1.05rem; }
.rank li .pop { color: var(--fg-faint); font-size: 0.78rem; display: block; text-align: right; }

/* county table */
.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; }
tbody tr:hover { background: var(--bg-raised); }
.bar { display: inline-block; height: 8px; border-radius: 4px; background: var(--accent); vertical-align: middle; margin-right: 0.4rem; }

.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; }

.sr-live { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.back-top { position: fixed; right: 1rem; bottom: 1rem; z-index: 10; }
@media (min-width: 901px) { .back-top { display: none; } }
