/* ==========================================================================
   HistGeocoder — project site
   --------------------------------------------------------------------------
   Palette is drawn from the subject's own instruments: map-stock paper,
   verdigris (oxidized brass, the patina on a theodolite), and the red used
   for magnetic declination on a compass rose — reserved here, strictly, for
   error and abstention. Never decorative.

   Theming has three states. Bare :root carries the complete light palette.
   The media query covers viewers on "system". The [data-theme] blocks let an
   explicit choice win in either direction. Components read tokens only —
   no color is ever declared inside a media or [data-theme] block, or it
   would go undefined in the un-stamped state.
   ========================================================================== */

:root {
  --paper:      #EEF0EA;
  --paper-2:    #E5E8E0;
  --card:       #F6F7F3;
  --ink:        #17201E;
  --graphite:   #55615B;
  --faint:      #76827B;
  --accent:     #176B5C;
  --accent-dim: #3D8C7C;
  --declin:     #A83D25;
  --rule:       #C6CDC2;
  --rule-soft:  #D9DED4;
  --veil:       rgba(238, 240, 234, 0.86);

  --display: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", "URW Palladio L", Georgia, serif;
  --body: ui-sans-serif, -apple-system, "Segoe UI Variable Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Consolas, "Liberation Mono", monospace;

  --measure: 68ch;
  --rail: 9.5rem;
  --gap: 2.5rem;
  --bar: 3.25rem;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper:      #0E1412;
    --paper-2:    #131B18;
    --card:       #16201C;
    --ink:        #E4E9E2;
    --graphite:   #9AA69D;
    --faint:      #78857D;
    --accent:     #58C4A9;
    --accent-dim: #3E8F7C;
    --declin:     #E58163;
    --rule:       #27332E;
    --rule-soft:  #1E2925;
    --veil:       rgba(14, 20, 18, 0.86);
  }
}

:root[data-theme="dark"] {
  --paper:      #0E1412;
  --paper-2:    #131B18;
  --card:       #16201C;
  --ink:        #E4E9E2;
  --graphite:   #9AA69D;
  --faint:      #78857D;
  --accent:     #58C4A9;
  --accent-dim: #3E8F7C;
  --declin:     #E58163;
  --rule:       #27332E;
  --rule-soft:  #1E2925;
  --veil:       rgba(14, 20, 18, 0.86);
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--bar) + 1rem);
  /* The hero canvas is deliberately wider than its column. Clipping here as
     well as on body keeps that bleed from creating a document-level
     horizontal scrollbar. */
  overflow-x: hidden;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--body);
  font-size: 17px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

::selection { background: var(--accent); color: var(--paper); }

a { color: var(--accent); text-underline-offset: 3px; text-decoration-thickness: 1px; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}

h1, h2, h3 {
  margin: 0;
  font-family: var(--display);
  font-weight: 600;
  letter-spacing: -0.01em;
  text-wrap: balance;
}

p { margin: 0; }
code { font-family: var(--mono); font-size: 0.88em; }

.skip {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  background: var(--accent);
  color: var(--paper);
  padding: 0.6rem 1rem;
  font-family: var(--mono);
  font-size: 0.75rem;
}
.skip:focus { left: 0.5rem; top: 0.5rem; }

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

.bar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--bar);
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0 1.5rem;
  background: var(--veil);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s ease;
}
.bar.is-stuck { border-bottom-color: var(--rule-soft); }

