/* ===========================================================================
   Etymology Maps — proof of concept
   Palette: cool indigo "antiquarian atlas", warm brass accent.
   Light + dark via tokens. Product register, editorial serif for the content.
   =========================================================================== */

:root {
  /* --- Brand + neutral (light) --- */
  --bg:        oklch(1 0 0);
  --surface:   oklch(0.975 0.004 255);
  --surface-2: oklch(0.955 0.006 255);
  --ink:       oklch(0.24 0.028 258);
  --muted:     oklch(0.50 0.02 258);
  --faint:     oklch(0.70 0.015 258);
  --line:      oklch(0.90 0.008 258);
  --line-strong: oklch(0.82 0.012 258);

  --primary:        oklch(0.46 0.11 250);
  --primary-ink:    oklch(0.99 0.004 255);   /* text on primary */
  --primary-soft:   oklch(0.95 0.02 250);    /* tinted fill */
  --primary-hover:  oklch(0.40 0.11 250);

  --accent:         oklch(0.70 0.13 70);     /* brass */
  --accent-ink:     oklch(0.26 0.05 70);

  /* --- Confidence (encoded by color AND shape in markup) --- */
  --conf-documented: oklch(0.52 0.10 168);
  --conf-inferred:   oklch(0.64 0.13 78);
  --conf-debated:    oklch(0.57 0.15 24);
  --conf-documented-soft: oklch(0.95 0.03 168);
  --conf-inferred-soft:   oklch(0.95 0.045 85);
  --conf-debated-soft:    oklch(0.95 0.035 24);

  /* --- Layer tag hues --- */
  --layer-celtic:  oklch(0.56 0.14 150);
  --layer-roman:   oklch(0.56 0.18 25);
  --layer-english: oklch(0.52 0.15 255);
  --layer-greek:   oklch(0.56 0.13 340);
  --layer-norse:   oklch(0.52 0.15 305);
  --layer-norman:  oklch(0.64 0.15 65);

  /* --- Shape --- */
  --radius-sm: 7px;
  --radius:    11px;
  --radius-lg: 16px;
  --shadow-1: 0 1px 2px oklch(0.24 0.03 258 / 0.06), 0 1px 1px oklch(0.24 0.03 258 / 0.04);
  --shadow-2: 0 4px 14px oklch(0.24 0.03 258 / 0.10), 0 2px 5px oklch(0.24 0.03 258 / 0.06);
  --shadow-3: 0 14px 40px oklch(0.2 0.03 258 / 0.22), 0 4px 12px oklch(0.2 0.03 258 / 0.12);

  /* --- Type --- */
  --font-serif: "Fjord One", Georgia, "Times New Roman", serif;
  --font-sans:  "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  /* --- Z scale --- */
  --z-toolbar: 10;
  --z-card: 20;
  --z-backdrop: 1050;
  --z-sheet: 1060;
  --z-popover: 1100;
  --z-banner: 1200;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --dur: 200ms;

  --tile-filter: none;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg:        oklch(0.17 0.016 258);
  --surface:   oklch(0.215 0.018 258);
  --surface-2: oklch(0.255 0.02 258);
  --ink:       oklch(0.94 0.008 255);
  --muted:     oklch(0.72 0.016 255);
  --faint:     oklch(0.56 0.018 255);
  --line:      oklch(0.33 0.02 258);
  --line-strong: oklch(0.42 0.022 258);

  --primary:       oklch(0.72 0.12 248);
  --primary-ink:   oklch(0.17 0.02 258);
  --primary-soft:  oklch(0.30 0.05 250);
  --primary-hover: oklch(0.78 0.12 248);

  --accent:        oklch(0.78 0.13 72);
  --accent-ink:    oklch(0.22 0.05 72);

  --conf-documented: oklch(0.74 0.12 168);
  --conf-inferred:   oklch(0.80 0.13 85);
  --conf-debated:    oklch(0.72 0.15 26);
  --conf-documented-soft: oklch(0.32 0.05 168);
  --conf-inferred-soft:   oklch(0.34 0.06 85);
  --conf-debated-soft:    oklch(0.33 0.06 26);

  --layer-celtic:  oklch(0.74 0.14 150);
  --layer-roman:   oklch(0.72 0.16 25);
  --layer-english: oklch(0.72 0.13 255);
  --layer-greek:   oklch(0.74 0.12 340);
  --layer-norse:   oklch(0.72 0.14 305);
  --layer-norman:  oklch(0.78 0.14 68);

  --shadow-1: 0 1px 2px oklch(0 0 0 / 0.4);
  --shadow-2: 0 4px 14px oklch(0 0 0 / 0.5);
  --shadow-3: 0 16px 44px oklch(0 0 0 / 0.6);

  /* Darken the light OSM raster tiles to sit in a dark UI, keep labels legible */
  --tile-filter: invert(1) hue-rotate(180deg) brightness(0.92) contrast(0.9) saturate(0.8);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:        oklch(0.17 0.016 258);
    --surface:   oklch(0.215 0.018 258);
    --surface-2: oklch(0.255 0.02 258);
    --ink:       oklch(0.94 0.008 255);
    --muted:     oklch(0.72 0.016 255);
    --faint:     oklch(0.56 0.018 255);
    --line:      oklch(0.33 0.02 258);
    --line-strong: oklch(0.42 0.022 258);
    --primary:       oklch(0.72 0.12 248);
    --primary-ink:   oklch(0.17 0.02 258);
    --primary-soft:  oklch(0.30 0.05 250);
    --primary-hover: oklch(0.78 0.12 248);
    --accent:        oklch(0.78 0.13 72);
    --accent-ink:    oklch(0.22 0.05 72);
    --conf-documented: oklch(0.74 0.12 168);
    --conf-inferred:   oklch(0.80 0.13 85);
    --conf-debated:    oklch(0.72 0.15 26);
    --conf-documented-soft: oklch(0.32 0.05 168);
    --conf-inferred-soft:   oklch(0.34 0.06 85);
    --conf-debated-soft:    oklch(0.33 0.06 26);
    --layer-celtic:  oklch(0.74 0.14 150);
    --layer-roman:   oklch(0.72 0.16 25);
    --layer-english: oklch(0.72 0.13 255);
    --layer-greek:   oklch(0.74 0.12 340);
    --layer-norse:   oklch(0.72 0.14 305);
    --layer-norman:  oklch(0.78 0.14 68);
    --shadow-1: 0 1px 2px oklch(0 0 0 / 0.4);
    --shadow-2: 0 4px 14px oklch(0 0 0 / 0.5);
    --shadow-3: 0 16px 44px oklch(0 0 0 / 0.6);
    --tile-filter: invert(1) hue-rotate(180deg) brightness(0.92) contrast(0.9) saturate(0.8);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-synthesis-weight: none; /* Fjord One ships one weight; never fake bold */
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

a { color: var(--primary); }
a:focus-visible,
button:focus-visible,
input:focus-visible,
[tabindex]:focus-visible,
.term:focus-visible {
  outline: 2.5px solid var(--primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

h1, h2, h3 { font-family: var(--font-serif); font-weight: 560; line-height: 1.12; letter-spacing: -0.015em; text-wrap: balance; margin: 0; }

.btn {
  font: inherit;
  font-weight: 500;
  font-size: 0.9rem;
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn[aria-pressed="true"] { background: var(--primary-soft); border-color: var(--primary); color: var(--ink); }
.btn-icon { padding: 0.5rem; }

/* ---------- Header ---------- */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem clamp(0.9rem, 3vw, 1.6rem);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.wordmark { display: flex; align-items: baseline; gap: 0.6rem; min-width: 0; }
.wordmark .mark {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 1.22rem;
  letter-spacing: -0.02em;
  color: var(--ink);
  white-space: nowrap;
}
.wordmark .mark .emphasis { color: var(--primary); font-style: italic; }
.wordmark .tag {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-actions { display: flex; align-items: center; gap: 0.5rem; }

/* ---------- Hero / thesis ---------- */
.hero {
  padding: clamp(1rem, 3vw, 1.6rem) clamp(0.9rem, 3vw, 1.6rem);
  background:
    radial-gradient(120% 140% at 100% 0%, var(--primary-soft) 0%, transparent 55%),
    var(--bg);
  border-bottom: 1px solid var(--line);
}
.hero-inner { max-width: 64ch; }
.hero p.thesis {
  font-family: var(--font-serif);
  font-size: clamp(1.15rem, 0.95rem + 1.1vw, 1.6rem);
  line-height: 1.26;
  letter-spacing: -0.012em;
  margin: 0 0 0.5rem;
  text-wrap: balance;
  max-width: 68ch;
}
.hero p.thesis .emphasis { color: var(--primary); }
.hero p.prompt { margin: 0; color: var(--muted); font-size: 0.95rem; }

/* ---------- Toolbar ---------- */
.toolbar {
  position: relative;
  z-index: var(--z-toolbar);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem 1.4rem;
  padding: 0.75rem clamp(0.9rem, 3vw, 1.6rem);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.tool-group { display: flex; flex-direction: column; gap: 0.35rem; min-width: 0; }
.tool-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--faint);
}

/* Timeline slider */
.timeline { flex: 1 1 320px; min-width: 260px; }
.timeline-head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.6rem; }
.timeline-year { font-family: var(--font-serif); font-weight: 600; font-size: 1.05rem; color: var(--primary); }
.timeline-caption { color: var(--muted); font-size: 0.85rem; margin: 0.2rem 0 0; min-height: 1.1em; }
input[type="range"].slider {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 26px; background: transparent; cursor: pointer; margin: 0.15rem 0 0;
}
input[type="range"].slider::-webkit-slider-runnable-track {
  height: 4px; border-radius: 999px;
  background: linear-gradient(to right, var(--primary) var(--fill, 0%), var(--line-strong) var(--fill, 0%));
}
input[type="range"].slider::-moz-range-track { height: 4px; border-radius: 999px; background: var(--line-strong); }
input[type="range"].slider::-moz-range-progress { height: 4px; border-radius: 999px; background: var(--primary); }
input[type="range"].slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 18px; height: 18px; margin-top: -7px; border-radius: 50%;
  background: var(--primary); border: 3px solid var(--bg); box-shadow: var(--shadow-1);
  transition: transform var(--dur) var(--ease);
}
input[type="range"].slider::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--primary); border: 3px solid var(--bg); box-shadow: var(--shadow-1);
}
input[type="range"].slider:hover::-webkit-slider-thumb { transform: scale(1.12); }
.timeline-ticks { display: flex; justify-content: space-between; margin-top: 0.3rem; }
.timeline-ticks button {
  font: inherit; font-size: 0.72rem; color: var(--muted);
  background: none; border: none; padding: 0.1rem 0.2rem; cursor: pointer; border-radius: var(--radius-sm);
}
.timeline-ticks button[aria-current="true"] { color: var(--primary); font-weight: 600; }
.timeline-ticks button:hover { color: var(--ink); }

