:root {
  --paper: #f4efe6;
  --surface: #fffdf8;
  --ink: #211f1b;
  --muted: #665f55;
  --faint: #6f675d;
  --rule: #cfc5b6;
  --blue: #1d508c;
  --blue-dark: #153c69;
  --red: #a42222;
  --focus: #005fcc;
  --shadow: 0 16px 44px rgba(55, 45, 28, 0.12);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 300px;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, system-ui, -apple-system, sans-serif;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--blue); }
a:hover { color: var(--blue-dark); }
button, input, select { font: inherit; }
button, select { cursor: pointer; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

.skip-link {
  position: fixed; z-index: 100; top: 10px; left: 10px;
  transform: translateY(-180%); padding: 10px 14px; border-radius: 6px;
  background: var(--ink); color: white;
}
.skip-link:focus { transform: none; }

.site-header {
  min-height: 62px; padding: 0 24px; border-bottom: 1px solid var(--rule);
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  background: color-mix(in srgb, var(--paper) 94%, white);
}
.wordmark {
  color: var(--ink); font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 24px; font-weight: 600; letter-spacing: 0.06em; text-decoration: none;
}
.site-header nav { display: flex; gap: 18px; flex-wrap: wrap; }
.site-header nav a { color: var(--muted); font-size: 13px; font-weight: 600; text-decoration: none; }
.site-header nav a:hover { color: var(--ink); text-decoration: underline; }

.intro { max-width: 1180px; margin: 0 auto; padding: 58px 24px 34px; }
.eyebrow {
  margin: 0 0 5px; color: var(--red); font-size: 11px; font-weight: 700;
  letter-spacing: 0.14em; text-transform: uppercase;
}
h1, h2, h3 { color: var(--ink); }
h1, .sources > h2, dialog h2 { font-family: "Cormorant Garamond", Georgia, serif; }
h1 {
  margin: 0; max-width: 760px; font-size: clamp(40px, 7vw, 70px);
  font-weight: 500; letter-spacing: -0.025em; line-height: 0.98;
}
.intro > p:not(.eyebrow) {
  max-width: 760px; margin: 22px 0 0; color: var(--muted);
  font-size: 17px; line-height: 1.65;
}
.dataset-stats { display: flex; flex-wrap: wrap; gap: 12px 28px; margin: 30px 0 0; }
.dataset-stats div { display: grid; gap: 0; }
.dataset-stats dt { color: var(--faint); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; }
.dataset-stats dd { margin: 0; font-family: "Cormorant Garamond", Georgia, serif; font-size: 28px; font-weight: 600; }
.load-status { max-width: 1180px; margin: 0 auto 42px; padding: 14px 24px; color: var(--muted); }
.load-status.error { color: #781b1b; font-weight: 600; }

.workspace {
  max-width: 1440px; margin: 0 auto; padding: 0 24px 56px;
  display: grid; grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
  gap: 24px; align-items: start;
}
.filters, .results {
  border: 1px solid var(--rule); border-radius: 12px; background: var(--surface);
  box-shadow: 0 5px 18px rgba(55, 45, 28, 0.05);
}
.filters { position: sticky; top: 18px; padding: 20px; display: grid; gap: 7px; }
.filter-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.filter-head h2 { margin: 0 0 8px; font-size: 16px; }
.text-button { border: 0; background: transparent; color: var(--blue); padding: 6px; font-size: 12px; }
.text-button:hover { text-decoration: underline; }
.filters label, .map-toolbar label {
  margin-top: 8px; color: var(--muted); font-size: 12px; font-weight: 700;
}
input, select {
  width: 100%; min-height: 44px; border: 1px solid var(--rule); border-radius: 7px;
  background: white; color: var(--ink); padding: 9px 10px;
}
.download-button {
  min-height: 44px; margin-top: 13px; border: 1px solid var(--blue); border-radius: 7px;
  background: var(--blue); color: white; font-weight: 700;
}
.download-button:hover { background: var(--blue-dark); }
.filter-note { margin: 10px 0 0; color: var(--faint); font-size: 11px; line-height: 1.5; }

.results { min-width: 0; overflow: hidden; }
.result-head {
  padding: 20px 22px; display: flex; justify-content: space-between; align-items: end;
  gap: 18px; border-bottom: 1px solid var(--rule);
}
.result-head h2 { margin: 0; font-family: "Cormorant Garamond", Georgia, serif; font-size: 30px; }
.result-summary { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.word-bridge {
  margin: 18px 22px 0; padding: 16px 18px; border: 1px solid #bdad93;
  border-radius: 9px; background: #f7eddb; display: flex;
  align-items: center; justify-content: space-between; gap: 22px;
}
.word-bridge[hidden] { display: none; }
.word-bridge h3 { margin: 0; font-family: "Cormorant Garamond", Georgia, serif; font-size: 22px; }
.word-bridge p:not(.eyebrow) { max-width: 680px; margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.word-bridge > a {
  flex: 0 0 auto; padding: 9px 11px; border: 1px solid var(--blue); border-radius: 7px;
  font-size: 12px; font-weight: 700; text-decoration: none;
}
.view-switch {
  display: inline-flex; padding: 3px; border: 1px solid var(--rule); border-radius: 9px;
  background: var(--paper);
}
.view-switch button {
  min-height: 38px; border: 0; border-radius: 6px; background: transparent;
  color: var(--muted); padding: 7px 12px; font-weight: 700;
}
.view-switch button[aria-pressed="true"] { background: var(--ink); color: white; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  padding: 10px 14px; border-bottom: 1px solid var(--rule); background: var(--paper);
  color: var(--muted); font-size: 10px; letter-spacing: 0.08em; text-align: left;
  text-transform: uppercase; white-space: nowrap;
}
td { padding: 12px 14px; border-bottom: 1px solid color-mix(in srgb, var(--rule) 70%, white); vertical-align: top; }
tbody tr:hover { background: #f8f4ec; }
.empty-result { padding: 36px 14px; color: var(--muted); text-align: center; }
.record-button, .country-button {
  border: 0; background: transparent; color: var(--blue); padding: 0; text-align: left;
  font-weight: 700; text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--blue) 35%, transparent); text-underline-offset: 3px;
}
.code { display: block; margin-top: 2px; color: var(--faint); font: 11px ui-monospace, SFMono-Regular, Menlo, monospace; }
.subcell { display: block; margin-top: 2px; color: var(--faint); font-size: 11px; }
.missing { color: var(--faint); font-style: italic; }
.pagination {
  min-height: 62px; padding: 12px 18px; display: flex; justify-content: space-between;
  align-items: center; gap: 12px;
}
.pagination button {
  min-width: 44px; min-height: 40px; border: 1px solid var(--rule); border-radius: 7px;
  background: white; color: var(--ink);
}
.pagination button:disabled { cursor: default; opacity: 0.45; }
.pagination span { color: var(--muted); font-size: 12px; }

.map-toolbar {
  padding: 20px 22px 0; display: flex; justify-content: space-between;
  gap: 20px; align-items: end;
}
.map-toolbar h3, .country-summary h3 { margin: 0; font-size: 17px; }
.map-toolbar p, .country-summary p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.map-toolbar > div:last-child { width: min(240px, 45%); }
.map-toolbar label { display: block; margin: 0 0 4px; }
.map-figure { margin: 0; padding: 8px 18px 20px; }
#country-map { display: block; width: 100%; height: auto; border-radius: 8px; background: #e8eef0; }
.country-shape { stroke: #fffdf8; stroke-width: 0.7; vector-effect: non-scaling-stroke; }
.country-shape:hover { stroke: var(--ink); stroke-width: 1.5; }
.map-figure figcaption {
  min-height: 32px; display: flex; justify-content: space-between; gap: 14px;
  color: var(--muted); font-size: 11px;
}
.legend { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.legend i { width: 20px; height: 9px; display: inline-block; }
.country-summary { padding: 0 22px 22px; }
.compact { margin-top: 10px; max-height: 420px; border: 1px solid var(--rule); border-radius: 7px; }
.compact th { position: sticky; top: 0; }
.compact td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.map-tip {
  position: fixed; z-index: 50; max-width: 260px; display: none; padding: 9px 11px;
  border: 1px solid var(--rule); border-radius: 6px; background: var(--surface);
  color: var(--ink); box-shadow: var(--shadow); font-size: 12px; pointer-events: none;
}
.map-tip.show { display: block; }
.map-tip strong { display: block; margin-bottom: 2px; }

.sources { max-width: 1180px; margin: 0 auto; padding: 20px 24px 70px; }
.sources > h2 { margin: 0; font-size: 38px; font-weight: 500; }
.source-grid { margin-top: 20px; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.source-grid article { padding: 17px; border-top: 2px solid var(--ink); background: color-mix(in srgb, white 35%, var(--paper)); }
.source-grid h3 { margin: 0; font-family: "Cormorant Garamond", Georgia, serif; font-size: 20px; }
.source-grid p, .method-note { color: var(--muted); font-size: 12px; line-height: 1.6; }
.method-note { margin: 18px 0 0; }

dialog {
  width: min(620px, calc(100% - 32px)); max-height: min(760px, calc(100dvh - 40px));
  padding: 0; border: 1px solid var(--rule); border-radius: 12px;
  overflow: auto; background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(32, 27, 20, 0.55); }
.dialog-head {
  padding: 22px; border-bottom: 1px solid var(--rule); display: flex;
  justify-content: space-between; align-items: start; gap: 18px;
}
.dialog-head h2 { margin: 0; font-size: 36px; line-height: 1; }
.dialog-codes { margin: 7px 0 0; color: var(--faint); font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; }
.dialog-close {
  width: 44px; height: 44px; border: 1px solid var(--rule); border-radius: 50%;
  background: white; color: var(--ink); font-size: 25px; line-height: 1;
}
.record-fields { padding: 8px 22px; display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; }
.record-fields div { padding: 12px 0; border-bottom: 1px solid var(--rule); }
.record-fields dt { color: var(--faint); font-size: 10px; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase; }
.record-fields dd { margin: 4px 0 0; font-size: 14px; }
.dialog-actions { padding: 18px 22px 22px; display: flex; flex-wrap: wrap; gap: 10px; }
.dialog-actions a {
  min-height: 42px; padding: 10px 13px; border: 1px solid var(--blue);
  border-radius: 7px; text-decoration: none; font-size: 13px; font-weight: 700;
}
.dialog-actions a:first-child { background: var(--blue); color: white; }
footer { padding: 28px 24px 40px; border-top: 1px solid var(--rule); color: var(--faint); text-align: center; font-size: 12px; }
footer a { color: var(--muted); text-decoration: none; }
footer a:hover { text-decoration: underline; }

@media (max-width: 980px) {
  .workspace { grid-template-columns: 1fr; }
  .filters { position: static; grid-template-columns: 1fr 1fr; column-gap: 16px; }
  .filter-head, .filters .download-button, .filter-note { grid-column: 1 / -1; }
  .source-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 680px) {
  .site-header { padding: 12px 16px; align-items: flex-start; flex-direction: column; gap: 5px; }
  .site-header nav { gap: 14px; }
  .intro { padding: 42px 18px 28px; }
  .workspace { padding: 0 12px 44px; }
  .filters { grid-template-columns: 1fr; }
  .filter-head, .filters .download-button, .filter-note { grid-column: auto; }
  .result-head, .map-toolbar { align-items: stretch; flex-direction: column; }
  .word-bridge { margin: 14px 12px 0; align-items: stretch; flex-direction: column; gap: 12px; }
  .view-switch { width: 100%; }
  .view-switch button { flex: 1; }
  .map-toolbar > div:last-child { width: 100%; }
  th:nth-child(3), td:nth-child(3), th:nth-child(5), td:nth-child(5) { display: none; }
  .source-grid { grid-template-columns: 1fr; }
  .record-fields { grid-template-columns: 1fr; }
  .map-figure figcaption { flex-direction: column; }
}
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
@media (forced-colors: active) {
  .view-switch button[aria-pressed="true"], .download-button { border: 2px solid ButtonText; }
  .country-shape { fill: Canvas !important; stroke: CanvasText; }
}
