/* Visual Study Notes (noahxie.com) — Stage, Dark Obsidian Tokens, Dual-Layer Canvas, HUD & Library Chrome */
:root {
  --bg: #18171C;
  --fg: #ECE9E2;
  --accent: #34C6CE;
  --accent-ink: #18171C;
  --brass: #C9A86A;
  --surface: #212028;
  --paper: #ECE9E2;
  --night: #18171C;
  --dim: color-mix(in srgb, var(--fg) 60%, var(--bg));
  --hair: color-mix(in srgb, var(--fg) 20%, var(--bg));

  --t0: 17px;
  --t1: calc(var(--t0) * 9 / 8);
  --t2: calc(var(--t0) * 4 / 3);
  --t3: calc(var(--t0) * 3 / 2);
  --t4: calc(var(--t0) * 2);

  /* 4-Step Micro Scale (zero < 12px micro text across observatory & reading views) */
  --ts-xs: 12px;
  --ts-sm: 13px;
  --ts-md: 14px;
  --ts-lg: 15px;

  /* Three-Tier Self-Hosted Typography Tokens (zero external CDN, zero SimSun fallback) */
  /* Latin serifs precede CJK so ASCII/smart apostrophes in Xi'an never inherit wide CJK metrics */
  --font-medieval-deco: 'Cinzel Decorative', 'Cinzel', 'Noto Serif SC', 'Songti SC', serif;
  --font-medieval: 'Cinzel', 'Noto Serif SC', 'Songti SC', 'Microsoft YaHei UI', serif;
  --font-acad-display: 'Source Serif 4', 'Noto Serif SC', 'PingFang SC', 'Microsoft YaHei UI', serif;
  --font-acad-body: 'Source Serif 4', 'Noto Serif SC', 'PingFang SC', 'Microsoft YaHei UI', serif;
  --font-acad-ui: 'Inter', 'PingFang SC', 'Microsoft YaHei UI', 'Microsoft YaHei', sans-serif;
  --font-ornate-display: 'Cinzel Decorative', 'Cormorant Garamond', 'LXGW WenKai', 'Kaiti SC', 'STKaiti', 'KaiTi', serif;
  --font-ornate-accent: 'Uncial Antiqua', 'Cinzel Decorative', 'LXGW WenKai', 'Kaiti SC', serif;
  --font-ornate-body: 'Cormorant Garamond', 'LXGW WenKai', 'Kaiti SC', 'STKaiti', 'KaiTi', serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* Observatory shell defaults (reading sections override inside main#lectio) */
  --font-display: var(--font-medieval);
  --font-body: var(--font-acad-body);

  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  overflow-x: clip;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 400 var(--t0)/1.88 var(--font-body);
  overflow-x: clip;
}

html.js body:not(.legens) {
  overflow: hidden;
  height: 100svh;
  user-select: none;
  -webkit-user-select: none;
}

html.js body:not(.legens) #cv {
  touch-action: none;
}

html.js a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 1.5px solid var(--accent); outline-offset: 3px; }

.caps {
  font-family: var(--font-medieval);
  font-size: var(--ts-xs);
  letter-spacing: 0.24em;
  text-transform: uppercase;
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* Reading Mode Observatory Nebula Ambiance (pure CSS, 0 GPU overhead; ::before is reserved for mobile topbar mask) */
body.legens::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 62% 52% at 86% 18%, rgba(68, 56, 128, 0.17) 0%, rgba(44, 38, 86, 0.06) 48%, transparent 76%),
    radial-gradient(ellipse 42% 38% at 88% 42%, rgba(52, 198, 206, 0.08) 0%, rgba(52, 198, 206, 0.02) 44%, transparent 72%),
    radial-gradient(ellipse 52% 46% at 14% 86%, rgba(44, 38, 78, 0.14) 0%, rgba(36, 31, 64, 0.04) 50%, transparent 78%),
    radial-gradient(ellipse at 50% 45%, transparent 48%, rgba(12, 11, 16, 0.42) 100%);
}

.skip-link {
  position: fixed;
  left: -999em;
  top: 0;
  z-index: 80;
  background: var(--bg);
  color: var(--fg);
  padding: 8px 14px;
  border: 1px solid var(--fg);
}
.skip-link:focus { left: 12px; top: 12px; clip-path: none; }

