/* ============================================================
   LOOM · design system — a cartographer's atlas
   Pigments: Lapis (ideas) · Oxblood (power) · Gilt (wealth) · Verdigris (craft)
   ============================================================ */

:root {
  --parchment: #efe3c6;
  --parchment-deep: #e7d7b2;
  --paper: #f7efdd;
  --card: #f3e9d0;
  --ink: #2c2318;
  --ink-soft: #6a5a42;
  --ink-faint: #a08c68;
  --line: rgba(44, 35, 24, 0.35);
  --line-faint: rgba(44, 35, 24, 0.16);
  --gilt: #a67c1e;
  --gilt-bright: #c29b2a;
  --seal: #8c3b2e;
  --th-ideas: #34558b;
  --th-power: #8c3b2e;
  --th-wealth: #8a6a1f;
  --th-craft: #2e6e63;
  --shadow: 0 10px 40px rgba(44, 35, 24, 0.28);
  --serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, 'Book Antiqua', Georgia, serif;
}

body.lamplight {
  --parchment: #211a10;
  --parchment-deep: #191307;
  --paper: #2a2214;
  --card: #251e11;
  --ink: #e8dbba;
  --ink-soft: #b5a37e;
  --ink-faint: #7c6c50;
  --line: rgba(232, 219, 186, 0.4);
  --line-faint: rgba(232, 219, 186, 0.14);
  --gilt: #c9a34a;
  --gilt-bright: #e0bc55;
  --seal: #c96f5c;
  --th-ideas: #7f97cf;
  --th-power: #cf7f6d;
  --th-wealth: #c9a34a;
  --th-craft: #6fae9f;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}

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

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  font-family: var(--serif);
  background: var(--parchment);
  color: var(--ink);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: background 0.4s ease, color 0.4s ease;
}

/* aged-paper atmosphere: blotches + vignette, then grain over everything */
body::before {
  content: '';
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(1200px 700px at 12% 8%, rgba(140, 100, 40, 0.07), transparent 60%),
    radial-gradient(900px 900px at 88% 30%, rgba(120, 80, 30, 0.06), transparent 60%),
    radial-gradient(1000px 600px at 30% 95%, rgba(140, 100, 40, 0.08), transparent 60%),
    radial-gradient(140% 120% at 50% 45%, transparent 55%, rgba(70, 48, 16, 0.16) 100%);
}
body::after {
  content: '';
  position: fixed; inset: 0; z-index: 300; pointer-events: none; opacity: 0.55;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='260'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.2 0 0 0 0 0.15 0 0 0 0 0.05 0 0 0 0.06 0'/%3E%3C/filter%3E%3Crect width='260' height='260' filter='url(%23n)'/%3E%3C/svg%3E");
}

button { font-family: inherit; color: inherit; }

/* ---------------- header bar ---------------- */
#bar {
  position: relative; z-index: 20;
  flex: none;
  display: flex; align-items: center; gap: 18px;
  padding: 10px 18px 9px;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 0 var(--line-faint), 0 4px 18px rgba(44, 35, 24, 0.1);
  background: linear-gradient(var(--parchment), var(--parchment) 60%, var(--parchment-deep));
}
.bar-title { display: flex; align-items: baseline; gap: 10px; white-space: nowrap; }
.bar-title h1 { font-size: 24px; letter-spacing: 0.42em; font-weight: 600; margin-right: -0.42em; }
.bar-sub { font-style: italic; color: var(--ink-soft); font-size: 13.5px; }

.bar-search { position: relative; flex: 1; max-width: 430px; min-width: 150px; }
#search {
  width: 100%; font-family: inherit; font-size: 14px; color: var(--ink);
  background: transparent; border: 1px solid var(--line);
  border-radius: 2px; padding: 7px 12px; outline: none;
}
#search::placeholder { color: var(--ink-faint); font-style: italic; }
#search:focus { border-color: var(--gilt); box-shadow: 0 0 0 1px var(--gilt); }
#search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 60;
  min-width: min(280px, calc(100vw - 24px));
  background: var(--card); border: 1px solid var(--line); border-radius: 2px;
  box-shadow: var(--shadow); max-height: 330px; overflow: auto;
}
.sr-item { padding: 9px 12px; cursor: pointer; border-bottom: 1px solid var(--line-faint); }
.sr-item:hover, .sr-item.active { background: var(--parchment-deep); }
.sr-item .sr-title { font-size: 14.5px; }
.sr-item .sr-meta { font-size: 11.5px; color: var(--ink-soft); font-variant: small-caps; letter-spacing: 0.08em; }

