/* =========================================================
   BPhO Bilingual Handbook — visual system
   ========================================================= */

:root {
  --navy: #0b1220;
  --navy-2: #111d34;
  --navy-3: #17233d;
  --gold: #c9a227;
  --gold-2: #e3c05a;
  --gold-soft: #fbf3d9;
  --paper: #f5f1e8;
  --paper-2: #efe9dc;
  --card: #ffffff;
  --ink: #1d2533;
  --ink-2: #334155;
  --muted: #6b7280;
  --muted-2: #94a3b8;
  --line: #e6dfd0;
  --line-2: #d8cfbc;
  --blue: #1d4ed8;
  --blue-soft: #eef4ff;
  --red: #b42318;
  --red-soft: #fef3f2;
  --green: #047857;
  --green-soft: #ecfdf5;
  --purple: #6d28d9;
  --purple-soft: #f5f3ff;
  --sidebar-w: 306px;
  --content-max: 940px;
  --radius: 16px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow-md: 0 12px 30px -18px rgba(15, 23, 42, .35);
  --shadow-lg: 0 30px 70px -40px rgba(15, 23, 42, .45);
  --font-sans: "Noto Sans SC", "Source Sans 3", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-serif: "Noto Serif SC", "Source Serif 4", Georgia, serif;
  --font-en: "Source Serif 4", Georgia, "Times New Roman", serif;
  --font-mono: "JetBrains Mono", "Fira Code", Consolas, monospace;
}

[data-theme="dark"] {
  --paper: #0f1726;
  --paper-2: #131e30;
  --card: #162134;
  --ink: #e8edf6;
  --ink-2: #c7d2e3;
  --muted: #93a0b5;
  --muted-2: #6c7a90;
  --line: #253249;
  --line-2: #31405a;
  --blue-soft: #172a50;
  --red-soft: #3a1d1d;
  --green-soft: #12352c;
  --purple-soft: #2a2148;
  --gold-soft: #3a3115;
  --shadow-md: 0 12px 30px -18px rgba(0, 0, 0, .65);
  --shadow-lg: 0 30px 70px -40px rgba(0, 0, 0, .8);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--paper);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.82;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection { background: rgba(201, 162, 39, .28); }

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  z-index: 60;
  display: flex;
  flex-direction: column;
  color: #dbe4f4;
  background:
    radial-gradient(1200px 500px at -10% -10%, rgba(201, 162, 39, .14), transparent 60%),
    linear-gradient(180deg, var(--navy) 0%, #0d1729 55%, #0a1220 100%);
  border-right: 1px solid rgba(255, 255, 255, .07);
  transition: transform .28s ease;
}

.sidebar-brand {
  padding: 22px 22px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.sidebar-brand img {
  height: 34px;
  width: auto;
  display: block;
  margin-bottom: 14px;
  opacity: .96;
}
.sidebar-brand img.aurora-logo {
  height: 48px;
  margin-bottom: 12px;
}
.brand-kicker {
  font-size: .64rem;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--gold-2);
  font-weight: 700;
}
.brand-title {
  margin-top: 4px;
  font-family: var(--font-serif);
  font-size: 1.16rem;
  font-weight: 700;
  color: #f5f7fb;
  letter-spacing: .01em;
}
.brand-sub {
  margin-top: 5px;
  font-size: .72rem;
  color: #8fa0bb;
  letter-spacing: .02em;
}

.sidebar-progress {
  padding: 15px 22px 13px;
  border-bottom: 1px solid rgba(255, 255, 255, .07);
}
.progress-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: .7rem;
  color: #9fb0ca;
  letter-spacing: .04em;
  margin-bottom: 7px;
}
.progress-label strong { color: var(--gold-2); font-weight: 700; }
.progress-track {
  height: 5px;
  border-radius: 99px;
  background: rgba(255, 255, 255, .1);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #b8891c, var(--gold-2));
  transition: width .35s ease;
}

