:root {
  color-scheme: light dark;

  /* accent (shared) */
  --amber: #d4af5e;
  --star-500: #c8a44e;
  --star-700: #8f6e2e;

  /* typography */
  --serif: "Noto Serif SC", "Songti SC", "STSong", Georgia, serif;
  --sans: "PingFang SC", "Noto Sans SC", -apple-system, "Segoe UI", sans-serif;

  /* light mode (default) */
  --surface-bg: #faf5f0;
  --text-primary: #2d2320;
  --text-secondary: #55433d;
  --text-tertiary: #8a756a;
  --text-muted: #b8a89c;
  --line: rgba(143, 110, 46, 0.28);
  --orb-1: rgba(228, 200, 160, 0.35);
  --orb-2: rgba(218, 180, 175, 0.30);
  --orb-3: rgba(210, 190, 175, 0.25);
  --nav-glow: rgba(212, 175, 94, 0.7);
  --nav-glow-outer: rgba(212, 175, 94, 0.22);
  --hud-active-bg: rgba(212, 175, 94, 0.16);
  --edge-glow: rgba(212, 175, 94, 0.22);
  --egg-color: #8b7bb8;
  --menu-bg: rgba(255, 252, 248, 0.92);
  --menu-shadow: 0 8px 30px rgba(45, 35, 32, 0.10);
  --reader-bg: #fcf8f1;
  --code-bg: rgba(0, 0, 0, 0.045);
}

@media (prefers-color-scheme: dark) {
  :root {
    --surface-bg: #0d0d0d;
    --text-primary: rgba(255, 255, 255, 0.88);
    --text-secondary: rgba(255, 255, 255, 0.65);
    --text-tertiary: rgba(255, 255, 255, 0.45);
    --text-muted: rgba(255, 255, 255, 0.25);
    --line: rgba(255, 255, 255, 0.12);
    --orb-1: rgba(20, 23, 51, 0.7);
    --orb-2: rgba(26, 20, 56, 0.7);
    --orb-3: rgba(15, 26, 46, 0.7);
    /* accent shifts from amber to deep violet in dark mode */
    --amber: #8b7bb8;
    --star-500: #8b7bb8;
    --star-700: #66568f;
    --nav-glow: rgba(139, 123, 184, 0.6);
    --nav-glow-outer: rgba(139, 123, 184, 0.18);
    --hud-active-bg: rgba(139, 123, 184, 0.16);
    --edge-glow: rgba(139, 123, 184, 0.20);
    --egg-color: #b8a8e8;
    --menu-bg: rgba(22, 22, 28, 0.92);
    --menu-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
    --reader-bg: #101014;
    --code-bg: rgba(255, 255, 255, 0.07);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { font-family: var(--sans); color: var(--text-primary); background: var(--surface-bg); }

#viewport {
  position: fixed; inset: 0; overflow: hidden; background: var(--surface-bg);
}

/* ambient orbs (screen-space, slow drift) */
#orbs {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(ellipse 60% 50% at 20% 30%, var(--orb-1) 0%, transparent 60%),
    radial-gradient(ellipse 50% 55% at 75% 60%, var(--orb-2) 0%, transparent 55%),
    radial-gradient(ellipse 45% 40% at 50% 85%, var(--orb-3) 0%, transparent 55%);
  animation: drift 80s ease-in-out infinite;
  transition: background 0.4s ease;
}
@keyframes drift {
  0%, 100% { transform: translate(0, 0) scale(1); }
  25%      { transform: translate(-2%, 1%) scale(1.04); }
  50%      { transform: translate(1%, -1.5%) scale(0.97); }
  75%      { transform: translate(2%, 0.5%) scale(1.03); }
}
@media (prefers-reduced-motion: reduce) { #orbs { animation: none; } }

#stars { position: fixed; inset: 0; z-index: 1; }

#constellation {
  position: fixed; inset: 0; z-index: 1;
  width: 100%; height: 100%;
  pointer-events: none;
}
#constellation line {
  stroke: var(--star-500);
  stroke-width: 1;
  stroke-linecap: round;
  opacity: 0;
}

