/* ==========================================================================
   Cultivation Wiki — Xianxia theme
   Palette is lifted from the mod's own in-game CultivationTheme.ui so the
   website and the menus read as one artifact:
     ink #1D0D07 · lacquer #35100B · crimson #5C1712 / #7C241B / #40100C
     gold #F6D77B · parchment #E4D6B0 · warn #B33A3A
   Two modes, named for the obvious reason: Yin (night ink) and Yang (day paper).
   ========================================================================== */

/* ---------- 1. Tokens ---------------------------------------------------- */

:root {
  /* Ink / lacquer surfaces */
  --ink-900:   #0E0603;
  --ink-850:   #150904;
  --ink-800:   #1D0D07;
  --ink-750:   #241009;
  --ink-700:   #2C130A;
  --lacquer:   #35100B;

  /* Crimson */
  --crimson-900: #2A0A07;
  --crimson-800: #40100C;
  --crimson-700: #5C1712;
  --crimson-600: #7C241B;
  --crimson-400: #B33A3A;

  /* Gold */
  --gold-100:  #FFF0C4;
  --gold-200:  #F6D77B;
  --gold-300:  #E0B44C;
  --gold-400:  #C9A227;
  --gold-600:  #8C6B1F;
  --gold-800:  #4A3711;

  /* Neutrals + jewel accents */
  --parchment:     #E4D6B0;
  --parchment-dim: #B9A87E;
  --parchment-mut: #8E7F5C;
  --jade:      #6FBF9B;
  --azure:     #7EA8D9;
  --violet:    #A98BD1;

  /* Semantic (Yin / night — the default) */
  --bg:            var(--ink-900);
  --bg-panel:      var(--ink-800);
  --bg-raise:      var(--ink-750);
  --bg-sunken:     var(--ink-850);
  --bg-header:     rgba(21, 9, 4, 0.88);
  --rule:          rgba(201, 162, 39, 0.22);
  --rule-strong:   rgba(201, 162, 39, 0.45);
  --text:          var(--parchment);
  --text-dim:      var(--parchment-dim);
  --text-mut:      var(--parchment-mut);
  --heading:       var(--gold-200);
  --link:          var(--gold-300);
  --link-hover:    var(--gold-100);
  --accent:        var(--crimson-600);
  --accent-soft:   rgba(124, 36, 27, 0.30);
  /* Text for "you are here" states, which sit on a tinted (not crimson) fill —
     so it must flip with the theme, unlike gold-on-lacquer. */
  --active-text:   var(--gold-100);
  --code-bg:       #15090533;
  --shadow:        0 18px 44px -18px rgba(0, 0, 0, 0.85);
  --glow:          0 0 22px -4px rgba(246, 215, 123, 0.35);
  --mist:          rgba(246, 215, 123, 0.06);

  /* Metrics */
  --sidebar-w: 268px;
  --toc-w:     216px;
  --header-h:  62px;
  --measure:   74ch;
  --radius:    3px;      /* lacquered panels are square-ish, not pill-soft */
  --radius-lg: 5px;

  --font-display: "Cinzel", "Noto Serif SC", Georgia, "Times New Roman", serif;
  --font-han: "Noto Serif SC", "Songti SC", "SimSun", serif;
  --font-body: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "JetBrains Mono", Consolas,
               "Liberation Mono", monospace;
}

/* Yang / day — aged paper, cinnabar and ink */
html[data-theme="light"] {
  --bg:          #EFE1C4;
  --bg-panel:    #F7EDD8;
  --bg-raise:    #FBF5E7;
  --bg-sunken:   #E7D7B6;
  --bg-header:   rgba(247, 237, 216, 0.90);
  --rule:        rgba(92, 23, 18, 0.20);
  --rule-strong: rgba(92, 23, 18, 0.40);
  --text:        #35211A;
  --text-dim:    #5E4436;
  --text-mut:    #8A6D58;
  --heading:     #6B1F12;
  --link:        #8A2B14;
  --link-hover:  #B33A3A;
  --accent:      var(--crimson-700);
  --accent-soft: rgba(124, 36, 27, 0.14);
  --active-text: #5A1A0E;
  --code-bg:     rgba(92, 23, 18, 0.06);
  --shadow:      0 16px 40px -20px rgba(74, 40, 20, 0.45);
  --glow:        0 0 20px -6px rgba(139, 43, 20, 0.30);
  --mist:        rgba(107, 31, 18, 0.05);
  --gold-200:    #8A5A12;
  --gold-300:    #9A6714;
  --parchment-mut: #8A6D58;
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + 18px);
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.72;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

