* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --paper: #f5f0e4;
  --ink-navy: #1e2d4a;
  --ink-slate: #2c3d5c;
  --ink-dim: #4a5e78;
  --brass: #9a7820;
  --brass-pale: #c8a040;
  --brass-dark: #7a5c10;
  --ink-rubric: #8a3a1f;
}

body {
  background: var(--paper);
  color: var(--ink-navy);
  font-family: 'EB Garamond', Georgia, serif;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 32px 8px;
  transition: padding 0.25s ease;
}

body.zoomed {
  padding: 8px 0;
}

header {
  width: 100%;
  max-width: 1600px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 16px;
  transition: opacity 0.25s ease, max-height 0.25s ease, margin-bottom 0.25s ease;
  max-height: 200px;
  overflow: hidden;
}

body.zoomed header {
  opacity: 0;
  max-height: 0;
  margin-bottom: 0;
  pointer-events: none;
}

.title-block .subtitle {
  font-size: 13px;
  letter-spacing: 3px;
  color: var(--ink-slate);
  margin-bottom: 4px;
}

.title-block h1 {
  font-size: 44px;
  font-weight: 600;
  font-style: italic;
  letter-spacing: 0.5px;
  color: var(--ink-navy);
  line-height: 1.1;
}

.title-block .tagline {
  font-size: 14px;
  color: var(--ink-slate);
  margin-top: 6px;
  letter-spacing: 0.5px;
}

