/* ============================================================
   ARCHIVUS — v0.5 "Lens"
   Dark observatory. Modern instrument typography:
   Space Grotesk (structure) · Inter (reading) · IBM Plex Mono (data)
   ============================================================ */

:root {
  --obsidian:      #0a0c12;
  --obsidian-2:    #0e1119;
  --obsidian-3:    #131826;
  --paper:         #e6e1d3;
  --paper-dim:     #a8a494;
  --gold:          #c9a227;
  --gold-bright:   #e8c455;
  --gold-dim:      #6e5c1f;
  --indigo:        #7c9ac9;
  --line:          #262c3b;
  --line-faint:    #181d29;
  --panel-bg:      #10131dfa;
  --sans: "Inter", system-ui, sans-serif;
  --display: "Space Grotesk", system-ui, sans-serif;
  --mono: "IBM Plex Mono", Consolas, monospace;
}

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

html, body { height: 100%; }
body { height: 100dvh; }        /* dynamic viewport: tracks the phone's address bar */

body {
  background:
    radial-gradient(ellipse 130% 75% at 50% -12%, #151d33 0%, transparent 55%),
    radial-gradient(ellipse 85% 55% at 88% 112%, #1c1324 0%, transparent 60%),
    var(--obsidian);
  color: var(--paper);
  font-family: var(--sans);
  font-size: 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.mono { font-family: var(--mono); font-size: 0.82em; letter-spacing: 0.03em; }

/* ============ motion ============ */
@keyframes glowpulse {
  0%, 100% { box-shadow: 0 0 8px rgba(201,162,39,0.35); }
  50%      { box-shadow: 0 0 20px rgba(232,196,85,0.7); }
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes twinkle { 0%, 100% { opacity: 0.04; } 50% { opacity: 0.45; } }
@keyframes condense { from { transform: scale(0); } to { transform: scale(1); } }
@keyframes flow { to { stroke-dashoffset: -24; } }
@keyframes reveal-up {
  from { transform: translateY(8px); opacity: 0; }
  to   { transform: translateY(0);   opacity: 1; }
}

/* ============ masthead ============ */
#masthead {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 22px 10px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(201,162,39,0.05), transparent);
  position: relative;
}
#masthead::after {
  content: "";
  position: absolute; left: 0; right: 0; bottom: -2px; height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-dim) 25%, var(--gold) 50%, var(--gold-dim) 75%, transparent);
  opacity: 0.5;
  pointer-events: none;
}

/* pure-geometry sigil: ring, orbit, nucleus */
.sigil {
  position: relative;
  width: 34px; height: 34px;
  border: 1px solid rgba(201,162,39,0.55);
  border-radius: 50%;
  animation: glowpulse 6s ease-in-out infinite;
}
.sigil::before {
  content: "";
  position: absolute; inset: -5px;
  border: 1px dashed rgba(201,162,39,0.3);
  border-radius: 50%;
  animation: spin 50s linear infinite;
}
.sigil::after {
  content: "";
  position: absolute; left: 50%; top: 50%;
  width: 6px; height: 6px; margin: -3px 0 0 -3px;
  background: var(--gold-bright);
  border-radius: 50%;
  box-shadow: 0 0 10px var(--gold-bright);
}

#masthead h1 {
  font-family: var(--display);
  font-weight: 600;
  font-size: 19px;
  letter-spacing: 0.34em;
  color: var(--gold-bright);
}
.tagline {
  color: var(--paper-dim);
  font-size: 12px;
  letter-spacing: 0.06em;
  margin-top: 1px;
}

#tx-link {
  margin-left: auto;
  font-family: var(--display);
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--gold);
  text-decoration: none;
  border: 1px solid var(--gold-dim);
  border-radius: 4px;
  padding: 7px 14px;
  transition: all 0.18s;
}
#tx-link:hover { color: var(--gold-bright); box-shadow: 0 0 12px rgba(201,162,39,0.22); }
#bl-link, #pn-link, #cx-link, #tr-link {
  margin-left: 8px;
  font-family: var(--display);
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--gold);
  text-decoration: none;
  border: 1px solid var(--gold-dim);
  border-radius: 4px;
  padding: 7px 14px;
  transition: all 0.18s;
}
#bl-link:hover, #pn-link:hover, #cx-link:hover { color: var(--gold-bright); box-shadow: 0 0 12px rgba(201,162,39,0.22); }