/* Permanent Full-Viewport WebGL2 PBR Stage (#cv), 2D Precision HUD (#cv-fx) & SVG Overlay (#ov) */
#cv,
#cv-fx {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
#cv {
  z-index: 1;
}
#cv-fx {
  z-index: 2;
  pointer-events: none;
}
body.legens #cv {
  pointer-events: none;
}

#ov {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 3;
  pointer-events: none;
  transition: opacity 0.28s ease;
}
#ov a { pointer-events: auto; cursor: pointer; outline: none; transition: opacity 0.32s ease; }
#ov text { font-family: var(--font-medieval); }
#ov a .hit { fill: none; stroke: transparent; pointer-events: stroke; }

.lab {
  letter-spacing: 0.2em;
  text-transform: uppercase;
  font-weight: 600;
  paint-order: stroke;
  stroke: var(--bg);
  stroke-width: 4.5px;
  stroke-linejoin: round;
  transition: letter-spacing 0.32s ease;
}
.lab .ra {
  font-family: var(--font-mono);
  font-style: normal;
  font-size: 0.78em;
  letter-spacing: 0.08em;
  opacity: 0.78;
}
.lab .zh-name {
  font-family: var(--font-medieval);
  font-weight: 600;
  letter-spacing: 0.28em;
}
#ov a:hover .lab,
#ov a:focus-visible .lab,
#ov a.on .lab {
  letter-spacing: 0.32em;
}
#ov a:hover .lab .ra,
#ov a:focus-visible .lab .ra,
#ov a.on .lab .ra {
  fill: var(--accent);
  opacity: 1;
}
#ov a[data-k="0"]:hover .lab .ra,
#ov a[data-k="0"]:focus-visible .lab .ra,
#ov a[data-k="0"].on .lab .ra {
  fill: #76A7FF;
}
#ov a:focus-visible .lab { text-decoration: underline; }

body.sero #ov a,
body.sero .index,
body.legens #ov,
body.legens #ov a,
body.bibl #ov,
body.bibl #ov a,
body.vertens #ov,
body.vertens #ov a,
body.trans #ov,
body.trans #ov a {
  opacity: 0;
  pointer-events: none;
}
body.legens #ov,
body.bibl #ov,
body.vertens #ov,
body.trans #ov {
  visibility: hidden;
}
body.sero #ov:focus-within a,
body.sero .index:focus-within {
  opacity: 1;
}

.hud { position: fixed; z-index: 20; }

/* Top-Left Minimalist Observatory Emblem (Home stage only) */
#emblem {
  left: clamp(18px, 3.4vw, 48px);
  top: clamp(16px, 3vh, 30px);
  display: grid;
  gap: 3px;
  pointer-events: none;
  transition: opacity 0.32s ease;
}
.emblem-row {
  display: inline-flex;
  align-items: center;
  gap: 9px;
}
.emblem-name {
  font-family: var(--font-medieval-deco);
  font-weight: 700;
  font-size: clamp(16px, 1.4vw, 20px);
  letter-spacing: 0.2em;
  line-height: 1.15;
  text-transform: uppercase;
}
.emblem-name .name-short { display: none; }
.emblem-star {
  width: 12px;
  height: 12px;
  color: var(--brass);
  flex: none;
}
.emblem-sub {
  font-family: var(--font-ornate-body);
  font-style: italic;
  font-size: 13.5px;
  letter-spacing: 0.04em;
  color: var(--dim);
  line-height: 1.25;
}
body[data-lang="zh"] .emblem-sub {
  font-style: normal;
  font-size: 12.5px;
  letter-spacing: 0.08em;
}
.emblem-sub .sub-short { display: none; }
body.legens #emblem,
body.bibl #emblem,
body.vertens #emblem,
body.trans #emblem {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.14s ease, visibility 0s 0.14s;
}

