/* Layout: map (left) beside a swipeable donut (right), a slim tappable legend below, then the chosen prefecture's 30 years as stacked bars */
:root {
  --bg: #070b14;
  --surface: #0f1625;
  --surface2: #141d30;
  --line: #22304a;
  --fg: #e9eef6;
  --muted: #8b98ae;
  --accent: #5b9dff;
  --warm: #ff5a4e;
  --font-body: "Zen Kaku Gothic New", "Hiragino Sans", "Yu Gothic", "Meiryo", sans-serif;
  --font-num: "IBM Plex Sans Condensed", "Arial Narrow", "Zen Kaku Gothic New", sans-serif; /* has tabular figures, so amounts line up */
  color-scheme: dark;
}
* { box-sizing: border-box; }
body {
  background: radial-gradient(120% 60% at 10% 0%, #10233a 0%, rgba(7, 11, 20, 0) 60%), radial-gradient(90% 50% at 100% 30%, #1c1433 0%, rgba(7, 11, 20, 0) 60%), var(--bg);
  background-attachment: fixed;
  color: var(--fg); font-family: var(--font-body); font-size: 15px; line-height: 1.6;
  touch-action: manipulation; /* no double-tap zoom: double taps open a breakdown */
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 20px 40px;
  -webkit-tap-highlight-color: transparent;
}
.wrap { max-width: 720px; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; }
.wrap > * { min-width: 0; }
header { display: grid; gap: 4px; }
.eyebrow { font-size: 12px; letter-spacing: .12em; color: var(--muted); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.badge { border: 1px solid var(--accent); color: var(--accent); border-radius: 4px; padding: 0 6px; font-size: 11px; letter-spacing: .05em; }
h1 { margin: 0; font-size: 24px; font-weight: 700; text-wrap: balance; line-height: 1.3;
  background: linear-gradient(90deg, var(--fg) 0%, var(--fg) 55%, var(--accent) 100%); -webkit-background-clip: text; background-clip: text; color: transparent; }
.lead { margin: 0; color: var(--muted); font-size: 13px; }
.num, .rank li .val, .rank li .n, .chip .pct, svg text { font-family: var(--font-num); font-variant-numeric: tabular-nums; letter-spacing: 0; }

.sharebtn { justify-self: start; min-height: 36px; padding: 0 14px; border-radius: 18px; border: 1px solid var(--line); background: var(--surface); color: var(--accent); font: inherit; font-size: 13px; cursor: pointer; }
/* controls */
.controls { display: grid; gap: 10px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 4px; gap: 4px; }
.seg button { min-height: 44px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); font: inherit; font-weight: 500; cursor: pointer; }
.seg button[aria-pressed="true"] { background: linear-gradient(135deg, #2f5fd0, #5b9dff 55%, #8a7bff); color: #ffffff; font-weight: 700; }
.row { display: flex; gap: 10px; align-items: center; }
.row label { font-size: 13px; color: var(--muted); white-space: nowrap; }
select { flex: 1; min-width: 0; min-height: 44px; background: var(--surface); color: var(--fg); border: 1px solid var(--line); border-radius: 8px; padding: 0 10px; font: inherit; }
input[type=range] { width: 100%; min-width: 0; accent-color: var(--accent); height: 34px; margin: 0; }
.yr { flex: 1; min-width: 0; position: relative; padding-bottom: 16px; }
.ticks { position: absolute; left: 8px; right: 8px; bottom: 0; height: 14px; font-size: 11px; color: var(--muted); }
.ticks span { position: absolute; transform: translateX(-50%); }
.yearval { font-size: 22px; min-width: 56px; text-align: right; }
button:focus-visible, select:focus-visible, input:focus-visible, path:focus-visible, circle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* map + donut side by side */
.hero { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 10px; align-items: stretch; }
.panel { background: linear-gradient(160deg, var(--surface2), var(--surface)); border: 1px solid var(--line); border-radius: 14px; padding: 10px; display: grid; gap: 6px; min-width: 0; align-content: start; }
.panel.mappanel { grid-template-rows: auto auto 1fr auto; }
.panel.mappanel h2 { min-height: 2.7em; } /* keep two lines so the map does not shift when the title length changes */
.panel.mappanel svg.map { align-self: center; }
.panel h2 { margin: 0; font-size: 14px; line-height: 1.35; }
.panel small { color: var(--muted); font-size: 11px; display: block; }
svg.map { width: 100%; height: auto; max-height: 420px; display: block; touch-action: manipulation; }
svg.map path { stroke: var(--bg); stroke-width: 3; cursor: pointer; transition: fill .4s; }
svg.map path.sel { stroke: var(--fg); stroke-width: 7; }
svg.map .inset { fill: none; stroke: var(--line); stroke-width: 3; }
.legend { display: grid; gap: 2px; font-size: 10px; color: var(--muted); }
.legend .bar { height: 6px; border-radius: 3px; }
.legend .ends { display: flex; justify-content: space-between; gap: 6px; }

.carousel { display: grid; grid-auto-flow: column; grid-auto-columns: 100%; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; overscroll-behavior-x: contain; }
.carousel::-webkit-scrollbar { display: none; }
.dcard { scroll-snap-align: start; display: grid; gap: 4px; justify-items: center; align-content: start; min-width: 0; text-align: center; }
.dcard h3 { margin: 0; font-size: 14px; line-height: 1.3; }
.dcard h3 small { font-weight: 400; display: block; }
.subhead { margin: 4px 0 6px; font-size: 13px; font-weight: 700; text-align: center; }
svg.subbar { display: block; width: 100%; height: 18px; margin-bottom: 8px; }
.sublegend { display: grid; }
.srow { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: stretch; }
.srow .more { width: 16px; border: 0; border-bottom: 1px solid var(--line); background: transparent; color: var(--accent); font: inherit; font-size: 16px; font-weight: 700; cursor: pointer; padding: 0; }
.sublegend button { display: grid; grid-template-columns: 8px minmax(0, 1fr) auto; gap: 4px; align-items: center; min-height: 28px; padding: 0 2px; border: 0; border-bottom: 1px solid var(--line); background: transparent; color: var(--fg); font: inherit; font-size: 12px; line-height: 1.2; text-align: left; cursor: pointer; }
.sublegend button span:nth-child(2) { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; } /* one line; the full name shows in the map title */
.sublegend button.on { color: var(--accent); font-weight: 700; }
.sublegend i { width: 7px; height: 7px; border-radius: 50%; }
.sublegend .pct { font-family: var(--font-num); font-size: 13px; font-variant-numeric: tabular-nums; }
.vlegend .crumb { font-size: 11px; text-align: left; padding: 0 2px; min-height: 24px; }
.crumb { border: 0; background: transparent; color: var(--accent); font: inherit; font-size: 13px; font-weight: 700; padding: 2px 4px; min-height: 28px; cursor: pointer; }
svg.donut { width: 100%; max-width: 170px; height: auto; }
.donut circle.seg { fill: none; cursor: pointer; transition: opacity .2s, stroke-width .2s; }
.donut text { fill: var(--fg); }
.dots { display: flex; justify-content: center; gap: 6px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--line); }
.dots i.on { background: var(--accent); }
.swipehint { color: var(--muted); font-size: 10px; text-align: center; }

/* slim legend list in the right column, under the donut (tappable) */
.chips { display: grid; width: 100%; align-content: start; height: 292px; } /* fixed, so the map does not resize */
.chips.expanded { overflow-y: auto; overscroll-behavior: contain; } /* an expanded "その他" scrolls inside */
.chips.expanded::after { content: ""; position: sticky; bottom: 0; height: 28px; margin-top: -28px; pointer-events: none;
  background: linear-gradient(rgba(15, 22, 37, 0), var(--surface)); } /* fade at the bottom: "there is more below" */
.srow.ex button[data-g] { padding-left: 12px; }
.srow.ex span:nth-child(2) { color: var(--muted); }
.sublegend .tog { justify-self: start; border: 0; background: transparent; color: var(--accent); font: inherit; font-size: 11px; white-space: nowrap; padding: 2px 2px 2px 14px; min-height: 26px; cursor: pointer; }
.vlegend button.ex { padding-left: 10px; }
.chip { display: grid; grid-template-columns: 8px minmax(0, 1fr) auto; gap: 6px; align-items: center; min-height: 29px; padding: 0 2px; border: 0; border-bottom: 1px solid var(--line); background: transparent; color: var(--fg); font: inherit; font-size: 12px; line-height: 1.2; text-align: left; cursor: pointer; }
.chip > span:nth-child(2) { overflow-wrap: anywhere; }
.chip i { width: 8px; height: 8px; border-radius: 50%; }
.chip .pct { font-family: var(--font-num); font-size: 14px; font-variant-numeric: tabular-nums; }
.chip[aria-pressed="true"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 700; }
.chips.picking .chip:not([aria-pressed="true"]) { opacity: .55; }
/* legend + values under the trend chart */
.tinfo { font-size: 13px; display: flex; justify-content: space-between; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.tinfo b { font-family: var(--font-num); font-size: 20px; font-weight: 600; }
/* year table (left) + vertical legend (right) above the trend chart */
.summary { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: start; }
.sumleft { display: grid; gap: 6px; min-width: 0; }
.tdots { display: inline-flex; gap: 4px; margin-left: 8px; vertical-align: middle; }
.tdots i { width: 5px; height: 5px; border-radius: 50%; background: var(--line); }
.tdots i.on { background: var(--accent); }

/* 目的別 | 性質別 | 歳入 tabs above the chart */
.ttabs { display: grid; grid-template-columns: repeat(3, 1fr); border-bottom: 1px solid var(--line); }
.ttabs button { min-height: 38px; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; background: transparent; color: var(--muted); font: inherit; font-size: 13px; cursor: pointer; }
.ttabs button[aria-selected="true"] { color: var(--fg); font-weight: 700; border-bottom-color: var(--accent); }

.ktab { width: 100%; border-collapse: collapse; }
.ktab th { font-size: 11px; color: var(--muted); font-weight: 400; text-align: left; padding: 0 4px 4px; }
.ktab tbody th { font-size: 22px; font-weight: 600; color: var(--fg); vertical-align: top; padding-top: 4px; }
.ktab td { vertical-align: top; padding: 6px 4px; font-size: 14px; line-height: 1.35; }
.ktab td b { font-size: 30px; font-weight: 600; }
.ktab td small { color: var(--muted); margin-left: 1px; }
.ktab td .num { font-variant-numeric: tabular-nums; }
.ktab td .d { display: block; color: var(--accent); font-family: var(--font-num); font-size: 15px; }
.ktab tr.cmp td, .ktab tr.cmp th { border-top: 1px solid var(--line); color: var(--muted); }
.ktab tr.cmp td b { color: var(--fg); }
.ktab td.thint { border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; padding-top: 8px; }
.vlegend { display: grid; gap: 0; }
.vlegend { max-width: 8em; }
.vlegend button span { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.vlegend .mk { color: var(--accent); font-weight: 700; font-size: 14px; margin-left: auto; padding: 0 4px 0 8px; min-height: 24px; display: inline-flex; align-items: center; cursor: pointer; flex: none; }
.vlegend button { width: 100%; }
.vlegend button { display: flex; align-items: center; gap: 5px; min-height: 24px; padding: 0 2px; border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 11px; text-align: left; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.vlegend button.on { color: var(--accent); font-weight: 700; }
.vlegend i { width: 7px; height: 7px; border-radius: 50%; flex: none; }
svg.trend rect.bar { cursor: pointer; }

/* detail */
.detail { background: linear-gradient(160deg, var(--surface2), var(--surface)); border: 1px solid var(--line); border-radius: 14px; padding: 18px 16px; display: grid; gap: 14px; }
.detail h2 { margin: 0; font-size: 20px; }
.detail .sub { color: var(--muted); font-size: 13px; margin: 0; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kpi { display: grid; gap: 2px; }
.kpi .k { font-size: 12px; color: var(--muted); }
.kpi .v { font-size: 30px; line-height: 1.1; }
.kpi .v small { font-size: 14px; margin-left: 2px; color: var(--muted); font-family: var(--font-body); }
.trendhead { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.trendhead span { font-size: 12px; color: var(--muted); }
.mini { min-height: 32px; padding: 0 10px; border-radius: 16px; border: 1px solid var(--line); background: transparent; color: var(--fg); font: inherit; font-size: 12px; cursor: pointer; }
.mini[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.tmode { display: inline-flex; gap: 4px; }
.tmode .mini { min-height: 36px; }
.tmode .mini[aria-pressed="true"] { background: rgba(91, 157, 255, .16); }
svg.trend { width: 100%; height: auto; display: block; }
svg.trend text { fill: var(--muted); font-size: 11px; font-family: var(--font-num); paint-order: stroke; stroke: #0f1625; stroke-width: 3px; } /* halo: labels stay readable over bars */
.hint { color: var(--muted); font-size: 13px; text-align: center; margin: 0; }

/* ranking */
.rank { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.rank ol { margin: 0; padding: 0; list-style: none; display: grid; gap: 2px; }
.rank h3 { margin: 0 0 6px; font-size: 13px; color: var(--muted); font-weight: 500; }
.rank .rhead { grid-column: 1 / -1; margin: 0; font-size: 14px; font-weight: 700; }
.rank li button { width: 100%; display: grid; grid-template-columns: 22px 1fr auto; gap: 6px; align-items: center; min-height: 36px; background: transparent; border: 0; border-bottom: 1px solid var(--line); color: var(--fg); font: inherit; font-size: 13px; text-align: left; cursor: pointer; padding: 0 2px; }
.rank li .n { color: var(--muted); font-family: var(--font-num); }
.rank li .val { font-family: var(--font-num); font-size: 14px; }

footer { color: #b4bdcc; font-size: 13px; line-height: 1.7; display: grid; gap: 8px; border-top: 1px solid var(--line); padding-top: 14px; } /* notes are important: readable size and contrast */
footer p { margin: 0; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
