/* ---------- tokens ---------- */
:root {
  --bg: #0b0d12;
  --surface: #12151c;
  --surface-2: #181c25;
  --line: #232836;
  --ink: #e8ebf1;
  --muted: #8b94a7;
  --scrim: 11, 13, 18;
  --shadow: 0 1px 0 rgba(255,255,255,.03) inset, 0 10px 30px rgba(0,0,0,.35);
  --radius: 14px;
  --text: "Inter", system-ui, sans-serif;
  --ui: "Space Grotesk", "Inter", sans-serif;

  /* set per faction by codex.js */
  --accent: #7c9cff;
  --accent-2: #b18cff;
  --display: var(--ui);
  --display-tracking: -.01em;
  --display-case: none;
  --accent-ink: var(--accent);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f5f6f8; --surface: #ffffff; --surface-2: #f0f2f5; --line: #e2e5eb;
    --ink: #11141b; --muted: #5c6577; --scrim: 245, 246, 248;
    --shadow: 0 1px 2px rgba(16,20,30,.06), 0 8px 24px rgba(16,20,30,.06);
    --accent-ink: color-mix(in srgb, var(--accent) 62%, #000);
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #f5f6f8; --surface: #ffffff; --surface-2: #f0f2f5; --line: #e2e5eb;
  --ink: #11141b; --muted: #5c6577; --scrim: 245, 246, 248;
  --shadow: 0 1px 2px rgba(16,20,30,.06), 0 8px 24px rgba(16,20,30,.06);
  --accent-ink: color-mix(in srgb, var(--accent) 62%, #000);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { scroll-padding-top: 80px; -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.65 var(--text); -webkit-font-smoothing: antialiased; }
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
button { font: inherit; color: inherit; }
::selection { background: color-mix(in srgb, var(--accent) 35%, transparent); }

/* ---------- top bar ---------- */
.top {
  position: sticky; top: 0; z-index: 20; height: 60px;
  display: flex; align-items: center; gap: 14px; padding: 0 20px;
  background: rgba(var(--scrim), .78); backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { font: 700 15px/1 var(--ui); letter-spacing: .14em; text-transform: uppercase; color: var(--ink); white-space: nowrap; }
.brand::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 10px; vertical-align: 2px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); transition: background .4s; }
.brand:hover { text-decoration: none; }
.back { font-size: 14px; color: var(--muted); white-space: nowrap; }
.back:hover { color: var(--ink); text-decoration: none; }
.icon-btn { display: grid; place-items: center; width: 36px; height: 36px; flex: none; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); cursor: pointer; color: var(--muted); }
.icon-btn:hover { color: var(--ink); }
.tree-btn { display: none; }
#themeBtn { margin-left: auto; }

.search { position: relative; flex: 1; max-width: 440px; }
.search input {
  width: 100%; height: 38px; padding: 0 40px 0 36px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--ink); font: 14px var(--text);
}
.search input::-webkit-search-cancel-button { display: none; }
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.search-ico { position: absolute; left: 12px; top: 11px; color: var(--muted); }
.search kbd { position: absolute; right: 10px; top: 9px; font: 12px var(--ui); color: var(--muted); border: 1px solid var(--line); border-radius: 5px; padding: 0 6px; }
.results {
  position: absolute; top: calc(100% + 8px); left: 0; right: 0; margin: 0; padding: 6px; list-style: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); max-height: 65vh; overflow: auto;
}
.results a { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 8px; color: var(--ink); }
.results a:hover, .results a.active { background: var(--surface-2); text-decoration: none; }
.results .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--a); }
.results small { display: block; color: var(--muted); font-size: 12px; line-height: 1.3; }
.results .none { padding: 10px; color: var(--muted); font-size: 14px; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 264px minmax(0, 1fr); }
.tree {
  position: sticky; top: 60px; align-self: start; height: calc(100vh - 60px); overflow: auto;
  padding: 20px 12px 48px; border-right: 1px solid var(--line); font-size: 14px;
}
.tree ul { list-style: none; margin: 0; padding-left: 12px; }
.tree > ul { padding-left: 0; }
.tree li { margin: 1px 0; }
.tree .row { display: flex; align-items: center; }
.tree .tog { width: 22px; height: 22px; flex: none; border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0; display: grid; place-items: center; }
.tree .tog svg { transition: transform .15s; }
.tree .tog[aria-expanded="true"] svg { transform: rotate(90deg); }
.tree .spacer { width: 22px; flex: none; }
.tree a { display: flex; align-items: center; gap: 8px; padding: 4px 8px; border-radius: 7px; color: var(--muted); flex: 1; min-width: 0; }
.tree a span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree a img { width: 16px; height: 16px; object-fit: contain; flex: none; }
.tree a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.tree a.current { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--ink); font-weight: 600; box-shadow: inset 2px 0 0 var(--accent); }
.scrim { display: none; }

