/* ═══════════════════════════════════════════════
   THE LOREBOOK COMPENDIUM — SHARED STYLES
   aceenvw
   ═══════════════════════════════════════════════ */

/* ═══ 1. RESET ═══ */

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

/* ═══ 2. THEME TOKENS ═══ */

:root {
  /* surfaces */
  --bg:             #f7f4ec;
  --bg-surface:     #efeade;
  --bg-elevated:    #fffdf7;

  /* text */
  --text:           #191713;
  --text-secondary: #544e44;
  /* clears AA (4.5:1) on every surface token, including --bg-surface */
  --text-dim:       #6e6659;

  /* lines */
  --border:         #e0d8c6;
  --border-hover:   #cabfa6;

  /* accents */
  --accent:         #a4522c;
  --accent-hover:   #8b421f;
  --accent-faint:   rgba(164, 82, 44, 0.07);
  --accent-line:    rgba(164, 82, 44, 0.20);
  --accent-2:       #3f6b4a;

  /* semantic */
  --ok:             #3f6b4a;
  --ok-faint:       rgba(63, 107, 74, 0.08);
  --warn:           #9a6a1e;
  --warn-faint:     rgba(154, 106, 30, 0.09);
  --bad:            #9c3b30;
  --bad-faint:      rgba(156, 59, 48, 0.08);

  /* code */
  --code-bg:        #f1ece0;
  --code-text:      #2a2620;
  --code-border:    #e2dac8;

  /* type */
  --font-display:   'EB Garamond', Georgia, serif;
  --font-body:      'Inter', system-ui, -apple-system, sans-serif;
  --font-mono:      'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  /* metrics */
  --nav-height:     56px;
  --max-content:    760px;
  --max-wide:       1140px;
  --radius-sm:      6px;
  --radius-md:      8px;
  --radius-lg:      12px;
  --radius-pill:    20px;

  --shadow-soft:    0 1px 2px rgba(25, 23, 19, .04), 0 12px 28px -18px rgba(25, 23, 19, .22);
}

[data-theme="dark"] {
  --bg:             #14130f;
  --bg-surface:     #1c1a15;
  --bg-elevated:    #24211a;

  --text:           #e9e4d8;
  --text-secondary: #b0a795;
  /* clears AA (4.5:1) on every surface token, including --bg-elevated */
  --text-dim:       #968d7c;

  --border:         #2e2a22;
  --border-hover:   #423c31;

  --accent:         #d98a5c;
  --accent-hover:   #eda173;
  --accent-faint:   rgba(217, 138, 92, 0.09);
  --accent-line:    rgba(217, 138, 92, 0.24);
  --accent-2:       #6fa87d;

  --ok:             #6fa87d;
  --ok-faint:       rgba(111, 168, 125, 0.10);
  --warn:           #cfa257;
  --warn-faint:     rgba(207, 162, 87, 0.11);
  --bad:            #d97a6c;
  --bad-faint:      rgba(217, 122, 108, 0.10);

  --code-bg:        #1a1814;
  --code-text:      #d8d1c2;
  --code-border:    #302b23;

  --shadow-soft:    0 1px 2px rgba(0, 0, 0, .3), 0 12px 28px -18px rgba(0, 0, 0, .7);
}

/* ═══ 3. BASE ═══ */

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--nav-height) + 60px);
  scrollbar-width: thin;
  scrollbar-color: var(--border) var(--bg);
}
html::-webkit-scrollbar { width: 5px; }
html::-webkit-scrollbar-track { background: var(--bg); }
html::-webkit-scrollbar-thumb { background: var(--border); }

body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: inherit; text-decoration: none; }
img, svg { max-width: 100%; }
button { font-family: inherit; }