.masthead-readout { margin-left: 16px; text-align: right; }
.readout-line { font-family: var(--display); font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--gold); }
.readout-line.mono { font-family: var(--mono); color: var(--paper-dim); font-size: 11px; margin-top: 3px; text-transform: none; }

/* ============ single command bar (main app) ============ */
#bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(201,162,39,0.05), transparent);
  position: relative;
  z-index: 30;
  flex-wrap: nowrap;
}
#bar::after {
  content: "";
  position: absolute; left: 0; right: 0; bottom: -2px; height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-dim) 25%, var(--gold) 50%, var(--gold-dim) 75%, transparent);
  opacity: 0.5;
  pointer-events: none;
}
#bar-title {
  font-family: var(--display);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.3em;
  color: var(--gold-bright);
  margin-right: 4px;
}
.sigil.mini { width: 24px; height: 24px; }
.sigil.mini::before { inset: -4px; }
.sigil.mini::after { width: 5px; height: 5px; margin: -2.5px 0 0 -2.5px; }
#bar .masthead-readout { margin-left: 4px; }
#bar #search { flex: 0 1 220px; }
#bar #tx-link, #bar #bl-link, #bar #pn-link, #bar #cx-link, #bar #tr-link { margin-left: 0; padding: 6px 10px; font-size: 10.5px; }
#bar .sigil.mini { cursor: pointer; }

/* ============ the portal (welcome overlay) ============ */
#welcome {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(7, 9, 15, 0.93);
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
  overflow-y: auto;
}
#welcome[hidden] { display: none !important; }   /* the hidden attribute must always win */
#welcome-card {
  width: min(680px, 96vw);
  max-height: 92dvh; overflow-y: auto;
  background: var(--obsidian-2);
  border: 1px solid var(--gold-dim);
  border-radius: 10px;
  padding: 30px 30px 22px;
  text-align: center;
  box-shadow: 0 30px 90px rgba(0,0,0,.7), 0 0 60px rgba(201,162,39,.08);
  animation: reveal-up 0.35s ease-out;
}
.w-sigil {
  width: 44px; height: 44px; margin: 0 auto 14px;
  border: 1px solid rgba(201,162,39,0.6); border-radius: 50%;
  position: relative; animation: glowpulse 5s ease-in-out infinite;
}
.w-sigil::after {
  content: ""; position: absolute; left: 50%; top: 50%;
  width: 8px; height: 8px; margin: -4px 0 0 -4px;
  background: var(--gold-bright); border-radius: 50%;
  box-shadow: 0 0 12px var(--gold-bright);
}
#welcome-card h2 {
  font-family: var(--display); font-weight: 700; font-size: 20px;
  letter-spacing: 0.34em; color: var(--gold-bright); margin-bottom: 8px;
}
.w-sub { font-size: 13.5px; line-height: 1.6; color: var(--paper-dim); margin-bottom: 20px; }
.w-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.w-door {
  display: flex; flex-direction: column; gap: 4px; align-items: flex-start; text-align: left;
  background: var(--obsidian-3); border: 1px solid var(--line); border-radius: 7px;
  padding: 13px 15px; cursor: pointer; text-decoration: none;
  color: var(--paper); font-family: var(--sans); transition: all 0.16s;
}
.w-door:hover { border-color: var(--gold); background: rgba(201,162,39,0.08); transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,.4); }
.w-door.wide { grid-column: 1 / -1; }
.w-door .w-ic { font-size: 19px; }
.w-door b { font-family: var(--display); font-weight: 600; font-size: 14px; color: var(--gold-bright); letter-spacing: 0.03em; }
.w-door span:last-child { font-size: 11.5px; line-height: 1.5; color: var(--paper-dim); }
.w-foot { margin-top: 16px; font-family: var(--mono); font-size: 10px; color: #59617c; }
.w-foot b { color: var(--gold); font-weight: 400; }
@media (max-width: 700px) {
  .w-grid { grid-template-columns: 1fr; }
  #welcome-card { padding: 22px 18px 16px; }
  #welcome-card h2 { font-size: 16px; letter-spacing: 0.24em; }
}

/* ============ collapsible drawer ============ */
#drawer {
  position: fixed;
  left: 0; top: 48px; bottom: 0;
  width: 300px;
  max-width: 85vw;
  background: var(--panel-bg);
  backdrop-filter: blur(6px);
  border-right: 1px solid var(--line);
  box-shadow: 24px 0 60px rgba(0,0,0,0.5);
  padding: 18px 16px 30px;
  overflow-y: auto;
  z-index: 25;
  transform: translateX(-104%);
  transition: transform 0.3s cubic-bezier(.22,1,.36,1);
}
#drawer.open { transform: translateX(0); }
.d-section { margin-bottom: 20px; }
.d-title {
  font-family: var(--display);
  font-weight: 600;
  font-size: 10px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 9px;
}
.d-row { display: flex; flex-wrap: wrap; gap: 6px; }
.d-row select { max-width: 100%; flex: 1 1 120px; }
#drawer #theme-chips { display: flex; flex-direction: column; gap: 6px; padding: 0; border: none; }
#drawer .chip { justify-content: flex-start; }
.d-legend { display: flex; flex-direction: column; gap: 8px; font-size: 12px; color: var(--paper-dim); }
.d-legend .legend-item { display: inline-flex; align-items: center; gap: 7px; line-height: 1.5; }

