/* Layout: yksi kapea lukupalsta (max 60rem), laskurissa kaksi saraketta; numerot tasalevyisinä.
   Visuaalinen idea: postinumeroruudukko ja tilastotaulukon tarkkuus, ei koristeita. */
:root {
  --bg: #f3f6f5;        /* koivun harmaa, vihertävä */
  --surface: #ffffff;
  --fg: #12232d;        /* järvenpohjan muste */
  --muted: #55666f;
  --line: #d5dfdd;
  --accent: #1d6fa3;    /* järvensininen */
  --accent-soft: #dbe9f3;
  --you: #c98a0c;       /* "sinä"-merkki, meripihka */
  --you-soft: #fbefd2;
  --lo: #8fb3c9; --mid: #4f86ab; --hi: #1b4f78;
  --font-display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --font-body: "Public Sans", "Segoe UI", system-ui, sans-serif;
  --font-data: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --r: 6px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1a21; --surface: #142530; --fg: #e4ecee; --muted: #9aaeb6; --line: #27414f;
    --accent: #6cb4e4; --accent-soft: #183a50; --you: #f0b43c; --you-soft: #3a2e14;
    --lo: #3d6178; --mid: #5c95bd; --hi: #a9d3f0; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1a21; --surface: #142530; --fg: #e4ecee; --muted: #9aaeb6; --line: #27414f;
  --accent: #6cb4e4; --accent-soft: #183a50; --you: #f0b43c; --you-soft: #3a2e14;
  --lo: #3d6178; --mid: #5c95bd; --hi: #a9d3f0; color-scheme: dark;
}

* { box-sizing: border-box; }
body { background: var(--bg); color: var(--fg); font: 400 1rem/1.6 var(--font-body); margin: 0; }
a { color: var(--accent); text-underline-offset: 2px; }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, h3 { font-family: var(--font-display); line-height: 1.15; text-wrap: balance; margin: 0; }
h1 { font-size: clamp(1.9rem, 5vw, 2.8rem); font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 1.4rem; font-weight: 650; }
h3 { font-size: 1.05rem; font-weight: 600; margin-top: 1.2rem; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.9rem; }
.code, .tile-value, .bar-val, .li-val, .kv b, .facts b, table { font-variant-numeric: tabular-nums; }
.code { font-family: var(--font-data); font-weight: 500; }

.site-head { border-bottom: 1px solid var(--line); background: var(--surface); }
.site-head .wrap { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding-block: 0.8rem; flex-wrap: wrap; }
.logo { font-family: var(--font-display); font-weight: 800; font-size: 1.25rem; color: var(--fg); text-decoration: none; display: inline-flex; align-items: center; gap: 0.5rem; }
.logo-grid { display: inline-grid; grid-template-columns: repeat(3, 6px); gap: 2px; }
.logo-grid i { width: 6px; height: 6px; background: var(--accent); display: block; }
.logo-grid i:nth-child(2n) { opacity: 0.35; }
.logo-grid i:nth-child(5) { background: var(--you); opacity: 1; }
.site-nav { display: flex; gap: 1.2rem; flex-wrap: wrap; }
.site-nav a { color: var(--fg); text-decoration: none; font-weight: 500; }
.site-nav a[aria-current="page"] { color: var(--accent); box-shadow: inset 0 -2px 0 var(--accent); }

.wrap { max-width: 60rem; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
main.wrap { padding-block: 2rem 4rem; display: flex; flex-direction: column; gap: 2rem; }
main section { display: flex; flex-direction: column; gap: 0.8rem; }
.eyebrow { font-family: var(--font-data); font-size: 0.78rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.lede { font-size: 1.15rem; color: var(--muted); max-width: 40rem; margin-top: 0.4rem; }
.crumbs { font-size: 0.9rem; color: var(--muted); }
.pc-head, .tool-head { display: flex; flex-direction: column; gap: 0.3rem; }
.pc-head h1 .code { color: var(--accent); }

/* Etusivu */
.hero { display: grid; gap: 1.5rem; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); align-items: center; }
.hero h1 { font-size: clamp(2.1rem, 6vw, 3.4rem); }
.hero-grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; max-width: 100%; }
.hero-grid i { aspect-ratio: 1; border-radius: 2px; background: var(--accent); display: block; }
.ideas { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: 1rem; }
.idea { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 1.2rem; display: flex; flex-direction: column; gap: 0.5rem; text-decoration: none; color: var(--fg); }
a.idea:hover { border-color: var(--accent); }
.idea .status { font-family: var(--font-data); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); }
.idea.soon { background: transparent; border-style: dashed; }
.idea.soon .status { color: var(--muted); }
.idea h2 { font-size: 1.2rem; }