/* DOM world: pages floating on the starfield */
#world {
  position: fixed; inset: 0; z-index: 2;
  pointer-events: none;
}

.page {
  position: absolute; left: 50%; top: 50%;
  width: min(680px, 88vw);
  max-height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  padding: clamp(2rem, 6vw, 4rem);
  pointer-events: auto;
  text-align: center;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.page::-webkit-scrollbar { width: 6px; }
.page::-webkit-scrollbar-track { background: transparent; }
.page::-webkit-scrollbar-thumb { background: var(--line); border-radius: 999px; }
.page::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }
.page__content { transition: opacity 0.45s ease; }
#constellation circle {
  fill: var(--star-500);
  opacity: 0;
}

/* intro: hold content (and hint) back until the camera arrives */
.is-intro .page__content { opacity: 0; }
.is-intro.intro-reveal .page__content { opacity: 1; }
.is-intro .hint { opacity: 0; }

.page h1 {
  font-family: var(--serif); font-weight: 400;
  font-size: clamp(2rem, 6vw, 3rem); letter-spacing: 0.06em;
  margin: 0 0 1rem; color: var(--text-primary);
}
.page__sub { color: var(--text-tertiary); margin: 0 0 1.5rem; }
.page__body { color: var(--text-secondary); line-height: 1.9; margin: 0; }
.page__list { list-style: none; padding: 0; margin: 0; text-align: left; color: var(--text-secondary); line-height: 2.2; }
.page__egg {
  font-family: var(--serif); letter-spacing: 0.04em;
  font-size: clamp(1.4rem, 4vw, 2rem);
  color: var(--egg-color); margin: 0;
}

/* ── Nav (horizontal, click to toggle) ───────────────────────────── */
.dropdown {
  position: fixed; top: 18px; left: 24px; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  pointer-events: auto; font-family: var(--serif);
  letter-spacing: 0.04em;
}

.dropdown__brand { color: var(--text-primary); white-space: nowrap; }

/* item row folds horizontally (grid 0fr → 1fr animates width) */
.dropdown__menu {
  display: grid;
  grid-template-columns: 0fr;
  transition: grid-template-columns 0.28s ease;
}
.dropdown.is-open .dropdown__menu { grid-template-columns: 1fr; }

.dropdown__items {
  display: flex; align-items: center; gap: 4px;
  list-style: none; margin: 0; padding: 0;
  min-width: 0; overflow: hidden; white-space: nowrap;
}

.dropdown__item {
  display: inline-flex; align-items: center; padding: 6px 10px; border-radius: 8px;
  color: var(--text-secondary); text-decoration: none; cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
}
.dropdown__item:hover { color: var(--text-primary); background: var(--hud-active-bg); }
.dropdown__item.is-active { color: var(--text-primary); }

/* caret button: current page shows when folded, arrow is always present */
.dropdown__caret {
  display: flex; align-items: center; gap: 6px;
  border: 0; background: none; padding: 6px 10px; cursor: pointer;
  font-family: inherit; font-size: 1rem; letter-spacing: 0.04em;
}
.dropdown__current {
  color: var(--text-primary); white-space: nowrap;
  max-width: 0; opacity: 0; overflow: hidden;
  transition: max-width 0.28s ease, opacity 0.28s ease;
}
.dropdown:not(.is-open) .dropdown__current { max-width: 8em; opacity: 1; }
.dropdown__arrow { color: var(--text-tertiary); }

/* easter egg: a ghost item that may appear in the nav */
.dropdown__item--egg { display: none; color: var(--egg-color); animation: eggpulse 2.6s ease-in-out infinite; }
.dropdown__item--egg.is-shown { display: inline-flex; }
.dropdown__item--egg:hover { color: var(--egg-color); background: transparent; }
@keyframes eggpulse { 0%, 100% { opacity: 0.35; } 50% { opacity: 0.85; } }

