:root {
  --bg: #0f1419;
  --bg-elev: #1a2129;
  --ink: #e8eef2;
  --ink-dim: #9bb0bd;
  --ink-faint: #5f7382;
  --line: #2c3a45;
  --spine: #3a4d5a;
  --accent: #4ea3d6;

  --c-teton: #e0564a;
  --c-recl: #4ea3d6;
  --c-disaster: #e89b3c;
  --c-lds: #9b7ad6;
  --c-idaho: #4cb888;
  --c-politics: #d6608f;
  --c-other: #7e93a1;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--ink);
  font-family: 'Inter', system-ui, sans-serif;
  overflow: hidden;
}
body { display: flex; flex-direction: column; height: 100vh; }

/* ---------- Header ---------- */
.site-header {
  display: flex; justify-content: space-between; align-items: flex-end;
  gap: 24px; padding: 16px 28px 12px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #131a21, var(--bg));
  flex-wrap: wrap; flex: none;
}
.site-header h1 {
  font-family: 'Fraunces', serif; font-weight: 600; font-size: 26px;
  margin: 0; letter-spacing: -0.01em;
}
.subtitle { margin: 3px 0 0; color: var(--ink-dim); font-size: 13.5px; }
.header-right { display: flex; align-items: center; gap: 16px; }
.buy-book {
  flex: none; display: inline-flex; align-items: center; white-space: nowrap;
  background: linear-gradient(180deg, #5cb3e6, var(--accent));
  color: #07121a; font-weight: 600; font-size: 13.5px; text-decoration: none;
  padding: 9px 16px; border-radius: 999px; border: 1px solid #6cc0ee;
  box-shadow: 0 2px 10px rgba(78,163,214,.35); transition: transform .1s, box-shadow .12s;
}
.buy-book:hover { transform: translateY(-1px); box-shadow: 0 5px 16px rgba(78,163,214,.5); }
.buy-book:active { transform: translateY(0); }
.search-wrap input {
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: 999px;
  color: var(--ink); padding: 8px 15px; font-size: 14px; width: 210px; outline: none;
  transition: border-color .15s, width .2s;
}
.search-wrap input:focus { border-color: var(--accent); width: 250px; }
.stats { font-size: 12.5px; color: var(--ink-faint); white-space: nowrap; }

/* ---------- Toolbar (filters + zoom) ---------- */
.toolbar {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 28px; border-bottom: 1px solid var(--line);
  background: var(--bg); flex: none; flex-wrap: wrap;
}
.filters { display: flex; gap: 8px; flex-wrap: wrap; flex: 1; min-width: 280px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--line); background: var(--bg-elev); color: var(--ink-dim);
  border-radius: 999px; padding: 6px 12px; font-size: 12.5px; font-weight: 500;
  cursor: pointer; user-select: none; transition: all .14s; opacity: .5;
}
.chip:hover { color: var(--ink); border-color: var(--spine); opacity: .85; }
.chip .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ink-faint); }
.chip .cnt { opacity: .55; }
/* selected state */
.chip.on { opacity: 1; color: var(--ink); border-color: var(--c, var(--accent)); }
.chip.on .dot { background: var(--c); }
.chip.on .cnt { opacity: .7; }
/* the "All" chip (no color dot) */
.chip-all { font-weight: 600; }
.chip-all.on { border-color: var(--accent); }

.zoom-controls { display: flex; align-items: center; gap: 8px; }
.zoom-label {
  font-size: 12px; color: var(--ink-faint); min-width: 86px; text-align: right;
  font-variant-numeric: tabular-nums;
}
.zoom-btn {
  width: 28px; height: 28px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--bg-elev); color: var(--ink); font-size: 18px; line-height: 1;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.zoom-btn:hover { border-color: var(--accent); color: var(--accent); }
#zoom-range { width: 130px; accent-color: var(--accent); cursor: pointer; }

