:root {
  --font-display: "Caprasimo", "Georgia", serif;
  --font-body: "Vollkorn", "Iowan Old Style", "Georgia", serif;

  --space-2xs: 4px;
  --space-xs: 8px;
  --space-sm: 12px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;
  --space-3xl: 64px;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 14px;

  --hairline: 1px;

  --topbar-h: 76px;
  --footer-h: 40px;
  --margin-w: 360px;
}

:root[data-theme="light"] {
  --paper:        oklch(98.5% 0.012 82);
  --paper-2:      oklch(96%   0.015 82);
  --paper-3:      oklch(93%   0.018 80);
  --ink:          oklch(22%   0.025 60);
  --ink-soft:     oklch(38%   0.025 60);
  --ink-mute:     oklch(55%   0.020 60);
  --rule:         oklch(85%   0.020 70);
  --rule-strong:  oklch(72%   0.025 60);

  --terracotta:   oklch(58%   0.155 38);
  --terracotta-2: oklch(50%   0.145 35);
  --cobalt:       oklch(48%   0.135 248);
  --saffron:      oklch(72%   0.150 78);
  --moss:         oklch(52%   0.105 142);
  --plum:         oklch(45%   0.120 340);
  --ochre:        oklch(62%   0.120 65);

  --kind-birth:   var(--moss);
  --kind-death:   var(--plum);
  --kind-work:    var(--terracotta);

  --map-cluster-fill:   oklch(58% 0.155 38 / 0.92);
  --map-cluster-stroke: oklch(20% 0.025 60);
  --map-cluster-text:   oklch(98% 0.012 82);
  --map-marker-stroke:  oklch(18% 0.020 60 / 0.85);
  --map-attribution-bg: oklch(98% 0.012 82 / 0.85);

  --shadow-detail: 0 2px 0 oklch(20% 0.02 60 / 0.04),
                   0 24px 60px oklch(20% 0.02 60 / 0.10),
                   0 8px 24px oklch(20% 0.02 60 / 0.05);

  color-scheme: light;
}

:root[data-theme="dark"] {
  --paper:        oklch(17%   0.018 60);
  --paper-2:      oklch(21%   0.020 60);
  --paper-3:      oklch(25%   0.022 60);
  --ink:          oklch(92%   0.015 80);
  --ink-soft:     oklch(78%   0.018 75);
  --ink-mute:     oklch(60%   0.020 70);
  --rule:         oklch(30%   0.020 60);
  --rule-strong:  oklch(42%   0.025 60);

  --terracotta:   oklch(72%   0.140 40);
  --terracotta-2: oklch(80%   0.130 45);
  --cobalt:       oklch(70%   0.120 245);
  --saffron:      oklch(82%   0.140 82);
  --moss:         oklch(72%   0.110 145);
  --plum:         oklch(72%   0.110 340);
  --ochre:        oklch(75%   0.115 68);

  --kind-birth:   var(--moss);
  --kind-death:   var(--plum);
  --kind-work:    var(--terracotta);

  --map-cluster-fill:   oklch(70% 0.130 40 / 0.92);
  --map-cluster-stroke: oklch(95% 0.015 80);
  --map-cluster-text:   oklch(17% 0.018 60);
  --map-marker-stroke:  oklch(95% 0.015 80 / 0.85);
  --map-attribution-bg: oklch(20% 0.020 60 / 0.85);

  --shadow-detail: 0 2px 0 oklch(0% 0 0 / 0.20),
                   0 24px 60px oklch(0% 0 0 / 0.50),
                   0 8px 24px oklch(0% 0 0 / 0.30);

  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  display: grid;
  grid-template-columns: var(--margin-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr var(--footer-h);
  grid-template-areas:
    "topbar topbar"
    "margin map"
    "footer footer";
  height: 100vh;
  overflow: hidden;
}

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

::selection { background: var(--saffron); color: var(--ink); }

/* ── Topbar ─────────────────────────────────────────────────── */

.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 clamp(var(--space-md), 2vw, var(--space-xl));
  background: var(--paper-2);
  border-bottom: var(--hairline) solid var(--rule);
  z-index: 6;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  color: var(--ink);
  font-family: var(--font-display);
  font-size: clamp(20px, 1.6vw, 26px);
  letter-spacing: -0.01em;
  text-decoration: none;
}
.brand:hover { color: var(--ink); text-decoration: none; }
.brand-text { line-height: 1; padding-top: 4px; }