/* Layer filter chips */
.filters { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip {
  font: inherit; font-size: 0.83rem; font-weight: 500;
  display: inline-flex; align-items: center; gap: 0.4em;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: all var(--dur) var(--ease);
}
.chip .swatch { width: 9px; height: 9px; border-radius: 50%; background: var(--chip-color, var(--muted)); flex: none; }
.chip[aria-pressed="true"] { color: var(--ink); background: var(--surface-2); border-color: var(--chip-color, var(--line-strong)); }
.chip[aria-pressed="false"] { opacity: 0.6; }
.chip[aria-pressed="false"] .swatch { background: var(--faint); }

/* ---------- Main / map + card ---------- */
.workspace {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 1fr minmax(320px, 400px);
  min-height: 0;
}
.workspace.no-selection { grid-template-columns: 1fr minmax(320px, 400px); }

#map {
  min-height: min(72vh, 680px);
  height: 100%;
  background: var(--surface-2);
  z-index: 0;
}
.leaflet-tile-pane { filter: var(--tile-filter); }
.leaflet-container { font-family: var(--font-sans); background: var(--surface-2); }
.leaflet-bar a, .leaflet-bar a:hover { background: var(--surface); color: var(--ink); border-color: var(--line); }
.leaflet-control-attribution { background: var(--surface) !important; color: var(--muted) !important; font-size: 0.68rem; }
.leaflet-control-attribution a { color: var(--primary) !important; }