.sidebar-search {
  padding: 14px 18px 10px;
}
.search-box {
  position: relative;
  display: flex;
  align-items: center;
}
.search-box svg {
  position: absolute;
  left: 11px;
  width: 15px;
  height: 15px;
  color: #7f90ac;
  pointer-events: none;
}
.search-box input {
  width: 100%;
  padding: 9px 12px 9px 34px;
  border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, .11);
  background: rgba(255, 255, 255, .055);
  color: #eaf0fa;
  font-family: var(--font-sans);
  font-size: .78rem;
  outline: none;
  transition: border-color .2s, background .2s, box-shadow .2s;
}
.search-box input::placeholder { color: #7f90ac; }
.search-box input:focus {
  border-color: rgba(201, 162, 39, .65);
  background: rgba(255, 255, 255, .08);
  box-shadow: 0 0 0 3px rgba(201, 162, 39, .13);
}

.toc {
  flex: 1;
  overflow-y: auto;
  padding: 6px 12px 24px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.16) transparent;
}
.toc::-webkit-scrollbar { width: 6px; }
.toc::-webkit-scrollbar-thumb { background: rgba(255,255,255,.14); border-radius: 99px; }

.toc-part {
  margin: 18px 10px 7px;
  font-size: .62rem;
  font-weight: 800;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: #7183a1;
}
.toc-item {
  display: flex;
  gap: 11px;
  align-items: flex-start;
  width: 100%;
  padding: 9px 10px;
  margin-bottom: 2px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: #c5d0e2;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  transition: background .18s, color .18s;
}
.toc-item:hover { background: rgba(255, 255, 255, .055); color: #fff; }
.toc-item.active {
  background: linear-gradient(90deg, rgba(201, 162, 39, .18), rgba(201, 162, 39, .05));
  color: #fff;
  box-shadow: inset 2px 0 0 var(--gold);
}
.toc-num {
  flex: 0 0 26px;
  height: 26px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  font-size: .68rem;
  font-weight: 800;
  color: #93a5c0;
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(255, 255, 255, .07);
  margin-top: 1px;
}
.toc-item.active .toc-num {
  color: #1a2333;
  background: var(--gold-2);
  border-color: var(--gold-2);
}
.toc-text { min-width: 0; }
.toc-title {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  line-height: 1.45;
  color: inherit;
}
.toc-en {
  display: block;
  margin-top: 1px;
  font-family: var(--font-en);
  font-size: .68rem;
  color: #7f90ac;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toc-item.active .toc-en { color: #c9b46a; }
.toc-check {
  margin-left: auto;
  color: var(--gold-2);
  font-size: .75rem;
  opacity: 0;
  flex: 0 0 auto;
}
.toc-item.done .toc-check { opacity: 1; }

.search-results {
  padding: 4px 4px 10px;
}
.search-results-label {
  padding: 8px 8px 6px;
  font-size: .62rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: #7183a1;
  font-weight: 800;
}
.search-result {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: #c5d0e2;
  padding: 8px 9px;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
}
.search-result:hover { background: rgba(255,255,255,.06); color: #fff; }
.search-result .sr-ch {
  display: block;
  font-size: .63rem;
  color: #8fa0bb;
  margin-bottom: 1px;
}
.search-result .sr-title {
  display: block;
  font-size: .78rem;
  font-weight: 600;
}
.search-empty {
  padding: 16px 10px;
  color: #7f90ac;
  font-size: .76rem;
  text-align: center;
}

.sidebar-footer {
  padding: 13px 20px 16px;
  border-top: 1px solid rgba(255, 255, 255, .08);
  font-size: .66rem;
  color: #7183a1;
  line-height: 1.6;
}
.sidebar-footer a {
  color: #b9c6da;
  text-decoration: none;
}
.sidebar-footer a:hover { color: var(--gold-2); }

/* ---------- Main ---------- */
.main-wrap {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: 58px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 28px;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 75%, transparent);
}
.breadcrumb {
  min-width: 0;
  font-size: .76rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.breadcrumb strong { color: var(--ink); font-weight: 600; }
.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
}
.icon-btn {
  width: 34px;
  height: 34px;
  border: 1px solid transparent;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background .18s, color .18s, border-color .18s;
}
.icon-btn:hover {
  color: var(--ink);
  background: color-mix(in srgb, var(--card) 70%, transparent);
  border-color: var(--line);
}
.icon-btn svg { width: 17px; height: 17px; }

/* 明暗主题切换：图标 + 文字，移动端收成图标 */
.theme-toggle {
  width: auto;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 12px 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--card) 55%, transparent);
  color: var(--ink-2);
  font-family: var(--font-sans);
  font-size: .74rem;
  font-weight: 600;
  line-height: 1;
  letter-spacing: .02em;
  white-space: nowrap;
  cursor: pointer;
  transition: background .18s, color .18s, border-color .18s, box-shadow .18s;
}
.theme-toggle:hover {
  color: var(--ink);
  background: var(--card);
  border-color: var(--gold);
  box-shadow: 0 4px 14px -8px rgba(15, 23, 42, .35);
}
.theme-toggle svg { width: 15px; height: 15px; flex: none; }
.theme-toggle:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.theme-toggle .theme-label { line-height: 1; }

