:root {
  color-scheme: light;
  --ink: #12252c;
  --muted: #607077;
  --line: #d9e1e3;
  --paper: #ffffff;
  --wash: #edf2f3;
  --deep: #0a3542;
  --accent: #d8f25c;
  --missing: #101417;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    linear-gradient(120deg, rgba(216, 242, 92, 0.17), transparent 26rem),
    var(--wash);
}

button, input, select { font: inherit; }

.shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 22px clamp(16px, 3vw, 44px) 28px;
}

.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 15px 4px 15px 4px;
  color: var(--accent);
  background: var(--deep);
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

h1, h2, h3, p { margin-top: 0; }

h1 {
  margin-bottom: 0;
  font-size: clamp(1.45rem, 2.5vw, 2.3rem);
  line-height: 1.08;
  letter-spacing: -0.045em;
}

h2 {
  margin-bottom: 0;
  font-size: clamp(1.2rem, 1.8vw, 1.55rem);
  line-height: 1.2;
  letter-spacing: -0.025em;
}

h3 {
  margin-bottom: 10px;
  font-size: 0.83rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.eyebrow {
  margin-bottom: 5px;
  color: #587079;
  font-size: 0.73rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.source-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 650;
}

.controls {
  display: grid;
  grid-template-columns: minmax(250px, 1.35fr) minmax(220px, 1fr) minmax(150px, 0.55fr) minmax(250px, 1fr);
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 18px 18px 5px 18px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 14px 45px rgba(10, 53, 66, 0.07);
  backdrop-filter: blur(12px);
}

[hidden] { display: none !important; }

.control {
  display: grid;
  gap: 7px;
  min-width: 0;
  color: #4f6168;
  font-size: 0.8rem;
  font-weight: 750;
}

.control select {
  width: 100%;
  min-height: 45px;
  padding: 0 40px 0 13px;
  border: 1px solid #cbd6d9;
  border-radius: 10px;
  color: var(--ink);
  background: #fff;
  font-size: 0.94rem;
  font-weight: 650;
}

.control select:focus-visible,
.control input:focus-visible,
.country:focus-visible {
  outline: 3px solid rgba(10, 104, 126, 0.28);
  outline-offset: 2px;
}

.year-control > span:first-child {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

#year-output {
  min-width: 55px;
  padding: 3px 8px;
  border-radius: 8px;
  color: var(--accent);
  background: var(--deep);
  text-align: center;
  font-weight: 850;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--deep);
}

.year-bounds {
  display: flex;
  justify-content: space-between;
  color: #718187;
  font-size: 0.72rem;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 290px;
  gap: 14px;
  margin-top: 14px;
}

.map-card,
.summary-card {
  border: 1px solid var(--line);
  background: var(--paper);
  box-shadow: 0 16px 48px rgba(10, 53, 66, 0.08);
}

.map-card {
  min-width: 0;
  padding: clamp(16px, 2.4vw, 28px);
  border-radius: 22px 6px 22px 22px;
}