/* atlas time-play + narrative tours */
#play-btn {
  position: absolute;
  left: 10px; bottom: 46px;
  z-index: 6;
  box-shadow: 0 4px 18px rgba(0,0,0,0.5), 0 0 14px rgba(201,162,39,0.15);
}
#tours-menu {
  position: absolute;
  right: 12px; top: 8px;
  z-index: 40;
  background: var(--panel-bg);
  backdrop-filter: blur(6px);
  border: 1px solid var(--gold-dim);
  border-radius: 6px;
  padding: 10px;
  width: 340px;
  max-width: 90vw;
  box-shadow: 0 14px 44px rgba(0,0,0,0.6);
}
.tour-item {
  padding: 9px 10px;
  border-left: 2px solid var(--gold-dim);
  background: rgba(255,255,255,0.02);
  margin-bottom: 6px;
  cursor: pointer;
  transition: all 0.15s;
}
.tour-item:hover { background: rgba(201,162,39,0.1); border-left-color: var(--gold); }
.tour-item .tt { font-family: var(--display); font-weight: 600; font-size: 12.5px; color: var(--gold-bright); }
.tour-item .tb { font-size: 11.5px; color: var(--paper-dim); margin-top: 2px; line-height: 1.45; }
#tour-card {
  position: absolute;
  left: 50%; bottom: 52px;
  transform: translateX(-50%);
  z-index: 35;
  width: 560px; max-width: 92%;
  background: var(--panel-bg);
  backdrop-filter: blur(6px);
  border: 1px solid var(--gold-dim);
  border-radius: 6px;
  padding: 14px 16px 12px;
  box-shadow: 0 16px 50px rgba(0,0,0,0.65), 0 0 24px rgba(201,162,39,0.1);
  animation: reveal-up 0.25s ease-out;
}
#tour-note { font-size: 14px; line-height: 1.6; color: var(--paper); margin: 6px 0 10px; }
#tour-nav { display: flex; align-items: center; gap: 8px; }
#tour-step { font-size: 10.5px; color: #59617c; margin: 0 auto 0 4px; }
.map-year-big {
  font-family: "IBM Plex Mono", monospace;
  fill: var(--gold-bright);
  font-size: 34px;
  letter-spacing: 0.06em;
  paint-order: stroke; stroke: rgba(10,12,18,0.85); stroke-width: 6px;
}
.ignite { pointer-events: none; }
#play-speed { position: absolute; left: 150px; bottom: 46px; z-index: 6; }
#play-era {
  position: absolute; left: 10px; bottom: 88px; z-index: 6;
  font-family: var(--display); font-weight: 700;
  font-size: 21px; letter-spacing: 0.24em; text-transform: uppercase;
  color: var(--gold-bright);
  text-shadow: 0 0 18px rgba(201,162,39,0.5), 0 2px 4px rgba(0,0,0,0.8);
  pointer-events: none;
}
#play-era.flash { animation: era-flash 0.9s ease-out; }
@keyframes era-flash {
  0% { transform: scale(1.5); opacity: 0; letter-spacing: 0.5em; }
  100% { transform: scale(1); opacity: 1; letter-spacing: 0.24em; }
}
#play-feed {
  position: absolute; left: 10px; top: 46px; z-index: 6;
  width: 320px; max-width: 44vw;
  display: flex; flex-direction: column; gap: 4px;
  pointer-events: none;
}
.feed-item {
  background: rgba(10,12,18,0.72);
  border-left: 3px solid var(--c, var(--gold));
  border-radius: 0 3px 3px 0;
  padding: 4px 10px;
  font-size: 12px;
  color: var(--paper);
  animation: reveal-up 0.3s ease-out;
}
.feed-item .fy { font-family: var(--mono); font-size: 9.5px; color: var(--gold-bright); display: block; }
.feed-item:nth-child(n+4) { opacity: 0.55; }
.feed-item:nth-child(n+6) { opacity: 0.28; }
.wheel-hand { stroke: var(--gold-bright); stroke-width: 1.6; filter: drop-shadow(0 0 8px rgba(232,196,85,0.8)); pointer-events: none; }
.wheel-hand-tip { fill: var(--gold-bright); filter: drop-shadow(0 0 10px rgba(232,196,85,0.9)); pointer-events: none; }
.wheel-year-big {
  font-family: "IBM Plex Mono", monospace;
  fill: var(--gold-bright); font-size: 22px;
  paint-order: stroke; stroke: rgba(10,12,18,0.85); stroke-width: 5px;
}