.detail-toggle { display: flex; align-items: center; gap: 6px; }
.dt-label { font-size: 12px; color: var(--ink-faint); }
.seg {
  border: 1px solid var(--line); background: var(--bg-elev); color: var(--ink-dim);
  font-size: 12px; padding: 5px 10px; cursor: pointer;
}
.seg:first-of-type { border-radius: 6px 0 0 6px; }
.seg:last-of-type { border-radius: 0 6px 6px 0; border-left: none; }
.seg.active { background: var(--accent); color: #07121a; border-color: var(--accent); font-weight: 600; }
.seg:not(.active):hover { color: var(--ink); }

.backdrop {
  position: fixed; inset: 0; background: rgba(4, 8, 12, 0.6);
  opacity: 0; pointer-events: none; transition: opacity .22s; z-index: 40;
  backdrop-filter: blur(1.5px);
}
.backdrop.show { opacity: 1; pointer-events: auto; }

/* ---------- Tabs / views ---------- */
.tabs { display: flex; gap: 5px; align-self: center; }
.tab {
  background: transparent; border: 1px solid var(--line); color: var(--ink-dim);
  padding: 7px 18px; font-size: 13px; font-weight: 600; cursor: pointer; border-radius: 8px;
  font-family: inherit;
}
.tab:hover:not(.active) { color: var(--ink); border-color: var(--spine); }
.tab.active { background: var(--bg-elev); color: var(--ink); border-color: var(--accent); }

.views { flex: 1; min-height: 0; display: flex; }
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.view[hidden] { display: none; }

body[data-view="map"] .search-wrap,
body[data-view="map"] #stats { display: none; }

/* ---------- Map ---------- */
.map-wrap {
  flex: 1; min-height: 0; position: relative;
  background:
    radial-gradient(1200px 600px at 50% 38%, #141d25, var(--bg));
  overflow: hidden;
}
#map-svg { width: 100%; height: 100%; display: block; }
.us-land { fill: #1a2530; stroke: #445866; stroke-width: 1.1; stroke-linejoin: round; stroke-linecap: round; }
.rivers .river-line {
  fill: none; stroke: var(--accent); stroke-width: 1.7; stroke-opacity: .75;
  stroke-linecap: round; stroke-linejoin: round;
}
.river-label {
  fill: #7fa3ba; font-size: 10px; font-family: 'Inter', sans-serif;
  pointer-events: none; paint-order: stroke; stroke: #0f1419; stroke-width: 2.5px;
}
.dam .dam-dot { stroke: #0b0f14; stroke-width: 1.5; transition: r .1s; }
.dam:hover .dam-dot { stroke: #fff; r: 8; }
.dam-label {
  fill: #d8e4ec; font-size: 10px; font-weight: 600; font-family: 'Inter', sans-serif;
  pointer-events: none; paint-order: stroke; stroke: #0b0f14; stroke-width: 2.6px;
}
.dam:hover .dam-label { fill: #fff; }
.map-loading {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  color: var(--ink-faint); font-size: 14px; max-width: 70%; text-align: center;
}
.map-legend {
  position: absolute; left: 16px; bottom: 14px; display: flex; flex-wrap: wrap; gap: 14px;
  background: rgba(12, 17, 22, .82); border: 1px solid var(--line);
  padding: 9px 13px; border-radius: 9px; font-size: 12px; color: var(--ink-dim);
  backdrop-filter: blur(3px); max-width: calc(100% - 32px);
}
.lg-item { display: flex; align-items: center; gap: 7px; }
.lg-dot { width: 11px; height: 11px; border-radius: 50%; flex: none; }
.lg-river { width: 18px; height: 0; border-top: 2px solid var(--accent); opacity: .8; flex: none; }

/* ---------- Ruler ---------- */
.ruler {
  position: relative; height: 28px; border-bottom: 1px solid var(--line);
  overflow: hidden; background: #11171d; flex: none;
}
.ruler .tick {
  position: absolute; top: 0; height: 100%;
  display: flex; align-items: center; padding-left: 7px;
  font-size: 11.5px; color: var(--ink-faint);
  border-left: 1px solid var(--line); white-space: nowrap;
  transform: translateX(-1px);
}
.ruler .tick.strong { color: var(--ink-dim); font-weight: 600; border-left-color: var(--spine); }

/* ---------- Timeline ---------- */
.timeline-viewport {
  flex: 1; position: relative; overflow: hidden; outline: none;
  cursor: grab; touch-action: none;
}
.timeline-viewport.grabbing { cursor: grabbing; }
.timeline-track { position: relative; height: 100%; width: 100%; }
.nodes { position: absolute; inset: 0; }
.spine {
  position: absolute; top: 50%; left: 0; right: 0; height: 2px;
  background: var(--spine); transform: translateY(-1px);
}

.node { position: absolute; top: 50%; }
.node .dot {
  position: absolute; left: -6px; top: -6px; width: 12px; height: 12px;
  border-radius: 50%; background: var(--c, var(--accent));
  border: 2px solid var(--bg); box-shadow: 0 0 0 2px var(--c, var(--accent)); z-index: 2;
}
.node .stem { position: absolute; left: -1px; width: 2px; background: var(--c, var(--spine)); opacity: .45; }
.node .card {
  position: absolute; left: 12px; width: 184px;
  background: var(--bg-elev); border: 1px solid var(--line);
  border-left: 3px solid var(--c, var(--accent)); border-radius: 8px;
  padding: 8px 10px; cursor: pointer;
  transition: border-color .12s, box-shadow .12s, transform .08s;
  display: flex; gap: 8px; align-items: flex-start;
}
.node .card-text { flex: 1; min-width: 0; }
.node .card:hover {
  border-color: var(--c, var(--accent)); box-shadow: 0 6px 20px rgba(0,0,0,.4);
}
.node .card .thumb {
  flex: none; width: 46px; height: 46px; border-radius: 6px;
  background: #0c1116; overflow: hidden; border: 1px solid var(--line);
}
.node .card .thumb img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  opacity: .92; transition: opacity .12s, transform .2s;
}
.node .card:hover .thumb img { opacity: 1; transform: scale(1.06); }
.node .date {
  font-family: 'Fraunces', serif; font-size: 13px; font-weight: 600;
  color: var(--ink); margin-bottom: 3px; line-height: 1.15;
}
.node .ev {
  font-size: 11.5px; line-height: 1.34; color: var(--ink-dim);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
/* level 1 keystones stand out a touch */
.node.lvl1 .dot { width: 14px; height: 14px; left: -7px; top: -7px; }
.node.lvl1 .date { font-size: 13.5px; }
.node.lvl1 .card { border-width: 1px; border-left-width: 4px; }
.node.match .card { box-shadow: 0 0 0 2px var(--accent); }
/* small camera dot indicating an attached photo */
.node .cam {
  display: inline-block; width: 11px; height: 9px; margin-left: 6px;
  border: 1.5px solid var(--c, var(--accent)); border-radius: 2px;
  position: relative; vertical-align: middle; opacity: .85;
}
.node .cam::before {
  content: ""; position: absolute; top: 1.5px; left: 50%; transform: translateX(-50%);
  width: 4px; height: 4px; border-radius: 50%; border: 1.5px solid var(--c, var(--accent));
}

.empty {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  color: var(--ink-faint); font-size: 15px; pointer-events: none;
}

/* ---------- Minimap ---------- */
.minimap {
  position: relative; height: 46px; flex: none;
  border-top: 1px solid var(--line); background: #0c1116; cursor: pointer;
  touch-action: none;
}
.minimap canvas { display: block; width: 100%; height: 100%; }
.mm-window {
  position: absolute; top: 0; height: 100%;
  background: rgba(78,163,214,0.14); border-left: 2px solid var(--accent);
  border-right: 2px solid var(--accent); pointer-events: none;
}

/* ---------- Footer ---------- */
.hint {
  padding: 8px 28px; font-size: 12px; color: var(--ink-faint);
  border-top: 1px solid var(--line); background: var(--bg); flex: none;
}
.hint strong { color: var(--ink-dim); font-weight: 600; }

/* ---------- Drawer ---------- */
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: 380px; max-width: 90vw;
  background: var(--bg-elev); border-left: 1px solid var(--line);
  box-shadow: -12px 0 40px rgba(0,0,0,.4); padding: 56px 26px 26px;
  transform: translateX(100%); transition: transform .26s cubic-bezier(.4,0,.2,1);
  z-index: 50; overflow-y: auto;
}
.drawer.open { transform: translateX(0); }

/* Modal mode: centered card with dimmed backdrop */
.drawer.as-modal {
  top: 50%; left: 50%; right: auto; bottom: auto;
  width: 560px; max-width: 92vw; height: auto; max-height: 86vh;
  border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 24px 70px rgba(0,0,0,.55);
  transform: translate(-50%, -50%) scale(.95); opacity: 0;
  transition: transform .22s cubic-bezier(.4,0,.2,1), opacity .22s;
}
.drawer.as-modal.open { transform: translate(-50%, -50%) scale(1); opacity: 1; }
.drawer.as-modal:not(.open) { pointer-events: none; }

.drawer-close {
  position: absolute; top: 14px; right: 16px; background: none; border: none;
  color: var(--ink-dim); font-size: 28px; line-height: 1; cursor: pointer;
}
.drawer-close:hover { color: var(--ink); }
.drawer-cat {
  display: inline-flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em; color: var(--c, var(--accent)); margin-bottom: 10px;
}
.drawer-cat::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--c, var(--accent)); }
.drawer-date { font-family: 'Fraunces', serif; font-size: 24px; font-weight: 600; margin-bottom: 12px; }
.drawer-figure { margin: 0 0 18px; }
.drawer-figure img {
  width: 100%; border-radius: 8px; display: block; background: #0c1116;
  border: 1px solid var(--line); min-height: 60px;
}
.drawer-figure figcaption {
  font-size: 11.5px; line-height: 1.45; color: var(--ink-faint); margin-top: 7px;
}
.drawer-figure figcaption a { color: var(--accent); text-decoration: none; white-space: nowrap; }
.drawer-figure figcaption a:hover { text-decoration: underline; }
.drawer-event { font-size: 16px; line-height: 1.5; color: var(--ink); margin: 0 0 24px; }
.drawer-meta { border-top: 1px solid var(--line); padding-top: 16px; }
.drawer-row { margin-bottom: 14px; }
.drawer-row .lbl {
  display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-faint); margin-bottom: 4px;
}
.drawer-row span:last-child { font-size: 13.5px; color: var(--ink-dim); line-height: 1.45; }
#drawer-raw { font-style: italic; }

@media (max-width: 680px) {
  .site-header { flex-direction: column; align-items: flex-start; gap: 12px; }
  .header-right { width: 100%; }
  .search-wrap input { width: 100%; }
  .toolbar { gap: 10px; }
  .zoom-controls { width: 100%; justify-content: flex-end; }
}