.bar-tools { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.bar-progress { font-size: 12.5px; color: var(--ink-soft); font-variant: small-caps; letter-spacing: 0.1em; white-space: nowrap; }
.bar-streak {
  font-size: 12.5px; color: var(--gilt); letter-spacing: 0.08em; white-space: nowrap;
  border: 1px solid var(--line-faint); border-radius: 999px; padding: 2px 9px;
  cursor: default;
}

#thread-chips { display: flex; gap: 7px; }
.chip {
  display: flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: transparent; border-radius: 999px;
  padding: 3.5px 10px 3.5px 7px; font-size: 11.5px; cursor: pointer;
  color: var(--ink-soft); font-variant: small-caps; letter-spacing: 0.07em;
  transition: all 0.15s ease;
}
.chip .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c); box-shadow: inset 0 0 0 1px rgba(0,0,0,0.25); }
.chip.on { background: var(--c); color: var(--paper); border-color: var(--c); }
.chip.on .dot { background: var(--paper); }
body.lamplight .chip.on { color: #16110a; }

.btn {
  border: 1px solid var(--line); background: transparent; cursor: pointer;
  border-radius: 2px; padding: 6px 13px; font-size: 13px;
  transition: all 0.15s ease;
}
.btn:hover { border-color: var(--ink-soft); background: var(--parchment-deep); }
.btn-gilt {
  background: var(--gilt); border-color: var(--gilt); color: var(--paper);
  font-variant: small-caps; letter-spacing: 0.09em; font-size: 13.5px;
}
body.lamplight .btn-gilt { color: #16110a; }
.btn-gilt:hover { background: var(--gilt-bright); border-color: var(--gilt-bright); color: var(--paper); }
body.lamplight .btn-gilt:hover { color: #16110a; }
.btn-ghost { padding: 6px 10px; color: var(--ink-soft); }

/* ---------------- chart ---------------- */
#chart-wrap { position: relative; z-index: 5; flex: 1 1 auto; min-height: 0; }
#chart { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
#chart.panning { cursor: grabbing; }

/* the world, engraved: a map band below the oldest era and above the newest,
   so the whole chart reads as history rising between two earths */
.world-layer { pointer-events: none; }
.world-land {
  fill: var(--ink);
  fill-opacity: 0.10;
  stroke: var(--ink);
  stroke-opacity: 0.62;
  stroke-width: 1.1;
  stroke-linejoin: round;
}
.world-graticule line { stroke: var(--ink); stroke-opacity: 0.14; stroke-width: 1; }
.world-equator { stroke: var(--ink); stroke-opacity: 0.22; stroke-width: 1.4; stroke-dasharray: 7 6; }
body.lamplight .world-land { fill-opacity: 0.11; stroke-opacity: 0.45; }

.era-band { fill: var(--ink); opacity: 0; }
.era-band.alt { opacity: 0.045; }
.era-rule { stroke: var(--line-faint); stroke-width: 1; }
.era-label { fill: var(--ink-soft); font-variant: small-caps; letter-spacing: 0.34em; font-size: 15px; }
.era-span { fill: var(--ink-faint); font-size: 11px; letter-spacing: 0.12em; font-style: italic; }

.meridian { stroke: var(--line-faint); stroke-width: 1; stroke-dasharray: 1 7; }
.meridian-label { fill: var(--ink-faint); font-variant: small-caps; letter-spacing: 0.26em; font-size: 11.5px; text-anchor: middle; }

.wire { fill: none; stroke: var(--c, var(--ink-faint)); stroke-width: 1.3; opacity: 0.34; transition: opacity 0.25s ease, stroke-width 0.25s ease; }
.wire.t-echoes { stroke-dasharray: 5 4; }
.wire.t-collides { stroke-dasharray: 8 3 2 3; }

.node { cursor: pointer; }
.node .halo { fill: none; stroke: var(--gilt-bright); stroke-width: 2; opacity: 0; }
.node .core { fill: var(--parchment); stroke: var(--ink); stroke-width: 1.6; transition: fill 0.3s ease; }
.node.seed .core { stroke-dasharray: 2.6 2.8; stroke-width: 1.3; }
.node.seed .label { opacity: 0.72; }
.node.written .core { stroke-width: 2.2; }
.node .pip { fill: var(--c, var(--ink-faint)); }
.node.read .core { fill: var(--gilt); stroke-width: 2.2; }
.node.read .pip { fill: var(--paper); }
.node.next .halo { opacity: 1; animation: breathe 2.6s ease-in-out infinite; }
@keyframes breathe {
  0%, 100% { stroke-width: 2; r: 15; opacity: 0.9; }
  50% { stroke-width: 1; r: 20; opacity: 0.25; }
}
.node .label {
  fill: var(--ink); font-size: 12.5px; text-anchor: middle;
  paint-order: stroke; stroke: var(--parchment); stroke-width: 3px; stroke-linejoin: round;
  pointer-events: none;
}
/* r is driven by --hit-r (set in js/map.js on zoom) so the invisible tap
   target never shrinks below a fingertip on screen; the r=18 attribute is the
   floor for browsers without SVG geometry-property support */
.node .hit { fill: transparent; r: var(--hit-r, 18px); }

/* zoom tiers: hide labels when far out */
#chart.far .label { display: none; }
#chart.far .wire { stroke-width: 2; }

/* focus mode: hovering/selecting a node dims the rest of the world */
#chart.focused .wire { opacity: 0.05; }
#chart.focused .wire.lit { opacity: 0.95; stroke-width: 2; }
#chart.focused .node { opacity: 0.3; }
#chart.focused .node.lit { opacity: 1; }
#chart.focused.far .node.lit .label { display: block; }

/* thread filters */
#chart.filtered .node:not(.th-match) { opacity: 0.16; }
#chart.filtered .wire:not(.th-match) { opacity: 0.04; }

/* path mode: only the route is lit */
#chart.pathed .node:not(.on-path) { opacity: 0.1; }
#chart.pathed .wire:not(.on-path) { opacity: 0.03; }
#chart.pathed .wire.on-path { opacity: 0.9; stroke-width: 2.1; }

#path-bar {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 18;
  display: flex; align-items: center; gap: 12px;
  padding: 8px 10px 8px 12px;
  background: color-mix(in srgb, var(--card) 94%, transparent);
  border: 1px solid var(--line); outline: 1px solid var(--line); outline-offset: 3px;
  box-shadow: var(--shadow); backdrop-filter: blur(3px);
}
.path-step { width: 32px; height: 32px; padding: 0; font-size: 17px; line-height: 1; }
.path-step:disabled { opacity: 0.3; cursor: default; }
.path-mid { min-width: 240px; text-align: center; }
.path-title { font-variant: small-caps; letter-spacing: 0.13em; font-size: 12.5px; color: var(--gilt); }
.path-where { font-size: 13.5px; margin-top: 1px; }
.path-quit { font-size: 11.5px; padding: 5px 10px; color: var(--ink-soft); font-variant: small-caps; letter-spacing: 0.08em; }

/* paths chooser */
#paths {
  position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center;
  background: rgba(44, 35, 24, 0.45); backdrop-filter: blur(2px); padding: 20px;
}
.paths-card {
  position: relative; max-width: 620px; width: 100%; max-height: 86vh; max-height: 86dvh; overflow-y: auto;
  background: var(--card); padding: 32px 36px 30px;
  border: 1px solid var(--line); outline: 1px solid var(--line); outline-offset: 4px;
  box-shadow: var(--shadow);
}
.paths-h { font-size: 26px; margin-bottom: 6px; }
.paths-sub { font-size: 14.5px; line-height: 1.62; color: var(--ink-soft); }
.paths-threads, .paths-roots { display: grid; gap: 7px; }
.path-opt {
  display: flex; align-items: flex-start; gap: 11px; text-align: left;
  border: 1px solid var(--line-faint); background: transparent; cursor: pointer;
  padding: 10px 12px; font-family: inherit; transition: all 0.15s ease;
}
.path-opt:hover { border-color: var(--c); background: var(--parchment-deep); }
.path-swatch { width: 10px; height: 10px; border-radius: 50%; background: var(--c); flex: none; margin-top: 5px; }
.path-opt-text { display: block; }
.path-opt-title { display: block; font-size: 15px; }
.path-opt-meta { display: block; font-size: 12px; color: var(--ink-soft); margin-top: 2px; line-height: 1.45; }

.node.selected .core { stroke: var(--gilt); stroke-width: 3; }

/* ---------------- overlays on the chart ---------------- */
#era-rail {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%); z-index: 15;
  display: flex; flex-direction: column; gap: 2px;
}
.rail-era {
  border: none; background: transparent; cursor: pointer;
  font-family: inherit; font-size: 12px; color: var(--ink-faint);
  padding: 3px 8px; text-align: right; letter-spacing: 0.12em;
  border-right: 2px solid var(--line-faint); border-radius: 0;
  transition: all 0.15s ease;
}
.rail-era:hover, .rail-era.here { color: var(--ink); border-right-color: var(--gilt); }