::selection { background: var(--accent); color: #fff; }
[data-theme="dark"] ::selection { color: #14130f; }

:where(a, button, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.sr-only:focus {
  position: fixed;
  top: 8px; left: 8px;
  width: auto; height: auto;
  margin: 0; padding: 10px 16px;
  clip: auto;
  z-index: 200;
  background: var(--bg-elevated);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
}

/* paper grain */
body::after {
  content: '';
  position: fixed;
  top: -50%; left: -50%;
  width: 200%; height: 200%;
  pointer-events: none;
  z-index: 1;
  opacity: 0.022;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 512 512' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

@media (max-width: 768px), (prefers-reduced-motion: reduce) {
  body::after { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* ═══ 4. TYPOGRAPHY ═══ */

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 500;
  line-height: 1.15;
  color: var(--text);
}

.t-display {
  font-family: var(--font-display);
  font-size: clamp(2.8rem, 7vw, 5.2rem);
  font-weight: 400;
  line-height: 0.95;
  letter-spacing: -0.025em;
}

.t-display em {
  font-style: italic;
  color: var(--accent);
}

.t-kicker,
.footnote,
.footnote-mark {
  font-family: var(--font-mono);
  font-weight: 500;
}

.t-kicker {
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
}

.prose h2 {
  font-size: clamp(1.9rem, 3.6vw, 2.5rem);
  margin: 0 0 0.4rem;
  letter-spacing: -0.015em;
}

.prose section { margin-bottom: 5.5rem; }
.prose section:last-of-type { margin-bottom: 0; }

/* first paragraph after a section rule gets room to breathe */
.prose .rule + p { margin-top: 1.35rem; }

.prose h3 {
  font-size: 1.35rem;
  margin: 3rem 0 0.6rem;
  color: var(--text);
}

.prose h3:first-child { margin-top: 0; }

.prose h4,
.prose h3.h-label {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 2.25rem 0 0.6rem;
}

.prose p {
  margin: 0.85rem 0;
  color: var(--text-secondary);
}

.prose p strong { color: var(--text); font-weight: 600; }
.prose p em { color: var(--text); font-style: italic; }

.prose li { margin: 0.35rem 0; }
.prose li strong { color: var(--text); font-weight: 600; }

.prose a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: color .2s;
}

.prose a:hover { color: var(--accent-hover); }

.rule {
  height: 1px;
  border: 0;
  background: linear-gradient(90deg, var(--border), transparent);
  margin: 0.6rem 0 1.75rem;
}

code { font-family: var(--font-mono); }

.footnote,
.footnote-mark {
  color: var(--text-dim);
}

.footnote {
  font-size: 0.75rem;
  line-height: 1.5;
}

.footnote a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.footnote a:hover { color: var(--accent-hover); }

.footnote-mark { font-size: 0.65em; }

.prose :not(pre) > code {
  font-size: 0.85em;
  background: var(--code-bg);
  color: var(--code-text);
  padding: 0.15em 0.4em;
  border: 1px solid var(--code-border);
  border-radius: var(--radius-sm);
  word-break: break-word;
}

/* ═══ 5. LAYOUT ═══ */

.container {
  max-width: var(--max-wide);
  margin: 0 auto;
  padding: 0 32px;
}

.container--narrow { max-width: var(--max-content); }

.page-content {
  padding-top: var(--nav-height);
  position: relative;
  z-index: 3;
}

.page-header {
  padding: 4.5rem 0 2.5rem;
  border-bottom: 1px solid var(--border);
}

.page-header .t-kicker { display: block; margin-bottom: 1.1rem; }

.page-header--characters > .container { max-width: var(--max-content); }

.page-header-actions { margin-top: 1.15rem; }

.page-title {
  font-size: clamp(2.4rem, 5.5vw, 4rem);
  font-weight: 400;
  line-height: 0.98;
  letter-spacing: -0.03em;
  margin-bottom: 1.1rem;
}

.page-lead {
  max-width: 62ch;
  font-size: 1.08rem;
  line-height: 1.7;
  color: var(--text-secondary);
}

.page-body { padding: 3rem 0 5rem; }

section[id] { scroll-margin-top: calc(var(--nav-height) + 64px); }

@media (max-width: 700px) {
  .container { padding: 0 20px; }
  .page-header { padding: 3rem 0 2rem; }
  .page-body { padding: 2.25rem 0 3.5rem; }
}

/* ═══ 6. NAVIGATION ═══ */

.nav {
  position: fixed;
  top: 0; left: 0;
  width: 100%;
  z-index: 100;
  height: var(--nav-height);
  padding: 0 32px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.nav-logo { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }

.nav-logo-icon { width: 20px; height: 20px; color: var(--accent); }

.nav-logo-text {
  font-family: var(--font-display);
  font-size: 19px;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.nav-center {
  display: flex;
  align-items: center;
  gap: 12px;
  white-space: nowrap;
}

.nav-link {
  min-height: 44px;
  padding: 0 4px;
  display: inline-flex;
  align-items: center;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  letter-spacing: 0.2px;
  transition: color .2s;
  position: relative;
}

.nav-link:hover, .nav-link.active { color: var(--text); }

.nav-link.active::after {
  content: '';
  position: absolute;
  bottom: 10px; left: 4px; right: 4px;
  height: 1px;
  background: var(--accent);
}

.nav-right { display: flex; align-items: center; gap: 12px; flex: 0 0 auto; }

.nav-author {
  font-size: 12px;
  color: var(--text-dim);
  letter-spacing: .4px;
  transition: color .2s;
}
.nav-author:hover { color: var(--accent); }

.icon-btn {
  width: 44px; height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0;
  transition: border-color .2s, color .2s;
}
.icon-btn:hover { border-color: var(--border-hover); color: var(--text); }

.icon-btn svg { width: 16px; height: 16px; }

.theme-toggle .icon-sun { display: block; }
.theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: block; }

.lang-toggle {
  width: auto;
  min-width: 44px;
  padding: 0 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: .1em;
}

.nav-burger {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 44px; height: 44px;
  padding: 8px;
  background: none;
  border: none;
  cursor: pointer;
}

.nav-burger span {
  display: block;
  width: 20px; height: 1.5px;
  background: var(--text);
  transition: transform .3s, opacity .3s;
}

.nav-burger[aria-expanded="true"] span:nth-child(1) { transform: translateY(6.5px) rotate(45deg); }
.nav-burger[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.nav-burger[aria-expanded="true"] span:nth-child(3) { transform: translateY(-6.5px) rotate(-45deg); }

.nav-mobile {
  display: none;
  position: fixed;
  top: var(--nav-height);
  left: 0; right: 0;
  z-index: 99;
  flex-direction: column;
  gap: 0;
  padding: 12px 20px 20px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  max-height: calc(100dvh - var(--nav-height));
  overflow-y: auto;
  overscroll-behavior: contain;
}

.nav-mobile a {
  display: flex;
  align-items: center;
  min-height: 46px;
  font-size: 15px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  transition: color .2s;
}
.nav-mobile a:last-child { border-bottom: 0; }
.nav-mobile a:hover, .nav-mobile a.active { color: var(--accent); }

@media (max-width: 1200px) { .nav-author { display: none; } }

@media (min-width: 861px) and (max-width: 1100px) {
  :root { --nav-height: 100px; }
  .nav {
    height: var(--nav-height);
    padding: 0 24px;
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-rows: 56px 44px;
  }
  .nav-logo  { grid-column: 1; grid-row: 1; }
  .nav-right { grid-column: 3; grid-row: 1; }
  .nav-center {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%; height: 44px;
    justify-content: flex-start;
    gap: 8px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    border-top: 1px solid var(--border);
  }
  .nav-center::-webkit-scrollbar { display: none; }
  .nav-link { flex: 0 0 auto; padding: 0 8px; }
}

@media (max-width: 860px) {
  .nav { padding: 0 20px; }
  .nav-center { display: none; }
  .nav-burger { display: flex; }
  .nav-mobile.open { display: flex; }
}

@media (max-width: 480px) {
  .nav-logo-text { display: none; }
}

/* ═══ 7. SECTION INDEX ═══ */

.section-index {
  position: sticky;
  top: var(--nav-height);
  z-index: 60;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
}

.section-index-inner {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 48px;
  overflow-x: auto;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
}
.section-index-inner::-webkit-scrollbar { display: none; }

.section-index-label {
  flex: 0 0 auto;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding-right: 0.75rem;
  margin-right: 0.25rem;
  border-right: 1px solid var(--border);
}

.section-index a {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 0.6rem;
  font-size: 0.82rem;
  color: var(--text-dim);
  white-space: nowrap;
  transition: color .2s;
}

.section-index a:hover { color: var(--accent); }

@media (max-width: 700px) {
  .section-index-label { display: none; }
}

/* ═══ 8. SHARED COMPONENTS ═══ */

/* ─── callout ─── */
.callout {
  margin: 1.5rem 0;
  padding: 1.05rem 1.25rem;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-md);
  background: var(--accent-faint);
  font-size: 0.95rem;
  color: var(--text-secondary);
}

.callout > :first-child { margin-top: 0; }
.callout > :last-child { margin-bottom: 0; }
.callout p { margin: 0.5rem 0; color: inherit; }
.callout strong { color: var(--text); font-weight: 600; }

.callout-title {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.66rem;
  font-weight: 500;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.45rem;
}

.callout--warn { border-left-color: var(--warn); background: var(--warn-faint); }
.callout--warn .callout-title { color: var(--warn); }

.callout--ok { border-left-color: var(--ok); background: var(--ok-faint); }
.callout--ok .callout-title { color: var(--ok); }

.callout--bad { border-left-color: var(--bad); background: var(--bad-faint); }
.callout--bad .callout-title { color: var(--bad); }

.callout--quiet {
  border-left-color: var(--border-hover);
  background: var(--bg-surface);
}
.callout--quiet .callout-title { color: var(--text-dim); }

/* ─── compare (do / don't) ─── */
.compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin: 1.5rem 0;
}

.compare-col {
  padding: 1.1rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
}

.compare-col .compare-head {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin: 0 0 0.6rem;
}

.compare-col--do    { border-top: 2px solid var(--ok); }
.compare-col--do .compare-head { color: var(--ok); }
.compare-col--dont    { border-top: 2px solid var(--bad); }
.compare-col--dont .compare-head { color: var(--bad); }

.compare-col ul { list-style: none; margin: 0; padding: 0; }

.compare-col li {
  position: relative;
  padding: 0.4rem 0 0.4rem 1.4rem;
  font-size: 0.92rem;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}
.compare-col li:last-child { border-bottom: 0; }

.compare-col li::before {
  position: absolute;
  left: 0; top: 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
}
.compare-col--do   li::before { content: '+'; color: var(--ok); }
.compare-col--dont li::before { content: '−'; color: var(--bad); }

@media (max-width: 700px) {
  .compare { grid-template-columns: 1fr; }
}

/* ─── numbered path ─── */
.path {
  counter-reset: step;
  margin: 2rem 0 0;
  padding: 0;
  list-style: none;
}

.path li {
  counter-increment: step;
  position: relative;
  padding: 0.6rem 0 0.6rem 2.6rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.path li:last-child { border-bottom: 0; }

.path li::before {
  content: counter(step, decimal-leading-zero);
  position: absolute;
  left: 0;
  top: 0.7rem;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  color: var(--accent);
}

.path li a { color: var(--text); font-weight: 500; }
.path li a:hover { color: var(--accent); }

/* ─── chips ─── */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--bg-surface);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  white-space: nowrap;
}

.chip .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent-2);
  flex: 0 0 auto;
}
.chip--warm .dot { background: var(--accent); }

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 1.25rem 0;
}