.bar-mark {
  font-family: var(--display);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
  text-decoration: none;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.bar.is-stuck .bar-mark { opacity: 1; }
.bar-mark em { font-style: normal; color: var(--accent); }

.bar-nav { margin-left: auto; display: flex; gap: 1.25rem; }
.bar-nav a {
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--faint);
  text-decoration: none;
}
.bar-nav a:hover { color: var(--accent); }

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 2px;
  background: transparent;
  color: var(--graphite);
  cursor: pointer;
}
.theme-toggle:hover { color: var(--accent); border-color: var(--accent); }
.theme-toggle svg { width: 15px; height: 15px; display: block; }
.theme-toggle .icon-dark { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-dark { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-light { display: none; }

/* ---------- shell ---------- */

.sheet {
  max-width: calc(var(--rail) + var(--gap) + var(--measure) + 3rem);
  margin: 0 auto;
  padding: 0 1.5rem;
}

.row {
  display: grid;
  grid-template-columns: var(--rail) minmax(0, var(--measure));
  gap: var(--gap);
  align-items: start;
}

.row > .rail {
  position: sticky;
  top: calc(var(--bar) + 1.5rem);
  min-height: 2.2rem;
  padding-top: 0.55rem;
  padding-right: 0.85rem;
  border-right: 1px solid var(--rule-soft);
  font-family: var(--mono);
  font-size: 0.66rem;
  line-height: 1.5;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-align: right;
  color: var(--faint);
}
.rail b { display: block; color: var(--accent); font-weight: 600; letter-spacing: 0.1em; }

.band { padding: 4.5rem 0; border-top: 1px solid var(--rule-soft); }
.band-hero { padding: 4rem 0 4rem; border-top: 0; }

.stack   { display: flex; flex-direction: column; gap: 1.15rem; }
.stack-l { display: flex; flex-direction: column; gap: 2.25rem; }

h2 { font-size: clamp(1.6rem, 3.4vw, 2.1rem); line-height: 1.15; }
h3 { font-size: 1.12rem; line-height: 1.3; }
.lede { font-size: 1.16rem; line-height: 1.55; color: var(--graphite); }
.muted { color: var(--graphite); }
.small { font-size: 0.9rem; }

.eyebrow {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--faint);
}

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

.hero { position: relative; }

/* Full-bleed: centred on the hero, exactly one viewport wide. */
#contours {
  position: absolute;
  top: -3rem;
  left: 50%;
  transform: translateX(-50%);
  width: 100vw;
  height: 100%;
  z-index: 0;
  opacity: 0.55;
  pointer-events: none;
}
.hero > *:not(#contours) { position: relative; z-index: 1; }

.wordmark {
  margin: 0.7rem 0 0;
  font-family: var(--display);
  font-size: clamp(2.9rem, 8vw, 4.6rem);
  line-height: 0.98;
  letter-spacing: -0.028em;
}
.wordmark em { font-style: normal; color: var(--accent); }

.hero-sub {
  max-width: 52ch;
  margin-top: 1.1rem;
  font-size: 1.2rem;
  line-height: 1.5;
  color: var(--graphite);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1.9rem;
  padding: 0.3rem 0.75rem;
  border: 1px solid var(--rule);
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--graphite);
}
.status i { display: block; width: 6px; height: 6px; border-radius: 50%; background: var(--declin); }

/* ---------- instruments ---------- */

.instrument {
  margin-top: 3rem;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 3px;
}
.instrument-head {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1.5rem;
  justify-content: space-between;
  align-items: baseline;
  padding: 0.9rem 1.15rem;
  border-bottom: 1px solid var(--rule-soft);
}
.instrument-head .q { font-family: var(--mono); font-size: 0.82rem; color: var(--ink); }
.instrument-body { padding: 0.5rem 0.5rem 0; overflow-x: auto; }

svg.plot { display: block; width: 100%; height: auto; min-width: 470px; }