#compass {
  position: absolute; top: 16px; right: 54px; z-index: 10; width: 74px;
  color: var(--ink-soft); opacity: 0.85; pointer-events: none; text-align: center;
}
#compass svg { width: 74px; height: 74px; display: block; }
.compass-now, .compass-origins {
  display: block; font-size: 9.5px; font-variant: small-caps; letter-spacing: 0.3em; margin-left: 0.3em;
}
.compass-now { margin-top: -76px; transform: translateY(-12px); }
.compass-origins { transform: translateY(64px); }

#cartouche {
  position: absolute; left: 16px; bottom: 16px; z-index: 10;
  border: 1px solid var(--line); outline: 1px solid var(--line); outline-offset: 3px;
  background: color-mix(in srgb, var(--parchment) 82%, transparent);
  backdrop-filter: blur(2px);
  padding: 12px 15px; max-width: 240px;
}
.cart-title { font-variant: small-caps; letter-spacing: 0.2em; font-size: 12px; line-height: 1.6; }
.cart-rule { height: 1px; background: var(--line); margin: 9px 0; }
.cart-legend { display: grid; gap: 5px; font-size: 11px; color: var(--ink-soft); }
.leg-row { display: flex; align-items: center; gap: 8px; }
.leg-swatch { width: 22px; height: 0; border-top: 2px solid var(--c); flex: none; }
.leg-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.leg-name { font-variant: small-caps; letter-spacing: 0.09em; }
.leg-sep { height: 1px; background: var(--line-faint); margin: 3px 0; }