/* ─── code blocks ─── */
.codeblock {
  position: relative;
  margin: 1.1rem 0;
  border: 1px solid var(--code-border);
  border-radius: var(--radius-md);
  background: var(--code-bg);
  overflow: hidden;
}

.codeblock-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0.5rem 0.75rem 0.5rem 1rem;
  border-bottom: 1px solid var(--code-border);
  background: var(--bg-surface);
  font-family: var(--font-mono);
  font-size: 0.64rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.codeblock pre {
  margin: 0;
  padding: 1rem;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.84rem;
  line-height: 1.65;
  color: var(--code-text);
  tab-size: 2;
}

.codeblock code { font-family: inherit; background: none; border: 0; padding: 0; }

.copy-btn {
  flex: 0 0 auto;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color .2s, border-color .2s;
}
.copy-btn:hover { color: var(--accent); border-color: var(--accent-line); }
.copy-btn[data-copied="true"] { color: var(--ok); border-color: var(--ok); }

/* ─── toast ─── */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 16px);
  z-index: 300;
  padding: 10px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 0.85rem;
  box-shadow: var(--shadow-soft);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
body[data-build] .toast.visible { opacity: 1; transform: translate(-50%, 0); }

/* ─── tables ─── */
.table-wrap {
  margin: 1.5rem 0;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
}

