/* Iberia · Mapa vivo — "Atlas mediterráneo" (docs/design/brief.md). */

:root {
  --paper: #f4ecdd;
  --paper-2: #f8f2e6;
  --paper-edge: #e6dac4;
  --page: #fbf7ef;
  --sea: #cfdde0;
  --sea-line: rgba(52, 96, 118, 0.20);
  --sea-ring: #a9c0c6;
  --coast-ctx: rgba(42, 36, 32, 0.45);
  --sea-text: #4b7184;
  --hatch: rgba(52, 96, 118, 0.42);
  --ink: #2a2420;
  --ink-80: rgba(42, 36, 32, 0.8);
  --ink-60: rgba(42, 36, 32, 0.62);
  --ink-40: rgba(42, 36, 32, 0.4);
  --ink-20: rgba(42, 36, 32, 0.18);
  --ink-10: rgba(42, 36, 32, 0.09);
  --azul: #1f5fa8;
  --azul-soft: rgba(31, 95, 168, 0.12);
  --azafran: #e3a628;
  --azafran-ink: #c08410;
  --azafran-soft: rgba(227, 166, 40, 0.16);
  --context: #e5dccb;
  --land-base: #e9e0cc;
  --shadow-land: rgba(60, 44, 30, 0.22);
  --halo: rgba(244, 236, 221, 0.85);
  --umber-text: #6b4f36;
  --vig: rgba(60, 44, 30, 0.13);
  --card-shadow: 0 1px 2px rgba(42, 36, 32, 0.08), 0 8px 28px rgba(42, 36, 32, 0.16);
  --glass: rgba(248, 242, 230, 0.86);
  --h0: #b9c7a5; --h200: #cdcb9d; --h500: #d9c08a; --h1000: #c9a571; --h1500: #a8805a; --h2000: #8e6f55; --h2500: #ece6da;
  --serif: "Fraunces", "Iowan Old Style", Georgia, serif;
  --sans: "Inter", -apple-system, "Segoe UI", system-ui, sans-serif;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --paper: #18222c;
  --paper-2: #1b2631;
  --paper-edge: #2a3744;
  --page: #1a232c;
  --sea: #132330;
  --sea-line: rgba(140, 180, 200, 0.12);
  --sea-ring: #213847;
  --coast-ctx: rgba(236, 227, 210, 0.3);
  --sea-text: #7fa3b5;
  --hatch: rgba(140, 180, 200, 0.22);
  --ink: #ece3d2;
  --ink-80: rgba(236, 227, 210, 0.82);
  --ink-60: rgba(236, 227, 210, 0.62);
  --ink-40: rgba(236, 227, 210, 0.38);
  --ink-20: rgba(236, 227, 210, 0.18);
  --ink-10: rgba(236, 227, 210, 0.08);
  --azul: #6ea2e0;
  --azul-soft: rgba(110, 162, 224, 0.16);
  --azafran: #e8b445;
  --azafran-ink: #e8b445;
  --azafran-soft: rgba(232, 180, 69, 0.14);
  --context: #1c2630;
  --land-base: #222e38;
  --shadow-land: rgba(0, 0, 0, 0.5);
  --halo: rgba(15, 23, 32, 0.8);
  --umber-text: #d8b48a;
  --vig: rgba(0, 0, 0, 0.42);
  --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 30px rgba(0, 0, 0, 0.45);
  --glass: rgba(24, 34, 44, 0.86);
  --h0: #4d5a45; --h200: #5a5b43; --h500: #6a5c3f; --h1000: #6a5539; --h1500: #5a4330; --h2000: #4a3a2e; --h2500: #9c978e;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: var(--sea);
  color: var(--ink);
  font: 400 17px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  font-optical-sizing: auto;
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--azul); outline-offset: 2px; }

#app { position: fixed; inset: 0; }
.engraving { position: absolute; pointer-events: none; will-change: transform; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; user-select: none; -webkit-user-select: none; --k: 1; }

/* Paper grain over everything (one static image, cheap to composite). */
.grain {
  position: absolute; inset: 0; pointer-events: none; z-index: 1; opacity: 0.5; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.45 0 0 0 0 0.38 0 0 0 0 0.3 0 0 0 0.16 0'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23n)'/%3E%3C/svg%3E");
}
:root[data-theme="dark"] .grain { mix-blend-mode: screen; opacity: 0.22; }

/* ---------------- map ---------------- */
.sea { fill: var(--sea); }
.vignette { pointer-events: none; }
.vig-0 { stop-color: var(--vig); stop-opacity: 0; }
.vig-1 { stop-color: var(--vig); stop-opacity: 1; }
#vignette stop.vig-1 { stop-color: #000; stop-opacity: 0.11; }
:root[data-theme="dark"] #vignette stop.vig-1 { stop-opacity: 0.45; }