#zoom-tools { position: absolute; right: 12px; bottom: 16px; z-index: 15; display: flex; flex-direction: column; gap: 6px; }
#zoom-tools .btn { width: 34px; height: 34px; padding: 0; font-size: 17px; background: color-mix(in srgb, var(--parchment) 82%, transparent); }

#tip {
  position: fixed; z-index: 80; pointer-events: none;
  background: var(--ink); color: var(--parchment);
  padding: 7px 11px; border-radius: 2px; font-size: 12.5px; max-width: 280px;
  box-shadow: var(--shadow);
}
#tip .tip-date { opacity: 0.65; font-size: 11px; font-variant: small-caps; letter-spacing: 0.1em; }

/* ---------------- dossier panel ---------------- */
#dossier {
  position: fixed; top: 64px; right: 12px; bottom: 12px; width: 400px; z-index: 40;
  background: var(--card);
  border: 1px solid var(--line); outline: 1px solid var(--line); outline-offset: 3px;
  box-shadow: var(--shadow);
  overflow-y: auto; padding: 22px 24px 26px;
  animation: dossier-in 0.22s ease;
}
@keyframes dossier-in { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }

.dos-close {
  position: absolute; top: 10px; right: 10px;
  border: none; background: none; font-size: 19px; cursor: pointer; color: var(--ink-faint); padding: 4px 8px;
}
.dos-close:hover { color: var(--ink); }
.dos-era { font-size: 11px; font-variant: small-caps; letter-spacing: 0.22em; color: var(--gilt); }
.dos-title { font-size: 26px; line-height: 1.15; margin: 7px 0 3px; font-weight: 600; }
.dos-date { font-size: 13px; color: var(--ink-soft); font-style: italic; }
.dos-region { font-size: 11px; color: var(--ink-faint); font-variant: small-caps; letter-spacing: 0.16em; margin-top: 2px; }
.dos-threads { display: flex; gap: 6px; flex-wrap: wrap; margin: 12px 0; }
.dos-thread {
  font-size: 10.5px; font-variant: small-caps; letter-spacing: 0.1em;
  color: var(--paper); background: var(--c); border-radius: 999px; padding: 2.5px 9px;
}
body.lamplight .dos-thread { color: #16110a; }
.dos-hook { font-style: italic; font-size: 15.5px; line-height: 1.5; color: var(--ink-soft); margin: 12px 0; }
.dos-summary { font-size: 14.5px; line-height: 1.62; margin-bottom: 16px; }
.dos-head {
  font-size: 11.5px; font-variant: small-caps; letter-spacing: 0.24em; color: var(--ink-soft);
  border-bottom: 1px solid var(--line-faint); padding-bottom: 5px; margin: 18px 0 10px;
}
.dos-conn { margin-bottom: 12px; }
.conn-link {
  background: none; border: none; padding: 0; cursor: pointer;
  font-family: inherit; font-size: 14px; color: var(--ink); text-align: left;
}
.conn-link:hover { color: var(--gilt); }
.conn-link .conn-type { font-size: 10.5px; font-variant: small-caps; letter-spacing: 0.12em; color: var(--c, var(--ink-faint)); margin-right: 6px; }
.conn-why { font-size: 12.5px; color: var(--ink-soft); line-height: 1.5; margin-top: 2px; }
.dos-cta { margin-top: 20px; }
.dos-cta .btn { width: 100%; padding: 11px; font-size: 15px; }
.dos-charted { text-align: center; font-size: 12px; color: var(--gilt); font-variant: small-caps; letter-spacing: 0.18em; margin-top: 8px; }
.dos-forge {
  border: 1px dashed var(--line); padding: 12px 14px; margin-top: 8px; font-size: 13px; color: var(--ink-soft); line-height: 1.55;
}
.dos-forge code {
  display: block; font-size: 12.5px; background: var(--parchment-deep); color: var(--ink);
  padding: 6px 9px; margin: 8px 0 4px; border-radius: 2px; user-select: all;
}
.dos-forge .forge-hint { font-size: 11.5px; color: var(--ink-faint); font-style: italic; }

/* ---------------- reader ---------------- */
#reader {
  position: fixed; inset: 0; z-index: 100; overflow-y: auto;
  background: var(--paper);
}
.reader-close {
  position: fixed; top: 18px; right: 22px; z-index: 110;
  border: 1px solid var(--line); background: var(--paper); border-radius: 50%;
  width: 40px; height: 40px; font-size: 17px; cursor: pointer; color: var(--ink-soft);
}
.reader-close:hover { color: var(--ink); border-color: var(--ink-soft); }
.page { max-width: 680px; margin: 0 auto; padding: 64px 28px 120px; }
.page-era { text-align: center; font-size: 12px; font-variant: small-caps; letter-spacing: 0.3em; color: var(--gilt); }
.page-title { text-align: center; font-size: 40px; line-height: 1.12; font-weight: 600; margin: 14px 0 8px; }
.page-date { text-align: center; font-style: italic; color: var(--ink-soft); font-size: 15px; }
.page-threads { display: flex; justify-content: center; gap: 7px; margin: 14px 0 8px; }
.page-context {
  text-align: center; font-style: italic; color: var(--ink-soft); font-size: 14.5px;
  margin: 26px 0 10px;
}
.orn { text-align: center; color: var(--gilt); font-size: 15px; letter-spacing: 0.6em; margin: 30px 0; }
.page p { font-size: 17.5px; line-height: 1.74; margin-bottom: 1.15em; }
.page .story p:first-of-type::first-letter {
  font-size: 3.4em; line-height: 0.82; float: left; padding: 6px 8px 0 0; color: var(--gilt); font-weight: 600;
}
.sec-head {
  font-size: 13px; font-variant: small-caps; letter-spacing: 0.3em; color: var(--ink-soft);
  text-align: center; margin: 34px 0 18px;
}
.threads-out { list-style: none; }
.threads-out li { margin-bottom: 14px; font-size: 15.5px; line-height: 1.6; }
.threads-out .conn-link { font-size: 16px; }
.threads-out .conn-why { font-size: 14px; }