@media (max-width: 640px) {
  .theme-toggle {
    width: 34px;
    padding: 0;
    border-color: transparent;
    background: transparent;
  }
  .theme-toggle .theme-label { display: none; }
}

.mobile-only { display: none; }

.content {
  flex: 1;
  width: 100%;
  padding: 40px 30px 56px;
}
.chapter {
  max-width: var(--content-max);
  margin: 0 auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.chapter-head {
  position: relative;
  padding: 52px 58px 38px;
  border-bottom: 1px solid var(--line);
  background:
    radial-gradient(700px 280px at 100% -20%, rgba(201, 162, 39, .12), transparent 60%),
    linear-gradient(180deg, color-mix(in srgb, var(--card) 88%, var(--gold-soft)), var(--card));
  overflow: hidden;
}
.chapter-head::after {
  content: attr(data-mark);
  position: absolute;
  right: 34px;
  top: -18px;
  font-family: var(--font-en);
  font-size: 8.4rem;
  font-weight: 700;
  line-height: 1;
  color: color-mix(in srgb, var(--gold) 12%, transparent);
  pointer-events: none;
}
.chapter-kicker {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: .66rem;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--gold);
  font-weight: 800;
  margin-bottom: 14px;
}
.chapter-kicker::before {
  content: "";
  width: 30px;
  height: 1px;
  background: var(--gold);
}
.chapter-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: clamp(1.9rem, 3.4vw, 2.9rem);
  line-height: 1.25;
  letter-spacing: -.015em;
  color: var(--ink);
  position: relative;
  z-index: 1;
}
.chapter-en {
  margin: 7px 0 0;
  font-family: var(--font-en);
  font-size: clamp(1.02rem, 1.7vw, 1.32rem);
  font-style: italic;
  color: var(--muted);
  position: relative;
  z-index: 1;
}
.meta-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 22px;
  position: relative;
  z-index: 1;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  background: color-mix(in srgb, var(--card) 70%, transparent);
  font-size: .7rem;
  color: var(--muted);
}
.chip b { color: var(--ink-2); font-weight: 600; }
.chip.gold {
  border-color: color-mix(in srgb, var(--gold) 45%, var(--line));
  background: var(--gold-soft);
  color: #7b5b0d;
}
[data-theme="dark"] .chip.gold { color: var(--gold-2); }

.chapter-body {
  padding: 42px 58px 20px;
  font-size: 1.01rem;
  color: var(--ink-2);
}
.chapter-body > *:first-child { margin-top: 0; }

/* ---------- Typography inside chapters ---------- */
.chapter-body h2 {
  margin: 2.2em 0 .7em;
  padding-top: .2em;
  font-family: var(--font-serif);
  font-size: 1.5rem;
  line-height: 1.35;
  color: var(--ink);
  letter-spacing: -.01em;
  scroll-margin-top: 80px;
}
.chapter-body h2::before {
  content: "";
  display: block;
  width: 34px;
  height: 3px;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--gold), var(--gold-2));
  margin-bottom: 14px;
}
.chapter-body h3 {
  margin: 1.7em 0 .5em;
  font-family: var(--font-serif);
  font-size: 1.14rem;
  line-height: 1.45;
  color: var(--ink);
  scroll-margin-top: 80px;
}
.chapter-body h4 {
  margin: 1.4em 0 .35em;
  font-size: .98rem;
  color: var(--ink);
}
.chapter-body p { margin: .75em 0; }
.chapter-body strong { color: var(--ink); font-weight: 700; }
.chapter-body strong.en-term {
  color: #173b8f;
  font-weight: 700;
  border-bottom: 1px dotted color-mix(in srgb, var(--gold) 70%, transparent);
  cursor: help;
}
[data-theme="dark"] .chapter-body strong.en-term { color: #93b4ff; }
.chapter-body em { color: var(--ink-2); }
.chapter-body a {
  color: var(--blue);
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, var(--blue) 35%, transparent);
}
.chapter-body a:hover { border-bottom-color: var(--blue); }
.chapter-body ul, .chapter-body ol { margin: .7em 0 .9em; padding-left: 1.45em; }
.chapter-body li { margin: .35em 0; }
.chapter-body li::marker { color: var(--gold); }
.chapter-body hr {
  border: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--line-2), transparent);
  margin: 2.4em 0;
}
.chapter-body blockquote {
  margin: 1.5em 0;
  padding: 16px 20px;
  border-left: 4px solid var(--gold);
  border-radius: 0 10px 10px 0;
  background: color-mix(in srgb, var(--gold-soft) 55%, var(--card));
  color: var(--ink-2);
}
.chapter-body blockquote p { margin: .3em 0; }
.chapter-body code {
  font-family: var(--font-mono);
  font-size: .88em;
  background: color-mix(in srgb, var(--paper-2) 80%, var(--card));
  padding: .12em .35em;
  border-radius: 5px;
}
.chapter-body pre {
  background: #0e1729;
  color: #e6edf8;
  padding: 18px 20px;
  border-radius: 12px;
  overflow-x: auto;
  font-size: .84rem;
  line-height: 1.65;
}
.chapter-body pre code { background: transparent; padding: 0; color: inherit; }

