/* ehmap — Euskal Herria mapetan
   An atlas on paper: warm paper, ink in brown-grey, Fraunces for display, Source Sans 3 for text.
   Map colours live in palette.json (validated); the UI only uses the neutral tokens below. */

@font-face {
  font-family: "Fraunces";
  src: url("fonts/Fraunces.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Fraunces";
  src: url("fonts/Fraunces-Italic.woff2") format("woff2");
  font-weight: 100 900;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "Source Sans 3";
  src: url("fonts/SourceSans3.woff2") format("woff2");
  font-weight: 200 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Source Sans 3";
  src: url("fonts/SourceSans3-Italic.woff2") format("woff2");
  font-weight: 200 900;
  font-style: italic;
  font-display: swap;
}

:root {
  --paper: #F3EEE3;
  --card: #FAF7F0;
  --rule: #DDD4C3;
  --ink: #2A2925;
  --ink-2: #5E594E;
  --muted: #6B6457;
  --accent: #A44C32;      /* terracotta: chapter numbers, focus */
  --link: #1F5A94;
  --shadow: 0 1px 2px rgb(42 41 37 / .06), 0 8px 28px rgb(42 41 37 / .08);

  --serif: "Fraunces", "Iowan Old Style", Georgia, serif;
  --sans: "Source Sans 3", "Segoe UI", system-ui, sans-serif;

  --step--1: clamp(0.84rem, 0.82rem + 0.1vw, 0.9rem);
  --step-0: clamp(1.05rem, 1rem + 0.25vw, 1.2rem);
  --step-1: clamp(1.3rem, 1.2rem + 0.5vw, 1.6rem);
  --step-2: clamp(1.7rem, 1.45rem + 1.2vw, 2.5rem);
  --step-3: clamp(2.6rem, 1.9rem + 3.4vw, 5rem);
  --measure: 34rem;
  --gutter: clamp(1rem, 0.6rem + 2vw, 2.5rem);
  --radius: 6px;

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1C1B18;
    --card: #24221E;
    --rule: #3A372F;
    --ink: #ECE6D8;
    --ink-2: #BEB6A4;
    --muted: #A39B89;
    --accent: #E08E6B;
    --link: #8FBDEB;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 10px 30px rgb(0 0 0 / .35);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 var(--step-0)/1.6 var(--sans);
  font-kerning: normal;
  text-rendering: optimizeLegibility;
}

img { max-width: 100%; height: auto; display: block; }

a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }

.skip { position: absolute; left: -999px; }
.skip:focus { left: var(--gutter); top: 0.5rem; background: var(--card); padding: 0.4rem 0.8rem; z-index: 20; }

/* --- top bar ------------------------------------------------------------------------- */

.bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 1.5rem;
  padding: 0.7rem var(--gutter);
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--rule);
}
.brand {
  font: 600 1.15rem/1 var(--serif);
  color: var(--ink); text-decoration: none; letter-spacing: 0.01em;
  display: flex; align-items: center; gap: 0.5rem;
}
.brand svg { width: 1.5rem; height: 1.5rem; }
.bar nav { margin-left: auto; display: flex; gap: 1.25rem; font-size: var(--step--1); }
.bar nav a { color: var(--ink-2); text-decoration: none; letter-spacing: 0.04em; text-transform: uppercase; font-weight: 600; }
.bar nav a:hover, .bar nav a[aria-current="page"] { color: var(--ink); }

/* --- hero ---------------------------------------------------------------------------- */