/* Faint drifting qi-mist over the whole page */
body::before {
  content: "";
  position: fixed;
  inset: -20vh -20vw;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(48rem 30rem at 12% -5%, var(--mist), transparent 70%),
    radial-gradient(40rem 26rem at 88% 12%, rgba(124, 36, 27, 0.10), transparent 72%),
    radial-gradient(52rem 34rem at 50% 108%, rgba(111, 191, 155, 0.05), transparent 70%);
  animation: mist-drift 46s ease-in-out infinite alternate;
}
@keyframes mist-drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to   { transform: translate3d(-2.5%, 1.5%, 0) scale(1.06); }
}

/* ---------- 2. Typography ------------------------------------------------ */

h1, h2, h3, h4, h5 {
  font-family: var(--font-display);
  color: var(--heading);
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: 0.01em;
  margin: 2.2em 0 0.6em;
  scroll-margin-top: calc(var(--header-h) + 20px);
}
h1 { font-size: clamp(2rem, 1.4rem + 2vw, 2.9rem); margin-top: 0; letter-spacing: 0.02em; }
h2 { font-size: clamp(1.42rem, 1.2rem + 0.9vw, 1.8rem); padding-bottom: 0.34em; border-bottom: 1px solid var(--rule); }
h3 { font-size: 1.22rem; color: var(--gold-300); }
h4 { font-size: 1.02rem; color: var(--text); letter-spacing: 0.06em; text-transform: uppercase; }

/* Anchor links on headings */
.heading-anchor {
  opacity: 0;
  margin-left: 0.4em;
  color: var(--gold-600);
  text-decoration: none;
  font-family: var(--font-body);
  font-weight: 400;
  transition: opacity 0.16s ease, color 0.16s ease;
}
h2:hover .heading-anchor, h3:hover .heading-anchor,
.heading-anchor:focus-visible { opacity: 1; color: var(--link-hover); }

p { margin: 0 0 1.15em; }
a { color: var(--link); text-decoration-color: color-mix(in srgb, var(--link) 40%, transparent); text-underline-offset: 3px; transition: color 0.15s ease; }
a:hover { color: var(--link-hover); }

strong { color: var(--gold-200); font-weight: 600; }
html[data-theme="light"] strong { color: #6B1F12; }
em { color: var(--text-dim); }
hr { border: 0; height: 1px; background: linear-gradient(90deg, transparent, var(--rule-strong), transparent); margin: 2.6em 0; }

/* Chinese-character accents */
.han { font-family: var(--font-han); font-weight: 600; letter-spacing: 0.06em; }
.han-dim { font-family: var(--font-han); color: var(--text-mut); font-size: 0.86em; letter-spacing: 0.14em; }

ul, ol { padding-left: 1.35em; margin: 0 0 1.2em; }
li { margin: 0.34em 0; }
li::marker { color: var(--gold-600); }

blockquote {
  margin: 1.6em 0;
  padding: 0.2em 0 0.2em 1.2em;
  border-left: 2px solid var(--rule-strong);
  color: var(--text-dim);
  font-style: italic;
}

code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--code-bg);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 0.12em 0.4em;
  color: var(--gold-200);
}
html[data-theme="light"] code { color: #8A2B14; }

pre {
  background: var(--bg-sunken);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--gold-600);
  border-radius: var(--radius);
  padding: 1em 1.15em;
  overflow-x: auto;
  margin: 1.5em 0;
  font-size: 0.9rem;
  line-height: 1.62;
}
pre code { background: none; border: 0; padding: 0; color: var(--text); font-size: 0.9rem; }

/* ---------- 3. Site chrome: header + nav --------------------------------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 60;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 20px;
  background: var(--bg-header);
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  border-bottom: 1px solid var(--rule);
  box-shadow: 0 1px 0 rgba(246, 215, 123, 0.06), 0 10px 30px -22px #000;
}
/* the gold seam under the header, same trick as the in-game title bar */
.site-header::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -2px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold-600) 18%, var(--gold-300) 50%, var(--gold-600) 82%, transparent);
  opacity: 0.55;
}

.brand { display: flex; align-items: center; gap: 11px; text-decoration: none; flex-shrink: 0; }
.brand img { width: 34px; height: 34px; border-radius: var(--radius); border: 1px solid var(--rule-strong); box-shadow: var(--glow); }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-family: var(--font-display); font-size: 1.02rem; font-weight: 700; color: var(--gold-200); letter-spacing: 0.07em; text-transform: uppercase; }
.brand-sub { font-family: var(--font-han); font-size: 0.68rem; color: var(--text-mut); letter-spacing: 0.3em; }

.nav-main { display: flex; align-items: center; gap: 2px; margin-left: 10px; flex: 1; min-width: 0; }
.nav-link {
  position: relative;
  padding: 7px 13px;
  border-radius: var(--radius);
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.875rem;
  letter-spacing: 0.05em;
  font-weight: 500;
  white-space: nowrap;
  transition: color 0.15s ease, background 0.15s ease;
}
.nav-link:hover { color: var(--gold-200); background: var(--accent-soft); }
.nav-link.is-active { color: var(--active-text); background: var(--accent-soft); }
.nav-link.is-active::after {
  content: "";
  position: absolute;
  left: 13px; right: 13px; bottom: 1px;
  height: 1.5px;
  background: linear-gradient(90deg, transparent, var(--gold-300), transparent);
}