/* Top-Left Return Crest (Reading & Library states) */
#redi {
  left: clamp(18px, 3.4vw, 48px);
  top: clamp(14px, 3vh, 28px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.32s ease;
  font-family: var(--font-medieval);
  font-style: normal;
  font-weight: 600;
  font-size: clamp(15px, 1.2vw, 18px);
  letter-spacing: 0.08em;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg);
  padding: 0 14px 0 0;
  white-space: nowrap;
}
#redi::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--brass) 45%, transparent);
  flex: none;
}
body.legens #redi,
body.bibl #redi {
  opacity: 1;
  pointer-events: auto;
}
body.bibl #redi {
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(4px);
  padding: 0 14px 0 10px;
  border-radius: 99px;
}

/* Top-Right 4-Icon Toolbar */
.tools {
  right: clamp(14px, 3vw, 40px);
  top: clamp(14px, 3vh, 28px);
  display: flex;
  align-items: center;
  gap: 8px;
}
.tools button,
.tools a {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid color-mix(in srgb, var(--hair) 95%, transparent);
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(4px);
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background-color 0.18s ease, color 0.18s ease, transform 0.12s ease;
}
.tools button:active,
.tools a:active {
  transform: scale(0.95);
}
.tools svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.25;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tools button:hover,
.tools a:hover,
.tools button:focus-visible,
.tools a:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
}
#lang-btn {
  font-family: var(--font-mono);
  font-size: var(--ts-xs);
  font-weight: 500;
  letter-spacing: 0.04em;
}
#voc .novum { fill: var(--accent); stroke: none; }
#voc[aria-current="true"] { background: var(--fg); color: var(--bg); border-color: var(--fg); }
body.legens #voc { display: none; }

#bib[aria-pressed="true"],
#lab[aria-expanded="true"] {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}
#voc[aria-current="true"]:hover,
#bib[aria-pressed="true"]:hover,
#lab[aria-expanded="true"]:hover {
  border-color: var(--accent);
  color: var(--bg);
}
#lab[data-sound="on"] .lab-wave { stroke: var(--accent); }
#lab[aria-expanded="true"] .lab-wave { stroke: var(--bg); }

/* Right Margin Telemetry (.margo) */
.margo {
  right: clamp(18px, 3.4vw, 48px);
  width: min(24vw, 310px);
  text-align: right;
  line-height: 1.3;
  transition: opacity 0.32s ease;
}
#clock {
  top: calc(clamp(14px, 3vh, 28px) + 64px);
  transition: opacity 0.22s ease;
}
#clock time {
  display: block;
  font: 600 var(--t4)/1 var(--font-medieval);
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}
#clock span {
  display: block;
  margin-top: 7px;
  color: var(--dim);
}
#nunc {
  top: 42svh;
}
#nunc small {
  display: block;
  color: var(--dim);
  margin-bottom: 8px;
}
#nunc a {
  display: block;
  font-family: var(--font-medieval);
  font-size: var(--t1);
  font-weight: 600;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s ease;
}
#nunc a:hover,
#nunc a:focus-visible { border-bottom-color: var(--accent); }
#nunc time {
  display: block;
  margin-top: 6px;
  font-family: var(--font-mono);
  letter-spacing: 0.08em;
  color: var(--dim);
  font-size: 13px;
}
#nt:empty, #nd:empty { display: none; }
#nunc:has(#nt:empty) { visibility: hidden; }

#iv {
  bottom: clamp(20px, 5vh, 44px);
  margin: 0;
}
#iv b {
  display: block;
  font: 600 clamp(24px, 2.1vw, 34px)/1.12 var(--font-medieval);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}
#iv span {
  display: block;
  margin-top: 4px;
  font-family: var(--font-medieval);
  color: var(--dim);
}

/* Precision Optical / Tactical Micro-Reticle Coordinate — cleanly anchored in bottom-right clear sky above #iv */
#reticle-coord {
  right: clamp(18px, 3.4vw, 48px);
  bottom: calc(clamp(20px, 5vh, 44px) + 74px);
  margin: 0;
  text-align: right;
  font-family: var(--font-mono);
  font-size: var(--ts-xs);
  letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums;
  color: var(--dim);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
#reticle-coord.vis { opacity: 0.78; }
body.legens #reticle-coord,
body.vertens #reticle-coord,
body.bibl #reticle-coord,
body.trans #reticle-coord {
  opacity: 0 !important;
}