/* Top-right menu: Index | ? | ♡ */
.topnav {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  color: var(--ink-slate);
  letter-spacing: 0.4px;
}
.topnav-btn {
  background: none;
  border: none;
  font-family: 'EB Garamond', Georgia, serif;
  font-size: 15px;
  color: var(--ink-slate);
  cursor: pointer;
  padding: 4px 8px;
  letter-spacing: 0.4px;
  border-bottom: 1px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.topnav-btn:hover { color: var(--ink-navy); border-bottom-color: var(--brass-pale); }
.topnav-btn[aria-expanded="true"] { color: var(--ink-navy); border-bottom-color: var(--brass); }
.topnav-btn:disabled { color: var(--ink-dim); opacity: 0.55; cursor: default; }
.topnav-btn:disabled:hover { border-bottom-color: transparent; color: var(--ink-dim); }
.topnav-btn--heart { font-size: 18px; color: var(--brass-dark); padding: 2px 8px 4px; }
.topnav-btn--heart:hover { color: var(--brass); }
.topnav-sep { color: var(--ink-dim); font-size: 13px; }

/* Floating panes anchored at viewport center. Each pane shows on demand
   (toggled by the matching button); click-outside dismisses. */
.topnav-pane {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--paper);
  border: 1px solid #d8cfb8;
  box-shadow: 0 4px 16px rgba(30, 45, 74, 0.10);
  padding: 28px 34px;
  width: 380px;
  max-width: 90vw;
  z-index: 20;
  font-family: 'EB Garamond', Georgia, serif;
  color: var(--ink-navy);
}
.topnav-pane--small { width: 460px; padding: 36px 40px; }
.topnav-pane[hidden] { display: none; }
.topnav-pane h3 {
  font-size: 15px;
  letter-spacing: 2.6px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--ink-slate);
  margin-bottom: 16px;
  text-align: center;
}
.legend-list {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 17px;
  color: var(--ink-slate);
}
.legend-list li { display: flex; align-items: center; gap: 14px; }
.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
  flex: 0 0 auto;
}
.legend-dot--brass  { background: var(--brass); border: 1px solid var(--brass-dark); }
.legend-dot--rubric { background: var(--ink-rubric); border: 1px solid #5a2310; }
.legend-dot--cloud  { background: #7a8499; border: 1px solid #5a6478; opacity: 0.85; }
.legend-edge {
  width: 22px;
  height: 0;
  border-top: 1px solid var(--ink-slate);
  display: inline-block;
  flex: 0 0 auto;
}
.legend-edge--up      { border-top-color: var(--ink-navy); }
.legend-edge--down    { border-top-color: var(--ink-rubric); }
.legend-edge--dashed  { border-top-style: dashed; }
.legend-text { line-height: 1.3; }
.legend-tip {
  margin-top: 6px;
  font-size: 14px;
  color: var(--ink-dim);
  font-style: italic;
  text-align: center;
  border-top: 1px solid #e0d6be;
  padding-top: 14px;
}
.dedication {
  font-size: 32px;
  font-style: italic;
  color: var(--ink-slate);
  line-height: 1.4;
  text-align: center;
}

main {
  width: 100%;
  max-width: 1600px;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  transition: max-width 0.25s ease;
}

body.zoomed main {
  max-width: 100vw;
}

svg#stage {
  width: 100%;
  display: block;
  /* height set explicitly by app.js (Safari ignores height:auto on inline SVG) */
}

/* SVG text defaults */
svg text {
  font-family: 'EB Garamond', Georgia, serif;
  fill: var(--ink-navy);
  pointer-events: none;   /* let hover pass through to dots underneath */
  user-select: none;      /* prevent accidental selection while hovering */
}

/* Per-glyph paper halo so labels stay legible over dots/edges. paint-order
   draws the (semi-transparent paper) stroke before the fill — the underlying
   art shows through, but tinted, while the glyph itself stays crisp. */
svg .node-label,
svg .node-city,
svg .cloud-hover-name,
svg .cloud-hover-place {
  paint-order: stroke fill;
  stroke: rgba(245, 240, 228, 0.82);
  stroke-width: 4px;
  stroke-linejoin: round;
}
svg .era-header { font-size: 18px; letter-spacing: 2.4px; font-weight: 600; }
svg .era-century { font-size: 14px; letter-spacing: 1.8px; fill: var(--ink-dim); }
svg .node-label { font-size: 14px; pointer-events: auto; cursor: pointer; transition: opacity 0.2s ease; }
svg .node-label.italic { font-style: italic; }
svg .cloud-hover-name { font-size: 12px; fill: var(--ink-slate); font-weight: 400;
                         pointer-events: none; transition: opacity 0.2s ease; }
svg .cloud-hover-place { font-size: 9px; fill: var(--ink-dim); font-style: italic;
                          pointer-events: none; transition: opacity 0.2s ease; }
svg .node-city { font-size: 9px; fill: var(--ink-dim); font-style: italic; pointer-events: auto; cursor: pointer;
                  opacity: 0; transition: opacity 0.2s ease; }
svg g.curated-node:hover .node-city,
svg g.curated-node.selected .node-city { opacity: 1; }
svg .node-years { font-size: 9px; fill: var(--ink-dim); }

/* Hover & selection states — transitions live here so SVG attribute changes animate. */
svg .cloud-layer circle,
svg g.curated-node {
  transition: opacity 0.18s ease, fill-opacity 0.18s ease, stroke-width 0.18s ease;
}
svg .cloud-layer circle:hover { fill-opacity: 1; stroke-width: 1.2; }
svg g.curated-node:hover circle { stroke-width: 2.2; }

/* Dimming on selection — when bio drawer is open, fade everything except the
   chosen node so it pops. Hovering a dimmed node still brightens it via the
   :hover rules above (higher specificity due to :hover pseudo-class). */
body.has-selection svg .cloud-layer circle { opacity: 0.70; }
body.has-selection svg g.curated-node { opacity: 0.70; }
body.has-selection svg .edge-layer { opacity: 0.55; transition: opacity 0.18s ease; }
body.has-selection svg .cloud-layer circle.selected,
body.has-selection svg g.curated-node.selected { opacity: 1; }
body.has-selection svg .cloud-layer circle:hover,
body.has-selection svg g.curated-node:hover { opacity: 1; }

/* Index panel — slides in from the left, mirrors the bio drawer geometry. */
.index-panel {
  position: fixed;
  top: 0;
  left: 0;
  width: 340px;
  max-width: 90vw;
  height: 100vh;
  background: var(--paper);
  border-right: 1px solid #d8cfb8;
  box-shadow: 8px 0 24px rgba(30, 45, 74, 0.08);
  padding: 18px 0 0;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  z-index: 10;
}
.index-panel.open { transform: translateX(0); }

.index-close {
  position: absolute;
  top: 8px;
  right: 12px;
  background: none;
  border: none;
  font-size: 28px;
  line-height: 1;
  color: var(--ink-dim);
  cursor: pointer;
  padding: 4px 10px;
  font-family: 'EB Garamond', Georgia, serif;
  transition: color 0.15s ease;
}
.index-close:hover { color: var(--ink-navy); }

.index-header {
  padding: 0 22px 12px;
  border-bottom: 1px solid #e0d6be;
  flex: 0 0 auto;
}
.index-title {
  font-size: 13px;
  letter-spacing: 2.6px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--ink-slate);
  margin-bottom: 12px;
}
.index-sort {
  display: flex;
  gap: 4px;
  margin-bottom: 10px;
}
.index-sort-btn {
  flex: 1;
  background: none;
  border: 1px solid #d8cfb8;
  font-family: 'EB Garamond', Georgia, serif;
  font-size: 13px;
  color: var(--ink-slate);
  padding: 5px 8px;
  cursor: pointer;
  letter-spacing: 0.4px;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.index-sort-btn:hover { color: var(--ink-navy); border-color: var(--brass-pale); }
.index-sort-btn.active {
  background: var(--ink-navy);
  border-color: var(--ink-navy);
  color: var(--paper);
}
.index-search {
  width: 100%;
  font-family: 'EB Garamond', Georgia, serif;
  font-size: 14px;
  color: var(--ink-navy);
  background: rgba(255, 255, 255, 0.4);
  border: 1px solid #d8cfb8;
  padding: 6px 10px;
  outline: none;
  transition: border-color 0.15s ease;
}
.index-search:focus { border-color: var(--brass); }
.index-search::placeholder { color: var(--ink-dim); font-style: italic; }

.index-list {
  list-style: none;
  margin: 0;
  padding: 6px 0 18px;
  overflow-y: auto;
  flex: 1 1 auto;
  font-size: 14px;
}
.index-list li {
  padding: 5px 22px;
  cursor: pointer;
  color: var(--ink-slate);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  transition: background 0.12s ease, color 0.12s ease;
}
.index-list li:hover { background: rgba(154, 120, 32, 0.08); color: var(--ink-navy); }
.index-list li.selected { background: rgba(154, 120, 32, 0.16); color: var(--ink-navy); }
.index-list .index-name { flex: 1 1 auto; line-height: 1.3; }
.index-list .index-year {
  font-size: 12px;
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
}
.index-era-header {
  padding: 12px 22px 4px;
  font-size: 11px;
  letter-spacing: 2.2px;
  text-transform: uppercase;
  color: var(--ink-dim);
  font-weight: 600;
  cursor: default;
}
.index-era-header:hover { background: none; color: var(--ink-dim); }

/* Bio drawer */
.bio-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 646px;
  max-width: 90vw;
  height: 100vh;
  background: var(--paper);
  border-left: 1px solid #d8cfb8;
  box-shadow: -8px 0 24px rgba(30, 45, 74, 0.08);
  padding: 56px 32px 24px;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  z-index: 10;
}