.q { border: 1px solid var(--line-faint); padding: 16px 18px; margin-bottom: 14px; background: color-mix(in srgb, var(--card) 55%, transparent); }
.q-tag { font-size: 10.5px; font-variant: small-caps; letter-spacing: 0.14em; color: var(--paper); background: var(--ink-soft); padding: 2px 8px; border-radius: 999px; }
.q-tag.t-callback { background: var(--th-ideas); }
.q-tag.t-why { background: var(--th-craft); }
.q-callback-chip {
  font-size: 11.5px; color: var(--ink-soft); font-style: italic; margin-left: 8px;
}
.q-prompt { font-size: 16px; line-height: 1.55; margin: 9px 0 12px; }
.q-reveal { font-size: 12.5px; }
.q-answer { font-size: 15px; line-height: 1.65; color: var(--ink-soft); border-left: 2px solid var(--gilt); padding-left: 13px; margin-top: 11px; }
.q-marks { display: flex; gap: 8px; margin-top: 11px; }
.q-marks .btn { font-size: 12px; padding: 4px 11px; }
.q-marks .btn.picked-yes { background: var(--th-craft); border-color: var(--th-craft); color: var(--paper); }
.q-marks .btn.picked-no { background: var(--seal); border-color: var(--seal); color: var(--paper); }
body.lamplight .q-marks .btn.picked-yes, body.lamplight .q-marks .btn.picked-no { color: #16110a; }

/* ---------------- citations ---------------- */
/* Markers live in the prose but stay invisible until the reader asks for them.
   The numbered list at the foot of the lesson is always present. */
.ev-row { display: flex; justify-content: center; margin: 4px 0 26px; }
.ev-btn {
  border: 1px solid var(--line-faint); background: transparent; cursor: pointer;
  border-radius: 999px; padding: 5px 14px;
  font-size: 11.5px; font-variant: small-caps; letter-spacing: 0.16em; color: var(--ink-faint);
  transition: color 0.15s ease, border-color 0.15s ease;
}
.ev-btn::before { content: '✦ '; color: var(--gilt); }
.ev-btn:hover { color: var(--ink-soft); border-color: var(--line); }
.ev-btn[aria-pressed='true'] { color: var(--gilt); border-color: var(--gilt); }

.cite-mark {
  border: none; background: none; padding: 0; margin: 0 0 0 1px;
  font-family: inherit; font-size: 0.62em; line-height: 1;
  vertical-align: super; color: var(--gilt); cursor: pointer;
  position: relative;
}
.cite-mark:hover { color: var(--gilt-bright); }
/* the tap target is a fingertip; the glyph stays a superscript numeral, so this
   pseudo-element grows the hit area without touching the line box */
.cite-mark::before { content: ''; position: absolute; inset: -13px -9px -11px -9px; }
/* expanding must not change the numeral's width, or the whole line reflows */
.cite-mark[aria-expanded='true'] {
  color: var(--gilt-bright); font-weight: 700;
  text-decoration: underline; text-underline-offset: 2px;
}
/* the default read: no markers, no glosses, prose exactly as written */
body:not(.evidence-on) .cite-mark,
body:not(.evidence-on) .cite-gloss { display: none !important; }

.cite-gloss {
  font-size: 13.5px; line-height: 1.6; color: var(--ink-soft);
  border-left: 2px solid var(--gilt); padding: 2px 0 2px 13px;
  margin: -0.35em 0 1.15em 2px;
}
.cite-n { font-variant: small-caps; letter-spacing: 0.14em; color: var(--gilt); font-size: 12px; }
.cite-label { color: var(--ink); }
.cite-note { display: block; margin-top: 3px; font-style: italic; }
.cite-links { display: block; margin-top: 5px; font-size: 12.5px; }
.cite-sep { color: var(--ink-faint); margin: 0 7px; }
.cite-gloss a, .cart-list a {
  color: var(--ink); text-decoration-color: var(--gilt); text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}
.cite-gloss a:hover, .cart-list a:hover { color: var(--gilt); }
a.cite-out::after { content: ' ↗'; font-size: 0.8em; color: var(--gilt); }
@media (prefers-reduced-motion: no-preference) {
  .cite-gloss { animation: gloss-in 0.22s ease; }
}
@keyframes gloss-in { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: none; } }

