:root {
  --navy: #0a3555;
  --navy-2: #0f476f;
  --teal: #18a79e;
  --teal-soft: #dff5f2;
  --blue-soft: #edf6fb;
  --ink: #17232d;
  --muted: #647382;
  --line: #d9e2e8;
  --paper: #ffffff;
  --background: #f5f8fa;
  --green: #177a58;
  --amber: #a46600;
  --red: #a33a3a;
  --shadow: 0 10px 30px rgba(16, 51, 73, .08);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--background);
  font-family: Inter, "Noto Sans JP", "Segoe UI", system-ui, sans-serif;
  line-height: 1.55;
}
a { color: #075a91; }
a:hover { color: #003f68; }
button, input, select { font: inherit; }

.skip-link { position: fixed; top: -5rem; left: 1rem; z-index: 999; padding: .7rem 1rem; background: #fff; }
.skip-link:focus { top: 1rem; }

.site-header { background: var(--navy); color: #fff; }
.header-inner {
  max-width: 1440px;
  min-height: 74px;
  margin: auto;
  padding: 0 28px;
  display: flex;
  align-items: stretch;
  gap: 24px;
}
.brand { display: flex; align-items: center; gap: 12px; color: #fff; text-decoration: none; min-width: 250px; }
.brand img { width: 42px; height: 42px; }
.brand strong { font-size: 1.2rem; letter-spacing: .01em; }
.brand span { display: block; color: #c7dbe8; font-size: .72rem; font-weight: 500; }
.main-nav { display: flex; align-items: stretch; flex: 1; }
.main-nav a {
  display: flex;
  align-items: center;
  padding: 0 19px;
  color: #e5f0f7;
  text-decoration: none;
  font-size: .88rem;
  font-weight: 650;
  border-bottom: 4px solid transparent;
}
.main-nav a:hover, .main-nav a[aria-current="page"] { background: rgba(255,255,255,.05); border-color: var(--teal); color: #fff; }
.language { align-self: center; color: #fff; background: var(--navy-2); border: 1px solid rgba(255,255,255,.25); border-radius: 8px; padding: .45rem .55rem; }

.context-bar { background: #eef6f5; border-bottom: 1px solid #d6e6e5; }
.context-inner { max-width: 1320px; margin: auto; padding: 11px 28px; color: #45626e; font-size: .8rem; }
.context-inner strong { margin-right: 14px; color: var(--teal); font-size: .7rem; letter-spacing: .08em; }

main { max-width: 1320px; margin: auto; padding: 28px; }
.page-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.page-heading h1 { margin: 0 0 4px; font-size: clamp(1.55rem, 3vw, 2.25rem); line-height: 1.2; }
.page-heading p { margin: 0; color: var(--muted); }
.coverage-chip { flex: none; display: inline-flex; gap: 8px; align-items: center; padding: .55rem .8rem; border-radius: 999px; background: var(--teal-soft); color: #075f5a; font-size: .82rem; font-weight: 700; }

.card { background: var(--paper); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); }
.card-header { padding: 16px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-header h2, .card-header h3 { margin: 0; font-size: 1.05rem; }
.card-body { padding: 18px; }
.selection-layout { display: grid; grid-template-columns: minmax(270px, .72fr) minmax(500px, 1.8fr); gap: 16px; align-items: stretch; }
.selection-panel { display: flex; flex-direction: column; }
.field { display: grid; gap: 6px; margin-bottom: 13px; }
.field label { font-size: .78rem; font-weight: 700; color: #4f616d; }
.field input, .field select { width: 100%; padding: .72rem .78rem; border: 1px solid #cbd8df; border-radius: 10px; background: #fff; color: var(--ink); }
.field input:focus, .field select:focus { outline: 3px solid rgba(24,167,158,.18); border-color: var(--teal); }

.profile-box { margin-top: auto; padding: 16px; border-radius: 14px; background: var(--blue-soft); border: 1px solid #d4e7f2; }
.eyebrow { color: var(--teal); font-weight: 800; letter-spacing: .08em; font-size: .7rem; text-transform: uppercase; }
.profile-box h2 { margin: 4px 0 6px; font-size: 1.25rem; }
.profile-meta { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 14px 0 0; }
.profile-meta div { min-width: 0; }
.profile-meta dt { color: var(--muted); font-size: .72rem; }
.profile-meta dd { margin: 1px 0 0; font-weight: 750; }

.map-wrap { position: relative; min-height: 500px; overflow: hidden; background: linear-gradient(180deg, #dff1f5 0%, #eaf4f6 100%); border-radius: 0 0 18px 18px; }
#world-map { width: 100%; height: 500px; display: block; }
.country-shape { fill: #d3dde2; stroke: #fff; stroke-width: .65; vector-effect: non-scaling-stroke; cursor: pointer; transition: fill .14s, opacity .14s; }
.country-shape[data-status="adopted"] { fill: #5fbfa8; }
.country-shape[data-link="census"]:not([data-status="adopted"]),
.country-shape[data-link="un_census_reference"]:not([data-status="adopted"]) { fill: #8fb9cf; }
.country-shape:hover, .country-shape:focus { fill: #f4a340; outline: none; }
.country-shape.is-selected { fill: #e66c3d; stroke: #77270e; stroke-width: 1.7; }
.map-legend { position: absolute; left: 14px; bottom: 12px; display: flex; flex-wrap: wrap; gap: 10px; padding: 8px 10px; border-radius: 10px; background: rgba(255,255,255,.92); font-size: .7rem; }
.legend-item { display: flex; align-items: center; gap: 5px; }
.legend-dot { width: 11px; height: 11px; border-radius: 3px; background: #d3dde2; }
.legend-dot.adopted { background: #5fbfa8; }
.legend-dot.link { background: #8fb9cf; }
.legend-dot.selected { background: #e66c3d; }

.section { margin-top: 28px; }
.section-title { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin-bottom: 12px; }
.section-title h2 { margin: 0; font-size: 1.35rem; }
.section-title p { margin: 0; color: var(--muted); font-size: .83rem; }

.overview-heading { margin: 20px 0 10px; font-size: 1rem; color: var(--navy-2); }
.metrics-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-bottom: 22px; }
.overview-metric { padding: 18px 20px; border-top: 3px solid var(--teal); }
.metric-name { color: #415463; font-size: .84rem; }
.metric-value { margin: 8px 0; font-size: 1.8rem; font-weight: 750; line-height: 1.2; color: #103f60; overflow-wrap: anywhere; }
.metric-value small { margin-left: 8px; font-size: .75rem; font-weight: 400; color: var(--muted); }
.metric-unit { color: var(--muted); font-size: .74rem; }
.topic-sections { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); align-items: start; gap: 16px; }
.topic-section { min-width: 0; box-shadow: none; }
.topic-section:has(.meaningful-chart) { grid-column: 1 / -1; }
.topic-heading { padding: 12px 18px; background: #edf6fc; border-bottom: 1px solid var(--line); border-radius: 13px 13px 0 0; }
.topic-heading h3 { margin: 0; color: #15537b; font-size: .95rem; }
.topic-content { padding: 0 18px; }
.topic-section:has(.meaningful-chart) .topic-content { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.observation { min-width: 0; padding: 14px 0; border-bottom: 1px solid #e5edf2; break-inside: avoid; }
.observation:last-child { border-bottom: 0; }
.observation-main { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; }
.observation-label { font-size: .85rem; overflow-wrap: anywhere; }
.observation-meta { display: block; margin-top: 4px; color: var(--muted); font-size: .7rem; }
.observation-value { flex-shrink: 0; color: #164765; font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.observation-value small { font-size: .75rem; font-weight: 400; margin-left: 3px; }
.observation-evidence { margin-top: 7px; font-size: .73rem; color: var(--muted); }
.observation-evidence summary { cursor: pointer; width: fit-content; color: #386988; }
.observation-evidence > div { padding: 5px 0; overflow-wrap: anywhere; }
.observation-evidence p { margin: 5px 0; }
.metric-warning { padding: 6px 8px; font-size: .72rem; color: #7a4c00; background: #fff3d6; }
.meaningful-chart { margin: 0; padding: 18px 0; min-width: 0; }
.meaningful-chart h4 { font-size: 1rem; margin: 0; color: #15537b; }
.meaningful-chart figcaption p, .chart-note { font-size: .75rem; color: var(--muted); margin: 6px 0 16px; }
.composition-layout { display: grid; grid-template-columns: 150px minmax(0,1fr); gap: 20px; align-items: center; }
.composition-chart { width: 150px; height: 150px; }
.composition-chart text { fill: #173e5c; font-size: 14px; font-weight: 700; }
.composition-chart .donut-unit { font-size: 11px; fill: #708392; font-weight: 400; }
.composition-item { margin: 12px 0; }
.composition-item > div { display: flex; align-items: center; gap: 7px; font-size: .82rem; }
.composition-item strong { margin-left: auto; }
.color-key { display: inline-block; width: 10px; height: 10px; border-radius: 2px; flex: none; }
.trend-chart, .pyramid-chart { display: block; width: 100%; }
.trend-chart text, .pyramid-chart text { font-size: 12px; fill: #415463; }
.chart-axis { stroke: #b7c7d1; }
.pyramid-labels { display: flex; justify-content: space-around; font-size: .8rem; }
.empty-state { grid-column: 1 / -1; padding: 32px; text-align: center; color: var(--muted); background: #fff; border: 1px dashed #bfcdd5; border-radius: 14px; }

.source-layout { display: grid; grid-template-columns: 1.25fr .75fr; gap: 14px; }
.source-callout { padding: 20px; border-left: 5px solid var(--teal); }
.source-callout h3 { margin: 3px 0 8px; }
.source-callout p { color: var(--muted); }
.census-listings { display: grid; gap: 8px; margin-top: 14px; }
.census-listing { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #f7fbfd; color: var(--ink); line-height: 1.45; }
.census-listing a { color: var(--blue); font-weight: 700; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px; padding: .65rem .9rem; border: 0; border-radius: 9px; background: #1269a0; color: #fff; text-decoration: none; font-weight: 720; font-size: .82rem; cursor: pointer; }
.button:hover { background: #0b4f7b; color: #fff; }
.button.secondary { color: #17415d; background: #e8f1f6; }
.button.disabled { background: #e1e6e9; color: #798690; cursor: not-allowed; }

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(175px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { padding: 15px; }
.stat strong { display: block; font-size: 1.5rem; color: var(--navy-2); }
.stat span { color: var(--muted); font-size: .75rem; }

.toolbar { display: grid; grid-template-columns: minmax(220px, 1fr) repeat(2, minmax(150px, .35fr)); gap: 10px; margin-bottom: 14px; }
.toolbar input, .toolbar select { padding: .7rem .8rem; border-radius: 9px; border: 1px solid #cbd7de; background: #fff; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 14px; background: #fff; }
table { width: 100%; border-collapse: collapse; font-size: .82rem; }
th { position: sticky; top: 0; z-index: 1; padding: 11px 12px; text-align: left; color: #fff; background: var(--navy-2); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid #e5ebef; vertical-align: top; }
tbody tr:hover { background: #f2f8fa; }
.status { display: inline-flex; align-items: center; padding: .2rem .48rem; border-radius: 999px; font-size: .68rem; font-weight: 750; white-space: nowrap; }
.status.adopted { color: #0d6045; background: #dff4e8; }
.status.link { color: #155a7f; background: #e1f0f7; }
.status.missing { color: #746431; background: #f7f0d9; }
.status.failed { color: var(--red); background: #fae7e7; }
.pagination-note { margin: 10px 2px 0; color: var(--muted); font-size: .75rem; }
.link-stack { display: grid; gap: 4px; min-width: 180px; }
.link-stack span { color: var(--muted); }

.prose { max-width: 920px; }
.prose h2 { margin-top: 2rem; }
.prose li { margin-bottom: .45rem; }
.notice { padding: 16px 18px; border-radius: 12px; background: #fff6df; border: 1px solid #edd99c; color: #5d4b16; }

.site-footer { margin-top: 44px; padding: 28px; background: #082c46; color: #d6e4ec; }
.footer-inner { max-width: 1320px; margin: auto; display: flex; justify-content: space-between; gap: 20px; font-size: .76rem; }
.site-footer a { color: #fff; }

@media (max-width: 1000px) {
  .header-inner { flex-wrap: wrap; padding-top: 10px; }
  .brand { min-width: 0; flex: 1; }
  .main-nav { order: 3; flex: 0 0 100%; width: 100%; overflow-x: auto; }
  .main-nav a { min-height: 48px; white-space: nowrap; }
  .selection-layout, .source-layout { grid-template-columns: 1fr; }
  .topic-section:has(.meaningful-chart) .topic-content { grid-template-columns: 1fr; gap: 0; }
  .map-wrap, #world-map { min-height: 420px; height: 420px; }
}

@media (max-width: 640px) {
  .header-inner, main, .context-inner { padding-left: 16px; padding-right: 16px; }
  .brand span { display: none; }
  .brand strong { display: block; max-width: 145px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 1.05rem; }
  .header-inner { gap: 10px; }
  .main-nav a { padding: 0 12px; }
  .page-heading { display: block; }
  .coverage-chip { margin-top: 12px; }
  .metrics-grid, .stat-row, .topic-sections { grid-template-columns: 1fr; }
  .composition-layout { grid-template-columns: 110px minmax(0,1fr); gap: 12px; }
  .composition-chart { width: 110px; height: 110px; }
  .observation-main { gap: 10px; }
  .toolbar { grid-template-columns: 1fr; }
  .map-wrap, #world-map { min-height: 310px; height: 310px; }
  .footer-inner { display: block; }
}

@media print {
  .site-header, .context-bar, .toolbar, .site-footer, .actions { display: none !important; }
  body { background: #fff; }
  main { max-width: none; padding: 0; }
  .card { box-shadow: none; break-inside: avoid; }
  .topic-sections { display: block; }
  .topic-section { margin-bottom: 16px; }
  .observation-evidence > div { display: block !important; }
}