/* Tables */
.chapter-body table, .glossary-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 1.4em 0;
  font-size: .88rem;
  line-height: 1.65;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}
.chapter-body thead th, .glossary-table thead th {
  background: var(--navy-2);
  color: #f1f5fb;
  font-weight: 600;
  text-align: left;
  padding: 11px 14px;
  font-size: .76rem;
  letter-spacing: .02em;
}
.chapter-body tbody td, .glossary-table tbody td {
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  vertical-align: top;
}
.chapter-body tbody tr:nth-child(even), .glossary-table tbody tr:nth-child(even) {
  background: color-mix(in srgb, var(--paper) 55%, var(--card));
}
.chapter-body tbody tr:hover, .glossary-table tbody tr:hover {
  background: color-mix(in srgb, var(--gold-soft) 45%, var(--card));
}

/* Callouts */
.callout {
  margin: 1.5em 0;
  padding: 16px 19px 15px;
  border-left: 4px solid var(--blue);
  border-radius: 0 12px 12px 0;
  background: var(--blue-soft);
  font-size: .96rem;
}
.callout-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
  font-weight: 800;
  font-size: .78rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--blue);
}
.callout p:last-child { margin-bottom: 0; }
.callout.definition { border-color: var(--blue); background: var(--blue-soft); }
.callout.definition .callout-title { color: var(--blue); }
.callout.formula { border-color: var(--gold); background: var(--gold-soft); }
.callout.formula .callout-title { color: #8a650c; }
[data-theme="dark"] .callout.formula .callout-title { color: var(--gold-2); }
.callout.pitfall { border-color: var(--red); background: var(--red-soft); }
.callout.pitfall .callout-title { color: var(--red); }
.callout.exam { border-color: var(--green); background: var(--green-soft); }
.callout.exam .callout-title { color: var(--green); }
.callout.bpho { border-color: var(--purple); background: var(--purple-soft); }
.callout.bpho .callout-title { color: var(--purple); }
.callout.alevel { border-color: #0f766e; background: #effcf9; }
.callout.alevel .callout-title { color: #0f766e; }
[data-theme="dark"] .callout.alevel { background: #0f2f2c; }

/* Worked example */
.example {
  margin: 1.8em 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: var(--card);
}
.example-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  background: linear-gradient(90deg, var(--navy-2), var(--navy-3));
  color: #f1f5fb;
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .04em;
}
.example-head span:last-child {
  font-weight: 500;
  color: #a9b8d1;
  font-size: .7rem;
  letter-spacing: .02em;
}
.example-body { padding: 18px 20px 8px; }
.example-body > *:first-child { margin-top: 0; }

/* Self-check */
details.check {
  margin: .8em 0;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: color-mix(in srgb, var(--paper) 60%, var(--card));
  overflow: hidden;
}
details.check summary {
  cursor: pointer;
  padding: 11px 15px;
  font-weight: 600;
  font-size: .9rem;
  color: var(--ink);
  list-style: none;
  display: flex;
  align-items: flex-start;
  gap: 9px;
}
details.check summary::-webkit-details-marker { display: none; }
details.check summary::before {
  content: "?";
  flex: 0 0 20px;
  height: 20px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--gold);
  color: #1b2333;
  font-size: .68rem;
  font-weight: 800;
  margin-top: 2px;
}
details.check[open] summary { border-bottom: 1px solid var(--line); }
details.check .check-answer {
  padding: 12px 15px 14px 44px;
  font-size: .9rem;
  color: var(--ink-2);
  background: var(--card);
}
details.check .check-answer p:first-child { margin-top: 0; }
details.check .check-answer p:last-child { margin-bottom: 0; }

/* Chapter footer / navigation */
.chapter-check {
  margin: 30px 58px 0;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: color-mix(in srgb, var(--paper) 55%, var(--card));
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.chapter-check p { margin: 0; font-size: .84rem; color: var(--muted); flex: 1; min-width: 220px; }
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 15px;
  border-radius: 9px;
  border: 1px solid var(--line-2);
  background: var(--card);
  color: var(--ink);
  font-family: inherit;
  font-size: .78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .18s, border-color .18s, color .18s, transform .08s;
}
.btn:hover { border-color: var(--gold); background: var(--gold-soft); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--navy-2);
  border-color: var(--navy-2);
  color: #fff;
}
.btn.primary:hover { background: var(--navy-3); border-color: var(--navy-3); color: #fff; }
.btn.done {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}
.btn.done:hover { background: #036b50; border-color: #036b50; color: #fff; }

.chapter-nav {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 22px 58px 34px;
}
.chapter-nav a {
  flex: 1;
  max-width: 48%;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 13px 16px;
  border: 1px solid var(--line);
  border-radius: 11px;
  text-decoration: none;
  color: var(--ink);
  transition: border-color .18s, background .18s;
}
.chapter-nav a:hover { border-color: var(--gold); background: var(--gold-soft); }
.chapter-nav a.next { align-items: flex-end; text-align: right; }
.chapter-nav .nav-label {
  font-size: .64rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}
.chapter-nav .nav-title { font-size: .84rem; font-weight: 600; }
.chapter-nav .nav-empty { visibility: hidden; }

/* Glossary */
.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 1.2em 0 1.4em;
}
.toolbar input {
  flex: 1;
  min-width: 220px;
  padding: 10px 13px;
  border: 1px solid var(--line-2);
  border-radius: 9px;
  background: var(--card);
  color: var(--ink);
  font-family: inherit;
  font-size: .86rem;
  outline: none;
}
.toolbar input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(201,162,39,.16); }
.toolbar select {
  padding: 10px 12px;
  border: 1px solid var(--line-2);
  border-radius: 9px;
  background: var(--card);
  color: var(--ink);
  font-family: inherit;
  font-size: .82rem;
}
.glossary-table td:first-child {
  font-family: var(--font-en);
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
}
.glossary-table td:nth-child(2) { color: var(--ink-2); }
.glossary-table td:nth-child(3) {
  color: var(--muted);
  font-size: .76rem;
  white-space: nowrap;
}
.glossary-empty {
  padding: 30px 0;
  text-align: center;
  color: var(--muted);
  font-size: .86rem;
}

/* Formula sheet */
.formula-group { margin: 2em 0 2.6em; }
.formula-group h2 { margin-top: 0; }
.formula-card {
  display: grid;
  grid-template-columns: minmax(150px, 210px) 1fr;
  gap: 16px;
  align-items: center;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 11px;
  margin: 9px 0;
  background: color-mix(in srgb, var(--paper) 45%, var(--card));
}
.formula-card .f-name {
  font-size: .8rem;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.5;
}
.formula-card .f-name small {
  display: block;
  font-weight: 400;
  color: var(--muted);
  font-size: .68rem;
  margin-top: 2px;
}
.formula-card .f-math {
  overflow-x: auto;
  padding: 2px 0;
  font-size: .95rem;
}
.formula-card .f-math .katex-display { margin: .2em 0; text-align: left; }

/* Hero on guide page */
.hero {
  margin: 0 0 2em;
  padding: 26px 28px;
  border-radius: 16px;
  background:
    radial-gradient(600px 240px at 95% 0%, rgba(201, 162, 39, .18), transparent 65%),
    linear-gradient(135deg, var(--navy), var(--navy-2));
  color: #eef3fb;
}
.hero .hero-kicker {
  font-size: .66rem;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--gold-2);
  font-weight: 800;
}
.hero h2 {
  margin: .35em 0 .3em;
  padding: 0;
  color: #fff;
  font-size: 1.65rem;
}
.hero h2::before { display: none; }
.hero p { color: #c4d1e6; margin: .4em 0; }
.hero .hero-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 18px;
}
.hero .hero-stat {
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.09);
}
.hero .hero-stat b {
  display: block;
  font-size: 1.15rem;
  color: var(--gold-2);
  line-height: 1.3;
}
.hero .hero-stat span { font-size: .7rem; color: #a9b8d1; }

/* Footer */
.page-footer {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 0 30px 34px;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  font-size: .68rem;
  color: var(--muted-2);
}
.page-footer a { color: var(--muted); text-decoration: none; }
.page-footer a:hover { color: var(--gold); }

/* Overlay for mobile */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(4, 10, 20, .55);
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity .25s;
}
.sidebar-overlay.show { display: block; opacity: 1; }

