/* ==========================================================================
   Hamn to Horn — V4
   A dark/light editorial site with a satellite map feathered into a faint
   volcanic texture. Design tokens live in :root; theming is a single
   data-theme swap. No image assets for chrome — texture, map mask and the
   depth glow are all generated.
   ========================================================================== */

/* ---- Tokens -------------------------------------------------------------- */
:root {
  /* type */
  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  /* fluid type scale */
  --step--1: clamp(0.82rem, 0.79rem + 0.12vw, 0.88rem);
  --step-0:  clamp(1rem, 0.96rem + 0.2vw, 1.12rem);
  --step-1:  clamp(1.2rem, 1.1rem + 0.5vw, 1.5rem);
  --step-2:  clamp(1.6rem, 1.4rem + 1vw, 2.2rem);
  --step-3:  clamp(2.6rem, 2rem + 3vw, 4.6rem);

  /* spacing scale */
  --space-2xs: 0.5rem;
  --space-xs: 0.75rem;
  --space-s: 1rem;
  --space-m: 1.5rem;
  --space-l: 2.5rem;
  --space-xl: clamp(3.5rem, 8vh, 6rem);
  --space-2xl: clamp(5rem, 13vh, 9rem);

  --radius: 16px;
  --radius-s: 11px;
  --measure: 62ch;
  --shell: 1240px;

  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);

  color-scheme: dark;
}

/* Dark — ember on warm basalt */
:root[data-theme="dark"] {
  --bg: #14110f;
  --surface: rgba(255, 255, 255, 0.045);
  --surface-solid: #1c1815;
  --line: rgba(255, 255, 255, 0.10);
  --hairline: rgba(255, 255, 255, 0.07);
  --ink: #efeae3;
  --ink-soft: rgba(239, 234, 227, 0.66);
  --ink-faint: rgba(239, 234, 227, 0.40);
  --accent: #ea8259;
  --accent-ink: #1a1009;        /* text on an accent fill */
  --glow: rgba(234, 130, 89, 0.22);
  --scrim: rgba(8, 6, 5, 0.66);
  --grain: 0.07;
  color-scheme: dark;
}

/* Light — clay on off-white paper */
:root[data-theme="light"] {
  --bg: #f4f0e8;
  --surface: rgba(40, 31, 24, 0.035);
  --surface-solid: #fcfaf4;
  --line: rgba(40, 31, 24, 0.14);
  --hairline: rgba(40, 31, 24, 0.09);
  --ink: #241f1a;
  --ink-soft: rgba(36, 31, 26, 0.66);
  --ink-faint: rgba(36, 31, 26, 0.42);
  --accent: #bc5530;
  --accent-ink: #fff;
  --glow: rgba(120, 150, 165, 0.30);   /* cool sea-mist lift on paper */
  --scrim: rgba(45, 38, 32, 0.42);
  --grain: 0.05;
  color-scheme: light;
}

/* ---- Base ---------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--step-0);
  line-height: 1.65;
  color: var(--ink);
  background-color: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color 0.4s var(--ease), color 0.4s var(--ease);
}

/* Faint volcanic grain: a fixed full-page layer of fine + coarse SVG
   turbulence. No image files. Per-theme strength via the --grain token. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: var(--grain);
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='260'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='260' height='260' filter='url(%23g)'/%3E%3C/svg%3E"),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1000' height='1000'%3E%3Cfilter id='m'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.0035' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='1000' height='1000' filter='url(%23m)' opacity='0.7'/%3E%3C/svg%3E");
}

h1, h2, h3 { font-family: var(--font-display); font-weight: 500; line-height: 1.1; margin: 0; }

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

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

.skip-link {
  position: fixed;
  top: -100px;
  left: 12px;
  z-index: 1000;
  padding: 10px 16px;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 8px;
  font-weight: 600;
  transition: top 0.2s var(--ease);
}
.skip-link:focus { top: 12px; text-decoration: none; }

/* ---- Reveal-on-scroll ---------------------------------------------------- */
.reveal {
  opacity: 0;
  transform: translateY(18px);
  transition: opacity 0.7s var(--ease), transform 0.7s var(--ease);
}
.reveal.in { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .reveal { opacity: 1; transform: none; transition: none; }
}