.hero {
  padding: clamp(2.5rem, 7vw, 6rem) var(--gutter) clamp(2rem, 4vw, 3.5rem);
  max-width: 78rem; margin: 0 auto;
  display: grid; gap: clamp(1.5rem, 4vw, 4rem); align-items: center;
}
@media (min-width: 60rem) { .hero { grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); } }
.hero .cover { margin: 0; }
.hero .cover img { width: 100%; border-radius: var(--radius); box-shadow: var(--shadow); background: #F3EEE3; }
.hero .facts { grid-column: 1 / -1; }
.eyebrow {
  font: 600 var(--step--1)/1 var(--sans);
  letter-spacing: 0.16em; text-transform: uppercase; color: var(--accent);
  margin: 0 0 1.2rem;
}
h1 {
  font: 500 var(--step-3)/0.98 var(--serif);
  font-optical-sizing: auto;
  letter-spacing: -0.015em;
  margin: 0 0 1.5rem; max-width: 14ch;
}
.lede { font-size: var(--step-1); line-height: 1.45; color: var(--ink-2); max-width: var(--measure); margin: 0; }

.facts {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr));
  gap: 1.5rem 2rem; margin: clamp(2rem, 5vw, 3.5rem) 0 0; padding: 1.5rem 0 0;
  border-top: 1px solid var(--rule);
}
.fact { margin: 0; }
.fact dt { order: 2; font-size: var(--step--1); color: var(--muted); line-height: 1.35; }
.fact dd {
  margin: 0 0 0.25rem;
  font: 500 var(--step-2)/1 var(--serif); font-variant-numeric: lining-nums;
}
.fact { display: flex; flex-direction: column; }

/* --- chapter index ------------------------------------------------------------------- */