/* Reading progress line */
.read-progress {
  position: fixed;
  top: 0;
  left: var(--sidebar-w);
  right: 0;
  height: 2px;
  z-index: 70;
  background: transparent;
  pointer-events: none;
}
.read-progress > div {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--gold), var(--gold-2));
  transition: width .08s linear;
}

/* KaTeX tweaks */
.katex { font-size: 1.04em; }
.katex-display {
  margin: 1.1em 0 !important;
  padding: 4px 0;
  overflow-x: auto;
  overflow-y: hidden;
}

/* Responsive */
@media (max-width: 1120px) {
  :root { --sidebar-w: 280px; }
  .chapter-head, .chapter-body { padding-left: 42px; padding-right: 42px; }
  .chapter-check { margin-left: 42px; margin-right: 42px; }
  .chapter-nav { padding-left: 42px; padding-right: 42px; }
}

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); box-shadow: 20px 0 60px rgba(0,0,0,.3); }
  .sidebar.open { transform: translateX(0); }
  .main-wrap { margin-left: 0; }
  .read-progress { left: 0; }
  .mobile-only { display: grid; }
  .topbar { padding: 0 16px; height: 54px; }
  .content { padding: 22px 14px 40px; }
  .chapter { border-radius: 16px; }
  .chapter-head { padding: 36px 24px 28px; }
  .chapter-head::after { font-size: 5.6rem; right: 14px; top: -8px; }
  .chapter-body { padding: 28px 24px 12px; font-size: .98rem; }
  .chapter-check { margin: 24px 24px 0; }
  .chapter-nav { padding: 18px 24px 26px; flex-direction: column; }
  .chapter-nav a { max-width: 100%; }
  .chapter-nav a.next { align-items: flex-start; text-align: left; }
  .hero .hero-grid { grid-template-columns: 1fr; }
  .formula-card { grid-template-columns: 1fr; gap: 6px; }
  .page-footer { padding: 0 18px 26px; }
}