.brand-rose { width: 30px; height: 30px; }
.brand-rose .rose-ring { fill: none; stroke: var(--rule-strong); stroke-width: 1.2; }
.brand-rose .rose-quill { fill: var(--terracotta); }
.brand-rose .rose-brush { fill: var(--cobalt); opacity: 0.75; }
.brand-rose .rose-pin { fill: var(--ink); }

.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.meta {
  font-family: var(--font-body);
  font-style: italic;
  font-size: 13px;
  color: var(--ink-mute);
  text-align: right;
  line-height: 1.35;
  max-width: 320px;
}

.theme-toggle {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  background: transparent;
  color: var(--ink-soft);
  border: var(--hairline) solid var(--rule);
  border-radius: 999px;
  cursor: pointer;
  transition: color .2s ease, border-color .2s ease, background .2s ease;
}
.theme-toggle:hover {
  color: var(--terracotta);
  border-color: var(--terracotta);
  background: oklch(from var(--terracotta) l c h / 0.08);
}
.theme-toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; }
:root[data-theme="light"] .icon-moon { display: none; }
:root[data-theme="dark"] .icon-sun { display: none; }
:root[data-theme="dark"] .icon-moon { fill: currentColor; stroke: none; }

/* ── Margin (editorial sidebar) ─────────────────────────────── */

.margin {
  grid-area: margin;
  background: var(--paper);
  border-right: var(--hairline) solid var(--rule);
  overflow-y: auto;
  padding: var(--space-xl) var(--space-xl) var(--space-2xl);
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

.m-section { display: flex; flex-direction: column; gap: var(--space-sm); }

.m-section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-sm);
}

.m-title {
  margin: 0 0 var(--space-xs);
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 28px;
  line-height: 1;
  color: var(--ink);
}

.m-rule {
  border: 0;
  height: var(--hairline);
  background: var(--rule);
  margin: var(--space-sm) 0;
  width: 100%;
}

/* ── Year section (hero control) ────────────────────────────── */

.year-section { gap: var(--space-md); }

.year-readout {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-2xs) var(--space-xs);
  line-height: 1;
  margin-bottom: var(--space-xs);
}
.year-prefix {
  font-family: var(--font-body);
  font-style: italic;
  font-size: 13px;
  color: var(--ink-mute);
}
.year-value {
  font-family: var(--font-display);
  font-size: clamp(46px, 5vw, 60px);
  letter-spacing: -0.02em;
  color: var(--terracotta);
  font-variant-numeric: tabular-nums;
  line-height: 0.95;
}
.year-suffix {
  font-family: var(--font-body);
  font-style: italic;
  font-size: 13px;
  color: var(--ink-mute);
}

body[data-snapshot="off"] .year-value { color: var(--ink-mute); opacity: 0.55; }
body[data-snapshot="off"] .year-prefix::before { content: "across "; }
body[data-snapshot="off"] .year-prefix { font-style: italic; }
body[data-snapshot="off"] .year-suffix::before { content: "(all of it)"; }