.toc {
  max-width: 78rem; margin: 0 auto; padding: 0 var(--gutter) clamp(2rem, 5vw, 4rem);
  display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: 0.75rem;
  list-style: none;
}
@media (min-width: 50rem) { .toc { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.toc a {
  display: grid; grid-template-columns: auto 1fr; gap: 0.25rem 0.9rem; align-items: center;
  padding: 0.6rem; border-radius: var(--radius);
  color: var(--ink); text-decoration: none;
  transition: background-color .2s;
}
.toc a:hover { background: var(--card); }
.toc img { grid-row: span 2; width: 4.2rem; aspect-ratio: 1; object-fit: cover; border-radius: 4px; box-shadow: var(--shadow); }
.toc .n { font: 600 var(--step--1)/1 var(--sans); color: var(--accent); letter-spacing: 0.1em; }
.toc .t { font: 500 1.08rem/1.2 var(--serif); }

/* --- chapters ------------------------------------------------------------------------ */

.chapter {
  max-width: 78rem; margin: 0 auto;
  padding: clamp(3rem, 7vw, 6rem) var(--gutter);
  display: grid; gap: clamp(1.5rem, 3vw, 3.5rem);
  grid-template-columns: minmax(0, 1fr);
  border-top: 1px solid var(--rule);
  scroll-margin-top: 3.5rem;
}
@media (min-width: 60rem) {
  .chapter { grid-template-columns: minmax(0, 1.85fr) minmax(17rem, 1fr); align-items: start; }
  .chapter.flip { grid-template-columns: minmax(17rem, 1fr) minmax(0, 1.85fr); }
  .chapter.flip .map { order: 2; }
  .chapter .text { position: sticky; top: 5rem; }
}

.map { margin: 0; }
.map button {
  all: unset; display: block; cursor: zoom-in; width: 100%;
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
  background: #F3EEE3;
}
.map button:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.map img { width: 100%; transition: transform .6s cubic-bezier(.2,.7,.2,1); }
@media (hover: hover) { .map button:hover img { transform: scale(1.012); } }
.map figcaption { margin-top: 0.7rem; font-size: var(--step--1); color: var(--muted); line-height: 1.45; }

.text .num { font: 600 var(--step--1)/1 var(--sans); letter-spacing: 0.16em; color: var(--accent); margin: 0 0 0.9rem; }
h2 {
  font: 500 var(--step-2)/1.08 var(--serif); font-optical-sizing: auto;
  letter-spacing: -0.01em; margin: 0 0 1rem;
}
.text p { margin: 0 0 1rem; max-width: var(--measure); color: var(--ink-2); }
.text p strong { color: var(--ink); font-weight: 600; }

.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.1rem 1.5rem; margin: 1.6rem 0; }
.stats div { border-top: 1px solid var(--rule); padding-top: 0.6rem; }
.stats b { display: block; font: 500 var(--step-1)/1.1 var(--serif); font-variant-numeric: lining-nums; color: var(--ink); }
.stats span { font-size: var(--step--1); color: var(--muted); line-height: 1.35; display: block; margin-top: 0.2rem; }

/* legends: swatches carry identity, text stays in ink */
.legend { margin: 1.4rem 0; padding: 0; list-style: none; font-size: var(--step--1); color: var(--ink-2); }
.legend li { display: flex; align-items: center; gap: 0.6rem; margin: 0.35rem 0; }
.legend .title { font-weight: 600; color: var(--ink); margin-bottom: 0.5rem; }
.sw { flex: none; width: 1.6rem; height: 0.9rem; border-radius: 2px; box-shadow: inset 0 0 0 1px rgb(0 0 0 / .08); }
.sw.line { height: 0; box-shadow: none; border-top: 2px solid var(--ink); }
.sw.hair { height: 0; box-shadow: none; border-top: 1px solid color-mix(in srgb, var(--ink) 45%, transparent); }
.sw.dash { height: 0; box-shadow: none; border-top: 2px dashed #A44C32; }
.sw.river { height: 0; box-shadow: none; border-top: 2px solid #2867A8; }
.sw.peak { width: 1.6rem; height: 0.9rem; box-shadow: none; display: grid; place-items: center; }
.sw.peak::before { content: ""; border: 0.42rem solid transparent; border-bottom: 0.72rem solid var(--ink); border-top: 0; }
.ramp { height: 0.7rem; border-radius: 2px; margin: 0.2rem 0 0.25rem; }
.ramp-labels { display: flex; justify-content: space-between; font-variant-numeric: tabular-nums; }

.note { font-size: var(--step--1); color: var(--muted) !important; line-height: 1.45; }

/* warming stripes: one row per area, one stripe per year */
.chapter:has(+ .band) { padding-bottom: clamp(1.5rem, 3vw, 2.5rem); }
.band { max-width: 78rem; margin: 0 auto; padding: 0 var(--gutter) clamp(3rem, 7vw, 6rem); }
.stripes { margin: 0; }
.stripes h3 { font: 500 var(--step-1)/1.15 var(--serif); margin: 0 0 0.4rem; }
.stripes figcaption p { margin: 0 0 1.2rem; color: var(--ink-2); max-width: 42rem; }
.stripes-chart { position: relative; display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 0.9rem; align-items: center; }
.stripes-chart .lbl { font-size: var(--step--1); color: var(--ink-2); text-align: right; }
.stripes-chart .lbl.main { font-weight: 600; color: var(--ink); }
.stripes-chart svg { display: block; width: 100%; height: 1.15rem; border-radius: 2px; cursor: crosshair; }
.stripes-chart svg.main { height: 3.2rem; }
.stripes-chart .axis { grid-column: 2; position: relative; height: 2.6rem; font-size: 0.78rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.stripes-chart .axis span { position: absolute; top: 0.3rem; transform: translateX(-50%); }
.stripes-chart .axis .ref { top: 1.45rem; transform: none; border-top: 1px solid var(--muted); padding-top: 0.15rem; text-align: center; }
.stripes-chart .cursor { position: absolute; top: 0; width: 2px; margin-left: -1px; background: var(--ink); pointer-events: none; opacity: 0; }
.stripes-chart:hover .cursor { opacity: 0.85; }
.sw.river-c { height: 0; box-shadow: none; border-top: 4px solid var(--c); border-radius: 2px; }
.felt, .duo { margin-top: clamp(3rem, 6vw, 5rem); }
.felt h3, .duo h3 { font: 500 var(--step-1)/1.15 var(--serif); margin: 0 0 0.6rem; }
.felt > p { color: var(--ink-2); margin: 0; }
.stats.three { grid-template-columns: repeat(3, minmax(0, 1fr)); max-width: 52rem; }
.stats.three b { font-size: var(--step-2); }
.stats span strong { color: var(--ink); font-weight: 600; }
@media (max-width: 36rem) { .stats.three { grid-template-columns: minmax(0, 1fr); } }
.duo { display: grid; gap: clamp(1.5rem, 3vw, 3.5rem); grid-template-columns: minmax(0, 1fr); }
@media (min-width: 60rem) { .duo { grid-template-columns: minmax(0, 1.85fr) minmax(17rem, 1fr); align-items: start; } }
@media (max-width: 59.99rem) { .duo .text { order: -1; } }
.sea { margin: 0; }
.sea figcaption { margin-top: 0.7rem; font-size: var(--step--1); color: var(--muted); line-height: 1.45; }
.sea-chart svg { display: block; width: 100%; overflow: visible; }
.sea-chart .grid { stroke: var(--rule); }
.sea-chart .tick { font: 12px var(--sans); fill: var(--muted); font-variant-numeric: tabular-nums; }
.sea-chart rect { fill: #CA322B; }
.sea-chart rect:hover { fill: #A31C22; }
@media (prefers-color-scheme: dark) { .sea-chart rect { fill: #E25E44; } .sea-chart rect:hover { fill: #EE8B68; } }
.legend.diverging { display: flex; flex-wrap: wrap; gap: 0.2rem 0; margin: 0.6rem 0 0; }
.legend.diverging li { flex-direction: column; gap: 0.25rem; margin: 0; align-items: center; min-width: 2.6rem; font-variant-numeric: tabular-nums; }
.legend.diverging .sw { width: 2.6rem; border-radius: 0; }
.tip {
  position: fixed; z-index: 20; pointer-events: none; padding: 0.45rem 0.7rem; border-radius: var(--radius);
  background: var(--card); color: var(--ink); border: 1px solid var(--rule); box-shadow: var(--shadow);
  font-size: var(--step--1); line-height: 1.35; white-space: nowrap;
}
.tip b { font-weight: 600; }
.tip span { color: var(--ink-2); }

.dl { display: flex; flex-wrap: wrap; gap: 0.5rem 1.2rem; margin-top: 1.4rem; font-size: var(--step--1); }
.dl a { font-weight: 600; }
.dl a::before { content: "↓ "; }

/* --- data page ----------------------------------------------------------------------- */

.page { max-width: 62rem; margin: 0 auto; padding: clamp(2.5rem, 6vw, 5rem) var(--gutter); }
.page h1 { font-size: var(--step-2); max-width: none; }
.page h2 { font-size: var(--step-1); margin-top: 2.5rem; }
.page p { color: var(--ink-2); max-width: 42rem; }
table { width: 100%; border-collapse: collapse; font-size: var(--step--1); margin: 1rem 0 2rem; }
th, td { text-align: left; padding: 0.6rem 0.75rem 0.6rem 0; border-bottom: 1px solid var(--rule); vertical-align: top; }
th { font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.78rem; }
td:first-child a { font-weight: 600; }
.lic { white-space: nowrap; color: var(--ink-2); }
.table-wrap { overflow-x: auto; }

/* --- footer -------------------------------------------------------------------------- */

footer {
  border-top: 1px solid var(--rule);
  padding: 2.5rem var(--gutter) 3rem; font-size: var(--step--1); color: var(--muted);
}
footer .inner { max-width: 78rem; margin: 0 auto; display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); }
footer p { margin: 0; }

/* --- map viewer ---------------------------------------------------------------------- */

.viewer {
  width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0;
  border: 0; background: #F3EEE3; overflow: hidden;
}
.viewer::backdrop { background: rgb(28 27 24 / .6); }
.viewer .stage { position: absolute; inset: 0; cursor: grab; touch-action: none; }
.viewer .stage.dragging { cursor: grabbing; }
.viewer img { position: absolute; left: 0; top: 0; max-width: none; transform-origin: 0 0; user-select: none; -webkit-user-drag: none; }
.viewer .controls {
  position: absolute; right: 1rem; top: 1rem; display: flex; gap: 0.4rem;
}
.viewer .controls button, .viewer .caption {
  font: 600 0.95rem/1 var(--sans); color: #2A2925; background: rgb(250 247 240 / .92);
  border: 1px solid #DDD4C3; border-radius: 999px; box-shadow: 0 2px 10px rgb(42 41 37 / .12);
}
.viewer .controls button { width: 2.6rem; height: 2.6rem; cursor: pointer; }
.viewer .caption { position: absolute; left: 1rem; bottom: 1rem; padding: 0.6rem 1rem; font-weight: 500; max-width: calc(100% - 2rem); }