/* Language territories. Colours reuse the layer-tag hues so chips, tags and
   map areas all match. Semi-transparent fills let overlaps stack visibly. */
.lang-gaulish   { --c: var(--layer-celtic); --fo: 0.38; }
.lang-brittonic { --c: color-mix(in oklch, var(--layer-celtic) 55%, oklch(0.6 0.12 200)); --fo: 0.36; }
.lang-gaelic    { --c: color-mix(in oklch, var(--layer-celtic) 55%, oklch(0.68 0.15 105)); --fo: 0.38; }
.lang-roman     { --c: var(--layer-roman);   --fo: 0.34; }
.lang-anglo     { --c: var(--layer-english); --fo: 0.34; }
.lang-norse     { --c: var(--layer-norse);   --fo: 0.40; }
.lang-norman    { --c: var(--layer-norman);  --fo: 0.10; }
path.lang {
  fill: var(--c); fill-opacity: var(--fo, 0.4);
  stroke: var(--c); stroke-opacity: 0.95; stroke-width: 2;
  animation: lang-in 450ms var(--ease) both;
}
/* Norman rule is a ruling layer over land already spoken for, so it reads as a
   dashed outline with a faint tint rather than another solid fill. */
path.lang-norman { stroke-width: 3; stroke-dasharray: 8 6; }
@keyframes lang-in { from { opacity: 0; } to { opacity: 1; } }