.year-controls {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.play-btn {
  flex: none;
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  background: var(--paper-2);
  color: var(--terracotta-2);
  border: var(--hairline) solid var(--rule-strong);
  border-radius: 999px;
  cursor: pointer;
  transition: color .2s ease, border-color .2s ease, background .2s ease, transform .2s ease;
}
.play-btn:hover {
  color: var(--terracotta);
  border-color: var(--terracotta);
  background: oklch(from var(--terracotta) l c h / 0.08);
}
.play-btn:active { transform: scale(0.95); }
.play-btn svg { width: 14px; height: 14px; fill: currentColor; }
.play-btn .icon-pause { display: none; }
body[data-playing="true"] .play-btn .icon-play { display: none; }
body[data-playing="true"] .play-btn .icon-pause { display: block; }
body[data-snapshot="off"] .play-btn { opacity: 0.4; pointer-events: none; }

.year-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: linear-gradient(to right,
    var(--saffron) 0%,
    var(--saffron) var(--slider-pct, 50%),
    var(--rule) var(--slider-pct, 50%),
    var(--rule) 100%);
  border-radius: 999px;
  outline: none;
  cursor: pointer;
}
.year-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--paper);
  border: 2.5px solid var(--terracotta);
  box-shadow: 0 2px 6px oklch(20% 0.025 60 / 0.18);
  cursor: pointer;
  transition: transform .15s ease;
}
.year-slider::-webkit-slider-thumb:hover { transform: scale(1.15); }
.year-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--paper);
  border: 2.5px solid var(--terracotta);
  box-shadow: 0 2px 6px oklch(20% 0.025 60 / 0.18);
  cursor: pointer;
}
body[data-snapshot="off"] .year-slider { opacity: 0.4; pointer-events: none; }

.year-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-xs);
  font-size: 12.5px;
  color: var(--ink-mute);
  font-variant-numeric: tabular-nums;
}
.year-bounds { font-style: italic; }

/* ── Kind list ──────────────────────────────────────────────── */

.kind-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: var(--space-2xs);
}

.kind-row {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  align-items: center;
  gap: var(--space-sm);
  padding: 7px 6px 7px 2px;
  cursor: pointer;
  user-select: none;
  font-size: 15px;
  color: var(--ink);
  border-radius: var(--radius-sm);
  transition: background .15s ease, opacity .15s ease;
}
.kind-row:hover { background: var(--paper-2); }
.kind-row.off { opacity: 0.35; }
.kind-row.off:hover { opacity: 0.55; }

.kind-glyph {
  width: 22px;
  height: 22px;
  display: block;
}
.kind-glyph svg { width: 100%; height: 100%; display: block; }
.kind-glyph-birth { color: var(--kind-birth); }
.kind-glyph-death { color: var(--kind-death); }
.kind-glyph-work  { color: var(--kind-work); }

.kind-label {
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.2;
}

.kind-count {
  font-size: 12.5px;
  font-style: italic;
  color: var(--ink-mute);
  font-variant-numeric: tabular-nums;
}

.m-link-group {
  display: inline-flex;
  align-items: baseline;
  gap: var(--space-2xs);
  color: var(--ink-mute);
  font-size: 13px;
}
.link-sep { color: var(--rule-strong); }

.link-btn {
  background: none;
  border: 0;
  color: var(--ink-mute);
  font-family: var(--font-body);
  font-size: 13px;
  font-style: italic;
  cursor: pointer;
  padding: 2px 2px;
  border-bottom: 1px solid transparent;
  transition: color .2s ease, border-color .2s ease;
}
.link-btn:hover { color: var(--terracotta); border-bottom-color: var(--terracotta); }
body[data-snapshot="off"] #year-all { color: var(--terracotta); border-bottom-color: var(--terracotta); }

.m-hint {
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--ink-soft);
}
.m-hint p { margin: 0 0 var(--space-xs); }
.m-hint p:last-child { margin: 0; }
.m-hint em { font-style: italic; color: var(--ink); }
.m-fineprint {
  margin-top: var(--space-sm) !important;
  font-size: 12.5px;
  color: var(--ink-mute);
}

/* ── Map ────────────────────────────────────────────────────── */

#map {
  grid-area: map;
  position: relative;
  background: var(--paper-2);
}