/* the sources apparatus, drawn as a chart legend rather than a bibliography */
.cartouche {
  border: 1px solid var(--line); outline: 1px solid var(--line); outline-offset: 3px;
  background: color-mix(in srgb, var(--parchment) 55%, transparent);
  padding: 18px 20px 16px;
}
.cart-h { font-variant: small-caps; letter-spacing: 0.22em; font-size: 11.5px; color: var(--gilt); text-align: center; }
.cart-rule { height: 1px; background: var(--line-faint); margin: 11px 0 14px; }
.cart-list { list-style: none; display: grid; gap: 13px; }
.cart-list li { display: grid; grid-template-columns: 24px 1fr; font-size: 13.5px; line-height: 1.58; color: var(--ink-soft); }
.cart-n { color: var(--gilt); font-variant: small-caps; letter-spacing: 0.1em; font-size: 12.5px; }
.cart-kind {
  font-size: 10px; font-variant: small-caps; letter-spacing: 0.13em; color: var(--ink-faint);
  border: 1px solid var(--line-faint); border-radius: 999px; padding: 1px 7px; margin-left: 7px;
  white-space: nowrap;
}

.deeper { list-style: none; }
.deeper li { font-size: 15px; line-height: 1.6; margin-bottom: 9px; padding-left: 20px; position: relative; color: var(--ink-soft); }
.deeper li::before { content: '❧'; position: absolute; left: 0; color: var(--gilt); }
.deeper-link {
  color: var(--ink); text-decoration-color: var(--gilt); text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}