/* ---- Nav ----------------------------------------------------------------- */
.nav {
  position: sticky;
  top: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-s);
  padding: 14px clamp(16px, 4vw, 48px);
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  backdrop-filter: blur(16px) saturate(1.4);
  border-bottom: 1px solid var(--hairline);
}

.wordmark {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--step-1);
  letter-spacing: -0.01em;
  color: var(--ink);
}
.wordmark:hover { text-decoration: none; }

.nav-links {
  display: flex;
  align-items: center;
  gap: clamp(14px, 2.4vw, 30px);
}

.nav-links > a {
  font-size: var(--step--1);
  font-weight: 500;
  color: var(--ink-soft);
}
.nav-links > a:hover { color: var(--ink); text-decoration: none; }
.nav-ig { color: var(--accent) !important; }

.theme-toggle {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  transition: color 0.2s var(--ease), border-color 0.2s var(--ease), transform 0.4s var(--ease);
}
.theme-toggle:hover { color: var(--ink); border-color: var(--accent); transform: rotate(35deg); }
.theme-toggle svg { grid-area: 1 / 1; }
:root[data-theme="dark"]  .icon-sun  { display: none; }
:root[data-theme="light"] .icon-moon { display: none; }

/* ---- Hero ---------------------------------------------------------------- */
.hero {
  max-width: 920px;
  margin: 0 auto;
  padding: clamp(56px, 11vh, 120px) 24px var(--space-l);
  text-align: center;
}

.eyebrow {
  margin: 0 0 var(--space-m);
  font-size: var(--step--1);
  font-weight: 600;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: var(--accent);
}

.display {
  font-size: var(--step-3);
  letter-spacing: -0.02em;
}

.lede {
  max-width: 34em;
  margin: var(--space-m) auto 0;
  font-size: var(--step-1);
  line-height: 1.5;
  color: var(--ink-soft);
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, auto);
  justify-content: center;
  gap: clamp(20px, 5vw, 64px);
  margin: var(--space-xl) 0 0;
}
.stat { display: flex; flex-direction: column-reverse; gap: 4px; }
.stat dt {
  font-size: var(--step--1);
  font-weight: 600;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.stat dd {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: var(--step-2);
  font-variant-numeric: tabular-nums lining-nums;
}

@media (max-width: 560px) {
  .stats { grid-template-columns: repeat(2, auto); gap: 22px 40px; }
}

/* ---- Map ----------------------------------------------------------------- */
.map-section { padding: var(--space-l) 0 var(--space-xl); }

.map-stage {
  position: relative;
  max-width: var(--shell);
  margin: 0 auto;
}

/* depth: a soft glow behind the island so it lifts off the texture */
.map-glow {
  position: absolute;
  inset: 6% 8%;
  z-index: 0;
  background: radial-gradient(closest-side, var(--glow), transparent 72%);
  filter: blur(34px);
  pointer-events: none;
}

/* organic, gradual feather — an SVG radial gradient warped by turbulence so
   the edge wanders like a coastline. Long ramp (solid only to ~44%). Tune the
   gradient stops for the ramp, or seed/scale for the coastline shape. */
.map-feather {
  position: relative;
  z-index: 1;
  --mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1200 800' preserveAspectRatio='none'%3E%3Cdefs%3E%3CradialGradient id='g' cx='50%25' cy='50%25' r='50%25'%3E%3Cstop offset='44%25' stop-color='%23fff'/%3E%3Cstop offset='64%25' stop-color='%23fff' stop-opacity='0.82'/%3E%3Cstop offset='83%25' stop-color='%23fff' stop-opacity='0.36'/%3E%3Cstop offset='100%25' stop-color='%23fff' stop-opacity='0'/%3E%3C/radialGradient%3E%3Cfilter id='w' x='-25%25' y='-25%25' width='150%25' height='150%25'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.006 0.009' numOctaves='3' seed='7'/%3E%3CfeDisplacementMap in='SourceGraphic' scale='118'/%3E%3C/filter%3E%3C/defs%3E%3Cellipse cx='600' cy='400' rx='552' ry='352' fill='url(%23g)' filter='url(%23w)'/%3E%3C/svg%3E");
  -webkit-mask-image: var(--mask);
  mask-image: var(--mask);
  -webkit-mask-size: 100% 100%; mask-size: 100% 100%;
  -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
}

#map {
  width: 100%;
  height: clamp(440px, 84svh, 820px);
  background: transparent;
}
.leaflet-container { background: transparent; font-family: var(--font-sans); }