.terr-legend {
  background: color-mix(in oklch, var(--surface) 94%, transparent);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  padding: 0.6rem 0.75rem;
  max-width: 270px;
  font-size: 0.74rem; line-height: 1.35; color: var(--ink);
}
.terr-legend[hidden] { display: none; }
.terr-legend summary { font-family: var(--font-sans); font-size: 0.7rem; font-weight: 600; color: var(--muted); cursor: pointer; list-style: none; display: flex; align-items: center; gap: 0.4rem; }
.terr-legend summary::-webkit-details-marker { display: none; }
.terr-legend summary::before { content: "▸"; font-size: 0.8em; transition: transform 150ms var(--ease); }
.terr-legend details[open] > summary::before { transform: rotate(90deg); }
.terr-legend details[open] > summary { margin-bottom: 0.45rem; }
.terr-legend summary:focus-visible { outline: 2.5px solid var(--primary); outline-offset: 3px; border-radius: 4px; }
.terr-legend ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.35rem; }
.terr-legend li { display: flex; gap: 0.5rem; align-items: flex-start; }
.terr-legend strong { font-weight: 600; }
.terr-legend .sw { flex: none; width: 11px; height: 11px; margin-top: 0.2rem; border-radius: 3px; background: var(--c); border: 1.5px solid var(--c); background: color-mix(in oklch, var(--c) 40%, transparent); }
.terr-legend .terr-hint { margin: 0.5rem 0 0; color: var(--muted); font-size: 0.68rem; }
@media (max-width: 760px) {
  .terr-legend { max-width: 220px; padding: 0.45rem 0.6rem; font-size: 0.68rem; }
  .terr-legend .terr-hint { display: none; }
}

/* Map markers (divIcon) */
.pin { display: grid; place-items: center; }
.pin .dot {
  width: 15px; height: 15px; border-radius: 50%;
  background: var(--primary); border: 2.5px solid var(--bg);
  box-shadow: var(--shadow-1);
  transition: transform 150ms var(--ease);
}
.pin.preview .dot { background: transparent; border: 2.5px dashed var(--accent); box-shadow: none; }
.pin:hover .dot { transform: scale(1.25); }
.pin.selected .dot { background: var(--accent); width: 19px; height: 19px; box-shadow: var(--shadow-2); }
.pin .pin-label {
  position: absolute; top: -0.5rem; left: 50%; transform: translate(-50%, -100%);
  font-size: 0.72rem; font-weight: 600; white-space: nowrap;
  background: var(--surface); color: var(--ink);
  padding: 0.1rem 0.4rem; border-radius: var(--radius-sm);
  border: 1px solid var(--line); box-shadow: var(--shadow-1);
  opacity: 0; pointer-events: none; transition: opacity 150ms var(--ease);
}
.pin:hover .pin-label, .pin.selected .pin-label { opacity: 1; }