.deeper-link:hover { color: var(--gilt); }
.deeper-link::after { content: ' ↗'; font-size: 0.78em; color: var(--gilt); }

.page-foot { margin-top: 44px; text-align: center; }
.chart-it { font-size: 16px; padding: 13px 34px; }
.next-up { margin-top: 18px; font-size: 14px; color: var(--ink-soft); }
.next-up button { margin-left: 8px; }

/* wax seal moment */
#seal {
  position: fixed; inset: 0; z-index: 150; display: flex; align-items: center; justify-content: center;
  background: rgba(44, 35, 24, 0.25); animation: seal-fade 1.5s ease forwards;
}
#seal .seal-disc {
  width: 150px; height: 150px; border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #a8503f, var(--seal) 60%, #5e2418);
  display: flex; align-items: center; justify-content: center;
  color: #f3e0c0; font-variant: small-caps; letter-spacing: 0.2em; font-size: 15px;
  box-shadow: 0 6px 30px rgba(0,0,0,0.4), inset 0 0 0 6px rgba(243, 224, 192, 0.18);
  animation: seal-press 0.5s cubic-bezier(0.2, 1.6, 0.4, 1);
}
@keyframes seal-press { from { transform: scale(2.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes seal-fade { 0%, 70% { opacity: 1; } 100% { opacity: 0; } }

/* ---------------- intro ---------------- */
#intro {
  position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center;
  background: rgba(44, 35, 24, 0.45); backdrop-filter: blur(2px); padding: 20px;
  overflow-y: auto;
}
.intro-card {
  max-width: 560px; background: var(--card); padding: 40px 44px;
  border: 1px solid var(--line); outline: 1px solid var(--line); outline-offset: 4px;
  box-shadow: var(--shadow); text-align: center;
}
.intro-card h2 { font-size: 30px; letter-spacing: 0.4em; margin-bottom: 4px; margin-right: -0.4em; }
.intro-card .intro-sub { font-style: italic; color: var(--ink-soft); margin-bottom: 20px; }
.intro-card p { font-size: 15.5px; line-height: 1.7; margin-bottom: 14px; text-align: left; }
.intro-actions { display: flex; gap: 10px; justify-content: center; margin-top: 24px; flex-wrap: wrap; }

/* ---------------- responsive ---------------- */
@media (max-width: 1360px) {
  /* the longest header text; dropping it first keeps the search box usable
     instead of letting flex crush it to its 31px minimum */
  .bar-progress { display: none; }
}

@media (max-width: 900px) {
  .bar-sub, #cartouche, #compass { display: none; }
  #dossier { left: 12px; width: auto; top: auto; height: 62vh; height: 62dvh; }
  /* 16px stops iOS Safari from zooming the page into a focused input */
  #search { font-size: 16px; }
  #bar {
    display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px 10px;
    padding: 8px 10px;
  }
  .bar-search { max-width: none; min-width: 0; }
  .bar-tools {
    grid-column: 1 / -1; width: 100%; min-width: 0; margin-left: 0;
    gap: 8px; overflow-x: auto; scrollbar-width: none;
  }
  .bar-tools::-webkit-scrollbar { display: none; }
  #intro { align-items: flex-start; padding: 16px; }
  .intro-card { width: 100%; margin: 0; }
}

@media (max-width: 560px) {
  .bar-title h1 { font-size: 20px; }
  #thread-chips { gap: 5px; }
  .chip { font-size: 0; gap: 0; padding: 5px; }
  .chip .dot { width: 10px; height: 10px; }
  .btn { padding: 6px 10px; }
  #dossier {
    left: 8px; right: 8px; bottom: max(8px, env(safe-area-inset-bottom));
    height: 68vh; height: 68dvh; padding: 20px 18px 24px;
  }
  body.path-active #dossier {
    bottom: var(--path-bar-clearance, 88px);
    height: calc(100vh - var(--path-bar-clearance, 88px) - var(--mobile-header-height, 94px) - 8px);
    height: calc(100dvh - var(--path-bar-clearance, 88px) - var(--mobile-header-height, 94px) - 8px);
    max-height: 68vh;
    max-height: 68dvh;
  }
  .paths-card { padding: 28px 20px 24px; }
  #path-bar { left: 8px; right: 8px; bottom: max(8px, env(safe-area-inset-bottom)); transform: none; gap: 7px; }
  .path-mid { min-width: 0; flex: 1; }
  .path-quit { padding: 5px 7px; }
  .intro-card { padding: 28px 22px; }
  .intro-card h2 { font-size: 26px; }
  .intro-card p { font-size: 14.5px; line-height: 1.62; }
  .page { padding: 58px 20px 96px; }
  .page-title { font-size: 34px; }
  .page p { font-size: 17px; line-height: 1.7; }
  .q { padding: 14px; }
  .next-up button { display: block; margin: 10px auto 0; }
}