/* floating status chip inside the chart */
#status {
  position: absolute;
  right: 10px; bottom: 8px;
  font-size: 10.5px;
  color: #59617c;
  background: rgba(10,12,18,0.55);
  border: 1px solid var(--line-faint);
  border-radius: 3px;
  padding: 3px 9px;
  pointer-events: none;
  z-index: 5;
}

/* ============ toolbar ============ */
#toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 22px;
  border-bottom: 1px solid var(--line-faint);
}

#view-switch {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 4px;
  overflow: hidden;
}
.view-btn {
  background: var(--obsidian-3);
  border: none;
  border-right: 1px solid var(--line);
  color: var(--paper-dim);
  font-family: var(--display);
  font-weight: 500;
  font-size: 12px;
  letter-spacing: 0.04em;
  padding: 8px 14px;
  cursor: pointer;
  transition: all 0.18s;
}
.view-btn:last-child { border-right: none; }
.view-btn:hover { color: var(--gold-bright); }
.view-btn.active {
  background: rgba(201,162,39,0.15);
  color: var(--gold-bright);
  box-shadow: inset 0 -2px 0 var(--gold);
}

#search {
  flex: 0 1 280px;
  background: var(--obsidian-3);
  border: 1px solid var(--line);
  color: var(--paper);
  font-family: var(--sans);
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 4px;
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s;
}
#search:focus { border-color: var(--gold-dim); box-shadow: 0 0 12px rgba(201,162,39,0.2); }
#search::placeholder { color: #5c637a; }

select {
  background: var(--obsidian-3);
  border: 1px solid var(--line);
  color: var(--paper);
  font-family: var(--sans);
  font-size: 12.5px;
  padding: 8px 8px;
  border-radius: 4px;
  max-width: 170px;
  transition: border-color 0.18s;
}
select:hover, select:focus { border-color: var(--gold-dim); outline: none; }

.toolbar-spacer { flex: 1; }

.tool-btn {
  background: var(--obsidian-3);
  border: 1px solid var(--line);
  color: var(--paper-dim);
  font-family: var(--display);
  font-weight: 500;
  font-size: 12px;
  letter-spacing: 0.04em;
  padding: 8px 12px;
  border-radius: 4px;
  cursor: pointer;
  min-width: 34px;
  transition: all 0.18s;
}
.tool-btn:hover {
  border-color: var(--gold-dim);
  color: var(--gold-bright);
  box-shadow: 0 0 10px rgba(201,162,39,0.16);
}
.tool-btn.accent { border-color: var(--gold-dim); color: var(--gold); }
.tool-btn.wide { padding: 8px 14px; }

