/* A deliberately dark "night sky" map: single theme by design. */
:root {
  color-scheme: dark;
  --bg: #0b0e16;
  --panel: rgba(15, 19, 30, 0.93);
  --panel-solid: #0f131e;
  --line: #262d42;
  --text: #ece6d6;
  --muted: #a1a7b8;
  --accent: #f2c46d;
  --accent-ink: #1a1405;
  --radius: 10px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 var(--sans);
  display: flex; flex-direction: column; overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* header */
#top {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--line); background: var(--panel-solid); z-index: 20;
}
.brand h1 { margin: 0; font: 600 20px/1.1 var(--serif); letter-spacing: 0.01em; text-wrap: balance; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; }
.search { position: relative; flex: 1 1 260px; max-width: 460px; }
.search input {
  width: 100%; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: #151a28; color: var(--text);
}
#results {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; margin: 0; padding: 4px; list-style: none;
  background: var(--panel-solid); border: 1px solid var(--line); border-radius: 8px; max-height: 60vh; overflow: auto; z-index: 30;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}
#results li { padding: 7px 10px; border-radius: 6px; cursor: pointer; display: flex; gap: 8px; align-items: baseline; }
#results li[aria-selected="true"], #results li:hover { background: #1d2437; }
#results .sw { flex: none; width: 9px; height: 9px; border-radius: 50%; transform: translateY(0); }
#results small { color: var(--muted); display: block; }
.tools { display: flex; gap: 8px; align-items: center; margin-left: auto; }
.tools button, .buttons button, #welcome button {
  padding: 7px 12px; border-radius: 8px; border: 1px solid var(--line); background: #151a28;
}
.tools button:hover, .buttons button:hover { border-color: #3a4566; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: transparent; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.only-narrow { display: none; }

/* stage */
#stage { position: relative; flex: 1; min-height: 0; }
#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline-offset: -3px; touch-action: none; }
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.lbl { position: absolute; transform: translate(-50%, -50%); white-space: nowrap; pointer-events: none; }
.lbl.topic {
  font: 600 12px/1 var(--sans); letter-spacing: 0.05em; text-transform: uppercase; color: var(--text);
  background: rgba(11, 14, 22, 0.82); border: 1px solid rgba(255, 255, 255, 0.16); border-radius: 999px; padding: 5px 10px 5px 8px;
  display: inline-flex; align-items: center; gap: 6px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}
.lbl.topic::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--c); flex: none; }
.lbl.book { font: 12px/1.2 var(--sans); color: var(--text); transform: translate(8px, -50%); background: rgba(11, 14, 22, 0.82); padding: 2px 6px; border-radius: 4px; }
.lbl.book.sel {
  transform: translate(-50%, 14px); white-space: normal; width: max-content; max-width: 230px; text-align: center; z-index: 3;
  background: rgba(8, 10, 16, 0.95); border: 1px solid var(--accent); border-radius: 8px; padding: 6px 10px; box-shadow: 0 4px 18px rgba(0, 0, 0, 0.6);
}
.lbl.book.sel b { display: block; font: 600 14px/1.25 var(--serif); color: #fff; }
.lbl.book.sel small { display: block; margin-top: 2px; color: var(--accent); font-size: 12px; }
#tip {
  position: absolute; z-index: 15; pointer-events: none; max-width: 280px; padding: 6px 10px; border-radius: 8px;
  background: var(--panel-solid); border: 1px solid var(--line); font-size: 12.5px; box-shadow: 0 8px 20px rgba(0,0,0,.5);
}
#tip b { display: block; font-family: var(--serif); font-size: 14px; }
#tip span { color: var(--muted); }

