:root {
  --night: #171510;
  --band: rgba(236, 230, 214, .035);
  --land: rgba(236, 230, 214, .075);
  --surface: #221f18;
  --surface-2: #2c2820;
  --star: #ece6d6;
  --dim: #a39b88;
  --rule: rgba(236, 230, 214, .14);
  --gold: #e2b85c;
  --focus: #f2c66d;
  --shadow: 0 18px 48px rgba(0, 0, 0, .5);

  --l-line: #d8b25a; --l-reborn: #f2913d; --l-cross: #ee7fb8; --l-kill: #ef5a5a;
  --l-deva: #ad94ff; --l-tell: #6cb4ff; --l-reign: #93cf6b; --l-story: #3fc9b5;
  --k-person: #ece6d6; --k-sage: #8cc4ff; --k-avatar: #f2a050; --k-deva: #bba6ff; --k-event: #4fd3be; --k-story: #4fd3be;

  --font-display: "Tiro Devanagari Sanskrit", "Iowan Old Style", Georgia, serif;
  --font-ui: "Hanken Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  --ribbon: 64px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --night: #f1efe9;
  --band: rgba(40, 34, 22, .045);
  --land: rgba(40, 34, 22, .09);
  --surface: #ffffff;
  --surface-2: #f4f2ec;
  --star: #24201a;
  --dim: #6e6656;
  --rule: rgba(40, 34, 22, .15);
  --gold: #a7781a;
  --focus: #a7781a;
  --shadow: 0 18px 48px rgba(40, 34, 22, .16);

  --l-line: #a7781a; --l-reborn: #c4600f; --l-cross: #b8337a; --l-kill: #c62828;
  --l-deva: #6b4fd1; --l-tell: #2563c9; --l-reign: #4d8a24; --l-story: #0f8a78;
  --k-person: #1b1f3d; --k-sage: #2563c9; --k-avatar: #c4600f; --k-deva: #6b4fd1; --k-event: #0f8a78; --k-story: #0f8a78;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; overflow: hidden; background: var(--night); color: var(--star);
  font: 15px/1.5 var(--font-ui); -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

#sky, #map { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; touch-action: none; cursor: grab; }
#sky.dragging, #map.dragging { cursor: grabbing; }
#sky.pointing, #map.pointing { cursor: pointer; }

.views { display: flex; }
.views .btn { display: inline-grid; place-items: center; text-decoration: none; border-radius: 0; }
.views .btn:first-child { border-radius: 10px 0 0 10px; }
.views .btn:last-child { border-radius: 0 10px 10px 0; border-left: 0; }
.views .btn[aria-current="page"] { background: var(--star); color: var(--night); border-color: var(--star); }

.timebar {
  position: fixed; z-index: 5; left: 0; right: 0; bottom: 0; display: flex; gap: 14px; align-items: center;
  padding: 14px 20px max(14px, env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--night) 35%);
}
.timebar input { flex: 1; min-width: 0; accent-color: var(--gold); }
/* Fixed size, so the slider and the bar keep their size whatever the label says. */
.timebar output { flex: none; width: 34ch; height: 56px; display: grid; align-content: center; gap: 3px; text-align: right; overflow: hidden; }
.timebar output .main { font: 400 20px/1 var(--font-display); color: var(--gold); white-space: nowrap; }
.timebar output .sub { font-size: 12px; line-height: 15px; color: var(--dim); display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.timebar .track { position: relative; flex: 1; min-width: 0; padding-bottom: 16px; }
.timebar .track input { width: 100%; margin: 0; height: 18px; background: transparent; -webkit-appearance: none; appearance: none; cursor: pointer; }
.timebar .track input:focus { outline: none; }
.timebar .track input:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 3px var(--night), 0 0 0 5px var(--focus); }
.timebar .track input::-webkit-slider-runnable-track { height: 4px; border: 0; border-radius: 2px; background: var(--rule); }
.timebar .track input::-moz-range-track { height: 4px; border: 0; border-radius: 2px; background: var(--rule); }
.timebar .track input::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--gold); }
.timebar .track input::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; margin-top: -6px; border: 0; border-radius: 50%; background: var(--gold); }
.timebar .track input::-moz-range-thumb { width: 16px; height: 16px; border: 0; border-radius: 50%; background: var(--gold); }
.timebar .ticks { position: absolute; left: 0; right: 0; bottom: 0; height: 14px; font-size: 11px; color: var(--dim); pointer-events: none; }
.timebar .ticks span { position: absolute; top: 0; transform: translateX(-50%); white-space: nowrap; }
.timebar .ticks span.age { color: var(--star); opacity: .8; }
.timebar .ticks span.end { transform: translateX(-100%); }
.links button.dim { opacity: .55; }
.realms { font-size: 14.5px; }
#mapPanel:not([hidden]) ~ .timebar { right: 412px; }

body.view-map .ribbon, body.view-map #filtersBtn, body.view-map #storiesBtn, body.view-map .hint { display: none; }
body.view-map .top { left: 0; }
body.view-map .zoom { bottom: 96px; }