.hint {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  z-index: 4; color: var(--text-muted); font-size: 0.8rem; pointer-events: none; margin: 0;
  transition: opacity 0.4s ease;
}

/* splash: one line typed between the constellation and the content */
.splash {
  position: fixed; left: 0; right: 0; top: 50%;
  transform: translateY(-50%);
  z-index: 3; margin: 0; padding: 0 2rem;
  text-align: center;
  font-family: var(--serif); font-weight: 300;
  font-size: clamp(1rem, 3.5vw, 1.35rem);
  letter-spacing: 0.1em;
  color: var(--text-secondary);
  opacity: 0; pointer-events: none;
}

.grain {
  position: fixed; inset: 0; z-index: 3; pointer-events: none; opacity: 0.03;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ── Reader (immersive detail, opened in place) ─────────────────── */
.reader {
  position: fixed; inset: 0; z-index: 6;
  display: flex; flex-direction: column;
  background: var(--reader-bg);
  opacity: 0; visibility: hidden;
  transform: translateY(26px);
  transition: opacity 0.4s ease, transform 0.4s ease, visibility 0.4s;
}
.reader.is-open { opacity: 1; visibility: visible; transform: translateY(0); }

.reader__bar {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 28px; flex: 0 0 auto;
  border-bottom: 1px solid var(--line);
}
.reader__back {
  border: 1px solid var(--line); background: none; color: var(--text-secondary);
  padding: 5px 14px; border-radius: 999px; cursor: pointer;
  font-family: var(--sans); font-size: 0.82rem; letter-spacing: 0.04em;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.reader__back:hover { color: var(--text-primary); border-color: var(--star-500); background: var(--hud-active-bg); }
.reader__heading { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.reader__title { font-family: var(--serif); font-size: 1.05rem; color: var(--text-primary); letter-spacing: 0.02em; }
.reader__crumb { font-size: 0.72rem; color: var(--text-muted); letter-spacing: 0.06em; }

.reader__scroll { flex: 1 1 auto; overflow-y: auto; }
.reader__body {
  max-width: 46rem; margin: 0 auto;
  padding: clamp(2rem, 6vw, 4rem) 2rem 6rem;
  color: var(--text-secondary); line-height: 1.9; font-size: 1.02rem;
  overflow-wrap: break-word;
}
.reader__body h1, .reader__body h2, .reader__body h3, .reader__body h4 {
  font-family: var(--serif); font-weight: 500; color: var(--text-primary);
  letter-spacing: 0.02em; line-height: 1.4; margin: 2.1em 0 0.7em;
}
.reader__body h1 { font-size: 1.85rem; margin-top: 0; }
.reader__body h2 { font-size: 1.4rem; border-bottom: 1px solid var(--line); padding-bottom: 0.4em; }
.reader__body h3 { font-size: 1.18rem; }
.reader__body h4 { font-size: 1.03rem; }
.reader__body p { margin: 0.9em 0; }
.reader__body strong { color: var(--text-primary); font-weight: 600; }
.reader__body a { color: var(--amber); text-decoration: none; border-bottom: 1px solid transparent; }
.reader__body a:hover { border-bottom-color: var(--amber); }
.reader__body code {
  font-family: "SF Mono", "JetBrains Mono", Consolas, "Courier New", monospace;
  font-size: 0.86em; background: var(--code-bg); padding: 0.12em 0.42em; border-radius: 4px;
}
.reader__body pre {
  background: var(--code-bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 1em 1.2em; overflow-x: auto; line-height: 1.6; margin: 1.2em 0;
}
.reader__body pre code { background: none; padding: 0; font-size: 0.85rem; }
.reader__body blockquote {
  margin: 1.2em 0; padding: 0.15em 0 0.15em 1em;
  border-left: 3px solid var(--star-500); color: var(--text-tertiary);
}
.reader__body table { border-collapse: collapse; width: 100%; margin: 1.2em 0; font-size: 0.9rem; }
.reader__body th, .reader__body td { border: 1px solid var(--line); padding: 0.55em 0.8em; text-align: left; }
.reader__body th { background: var(--hud-active-bg); color: var(--text-primary); font-weight: 600; }
.reader__body hr { border: 0; border-top: 1px solid var(--line); margin: 2em 0; }
.reader__body ul, .reader__body ol { padding-left: 1.5em; margin: 0.9em 0; }
.reader__body li { margin: 0.35em 0; }
.reader__body img { max-width: 100%; border-radius: 8px; border: 1px solid var(--line); }
.reader__body .wikilink { color: var(--star-700); border-bottom: 1px dashed var(--star-700); cursor: pointer; }
.reader__body .wikilink:hover { border-bottom-style: solid; }
.reader__body .wikilink--broken { cursor: help; opacity: 0.6; }
.reader__body .wikilink--broken:hover { border-bottom-style: dashed; }
.reader__empty { color: var(--text-muted); }

/* ── Browse pages (articles + knowledge): two-pane index ────────── */
.page--wide { width: min(880px, 92vw); }

.index {
  display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 24px;
  height: min(60vh, 480px); text-align: left; margin-top: 1rem;
}
.index__side, .index__main { overflow-y: auto; min-width: 0; min-height: 0; }
.index__side { border-right: 1px solid var(--line); padding-right: 14px; }

/* collapsible section: animated grid-rows fold */
.fold { border: 0; }
.fold + .fold { margin-top: 0.55rem; }
.fold__head {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; padding: 0.45rem 0.25rem; margin: 0; border: 0; background: none;
  font-family: var(--serif); color: var(--text-primary); letter-spacing: 0.04em;
  font-size: 0.95rem; cursor: pointer;
}
.fold__head::after { content: '▸'; color: var(--text-tertiary); font-size: 0.72rem; transition: transform 0.2s ease; }
.fold.is-open > .fold__head::after { transform: rotate(90deg); }
.fold__body {
  display: grid; grid-template-rows: 0fr; visibility: hidden;
  transition: grid-template-rows 0.28s ease, visibility 0.28s;
}
.fold.is-open > .fold__body { grid-template-rows: 1fr; visibility: visible; }
.fold__inner { min-height: 0; overflow: hidden; }

.fold__item {
  display: block; width: 100%; text-align: left;
  padding: 0.4rem 0.6rem 0.4rem 1.1rem; margin: 0;
  border: 0; border-left: 2px solid transparent; background: none; cursor: pointer;
  color: var(--text-secondary); font-size: 0.9rem; font-family: inherit;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.fold__item:hover { color: var(--text-primary); }
.fold__item.is-active { color: var(--text-primary); border-left-color: var(--star-500); }

/* knowledge: group heading + note list */
.kb__head {
  font-family: var(--serif); color: var(--text-primary); font-size: 1.05rem;
  letter-spacing: 0.03em; padding-bottom: 0.5rem; border-bottom: 1px solid var(--line); margin: 0 0 0.35rem;
}
.kb__note {
  display: block; width: 100%; text-align: left;
  padding: 0.5rem 0.6rem 0.5rem 0.25rem; margin: 0;
  border: 0; border-left: 2px solid transparent; background: none; cursor: pointer;
  color: var(--text-secondary); font-size: 0.95rem; font-family: inherit;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.kb__note:hover { color: var(--text-primary); border-left-color: var(--star-500); }

/* articles: preview */
.article__title { font-family: var(--serif); color: var(--text-primary); font-weight: 500; font-size: 1.5rem; letter-spacing: 0.02em; margin: 0 0 0.6rem; }
.article__date { color: var(--text-muted); font-size: 0.8rem; letter-spacing: 0.06em; margin: 0 0 1rem; }
.article__summary { color: var(--text-secondary); line-height: 1.85; font-size: 0.98rem; margin: 0 0 1.4rem; }
.article__read {
  border: 1px solid var(--line); background: none; color: var(--text-primary);
  padding: 0.5rem 1.15rem; border-radius: 999px; cursor: pointer;
  font-family: var(--sans); font-size: 0.85rem; letter-spacing: 0.04em;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.article__read:hover { border-color: var(--star-500); background: var(--hud-active-bg); }

/* ── Toolbar (category chips + search, under the slogan) ─────────── */
.toolbar {
  display: flex; align-items: center; justify-content: center; flex-wrap: wrap;
  gap: 10px; margin: 0 0 1rem;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.chip {
  border: 1px solid var(--line); background: none; color: var(--text-secondary);
  padding: 0.28rem 0.75rem; border-radius: 999px; cursor: pointer;
  font-family: var(--sans); font-size: 0.8rem; letter-spacing: 0.03em;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.chip:hover { color: var(--text-primary); border-color: var(--star-500); }
.chip.is-active { color: var(--text-primary); border-color: var(--star-500); background: var(--hud-active-bg); }

.toolbar__search {
  border: 1px solid var(--line); background: none; color: var(--text-primary);
  padding: 0.32rem 0.85rem; border-radius: 999px; min-width: 0;
  font-family: var(--sans); font-size: 0.85rem; letter-spacing: 0.02em;
  transition: border-color 0.15s ease;
}
.toolbar__search::placeholder { color: var(--text-muted); }
.toolbar__search:focus { outline: none; border-color: var(--star-500); }

/* search mode: hide the sidebar, let results span the index pane */
.index--search { grid-template-columns: minmax(0, 1fr); }
.index--search .index__side { display: none; }

/* ── Featured-pinned articles ────────────────────────────────────── */
.featured { margin-bottom: 0.9rem; }
.featured__head {
  font-family: var(--serif); color: var(--text-primary); letter-spacing: 0.06em;
  font-size: 0.82rem; text-transform: none; padding: 0.25rem 0.25rem 0.4rem;
}
.featured__card {
  display: flex; flex-direction: column; gap: 0.2rem; width: 100%; text-align: left;
  padding: 0.5rem 0.6rem; margin: 0 0 0.4rem;
  border: 1px solid var(--line); border-left: 2px solid var(--star-500); border-radius: 8px;
  background: var(--hud-active-bg); cursor: pointer;
  transition: border-color 0.15s ease;
}
.featured__card:hover { border-color: var(--star-500); }
.featured__title { color: var(--text-primary); font-family: var(--serif); font-size: 0.9rem; letter-spacing: 0.02em; }
.featured__summary {
  color: var(--text-tertiary); font-size: 0.76rem; line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

/* ── Badges (featured mark + category tags) ──────────────────────── */
.article__badges { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 0.7rem; }
.badge {
  border: 1px solid var(--line); color: var(--text-tertiary);
  padding: 0.12rem 0.55rem; border-radius: 999px;
  font-size: 0.72rem; letter-spacing: 0.04em;
}
.badge--featured { color: var(--star-700); border-color: var(--star-500); }

/* ── Search result hits ──────────────────────────────────────────── */
.search-hit { padding: 0.5rem 0 1.3rem; border-bottom: 1px solid var(--line); }
.search-hit:last-child { border-bottom: 0; }
.search-hit .article__title { font-size: 1.2rem; margin-bottom: 0.35rem; }

.kb__note-title { display: block; color: var(--text-primary); }
.kb__note-crumb { display: block; color: var(--text-muted); font-size: 0.72rem; letter-spacing: 0.05em; margin-top: 0.12rem; }

/* ── Home links / About ─────────────────────────────────────────── */
.page__links { text-align: left; margin: 1.2rem auto 0; max-width: 26rem; }
.page__links a { color: var(--amber); text-decoration: none; border-bottom: 1px solid transparent; }
.page__links a:hover { border-bottom-color: var(--amber); }
.about { text-align: left; margin-top: 0.6rem; }
.about h2 { font-family: var(--serif); font-weight: 500; color: var(--text-primary); font-size: 1.15rem; letter-spacing: 0.02em; margin: 1.6em 0 0.4em; }