.map-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.coverage-pill {
  padding: 7px 10px;
  border-radius: 999px;
  color: var(--deep);
  background: #eef6c9;
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

.map-wrap {
  position: relative;
  min-height: 520px;
  margin-top: 8px;
  overflow: hidden;
  border-radius: 16px;
  background:
    radial-gradient(circle at 45% 42%, #f7fafb 0 18rem, transparent 36rem),
    #e9f1f3;
}

#map {
  display: block;
  width: 100%;
  height: 540px;
}

.country {
  cursor: crosshair;
  stroke: #fff;
  stroke-width: 0.9;
  vector-effect: non-scaling-stroke;
  transition: fill 180ms ease, filter 180ms ease, stroke-width 180ms ease;
}

.country:hover,
.country:focus-visible {
  filter: brightness(1.08) drop-shadow(0 3px 4px rgba(3, 27, 34, 0.28));
  stroke: var(--accent);
  stroke-width: 2;
}

.tooltip {
  position: absolute;
  z-index: 5;
  min-width: 210px;
  max-width: 270px;
  padding: 13px 14px;
  border: 1px solid rgba(216, 242, 92, 0.6);
  border-radius: 12px 12px 12px 3px;
  color: #fff;
  background: rgba(7, 35, 43, 0.96);
  box-shadow: 0 16px 36px rgba(4, 24, 30, 0.25);
  pointer-events: none;
}

.tooltip strong {
  display: block;
  margin-bottom: 5px;
  font-size: 1rem;
}

.tooltip .value {
  color: var(--accent);
  font-size: 1.35rem;
  font-weight: 850;
}

.tooltip small {
  display: block;
  margin-top: 6px;
  color: #c6d5d9;
  font-size: 0.72rem;
  line-height: 1.35;
}

.legend {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
  color: #65777e;
  font-size: 0.76rem;
  font-weight: 700;
}

.gradient {
  width: min(210px, 34vw);
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(90deg, #d8f0f2, #5aafb5, #075568, #042e3a);
}

.missing-swatch {
  width: 13px;
  height: 13px;
  margin-left: 10px;
  border-radius: 3px;
  background: var(--missing);
}

.summary-card {
  display: flex;
  flex-direction: column;
  padding: 24px 22px;
  border-radius: 6px 22px 22px 22px;
}

.summary-card > h2 {
  font-size: 2.6rem;
  color: var(--deep);
}

.summary-metric {
  display: grid;
  gap: 2px;
  margin: 18px 0 24px;
  padding: 16px;
  border-radius: 14px 14px 4px 14px;
  background: var(--deep);
}

.summary-metric strong {
  color: var(--accent);
  font-size: 2rem;
  letter-spacing: -0.04em;
}

.summary-metric span {
  color: #d6e1e4;
  font-size: 0.78rem;
  line-height: 1.35;
}

.summary-block {
  padding: 18px 0;
  border-top: 1px solid var(--line);
}

.summary-block.compact p { margin-bottom: 0; }

.indicator-info p {
  margin-bottom: 9px;
  color: #66777d;
  font-size: 0.78rem;
  line-height: 1.48;
}

.indicator-code {
  display: inline-block;
  padding: 4px 7px;
  border-radius: 6px;
  color: var(--deep) !important;
  background: #edf2f3;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-weight: 750;
}

.analysis-card {
  margin-top: 14px;
  padding: clamp(16px, 2.4vw, 28px);
  border: 1px solid var(--line);
  border-radius: 6px 22px 22px 22px;
  background: var(--paper);
  box-shadow: 0 16px 48px rgba(10, 53, 66, 0.08);
}

.analysis-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
}

.analysis-heading > p {
  max-width: 420px;
  margin: 0;
  color: #5d6f76;
  font-size: 0.82rem;
  line-height: 1.45;
  text-align: right;
}

.scatter-wrap {
  position: relative;
  min-height: 410px;
  margin-top: 12px;
}

#scatter {
  display: block;
  width: 100%;
  height: 410px;
}