.view { padding: 24px 40px 96px; max-width: 1180px; width: 100%; }

/* ---------- breadcrumbs ---------- */
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; font: 500 13px var(--ui); color: var(--muted); margin-bottom: 16px; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--ink); }
.crumbs .sep { opacity: .45; }
.crumbs [aria-current] { color: var(--ink); }

/* ---------- hero ---------- */
.hero {
  position: relative; overflow: hidden; border-radius: 20px; border: 1px solid var(--line);
  background:
    radial-gradient(120% 140% at 0% 0%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 55%),
    radial-gradient(120% 140% at 100% 100%, color-mix(in srgb, var(--accent-2) 16%, transparent), transparent 55%),
    var(--surface);
  min-height: 220px; display: flex; align-items: flex-end;
}
.hero.has-image { min-height: clamp(300px, 44vw, 500px); background: var(--surface); }
.hero-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: center 30%; cursor: zoom-in; }
.hero.has-image::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(to top, rgba(var(--scrim), .96) 0%, rgba(var(--scrim), .7) 32%, rgba(var(--scrim), 0) 62%);
}
.hero .watermark { position: absolute; right: -40px; top: 50%; translate: 0 -50%; width: 340px; opacity: .08; pointer-events: none; }
.hero-body { position: relative; z-index: 1; display: flex; align-items: flex-end; gap: 22px; padding: 28px 32px; width: 100%; pointer-events: none; }
.hero-body a { pointer-events: auto; }
.hero-mark { width: 104px; height: 104px; object-fit: contain; flex: none; filter: drop-shadow(0 6px 18px rgba(0,0,0,.45)); }
.kind { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font: 600 12px/1 var(--ui); letter-spacing: .14em; text-transform: uppercase; color: var(--accent-ink); }
.part-of { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 4px; border-radius: 999px; background: rgba(var(--scrim), .6); border: 1px solid var(--line); color: var(--ink); letter-spacing: .04em; text-transform: none; font-weight: 500; }
.part-of img { width: 18px; height: 18px; object-fit: contain; }
.part-of:hover { text-decoration: none; border-color: var(--accent); }
.status { padding: 3px 8px; border-radius: 999px; border: 1px dashed currentColor; color: var(--muted); letter-spacing: .08em; }
h1 {
  font: 700 clamp(32px, 5.4vw, 58px)/1.02 var(--display); letter-spacing: var(--display-tracking); text-transform: var(--display-case);
  margin: 12px 0 8px; text-wrap: balance;
}
.tagline { margin: 0; color: var(--muted); font-size: 18px; }
.hero.has-image .tagline { color: color-mix(in srgb, var(--ink) 80%, transparent); }

/* ---------- body ---------- */
.content { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 40px; align-items: start; margin-top: 36px; }
.content.solo { grid-template-columns: minmax(0, 72ch); }
.body { font-size: 17px; max-width: 72ch; }
.body p { margin: 0 0 1.1em; }
.body ul, .body ol { margin: 0 0 1.2em; padding-left: 1.2em; }
.body li { margin: .35em 0; padding-left: .2em; }
.body li::marker { color: var(--accent-ink); }
.body ol li::marker { font: 600 .9em var(--ui); }
.body strong { font-weight: 600; color: var(--ink); }
.body .lead { font-size: 19px; color: color-mix(in srgb, var(--ink) 92%, var(--muted)); }
.missing { border-bottom: 1px dashed var(--muted); color: var(--muted); cursor: help; }
.empty { color: var(--muted); }