/* ---------- Place card ---------- */
.place-card {
  background: var(--surface);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  padding: clamp(1rem, 2.2vw, 1.5rem);
  min-height: 0;
}
.card-empty { color: var(--muted); display: flex; flex-direction: column; gap: 0.6rem; justify-content: flex-start; align-items: flex-start; padding-top: 1.5rem; }
.card-empty .big { font-family: var(--font-serif); font-size: 1.3rem; color: var(--ink); }
.card-empty svg { color: var(--primary); }

.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.6rem; }
.card-head h2 { font-size: clamp(1.6rem, 1.2rem + 1vw, 2rem); }
.card-country { font-size: 0.8rem; color: var(--muted); margin-top: 0.15rem; }
.card-close { font-size: 1.1rem; line-height: 1; }
.card-summary {
  font-family: var(--font-serif);
  font-size: 1.02rem; line-height: 1.5;
  color: var(--ink); margin: 0.7rem 0 0;
  padding-bottom: 1rem; border-bottom: 1px solid var(--line);
  max-width: 60ch;
}

.layer { padding: 1rem 0; border-bottom: 1px solid var(--line); }
.layer:last-child { border-bottom: none; }
.layer-top { display: flex; align-items: center; gap: 0.55rem; flex-wrap: wrap; }
.layer-form { font-family: var(--font-serif); font-style: italic; font-size: 1.18rem; font-weight: 500; color: var(--ink); }
.layer-period { font-size: 0.76rem; color: var(--faint); margin-left: auto; white-space: nowrap; }
.layer-note { color: var(--muted); font-size: 0.86rem; margin: 0.25rem 0 0; }

.claim { margin-top: 0.75rem; }
.claim-text { font-size: 0.92rem; line-height: 1.5; margin: 0; max-width: 62ch; }
.claim-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.6rem; margin-top: 0.45rem; }
.claim.unverified { opacity: 0.92; }
.claim.unverified .claim-text { border-left: none; }

/* Layer tag */
.tag {
  font-size: 0.68rem; font-weight: 600; letter-spacing: 0.03em; text-transform: uppercase;
  padding: 0.14rem 0.46rem; border-radius: 999px;
  color: var(--tag-color, var(--muted));
  background: color-mix(in oklch, var(--tag-color, var(--muted)) 14%, var(--surface));
  border: 1px solid color-mix(in oklch, var(--tag-color, var(--muted)) 32%, transparent);
}

/* Confidence badge */
.badge {
  font-size: 0.72rem; font-weight: 600;
  display: inline-flex; align-items: center; gap: 0.35em;
  padding: 0.16rem 0.5rem; border-radius: 999px;
  border: 1px solid transparent;
}
.badge .glyph { font-size: 0.85em; line-height: 1; }
.badge.documented { color: var(--conf-documented); background: var(--conf-documented-soft); border-color: color-mix(in oklch, var(--conf-documented) 30%, transparent); }
.badge.inferred   { color: var(--conf-inferred);   background: var(--conf-inferred-soft);   border-color: color-mix(in oklch, var(--conf-inferred) 35%, transparent); }
.badge.debated    { color: var(--conf-debated);    background: var(--conf-debated-soft);    border-color: color-mix(in oklch, var(--conf-debated) 32%, transparent); }

.badge.status-draft {
  color: var(--accent-ink); background: color-mix(in oklch, var(--accent) 22%, var(--surface));
  border-color: color-mix(in oklch, var(--accent) 45%, transparent);
}

/* Sources */
.sources { margin-top: 0.4rem; display: flex; flex-direction: column; gap: 0.2rem; }
.sources a, .sources span.src {
  font-size: 0.78rem; color: var(--muted); text-decoration: none;
  display: inline-flex; gap: 0.3em; align-items: baseline;
}
.sources a:hover { color: var(--primary); text-decoration: underline; }
.src-tier { font-size: 0.64rem; font-weight: 700; color: var(--faint); border: 1px solid var(--line-strong); border-radius: 4px; padding: 0 0.25em; }