/* ============ theme chips ============ */
#theme-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 22px 9px;
  border-bottom: 1px solid var(--line-faint);
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--sans);
  font-weight: 500;
  font-size: 11.5px;
  letter-spacing: 0.02em;
  color: var(--paper-dim);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 4px 11px;
  cursor: pointer;
  transition: all 0.18s;
  user-select: none;
}
.chip .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--c, var(--gold));
  box-shadow: 0 0 7px var(--c, var(--gold));
}
.chip:hover { border-color: var(--gold-dim); color: var(--paper); }
.chip.active {
  border-color: var(--c, var(--gold));
  color: var(--paper);
  background: color-mix(in srgb, var(--c, var(--gold)) 14%, transparent);
}
.chip.dimmed { opacity: 0.35; }

/* ============ stage ============ */
#stage { flex: 1; display: flex; min-height: 0; position: relative; }

#chart-wrap { flex: 1; position: relative; min-width: 0; }

#chart {
  width: 100%; height: 100%; display: block;
  cursor: crosshair;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
#chart.panning { cursor: grabbing; }

/* --- SVG vocabulary --- */
.era-band { cursor: pointer; transition: filter 0.18s; }
.era-band:hover { filter: brightness(1.8); }
.era-band-label {
  font-family: "Space Grotesk", system-ui, sans-serif;
  font-weight: 500;
  fill: #8f9ab5;
  letter-spacing: 0.12em;
  pointer-events: none;
  text-transform: uppercase;
}
.era-boundary { stroke: var(--line-faint); stroke-width: 1; }
.axis-tick-label { font-family: "IBM Plex Mono", monospace; fill: #66708c; font-size: 10px; }
.axis-line { stroke: var(--line); }
.meridian { stroke: var(--gold-dim); stroke-width: 1; stroke-dasharray: 3 4; }
.meridian-label { font-family: "Space Grotesk", sans-serif; fill: var(--gold-dim); font-size: 9px; letter-spacing: 0.16em; }
.lane-label {
  font-family: "Space Grotesk", system-ui, sans-serif;
  font-weight: 500;
  fill: #4d5670;
  font-size: 9.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  pointer-events: none;
}
.lane-line { stroke: var(--line-faint); stroke-dasharray: 1 5; }

.evt { cursor: pointer; }
.evt .node-core { transition: r 0.16s cubic-bezier(.34,1.56,.64,1); }
.evt-label {
  font-family: "Inter", system-ui, sans-serif;
  fill: var(--paper-dim);
  font-size: 10.5px;
  letter-spacing: 0.01em;
  pointer-events: none;
  paint-order: stroke;
  stroke: rgba(10,12,18,0.88);
  stroke-width: 3px;
}
.evt-label.major { fill: var(--paper); font-size: 11.5px; font-weight: 500; }

.enter .evt {
  transform-box: fill-box;
  transform-origin: center;
  animation: condense 0.5s cubic-bezier(.34,1.56,.64,1) both;
}

/* the standing web of relations */
.web-line {
  stroke: var(--gold);
  stroke-width: 0.6;
  opacity: 0.10;
  pointer-events: none;
}
/* the ignited thread */
.constellation {
  stroke: var(--gold-bright);
  stroke-width: 1;
  stroke-dasharray: 3 5;
  opacity: 0.8;
  pointer-events: none;
  animation: flow 1.6s linear infinite;
}

.star { fill: #b8c4e8; pointer-events: none; }
.star.twinkle { animation-name: twinkle; animation-iteration-count: infinite; animation-timing-function: ease-in-out; }

.time-cursor { stroke: rgba(232,196,85,0.3); stroke-width: 1; pointer-events: none; }
.time-cursor-label {
  font-family: "IBM Plex Mono", monospace;
  fill: var(--gold-bright); font-size: 10px;
  pointer-events: none;
  paint-order: stroke; stroke: rgba(10,12,18,0.9); stroke-width: 3px;
}

.ov-bg { fill: var(--obsidian-2); stroke: var(--line-faint); }
.ov-brush {
  fill: rgba(201,162,39,0.15);
  stroke: var(--gold-dim);
  stroke-width: 1;
  cursor: ew-resize;
  transition: fill 0.18s;
}
.ov-brush:hover { fill: rgba(201,162,39,0.26); }
.ov-dot { pointer-events: none; }
.ov-hit { fill: transparent; cursor: pointer; }

/* atlas */
.map-frame { fill: rgba(124,154,201,0.02); stroke: var(--line); stroke-width: 1; }
.graticule { stroke: var(--line-faint); stroke-width: 0.6; }
.graticule.equator { stroke: var(--gold-dim); stroke-dasharray: 2 5; opacity: 0.5; }
.map-land { fill: rgba(230,225,211,0.11); stroke: #6b7899; stroke-width: 0.9; }
.map-border { fill: none; stroke: #3a445c; stroke-width: 0.6; stroke-dasharray: 2 2; opacity: 0.7; }
.map-country { fill: rgba(230,225,211,0.10); stroke: #4d5a78; stroke-width: 0.7; transition: fill 0.2s; }
.map-country:hover { fill: rgba(201,162,39,0.14); stroke: var(--gold-dim); }
.map-caption {
  font-family: "Space Grotesk", sans-serif;
  fill: var(--gold-dim); font-size: 10px; letter-spacing: 0.16em;
}

/* wheel */
.wheel-ring { fill: none; stroke: var(--line-faint); stroke-dasharray: 1 5; }
.wheel-era { transition: filter 0.18s; }
.wheel-era:hover { filter: brightness(1.9); }
.wheel-era-label {
  font-family: "Space Grotesk", sans-serif;
  font-weight: 500;
  fill: #8f9ab5; font-size: 8.5px; letter-spacing: 0.1em; text-transform: uppercase;
  pointer-events: none;
}
.wheel-center-disc { fill: rgba(201,162,39,0.05); stroke: var(--gold-dim); stroke-width: 0.8; stroke-dasharray: 2 4; }
.wheel-center-title {
  font-family: "Space Grotesk", sans-serif;
  font-weight: 600;
  fill: var(--gold-bright); font-size: 12px; letter-spacing: 0.3em;
}
.wheel-center-sub { font-family: "IBM Plex Mono", monospace; fill: var(--paper-dim); font-size: 9px; }

/* ============ tooltip ============ */
#tooltip {
  position: absolute;
  pointer-events: none;
  background: #151927f5;
  border: 1px solid var(--gold-dim);
  border-radius: 4px;
  padding: 8px 12px;
  max-width: 280px;
  z-index: 30;
  box-shadow: 0 6px 24px rgba(0,0,0,0.6);
  animation: reveal-up 0.14s ease-out;
}
#tooltip .tt-title { font-family: var(--display); font-weight: 500; font-size: 12.5px; color: var(--gold-bright); }
#tooltip .tt-date { font-family: var(--mono); font-size: 10px; color: var(--paper-dim); margin-top: 3px; }

/* ============ slide-in panel ============ */
#panel {
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: 360px;
  max-width: 88vw;
  border-left: 1px solid var(--line);
  background: var(--panel-bg);
  backdrop-filter: blur(6px);
  padding: 48px 24px 30px;
  overflow-y: auto;
  z-index: 20;
  transform: translateX(102%);
  transition: transform 0.32s cubic-bezier(.22,1,.36,1);
  box-shadow: -24px 0 60px rgba(0,0,0,0.55);
}
#panel.open { transform: translateX(0); }
#panel::before {
  content: "";
  position: absolute; left: 0; top: 0; bottom: 0; width: 2px;
  background: linear-gradient(180deg, var(--gold-dim), transparent 40%, transparent 60%, var(--gold-dim));
  opacity: 0.5;
  pointer-events: none;
}

#panel-close {
  position: absolute;
  top: 10px; right: 12px;
  width: 30px; height: 30px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--paper-dim);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  transition: all 0.18s;
  z-index: 2;
}
#panel-close:hover { border-color: var(--gold-dim); color: var(--gold-bright); }