body.legens .margo,
body.vertens .margo,
body.trans .margo {
  opacity: 0;
  pointer-events: none;
}
body.bibl #clock,
body.bibl #iv,
body.lab-open #clock,
body:has(#labM:not([hidden])) #clock {
  opacity: 0;
  pointer-events: none;
}

/* Library Nunc Card */
body.bibl #nunc {
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  padding: 12px 16px 12px 18px;
  box-shadow: 0 0 0 1px var(--hair), 0 10px 28px rgba(0, 0, 0, 0.22);
  width: max-content;
  max-width: min(44vw, 500px);
}
body.bibl #nt,
body.bibl #nd {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
body.bibl #nd {
  font-family: var(--font-body);
  font-size: 13.5px;
  letter-spacing: 0.04em;
}

/* Flow / Denoising & Acoustic Console (#labM) */
#labM {
  z-index: 60;
  width: 312px;
  max-height: calc(100svh - 86px);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--bg);
  box-shadow: 0 0 0 1px var(--fg), 0 16px 38px rgba(0, 0, 0, 0.24);
  padding: 13px 16px 12px;
  text-align: left;
  line-height: 1.32;
}
#labM[hidden] { display: none; }
#labM small {
  display: block;
  color: var(--dim);
  margin: 0 0 6px;
  white-space: nowrap;
}
#labM hr {
  border: 0;
  border-top: 1px solid var(--hair);
  margin: 9px -16px;
}
.lab-slider-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: var(--ts-sm);
  margin-bottom: 4px;
}
.lab-slider-head output {
  font-family: var(--font-mono);
  font-size: var(--ts-xs);
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.lab-range {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
  margin: 2px 0 4px;
}
.lab-endpoints {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: var(--ts-xs);
  color: var(--dim);
}
.lab-seg {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
}
.lab-seg button {
  min-height: 29px;
  font-family: var(--font-mono);
  font-size: var(--ts-xs);
  border: 1px solid var(--hair);
  transition: background-color 0.16s ease, color 0.16s ease, border-color 0.16s ease;
}
.lab-seg button:hover { border-color: var(--accent); }
.lab-seg button[aria-checked="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.lab-compact-row {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 7px;
}
.lab-mini-seg {
  display: inline-flex;
  border: 1px solid var(--hair);
}
.lab-mini-seg button {
  min-height: 26px;
  padding: 0 6px;
  font-family: var(--font-mono);
  font-size: var(--ts-xs);
  border-right: 1px solid var(--hair);
  transition: background-color 0.14s ease, color 0.14s ease;
}
.lab-mini-seg button:last-child { border-right: 0; }
.lab-mini-seg button:hover { color: var(--accent); }
.lab-mini-seg button[aria-checked="true"] {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.lab-seed-btn {
  margin-left: auto;
  min-width: 28px;
  min-height: 27px;
  padding: 0 7px;
  border: 1px solid var(--hair);
  font-family: var(--font-mono);
  font-size: var(--ts-xs);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.14s ease, color 0.14s ease;
}
.lab-seed-btn:hover { border-color: var(--accent); color: var(--accent); }
.lab-inline-slider {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  margin-top: 7px;
  font-family: var(--font-mono);
  font-size: var(--ts-xs);
  color: var(--dim);
}
.lab-inline-slider input {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
  margin: 0;
}
.lab-inline-slider output {
  color: var(--accent);
  min-width: 2.8em;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.lab-fallback-badge {
  display: inline-block;
  margin-top: 6px;
  padding: 2px 6px;
  border: 1px solid var(--brass);
  color: var(--brass);
  font-family: var(--font-mono);
  font-size: var(--ts-xs);
  letter-spacing: 0.04em;
}
.lab-note {
  margin: 8px 0 0;
  padding-top: 7px;
  border-top: 1px solid var(--hair);
  font-size: var(--ts-xs);
  line-height: 1.44;
  color: var(--dim);
}
.lab-audio-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 34px;
  font-size: 13.5px;
  width: 100%;
  border-bottom: 1px solid transparent;
}
.lab-audio-row:hover { border-bottom-color: var(--accent); }
.lab-audio-row i { font-style: normal; font-family: var(--font-mono); font-size: var(--ts-xs); color: var(--accent); }
.lab-timbres {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 8px;
}
.lab-timbres button {
  padding: 6px 8px;
  text-align: left;
  border: 1px solid var(--hair);
  font-size: var(--ts-sm);
}
.lab-timbres button b { display: block; font-family: var(--font-display); font-weight: 500; }
.lab-timbres button span { font-size: var(--ts-xs); color: var(--dim); }
.lab-timbres button[aria-checked="true"] {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

/* Reading Top Navigation Bar (#via) */
#via {
  left: 0;
  right: 0;
  top: 0;
  z-index: 19;
  height: calc(clamp(14px, 3vh, 28px) + 58px);
  padding: clamp(14px, 3vh, 28px) clamp(180px, 14.5vw, 220px) 0 clamp(176px, 15vw, 224px);
  display: flex;
  align-items: center;
  background: var(--bg);
  box-shadow: 0 1px 0 var(--hair);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.32s ease, visibility 0s 0.32s;
}
body.legens #via {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.32s ease;
}
body.vertens #via,
body.bibl #via,
body.trans #via {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: none;
}
#via ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  gap: 0 clamp(9px, 1.05vw, 20px);
  white-space: nowrap;
}
#via a {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 44px;
  border-bottom: 1.5px solid transparent;
  font-size: 13.5px;
  line-height: 1;
  transition: border-color 0.2s ease, color 0.2s ease;
}
#via a i {
  font-family: var(--font-mono);
  font-style: normal;
  font-size: var(--ts-xs);
  color: var(--dim);
}
#via a b {
  font-family: var(--font-medieval);
  font-weight: 600;
  letter-spacing: 0.03em;
}
#via a .caps {
  font-family: var(--font-medieval);
  font-size: var(--ts-xs);
  letter-spacing: 0.1em;
  color: var(--dim);
}
#via a:hover,
#via a:focus-visible,
#via a[aria-current="true"] {
  border-bottom-color: var(--accent);
  outline: none;
}
#via a[aria-current="true"] b { color: var(--accent); }
@media (max-width: 1760px) { #via a .caps { display: none; } }
@media (max-width: 1360px) {
  #via { padding-left: 192px; padding-right: 176px; }
  #via ul { gap: 0 9px; }
  #via a { font-size: 12.5px; gap: 3px; }
  #via a i { font-size: var(--ts-xs); }
}
@media (max-width: 1220px) { #via a i { display: none; } }

/* Companion Astrolabe Hitbox (#domum) */
#domum {
  display: none;
  border-radius: 50%;
  z-index: 21;
  -webkit-tap-highlight-color: transparent;
}
body.legens #domum { display: block; }
#domum:focus-visible { outline: 1.5px solid var(--accent); outline-offset: 4px; }

/* Mobile Welcome Bottom 2-Column Index (#index) */
.index { display: none; }
.filing-links a + a { margin-inline-start: 0.8em; }
.hud-filing { display: none; }
body[data-type="home"]:not(.legens, .vertens) > .hud-filing {
  display: block;
  position: fixed;
  inset-inline: 12px;
  bottom: 10px;
  z-index: 20;
  text-align: center;
  font-size: var(--ts-xs);
  line-height: 1.4;
  color: rgba(180, 186, 206, 0.56);
  pointer-events: none;
}
.hud-filing a { pointer-events: auto; white-space: nowrap; }
.hud-filing a:is(:hover, :focus-visible) { color: var(--fg); }

/* Mobile Grand Library Browse Entry (hidden on desktop; dynamically created by stage.js) */
.lib-mobile-browse {
  display: none;
}

/* Shelf Catalog Drawer (#catalogus) */
#catalogus {
  z-index: 55;
  width: min(360px, calc(100vw - 28px));
  max-height: min(62vh, 560px);
  overflow: auto;
  overscroll-behavior: contain;
  background: var(--bg);
  box-shadow: 0 0 0 1px var(--fg), 0 18px 40px rgba(0, 0, 0, 0.28);
  padding: 16px 18px 12px;
  line-height: 1.4;
  text-align: left;
  user-select: auto;
  -webkit-user-select: auto;
}
#catalogus[hidden] { display: none; }
#catalogus .cat-tiers { display: none; }
#catalogus small { display: block; color: var(--dim); padding-right: 34px; }
#catalogus h2 { margin: 4px 0 8px; font: 600 var(--t1)/1.3 var(--font-medieval); }
#catalogus ol { list-style: none; margin: 0; padding: 0; }
#catalogus .thema { font: 700 14.5px/1.35 var(--font-body); color: var(--accent); padding: 12px 0 5px; }
#catalogus .genus { font: 500 var(--ts-xs)/1.3 var(--font-mono); letter-spacing: 0.06em; color: var(--dim); padding: 6px 0 4px; }
#catalogus .thema + .genus { padding-top: 0; }
#catalogus a {
  display: grid;
  grid-template-columns: 5.5em 1fr auto;
  gap: 10px;
  align-items: baseline;
  min-height: 40px;
  padding: 7px 0;
  border-top: 1px solid var(--hair);
}
#catalogus a time {
  font: 400 var(--ts-xs) var(--font-mono);
  color: var(--dim);
  white-space: nowrap;
}
#catalogus a b {
  font-weight: 400;
  font-size: var(--ts-md);
  justify-self: start;
  border-bottom: 1px solid transparent;
}
#catalogus a:hover b,
#catalogus a:focus-visible b { border-bottom-color: var(--accent); }
#catalogus .cat-lock {
  font-family: var(--font-mono);
  font-size: var(--ts-xs);
  color: var(--brass);
}
#catalogus .cat-empty {
  padding: 12px 0 8px;
  border-top: 1px solid var(--hair);
  color: var(--dim);
  font-size: 13.5px;
  line-height: 1.65;
}
#catalogus .cat-empty a {
  display: inline-block;
  min-height: auto;
  padding: 0;
  margin-top: 8px;
  border-top: 0;
  color: var(--accent);
  font: 500 12.5px/1.4 var(--font-mono);
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
}
#catalogus .cat-empty a:hover,
#catalogus .cat-empty a:focus-visible {
  border-bottom-color: var(--accent);
}
#catalogus .claudere {
  position: absolute;
  right: 6px;
  top: 4px;
  width: 38px;
  height: 38px;
  font: 400 20px/1 var(--font-display);
  color: var(--dim);
}
#catalogus .claudere:hover { color: var(--accent); }
body.legens #catalogus { display: none; }