.plot .grid { stroke: var(--rule-soft); stroke-width: 1; }
.plot .wedge { fill: var(--accent); opacity: 0.12; }
.plot .wedge-edge { fill: none; stroke: var(--accent); stroke-width: 1; stroke-dasharray: 4 4; opacity: 0.8; }
.plot .halo { fill: var(--accent); opacity: 0.13; }
.plot .halo-edge { fill: none; stroke: var(--accent); stroke-width: 1.25; }
.plot .axis { stroke: var(--accent); stroke-width: 1.25; }
.plot .anchor { fill: var(--ink); }
.plot .target { fill: var(--accent); }
.plot .pin { fill: none; stroke: var(--declin); stroke-width: 1.5; }
.plot .pin-fill { fill: var(--declin); }
.plot .err { stroke: var(--declin); stroke-width: 1.25; stroke-dasharray: 3 3; }
.plot text { font-family: var(--mono); font-size: 10px; letter-spacing: 0.06em; fill: var(--faint); }
.plot text.lbl-ink { fill: var(--ink); }
.plot text.lbl-acc { fill: var(--accent); }
.plot text.lbl-err { fill: var(--declin); }

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.25rem;
  padding: 1rem 1.15rem 1.15rem;
  border-top: 1px solid var(--rule-soft);
}
.controls label {
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--faint);
}
.controls .val {
  min-width: 4.5rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1 1 200px;
  height: 22px;
  background: transparent;
  cursor: ew-resize;
}
input[type="range"]::-webkit-slider-runnable-track { height: 2px; background: var(--rule); }
input[type="range"]::-moz-range-track { height: 2px; background: var(--rule); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px;
  height: 15px;
  margin-top: -6.5px;
  border: 2px solid var(--card);
  border-radius: 50%;
  background: var(--accent);
}
input[type="range"]::-moz-range-thumb {
  width: 15px;
  height: 15px;
  border: 2px solid var(--card);
  border-radius: 50%;
  background: var(--accent);
}

.readout {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(122px, 1fr));
  gap: 1px;
  margin: 0;
  background: var(--rule-soft);
  border-top: 1px solid var(--rule-soft);
}
.readout > div { background: var(--card); padding: 0.8rem 1.15rem; }
.readout dt {
  margin: 0 0 0.25rem;
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--faint);
}
.readout dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.readout dd.is-err { color: var(--declin); }
.readout dd.is-acc { color: var(--accent); }

.caption {
  margin-top: 0.85rem;
  font-size: 0.85rem;
  line-height: 1.55;
  color: var(--faint);
}

.noscript {
  margin-top: 1rem;
  padding: 0.8rem 1rem;
  border: 1px solid var(--rule);
  border-radius: 3px;
  font-size: 0.9rem;
  color: var(--graphite);
}

/* ---------- quote + comparison ---------- */

blockquote {
  margin: 0;
  padding-left: 1.15rem;
  border-left: 2px solid var(--accent);
  font-family: var(--display);
  font-size: 1.45rem;
  line-height: 1.4;
  color: var(--ink);
}
blockquote cite {
  display: block;
  margin-top: 0.8rem;
  font-family: var(--mono);
  font-style: normal;
  font-size: 0.68rem;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--faint);
}

.compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--rule-soft);
  border: 1px solid var(--rule-soft);
  border-radius: 3px;
}
.compare > div {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 1.15rem;
  background: var(--card);
}
.compare h3 {
  font-family: var(--mono);
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.compare h3.is-bad { color: var(--declin); }
.compare h3.is-good { color: var(--accent); }
.compare .coord { font-family: var(--mono); font-size: 0.86rem; font-variant-numeric: tabular-nums; }
.compare ul { margin: 0; padding-left: 1.05rem; font-size: 0.92rem; color: var(--graphite); }
.compare li { margin-bottom: 0.3rem; }

/* ---------- stages ---------- */

.stages { display: flex; flex-direction: column; }
.stage {
  display: grid;
  grid-template-columns: 2.6rem minmax(0, 1fr);
  gap: 1.25rem;
  padding: 1.35rem 0;
  border-top: 1px solid var(--rule-soft);
}
.stage:first-child { padding-top: 0; border-top: 0; }
.stage .n {
  padding-top: 0.2rem;
  font-family: var(--mono);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
  color: var(--accent);
}
.stage .n small {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.6rem;
  letter-spacing: 0.08em;
  color: var(--faint);
}
.stage p { margin-top: 0.4rem; font-size: 0.97rem; color: var(--graphite); }
.stage .tag {
  display: inline-block;
  margin-left: 0.5rem;
  padding: 0.08rem 0.4rem;
  border: 1px solid var(--rule);
  border-radius: 2px;
  vertical-align: 0.15em;
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--faint);
}