/* Glossary term */
.term {
  font: inherit; color: inherit; background: none; border: none; padding: 0; cursor: help;
  border-bottom: 1.5px dotted var(--primary); text-decoration: none;
}
.term:hover { color: var(--primary); }

/* ---------- Popover (glossary + legend) ---------- */
.popover {
  position: fixed;
  z-index: var(--z-popover);
  max-width: min(300px, calc(100vw - 2rem));
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-3);
  padding: 0.75rem 0.85rem;
  font-size: 0.86rem;
  line-height: 1.45;
}
.popover h4 { font-family: var(--font-sans); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--faint); margin: 0 0 0.35rem; }
.popover[hidden] { display: none; }

.legend-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.6rem; }
.legend-list li { display: flex; gap: 0.55rem; align-items: flex-start; }
.legend-list .badge { flex: none; margin-top: 0.05rem; }
.legend-list .desc { color: var(--muted); font-size: 0.82rem; }

/* ---------- Big-picture dialog ---------- */
dialog.sheet {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--ink);
  max-width: 640px;
  width: calc(100vw - 2rem);
  padding: 0;
  box-shadow: var(--shadow-3);
}
dialog.sheet::backdrop { background: oklch(0.2 0.03 258 / 0.5); backdrop-filter: blur(2px); }
.sheet-body { padding: clamp(1.1rem, 3vw, 1.7rem); }
.sheet-body h2 { font-size: 1.5rem; margin-bottom: 0.3rem; }
.sheet-body .lede { font-family: var(--font-serif); font-size: 1.05rem; color: var(--ink); margin: 0 0 1rem; max-width: 60ch; }
.sheet-close { position: absolute; top: 0.6rem; right: 0.6rem; }
.fact { padding: 0.8rem 0; border-top: 1px solid var(--line); }
.fact p { margin: 0 0 0.4rem; font-size: 0.92rem; max-width: 62ch; }

/* ---------- Footer ---------- */
.site-footer {
  padding: 1rem clamp(0.9rem, 3vw, 1.6rem);
  background: var(--surface);
  border-top: 1px solid var(--line);
  font-size: 0.78rem;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.2rem;
  align-items: center;
}
.site-footer a { color: var(--primary); }
.site-footer .spacer { flex: 1 1 auto; }
.site-footer .stamp { font-style: italic; }

/* ---------- Preview banner ---------- */
.preview-banner {
  position: sticky; top: 0; z-index: var(--z-banner);
  background: color-mix(in oklch, var(--accent) 24%, var(--surface));
  color: var(--accent-ink);
  border-bottom: 1px solid color-mix(in oklch, var(--accent) 45%, transparent);
  padding: 0.45rem clamp(0.9rem, 3vw, 1.6rem);
  font-size: 0.82rem; font-weight: 500;
  display: flex; gap: 0.5rem; align-items: center;
}

/* ---------- Loading / error ---------- */
.state-msg { padding: 2rem; color: var(--muted); font-size: 0.95rem; text-align: center; }
.state-msg.error { color: var(--conf-debated); }

/* ---------- Responsive: mobile bottom sheet ---------- */
@media (max-width: 760px) {
  .workspace,
  .workspace.no-selection { grid-template-columns: 1fr; }
  #map { min-height: 56vh; width: 100%; }
  .place-card {
    position: fixed; left: 0; right: 0; bottom: 0;
    max-height: 72dvh;
    border-left: none; border-top: 1px solid var(--line-strong);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: var(--shadow-3);
    z-index: var(--z-sheet);
    transform: translateY(101%);
    transition: transform var(--dur) var(--ease);
  }
  .place-card.open { transform: translateY(0); }
  body.card-open .sheet-backdrop { opacity: 1; pointer-events: auto; }
  .sheet-backdrop {
    position: fixed; inset: 0; background: oklch(0.2 0.03 258 / 0.4);
    z-index: var(--z-backdrop); opacity: 0; pointer-events: none;
    transition: opacity var(--dur) var(--ease);
  }
  .card-empty.desktop-only { display: none; }
  .hero p.thesis { font-size: clamp(1.15rem, 1rem + 2.5vw, 1.6rem); }
}
@media (min-width: 761px) {
  .sheet-backdrop { display: none; }
  .place-card .card-close.mobile-only { display: none; }
}