/* Password Unlock Modal (#clavW) */
#clavW {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 24px 14px;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(5px);
}
#clavW[hidden] { display: none; }
#clavW .win {
  width: min(440px, 100%);
  background: var(--bg);
  box-shadow: 0 0 0 1px var(--fg), 0 20px 44px rgba(0, 0, 0, 0.28);
}
#clavW header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px 12px 24px;
  border-bottom: 1px solid var(--fg);
}
#clavW header small { color: var(--dim); letter-spacing: 0.24em; }
#clavWx {
  position: relative;
  width: 34px;
  height: 34px;
  margin: -6px -8px -6px 0;
  border-radius: 50%;
  font-size: 0;
}
#clavWx::before, #clavWx::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  top: 50%;
  border-top: 1px solid currentColor;
  transform: rotate(45deg);
}
#clavWx::after { transform: rotate(-45deg); }
#clavWx:hover { box-shadow: inset 0 0 0 1px currentColor; }
#clavW form.clavis {
  display: flex;
  gap: 10px;
  padding: 18px 24px 14px;
}
#clavW form.clavis input[type="password"] {
  flex: 1 1 auto;
  min-width: 0;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--hair);
  background: var(--surface);
  font: inherit;
  font-size: 15px;
  color: inherit;
}
#clavW form.clavis input[type="password"]:focus { outline: none; border-color: var(--accent); }
#clavW form.clavis input[aria-invalid="true"] {
  border-color: var(--brass);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--brass) 25%, transparent);
}
#clavW form.clavis button {
  flex: none;
  height: 42px;
  padding: 0 18px;
  border: 1px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--bg));
  color: var(--accent);
  font-family: var(--font-body);
  font-size: var(--ts-sm);
  font-weight: 500;
  letter-spacing: 0.03em;
  transition: background-color 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}