.table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  min-width: 520px;
}

.table-wrap th {
  text-align: left;
  padding: 0.7rem 1rem;
  font-family: var(--font-mono);
  font-size: 0.64rem;
  font-weight: 500;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--text-dim);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table-wrap td {
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  vertical-align: top;
}

.table-wrap tr:last-child td { border-bottom: 0; }
.table-wrap td strong { color: var(--text); font-weight: 600; }
.table-wrap td code {
  font-size: 0.82em;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: var(--radius-sm);
  padding: 0.1em 0.35em;
  color: var(--code-text);
  white-space: nowrap;
}

.table-wrap td .none { color: var(--text-dim); font-style: italic; }

/* ─── accordion ─── */
.accordion { margin: 1.5rem 0; display: flex; flex-direction: column; gap: 0.6rem; }

.acc-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  overflow: hidden;
}

.acc-item summary {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1.1rem;
  min-height: 48px;
  cursor: pointer;
  list-style: none;
  font-weight: 500;
  color: var(--text);
  font-size: 0.97rem;
}

.acc-item summary::-webkit-details-marker { display: none; }

.acc-item summary::before {
  content: '+';
  flex: 0 0 auto;
  font-family: var(--font-mono);
  font-size: 1rem;
  line-height: 1;
  color: var(--accent);
}
.acc-item[open] summary::before { content: '−'; }