.map-controls {
  position: absolute;
  z-index: 2;
  right: clamp(14px, 5vw, 56px);
  bottom: clamp(40px, 9%, 92px);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.map-controls button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface-solid) 80%, transparent);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: var(--ink);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.15s var(--ease), box-shadow 0.15s var(--ease), border-color 0.15s var(--ease);
}
.map-controls button:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.28);
}

.map-caption {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 18px;
  max-width: var(--shell);
  margin: var(--space-s) auto 0;
  padding: 0 24px;
  text-align: center;
  font-size: var(--step--1);
}
.map-caption .hint { color: var(--ink-soft); }
.map-caption .credit { color: var(--ink-faint); }
.map-caption .credit a { color: inherit; }

/* ---- Dispatch cards ------------------------------------------------------ */
.updates {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(244px, 1fr));
  gap: var(--space-s);
  max-width: 1040px;
  margin: var(--space-l) auto 0;
  padding: 0 24px;
}

.dispatch {
  all: unset;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 20px 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  transition: transform 0.2s var(--ease), border-color 0.2s var(--ease), background 0.2s var(--ease);
}
.dispatch:hover { transform: translateY(-3px); border-color: var(--accent); }
.dispatch:focus-visible { outline-offset: 2px; }
.dispatch.is-active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 9%, var(--surface)); }