#clavW form.clavis button:hover,
#clavW form.clavis button:focus-visible {
  background: var(--accent);
  color: var(--accent-ink);
}
#clavW .clavis-err {
  margin: 0;
  padding: 0 24px 16px;
  font-size: var(--ts-xs);
  color: var(--brass);
  min-height: 28px;
}

/* Mobile Responsive (<= 820px) */
@media (max-width: 820px) {
  :root { --t0: 16px; }
  .margo { display: none !important; }
  #reticle-coord { display: none !important; }

  /* Mobile Reading Mode: hide floating bottom-right moon & 3D canvas so prose and footer stay 100% unobstructed; top-left #redi returns to Observatory */
  body.legens #domum { display: none !important; }
  body.legens #cv,
  body.legens #cv-fx { opacity: 0; pointer-events: none; }

  #emblem {
    left: 14px;
    top: 12px;
    gap: 1px;
    max-width: calc(100vw - 196px);
  }
  .emblem-row {
    min-width: 0;
    max-width: 100%;
  }
  .emblem-name {
    font-size: var(--ts-sm);
    letter-spacing: 0.14em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .emblem-name .name-full { display: none; }
  .emblem-name .name-short { display: inline; }
  .emblem-star { width: 10px; height: 10px; }
  .emblem-sub {
    font-size: var(--ts-xs);
    letter-spacing: 0.02em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .emblem-sub .sub-full { display: none; }
  .emblem-sub .sub-short { display: inline; }

  .tools {
    right: 12px;
    top: 12px;
    gap: 6px;
  }
  .tools button,
  .tools a {
    width: 36px;
    height: 36px;
  }
  .tools svg { width: 17px; height: 17px; }
  #lang-btn { font-size: var(--ts-xs); }

  #redi {
    left: 14px;
    top: 10px;
    font-size: 16px;
    min-height: 40px;
  }

  .index {
    display: grid;
    position: fixed;
    z-index: 15;
    left: 16px;
    right: 16px;
    bottom: 14px;
    grid-template-columns: 1fr 1fr;
    gap: 0 14px;
    list-style: none;
    margin: 0;
    padding: 0;
    transition: opacity 0.35s ease;
  }
  .index a {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 42px;
    border-top: 1px solid var(--hair);
    font-family: var(--font-medieval);
    font-weight: 600;
    font-size: 12.5px;
    letter-spacing: 0.03em;
    white-space: nowrap;
    overflow: hidden;
  }
  body[data-type="home"]:has(> .hud-filing) > .index {
    bottom: calc(36px + env(safe-area-inset-bottom));
  }
  body[data-type="home"]:not(.legens, .vertens) > .hud-filing {
    bottom: calc(8px + env(safe-area-inset-bottom));
  }
  .index a i {
    font-family: var(--font-mono);
    font-style: normal;
    font-size: var(--ts-xs);
    color: var(--dim);
    flex: none;
  }
  .index a span {
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .index a[aria-current="true"] { border-top-color: var(--accent); color: var(--accent); }
  body.legens .index,
  body.vertens .index {
    opacity: 0;
    pointer-events: none;
  }

  #via {
    top: calc(12px + 44px);
    height: 42px;
    padding: 0;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    box-shadow: 0 1px 0 var(--hair), 0 -1px 0 var(--hair);
    -webkit-mask-image: linear-gradient(90deg, #000 0%, #000 calc(100% - 28px), transparent 100%);
    mask-image: linear-gradient(90deg, #000 0%, #000 calc(100% - 28px), transparent 100%);
  }
  #via::-webkit-scrollbar { display: none; }
  #via ul { padding: 0 32px 0 16px; gap: 0 18px; }
  #via a { font-size: var(--ts-sm); height: 41px; }
  #via a i { display: inline; }

  body.legens::before {
    content: "";
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    height: 56px;
    background: var(--bg);
    z-index: 18;
  }

  body.legens { padding-bottom: 112px; }

  .lib-mobile-browse {
    display: none;
    position: fixed;
    left: 50%;
    bottom: calc(18px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    z-index: 25;
    align-items: center;
    gap: 8px;
    min-height: 42px;
    padding: 0 18px;
    border-radius: 99px;
    border: 1px solid color-mix(in srgb, var(--accent) 75%, var(--hair));
    background: color-mix(in srgb, var(--bg) 90%, var(--surface));
    backdrop-filter: blur(8px);
    color: var(--fg);
    font-family: var(--font-body);
    font-size: var(--ts-sm);
    font-weight: 500;
    letter-spacing: 0.02em;
    white-space: nowrap;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45), 0 0 0 1px color-mix(in srgb, var(--accent) 18%, transparent);
    transition: border-color 0.18s ease, background-color 0.18s ease, color 0.18s ease;
  }
  .lib-mobile-browse::before {
    content: "▤";
    color: var(--accent);
    font-size: var(--ts-md);
  }
  body.bibl:not(.cat-open) .lib-mobile-browse {
    display: inline-flex;
  }
  .lib-mobile-browse:hover,
  .lib-mobile-browse:focus-visible {
    border-color: var(--accent);
    color: var(--accent);
  }

  #catalogus {
    left: 12px !important;
    right: 12px;
    top: auto !important;
    bottom: 12px;
    width: auto;
    max-height: 60vh;
  }
  #catalogus .cat-tiers {
    display: flex;
    gap: 6px;
    margin: 0 32px 10px 0;
    padding: 2px 0 6px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }
  #catalogus .cat-tiers::-webkit-scrollbar { display: none; }
  #catalogus .cat-tier-pill {
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-height: 30px;
    padding: 0 10px;
    border-radius: 99px;
    border: 1px solid var(--hair);
    background: color-mix(in srgb, var(--surface) 60%, var(--bg));
    color: var(--dim);
    font-family: var(--font-body);
    font-size: var(--ts-xs);
    white-space: nowrap;
    transition: border-color 0.16s ease, color 0.16s ease, background-color 0.16s ease;
  }
  #catalogus .cat-tier-pill i {
    font-style: normal;
    font-family: var(--font-mono);
    color: var(--brass);
  }
  #catalogus .cat-tier-pill.is-active,
  #catalogus .cat-tier-pill[aria-pressed="true"] {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 16%, var(--bg));
    color: var(--accent);
    font-weight: 600;
  }
  #catalogus .cat-tier-pill.is-active i,
  #catalogus .cat-tier-pill[aria-pressed="true"] i {
    color: var(--accent);
  }
}