/* Laskuri */
.privacy { background: var(--accent-soft); border-radius: var(--r); padding: 0.9rem 1.1rem; font-size: 0.95rem; }
.tool-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 1.2rem; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 1.2rem; }
form.panel { display: flex; flex-direction: column; gap: 1.2rem; }
fieldset { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.7rem; min-width: 0; }
legend { font-family: var(--font-display); font-weight: 650; font-size: 1.05rem; margin-bottom: 0.5rem; padding: 0; }
.field { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.9rem; color: var(--muted); min-width: 0; }
.field em { font-style: normal; opacity: 0.8; }
input, select { font: 500 1.05rem var(--font-body); color: var(--fg); background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 0.55rem 0.65rem; width: 100%; min-width: 0; }
input#amount, input#pn, input#age, input[id^="cmp-"] { font-family: var(--font-data); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem; }
.row3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.7rem; align-items: end; }
.hint { font-size: 0.85rem; color: var(--muted); }
.seg-ctl { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
.seg-ctl label { position: relative; }
.seg-ctl input { position: absolute; opacity: 0; inset: 0; }
.seg-ctl span { display: block; text-align: center; padding: 0.5rem; cursor: pointer; font-weight: 500; }
.seg-ctl input:checked + span { background: var(--accent); color: var(--surface); }
.seg-ctl input:focus-visible + span { outline: 2px solid var(--you); outline-offset: -2px; }
details { border-top: 1px solid var(--line); padding-top: 1rem; }
details summary { cursor: pointer; font-weight: 600; color: var(--accent); }
details[open] summary { margin-bottom: 0.6rem; }
details .row3 { margin-top: 0.6rem; }

.result { display: flex; flex-direction: column; gap: 1rem; min-height: 100%; }
.headline { font-family: var(--font-display); font-size: clamp(1.4rem, 3.5vw, 1.9rem); font-weight: 650; line-height: 1.2; text-wrap: balance; }
mark { background: var(--you-soft); color: var(--fg); padding: 0 0.2em; border-radius: 3px; box-shadow: inset 0 -3px 0 var(--you); }
.facts { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.facts li { display: flex; justify-content: space-between; gap: 1rem; padding: 0.45rem 0; border-bottom: 1px solid var(--line); }
.facts em { font-style: normal; color: var(--muted); font-size: 0.85rem; margin-left: 0.3rem; }
.national { background: var(--you-soft); border-radius: var(--r); padding: 0.8rem 1rem; }
.empty { display: flex; flex-direction: column; gap: 0.6rem; }

.scale { position: relative; height: 9.6rem; margin: 0.4rem 2.2rem 0; }
.scale-line { position: absolute; left: -1rem; right: -1rem; top: 2.2rem; height: 2px; background: var(--line); }
.scale-mark, .scale-you { position: absolute; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; font-size: 0.75rem; white-space: nowrap; line-height: 1.25; }
.scale-mark { top: 2.2rem; }
.scale-mark i { width: 2px; height: 0.7rem; background: var(--muted); }
.scale-mark.lvl1 i { height: 2.9rem; }
.scale-mark.lvl2 i { height: 5.1rem; }
.scale-mark b { font-weight: 600; }
.scale-mark small { color: var(--muted); font-family: var(--font-data); }
.scale-you { top: 0.2rem; z-index: 1; }
.scale-you b { color: var(--you); font-weight: 700; font-size: 0.85rem; }
.scale-you i { width: 14px; height: 14px; border-radius: 50%; background: var(--you); border: 2px solid var(--surface); margin-top: 0.15rem; }

.share-row { display: grid; grid-template-columns: minmax(0, 20rem) minmax(0, 1fr); gap: 1.2rem; align-items: start; }
#share-canvas { width: 100%; max-width: 100%; height: auto; border-radius: var(--r); border: 1px solid var(--line); }
.share-actions { display: flex; flex-direction: column; gap: 0.6rem; align-items: flex-start; }
.btn { display: inline-block; background: var(--accent); color: var(--surface); border: 0; border-radius: 4px; padding: 0.6rem 1rem; font: 600 1rem var(--font-body); text-decoration: none; cursor: pointer; }
.btn-ghost { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.cta { align-self: flex-start; font-weight: 600; text-decoration: none; border: 1px solid var(--accent); padding: 0.6rem 1rem; border-radius: 4px; }
.cta:hover { background: var(--accent-soft); }
.method p { max-width: 42rem; }
.source { font-size: 0.85rem; color: var(--muted); border-top: 1px solid var(--line); padding-top: 1rem; max-width: 46rem; }

/* Postinumerosivut */
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.8rem; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 0.9rem 1rem; display: flex; flex-direction: column; gap: 0.15rem; }
.tile-label { font-size: 0.85rem; color: var(--muted); }
.tile-value { font-family: var(--font-display); font-size: 1.6rem; font-weight: 700; }
.tile-sub { font-size: 0.8rem; color: var(--muted); }
.prose { max-width: 42rem; gap: 0.7rem !important; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: 0 1.5rem; }
.kv div { display: flex; justify-content: space-between; gap: 1rem; padding: 0.45rem 0; border-bottom: 1px solid var(--line); }
.kv span { color: var(--muted); }

.bars { display: flex; flex-direction: column; gap: 0.35rem; max-width: 42rem; }
.bar-row { display: grid; grid-template-columns: 9.5rem minmax(0, 1fr) 4rem; gap: 0.7rem; align-items: center; font-size: 0.92rem; }
.bar-track { position: relative; height: 0.9rem; background: var(--accent-soft); border-radius: 2px; }
.bar-fill { position: absolute; inset: 0 auto 0 0; background: var(--accent); border-radius: 2px; }
.bar-ref { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--fg); }
.bar-val { text-align: right; font-family: var(--font-data); font-size: 0.85rem; }
.bar-legend { font-size: 0.8rem; color: var(--muted); display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem 0.5rem; }
.key { display: inline-block; width: 0.8rem; height: 0.8rem; border-radius: 2px; vertical-align: middle; }
.key-fill { background: var(--accent); }
.key-ref { width: 2px; background: var(--fg); }

.stack { display: flex; height: 2.2rem; border-radius: 3px; overflow: hidden; max-width: 42rem; }
.seg { display: flex; align-items: center; justify-content: center; font-size: 0.85rem; color: var(--surface); min-width: 2.6rem; }
.seg-lo { background: var(--lo); color: var(--fg); }
.seg-mid { background: var(--mid); }
.seg-hi { background: var(--hi); }
:root[data-theme="dark"] .seg-hi { color: var(--bg); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .seg-hi { color: var(--bg); } }
.stack-ref { height: 6px; margin-top: 3px; gap: 0; background: none; }
.stack-ref span { border-left: 2px solid var(--fg); border-right: 0; }
.stack-ref span:first-child { border-left: 0; }

.cols { display: grid !important; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.cols > div { min-width: 0; display: flex; flex-direction: column; gap: 0.6rem; }
.pc-list { list-style: none; margin: 0; padding: 0; }
.pc-list li { display: flex; justify-content: space-between; gap: 1rem; padding: 0.35rem 0; border-bottom: 1px solid var(--line); }
.pc-list li a { text-decoration: none; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li-val { font-family: var(--font-data); font-size: 0.85rem; color: var(--muted); white-space: nowrap; }

.search { display: flex; flex-direction: column; gap: 0.3rem; max-width: 26rem; color: var(--muted); font-size: 0.9rem; }
.mun-list { columns: 2 22rem; column-gap: 2rem; }
.mun { break-inside: avoid; margin-bottom: 1.4rem; gap: 0.3rem !important; }
.mun h2 { font-size: 1.1rem; }

.table-wrap { overflow-x: auto; }
table.cmp { border-collapse: collapse; width: 100%; min-width: 30rem; }
.cmp th, .cmp td { text-align: right; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--line); }
.cmp th:first-child { text-align: left; font-weight: 500; color: var(--muted); }
.cmp thead th { vertical-align: bottom; font-family: var(--font-data); }
.cmp thead small { display: block; font-family: var(--font-body); font-weight: 400; color: var(--muted); font-size: 0.78rem; }
.cmp-inputs { max-width: 26rem; }

.site-foot { border-top: 1px solid var(--line); padding-block: 1.5rem; font-size: 0.85rem; color: var(--muted); }

@media (max-width: 760px) {
  .hero, .tool-grid, .share-row, .cols { grid-template-columns: minmax(0, 1fr) !important; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .row3 { grid-template-columns: 1fr 1fr; }
  .bar-row { grid-template-columns: 7rem minmax(0, 1fr) 3.4rem; }
  .hero-grid { max-width: 18rem; }
}
@media (prefers-reduced-motion: no-preference) {
  .bar-fill { transition: width 0.3s ease; }
}

/* ---------- Kaaviot, kartta ja uudet työkalut ---------- */
:root { --s0: var(--accent); --s1: var(--you); --s2: #6c8f3d; --s3: var(--muted); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --s2: #a4c46c; } }
:root[data-theme="dark"] { --s2: #a4c46c; }
.chart { max-width: 46rem; margin-bottom: 0.6rem; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.c-grid { stroke: var(--line); stroke-width: 1; }
.c-tick { fill: var(--muted); font: 11px var(--font-data); }
.c-line { fill: none; stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.c-dash { stroke-dasharray: 5 4; }
.c-dot { stroke: none; }
.c-s0 { stroke: var(--s0); } .c-s0.c-dot, text.c-s0 { fill: var(--s0); }
.c-s1 { stroke: var(--s1); } .c-s1.c-dot, text.c-s1 { fill: var(--s1); }
.c-s2 { stroke: var(--s2); } .c-s2.c-dot, text.c-s2 { fill: var(--s2); }
.c-s3 { stroke: var(--s3); } .c-s3.c-dot, text.c-s3 { fill: var(--s3); }
text.c-end { font: 600 11px var(--font-body); stroke: none; }
.c-mark { stroke: var(--fg); stroke-width: 1; stroke-dasharray: 2 3; opacity: 0.6; }
.c-mark-t { fill: var(--fg); font: 11px var(--font-data); }

.hbars { display: flex; flex-direction: column; gap: 0.45rem; max-width: 46rem; }
.hb-row { display: grid; grid-template-columns: minmax(0, 14rem) minmax(0, 1fr) 6.5rem; gap: 0.7rem; align-items: center; font-size: 0.92rem; }
.hb-label { min-width: 0; line-height: 1.25; }
.hb-label small { display: block; color: var(--muted); font-size: 0.78rem; }
.hb-track { height: 0.9rem; background: var(--accent-soft); border-radius: 2px; position: relative; }
.hb-fill { position: absolute; inset: 0 auto 0 0; background: var(--accent); border-radius: 2px; }
.hb-row.hl .hb-fill { background: var(--you); }
.hb-val { text-align: right; font-family: var(--font-data); font-size: 0.85rem; white-space: nowrap; }
.sp { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: 0.8rem; max-width: 46rem; }
.sp-item { display: flex; flex-direction: column; gap: 0.1rem; border: 1px solid var(--line); border-radius: var(--r); padding: 0.7rem 0.9rem; background: var(--surface); }
.sp-item span { color: var(--muted); font-size: 0.85rem; }
.sp-item b { font-family: var(--font-display); font-size: 1.4rem; }
.sp-item small { color: var(--muted); font-size: 0.78rem; }
main details { margin-top: 0.4rem; }
.seg3 { grid-template-columns: repeat(3, 1fr); }

.k-grid { display: grid; grid-template-columns: minmax(0, 20rem) minmax(0, 1fr); gap: 1.5rem; align-items: start; }
.k-grid > .panel { position: sticky; top: calc(env(safe-area-inset-top, 0px) + 1rem); display: flex; flex-direction: column; gap: 0.8rem; }
.k-detail { display: flex; flex-direction: column; gap: 1.6rem; min-width: 0; }
.k-detail .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.k-name { font-size: clamp(1.8rem, 4vw, 2.4rem); }
.picker { display: flex; flex-direction: column; gap: 0.6rem; }
.map-wrap { max-width: 20rem; }
.fi-map { width: 100%; height: auto; display: block; }
.fi-map .muni { fill: var(--accent); stroke: var(--surface); stroke-width: 0.35; cursor: pointer; }
.fi-map .muni.na { fill: var(--line); }
.fi-map .muni:hover { stroke: var(--fg); stroke-width: 0.8; }
.fi-map .muni.sel { fill: var(--you); fill-opacity: 1 !important; stroke: var(--fg); stroke-width: 1; }
.map-legend { display: flex; align-items: center; gap: 0.5rem; font: 0.75rem var(--font-data); color: var(--muted); }
.map-legend .ramp { flex: 1; height: 8px; border-radius: 2px; background: linear-gradient(90deg, var(--accent-soft), var(--accent)); }
.nat { display: flex; flex-direction: column; gap: 0.8rem; margin-top: 1rem; }
.site-nav { gap: 0.4rem 1rem; font-size: 0.95rem; }
@media (max-width: 760px) {
  .k-grid { grid-template-columns: minmax(0, 1fr); }
  .k-grid > .panel { position: static; }
  .map-wrap { max-width: 14rem; margin: 0 auto; }
  .hb-row { grid-template-columns: minmax(0, 1fr) 5.5rem; }
  .hb-row .hb-track { grid-column: 1 / -1; grid-row: 2; }
}
.k-detail table.cmp { min-width: 0; }
.pc-after { padding-block: 0 3rem; display: flex; flex-direction: column; gap: 0.6rem; }
.cols3 { columns: 3 16rem; column-gap: 2rem; }
.cols3 li { break-inside: avoid; }
@media (max-width: 560px) { .c-tick, .c-mark-t { font-size: 15px; } text.c-end { font-size: 14px; } }

/* Naapurusto: kaksi korttia rinnakkain */
.duel { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; margin: 0.8rem 0; }
.duel-card { display: flex; flex-direction: column; gap: 0.1rem; padding: 0.8rem 0.9rem; border-radius: var(--r); border: 1px solid var(--line); text-decoration: none; color: var(--fg); min-width: 0; }
.duel-card:hover { border-color: var(--accent); }
.duel-card.rich { background: var(--accent-soft); }
.duel-card.poor { background: var(--you-soft); }
.duel-card .tag { font-family: var(--font-data); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.duel-card span { overflow-wrap: anywhere; }
.duel-card strong { font-family: var(--font-display); font-size: 1.5rem; font-variant-numeric: tabular-nums; margin-top: 0.3rem; }
.duel-card small { color: var(--muted); font-size: 0.78rem; }
.pc-list small.muted { font-size: 0.78rem; }
.foot-nav { display: flex; flex-wrap: wrap; gap: 0.3rem 1.1rem; margin-bottom: 0.9rem; }
.foot-nav a { color: inherit; }
.gap { margin: 0.4rem 0; text-align: center; }
.debt-clock { font-family: var(--font-data); font-size: clamp(1.5rem, 5vw, 2.3rem); font-weight: 500; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; margin: 0.2rem 0 0.4rem; color: var(--fg); }
#v-views { grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr)); margin: 0.6rem 0; }
.sc-dot { fill: var(--accent); fill-opacity: 0.35; stroke: var(--accent); stroke-width: 0.8; }
.sc-dot.hl { fill: var(--you); fill-opacity: 1; stroke: var(--fg); }
.c-hl { fill: var(--fg); font-weight: 600; }
.ctl-row { display: flex; flex-wrap: wrap; gap: 0.6rem; margin: 0.6rem 0; }
.ctl-row .field { flex: 1 1 11rem; }
.sc-lab { fill: var(--muted); font: 500 11px var(--font-body); } .sc-lab.c-hl { fill: var(--fg); font-weight: 700; } @media (max-width: 560px) { .sc-lab { font-size: 15px; } }
:root { --s4: #a34f6c; --s5: #7a5cb0; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --s4: #e08aa8; --s5: #b9a0e8; } }
:root[data-theme="dark"] { --s4: #e08aa8; --s5: #b9a0e8; }
.c-s4 { stroke: var(--s4); } .c-s4.c-dot, text.c-s4 { fill: var(--s4); }
.c-s5 { stroke: var(--s5); } .c-s5.c-dot, text.c-s5 { fill: var(--s5); }
