:root {
  --bg: #06070f;
  --fg: #eceefb;
  --dim: #9ba0bd;
  --faint: #60658a;
  --line: #252a48;
  --line-soft: #1a1e36;
  --card: #0c0e1e;
  --chip: rgba(255, 255, 255, 0.04);
  --hot: #ffc48a;
  --accent: #b3a5ff;
  --panel-w: 400px;
  --sans: 'Sora', ui-sans-serif, system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-weight: 300;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

body { display: flex; }

#stage {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  overflow: hidden;
}

#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}
#scene.grabbing { cursor: grabbing; }

/* ---------------------------------------------------------------- masthead */
#masthead {
  position: absolute;
  left: 34px;
  top: 30px;
  width: min(360px, 42vw);
  pointer-events: none;
  z-index: 3;
}
#masthead .eyebrow {
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--faint);
}
#masthead h1 {
  margin: 8px 0 0;
  font-size: 34px;
  font-weight: 200;
  line-height: 1.05;
  letter-spacing: 0.01em;
}
#masthead .lede {
  margin: 10px 0 0;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--dim);
}
#masthead a.about {
  pointer-events: auto;
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid rgba(179, 165, 255, 0.35);
  white-space: nowrap;
}
#masthead a.about:hover { border-bottom-color: var(--accent); }

#crumb {
  margin-top: 18px;
  font-size: 10.5px;
  letter-spacing: 0.05em;
  color: var(--faint);
  line-height: 1.6;
}
#crumb button {
  pointer-events: auto;
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--faint);
  cursor: pointer;
}
#crumb button:hover { color: var(--dim); }
#crumb .sep { opacity: 0.5; margin: 0 7px; }
#crumb .here { color: var(--dim); }

/* ------------------------------------------------------------------- chips */
#chips::before {
  content: '';
  position: absolute;
  left: -16px; right: -16px; top: -14px; bottom: -66px;
  background: radial-gradient(120% 100% at 0% 100%, rgba(6,7,15,.92) 40%, rgba(6,7,15,0) 100%);
  pointer-events: none;
  z-index: -1;
}
#chips {
  position: absolute;
  left: 34px;
  bottom: 104px;
  width: min(390px, 46vw);
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  z-index: 3;
  pointer-events: none;
}
#chips button {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--chip);
  color: var(--dim);
  font: inherit;
  font-size: 10.5px;
  cursor: pointer;
  transition: color .12s, border-color .12s, background .12s;
}
#chips button:hover { color: var(--fg); }
#chips button .dot {
  width: 7px; height: 7px; border-radius: 50%;
  flex-shrink: 0;
}
#chips button .ct { color: var(--faint); font-variant-numeric: tabular-nums; }
#chips button[aria-pressed="true"] { color: var(--fg); }

/* ---------------------------------------------------------------- controls */
#controls {
  position: absolute;
  left: 34px;
  bottom: 54px;
  display: flex;
  align-items: center;
  gap: 18px;
  font-size: 10.5px;
  color: var(--faint);
  z-index: 3;
  flex-wrap: wrap;
}
#controls label { display: inline-flex; align-items: center; gap: 7px; letter-spacing: 0.04em; }
#controls select {
  background: var(--card);
  color: var(--dim);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 3px 6px;
  font: inherit;
  font-size: 10.5px;
  cursor: pointer;
}
#controls input[type="range"] {
  width: 74px;
  accent-color: var(--accent);
  cursor: pointer;
}
#controls .tog { cursor: pointer; }
#controls input[type="checkbox"] { accent-color: var(--accent); cursor: pointer; }

#readout {
  position: absolute;
  left: 34px;
  bottom: 28px;
  font-size: 9.5px;
  letter-spacing: 0.1em;
  color: var(--faint);
  z-index: 3;
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------------- panel */
#panel {
  flex: 0 0 var(--panel-w);
  width: var(--panel-w);
  height: 100%;
  border-left: 1px solid var(--line-soft);
  background: var(--card);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: flex-basis .22s ease, width .22s ease;
}
#panel.wide { flex-basis: min(760px, 62vw); width: min(760px, 62vw); }
#panelInner { display: flex; flex-direction: column; height: 100%; min-height: 0; }

.pad { padding: 22px 24px; }
.sec-h {
  font-size: 9.5px;
  letter-spacing: 0.17em;
  text-transform: uppercase;
  color: var(--faint);
}

/* index view */
.index-intro {
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--dim);
}
.index-intro strong { color: var(--fg); font-weight: 400; }
.stat-row { display: flex; gap: 22px; margin: 18px 0 4px; }
.stat b { display: block; font-size: 20px; font-weight: 300; font-variant-numeric: tabular-nums; }
.stat span {
  display: block; margin-top: 3px; font-size: 8.5px;
  letter-spacing: 0.1em; text-transform: uppercase; color: var(--faint);
}