.layer path { vector-effect: non-scaling-stroke; }
.hatch-line { stroke: var(--hatch); stroke-width: 0.7; }
.hatch-band { fill: none; stroke: url(#hatch); stroke-width: 9; stroke-linejoin: round; opacity: 0.9; }
.waterline { fill: none; stroke-linejoin: round; }
.waterline.ring { stroke: var(--sea-ring); }
.waterline.gap { stroke: var(--sea); }

.patch { fill: var(--sea); stroke: none; }
/* Ceuta and Melilla: a halo of constant screen size until they are big enough to see. */
.enclave {
  r: calc(10px / var(--k)); fill-opacity: 0.8; stroke: var(--ink); stroke-width: 1.4; stroke-dasharray: 3 2;
  vector-effect: non-scaling-stroke; cursor: pointer; outline: none;
}
.enclave:hover, .enclave.sel, .enclave:focus-visible { stroke: var(--azul); stroke-width: 2; stroke-dasharray: none; }
.lod-prov .enclave { display: none; }
.patch-frame { fill: none; stroke: var(--ink-60); stroke-width: 1; vector-effect: non-scaling-stroke; }
.patch-caption {
  font: italic 500 calc(13px / var(--k)) var(--serif); fill: var(--ink-80); letter-spacing: 0.04em;
  paint-order: stroke; stroke: var(--sea); stroke-width: calc(3px / var(--k));
}

.land-shadow { fill: var(--shadow-land); stroke: var(--shadow-land); stroke-width: 3; stroke-linejoin: round; }
.context-land { fill: var(--context); stroke: var(--ink-20); stroke-width: 0.5; }
.land-base { fill: var(--context); }
[data-mode="geo"] .land-base { fill: var(--h0); }
[data-mode="geo"] .context-land { opacity: 0.75; }

.unit { stroke: none; cursor: pointer; outline: none; transition: fill-opacity 0.3s var(--ease); }
/* Keyboard focus on a map shape: the hover highlight shows, plus a ring (outline does not draw on SVG in Safari). */
.unit:focus-visible { stroke: var(--azul); stroke-width: 2.5; vector-effect: non-scaling-stroke; }
.panel-title:focus { outline: none; }
.panel-title:focus-visible { outline: 2px solid var(--azul); outline-offset: 4px; border-radius: 4px; }
.unit.polity { stroke: var(--ink-40); stroke-width: 0.6; stroke-linejoin: round; }
.has-sel .unit:not(.sel) { fill-opacity: 0.72; }
.region-mesh { fill: none; stroke: var(--ink); stroke-opacity: 0.42; stroke-width: 0.7; stroke-linejoin: round; }
.country-mesh { fill: none; stroke: var(--ink); stroke-opacity: 0.75; stroke-width: 1.5; stroke-linejoin: round; }
:not(.period-hoy) > .viewport .region-mesh, #map:not(.period-hoy) .region-mesh { stroke-opacity: 0.12; stroke-dasharray: 2 3; }
#map:not(.period-hoy) .country-mesh { stroke-opacity: 0.25; stroke-dasharray: 3 3; stroke-width: 0.8; }
.coastline { fill: none; stroke: var(--ink); stroke-opacity: 0.78; stroke-width: 0.85; stroke-linejoin: round; }

.prov-mesh { fill: none; stroke: var(--ink); stroke-opacity: 0; stroke-width: 0.5; stroke-dasharray: 2 2.5; transition: stroke-opacity 0.3s; }
.lod-prov .prov-mesh { stroke-opacity: 0.38; }
.prov-hit { fill: transparent; stroke: none; pointer-events: none; }
.lod-prov[data-mode="politica"] .prov-hit { pointer-events: all; cursor: pointer; }

.hl { stroke: var(--ink); stroke-width: 1.5; stroke-linejoin: round; pointer-events: none; }
.hl-prov { fill: none; stroke: var(--ink); stroke-width: 1; stroke-dasharray: 3 2; pointer-events: none; }
.sel-outline { fill: none; stroke: var(--azul); stroke-width: 2.4; stroke-linejoin: round; pointer-events: none; }

.relief { stroke: none; }
.river { fill: none; stroke: var(--azul); stroke-width: 1.3; stroke-linecap: round; stroke-linejoin: round; opacity: 0.85; }
.river.rank-2, .river.rank-3 { stroke-width: 0.8; opacity: 0.7; }
.lake { fill: var(--azul); fill-opacity: 0.5; stroke: var(--azul); stroke-width: 0.6; }
[data-mode="politica"] .layer-relief,
[data-mode="politica"] .layer-markers,
[data-mode="politica"] .range,
[data-mode="politica"] .river-label { display: none; }
[data-mode="politica"] .layer-rivers { display: none; }
[data-mode="geo"] .layer-political,
[data-mode="geo"] .layer-provinces,
[data-mode="geo"] .pol-labels,
[data-mode="geo"] .prov-label { display: none; }
[data-mode="geo"] .region-mesh { stroke-opacity: 0; }
[data-mode="geo"] .country-mesh { stroke-opacity: 0.4; stroke-width: 1; stroke-dasharray: 4 3; }

/* labels: constant size on screen at any zoom (font-size / k) */
.layer-labels text { pointer-events: none; }
.pol-label {
  font-family: var(--serif); font-weight: 560; font-size: calc(13px / var(--k)); font-variant-caps: all-small-caps;
  letter-spacing: 0.09em; text-anchor: middle; dominant-baseline: middle; fill: var(--ink);
  paint-order: stroke; stroke: var(--halo); stroke-width: calc(3px / var(--k)); stroke-linejoin: round;
  font-variation-settings: "SOFT" 40, "opsz" 24; transition: opacity 0.25s;
}
.pol-label.big { font-size: calc(15.5px / var(--k)); letter-spacing: 0.12em; }
.pol-label.hide, .prov-label.hide { opacity: 0; }
.prov-label {
  font: 500 calc(10.5px / var(--k)) var(--sans); fill: var(--ink-80); text-anchor: middle; dominant-baseline: middle;
  paint-order: stroke; stroke: var(--halo); stroke-width: calc(2.5px / var(--k)); opacity: 0; transition: opacity 0.3s;
}
.lod-prov .prov-label:not(.hide) { opacity: 1; }
.lod-prov .pol-label { opacity: 0.85; }
.lod-prov.period-hoy .pol-label { opacity: 0; }
#map:not(.period-hoy) .pol-label { stroke-opacity: 0.7; }
.water {
  font-family: var(--serif); font-style: italic; font-weight: 400; fill: var(--sea-text); text-anchor: middle;
  letter-spacing: 0.22em; font-variation-settings: "SOFT" 100;
}
.water.ocean { font-size: calc(21px / var(--k)); letter-spacing: 0.35em; }
.water.hide { opacity: 0; }
.water.sea { font-size: calc(15px / var(--k)); }
.water.small { font-size: calc(12px / var(--k)); letter-spacing: 0.16em; }
.ctx {
  font-family: var(--serif); font-size: calc(13px / var(--k)); font-variant-caps: all-small-caps; letter-spacing: 0.4em;
  fill: var(--ink-40); text-anchor: middle;
}
.range text {
  font-family: var(--serif); font-weight: 600; font-size: calc(12.5px / var(--k)); font-variant-caps: all-small-caps;
  letter-spacing: 0.42em; fill: var(--umber-text); text-anchor: middle; dominant-baseline: middle;
  paint-order: stroke; stroke: var(--halo); stroke-width: calc(2.5px / var(--k)); stroke-opacity: 0.6;
}
.range-axis { fill: none; stroke: none; }
.range text.hide, .river-label.hide { opacity: 0; }
.river-label {
  font-family: var(--serif); font-style: italic; font-size: calc(11.5px / var(--k)); fill: var(--azul); letter-spacing: 0.08em;
  paint-order: stroke; stroke: var(--halo); stroke-width: calc(2.5px / var(--k)); dominant-baseline: text-after-edge;
}

/* landmarks */
.lm { cursor: pointer; outline: none; }
.lm-bg { fill: var(--paper-2); stroke: var(--ink-80); stroke-width: 1; transition: r 0.2s; }
.lm:hover .lm-bg, .lm.hover .lm-bg, .lm:focus-visible .lm-bg { stroke: var(--azul); stroke-width: 2; }
.lm.sel .lm-bg { stroke: var(--azul); stroke-width: 2.6; fill: var(--paper); }
.lm-label {
  font: 500 12.5px var(--sans); fill: var(--ink); paint-order: stroke; stroke: var(--halo); stroke-width: 3.5px;
  stroke-linejoin: round; opacity: 0; transition: opacity 0.2s;
}
.lm.named .lm-label, .lm:hover .lm-label, .lm.hover .lm-label, .lm.sel .lm-label, .lm:focus-visible .lm-label { opacity: 1; }
.g-fill-earth { fill: #a8805a; stroke: #2a2420; stroke-width: 0.9; stroke-linejoin: round; }
.g-snow { fill: #fbf8f1; }
.g-fill-volcano { fill: #9a4a34; stroke: #2a2420; stroke-width: 0.9; stroke-linejoin: round; }
.g-ink { fill: none; stroke: var(--ink); stroke-width: 1.1; stroke-linecap: round; }
.g-water { fill: none; stroke: var(--azul); stroke-width: 1.4; stroke-linecap: round; }
.g-water-light { fill: none; stroke: #f8f2e6; stroke-width: 0.9; stroke-linecap: round; }
.g-fill-green { fill: #5f8a55; stroke: #2a2420; stroke-width: 0.8; stroke-linejoin: round; }
.g-reed { fill: none; stroke: #5f8a55; stroke-width: 1.5; stroke-linecap: round; }
.g-fill-water { fill: #6c9cc9; stroke: #2a2420; stroke-width: 0.8; }
.g-fill-paper { fill: #f4ecdd; stroke: #2a2420; stroke-width: 0.9; stroke-linejoin: round; }
.g-fill-light { fill: #e3a628; stroke: #2a2420; stroke-width: 0.9; }
.g-fill-sun { fill: #e3a628; }
.g-fill-sand { fill: #e0c48a; stroke: #2a2420; stroke-width: 0.8; stroke-linejoin: round; }
.g-fill-ink { fill: #2a2420; }

/* ---------------- floating chrome ---------------- */
.glass, .topbar .seg, .timeline, .legend, .zoom-ctl, .hovercard, .icon-btn.theme-toggle {
  background: var(--glass);
  -webkit-backdrop-filter: blur(12px) saturate(1.2);
  backdrop-filter: blur(12px) saturate(1.2);
  box-shadow: var(--card-shadow);
  border: 1px solid var(--ink-10);
}

.topbar {
  position: absolute; z-index: 5; top: 16px; left: 20px; right: 20px; display: flex; align-items: center; gap: 12px;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.spacer { flex: 1; pointer-events: none; }
/* Visits: one quiet line under the level switch; absolutely placed, so it never shifts the layout. */
.visits {
  position: absolute; z-index: 4; top: 64px; right: 24px; margin: 0; display: flex; flex-direction: column; align-items: flex-end;
  font: 400 12.5px/1.4 var(--sans); color: var(--ink); opacity: 0.55; transition: opacity 0.2s;
}
.visits[hidden] { display: none; }
.visits:hover, .visits:focus-within { opacity: 0.9; }
.panel-open .visits { opacity: 0; pointer-events: none; }
.visits-spark { margin-top: 3px; opacity: 0; transition: opacity 0.2s; }
.visits-spark rect { fill: currentColor; }
.visits:hover .visits-spark, .visits:focus-within .visits-spark { opacity: 1; }
.brand { display: flex; align-items: baseline; gap: 10px; text-decoration: none; color: var(--ink); padding: 2px 10px 2px 4px; }
.brand-mark {
  font-family: var(--serif); font-size: 34px; font-weight: 640; letter-spacing: 0.01em; line-height: 1;
  font-variation-settings: "SOFT" 60, "opsz" 144;
}
.brand-sub { font-family: var(--serif); font-style: italic; font-size: 17px; color: var(--ink-60); }

.seg { display: inline-flex; border-radius: 999px; padding: 4px; gap: 2px; }
.seg button {
  border: 0; background: transparent; padding: 6px 14px; border-radius: 999px; cursor: pointer;
  font: 500 14px/1.2 var(--sans); color: var(--ink-60); transition: background 0.2s, color 0.2s;
}
.seg button:hover { color: var(--ink); }
.seg button[aria-selected="true"], .seg button[aria-checked="true"] { background: var(--ink); color: var(--paper); }
.level-switch button { padding: 6px 10px; font-feature-settings: "tnum"; letter-spacing: 0.02em; }
.level-switch button[aria-checked="true"] { background: var(--azul); color: #fff; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 999px; border: 0; display: grid; place-items: center; cursor: pointer;
  background: transparent; color: var(--ink); font-size: 20px; line-height: 1;
}
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle .moon { display: none; }
:root[data-theme="dark"] .theme-toggle .moon { display: inline; }
:root[data-theme="dark"] .theme-toggle .sun { display: none; }

.zoom-ctl { position: absolute; z-index: 4; right: 20px; bottom: 112px; display: flex; flex-direction: column; border-radius: 22px; padding: 4px; }
.zoom-ctl .icon-btn { width: 38px; height: 38px; font-size: 22px; font-weight: 300; }
.zoom-ctl .icon-btn:hover, .icon-btn:hover { background: var(--ink-10); }
.panel-open .zoom-ctl { opacity: 0; pointer-events: none; }

/* timeline */
.timeline {
  position: absolute; z-index: 4; left: 50%; bottom: 20px; transform: translateX(-50%); border-radius: 22px;
  padding: 6px; max-width: calc(100vw - 32px); transition: opacity 0.3s, transform 0.35s var(--ease);
}
/* Reading: the map side keeps the brand and the view switch and a slim timeline (years only); the period card, zoom
   buttons and the visits line step aside. */
.panel-open .legend, .panel-open .visits { opacity: 0; pointer-events: none; }
.panel-open .timeline { left: calc((100vw - var(--pane-w, 58vw)) / 2); max-width: calc(100vw - var(--pane-w, 58vw) - 40px); padding: 4px; bottom: 16px; }
.panel-open .tl-label { display: none; }
.panel-open .timeline-track button { min-width: 0; padding: 5px 12px 6px; }
.panel-open .tl-year { font-size: 16px; }
[data-mode="geo"] .timeline { opacity: 0; pointer-events: none; transform: translate(-50%, 20px); }
.timeline-track { position: relative; display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.timeline-track::-webkit-scrollbar { display: none; }
.timeline-track button {
  position: relative; z-index: 1; border: 0; background: transparent; cursor: pointer; padding: 7px 14px 8px;
  border-radius: 16px; display: flex; flex-direction: column; align-items: center; min-width: 82px; flex: none;
  color: var(--ink-60); transition: color 0.25s;
}
.timeline-track button:hover { color: var(--ink); }
.timeline-track button[aria-selected="true"] { color: var(--paper); }
.tl-year { font-family: var(--serif); font-size: 19px; font-weight: 600; line-height: 1.1; font-variation-settings: "opsz" 36; font-feature-settings: "lnum"; }
.tl-label { font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; white-space: nowrap; font-weight: 500; }
.tl-ink {
  position: absolute; z-index: 0; left: 0; top: 0; bottom: 0; border-radius: 16px; background: var(--ink);
  transition: transform 0.4s var(--ease), width 0.4s var(--ease);
}

/* legend / period card */
.legend {
  position: absolute; z-index: 3; left: 20px; top: 84px; border-radius: 16px; padding: 14px 18px 14px; max-width: 280px;
  transition: opacity 0.3s;
}
.lg-era { font: 600 11px var(--sans); letter-spacing: 0.14em; text-transform: uppercase; color: var(--azul); }
.lg-title { font-family: var(--serif); font-size: 26px; font-weight: 600; line-height: 1.15; font-variation-settings: "opsz" 72, "SOFT" 50; }
.lg-sub { font-size: 13px; color: var(--ink-60); margin-top: 4px; line-height: 1.4; }
.legend ul { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 2px; }
.legend li button {
  display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: transparent; padding: 4px 6px;
  margin: 0 -6px; border-radius: 8px; cursor: pointer; font-size: 14.5px; text-align: left; line-height: 1.3;
}
.legend li button:hover { background: var(--ink-10); }
.legend li i { width: 14px; height: 14px; border-radius: 4px; flex: none; box-shadow: inset 0 0 0 1px var(--ink-20); }
.lg-ramp { display: flex; margin-top: 8px; gap: 0; }
.lg-ramp span { width: 34px; height: 12px; position: relative; }
.lg-ramp span:first-child { border-radius: 4px 0 0 4px; }
.lg-ramp span:last-child { border-radius: 0 4px 4px 0; }
.lg-ramp i { position: absolute; top: 15px; left: 0; font: 500 10.5px var(--sans); font-style: normal; color: var(--ink-60); white-space: nowrap; }
.legend .lg-ramp { margin-bottom: 18px; }

/* hover card */
.hovercard {
  position: fixed; z-index: 8; left: 0; top: 0; width: 300px; border-radius: 14px; padding: 13px 16px 12px;
  pointer-events: none; will-change: transform;
}
.card-eyebrow { font: 600 10.5px var(--sans); letter-spacing: 0.13em; text-transform: uppercase; color: var(--azul); }
.card-name { font-family: var(--serif); font-size: 25px; font-weight: 600; line-height: 1.12; margin-top: 2px; font-variation-settings: "opsz" 72, "SOFT" 50; }
.card-prov { font-size: 13px; color: var(--ink-60); }
.card-tag { font-family: var(--serif); font-style: italic; font-size: 16px; line-height: 1.4; margin-top: 6px; color: var(--ink-80); }
.card-stats { display: grid; grid-template-columns: repeat(3, auto); gap: 4px 14px; margin: 10px 0 0; justify-content: start; }
.card-stats dt { font: 600 10px var(--sans); letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-60); }
.card-stats dd { margin: 0; font-size: 14px; font-weight: 500; line-height: 1.3; }
.card-hint { margin-top: 10px; font-size: 12px; color: var(--ink-40); }

/* ---------------- reading view ----------------
   Opening a region, polity or landmark turns the page into an atlas spread: the map plate on the left (live, fitted
   to the selection), the article on the right on paper. --pane-w is set by sheet.js (58 % by default, resizable). */
.panel {
  --bar-h: 64px;
  position: absolute; z-index: 6; top: 0; right: 0; bottom: 0; width: var(--pane-w, 58vw);
  background: var(--page); color: var(--ink);
  box-shadow: -1px 0 0 var(--ink-10), -18px 0 48px -12px rgba(42, 36, 32, 0.28);
  transform: translateX(calc(100% + 48px)); transition: transform 0.35s cubic-bezier(0.16, 0.84, 0.3, 1);
  display: flex; flex-direction: column; overflow: hidden;
}
:root[data-theme="dark"] .panel { box-shadow: -1px 0 0 var(--ink-10), -18px 0 48px -12px rgba(0, 0, 0, 0.6); }
.panel.open { transform: none; }
.panel[hidden] { display: none; }
.resizing, .resizing * { cursor: col-resize !important; user-select: none; }
.resizing .panel { transition: none; }
.pane-grip { position: absolute; z-index: 4; left: -5px; top: 0; bottom: 0; width: 10px; cursor: col-resize; touch-action: none; }
.pane-grip::after {
  content: ""; position: absolute; left: 3px; top: 50%; width: 4px; height: 44px; margin-top: -22px; border-radius: 2px;
  background: var(--ink-20); opacity: 0; transition: opacity 0.2s;
}
.pane-grip:hover::after, .pane-grip:focus-visible::after, .resizing .pane-grip::after { opacity: 1; }
.pane-grip:focus-visible { outline: none; }

/* Toolbar: floats over the hero, turns to paper (with the title) once the article scrolls. */
.pane-bar {
  position: absolute; z-index: 3; top: 0; left: 0; right: 0; height: var(--bar-h); display: flex; align-items: center;
  gap: 10px; padding: 0 16px 0 24px; transition: background 0.2s, box-shadow 0.2s;
}
.pane-bar.scrolled { background: var(--page); box-shadow: 0 1px 0 var(--ink-10); }
.pane-mini {
  flex: 1; min-width: 0; font: 600 19px/1.2 var(--serif); font-variation-settings: "opsz" 36; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; opacity: 0; transform: translateY(4px); transition: opacity 0.2s, transform 0.2s;
}
.pane-bar.titled .pane-mini { opacity: 1; transform: none; }
.pane-tools { display: flex; align-items: center; gap: 8px; }
.pane-tools .seg button { padding: 6px 10px; font-size: 13px; }
.pane-bar .seg, .pane-bar .icon-btn {
  background: var(--glass); -webkit-backdrop-filter: blur(12px) saturate(1.2); backdrop-filter: blur(12px) saturate(1.2);
  border: 1px solid var(--ink-10); box-shadow: 0 1px 6px rgba(0, 0, 0, 0.1);
}
.pane-bar .icon-btn { width: 44px; height: 44px; }
.pane-bar.scrolled .seg, .pane-bar.scrolled .icon-btn { box-shadow: none; }
.panel-close svg { width: 20px; height: 20px; }
.sheet-handle { display: none; }

.panel-scroll {
  flex: 1; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; padding-bottom: 72px;
  container-type: inline-size; container-name: pane;
}

/* hero */
.hero { position: relative; margin: 0; }
.hero-strip { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; outline: none; }
.hero-strip::-webkit-scrollbar { display: none; }
.hero-strip img {
  width: 100%; flex: none; height: clamp(240px, 37vh, 440px); object-fit: cover; scroll-snap-align: start; display: block;
  background: var(--paper-edge);
}
.hero::after { /* a soft fade under the toolbar so the glass controls read on any photo */
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 96px; pointer-events: none;
  background: linear-gradient(rgba(0, 0, 0, 0.22), transparent);
}
.hero-vignette::after { display: none; }
.hero-nav {
  position: absolute; z-index: 2; right: 18px; bottom: 16px; display: flex; align-items: center; gap: 6px;
  padding: 4px; border-radius: 999px; background: rgba(20, 18, 16, 0.42); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
.hero-btn { width: 32px; height: 32px; border: 0; border-radius: 50%; background: transparent; color: #fff; cursor: pointer; display: grid; place-items: center; }
.hero-btn:hover { background: rgba(255, 255, 255, 0.16); }
.hero-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.hero-dots { display: flex; gap: 6px; }
.hero-dots i { width: 6px; height: 6px; border-radius: 50%; background: rgba(255, 255, 255, 0.45); transition: background 0.2s, transform 0.2s; }
.hero-dots i.on { background: #fff; transform: scale(1.25); }
.hero-vignette {
  height: clamp(200px, 30vh, 340px);
  background: repeating-linear-gradient(135deg, transparent 0 5px, var(--sea-line) 5px 6px), var(--sea);
  border-bottom: 1px solid var(--ink-10);
}
.hero-vignette svg { width: 100%; height: 100%; display: block; }
.vg-shape { stroke: var(--ink); stroke-width: 1; stroke-linejoin: round; }
.vg-water { fill: none; stroke: var(--sea-line); stroke-width: 14; stroke-linejoin: round; }
.vg-hatch { fill: url(#vg-hatch); stroke: none; opacity: 0.5; }
.vg-loc-land { fill: var(--paper); stroke: var(--ink-60); stroke-width: 0.6; }
.vg-loc-hl { fill: var(--azul); stroke: none; }
.vg-mark { fill: var(--azul); stroke: var(--paper); stroke-width: 2; }
.vg-mark-halo { fill: var(--azul); opacity: 0.22; }

/* article: one centred column, 60-70 characters */
.article {
  --measure: 664px; /* about 66 characters of 19.5 px Inter */
  font-size: 19.5px; line-height: 1.65; padding: 0 clamp(24px, 6cqi, 72px);
}
.article > *, .art-body > * { max-width: var(--measure); margin-left: auto; margin-right: auto; }
.article > .art-body { max-width: none; }
.hero-cap { font: 400 13px/1.45 var(--sans); color: var(--ink-60); margin-top: 10px; margin-bottom: 0; }
.hero-cap a { color: inherit; text-decoration-color: var(--ink-20); }
.hero-cap .credit { opacity: 0.85; }
.art-head { padding-top: 34px; }
.hero-vignette + .article .art-head { padding-top: 30px; }
.eyebrow { font: 600 12px var(--sans); letter-spacing: 0.15em; text-transform: uppercase; color: var(--azul); }
.panel-title {
  font-family: var(--serif); font-weight: 620; font-size: clamp(40px, 5.2cqi, 56px); line-height: 1.02; margin: 10px 0 14px;
  letter-spacing: -0.015em; font-variation-settings: "opsz" 144, "SOFT" 50; text-wrap: balance;
}
.standfirst {
  font-family: var(--serif); font-style: italic; font-size: 23px; line-height: 1.45; margin: 0 0 6px; color: var(--ink-80);
  font-variation-settings: "opsz" 36, "WONK" 0; text-wrap: pretty;
}
.prose p { margin: 0 0 1em; text-wrap: pretty; }
.summary { margin-top: 26px; }
.summary p:first-child::first-letter {
  font-family: var(--serif); float: left; font-size: 3.4em; line-height: 0.84; padding: 0.07em 0.09em 0 0; font-weight: 600; color: var(--azul);
}
.level-note { font: 400 14.5px/1.5 var(--sans); color: var(--ink-60); background: var(--ink-10); padding: 9px 14px; border-radius: 10px; margin-top: 22px; }
.pending { margin-top: 28px; padding: 20px; border: 1px dashed var(--ink-20); border-radius: 12px; color: var(--ink-60); font-family: var(--serif); font-style: italic; }

.stats {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); grid-auto-flow: dense; gap: 18px 28px;
  margin-top: 30px; margin-bottom: 8px; padding: 20px 0; border-top: 1px solid var(--ink-20); border-bottom: 1px solid var(--ink-20);
}
.stats div.wide { grid-column: 1 / -1; }
.stats dt { font: 600 11px var(--sans); letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-60); }
.stats dd { margin: 4px 0 0; font: 500 17px/1.4 var(--sans); }

.art-body { position: relative; }
.art-sec { scroll-margin-top: calc(var(--bar-h) + 16px); }
.art-sec h3 {
  font-family: var(--serif); font-weight: 600; font-size: 30px; line-height: 1.15; margin: 46px 0 14px;
  font-variation-settings: "opsz" 72, "SOFT" 50; letter-spacing: -0.005em;
}
.insight {
  margin-top: 44px; padding: 22px 26px 8px; border-radius: 16px; background: var(--azafran-soft); border-left: 4px solid var(--azafran);
}
.insight h3 { font-style: italic; font-size: 25px; margin: 0 0 8px; }
.insight p { margin: 0 0 14px; }
.vocab h3 { margin-bottom: 12px; }
.vocab dl { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0 28px; margin: 0; }
.vocab dl div { display: flex; flex-direction: column; padding: 9px 0; border-bottom: 1px solid var(--ink-10); }
.vocab dt { font-family: var(--serif); font-size: 19px; font-weight: 560; line-height: 1.3; }
.vocab dd { margin: 0; font: 400 15px/1.4 var(--sans); color: var(--ink-60); }
.sources { margin-top: 40px; font: 400 14px/1.5 var(--sans); color: var(--ink-60); }
.sources summary { cursor: pointer; font: 600 11px var(--sans); letter-spacing: 0.14em; text-transform: uppercase; }
.sources ul { padding-left: 18px; margin: 8px 0 0; }
.sources a { color: var(--azul); }

/* Table of contents. Narrow panes: a strip under the toolbar. Wide panes: a column in the left margin. Either way it
   follows the reader and lights the current section. */
.toc {
  position: sticky; z-index: 2; top: var(--bar-h); max-width: none; margin: 34px calc(-1 * clamp(24px, 6cqi, 72px)) 0;
  padding: 0 clamp(24px, 6cqi, 72px); background: var(--page); box-shadow: 0 1px 0 var(--ink-10);
}
.toc-in { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; max-width: var(--measure); margin: 0 auto; }
.toc-in::-webkit-scrollbar { display: none; }
.toc-label { display: none; }
.toc a {
  flex: none; padding: 10px 10px 11px; font: 500 14px/1.2 var(--sans); color: var(--ink-60); text-decoration: none;
  border-bottom: 2px solid transparent; white-space: nowrap; transition: color 0.2s, border-color 0.2s;
}
.toc a:hover { color: var(--ink); }
.toc a.on { color: var(--ink); border-bottom-color: var(--azul); }
@container pane (min-width: 1040px) {
  .toc {
    position: absolute; top: 0; bottom: 0; left: -40px; margin: 0; padding: 0; background: none; box-shadow: none;
    width: calc((100% - var(--measure)) / 2 + 40px - 36px); max-width: 230px;
  }
  .toc-in { position: sticky; top: calc(var(--bar-h) + 40px); display: block; margin: 50px 0 0; }
  .toc-label { display: block; font: 600 11px var(--sans); letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-40); margin-bottom: 10px; }
  .toc a {
    display: block; padding: 6px 0 6px 14px; border-bottom: 0; border-left: 2px solid var(--ink-10); white-space: normal; line-height: 1.35;
  }
  .toc a.on { border-left-color: var(--azul); }
}

.vw, .nw {
  border: 0; background: none; padding: 0 1px; margin: 0 -1px; cursor: help; color: inherit; font: inherit;
  text-decoration: underline; text-decoration-color: var(--azul); text-decoration-thickness: 1.5px; text-underline-offset: 3px;
  text-decoration-style: dotted; border-radius: 3px; transition: background 0.15s;
}
.vw:hover, .vw:focus-visible, .vw[aria-describedby] { background: var(--azafran-soft); text-decoration-style: solid; }
/* Numbers: a saffron dotted underline (vocabulary is blue); the tooltip writes them out in Spanish. */
.nb { white-space: nowrap; }
.nw { text-decoration-color: var(--azafran-ink); text-decoration-thickness: 2px; font-variant-numeric: lining-nums; white-space: nowrap; }
.nw:hover, .nw:focus-visible, .nw[aria-describedby] { background: var(--azafran-soft); text-decoration-style: solid; }
.hovercard .nw { cursor: inherit; }

.vocab-tip {
  position: fixed; z-index: 20; left: 0; top: 0; background: var(--ink); color: var(--paper); border-radius: 10px;
  padding: 7px 12px 8px; box-shadow: var(--card-shadow); pointer-events: none; display: flex; flex-direction: column; max-width: 260px;
}
.vocab-tip[hidden] { display: none; }
.tip-es { font-family: var(--serif); font-style: italic; font-size: 14px; opacity: 0.75; line-height: 1.2; }
.tip-en { font-size: 15.5px; font-weight: 500; line-height: 1.3; }
.vocab-tip.num { border-top: 3px solid var(--azafran); max-width: 300px; }
.vocab-tip.num .tip-en { font-family: var(--serif); font-size: 17px; font-weight: 500; }

.boot-error { position: absolute; inset: 40% 0 auto; text-align: center; font-family: var(--serif); font-size: 22px; }

/* ---------------- phones ---------------- */
.portrait .water.ocean, .portrait .water.small, .portrait .ctx { display: none; }
.portrait .water.sea { font-size: calc(12px / var(--k)); letter-spacing: 0.14em; }

@media (max-width: 719px) {
  body { font-size: 16px; }
  #app::before {
    content: ""; position: absolute; z-index: 2; left: 0; right: 0; top: 0; height: 120px; pointer-events: none;
    background: linear-gradient(var(--sea) 30%, transparent);
  }
  .topbar { top: max(10px, env(safe-area-inset-top)); left: 10px; right: 10px; gap: 6px; flex-wrap: wrap; }
  .brand { padding: 0 4px; }
  .brand-mark { font-size: 26px; }
  .brand-sub { display: none; }
  .visits { top: 58px; right: 12px; max-width: 150px; text-align: right; font-size: 11.5px; }
  .visits-spark { display: none; }
  .seg button { padding: 6px 10px; font-size: 13px; }
  .level-switch button { padding: 6px 7px; font-size: 12.5px; }
  .view-switch { order: 5; }
  .topbar .spacer { display: none; }
  .level-switch { margin-left: auto; }
  .theme-toggle { width: 36px; height: 36px; }
  .legend { top: auto; bottom: 92px; left: 10px; padding: 8px 12px; max-width: 60vw; }
  .legend ul, .lg-sub { display: none; }
  .lg-title { font-size: 18px; }
  .zoom-ctl { display: none; }
  .timeline { bottom: max(10px, env(safe-area-inset-bottom)); left: 10px; right: 10px; transform: none; max-width: none; }
  [data-mode="geo"] .timeline { transform: translateY(20px); }
  .timeline-track button { min-width: 74px; padding: 6px 10px 7px; }
  .tl-year { font-size: 17px; }
  .tl-label { font-size: 10px; }
  .hovercard { display: none; }

  .panel-open .legend, .panel-open .timeline { opacity: 0; pointer-events: none; }
}


/* Below 900 px the reading view is a bottom sheet: almost full height to read, dragged down to a peek of the map. */
@media (max-width: 899px) {
  .panel {
    --bar-h: 70px;
    top: auto; left: 0; right: 0; bottom: 0; width: auto; height: 92dvh; border-radius: 20px 20px 0 0;
    transform: translateY(100%); transition: transform 0.34s var(--ease); box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.22);
  }
  .panel.open[data-sheet="full"] { transform: translateY(var(--drag, 0px)); }
  .panel.open[data-sheet="peek"] { transform: translateY(calc(92dvh - 35dvh + var(--drag, 0px))); }
  .panel.dragging { transition: none; }
  .pane-grip, .pane-mini { display: none; }
  .pane-bar { padding: 22px 10px 0 12px; height: var(--bar-h); gap: 6px; pointer-events: none; }
  .pane-bar > * { pointer-events: auto; }
  .pane-bar .pane-tools { pointer-events: none; }
  .pane-bar .pane-tools > * { pointer-events: auto; }
  .pane-tools { flex: 1; justify-content: flex-start; }
  .pane-tools .level-switch button { padding: 6px 8px; font-size: 12.5px; }
  .pane-tools .level-switch button { min-height: 36px; }
  /* The grabber: a 44 px tall strip across the top of the sheet (the toolbar's buttons sit above it where they are). */
  .sheet-handle { display: block; position: absolute; top: 0; left: 0; right: 0; height: 44px; z-index: 2; cursor: grab; touch-action: none; }
  .sheet-handle::after {
    content: ""; position: absolute; left: 50%; top: 7px; width: 40px; height: 5px; margin-left: -20px; border-radius: 3px;
    background: rgba(255, 255, 255, 0.8); box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.12);
  }
  .hero-strip img { height: clamp(200px, 32vh, 320px); }
  .hero-vignette { height: clamp(170px, 26vh, 260px); }
  .article { font-size: 18px; line-height: 1.62; padding: 0 20px; }
  .art-head { padding-top: 22px; }
  .panel-title { font-size: clamp(32px, 9vw, 42px); }
  .standfirst { font-size: 20px; }
  .art-sec h3 { font-size: 25px; margin-top: 38px; }
  .stats { grid-template-columns: 1fr 1fr; gap: 14px 20px; }
  .stats dd { font-size: 16px; }
  .toc { margin-left: -20px; margin-right: -20px; padding: 0 12px; }
  .panel-open .legend, .panel-open .timeline { opacity: 0; pointer-events: none; }
}

/* A phone held sideways (or any short window): compact chrome so the map keeps its height. */
@media (max-height: 520px) and (min-width: 720px) {
  .topbar { top: 8px; }
  .brand-mark { font-size: 26px; }
  .brand-sub, .visits { display: none; }
  .legend { top: 56px; padding: 8px 12px; max-width: 220px; }
  .legend .lg-sub, .legend ul { display: none; }
  .lg-title { font-size: 17px; }
  .timeline { bottom: 8px; padding: 4px; }
  .timeline-track button { min-width: 64px; padding: 4px 10px 5px; }
  .tl-year { font-size: 15px; }
  .tl-label { font-size: 9.5px; }
  .hero-strip img { height: 50vh; min-height: 0; }
  .hero-vignette { height: 40vh; }
  .panel { --bar-h: 54px; }
  .zoom-ctl { display: none; }
}

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

/* Fraunces italic draws "wonky" l, b, h by default; reading text uses the plain forms. */
.card-tag, .insight h3, .pending { font-variation-settings: "WONK" 0; }