.dispatch-top { display: flex; align-items: center; gap: 10px; }
.dispatch .num {
  display: grid;
  place-items: center;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.78rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.dispatch .d-day {
  font-size: var(--step--1);
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.dispatch h3 {
  font-size: var(--step-1);
  font-weight: 500;
  line-height: 1.25;
}
.dispatch .d-peek { font-size: var(--step--1); color: var(--ink-soft); margin: 0; }

.updates-empty { text-align: center; color: var(--ink-soft); margin-top: var(--space-l); }

/* ---- Generic sections ---------------------------------------------------- */
.section {
  max-width: var(--shell);
  margin: 0 auto;
  padding: var(--space-2xl) 24px 0;
}
.section-index {
  margin: 0 0 var(--space-m);
  font-size: var(--step--1);
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
}
.section-title { font-size: var(--step-2); letter-spacing: -0.01em; }

.prose { max-width: var(--measure); }
.prose p { margin: 0 0 var(--space-m); color: var(--ink-soft); }
.prose .lead-para {
  font-family: var(--font-display);
  font-size: var(--step-1);
  line-height: 1.5;
  color: var(--ink);
}

/* ---- Elevation ----------------------------------------------------------- */
.elev-figure { margin: var(--space-m) 0 0; }
.elev-stage {
  position: relative;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 12%, #000 88%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 12%, #000 88%, transparent);
}
#elevation { display: block; width: 100%; height: 170px; cursor: crosshair; }
.elev-readout {
  position: absolute;
  top: 2px; right: 12%;
  font-size: var(--step--1);
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
  pointer-events: none;
}
.elev-figure figcaption {
  margin-top: var(--space-xs);
  font-size: var(--step--1);
  color: var(--ink-faint);
}

/* ---- Crew ---------------------------------------------------------------- */
.crew {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-m);
  margin-top: var(--space-l);
}
@media (max-width: 640px) { .crew { grid-template-columns: 1fr; } }

.crew-card {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.crew-card img { width: 100%; height: 260px; object-fit: cover; }
.crew-body { padding: var(--space-m) var(--space-m) calc(var(--space-m) + 4px); }
.crew-body h3 { font-size: var(--step-2); margin-bottom: var(--space-2xs); }
.crew-body p { margin: 0 0 var(--space-s); font-size: var(--step--1); color: var(--ink-soft); }
.crew-link { font-weight: 600; font-size: var(--step--1); }

/* ---- Footer -------------------------------------------------------------- */
.footer {
  max-width: var(--shell);
  margin: var(--space-2xl) auto 0;
  padding: var(--space-xl) 24px var(--space-l);
  border-top: 1px solid var(--hairline);
  text-align: center;
}
.footer-mark { font-family: var(--font-display); font-size: var(--step-1); margin: 0 0 var(--space-xs); }
.footer-social { display: flex; justify-content: center; gap: var(--space-m); margin: 0 0 var(--space-s); }
.footer-social a { font-weight: 600; }
.footer-fine { font-size: var(--step--1); color: var(--ink-faint); margin: 0; }

/* ---- Dispatch dialog ----------------------------------------------------- */
.dialog-scrim {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  padding: 16px;
  background: var(--scrim);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  animation: fade 0.2s var(--ease);
}
.dialog {
  position: relative;
  width: min(560px, 100%);
  max-height: 88svh;
  overflow-y: auto;
  padding: clamp(22px, 4vw, 32px);
  background: var(--surface-solid);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 36px 90px rgba(0, 0, 0, 0.5);
  animation: rise 0.24s var(--ease);
}
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(10px) scale(0.99); } }
@media (prefers-reduced-motion: reduce) {
  .dialog-scrim, .dialog { animation: none; }
}
.dialog-close {
  position: absolute;
  top: 12px; right: 14px;
  width: 34px; height: 34px;
  border: 0; border-radius: 50%;
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}
.dialog-close:hover { color: var(--ink); }
.d-date {
  margin: 0;
  font-size: var(--step--1);
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}
.d-title { font-size: var(--step-2); margin: 6px 0 10px; }
.d-caption { margin: 0 0 var(--space-s); color: var(--ink-soft); }
.d-media img, .d-media video { width: 100%; border-radius: var(--radius-s); margin-bottom: 10px; display: block; }

/* ---- Markers ------------------------------------------------------------- */
.pin {
  display: grid;
  place-items: center;
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 13px;
  border: 2px solid var(--surface-solid);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
  transition: transform 0.18s var(--ease), box-shadow 0.18s var(--ease);
}
.pin:hover { transform: scale(1.12); }
.pin.is-active {
  transform: scale(1.28);
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 32%, transparent), 0 2px 10px rgba(0, 0, 0, 0.45);
}

/* one-time route draw-in (set by JS, respects reduced motion) */
.route-draw { stroke-dasharray: var(--len); stroke-dashoffset: var(--len); }
.route-draw.go { transition: stroke-dashoffset 2.1s var(--ease); stroke-dashoffset: 0; }

/* ---- Data note ----------------------------------------------------------- */
.data-note {
  position: fixed;
  left: 50%; bottom: 16px;
  z-index: 2100;
  transform: translateX(-50%);
  max-width: min(480px, calc(100vw - 32px));
  padding: 12px 18px;
  font-size: var(--step--1);
  background: var(--surface-solid);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
}
.data-note code { font-size: 0.92em; }

/* ---- Responsive ---------------------------------------------------------- */
@media (max-width: 720px) {
  .nav-ig { display: none; }
  #map { height: clamp(400px, 66svh, 600px); }
}