.rank { display: flex; flex-direction: column; gap: 2px; margin-top: 12px; }
.rank button {
  position: relative;
  display: flex; align-items: center; gap: 9px;
  width: 100%; text-align: left;
  padding: 7px 9px;
  border: 0; border-radius: 4px;
  background: var(--chip);
  color: var(--fg);
  font: inherit; font-size: 11.5px;
  cursor: pointer;
  overflow: hidden;
}
.rank button:hover { background: rgba(255, 255, 255, 0.075); }
.rank .bar { position: absolute; left: 0; top: 0; bottom: 0; opacity: 0.14; }
.rank .n { position: relative; width: 15px; flex-shrink: 0; color: var(--faint); font-size: 10px; font-variant-numeric: tabular-nums; }
.rank .t { position: relative; flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank .v { position: relative; color: var(--faint); font-size: 10px; font-variant-numeric: tabular-nums; }

/* page view */
.page-head { padding: 20px 24px 16px; border-bottom: 1px solid var(--line-soft); flex-shrink: 0; }
.page-head .top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.page-head h2 { margin: 7px 0 0; font-size: 21px; font-weight: 300; line-height: 1.2; }
.page-head .desc { margin: 9px 0 0; font-size: 12px; line-height: 1.55; color: var(--dim); }
.tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 12px; }
.tags span {
  font-size: 9.5px; letter-spacing: 0.05em;
  padding: 3px 7px; border-radius: 3px;
  background: var(--chip); color: var(--faint);
}
.btn {
  flex-shrink: 0;
  border: 1px solid var(--line); border-radius: 5px;
  background: transparent; color: var(--dim);
  cursor: pointer; font: inherit; font-size: 11px;
  padding: 5px 9px; line-height: 1;
}
.btn:hover { color: var(--fg); border-color: var(--faint); }
.btn.icon { width: 27px; height: 27px; padding: 0; font-size: 15px; }
.head-actions { display: flex; gap: 6px; align-items: center; }