/* ---------- code ---------- */

.code {
  background: var(--paper-2);
  border: 1px solid var(--rule-soft);
  border-radius: 3px;
  overflow-x: auto;
}
.code-head {
  padding: 0.55rem 1rem;
  border-bottom: 1px solid var(--rule-soft);
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--faint);
}
pre {
  margin: 0;
  padding: 1rem;
  font-family: var(--mono);
  font-size: 0.81rem;
  line-height: 1.6;
  color: var(--ink);
}
.k { color: var(--accent); }
.s { color: var(--graphite); }
.c { color: var(--faint); font-style: italic; }

/* ---------- tables ---------- */

.tw { border: 1px solid var(--rule-soft); border-radius: 3px; overflow-x: auto; }
table { width: 100%; min-width: 460px; border-collapse: collapse; font-size: 0.92rem; }
th, td {
  padding: 0.62rem 0.9rem;
  border-bottom: 1px solid var(--rule-soft);
  text-align: left;
  vertical-align: top;
}
thead th {
  background: var(--paper-2);
  font-family: var(--mono);
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--faint);
}
tbody tr:last-child td { border-bottom: 0; }
td.num { font-family: var(--mono); font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.pending { font-family: var(--mono); color: var(--faint); }

/* ---------- conformal ---------- */

.conformal { background: var(--card); border: 1px solid var(--rule); border-radius: 3px; }
.conformal .instrument-body { padding: 1.15rem 1.15rem 0.35rem; }

.alpha {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0 1.15rem 1.15rem;
}
.alpha button {
  padding: 0.32rem 0.7rem;
  border: 1px solid var(--rule);
  border-radius: 2px;
  background: transparent;
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  color: var(--graphite);
  cursor: pointer;
}
.alpha button[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--card);
}

.cf .ok { fill: var(--accent-dim); }
.cf .miss { fill: var(--declin); }
.cf .is-dim { opacity: 0.2; }
.cf .tau { stroke: var(--ink); stroke-width: 1.5; }
.cf .base { stroke: var(--rule); stroke-width: 1; }

/* ---------- misc ---------- */

.note {
  padding-left: 1.05rem;
  border-left: 2px solid var(--declin);
  font-size: 0.95rem;
  color: var(--graphite);
}
.note strong { color: var(--ink); }

.kv {
  display: grid;
  grid-template-columns: minmax(7rem, auto) 1fr;
  gap: 0.5rem 1.25rem;
  margin: 0;
  font-size: 0.94rem;
}
.kv dt {
  padding-top: 0.3rem;
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--faint);
}
.kv dd { margin: 0; color: var(--graphite); }
.kv dd b { color: var(--ink); font-weight: 600; }

.checklist {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.95rem;
}
.checklist li {
  display: grid;
  grid-template-columns: 2.9rem 1fr;
  gap: 0.6rem;
  color: var(--graphite);
}
.checklist .m {
  padding-top: 0.3rem;
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--faint);
}
.checklist .m.is-done { color: var(--accent); }

.site-footer {
  padding: 3rem 0 4rem;
  border-top: 1px solid var(--rule-soft);
  font-size: 0.86rem;
  color: var(--faint);
}
.site-footer .fine {
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* ---------- responsive ---------- */

@media (max-width: 860px) {
  .bar-nav { display: none; }
  .bar-mark { opacity: 1; margin-right: auto; }
}

@media (max-width: 760px) {
  body { font-size: 16px; }
  .row { grid-template-columns: minmax(0, 1fr); gap: 1rem; }
  .row > .rail {
    position: static;
    padding: 0 0 0 0.7rem;
    border-right: 0;
    border-left: 2px solid var(--accent);
    text-align: left;
    min-height: 0;
  }
  .rail b { display: inline; }
  .compare { grid-template-columns: 1fr; }
  .band { padding: 3.25rem 0; }
  .kv { grid-template-columns: 1fr; gap: 0.15rem 0; }
  .kv dd { margin-bottom: 0.8rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