.maplibregl-ctrl-attrib {
  background: var(--map-attribution-bg) !important;
  font-family: var(--font-body) !important;
  font-size: 10.5px !important;
}
.maplibregl-ctrl-attrib a { color: var(--ink-soft); }

.maplibregl-ctrl-group {
  background: var(--paper) !important;
  border: var(--hairline) solid var(--rule) !important;
  box-shadow: none !important;
  border-radius: 999px !important;
  overflow: hidden;
}

/* palette rose on the map */
.compass {
  position: absolute;
  left: clamp(var(--space-md), 2vw, var(--space-xl));
  bottom: clamp(var(--space-2xl), 6vh, var(--space-3xl));
  width: 96px;
  height: 96px;
  pointer-events: none;
  z-index: 1;
  opacity: 0.88;
  filter: drop-shadow(0 2px 8px oklch(20% 0.02 60 / 0.18));
}
.compass-outer { fill: var(--paper); stroke: var(--rule-strong); stroke-width: 1.2; opacity: 0.92; }
.compass-inner { fill: none; stroke: var(--rule); stroke-width: 1; stroke-dasharray: 1 3; }
.palette { fill: var(--paper-2); stroke: var(--ink); stroke-width: 0.8; opacity: 0.95; }
.palette-dot-1 { fill: var(--terracotta); }
.palette-dot-2 { fill: var(--cobalt); }
.palette-dot-3 { fill: var(--saffron); }
.palette-dot-4 { fill: var(--moss); }
.compass-pin { fill: var(--ink); }

/* loading veil */
.loading-veil {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 4;
  background: oklch(from var(--paper) l c h / 0.65);
  backdrop-filter: blur(2px);
  font-family: var(--font-body);
  font-style: italic;
  color: var(--ink-soft);
  font-size: 14px;
  pointer-events: none;
  transition: opacity .35s ease;
}
.loading-veil.gone { opacity: 0; }

/* ── Detail panel ───────────────────────────────────────────── */

.detail {
  position: fixed;
  top: var(--topbar-h);
  right: 0;
  bottom: var(--footer-h);
  width: clamp(360px, 28vw, 440px);
  background: var(--paper);
  border-left: var(--hairline) solid var(--rule);
  box-shadow: var(--shadow-detail);
  z-index: 10;
  transform: translateX(110%);
  transition: transform .35s cubic-bezier(.22,.61,.36,1);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.detail.open { transform: translateX(0); }

.detail-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
  display: inline-grid;
  place-items: center;
  background: transparent;
  border: var(--hairline) solid var(--rule);
  border-radius: 999px;
  cursor: pointer;
  color: var(--ink-soft);
  z-index: 2;
  transition: color .2s ease, border-color .2s ease, transform .2s ease;
}
.detail-close:hover {
  color: var(--terracotta);
  border-color: var(--terracotta);
  transform: rotate(90deg);
}
.detail-close svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }

.detail-body {
  padding: var(--space-2xl) var(--space-xl) var(--space-xl);
  overflow-y: auto;
  flex: 1;
}

.detail-kind {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-body);
  font-size: 12px;
  font-style: italic;
  text-transform: lowercase;
  letter-spacing: 0.02em;
  padding: 4px 10px 4px 8px;
  border-radius: 999px;
  margin-bottom: var(--space-md);
}
.detail-kind .kind-glyph { width: 14px; height: 14px; }

.detail-kind[data-kind="birth"] { background: oklch(from var(--moss) l c h / 0.12);  color: var(--moss); }
.detail-kind[data-kind="death"] { background: oklch(from var(--plum) l c h / 0.12);  color: var(--plum); }
.detail-kind[data-kind="work"]  { background: oklch(from var(--terracotta) l c h / 0.10); color: var(--terracotta-2); }