.header-tools { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.search-trigger {
  display: flex; align-items: center; gap: 9px;
  min-width: 210px;
  padding: 7px 10px;
  background: var(--bg-sunken);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  color: var(--text-mut);
  font: inherit; font-size: 0.83rem;
  cursor: pointer;
  transition: border-color 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}
.search-trigger:hover { border-color: var(--rule-strong); color: var(--text-dim); box-shadow: var(--glow); }
.search-trigger svg { flex-shrink: 0; opacity: 0.8; }
.search-trigger .kbd-hint { margin-left: auto; }

.kbd {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  padding: 2px 6px;
  border: 1px solid var(--rule);
  border-bottom-width: 2px;
  border-radius: var(--radius);
  background: var(--bg-raise);
  color: var(--text-mut);
}

.icon-btn {
  display: grid; place-items: center;
  width: 34px; height: 34px;
  background: var(--bg-sunken);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  color: var(--text-dim);
  cursor: pointer;
  transition: color 0.16s ease, border-color 0.16s ease, transform 0.3s ease;
}
.icon-btn:hover { color: var(--gold-200); border-color: var(--rule-strong); }
.theme-toggle:hover svg { transform: rotate(180deg); }
.theme-toggle svg { transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1); }

.menu-toggle { display: none; }

/* ---------- 4. Layout ---------------------------------------------------- */

.layout {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--toc-w);
  gap: 0;
  max-width: 1500px;
  margin: 0 auto;
  align-items: start;
}
.layout.is-wide { grid-template-columns: minmax(0, 1fr); max-width: none; }

/* Mobile drawer backdrop. Sits inside .layout so it shares the sidebar's
   stacking context (see site.js), which means it is a grid child — hence
   position:fixed and display:none here, at ALL widths, so it never occupies
   a column. Only .scrim.is-open under 900px makes it visible. */
.scrim {
  display: none;
  position: fixed;
  inset: var(--header-h) 0 0;
  z-index: 70;
  background: rgba(6, 3, 1, 0.6);
}

/* --- Sidebar --- */
.sidebar {
  position: sticky;
  top: var(--header-h);
  max-height: calc(100vh - var(--header-h));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 26px 18px 60px 22px;
  border-right: 1px solid var(--rule);
  font-size: 0.875rem;
}
/* The nav rails still scroll — the scrollbar is just hidden. It sat right on
   the gold divider rule and read as a UI seam. The search results keep theirs,
   since a modal list genuinely needs the "there is more" affordance. */
.sidebar, .toc { scrollbar-width: none; -ms-overflow-style: none; }
.sidebar::-webkit-scrollbar, .toc::-webkit-scrollbar { width: 0; height: 0; display: none; }
.search-results::-webkit-scrollbar { width: 8px; }
.search-results::-webkit-scrollbar-thumb { background: var(--rule-strong); border-radius: 4px; }
.search-results::-webkit-scrollbar-track { background: transparent; }

.side-group { margin-bottom: 22px; }
.side-title {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--font-display);
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold-600);
  margin: 0 0 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--rule);
}
.side-title .han-dim { letter-spacing: 0.1em; font-size: 0.78em; margin-left: auto; }

.side-list { list-style: none; margin: 0; padding: 0; }
.side-list a {
  display: block;
  padding: 5px 10px;
  margin: 1px 0;
  border-left: 2px solid transparent;
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-dim);
  text-decoration: none;
  transition: all 0.14s ease;
}
.side-list a:hover { color: var(--gold-200); background: var(--accent-soft); border-left-color: var(--gold-600); }
.side-list a.is-current {
  color: var(--active-text);
  background: linear-gradient(90deg, var(--accent-soft), transparent);
  border-left-color: var(--gold-300);
  font-weight: 600;
}
.side-list a .soon { float: right; font-size: 0.66rem; letter-spacing: 0.1em; color: var(--text-mut); text-transform: uppercase; opacity: 0.7; }

/* --- Main content --- */
.content {
  min-width: 0;
  padding: 40px 46px 100px;
  /* Fill the grid track up to the TOC rail. The old `--measure` cap was far
     narrower than the track and left a dead gap on the right. */
  max-width: none;
}
.content > *:first-child { margin-top: 0; }

.page-eyebrow {
  display: flex; align-items: center; gap: 10px;
  font-size: 0.72rem; letter-spacing: 0.2em; text-transform: uppercase;
  color: var(--text-mut); margin-bottom: 12px;
}
.page-eyebrow .sep { color: var(--gold-800); }
.page-lede { font-size: 1.08rem; color: var(--text-dim); max-width: 68ch; margin-bottom: 1.6em; }