@media (max-width: 360px) {
  .bar-tools { gap: 4px; overflow-x: visible; }
  #thread-chips { gap: 3px; }
  .chip { padding: 4px; }
  .chip .dot { width: 9px; height: 9px; }
  .btn { padding: 5px 7px; }
  .btn-gilt { font-size: 12px; letter-spacing: 0.07em; }
  .btn-ghost { padding: 5px 7px; }
}

/* ---------------- touch ergonomics ---------------- */
/* Sized for fingers, not cursors; fine-pointer layouts are untouched. */
@media (pointer: coarse) {
  .rail-era { padding: 8px 10px; }
  #zoom-tools { gap: 8px; }
  #zoom-tools .btn { width: 42px; height: 42px; font-size: 19px; }
  .chip { padding: 7px; }
  .sr-item { padding: 12px 14px; }
}

html, body { overscroll-behavior: none; }
button, .chip, .rail-era, .sr-item {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* notched phones: keep the fixed chrome out of the sensor and home areas */
@supports (padding: max(0px)) {
  #bar {
    padding-left: max(18px, env(safe-area-inset-left));
    padding-right: max(18px, env(safe-area-inset-right));
  }
  #zoom-tools {
    right: max(12px, env(safe-area-inset-right));
    bottom: max(16px, env(safe-area-inset-bottom));
  }
  #era-rail { right: max(12px, env(safe-area-inset-right)); }
}

@media (prefers-reduced-motion: reduce) {
  /* iteration-count 1 matters: infinite animations at near-zero duration
     strobe instead of stopping (the .next halo breathes forever) */
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  /* the wax seal at zero opacity would still swallow taps for 1.5s */
  #seal { display: none; }
}