.facts { position: sticky; top: 84px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.facts h2 { font: 600 11px/1 var(--ui); letter-spacing: .16em; text-transform: uppercase; color: var(--muted); margin: 0 0 14px; }
.facts dl { margin: 0; }
.facts div { padding: 10px 0; border-top: 1px solid var(--line); }
.facts div:first-child { border-top: 0; padding-top: 0; }
.facts dt { font: 500 12px var(--ui); color: var(--muted); margin-bottom: 2px; }
.facts dd { margin: 0; font-size: 15px; font-weight: 500; line-height: 1.45; }

/* ---------- sections & cards ---------- */
section.group { margin-top: 56px; }
section.group > h2 {
  display: flex; align-items: center; gap: 10px; margin: 0 0 18px;
  font: 600 13px/1 var(--ui); letter-spacing: .16em; text-transform: uppercase; color: var(--muted);
}
section.group > h2::after { content: ""; flex: 1; height: 1px; background: var(--line); }
section.group > h2 small { font: inherit; color: var(--accent-ink); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.card {
  --a: var(--accent); --a2: var(--accent-2);
  position: relative; display: flex; flex-direction: column; overflow: hidden;
  border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); color: var(--ink); box-shadow: var(--shadow);
  transition: transform .18s ease, border-color .18s ease;
}
.card:hover { text-decoration: none; transform: translateY(-3px); border-color: var(--a); }
.card .thumb {
  position: relative; aspect-ratio: 16 / 9; overflow: hidden;
  background:
    radial-gradient(100% 120% at 0% 0%, color-mix(in srgb, var(--a) 40%, transparent), transparent 60%),
    radial-gradient(100% 120% at 100% 100%, color-mix(in srgb, var(--a2) 30%, transparent), transparent 60%),
    var(--surface-2);
}
.card .thumb img.photo { width: 100%; height: 100%; object-fit: cover; object-position: center 30%; transition: transform .4s ease; }
.card:hover .thumb img.photo { transform: scale(1.04); }
.card .thumb .mark { position: absolute; width: 56%; height: 72%; inset: 0; margin: auto; object-fit: contain; filter: drop-shadow(0 6px 16px rgba(0,0,0,.4)); }
.card .thumb .badge { position: absolute; left: 10px; bottom: 10px; width: 42px; height: 42px; object-fit: contain; filter: drop-shadow(0 2px 8px rgba(0,0,0,.6)); }
.card .thumb .initials { position: absolute; inset: 0; display: grid; place-items: center; font: 700 34px var(--cfont, var(--ui)); color: color-mix(in srgb, var(--a) 80%, var(--ink)); opacity: .9; }
.card .meta { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 4px; }
.card .sub { font: 600 11px/1 var(--ui); letter-spacing: .12em; text-transform: uppercase; color: var(--a); }
.card h3 { margin: 4px 0 2px; font: 700 19px/1.2 var(--cfont, var(--ui)); letter-spacing: var(--ctrack, -.01em); text-transform: var(--ccase, none); }
.card p { margin: 0; font-size: 14px; line-height: 1.5; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.card .count { font: 500 12px var(--ui); color: var(--muted); margin-top: 6px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { --a: var(--accent); display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px 6px 10px; border: 1px solid var(--line); border-radius: 999px; font-size: 14px; background: var(--surface); color: var(--ink); }
.chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--a); }
.chip small { color: var(--muted); font-size: 12px; }
.chip:hover { border-color: var(--a); text-decoration: none; }

.up { display: inline-flex; align-items: center; gap: 6px; margin-top: 56px; font: 500 14px var(--ui); color: var(--muted); }
.up:hover { color: var(--ink); text-decoration: none; }

/* ---------- lightbox ---------- */
.lightbox { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 24px; background: rgba(0,0,0,.88); cursor: zoom-out; }
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 10px; box-shadow: 0 20px 60px rgba(0,0,0,.6); }

/* ---------- responsive ---------- */
@media (max-width: 1000px) {
  .content { grid-template-columns: minmax(0, 1fr); gap: 24px; }
  .facts { position: static; order: -1; }
}
@media (max-width: 860px) {
  .top { padding: 0 16px; gap: 10px; }
  .tree-btn { display: grid; }
  .back { display: none; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .tree {
    position: fixed; top: 0; left: 0; z-index: 40; width: min(300px, 85vw); height: 100vh;
    background: var(--bg); transform: translateX(-100%); transition: transform .2s; padding-top: 24px;
  }
  body.tree-open .tree { transform: none; box-shadow: var(--shadow); }
  body.tree-open .scrim { display: block; position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.5); }
  .view { padding: 16px 16px 64px; }
  .hero { border-radius: 16px; }
  .hero-body { padding: 20px; gap: 14px; flex-direction: column; align-items: flex-start; }
  .hero-mark { width: 72px; height: 72px; }
  .hero .watermark { width: 220px; right: -50px; }
  .search kbd { display: none; }
  .body { font-size: 16px; }
}
@media (max-width: 520px) {
  .brand { display: none; }
  .cards { grid-template-columns: minmax(0, 1fr); }
}