/* --- TOC --- */
.toc {
  position: sticky;
  top: var(--header-h);
  max-height: calc(100vh - var(--header-h));
  overflow-y: auto;
  padding: 40px 20px 60px 10px;
  font-size: 0.82rem;
}
.toc-title { font-family: var(--font-display); font-size: 0.7rem; letter-spacing: 0.18em; text-transform: uppercase; color: var(--gold-600); margin: 0 0 10px; }
.toc ul { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--rule); }
.toc li a {
  display: block;
  padding: 4px 12px;
  margin-left: -1px;
  border-left: 2px solid transparent;
  color: var(--text-mut);
  text-decoration: none;
  line-height: 1.45;
  transition: all 0.14s ease;
}
.toc li a:hover { color: var(--gold-200); }
.toc li a.is-active { color: var(--gold-200); border-left-color: var(--gold-300); }
.toc li.lvl-3 a { padding-left: 24px; font-size: 0.95em; }

/* ---------- 5. Footer ---------------------------------------------------- */

.site-footer {
  position: relative;
  z-index: 1;
  border-top: 1px solid var(--rule);
  background: var(--bg-sunken);
  padding: 40px 46px 54px;
  color: var(--text-mut);
  font-size: 0.86rem;
}
.footer-inner { max-width: 1500px; margin: 0 auto; display: flex; flex-wrap: wrap; gap: 28px; align-items: flex-start; justify-content: space-between; }
.footer-col h5 { margin: 0 0 8px; font-size: 0.7rem; letter-spacing: 0.18em; color: var(--gold-600); }
.footer-col ul { list-style: none; margin: 0; padding: 0; }
.footer-col a { color: var(--text-dim); text-decoration: none; }
.footer-col a:hover { color: var(--gold-200); }
.footer-seal { text-align: right; font-family: var(--font-han); line-height: 1.9; }
.footer-seal .big { font-size: 1.5rem; color: var(--crimson-400); letter-spacing: 0.2em; }

/* ---------- 6. Components ------------------------------------------------ */

/* Lacquer panel — the site's workhorse surface, mirrors @XianxiaContainer */
.panel {
  position: relative;
  background: var(--bg-panel);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  margin: 1.6em 0;
  box-shadow: var(--shadow);
}
.panel-head {
  margin: -20px -22px 18px;
  padding: 11px 22px;
  background: var(--lacquer);
  border-bottom: 2px solid var(--gold-600);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  font-family: var(--font-display);
  font-size: 0.94rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--gold-200);
}
html[data-theme="light"] .panel-head { background: var(--crimson-700); color: var(--gold-100); }

/* Callouts */
.note {
  position: relative;
  margin: 1.6em 0;
  padding: 14px 18px 14px 46px;
  background: var(--bg-panel);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--gold-400);
  border-radius: var(--radius);
  font-size: 0.94rem;
}
.note::before {
  content: "☯";
  position: absolute; left: 15px; top: 13px;
  font-size: 1.05rem; line-height: 1.4; color: var(--gold-300);
}
.note > *:last-child { margin-bottom: 0; }
.note-title { display: block; font-family: var(--font-display); font-size: 0.76rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--gold-300); margin-bottom: 4px; }
.note.warn { border-left-color: var(--crimson-400); }
.note.warn::before { content: "⚡"; color: var(--crimson-400); }
.note.warn .note-title { color: var(--crimson-400); }
.note.tip { border-left-color: var(--jade); }
.note.tip::before { content: "❁"; color: var(--jade); }
.note.tip .note-title { color: var(--jade); }