.top {
  position: fixed; top: 0; left: var(--ribbon); right: 0; z-index: 5;
  display: flex; flex-wrap: wrap; gap: 10px 20px; align-items: center; justify-content: space-between;
  padding: max(14px, env(safe-area-inset-top)) 16px 14px 20px; pointer-events: none;
  background: linear-gradient(var(--night) 30%, transparent);
}
.top > * { pointer-events: auto; }
.brand { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; min-width: 0; }
.brand h1 { margin: 0; font: 400 30px/1 var(--font-display); letter-spacing: .01em; }
.brand p { margin: 0; color: var(--dim); font-size: 13.5px; }
.tools { display: flex; gap: 8px; align-items: center; flex: 1 1 320px; justify-content: flex-end; min-width: 0; }

.btn {
  height: 36px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--rule);
  background: var(--surface); color: var(--star); font-weight: 500; font-size: 14px; cursor: pointer;
}
.btn:hover { border-color: var(--dim); }
.btn.icon { width: 36px; padding: 0; display: inline-grid; place-items: center; }
.btn[aria-expanded="true"], .btn[aria-pressed="true"] { background: var(--star); color: var(--night); border-color: var(--star); }
#filtersBtn.on::after { content: ""; display: inline-block; width: 7px; height: 7px; margin-left: 8px; border-radius: 50%; background: var(--gold); vertical-align: 1px; }

.search { position: relative; flex: 1 1 200px; max-width: 360px; min-width: 0; }
.search svg { position: absolute; left: 12px; top: 10px; color: var(--dim); pointer-events: none; }
.search input {
  width: 100%; height: 36px; padding: 0 12px 0 36px; border-radius: 10px; border: 1px solid var(--rule);
  background: var(--surface); color: var(--star); font: 500 14.5px var(--font-ui);
}
.search input::placeholder { color: var(--dim); }
#qres {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; min-width: 260px; max-height: 60vh; overflow: auto;
  margin: 0; padding: 6px; list-style: none; background: var(--surface); border: 1px solid var(--rule);
  border-radius: 12px; box-shadow: var(--shadow);
}
#qres li { display: grid; grid-template-columns: 10px 1fr; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
#qres li[aria-selected="true"], #qres li:hover { background: var(--surface-2); }
#qres .sw { width: 10px; height: 10px; border-radius: 50%; }
#qres .where { display: block; font-size: 12.5px; color: var(--dim); }
#qres .empty { display: block; color: var(--dim); cursor: default; }

.ribbon {
  position: fixed; left: 0; top: 0; bottom: 0; width: var(--ribbon); z-index: 6;
  display: flex; flex-direction: column; padding: max(14px, env(safe-area-inset-top)) 10px max(14px, env(safe-area-inset-bottom));
  gap: 4px; background: var(--night); border-right: 1px solid var(--rule);
}
.ribbon button {
  position: relative; flex: var(--w) 1 0; min-height: 28px; border: 0; border-radius: 8px; cursor: pointer;
  background: var(--band); color: var(--dim); overflow: hidden; padding: 0;
}
.ribbon button span {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%) rotate(-90deg);
  white-space: nowrap; font: 400 15px/1 var(--font-display);
}
.ribbon button.short span { font-size: 12px; }
.ribbon button:hover { color: var(--star); }
.ribbon button[aria-current="true"] { background: var(--surface-2); color: var(--gold); }
.ribbon .here {
  position: absolute; left: 3px; right: 3px; top: 0; height: 2px; border-radius: 1px; background: var(--gold);
  box-shadow: 0 0 8px var(--gold); pointer-events: none; will-change: transform; transition: transform .12s linear;
}