.scatter-frame { fill: #f7fafb; stroke: #d9e1e3; }
.scatter-grid line { stroke: #dce5e7; stroke-width: 1; }
.scatter-grid path { display: none; }
.scatter-axis text { fill: #65777e; font-size: 12px; }
.scatter-axis path, .scatter-axis line { stroke: #9babb0; }
.scatter-point { fill: var(--deep); stroke: var(--accent); stroke-width: 1.5; opacity: 0.88; }
.scatter-point:hover { fill: #116f82; stroke-width: 2.5; }
.axis-label { fill: var(--ink); font-size: 13px; font-weight: 700; }

.analysis-caveat {
  margin: 4px 0 0;
  color: #718086;
  font-size: 0.78rem;
  line-height: 1.5;
}

.model-section,
.correlation-section {
  margin-top: 28px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

.model-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 14px;
}

.model-heading > p {
  max-width: 470px;
  margin: 0;
  color: #5d6f76;
  font-size: 0.82rem;
  line-height: 1.45;
  text-align: right;
}

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.results-table,
.nested-model-table,
.correlation-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  font-size: 0.84rem;
}

.results-table th,
.results-table td,
.nested-model-table th,
.nested-model-table td,
.correlation-table th,
.correlation-table td {
  padding: 11px 13px;
  border-bottom: 1px solid #e5ebed;
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.results-table th,
.nested-model-table th,
.correlation-table th {
  color: #586b72;
  background: #f4f7f8;
  font-size: 0.73rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.correlation-table th:first-child,
.nested-model-table th:first-child,
.nested-model-table td:first-child,
.correlation-table th:nth-child(2),
.correlation-table td:first-child,
.correlation-table td:nth-child(2) {
  text-align: left;
}

.results-table tbody tr:last-child td,
.nested-model-table tbody tr:last-child td,
.correlation-table tbody tr:last-child td { border-bottom: 0; }

.results-table td:first-child {
  color: var(--deep);
  font-size: 1.05rem;
  font-weight: 850;
}

.correlation-table tbody tr.is-active {
  background: #f3f8d9;
}

.correlation-table td:first-child { font-weight: 750; }
.correlation-table td:nth-child(2) { color: #65777e; }

.model-definitions {
  display: grid;
  gap: 7px;
  margin: 0 0 14px;
  padding-left: 20px;
  color: #52666d;
  font-size: 0.82rem;
  line-height: 1.5;
}

.nested-model-table th:first-child,
.nested-model-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  min-width: 175px;
  background: #fff;
  text-align: left;
}

.nested-model-table th:first-child {
  z-index: 2;
  background: #f4f7f8;
}

.nested-model-table td {
  min-width: 180px;
  vertical-align: top;
}

.nested-model-table td:first-child { font-weight: 750; }
.nested-model-table .estimate-value { color: var(--deep); font-weight: 800; }
.nested-model-table .estimate-detail { display: block; margin-top: 3px; color: #6b7b81; font-size: 0.73rem; }
.nested-model-table td.is-clear { background: #f3f8d9; }
.nested-model-table .not-in-model { color: #9aa6aa; text-align: center; }
.nested-model-table .sample-row td { background: #f8fafb; color: #52666d; font-size: 0.76rem; }
.nested-model-table .sample-row td:first-child { background: #f8fafb; }

.model-interpretation {
  margin: 14px 0 7px;
  color: var(--deep);
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.5;
}

.model-robustness {
  margin: 0 0 8px;
  color: #52666d;
  font-size: 0.8rem;
  line-height: 1.5;
}

#ranking {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: rank;
}

#ranking li {
  counter-increment: rank;
  display: grid;
  grid-template-columns: 22px 1fr auto;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
}

#ranking li::before {
  content: counter(rank, decimal-leading-zero);
  color: #839298;
  font-size: 0.7rem;
  font-weight: 800;
}

#ranking b { color: var(--deep); }

.method-note {
  margin: auto 0 0;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  color: #6d7c82;
  font-size: 0.77rem;
  line-height: 1.5;
}

footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 4px 0;
  color: #67787e;
  font-size: 0.77rem;
}

footer p { margin-bottom: 0; }
footer a { color: var(--deep); font-weight: 800; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 980px) {
  .controls { grid-template-columns: 1fr 1fr; }
  .indicator-control { grid-column: 1 / -1; }
  .year-control { grid-column: 1 / -1; }
  .workspace { grid-template-columns: 1fr; }
  .summary-card { min-height: 0; }
  .method-note { margin-top: 8px; }
}

@media (max-width: 640px) {
  .shell { padding: 14px 12px 24px; }
  .topbar { grid-template-columns: auto 1fr; }
  .source-note { display: none; }
  .brand-mark { width: 46px; height: 46px; }
  .controls { grid-template-columns: 1fr; }
  .year-control { grid-column: auto; }
  .indicator-control { grid-column: auto; }
  .map-heading { display: grid; }
  .coverage-pill { justify-self: start; }
  .map-wrap { min-height: 430px; }
  #map { height: 450px; }
  .legend { flex-wrap: wrap; justify-content: flex-start; }
  .gradient { width: 52vw; }
  footer { display: grid; }
  .analysis-heading { display: grid; }
  .analysis-heading > p { text-align: left; }
  .model-heading { display: grid; }
  .model-heading > p { text-align: left; }
  .scatter-wrap { min-height: 360px; }
  #scatter { height: 360px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