@media (max-width: 520px) {
  .chapter-head { padding: 30px 19px 24px; }
  .chapter-body { padding: 24px 19px 10px; }
  .chapter-check { margin: 20px 19px 0; }
  .chapter-nav { padding: 16px 19px 22px; }
  .chapter-title { font-size: 1.75rem; }
  .chapter-en { font-size: 1rem; }
  .meta-chips { gap: 6px; }
  .chip { font-size: .66rem; padding: 4px 8px; }
  .chapter-body h2 { font-size: 1.3rem; }
  .chapter-body h3 { font-size: 1.06rem; }
  .chapter-body table { font-size: .78rem; }
  .chapter-body thead th, .chapter-body tbody td { padding: 8px 9px; }
  .callout { padding: 13px 14px; }
  .example-body { padding: 14px 14px 6px; }
}

/* Print */
@media print {
  @page { margin: 16mm 14mm; }
  body { background: #fff; color: #111; font-size: 11pt; }
  .sidebar, .topbar, .read-progress, .chapter-check, .chapter-nav, .page-footer, .sidebar-overlay { display: none !important; }
  .main-wrap { margin-left: 0; }
  .content { padding: 0; }
  .chapter { border: 0; border-radius: 0; box-shadow: none; max-width: none; }
  .chapter-head { padding: 0 0 18px; background: #fff; border-bottom: 1px solid #ddd; }
  .chapter-head::after { display: none; }
  .chapter-body { padding: 18px 0 0; font-size: 10.5pt; }
  .chapter-body h2 { page-break-after: avoid; }
  .chapter-body h3 { page-break-after: avoid; }
  .callout, .example, table, details.check { page-break-inside: avoid; }
  details.check > summary { list-style: none; }
  details.check .check-answer { display: block !important; }
  a { color: #111; text-decoration: none; }
}