.filters {
  position: fixed; z-index: 7; top: 66px; right: 16px; width: min(440px, calc(100vw - var(--ribbon) - 32px));
  max-height: calc(100vh - 90px); overflow: auto; padding: 16px 18px 18px; display: grid; gap: 16px;
  background: var(--surface); border: 1px solid var(--rule); border-radius: 14px; box-shadow: var(--shadow);
}
/* Left of the view, so a picked step's detail panel opens beside it on the right. */
.stories { left: calc(var(--ribbon) + 16px); right: auto; width: min(380px, calc(100vw - var(--ribbon) - 32px)); align-content: start; }
.stories .seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 0; }
.stories .seg button { border-radius: 0; margin-left: -1px; }
.stories .seg button:first-child { border-radius: 8px 0 0 8px; margin-left: 0; }
.stories .seg button:last-child { border-radius: 0 8px 8px 0; }
.steps { margin: 0; padding: 0; list-style: none; display: grid; gap: 2px; }
.steps button {
  display: grid; grid-template-columns: 2ch 1fr; column-gap: 10px; width: 100%; padding: 8px 10px; border: 0; border-radius: 8px;
  background: transparent; color: var(--star); text-align: left; cursor: pointer; font-size: 14px;
}
.steps button .i { color: var(--dim); text-align: right; }
.steps button .d {
  grid-column: 2; color: var(--dim); font-size: 12.5px; line-height: 1.35; margin-top: 2px;
  display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.steps button:hover, .steps button[aria-current="true"] { background: var(--band); }
.steps button[aria-current="true"] { color: var(--gold); }
.fgroup { display: grid; gap: 8px; }
.fgroup h2 { margin: 0; font: 600 13px var(--font-ui); color: var(--dim); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; height: 32px; padding: 0 12px; border-radius: 16px;
  border: 1px solid var(--rule); background: transparent; color: var(--star); font-size: 13.5px; cursor: pointer;
}
.chip .n { color: var(--dim); font-size: 12px; }
.chip .ln { width: 18px; height: 3px; border-radius: 2px; }
.chip[aria-pressed="false"].toggle { opacity: .45; }
.chip[aria-pressed="true"]:not(.toggle) { background: var(--star); color: var(--night); border-color: var(--star); }
.chip[aria-pressed="true"]:not(.toggle) .n { color: var(--night); opacity: .7; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { height: 32px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--rule); background: transparent; cursor: pointer; font-size: 13.5px; }
.seg button[aria-checked="true"] { background: var(--star); color: var(--night); border-color: var(--star); }

.panel {
  position: fixed; z-index: 8; right: 16px; top: 66px; bottom: 16px; width: 380px; overflow: auto;
  padding: 20px 20px 24px; display: grid; align-content: start; gap: 12px;
  background: var(--surface); border: 1px solid var(--rule); border-radius: 16px; box-shadow: var(--shadow);
}
.panel-head { display: flex; gap: 12px; align-items: start; justify-content: space-between; }
.panel h2 { margin: 0; font: 400 30px/1.12 var(--font-display); text-wrap: balance; }
.close { flex: none; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-size: 12.5px; padding: 3px 9px; border-radius: 12px; background: var(--surface-2); color: var(--dim); }
.tag.age { color: var(--gold); }
.panel p { margin: 0; line-height: 1.55; max-width: 62ch; }
.panel h3 { margin: 8px 0 0; font: 600 13px var(--font-ui); color: var(--dim); }
.cites { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 13px; }
.cites a { color: var(--star); text-decoration-color: var(--rule); text-underline-offset: 3px; }
.cites .more { background: none; border: 0; padding: 0; color: var(--gold); font-size: 13px; cursor: pointer; }
.trace { display: flex; flex-wrap: wrap; gap: 2px 4px; align-items: center; font-size: 14px; }
.trace button { background: none; border: 0; padding: 2px; cursor: pointer; text-decoration: underline; text-decoration-color: var(--rule); text-underline-offset: 3px; }
.trace .sep { color: var(--dim); }
.places { margin: 0; padding: 0; list-style: none; display: grid; gap: 4px; font-size: 14.5px; }
.places .how { display: block; font-size: 12.5px; color: var(--dim); }
.links { display: grid; gap: 2px; }
.links button {
  display: grid; grid-template-columns: 16px 1fr; gap: 10px; align-items: baseline; text-align: left;
  background: none; border: 0; border-radius: 8px; padding: 6px 8px; cursor: pointer; font-size: 15px; line-height: 1.35;
}
.links button:hover { background: var(--surface-2); }
.links .ln { width: 16px; height: 3px; border-radius: 2px; align-self: center; }
.links .how { display: block; font-size: 12.5px; color: var(--dim); }

.zoom { position: fixed; z-index: 5; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); display: flex; gap: 6px; }
.panel:not([hidden]) ~ .zoom { right: 412px; }
.hint {
  position: fixed; z-index: 4; left: calc(var(--ribbon) + 20px); bottom: max(18px, env(safe-area-inset-bottom)); margin: 0;
  max-width: 50ch; color: var(--dim); font-size: 13px; pointer-events: none;
}

@media (max-width: 760px) {
  :root { --ribbon: 44px; }
  .ribbon { padding-inline: 6px; }
  .ribbon button span { font-size: 13px; }
  .brand h1 { font-size: 24px; }
  .brand p, .hint { display: none; }
  .tools { flex-basis: 100%; }
  .search { max-width: none; }
  .filters { top: 106px; right: 8px; }
  .panel { left: var(--ribbon); right: 0; top: auto; bottom: 0; width: auto; max-height: 56vh; border-radius: 16px 16px 0 0; padding-bottom: max(24px, env(safe-area-inset-bottom)); }
  .panel:not([hidden]) ~ .zoom { display: none; }
  body.view-map .panel { left: 0; }
  #mapPanel:not([hidden]) ~ .timebar { display: none; }
  .timebar { flex-wrap: wrap; row-gap: 6px; }
  .timebar .track { flex-basis: 100%; order: -2; }
  .timebar output { flex-basis: 100%; order: -1; width: auto; height: 56px; text-align: left; }
  /* Five age names do not fit in the first third of a phone-wide track; the label names the age. */
  .timebar .ticks span.age:not(:first-child) { display: none; }
  body.view-map .zoom { bottom: 184px; }
  .views .btn { padding: 0 10px; }
}
@media (prefers-reduced-motion: reduce) {
  .ribbon .here { transition: none; }
}