#panel-content, #panel-oracle { animation: reveal-up 0.28s ease-out; }

.kicker {
  font-family: var(--display);
  font-weight: 600;
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 8px;
}

#panel-title {
  font-family: var(--display);
  font-weight: 600;
  font-size: 20px;
  line-height: 1.25;
  color: var(--paper);
  margin-bottom: 8px;
}

#panel-date { color: var(--gold-bright); font-size: 12px; margin-bottom: 14px; }

#panel-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.meta-tag {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 3px 8px;
  color: var(--paper-dim);
}
.meta-tag.theme-tag { border-color: var(--c, var(--line)); color: var(--c, var(--paper-dim)); }

#panel-desc { font-size: 14.5px; line-height: 1.65; color: var(--paper); margin-bottom: 18px; }

#panel-importance { margin-bottom: 18px; }
#panel-importance .label {
  display: block; font-family: var(--display); font-weight: 500; font-size: 9.5px;
  letter-spacing: 0.2em; text-transform: uppercase; color: #59617c; margin-bottom: 6px;
}
.imp-track {
  display: block; height: 6px; border-radius: 3px;
  background: rgba(255,255,255,0.05);
  overflow: hidden;
}
.imp-fill {
  display: block; height: 100%;
  background: linear-gradient(90deg, var(--gold-dim), var(--gold-bright));
  border-radius: 3px;
  box-shadow: 0 0 8px rgba(201,162,39,0.5);
}

