:root {
  --bg: #0b1020;
  --panel: #131a2e;
  --panel-2: #1a2340;
  --line: #26304f;
  --text: #e6e9f2;
  --muted: #8f9ab8;
  --accent: #7aa2ff;
  --gold: #f5c542;
  --good: #5fd39a;
  --warn: #f0b04a;
  --bad: #f06a6a;
  --radius: 12px;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  color-scheme: dark;
}
:root[data-theme="night"] {
  --bg: #0a0000;
  --panel: #160303;
  --panel-2: #210505;
  --line: #3a0b0b;
  --text: #ff6b5e;
  --muted: #a8392f;
  --accent: #ff5040;
  --gold: #ff5040;
  --good: #d8443a;
  --warn: #d8443a;
  --bad: #ff6b5e;
}
:root[data-theme="night"] img,
:root[data-theme="night"] .skyview .aladin-el { filter: grayscale(1) sepia(1) hue-rotate(-50deg) saturate(4) brightness(.55); }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 Inter, system-ui, sans-serif;
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, select, input { font: inherit; color: inherit; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; gap: 12px; align-items: center;
  padding: 12px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--text); white-space: nowrap; letter-spacing: .02em; }
.navlink { color: var(--muted); white-space: nowrap; font-size: 14px; padding: 6px 10px; border-radius: 8px; border: 1px solid transparent; }
.navlink:hover { color: var(--text); text-decoration: none; background: var(--panel); }
.navlink[aria-current="page"] { color: var(--accent); border-color: var(--accent); }
#search {
  flex: 1; min-width: 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 12px;
}
#sort, .ghost {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
  cursor: pointer;
}
.ghost[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }

.chips { display: flex; gap: 8px; padding: 10px 16px; overflow-x: auto; border-bottom: 1px solid var(--line); }
.chip {
  border: 1px solid var(--line); background: var(--panel); border-radius: 999px;
  padding: 4px 12px; cursor: pointer; white-space: nowrap; font-size: 13px;
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.chip .n { opacity: .7; margin-left: 4px; }

.layout { display: grid; grid-template-columns: 340px 1fr; min-height: calc(100vh - 110px); }
.list { border-right: 1px solid var(--line); overflow-y: auto; max-height: calc(100vh - 110px); position: sticky; top: 110px; }
.group-title {
  position: sticky; top: 0; background: var(--bg); z-index: 1;
  font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
  padding: 10px 16px 6px; border-bottom: 1px solid var(--line);
}
.item {
  display: grid; grid-template-columns: 44px 1fr auto; gap: 10px; align-items: center;
  padding: 8px 16px; cursor: pointer; border-bottom: 1px solid color-mix(in srgb, var(--line) 50%, transparent);
  color: var(--text);
}
.item:hover { background: var(--panel); text-decoration: none; }
.item[aria-current="true"] { background: var(--panel-2); box-shadow: inset 3px 0 0 var(--accent); }
.item img, .item .noimg { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: var(--panel-2); }
.item .t { font-weight: 600; line-height: 1.2; }
.item .s { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .r { font-size: 12px; color: var(--muted); text-align: right; white-space: nowrap; }

.detail { padding: 24px; max-width: 1100px; min-width: 0; }
.list { min-width: 0; }
.empty { color: var(--muted); padding: 40px; text-align: center; }

.hero { display: grid; grid-template-columns: 1fr auto; gap: 24px; align-items: start; }
.hero h1 { margin: 0; font-size: 32px; line-height: 1.1; }
.hero .desc { color: var(--muted); margin-top: 6px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); }
.tag.mono { font-family: var(--mono); }
.images { display: flex; gap: 12px; }
.images figure { margin: 0; width: 220px; }
.images .photo img { background: #e9ecf3; }
.images img { width: 220px; height: 220px; object-fit: cover; border-radius: var(--radius); border: 1px solid var(--line); display: block; background: #000; cursor: zoom-in; }
.images figcaption { font-size: 11px; color: var(--muted); margin-top: 4px; }

h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 32px 0 12px; font-weight: 600; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.fact { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.fact .k { font-size: 12px; color: var(--muted); }
.fact .v { font-size: 20px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.fact .u { font-size: 13px; color: var(--muted); font-weight: 400; margin-left: 3px; }
td .u { color: var(--muted); margin-left: 3px; }
.fact .x { font-size: 12px; color: var(--muted); margin-top: 2px; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; box-shadow: 0 0 8px currentColor; }

table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.tablewrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.stars { color: var(--gold); letter-spacing: 1px; white-space: nowrap; }
.stars .off { color: var(--line); }
.pill { font-size: 12px; padding: 1px 6px; border-radius: 5px; background: var(--panel-2); }
.pill.good { color: var(--good); } .pill.warn { color: var(--warn); } .pill.bad { color: var(--bad); }
.muted { color: var(--muted); }
.note { font-size: 12px; color: var(--muted); margin-top: 6px; }

.prose { max-width: 75ch; }
.prose p { margin: 0 0 12px; }
pre {
  font-family: var(--mono); font-size: 12.5px; line-height: 1.5;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; overflow-x: auto; white-space: pre;
}
details { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin-top: 10px; }
details > summary { cursor: pointer; padding: 10px 14px; font-weight: 500; }
details > div { padding: 0 14px 14px; }
details table td, details table th { padding: 6px 8px; }
.ids { display: flex; flex-wrap: wrap; gap: 6px; }
.links { display: flex; flex-wrap: wrap; gap: 8px; }
.links a { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; font-size: 14px; }
.sources li { color: var(--muted); font-size: 13px; }

.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: grid; place-items: center; z-index: 20; cursor: zoom-out; }
.lightbox img { max-width: 92vw; max-height: 88vh; border-radius: var(--radius); }

.back { display: none; margin-bottom: 12px; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .list { position: static; max-height: none; border-right: 0; }
  .layout.showing .list { display: none; }
  .layout:not(.showing) .detail { display: none; }
  .back { display: inline-block; }
  .detail { padding: 16px; }
  .hero { grid-template-columns: 1fr; }
  .images figure, .images img { width: calc(50vw - 22px); height: auto; aspect-ratio: 1; }
  .topbar { flex-wrap: wrap; }
  #search { flex-basis: 100%; order: 3; }
  .brand { display: inline; }
  #objects-link { margin-right: auto; }
}

/* ---------- object page sections ---------- */
.sec { scroll-margin-top: 70px; min-width: 0; }
h2 .sec-src { font-size: 12px; text-transform: none; letter-spacing: 0; font-weight: 400; margin-left: 8px; }
h3 { font-size: 15px; font-weight: 600; margin: 22px 0 8px; }
.sec > h3:first-of-type, .two-col h3 { margin-top: 0; }
.pagenav { display: flex; gap: 6px; margin-top: 18px; overflow-x: auto; padding-bottom: 2px; }
.pagenav button, .more-btn {
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  padding: 3px 11px; font-size: 13px; cursor: pointer; white-space: nowrap; color: var(--muted);
}
.pagenav button:hover, .more-btn:hover { color: var(--text); border-color: var(--accent); }
.more-btn { margin-top: 8px; color: var(--accent); }
.linklike { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-align: left; }
.linklike:hover { text-decoration: underline; }
.clip:not(.open) .extra { display: none; }
.mono { font-family: var(--mono); font-size: .92em; }

.fact-link { display: block; width: 100%; text-align: left; cursor: pointer; font: inherit; color: inherit; }
.fact-link:hover, .fact-link:focus-visible { border-color: var(--accent); }
.fact-link .go { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.kv th { width: 34%; text-transform: none; letter-spacing: 0; font-size: 13px; color: var(--muted); font-weight: 500; }
.kv td { overflow-wrap: anywhere; }
.kv tr:last-child th, .kv tr:last-child td, .tablewrap tr:last-child td { border-bottom: 0; }
.tablewrap table { font-size: 13.5px; }
.clip .tablewrap td { white-space: nowrap; }
.kv td, .wd td { white-space: normal; }
.wdv { display: block; }
.wdv + .wdv { margin-top: 2px; }
.tfilter {
  width: 100%; max-width: 320px; margin-bottom: 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px;
}
.mtable { margin-top: 14px; }
.mtitle { font-weight: 500; margin-bottom: 6px; }
.notes p { margin: 0 0 8px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }

/* sky viewer */
.skyview {
  position: relative; height: 420px; border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--line); background: #000;
}
.skyview .aladin-el { position: absolute; inset: 0; }
.sky-msg { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); padding: 20px; text-align: center; background: var(--panel); }

/* Wikipedia article */
.article-grid { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 20px; align-items: start; }
.article-main { min-width: 0; }
.article-main details:first-child { margin-top: 0; }
.wp-sec { scroll-margin-top: 70px; }
.wp-sec > summary { font-weight: 600; }
.wp-sec .prose { max-width: 75ch; }
.wp-h { font-size: 14px; margin: 16px 0 6px; color: var(--text); }
.toc { position: sticky; top: 70px; max-height: calc(100vh - 90px); overflow-y: auto; font-size: 13px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.toc-t { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 4px; }
.toc ol { margin: 0; padding-left: 18px; }
.toc li { margin: 3px 0; }
.strip { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 14px; }
.strip figure { margin: 0; flex: 0 0 150px; }
.strip img { width: 150px; height: 110px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); background: #e9ecf3; display: block; cursor: zoom-in; }
.strip figcaption { font-size: 11px; color: var(--muted); margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* sources */
.srcrow { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 14px; }

/* research papers modal */
body.modal-open { overflow: hidden; }
.modal-backdrop {
  position: fixed; inset: 0; z-index: 30; padding: 4vh 16px;
  background: color-mix(in srgb, #000 70%, transparent); display: flex; justify-content: center; align-items: flex-start;
}
.modal {
  width: min(860px, 100%); max-height: 92vh; display: flex; flex-direction: column;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.modal-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px 8px; }
.modal-head h3 { margin: 0; flex: 1; min-width: 0; }
.modal-close { padding: 4px 10px; }
.modal-tools { display: flex; gap: 8px; padding: 0 16px 6px; }
.modal-search { flex: 1; min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 11px; }
.modal-sort { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 8px; }
.modal-count { font-size: 12px; padding: 0 16px 8px; border-bottom: 1px solid var(--line); }
.modal-body { overflow-y: auto; padding: 4px 16px 16px; flex: 1; min-height: 0; }
.papers { list-style: none; margin: 0; padding: 0; }
.paper { padding: 10px 0; border-bottom: 1px solid var(--line); }
.paper .pt { font-weight: 600; line-height: 1.35; }
.paper .pa { font-size: 13px; color: var(--muted); margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.paper .pm { font-size: 13px; margin-top: 3px; display: flex; flex-wrap: wrap; gap: 4px 12px; }
.paper .py { color: var(--gold); font-variant-numeric: tabular-nums; }
.paper .pl { display: flex; gap: 12px; font-size: 13px; margin-top: 3px; }

@media (max-width: 860px) {
  .two-col { grid-template-columns: 1fr; }
  .article-grid { grid-template-columns: 1fr; }
  .toc { position: static; max-height: none; }
  .skyview { height: 300px; }
  .kv th { width: auto; white-space: normal; }
  .modal-backdrop { padding: 0; }
  .modal { max-height: 100vh; height: 100%; border-radius: 0; border: 0; }
}

/* overview route (charts.js draws into #detail) */
body.is-overview .list, body.is-overview .chips { display: none; }
body.is-overview .layout { grid-template-columns: 1fr; }
body.is-overview .detail { max-width: none; display: block; }
body.is-overview .back { display: none; }

/* ---------- glossary tooltips (app.js: data-term / data-value-kind) ---------- */
.gl {
  text-decoration-line: underline; text-decoration-style: dotted; text-decoration-thickness: 1px;
  text-decoration-color: color-mix(in srgb, var(--muted) 85%, transparent); text-underline-offset: 3px;
  cursor: help;
}
.gl:hover, .gl:focus-visible { text-decoration-color: var(--accent); }
.gl:focus:not(:focus-visible) { outline: none; }
a .gl, button .gl { cursor: inherit; }
svg text.gl { text-decoration: underline dotted; }
svg text.gl:hover, svg text.gl:focus { fill: var(--text); }
svg text.gl:focus { outline: none; }
.gtip {
  position: fixed; left: 0; top: 0; z-index: 40; pointer-events: none;
  max-width: 360px; padding: 9px 12px;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45); font-size: 13px; line-height: 1.45; text-align: left;
  text-transform: none; letter-spacing: 0; font-weight: 400;
}
.gtip[hidden] { display: none; }
.gtip-t { font-weight: 600; color: var(--text); }
.gtip-v { margin-top: 4px; padding: 5px 8px; border-radius: 6px; background: color-mix(in srgb, var(--accent) 12%, transparent); }
.gtip-vv { font-family: var(--mono); font-size: .92em; color: var(--accent); margin-right: 2px; }
.gtip-s { margin-top: 4px; }
.gtip-l { margin-top: 4px; color: var(--muted); font-size: 12.5px; }

/* friendlier labels with the source's raw field name underneath */
.hz-orig { display: block; font-family: var(--mono); font-size: 11px; color: var(--muted); opacity: .75; text-transform: none; letter-spacing: 0; font-weight: 400; margin-top: 1px; }
.kv.hz th, .kv.ct th { width: 46%; }
.hz-pam { margin-top: 10px; }
.hz-pam th[scope="row"] { text-transform: none; letter-spacing: 0; font-size: 13px; font-weight: 500; }
table.eph th { text-transform: none; letter-spacing: 0; font-size: 12.5px; white-space: nowrap; }
details.raw { margin-top: 10px; }
details.raw > summary { font-size: 13px; color: var(--muted); }

/* glossary list modal */
#glossary-btn { min-width: 36px; font-weight: 600; }
.gloss { margin: 0; }
.gloss-item { padding: 10px 0; border-bottom: 1px solid var(--line); }
.gloss-item dt { font-weight: 600; }
.gloss-item dd { margin: 2px 0 0; }
.gloss-item .gloss-long { color: var(--muted); font-size: 13.5px; }
.hz-pam td { white-space: nowrap; }