.acc-body {
  padding: 0 1.1rem 1.1rem;
  font-size: 0.93rem;
  color: var(--text-secondary);
}
.acc-body p { margin: 0.6rem 0; color: inherit; }
.acc-body strong { color: var(--text); }

.acc-fix {
  margin-top: 0.85rem;
  padding: 0.75rem 0.9rem;
  border-left: 2px solid var(--ok);
  background: var(--ok-faint);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.acc-fix strong { color: var(--ok); }

/* ─── changed grid ─── */
.changed-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 1rem;
  margin: 2.25rem 0 0;
}

.changed {
  padding: 1.1rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
}

.changed .then,
.changed .now {
  display: block;
  font-size: 0.92rem;
  line-height: 1.5;
}

.changed .then {
  color: var(--text-dim);
  text-decoration: line-through;
  text-decoration-color: var(--border-hover);
  margin-bottom: 0.45rem;
}

.changed .now { color: var(--text); font-weight: 500; }

.changed .tagline {
  display: block;
  margin-top: 0.6rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* ─── card grid ─── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  margin: 2rem 0;
}

.chapter-card {
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1.35rem 1.35rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  transition: border-color .2s, transform .2s;
}

.prose a.chapter-card { text-decoration: none; }

a.chapter-card:hover {
  border-color: var(--accent-line);
  transform: translateY(-2px);
}

.chapter-card .num {
  font-family: var(--font-mono);
  font-size: 0.64rem;
  letter-spacing: 0.16em;
  color: var(--accent);
  margin-bottom: 0.6rem;
}

.chapter-card h3 {
  font-size: 1.2rem;
  margin: 0 0 0.4rem;
}

.chapter-card p {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text-secondary);
}

.chapter-card .go {
  margin-top: 0.85rem;
  font-family: var(--font-mono);
  font-size: 0.66rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

/* ─── definition list ─── */
.glossary {
  margin: 1.5rem 0;
  border-top: 1px solid var(--border);
}

.glossary dt {
  font-family: var(--font-display);
  font-size: 1.08rem;
  font-weight: 600;
  color: var(--text);
  margin-top: 1.1rem;
}

.glossary dd {
  margin: 0.25rem 0 1.1rem;
  padding-bottom: 1.1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.94rem;
}

.glossary dd:last-child { border-bottom: 0; }

/* ═══ 9. PAGER ═══ */

.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}

.pager a {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 1rem 1.2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  transition: border-color .2s, transform .2s;
}

.pager a:hover { border-color: var(--accent-line); transform: translateY(-2px); }

.pager .dir {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.pager .name {
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: var(--text);
}

.pager .next { text-align: right; }
.pager .spacer { border: 0; background: none; }

@media (max-width: 560px) {
  .pager { grid-template-columns: 1fr; }
  .pager .next { text-align: left; }
}

/* ═══ 10. CHARACTERS ═══ */

.character-rails {
  display: none;
  position: sticky;
  top: var(--nav-height);
  z-index: 4;
  height: 0;
  pointer-events: none;
}

.character-rail {
  position: absolute;
  top: 60px;
  z-index: 4;
  width: clamp(44px, calc((100vw - var(--max-content)) / 2 - 8px), 220px);
  pointer-events: auto;
}

.character-rail--left { left: 4px; }
.character-rail--right { right: 4px; }

.character-card {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-soft);
}

.character-card img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
  background: var(--bg-surface);
}

.character-card-open {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  cursor: pointer;
}

.character-card-open img {
  transition: filter .2s;
}

.character-card-open:hover img {
  filter: saturate(1.05);
}