.bio-panel.open {
  transform: translateX(0);
}

.bio-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  font-size: 32px;
  line-height: 1;
  color: var(--ink-dim);
  cursor: pointer;
  padding: 4px 10px;
  font-family: 'EB Garamond', Georgia, serif;
  transition: color 0.15s ease;
}

.bio-close:hover { color: var(--ink-navy); }

.bio-tier {
  font-size: 22px;
  letter-spacing: 2.4px;
  color: var(--ink-dim);
  text-transform: uppercase;
  margin-bottom: 6px;
}

.bio-name {
  font-size: 52px;
  font-weight: 600;
  font-style: italic;
  color: var(--ink-navy);
  line-height: 1.15;
  margin-bottom: 8px;
}

.bio-meta {
  font-size: 26px;
  color: var(--ink-slate);
  font-style: italic;
  margin-bottom: 22px;
}

.bio-lede {
  font-size: 30px;
  font-style: italic;
  color: var(--ink-slate);
  line-height: 1.5;
  margin-bottom: 14px;
}

.bio-text {
  font-size: 28px;
  color: var(--ink-navy);
  line-height: 1.6;
  margin-bottom: 24px;
}

/* Inline links inside bio prose (DOI, Google Scholar, etc.) — match the
   brass aesthetic of the Wikidata footer link, but understated to sit
   inline without dominating the surrounding sentence. */
.bio-lede a, .bio-text a {
  color: var(--brass-dark);
  text-decoration: none;
  border-bottom: 1px solid var(--brass-pale);
  transition: color 0.15s ease;
}
.bio-lede a:hover, .bio-text a:hover { color: var(--brass); }

.bio-wikidata {
  display: inline-block;
  font-size: 26px;
  color: var(--brass-dark);
  text-decoration: none;
  border-bottom: 1px solid var(--brass-pale);
  padding-bottom: 2px;
  letter-spacing: 0.3px;
  transition: color 0.15s ease;
}

.bio-wikidata:hover { color: var(--brass); }
.bio-wikidata.hidden { display: none; }

/* Short viewports (iPhone landscape, etc.): release the locked-viewport
   layout so the page can scroll and the SVG keeps a sensible aspect.
   Without this, <main> collapses to ~200px, the viewBox is rewritten to
   a 4:1 aspect, and curated nodes (baked at print-canvas y-coords) fall
   outside the visible area with no scroll/pan to reach them. */
@media (max-height: 520px) {
  body { height: auto; min-height: 100vh; overflow: auto; padding: 6px 12px; }
  /* Drop the title block so only the Index / ? / ♡ controls remain in the
     header — the topnav stays reachable while the SVG gets the room. */
  .title-block { display: none; }
  header { margin-bottom: 4px; justify-content: flex-end; max-height: 40px; }
  main { min-height: 600px; }
  /* Release vertical pan + pinch-zoom to the browser. Without this,
     d3-zoom's touch handlers preventDefault on every touchmove, so
     finger-drags on the SVG never bubble up as page-scroll — and the
     SVG covers most of the viewport. touch-action takes precedence
     over preventDefault per spec, so this works even with d3-zoom on. */
  svg#stage { touch-action: pan-y pinch-zoom; }
}