#panel-source {
  display: inline-block;
  font-family: var(--display);
  font-weight: 500;
  font-size: 11.5px;
  letter-spacing: 0.08em;
  color: var(--gold);
  text-decoration: none;
  border: 1px solid var(--gold-dim);
  padding: 7px 14px;
  border-radius: 4px;
  margin-bottom: 24px;
  transition: all 0.18s;
}
#panel-source:hover {
  background: rgba(201,162,39,0.12);
  color: var(--gold-bright);
}

#panel-related { display: flex; flex-direction: column; gap: 6px; }
.related-link {
  font-size: 13px;
  color: var(--paper-dim);
  cursor: pointer;
  padding: 6px 10px;
  border-left: 2px solid var(--gold-dim);
  background: rgba(255,255,255,0.02);
  transition: all 0.16s;
}
.related-link:hover {
  color: var(--gold-bright);
  background: rgba(201,162,39,0.09);
  border-left-color: var(--gold);
  transform: translateX(3px);
}
.related-link .rl-date { font-family: var(--mono); font-size: 9.5px; color: #59617c; display: block; }

/* ============ oracle & era records ============ */
#panel-oracle .o-title {
  font-family: var(--display);
  font-weight: 600;
  font-size: 18px;
  color: var(--gold-bright);
  margin-bottom: 4px;
}
#panel-oracle .o-span { font-family: var(--mono); font-size: 11px; color: var(--paper-dim); margin-bottom: 16px; }
#panel-oracle .o-prose { font-size: 14.5px; line-height: 1.68; color: var(--paper); margin-bottom: 18px; }
#panel-oracle .o-prose em { color: var(--gold-bright); font-style: normal; font-weight: 500; }
#panel-oracle .o-section { margin-bottom: 18px; }
#panel-oracle .o-evt {
  display: block;
  font-size: 13px;
  color: var(--paper-dim);
  cursor: pointer;
  padding: 5px 10px;
  border-left: 2px solid var(--gold-dim);
  background: rgba(255,255,255,0.02);
  margin-bottom: 5px;
  transition: all 0.16s;
}
#panel-oracle .o-evt:hover {
  color: var(--gold-bright);
  background: rgba(201,162,39,0.09);
  border-left-color: var(--gold);
  transform: translateX(3px);
}
#panel-oracle .o-evt .oe-date { font-family: var(--mono); font-size: 9.5px; color: #59617c; display: block; }
.o-bar-row { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; }
.o-bar-name { font-family: var(--mono); font-size: 9.5px; color: var(--paper-dim); width: 108px; flex: none; text-align: right; }
.o-bar-track { flex: 1; height: 7px; background: rgba(255,255,255,0.04); border-radius: 3px; overflow: hidden; }
.o-bar-fill {
  display: block;
  height: 100%; border-radius: 3px;
  box-shadow: 0 0 8px var(--c, var(--gold));
  background: var(--c, var(--gold));
  transition: width 0.6s cubic-bezier(.22,1,.36,1);
}
.o-bar-n { font-family: var(--mono); font-size: 9.5px; color: #59617c; width: 22px; }
.o-divider { border: none; border-top: 1px solid var(--line); margin: 16px 0; }

/* cross-instrument jump links + help overlay */
.tx-jump {
  display: block;
  font-size: 12.5px;
  color: var(--gold);
  text-decoration: none;
  padding: 6px 10px;
  border-left: 2px solid var(--gold-dim);
  background: rgba(201,162,39,0.04);
  margin-bottom: 5px;
  transition: all 0.16s;
}
.tx-jump:hover { color: var(--gold-bright); background: rgba(201,162,39,0.1); transform: translateX(3px); }
#panel-tx { margin-top: 18px; }
#help-overlay {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  z-index: 50;
  background: var(--panel-bg);
  backdrop-filter: blur(8px);
  border: 1px solid var(--gold-dim);
  border-radius: 6px;
  padding: 18px 22px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.7), 0 0 30px rgba(201,162,39,0.1);
  animation: reveal-up 0.2s ease-out;
}
#help-overlay table { border-collapse: collapse; margin: 6px 0 10px; }
#help-overlay td { padding: 3px 14px 3px 0; font-size: 13px; color: var(--paper); }
#help-overlay td:first-child { font-family: var(--mono); color: var(--gold-bright); font-size: 11.5px; white-space: nowrap; }
#help-overlay .hint { font-size: 10px; color: #59617c; line-height: 1.6; }