.detail-title {
  margin: 0 0 var(--space-xs);
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(28px, 2.6vw, 34px);
  line-height: 1.1;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.detail-sub {
  color: var(--ink-mute);
  font-style: italic;
  font-size: 14px;
  margin-bottom: var(--space-lg);
  max-width: 65ch;
}

.detail-image {
  width: 100%;
  max-height: 280px;
  object-fit: cover;
  border-radius: var(--radius-md);
  margin-bottom: var(--space-md);
  background: var(--paper-2);
}

.detail-section {
  margin-top: var(--space-lg);
  padding-top: var(--space-md);
  border-top: var(--hairline) solid var(--rule);
}

.detail-section h4 {
  margin: 0 0 var(--space-xs);
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 15px;
  color: var(--ink);
  letter-spacing: 0;
}

.detail-section p { margin: 0 0 var(--space-xs); line-height: 1.6; max-width: 65ch; }

.lifeline {
  display: inline-flex;
  align-items: baseline;
  gap: var(--space-2xs);
  font-family: var(--font-display);
  font-size: 18px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.lifeline .dash { color: var(--rule-strong); }

.tag-grid {
  display: grid;
  grid-template-columns: minmax(120px, auto) 1fr;
  gap: 4px var(--space-md);
  font-size: 13.5px;
  margin: 0;
}
.tag-grid dt { color: var(--ink-mute); font-style: italic; }
.tag-grid dd { margin: 0; word-break: break-word; color: var(--ink); }

.detail-links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  margin-top: var(--space-2xs);
}
.detail-links a {
  font-size: 13px;
  background: transparent;
  border: var(--hairline) solid var(--rule-strong);
  color: var(--ink);
  padding: 6px 12px;
  border-radius: 999px;
  text-decoration: none;
  transition: color .2s ease, border-color .2s ease, background .2s ease;
}
.detail-links a:hover {
  color: var(--terracotta);
  border-color: var(--terracotta);
  background: oklch(from var(--terracotta) l c h / 0.06);
  text-decoration: none;
}

.skeleton {
  height: 14px;
  background: linear-gradient(90deg, var(--paper-2), var(--paper-3), var(--paper-2));
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
  border-radius: 4px;
  margin: 6px 0;
}
.skeleton.lg { height: 200px; margin-bottom: var(--space-md); border-radius: var(--radius-md); }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ── Footer ─────────────────────────────────────────────────── */

.footer {
  grid-area: footer;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-xs);
  padding: 0 clamp(var(--space-md), 2vw, var(--space-xl));
  background: var(--paper-2);
  border-top: var(--hairline) solid var(--rule);
  font-family: var(--font-body);
  font-size: 12.5px;
  font-style: italic;
  color: var(--ink-mute);
}
.footer a { color: var(--ink-soft); font-style: normal; }
.footer a:hover { color: var(--terracotta); }
.footer-sep { color: var(--rule-strong); }
.footer .heart {
  color: var(--terracotta);
  font-family: var(--font-display);
  font-style: normal;
  padding: 0 2px;
  letter-spacing: -0.02em;
}

/* ── Responsive ─────────────────────────────────────────────── */

@media (max-width: 860px) {
  :root { --margin-w: 100%; --topbar-h: 64px; }
  body {
    grid-template-columns: 1fr;
    grid-template-rows: var(--topbar-h) auto 1fr var(--footer-h);
    grid-template-areas:
      "topbar"
      "margin"
      "map"
      "footer";
  }
  .margin {
    max-height: 44vh;
    padding: var(--space-md) var(--space-md) var(--space-lg);
    border-right: 0;
    border-bottom: var(--hairline) solid var(--rule);
  }
  .meta { display: none; }
  .compass { width: 64px; height: 64px; bottom: var(--space-lg); }
  .year-value { font-size: 40px; }
  .detail {
    top: auto;
    bottom: var(--footer-h);
    left: 0;
    right: 0;
    width: 100%;
    height: 65vh;
    transform: translateY(110%);
    border-left: 0;
    border-top: var(--hairline) solid var(--rule);
  }
  .detail.open { transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