/* panels */
.panel {
  position: absolute; z-index: 10; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  backdrop-filter: blur(6px); overflow: auto; padding: 14px;
}
#filters { top: 12px; left: 12px; bottom: 12px; width: 290px; }
#detail { top: 12px; right: 12px; bottom: 12px; width: 350px; }
.panel h2 { margin: 18px 0 6px; font: 600 12px var(--sans); letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.panel section:first-of-type h2 { margin-top: 10px; }
.panel label { display: block; margin: 10px 0 4px; font-size: 12.5px; color: var(--muted); }
.panel label.check { display: flex; gap: 8px; align-items: center; color: var(--text); margin-top: 12px; }
.panel input[type="number"], .panel select {
  width: 100%; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--line); background: #151a28;
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.hint { margin: 0 0 8px; color: var(--muted); font-size: 12.5px; }
.count { font-size: 13px; color: var(--muted); }
.count strong { color: var(--text); font-size: 18px; font-variant-numeric: tabular-nums; }
.link { background: none; border: 0; padding: 0; margin-top: 12px; color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.buttons { display: flex; gap: 8px; margin-top: 16px; }

#legend .fam { margin-bottom: 8px; }
#legend .famhead { display: flex; align-items: center; gap: 8px; width: 100%; padding: 4px 2px; background: none; border: 0; text-align: left; font-weight: 600; }
#legend .famhead i, #legend .t i { width: 10px; height: 10px; border-radius: 50%; flex: none; }
#legend .t { display: flex; align-items: center; gap: 8px; width: 100%; padding: 3px 2px 3px 18px; background: none; border: 0; text-align: left; border-radius: 6px; color: var(--text); }
#legend .t span.n { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; }
#legend .t[aria-pressed="true"] { background: #1d2437; box-shadow: inset 0 0 0 1px #3a4566; }
#legend .t:hover, #legend .famhead:hover { background: #181e2f; }
.etoggle { display: flex; align-items: center; gap: 8px; margin: 6px 0; color: var(--text) !important; }
.etoggle i { width: 22px; height: 3px; border-radius: 2px; flex: none; }

/* detail */
#detail h3 { margin: 0 0 2px; font: 600 20px/1.2 var(--serif); text-wrap: balance; }
#detail .by { color: var(--muted); margin: 0 0 10px; }
#detail .chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip { padding: 2px 9px; border-radius: 999px; border: 1px solid var(--line); font-size: 12px; background: #151a28; display: inline-flex; gap: 6px; align-items: center; }
.chip i { width: 8px; height: 8px; border-radius: 50%; }
#detail dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 10px 0; font-size: 13px; }
#detail dt { color: var(--muted); }
#detail dd { margin: 0; overflow-wrap: anywhere; }
#detail a { color: var(--accent); }
#detail .close { position: absolute; top: 8px; right: 8px; border: 0; background: none; font-size: 20px; color: var(--muted); width: 32px; height: 32px; }
#detail h4 { margin: 18px 0 4px; font: 600 12px var(--sans); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); display: flex; align-items: center; gap: 8px; }
#detail h4 i { width: 14px; height: 3px; border-radius: 2px; }
.nb { display: block; width: 100%; text-align: left; padding: 5px 6px; border: 0; background: none; border-radius: 6px; color: var(--text); }
.nb:hover { background: #1b2234; }
.nb small { display: block; color: var(--muted); }
.more { color: var(--muted); background: none; border: 0; text-decoration: underline; padding: 4px 6px; }
.pathbox { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--line); }
.pathbox input { width: 100%; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--line); background: #151a28; }
.pathres ol { margin: 8px 0 0; padding-left: 20px; }
.pathres li { margin: 4px 0; }
.pathres em { color: var(--muted); font-style: normal; font-size: 12px; }
.rel { position: relative; }
.mini { position: absolute; left: 0; right: 0; z-index: 5; margin: 2px 0 0; padding: 4px; list-style: none; background: var(--panel-solid); border: 1px solid var(--line); border-radius: 8px; max-height: 220px; overflow: auto; }
.mini li { padding: 5px 8px; cursor: pointer; border-radius: 6px; }
.mini li:hover { background: #1d2437; }

/* list view */
#list { position: absolute; inset: 0; overflow: auto; background: var(--bg); padding: 12px 12px 24px 318px; padding-right: 12px; }
#detail:not([hidden]) ~ #list { padding-right: 376px; }
#list table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
#list th { position: sticky; top: 0; background: var(--panel-solid); text-align: left; padding: 8px; border-bottom: 1px solid var(--line); cursor: pointer; white-space: nowrap; }
#list th[aria-sort] { color: var(--accent); }
#list td { padding: 6px 8px; border-bottom: 1px solid #171c2b; vertical-align: top; }
#list tr.row { cursor: pointer; }
#list tr.row:hover td, #list tr.sel td { background: #161c2c; }
#list td .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }
#list .empty { padding: 30px; color: var(--muted); }
#filters, #detail { z-index: 12; }

/* cards, dialog */
.card {
  position: absolute; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 14; max-width: min(520px, calc(100% - 32px));
  background: var(--panel-solid); border: 1px solid #3a4566; border-radius: var(--radius); padding: 14px 16px;
  display: flex; gap: 14px; align-items: center; box-shadow: 0 12px 32px rgba(0,0,0,.5);
}
.card p { margin: 0; }
.card button { background: var(--accent) !important; color: var(--accent-ink); border: 0 !important; font-weight: 600; white-space: nowrap; }
dialog { max-width: min(560px, calc(100% - 32px)); max-height: calc(100% - 32px); overflow: auto; background: var(--panel-solid); color: var(--text); border: 1px solid #3a4566; border-radius: 12px; padding: 22px 24px; }
dialog::backdrop { background: rgba(5, 7, 12, 0.7); }
dialog h2 { margin: 0 0 8px; font: 600 22px var(--serif); }
dialog h3 { margin: 18px 0 6px; font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
dialog ul { padding-left: 18px; } dialog li { margin: 6px 0; }
dialog .note { padding: 10px 12px; border-left: 3px solid var(--accent); background: #151a28; font-family: var(--serif); font-size: 16px; }
dialog .note p { margin: 0 0 10px; }
dialog .note p:last-child { margin: 0; }
dialog .fine { color: var(--muted); font-size: 12.5px; }
dialog button { margin-top: 10px; padding: 7px 16px; border-radius: 8px; border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 600; }

/* narrow screens: filters become a drawer, detail becomes a bottom sheet */
@media (max-width: 860px) {
  .only-narrow { display: inline-block; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  #filters { top: 0; bottom: 0; left: 0; width: min(320px, 88%); border-radius: 0 var(--radius) var(--radius) 0; transform: translateX(-102%); transition: transform .2s; }
  #filters.open { transform: none; }
  #detail { top: auto; left: 8px; right: 8px; bottom: 8px; width: auto; max-height: 52%; }
  #list, #detail:not([hidden]) ~ #list { padding: 8px 8px 60%; }
  #list td:nth-child(n+4), #list th:nth-child(n+4) { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