/* WordPress Admin Bar Offset (prevents #wpadminbar overlap when logged in) */
@media (min-width: 821px) {
  body.admin-bar #emblem { top: calc(clamp(16px, 3vh, 30px) + 32px); }
  body.admin-bar #redi { top: calc(clamp(14px, 3vh, 28px) + 32px); }
  body.admin-bar .tools { top: calc(clamp(14px, 3vh, 28px) + 32px); }
  body.admin-bar #via { top: 32px; }
  body.admin-bar #clock { top: calc(clamp(14px, 3vh, 28px) + 96px); }
  body.admin-bar main#lectio { padding-top: calc(15vh + 32px); }
}
@media (min-width: 783px) and (max-width: 820px) {
  body.admin-bar #emblem { top: 44px; }
  body.admin-bar #redi { top: 42px; }
  body.admin-bar .tools { top: 44px; }
  body.admin-bar #via { top: calc(12px + 44px + 32px); }
  body.admin-bar.legens::before { top: 32px; }
  body.admin-bar main#lectio { padding-top: 144px; }
}
@media (max-width: 782px) {
  body.admin-bar #emblem { top: 58px; }
  body.admin-bar #redi { top: 56px; }
  body.admin-bar .tools { top: 58px; }
  body.admin-bar #via { top: calc(12px + 44px + 46px); }
  body.admin-bar.legens::before { top: 46px; }
  body.admin-bar main#lectio { padding-top: 158px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

@media print {
  body.legens::after,
  .lib-mobile-browse {
    display: none !important;
  }
}

html, body * {
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--fg) 38%, transparent) transparent;
}