.body-scroll { overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.body-scroll::-webkit-scrollbar { width: 9px; }
.body-scroll::-webkit-scrollbar-thumb { background: #1f2440; border-radius: 5px; }

.doc { padding: 18px 24px 30px; font-size: 13px; line-height: 1.68; color: #c4c8e2; }
.doc h2 { font-size: 14px; font-weight: 500; color: var(--fg); margin: 24px 0 8px; letter-spacing: 0.01em; }
.doc h3 { font-size: 12.5px; font-weight: 500; color: var(--fg); margin: 20px 0 6px; }
.doc h4, .doc h5, .doc h6 { font-size: 11.5px; font-weight: 500; color: var(--dim); margin: 16px 0 5px; }
.doc p { margin: 0 0 12px; }
.doc ul, .doc ol { margin: 0 0 12px; padding-left: 20px; }
.doc li { margin-bottom: 5px; }
.doc strong { color: var(--fg); font-weight: 500; }
.doc code {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 11.5px; background: rgba(255, 255, 255, 0.055);
  padding: 1px 5px; border-radius: 3px; color: #d9d5ff;
}
.doc a { color: var(--accent); text-decoration: none; border-bottom: 1px solid rgba(179, 165, 255, 0.28); }
.doc a:hover { border-bottom-color: var(--accent); }
.doc a.wl { color: #a8e0ff; border-bottom-color: rgba(168, 224, 255, 0.3); }
.doc .wl.dead { color: var(--faint); border-bottom: 1px dotted var(--faint); }
.doc blockquote {
  margin: 0 0 12px; padding: 2px 0 2px 14px;
  border-left: 2px solid var(--line); color: var(--dim);
}
.doc hr { border: 0; border-top: 1px solid var(--line-soft); margin: 20px 0; }
.doc table { width: 100%; border-collapse: collapse; margin: 0 0 14px; font-size: 11.5px; }
.doc th, .doc td { text-align: left; padding: 6px 9px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.doc th { color: var(--faint); font-weight: 400; font-size: 9.5px; letter-spacing: 0.08em; text-transform: uppercase; }
.doc .img-ref { color: var(--faint); font-style: italic; }
.doc .callout {
  margin: 0 0 14px; padding: 12px 14px;
  border: 1px solid #4a3a2a; border-radius: 5px;
  background: rgba(255, 196, 138, 0.055);
}
.doc .callout-k {
  font-size: 9px; letter-spacing: 0.15em; text-transform: uppercase;
  color: var(--hot); margin-bottom: 6px;
}
.doc .callout p { margin: 0; }
.doc .callout.conflict { border-color: #4a3a2a; }

.conns { padding: 0 24px 26px; }
.conns .sec-h { margin-bottom: 9px; }

.foot-note { padding: 0 24px 26px; font-size: 10.5px; line-height: 1.6; color: var(--faint); }

/* ------------------------------------------------------------------- boot */
#boot {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg); color: var(--faint);
  font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase;
  z-index: 20; transition: opacity .35s;
}
#boot.gone { opacity: 0; pointer-events: none; }

/* ------------------------------------------------------------- responsive */
@media (max-width: 900px) {
  html, body { overflow: auto; }
  body { flex-direction: column; }
  #stage { height: 68vh; flex: 0 0 68vh; }
  #panel {
    flex: 1 1 auto; width: 100%;
    border-left: 0; border-top: 1px solid var(--line-soft);
    height: auto; min-height: 42vh;
  }
  #panel.wide { width: 100%; flex-basis: auto; }
  #masthead { width: min(320px, 62vw); left: 20px; top: 20px; }
  #masthead h1 { font-size: 25px; }
  #masthead .lede { display: none; }
  #chips { left: 20px; bottom: 76px; width: calc(100% - 40px); }
  #controls { left: 20px; bottom: 34px; gap: 12px; }
  #readout { display: none; }
  .body-scroll { overflow: visible; }
}

.doc ol.srcs { list-style: none; padding: 0; margin: 0; counter-reset: s; }
.doc ol.srcs li {
  counter-increment: s;
  position: relative;
  padding: 7px 0 7px 26px;
  border-bottom: 1px solid var(--line-soft);
  margin: 0;
}
.doc ol.srcs li:last-child { border-bottom: 0; }
.doc ol.srcs li::before {
  content: counter(s);
  position: absolute; left: 0; top: 8px;
  font-size: 10px; color: var(--faint); font-variant-numeric: tabular-nums;
}
.doc .st { display: block; font-size: 12px; color: #c4c8e2; line-height: 1.45; }
.doc .sm { display: block; margin-top: 3px; font-size: 10.5px; color: var(--faint); }

/* -------------------------------------------------------------- sign-in gate */
body.gated #stage, body.gated #panel { visibility: hidden; }

#gate {
  position: fixed; inset: 0; z-index: 30;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background:
    radial-gradient(60% 55% at 50% 42%, rgba(139, 123, 216, 0.16), rgba(6, 7, 15, 0) 70%),
    var(--bg);
}
#gate[hidden] { display: none; }

.gate-card {
  width: 100%; max-width: 348px;
  display: flex; flex-direction: column;
  text-align: center;
}
.gate-card .eyebrow {
  font-size: 10px; letter-spacing: 0.22em; text-transform: uppercase; color: var(--faint);
}
.gate-card h1 { margin: 10px 0 0; font-size: 38px; font-weight: 200; letter-spacing: 0.01em; }
.gate-card > p {
  margin: 12px 0 26px; font-size: 12.5px; line-height: 1.6; color: var(--dim);
}
#gbtn { display: flex; justify-content: center; min-height: 0; }
#gbtn[hidden] { display: none; }

.or {
  display: flex; align-items: center; gap: 12px;
  margin: 20px 0 18px; color: var(--faint); font-size: 10px;
  letter-spacing: 0.16em; text-transform: uppercase;
}
.or::before, .or::after {
  content: ''; flex: 1 1 auto; height: 1px; background: var(--line-soft);
}
.or[hidden] { display: none; }

.field { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.field[hidden] { display: none; }
.field span {
  font-size: 9.5px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--faint);
}
.field input {
  width: 100%; padding: 11px 13px;
  background: var(--card); color: var(--fg);
  border: 1px solid var(--line); border-radius: 7px;
  font: inherit; font-size: 13px;
}
.field input:focus { outline: none; border-color: var(--accent); }

.primary {
  margin-top: 12px; padding: 11px 16px;
  border: 1px solid var(--line); border-radius: 7px;
  background: rgba(179, 165, 255, 0.12); color: var(--fg);
  font: inherit; font-size: 12.5px; cursor: pointer;
  transition: background .12s, border-color .12s;
}
.primary:hover { background: rgba(179, 165, 255, 0.2); border-color: var(--accent); }

.err { margin: 14px 0 0; font-size: 11.5px; line-height: 1.5; color: #ffa9a9; min-height: 1em; }
.err.ok { color: var(--dim); }

#who {
  margin-top: 12px; font-size: 10px; color: var(--faint);
  letter-spacing: 0.04em; pointer-events: none;
}
#who button {
  pointer-events: auto;
  margin-left: 8px; padding: 0;
  background: none; border: 0; border-bottom: 1px solid var(--line);
  color: var(--faint); font: inherit; font-size: 10px; cursor: pointer;
}
#who button:hover { color: var(--dim); border-bottom-color: var(--faint); }

.reader {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 9px; border-radius: 4px; background: var(--chip);
  font-size: 11.5px;
}
.reader .t { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reader .v { color: var(--faint); font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; }
.reader .btn { padding: 3px 8px; font-size: 10px; }
.add-row { display: flex; gap: 6px; margin-top: 14px; }
.add-row input {
  flex: 1 1 auto; min-width: 0; padding: 8px 11px;
  background: transparent; color: var(--fg);
  border: 1px solid var(--line); border-radius: 5px;
  font: inherit; font-size: 11.5px;
}
.add-row input:focus { outline: none; border-color: var(--accent); }
#who a {
  margin-left: 10px; color: var(--faint); font-size: 10px;
  text-decoration: none; border-bottom: 1px solid var(--line);
  pointer-events: auto;
}
#who a:hover { color: var(--dim); border-bottom-color: var(--faint); }