/* ---------- Phones: the map comes first ---------- */
.short, .map-hint { display: none; }
.pin::after { content: ""; position: absolute; inset: -14px; } /* a bigger thumb target around the small dot */
dialog.sheet { max-height: calc(100dvh - 2rem); overflow-y: auto; }

@media (max-width: 760px) {
  .long { display: none; }
  .short { display: inline; }

  /* one-row header */
  .site-header { padding: calc(0.45rem + env(safe-area-inset-top)) 0.7rem 0.45rem; gap: 0.4rem; }
  .wordmark .tag { display: none; }
  .header-actions { gap: 0.3rem; }
  .header-actions .btn { font-size: 0.82rem; padding: 0.5rem 0.65rem; min-height: 40px; white-space: nowrap; }
  .header-actions .btn-icon { width: 40px; justify-content: center; padding: 0.5rem 0; }

  /* controls, then the map, then the long intro text below it */
  .toolbar { order: 1; padding: 0.55rem 0.8rem; gap: 0.5rem 0.8rem; }
  .workspace { order: 2; }
  .hero { order: 3; }
  .site-footer { order: 4; padding-bottom: calc(1rem + env(safe-area-inset-bottom)); }
  .map-hint { display: block; flex: 1 1 100%; margin: 0; font-size: 0.8rem; color: var(--muted); }

  .timeline { flex: 1 1 100%; min-width: 0; }
  input[type="range"].slider { height: 40px; margin: 0; }
  input[type="range"].slider::-webkit-slider-runnable-track { height: 5px; }
  input[type="range"].slider::-webkit-slider-thumb { width: 26px; height: 26px; margin-top: -10.5px; }
  input[type="range"].slider::-moz-range-thumb { width: 26px; height: 26px; }
  .timeline-ticks { margin-top: 0; }
  .timeline-ticks button { padding: 0.5rem 0.25rem; font-size: 0.74rem; min-height: 36px; }
  .timeline-caption { font-size: 0.82rem; }

  /* chips scroll sideways in one row, beside the key button */
  .tg-langs { flex: 1 1 0; min-width: 0; }
  .tg-legend { flex: none; }
  .filters { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .filters::-webkit-scrollbar { display: none; }
  .chip { flex: none; padding: 0.5rem 0.8rem; font-size: 0.85rem; }
  .tg-legend .btn { min-height: 40px; }

  #map { min-height: max(52svh, 340px); }
  .leaflet-touch .leaflet-bar a { width: 40px; height: 40px; line-height: 40px; font-size: 20px; }
  .place-card { padding-bottom: calc(1.2rem + env(safe-area-inset-bottom)); }
  .card-close { min-width: 40px; min-height: 40px; }
  .page-wrap .back { padding: 0.5rem 0; }
}

/* ---------- Suffix page ---------- */
.page-wrap { max-width: 760px; margin: 0 auto; padding: clamp(1.2rem, 4vw, 2.5rem) clamp(0.9rem, 3vw, 1.6rem); }
.page-wrap .back { font-size: 0.85rem; display: inline-flex; gap: 0.3em; align-items: center; margin-bottom: 1rem; text-decoration: none; }
.page-wrap h1 { font-size: clamp(1.8rem, 1.4rem + 2vw, 2.6rem); margin-bottom: 0.5rem; }
.page-wrap .lede { font-family: var(--font-serif); color: var(--muted); font-size: 1.05rem; max-width: 60ch; margin: 0 0 2rem; }
.suffix {
  padding: 1.2rem 0; border-top: 1px solid var(--line);
}
.suffix-el { font-family: var(--font-serif); font-size: 1.35rem; font-weight: 600; color: var(--primary); }
.suffix-claim { margin: 0.5rem 0 0.6rem; max-width: 62ch; }
.suffix-eg { font-size: 0.82rem; color: var(--muted); }
.suffix-meta { display: flex; flex-wrap: wrap; gap: 0.4rem 0.6rem; align-items: center; margin-top: 0.6rem; }

/* ---------- Motion off ---------- */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
}