.character-card-caption {
  padding: 0.7rem 0.75rem 0.75rem;
  border-top: 1px solid var(--border);
  text-align: center;
}

.character-card-caption strong,
.character-card-caption small {
  display: block;
}

.character-card-caption strong {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.15;
  color: var(--text);
}

.character-card-caption small {
  margin-top: 0.3rem;
  font-family: var(--font-mono);
  font-size: 0.55rem;
  line-height: 1.4;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}

.character-card-caption code {
  font: inherit;
  color: var(--accent);
}

.character-gallery-trigger {
  min-height: 44px;
  padding: 0.45rem 0.8rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-hover);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.66rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color .2s, color .2s, background .2s;
}

.character-gallery-trigger:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-faint);
}

.character-gallery {
  width: min(980px, calc(100% - 24px));
  height: min(900px, calc(100dvh - 24px));
  max-height: none;
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border-hover);
  border-radius: var(--radius-lg);
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .35);
}

.character-gallery[open] {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.character-gallery::backdrop {
  background: rgba(15, 13, 10, .72);
  backdrop-filter: blur(5px);
}

.character-gallery-header {
  position: relative;
  z-index: 2;
  min-height: 64px;
  padding: 0.85rem 0.9rem 0.85rem 1.1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: blur(12px);
}

.character-gallery-header h2 {
  font-size: clamp(1.25rem, 3vw, 1.65rem);
  line-height: 1.1;
}

.character-gallery-close {
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.character-gallery-close:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.character-gallery-grid {
  min-height: 0;
  width: 100%;
  padding: 1rem;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-auto-rows: max-content;
  align-content: start;
  gap: 0.9rem;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.character-gallery-grid .character-card {
  min-width: 0;
}

@media (min-width: 861px) {
  .character-rails { display: block; }
}

@media (min-width: 861px) and (max-width: 1040px) {
  .character-card--rail .character-card-caption { display: none; }
}

@media (max-width: 800px) {
  .character-gallery-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  .character-gallery {
    width: min(420px, calc(100% - 16px));
    height: calc(100dvh - 16px);
  }

  .character-gallery-header {
    min-height: 56px;
    padding: 0.65rem 0.7rem 0.65rem 0.85rem;
  }

  .character-gallery-header h2 { font-size: 1.05rem; }

  .character-gallery-grid {
    padding: 0.65rem;
    grid-template-columns: repeat(2, 118px);
    justify-content: center;
    gap: 0.6rem;
  }

  .character-gallery-grid .character-card-caption {
    padding: 0.55rem 0.4rem 0.6rem;
  }

  .character-gallery-grid .character-card-caption strong { font-size: 0.86rem; }
  .character-gallery-grid .character-card-caption small {
    font-size: 0.65rem;
    letter-spacing: 0.03em;
  }
}

@media (pointer: coarse) {
  .copy-btn { min-width: 44px; min-height: 44px; }
}

/* ═══ 10. FOOTER ═══ */

.footer {
  position: relative;
  z-index: 2;
  padding: 4rem 32px 3rem;
  text-align: center;
  border-top: 1px solid var(--border);
}

.footer-clover {
  width: 42px; height: 42px;
  margin: 0 auto 1.1rem;
  color: var(--accent);
  opacity: 0.28;
}

.footer-title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: var(--text);
  margin-bottom: 0.4rem;
}

.footer-text {
  font-size: 0.78rem;
  color: var(--text-dim);
  letter-spacing: 0.3px;
}

.footer-text a { color: var(--text-secondary); transition: color .2s; }
.footer-text a:hover { color: var(--accent); }

.footer-meta {
  margin-top: 1.25rem;
  font-family: var(--font-mono);
  font-size: 0.64rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.footer-meta a { color: var(--text-dim); transition: color .2s; }
.footer-meta a:hover { color: var(--accent); }

/* ═══ 11. I18N ═══ */

/* Russian markup is inserted as a sibling span. A block only switches when a
   translation actually exists, so partial coverage falls back to English
   instead of rendering blank. */

[data-lang="ru"] .i18n:has(> .lang-ru) > .lang-en { display: none; }
[data-lang="ru"] .i18n:has(> .lang-ru) > .lang-ru { display: inline; }

.i18n > .lang-ru { display: none; }

/* block-level variants keep their own display mode */
[data-lang="ru"] .i18n--block:has(> .lang-ru) > .lang-ru { display: block; }