/* Tables */
.table-wrap { overflow-x: auto; margin: 1.6em 0; border: 1px solid var(--rule); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
thead th {
  background: var(--lacquer);
  color: var(--gold-200);
  font-family: var(--font-display);
  font-size: 0.76rem;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  text-align: left;
  padding: 10px 14px;
  border-bottom: 2px solid var(--gold-600);
  white-space: nowrap;
}
html[data-theme="light"] thead th { background: var(--crimson-700); color: var(--gold-100); }
tbody td { padding: 9px 14px; border-bottom: 1px solid var(--rule); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:nth-child(even) { background: rgba(255, 255, 255, 0.016); }
html[data-theme="light"] tbody tr:nth-child(even) { background: rgba(92, 23, 18, 0.035); }
tbody tr:hover { background: var(--accent-soft); }

/* Card grid */
.grid { display: grid; gap: 16px; margin: 1.8em 0; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(258px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(215px, 1fr)); }

.card {
  position: relative;
  display: block;
  padding: 18px 20px;
  background: var(--bg-panel);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  text-decoration: none;
  color: inherit;
  overflow: hidden;
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1), border-color 0.2s ease, box-shadow 0.2s ease;
}
.card::before {
  content: "";
  position: absolute; inset: 0 auto 0 0; width: 2px;
  background: linear-gradient(180deg, transparent, var(--gold-400), transparent);
  opacity: 0; transition: opacity 0.2s ease;
}
a.card:hover { transform: translateY(-3px); border-color: var(--rule-strong); box-shadow: var(--shadow), var(--glow); }
a.card:hover::before { opacity: 1; }
.card h3, .card h4 { margin: 0 0 6px; font-size: 1.02rem; color: var(--gold-200); }
.card p { margin: 0; font-size: 0.88rem; color: var(--text-dim); line-height: 1.6; }
.card-icon { display: block; width: 34px; height: 34px; margin-bottom: 12px; color: var(--gold-300); }
.card-han {
  position: absolute; right: 10px; top: 2px;
  font-family: var(--font-han); font-size: 3.1rem; font-weight: 900;
  color: var(--gold-200); opacity: 0.07; pointer-events: none; user-select: none;
}

/* Realm ladder */
.realm-track { display: flex; flex-direction: column; gap: 10px; margin: 1.8em 0; }
.realm-row {
  display: grid;
  grid-template-columns: 54px 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  background: var(--bg-panel);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--realm, var(--gold-400));
  border-radius: var(--radius);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.realm-row:hover { transform: translateX(4px); box-shadow: var(--shadow); }
.realm-medal {
  position: relative;
  width: 46px; height: 46px;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 1.5px solid var(--realm, var(--gold-400));
  background: radial-gradient(circle at 50% 38%, color-mix(in srgb, var(--realm, #C9A227) 30%, transparent), transparent 68%);
  font-family: var(--font-han);
  font-size: 1.15rem; font-weight: 600;
  color: var(--realm, var(--gold-200));
  text-shadow: 0 0 14px color-mix(in srgb, var(--realm, #C9A227) 60%, transparent);
}
/* Realm accents are picked for glowing on ink; on paper they need darkening
   toward the text colour or the glyph washes out. */
html[data-theme="light"] .realm-medal {
  color: color-mix(in srgb, var(--realm, #C9A227) 55%, #2A1A0F);
  text-shadow: none;
  background: radial-gradient(circle at 50% 38%, color-mix(in srgb, var(--realm, #C9A227) 22%, transparent), transparent 70%);
}
.realm-medal::after {
  content: "";
  position: absolute; inset: -5px;
  border-radius: 50%;
  border: 1px solid color-mix(in srgb, var(--realm, #C9A227) 34%, transparent);
}
.realm-name { font-family: var(--font-display); font-size: 1.04rem; color: var(--gold-200); letter-spacing: 0.02em; }
.realm-sub { font-size: 0.83rem; color: var(--text-mut); }
.realm-tier { font-family: var(--font-mono); font-size: 0.74rem; letter-spacing: 0.12em; color: var(--text-mut); white-space: nowrap; }

/* Stat / meter */
.qi-meter { height: 7px; background: var(--bg-sunken); border: 1px solid var(--rule); border-radius: 4px; overflow: hidden; margin: 6px 0; }
.qi-meter > i { display: block; height: 100%; background: linear-gradient(90deg, var(--crimson-600), var(--gold-300)); box-shadow: 0 0 12px rgba(246, 215, 123, 0.55); }

/* Command / key chips */
.chip {
  display: inline-block;
  padding: 2px 9px;
  border: 1px solid var(--rule-strong);
  border-radius: 999px;
  font-size: 0.74rem;
  letter-spacing: 0.06em;
  color: var(--gold-300);
  background: var(--accent-soft);
  white-space: nowrap;
}
.chip.jade { color: var(--jade); border-color: color-mix(in srgb, var(--jade) 45%, transparent); background: color-mix(in srgb, var(--jade) 12%, transparent); }
.chip.crimson { color: var(--crimson-400); border-color: color-mix(in srgb, var(--crimson-400) 50%, transparent); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 9px;
  padding: 11px 22px;
  border: 1px solid var(--gold-600);
  border-radius: var(--radius);
  background: var(--crimson-700);
  color: var(--gold-200);
  font-family: var(--font-display);
  font-size: 0.84rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease, transform 0.16s ease, box-shadow 0.16s ease;
}
.btn:hover { background: var(--crimson-600); color: var(--gold-100); transform: translateY(-2px); box-shadow: var(--glow); }
.btn.ghost { background: transparent; border-color: var(--rule-strong); color: var(--text-dim); }
.btn.ghost:hover { background: var(--accent-soft); color: var(--gold-200); }

/* Ink-brush divider */
.divider-ink { display: block; width: 100%; max-width: 340px; margin: 3em auto; opacity: 0.5; color: var(--gold-400); }

/* Prev / next */
.page-nav { display: flex; gap: 14px; margin-top: 3.4em; padding-top: 1.6em; border-top: 1px solid var(--rule); }
.page-nav a { flex: 1; padding: 14px 18px; background: var(--bg-panel); border: 1px solid var(--rule); border-radius: var(--radius); text-decoration: none; transition: border-color 0.16s ease, transform 0.16s ease; }
.page-nav a:hover { border-color: var(--rule-strong); transform: translateY(-2px); }
.page-nav .dir { display: block; font-size: 0.7rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--text-mut); margin-bottom: 3px; }
.page-nav .ttl { font-family: var(--font-display); color: var(--gold-200); }
.page-nav a.next { text-align: right; }

/* ---------- 7. Hero (landing) -------------------------------------------- */

.hero {
  position: relative;
  z-index: 1;
  min-height: min(76vh, 640px);
  display: grid;
  place-items: center;
  text-align: center;
  padding: 76px 24px 88px;
  overflow: hidden;
  border-bottom: 1px solid var(--rule);
}
.hero-scene { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.hero-motes { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.hero-inner { position: relative; z-index: 3; max-width: 780px; }
.hero-seal { width: 118px; height: 118px; margin: 0 auto 22px; display: block; filter: drop-shadow(0 0 26px rgba(246, 215, 123, 0.30)); }
.hero h1 {
  font-size: clamp(2.5rem, 1.6rem + 3.6vw, 4.3rem);
  letter-spacing: 0.12em;
  margin: 0 0 4px;
  color: var(--gold-200);
  text-shadow: 0 0 42px rgba(246, 215, 123, 0.28), 0 3px 20px rgba(0, 0, 0, 0.6);
}
.hero .hero-han { font-family: var(--font-han); font-size: clamp(1rem, 0.8rem + 0.7vw, 1.35rem); letter-spacing: 0.6em; color: var(--crimson-400); margin: 0 0 22px; text-indent: 0.6em; }
.hero p.hero-lede { font-size: clamp(1rem, 0.94rem + 0.3vw, 1.15rem); color: var(--parchment); max-width: 60ch; margin: 0 auto 30px; text-shadow: 0 2px 12px rgba(0, 0, 0, 0.7); }
html[data-theme="light"] .hero p.hero-lede { color: var(--text); text-shadow: none; }
.hero-actions { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.hero-meta { margin-top: 34px; display: flex; gap: 26px; justify-content: center; flex-wrap: wrap; font-size: 0.8rem; color: var(--text-mut); letter-spacing: 0.08em; }
.hero-meta b { color: var(--gold-300); font-weight: 600; }

/* ---------- 8. Search modal ---------------------------------------------- */

.search-overlay {
  position: fixed; inset: 0; z-index: 200;
  display: none;
  background: rgba(6, 3, 1, 0.72);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  padding: 11vh 20px 20px;
  justify-content: center;
  align-items: flex-start;
}
.search-overlay.is-open { display: flex; animation: fade-in 0.16s ease; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.search-box {
  width: min(660px, 100%);
  background: var(--bg-panel);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-lg);
  box-shadow: 0 30px 90px -24px #000, var(--glow);
  overflow: hidden;
  animation: rise 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes rise { from { transform: translateY(-14px) scale(0.985); opacity: 0; } to { transform: none; opacity: 1; } }

.search-field { display: flex; align-items: center; gap: 12px; padding: 15px 18px; background: var(--lacquer); border-bottom: 2px solid var(--gold-600); }
html[data-theme="light"] .search-field { background: var(--crimson-700); }
.search-field svg { color: var(--gold-300); flex-shrink: 0; }
.search-field input {
  flex: 1; min-width: 0;
  background: none; border: 0; outline: none;
  color: var(--gold-100);
  font: inherit; font-size: 1.02rem;
}
.search-field input::placeholder { color: rgba(228, 214, 176, 0.42); }
/* Suppress the browser's own (bright blue, unthemeable) clear affordance. */
.search-field input { appearance: none; -webkit-appearance: none; }
.search-field input::-webkit-search-cancel-button,
.search-field input::-webkit-search-decoration { -webkit-appearance: none; display: none; }

.search-results { max-height: min(58vh, 480px); overflow-y: auto; padding: 8px; }
.search-hit {
  display: block;
  padding: 11px 14px;
  border-radius: var(--radius);
  border-left: 2px solid transparent;
  text-decoration: none;
  color: inherit;
}
.search-hit:hover, .search-hit.is-sel { background: var(--accent-soft); border-left-color: var(--gold-300); }
.search-hit .hit-crumb { font-size: 0.68rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-mut); }
.search-hit .hit-title { font-family: var(--font-display); font-size: 0.98rem; color: var(--gold-200); margin: 1px 0 3px; }
.search-hit .hit-snip { font-size: 0.83rem; color: var(--text-dim); line-height: 1.55; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.search-hit mark { background: rgba(246, 215, 123, 0.22); color: var(--gold-100); border-radius: 2px; padding: 0 2px; }
html[data-theme="light"] .search-hit mark { background: rgba(179, 58, 58, 0.18); color: #6B1F12; }
.search-empty { padding: 34px 20px; text-align: center; color: var(--text-mut); }
.search-empty .han { display: block; font-size: 2rem; color: var(--gold-800); margin-bottom: 8px; }
.search-foot { display: flex; gap: 16px; padding: 9px 16px; border-top: 1px solid var(--rule); background: var(--bg-sunken); font-size: 0.72rem; color: var(--text-mut); }
.search-foot span { display: flex; align-items: center; gap: 6px; }

/* ---------- 9. Mermaid --------------------------------------------------- */

.mermaid-wrap {
  margin: 1.8em 0;
  padding: 20px 18px;
  background: var(--bg-panel);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  overflow-x: auto;
  text-align: center;
}
.mermaid-wrap .mermaid-cap {
  display: block;
  margin-top: 12px;
  font-size: 0.78rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-mut);
}
pre.mermaid { background: none; border: 0; padding: 0; margin: 0; opacity: 0; transition: opacity 0.3s ease; }
pre.mermaid[data-processed="true"] { opacity: 1; }
/* Mermaid writes an inline max-width sized to the graph's natural width, which
   leaves diagrams marooned in the middle of a wide column. Override it so a
   diagram fills its frame and its labels scale up to a readable size.
   The max-height is essential: without it a tall diagram (subgraphs stacked
   vertically) scaled to 100% width becomes hundreds of pixels of giant boxes.
   With a viewBox present the SVG just scales down to fit, keeping its ratio. */
pre.mermaid svg {
  width: 100% !important;
  max-width: 100% !important;
  height: auto;
  max-height: 780px;
}

/* ---------- 10. Responsive ----------------------------------------------- */

@media (max-width: 1180px) {
  .layout { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .toc { display: none; }
}

@media (max-width: 900px) {
  :root { --header-h: 58px; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .nav-main { display: none; }
  .menu-toggle { display: grid; }
  .search-trigger { min-width: 0; }
  .search-trigger .label, .search-trigger .kbd-hint { display: none; }
  .brand-sub { display: none; }

  .sidebar {
    position: fixed;
    inset: var(--header-h) auto 0 0;
    width: min(310px, 84vw);
    z-index: 80;
    background: var(--bg-panel);
    max-height: none;
    transform: translateX(-102%);
    transition: transform 0.24s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 18px 0 50px -22px #000;
  }
  .sidebar.is-open { transform: none; }
  .scrim.is-open { display: block; }
  /* The drawer scrolls on its own (overscroll-behavior: contain); this stops
     the page underneath from scrolling too while it is open. */
  body.nav-open { overflow: hidden; }

  .content { padding: 30px 22px 80px; }
  .site-footer { padding: 34px 22px 44px; }
  .footer-seal { text-align: left; }
  .page-nav { flex-direction: column; }
}

@media (max-width: 560px) {
  .realm-row { grid-template-columns: 40px 1fr; }
  .realm-tier { grid-column: 2; }
  .realm-medal { width: 38px; height: 38px; font-size: 0.98rem; }
  .hero { min-height: 62vh; padding: 54px 18px 64px; }
}

/* ---------- 11. Accessibility / print ------------------------------------ */

:focus-visible { outline: 2px solid var(--gold-300); outline-offset: 2px; border-radius: var(--radius); }
.skip-link {
  position: absolute; left: 12px; top: -60px; z-index: 300;
  padding: 10px 16px; background: var(--crimson-700); color: var(--gold-100);
  border: 1px solid var(--gold-600); border-radius: var(--radius); text-decoration: none;
  transition: top 0.16s ease;
}
.skip-link:focus { top: 12px; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

@media print {
  .site-header, .sidebar, .toc, .site-footer, .search-overlay, .page-nav, .hero-motes { display: none !important; }
  body { background: #fff; color: #000; }
  .content { padding: 0; max-width: none; }
}

/* ---------- 12. Interactive tools (planner, calculator) ------------------ */

.tool-bar {
  display: flex; flex-wrap: wrap; gap: 14px 20px; align-items: flex-end;
  padding: 16px 18px; margin: 1.6em 0;
  background: var(--bg-panel); border: 1px solid var(--rule);
  border-left: 3px solid var(--gold-600); border-radius: var(--radius-lg);
}
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label {
  font-family: var(--font-display); font-size: 0.68rem; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--gold-600);
}
.field input, .field select {
  background: var(--bg-sunken); color: var(--text);
  border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 7px 10px; font: inherit; font-size: 0.9rem; min-width: 92px;
}
.field input:focus, .field select:focus { border-color: var(--rule-strong); outline: none; box-shadow: var(--glow); }
.field select option { background: var(--bg-panel); color: var(--text); }
.field .hint { font-size: 0.72rem; color: var(--text-mut); }
.field.wide input { min-width: 200px; }

.budget {
  display: flex; align-items: baseline; gap: 10px;
  font-family: var(--font-display); letter-spacing: 0.06em;
}
.budget .spent { font-size: 1.7rem; color: var(--gold-200); line-height: 1; }
.budget .of { color: var(--text-mut); font-size: 0.9rem; }
.budget.over .spent { color: var(--crimson-400); }

/* Planner canvas */
.tree-stage {
  position: relative; margin: 1.4em 0;
  background: radial-gradient(circle at 50% 50%, rgba(124,36,27,0.14), transparent 62%), var(--bg-sunken);
  border: 1px solid var(--rule); border-radius: var(--radius-lg);
  overflow: hidden;
}
.tree-stage svg { display: block; width: 100%; height: auto; touch-action: manipulation; }
.tree-stage .edge { stroke: var(--rule); stroke-width: 2; fill: none; }
.tree-stage .edge.on { stroke: var(--gold-400); stroke-width: 2.5; }
.tree-stage .node { cursor: pointer; }
.tree-stage .node circle { stroke-width: 2; transition: r 0.12s ease, fill-opacity 0.12s ease; }
.tree-stage .node .ring { fill: var(--ink-800); }
.tree-stage .node.locked { opacity: 0.34; cursor: not-allowed; }
.tree-stage .node.avail circle.ring { stroke-dasharray: 3 3; }
.tree-stage .node.on circle.ring { fill-opacity: 1; }
.tree-stage .node:hover circle.ring { stroke: var(--gold-100); }
.tree-stage .spoke-label {
  font-family: var(--font-han); font-size: 19px; font-weight: 600;
  text-anchor: middle; dominant-baseline: central; pointer-events: none;
}
.tree-stage .hub {
  font-family: var(--font-display); text-anchor: middle; fill: var(--gold-200);
}

.tip {
  position: absolute; z-index: 20; pointer-events: none;
  max-width: 260px; padding: 9px 12px;
  background: var(--bg-panel); border: 1px solid var(--rule-strong);
  border-radius: var(--radius); box-shadow: var(--shadow);
  font-size: 0.82rem; line-height: 1.5; opacity: 0; transition: opacity 0.12s ease;
}
.tip.show { opacity: 1; }
.tip .t-name { font-family: var(--font-display); color: var(--gold-200); display: block; }
.tip .t-meta { color: var(--text-mut); font-size: 0.74rem; letter-spacing: 0.08em; text-transform: uppercase; }
.tip .t-bonus { color: var(--jade); }
.tip .t-warn { color: var(--crimson-400); }

/* Result tables / stat readouts */
.readout { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin: 1.4em 0; }
.readout .stat {
  padding: 12px 14px; background: var(--bg-panel);
  border: 1px solid var(--rule); border-left: 3px solid var(--accent); border-radius: var(--radius);
}
.readout .stat .k { display: block; font-size: 0.72rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-mut); }
.readout .stat .v { font-family: var(--font-display); font-size: 1.32rem; color: var(--gold-200); }
.readout .stat .v small { font-size: 0.62em; color: var(--text-dim); letter-spacing: 0.04em; }

.bar-row { display: grid; grid-template-columns: 108px 1fr auto; gap: 10px; align-items: center; margin: 5px 0; font-size: 0.86rem; }
.bar-row .bar { height: 8px; background: var(--bg-sunken); border: 1px solid var(--rule); border-radius: 4px; overflow: hidden; }
.bar-row .bar > i { display: block; height: 100%; background: var(--fill, var(--gold-400)); }

.tool-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 1.2em 0; }
.copied { color: var(--jade); font-size: 0.82rem; opacity: 0; transition: opacity 0.2s ease; }
.copied.show { opacity: 1; }

@media (max-width: 700px) {
  .tool-bar { gap: 12px; }
  .bar-row { grid-template-columns: 86px 1fr auto; font-size: 0.8rem; }
}

/* Language switcher — an .icon-btn carrying text rather than an icon. */
.lang-toggle {
  width: auto; min-width: 34px; padding: 0 9px;
  font-family: var(--font-han); font-size: 0.78rem; font-weight: 600;
  letter-spacing: 0.04em; text-decoration: none;
}
.lang-toggle:hover { color: var(--gold-200); }
/* "EN" marker on Chinese sidebar rows whose page is not translated yet. */
html[lang^="zh"] .side-list a .soon { font-family: var(--font-body); letter-spacing: 0.08em; }