/* ============ legend ============ */
#legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  padding: 6px 22px;
  border-top: 1px solid var(--line);
  background: var(--obsidian-2);
  font-size: 11.5px;
  color: var(--paper-dim);
}
.legend-title {
  font-family: var(--display);
  font-weight: 600;
  font-size: 9.5px; letter-spacing: 0.24em; text-transform: uppercase;
  color: var(--gold-dim);
}
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
#event-count { margin-left: auto; color: #59617c; }

/* ============ responsive & a11y ============ */
@media (max-width: 900px) {
  #masthead h1 { font-size: 16px; letter-spacing: 0.22em; }
  .masthead-readout { display: none; }
  #search { flex-basis: 150px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001s !important; animation-iteration-count: 1 !important; transition-duration: 0.001s !important; }
}

::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-track { background: var(--obsidian); }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--gold-dim); }

/* ============ the pocket archive: phones & small screens ============ */
@media (max-width: 700px) {
  /* the page may always scroll on a phone — never trap the user */
  body { overflow-y: auto; -webkit-overflow-scrolling: touch; }
  main, #stage { min-height: 64dvh; }
  #panel, #drawer, #bl-panel, #pn-panel, #as-panel { -webkit-overflow-scrolling: touch; }
  #bar { flex-wrap: wrap; padding: 6px 8px; gap: 5px; row-gap: 5px; }
  #bar-title { font-size: 13px; letter-spacing: 0.2em; }
  #bar .tool-btn, #view-switch .view-btn { padding: 5px 8px; font-size: 10px; }
  #bar #tx-link, #bar #bl-link, #bar #pn-link { padding: 5px 7px; font-size: 9px; }
  #search { flex: 1 1 110px; min-width: 90px; font-size: 12px; padding: 6px 9px; }
  .masthead-readout { display: none; }
  .toolbar-spacer { display: none; }
  #drawer { width: 100vw; max-width: 100vw; }
  #panel { width: 100vw; max-width: 100vw; }
  #masthead { padding: 8px 12px; flex-wrap: wrap; gap: 6px; }
  #masthead h1 { font-size: 14px; }
  #masthead .tagline { display: none; }
  #play-feed { width: 58vw; font-size: 9px; }
  #play-era { font-size: 11px; }
  #status { font-size: 9px; }
  #help-overlay { width: 92vw; }
  #tour-card { width: 90vw; left: 5vw; }
  #bl-panel, #pn-panel { width: 100vw; max-width: 100vw; }
  #bl-toolbar, #pn-toolbar { padding: 6px 8px; gap: 4px; }
  #bl-mini { display: none; }
  #bl-hint, #pn-legend { display: none; }
}
