/* Shankar Quantum Mechanics — Offline Academic Static HTML Reader */
:root {
  --sidebar-w: 296px;
  --topbar-h: 52px;
  --reader-fs: 17px;

  --bg-page: #fdfcfa;
  --bg-sidebar: #f4f1ea;
  --bg-topbar: rgba(253, 252, 250, 0.92);
  --bg-card: #f7f5ef;
  --bg-hover: rgba(29, 67, 104, 0.06);
  --row-hover: rgba(29, 67, 104, 0.032);
  --border: #e4dfd4;
  --border-strong: #c8c0b0;
  --ink: #1b1f26;
  --ink-muted: #566070;
  --accent: #1d4368;
  --accent-soft: rgba(29, 67, 104, 0.10);
  --shadow-sm: 0 2px 10px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 14px 36px rgba(15, 23, 42, 0.14);
  --fig-bg: transparent;
}

html[data-theme="green"] {
  --bg-page: #e7f3e7;
  --bg-sidebar: #dcebd9;
  --bg-topbar: rgba(231, 243, 231, 0.94);
  --bg-card: #ddf0dd;
  --bg-hover: rgba(30, 86, 56, 0.08);
  --row-hover: rgba(30, 86, 56, 0.04);
  --border: #c4dac4;
  --border-strong: #9ebea0;
  --ink: #19241d;
  --ink-muted: #425c4a;
  --accent: #1d5a3b;
  --accent-soft: rgba(29, 90, 59, 0.12);
  --fig-bg: rgba(255, 255, 255, 0.72);
}

html[data-theme="sepia"] {
  --bg-page: #f7f1e3;
  --bg-sidebar: #efe7d5;
  --bg-topbar: rgba(247, 241, 227, 0.94);
  --bg-card: #f0e8d6;
  --bg-hover: rgba(107, 62, 38, 0.07);
  --row-hover: rgba(107, 62, 38, 0.035);
  --border: #dfd4bc;
  --border-strong: #c3b293;
  --ink: #2b231b;
  --ink-muted: #675847;
  --accent: #6b3e26;
  --accent-soft: rgba(107, 62, 38, 0.11);
  --fig-bg: rgba(255, 255, 255, 0.76);
}

html[data-theme="dark"] {
  --bg-page: #13161b;
  --bg-sidebar: #1a1e25;
  --bg-topbar: rgba(19, 22, 27, 0.92);
  --bg-card: #1d222b;
  --bg-hover: rgba(108, 166, 224, 0.10);
  --row-hover: rgba(255, 255, 255, 0.025);
  --border: #2a303c;
  --border-strong: #3d4656;
  --ink: #dde3ec;
  --ink-muted: #93a0b4;
  --accent: #6ca6e0;
  --accent-soft: rgba(108, 166, 224, 0.15);
  --shadow-sm: 0 2px 12px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.55);
  --fig-bg: #ffffff;
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--topbar-h) + 20px);
}

body {
  margin: 0;
  padding: 0;
  background: var(--bg-page);
  color: var(--ink);
  font-size: var(--reader-fs);
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.18s ease, color 0.18s ease;
}

body.edition-en {
  font-family: "KaTeX_Main", "Georgia", "Times New Roman", "Liberation Serif", serif;
  line-height: 1.66;
}

body.edition-zh,
body.edition-bilingual {
  font-family: "KaTeX_Main", "Noto Serif CJK SC", "Source Han Serif SC", "Songti SC", "STSong", "PingFang SC", serif;
  line-height: 1.78;
}

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 40;
  transition: transform 0.22s ease;
}

body.sidebar-collapsed .sidebar {
  transform: translateX(calc(-1 * var(--sidebar-w)));
}

.sidebar-head {
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.brand-link {
  text-decoration: none;
  color: var(--ink);
  display: block;
}

.brand-title {
  display: block;
  font-weight: 700;
  font-size: 14.5px;
  line-height: 1.35;
  color: var(--ink);
}

.brand-sub {
  display: block;
  margin-top: 3px;
  font-size: 11.5px;
  letter-spacing: 0.03em;
  color: var(--ink-muted);
  font-family: system-ui, -apple-system, sans-serif;
}

.sidebar-close-btn {
  display: none;
  background: transparent;
  border: 0;
  color: var(--ink-muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
}

.toc-search-wrap {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  position: relative;
}

.toc-search-input {
  width: 100%;
  padding: 7px 26px 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-page);
  color: var(--ink);
  font-size: 13px;
  font-family: system-ui, -apple-system, sans-serif;
  outline: none;
}

.toc-search-input:focus {
  border-color: var(--accent);
}

.toc-search-clear {
  position: absolute;
  right: 18px;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: transparent;
  color: var(--ink-muted);
  font-size: 16px;
  cursor: pointer;
}

.toc-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 10px 8px 28px;
  font-family: system-ui, -apple-system, "PingFang SC", "Noto Sans CJK SC", sans-serif;
}

.toc-root, .toc-l2, .toc-l3 {
  list-style: none;
  margin: 0;
  padding: 0;
}

.toc-ch {
  margin-bottom: 2px;
}

.toc-ch-row {
  display: flex;
  align-items: flex-start;
  gap: 2px;
}

.toc-toggle {
  flex: 0 0 22px;
  height: 28px;
  border: 0;
  background: transparent;
  color: var(--ink-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: transform 0.16s ease, color 0.15s ease;
}

.toc-toggle:hover {
  background: var(--bg-hover);
  color: var(--ink);
}

.toc-ch.is-open > .toc-ch-row .toc-toggle svg {
  transform: rotate(90deg);
}

.toc-toggle-spacer {
  flex: 0 0 22px;
}

.toc-link {
  display: block;
  flex: 1 1 auto;
  text-decoration: none;
  color: var(--ink);
  border-radius: 6px;
  transition: background-color 0.14s ease, color 0.14s ease;
}

.toc-link:hover {
  background: var(--bg-hover);
  color: var(--accent);
}

.toc-link-l1 {
  padding: 5px 8px;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.38;
}

.toc-l1-sub {
  display: block;
  font-size: 11px;
  font-weight: 400;
  color: var(--ink-muted);
  margin-top: 1px;
}

.toc-link-l1.active,
.toc-link-l2.active,
.toc-link-l3.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.toc-l2 {
  display: none;
  padding-left: 22px;
  margin: 2px 0 6px;
}

.toc-ch.is-open > .toc-l2 {
  display: block;
}

.toc-link-l2 {
  padding: 4px 8px;
  font-size: 12.6px;
  line-height: 1.4;
  color: var(--ink-muted);
}

.toc-l3 {
  padding-left: 12px;
  margin: 1px 0 3px;
  border-left: 1px solid var(--border);
}

.toc-link-l3 {
  padding: 3px 8px;
  font-size: 12px;
  line-height: 1.38;
  color: var(--ink-muted);
}

.toc-hidden { display: none !important; }

/* ---------- App Shell & Topbar ---------- */
.app-shell {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  transition: margin-left 0.22s ease;
}

body.sidebar-collapsed .app-shell {
  margin-left: 0;
}

.topbar {
  position: sticky;
  top: 0;
  height: var(--topbar-h);
  background: var(--bg-topbar);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  z-index: 30;
  font-family: system-ui, -apple-system, sans-serif;
}

.read-progress {
  position: absolute;
  left: 0;
  bottom: -1px;
  height: 2px;
  width: 0%;
  background: var(--accent);
  transition: width 0.08s linear;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.icon-btn {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--ink);
  width: 34px;
  height: 32px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.icon-btn:hover { background: var(--bg-hover); }

.topbar-crumb {
  font-size: 13.5px;
  color: var(--ink-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.bi-mode-switch {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.mode-btn {
  border: 0;
  background: transparent;
  color: var(--ink-muted);
  padding: 4px 10px;
  font-size: 12.5px;
  cursor: pointer;
}

.mode-btn.active {
  background: var(--accent);
  color: #ffffff;
}

.fs-controls {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.fs-btn {
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 4px 8px;
  font-size: 12.5px;
  cursor: pointer;
}

.fs-btn:hover { background: var(--bg-hover); }
.fs-val { min-width: 30px; color: var(--ink-muted); border-left: 1px solid var(--border); border-right: 1px solid var(--border); }

.theme-swatches {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1.5px solid var(--border-strong);
  cursor: pointer;
  padding: 0;
  transition: transform 0.14s ease, box-shadow 0.14s ease;
}

.swatch:hover { transform: scale(1.1); }
.swatch-light { background: #fdfcfa; }
.swatch-green { background: #cce8cf; }
.swatch-sepia { background: #f3e8cf; }
.swatch-dark  { background: #1c222b; }

html[data-theme="light"] .swatch-light,
html[data-theme="green"] .swatch-green,
html[data-theme="sepia"] .swatch-sepia,
html[data-theme="dark"]  .swatch-dark {
  box-shadow: 0 0 0 2px var(--bg-page), 0 0 0 3.8px var(--accent);
}

/* ---------- Main Article Area ---------- */
.reader-main {
  max-width: 820px;
  margin: 0 auto;
  padding: 36px 40px 80px;
}

body.edition-bilingual .reader-main {
  max-width: 1400px;
  padding: 32px 34px 80px;
}

/* ---------- Book Hero (index.html) ---------- */
.book-hero {
  display: flex;
  align-items: center;
  gap: 36px;
  padding: 28px 32px;
  margin-bottom: 36px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.hero-cover-wrap, .hero-covers-dual {
  flex-shrink: 0;
  display: flex;
  gap: 14px;
}

.hero-cover {
  height: 230px;
  width: auto;
  border-radius: 4px;
  box-shadow: var(--shadow-lg);
  cursor: zoom-in;
}

.hero-kicker {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 8px;
}

.hero-title {
  margin: 0 0 10px;
  font-size: 1.75em;
  line-height: 1.25;
  font-weight: 700;
}

.hero-title-zh {
  display: block;
  margin-top: 6px;
  font-size: 0.85em;
  font-weight: 600;
  color: var(--ink-muted);
}

.hero-author {
  margin: 0 0 18px;
  color: var(--ink-muted);
  font-size: 0.96em;
}

.btn-primary {
  display: inline-block;
  padding: 9px 18px;
  border-radius: 7px;
  background: var(--accent);
  color: #ffffff;
  text-decoration: none;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 14px;
  font-weight: 600;
  transition: opacity 0.15s ease;
}

.btn-primary:hover { opacity: 0.9; }

.frontispiece-card {
  padding: 20px 24px;
  margin-bottom: 30px;
  background: var(--bg-card);
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  font-size: 0.92em;
  color: var(--ink-muted);
}

.frontispiece-card p.para {
  text-indent: 0;
  margin: 0.5em 0;
}

/* ---------- Chapter & Section Headings ---------- */
.chapter-banner {
  margin-bottom: 30px;
  padding-bottom: 18px;
  border-bottom: 2px solid var(--ink);
}

.ch-label {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 8px;
}

.ch-title {
  margin: 0;
  font-size: 1.85em;
  line-height: 1.28;
  font-weight: 700;
}

.sec-heading {
  margin: 2em 0 0.75em;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  font-size: 1.32em;
  line-height: 1.35;
  font-weight: 700;
}

.subsec-heading {
  margin: 1.5em 0 0.55em;
  font-size: 1.1em;
  line-height: 1.38;
  font-weight: 700;
}

.sec-num {
  color: var(--accent);
}

/* ---------- Paragraphs, Lists, Footnotes ---------- */
p.para {
  margin: 0.6em 0;
  text-align: justify;
  hyphens: auto;
}

body.edition-en p.para.indented,
.col-en p.para.indented { text-indent: 1.8em; }

body.edition-zh p.para.indented,
.col-zh p.para.indented { text-indent: 2em; }

p.para.no-indent { text-indent: 0; }

.list-item {
  display: grid;
  grid-template-columns: 2.2em minmax(0, 1fr);
  margin: 0.5em 0;
  align-items: baseline;
}

.list-marker {
  font-weight: 600;
  color: var(--accent);
}

.list-body {
  text-align: justify;
}

aside.footnote {
  margin: 1em 0;
  padding: 10px 14px;
  background: var(--bg-card);
  border-left: 2.5px solid var(--border-strong);
  border-radius: 0 6px 6px 0;
  font-size: 0.87em;
  line-height: 1.55;
  color: var(--ink-muted);
}

aside.footnote p { margin: 0; text-indent: 0; }

sup.fn-ref {
  font-size: 0.72em;
  vertical-align: super;
  line-height: 0;
  color: var(--accent);
}

/* ---------- Equations (Vector KaTeX + Safe Horizontal Scroll) ---------- */
.eq-box {
  display: grid;
  grid-template-columns: 4.2em minmax(0, 1fr) 4.2em;
  align-items: center;
  margin: 1.05em 0;
  gap: 8px;
}

.eq-box.no-num {
  grid-template-columns: 0 minmax(0, 1fr) 0;
  gap: 0;
}

.eq-math {
  text-align: center;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 6px 2px;
}

.eq-math .katex-display {
  margin: 0 !important;
}

.eq-math .katex {
  font-size: 1.06em;
}

.eq-num {
  text-align: right;
  font-family: "KaTeX_Main", serif;
  font-size: 0.92em;
  color: var(--ink-muted);
  white-space: nowrap;
}

.katex {
  color: inherit;
}

/* ---------- Figures & Tables ---------- */
figure.book-figure {
  margin: 1.4em 0;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  text-align: center;
}

.fig-frame {
  display: inline-block;
  background: var(--fig-bg);
  padding: 8px 12px;
  border-radius: 6px;
  max-width: 100%;
}

figure.book-figure img {
  max-width: 100%;
  max-height: 460px;
  width: auto;
  height: auto;
  display: block;
  margin: 0 auto;
  cursor: zoom-in;
}

figure.book-figure figcaption {
  margin-top: 10px;
  font-size: 0.88em;
  line-height: 1.55;
  color: var(--ink-muted);
  text-align: justify;
}

/* ---------- Index ---------- */
.index-cols {
  column-count: 2;
  column-gap: 32px;
  font-size: 0.88em;
  line-height: 1.48;
}

p.index-entry {
  margin: 0.16em 0 0.16em 1.2em;
  text-indent: -1.2em;
  break-inside: avoid;
}

p.index-note {
  margin: 0.3em 0;
  font-size: 0.9em;
  color: var(--ink-muted);
}

/* ---------- Bilingual Side-by-Side Grid ---------- */
.bi-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0 32px;
  position: relative;
  padding: 2px 6px;
  border-radius: 6px;
  transition: background-color 0.12s ease;
}

.bi-row::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
  background: var(--border);
  pointer-events: none;
}

.bi-para-row:hover,
.bi-eq-row:hover,
.bi-list-row:hover {
  background: var(--row-hover);
}

.bi-row .col-en {
  font-family: "KaTeX_Main", "Georgia", "Times New Roman", serif;
  line-height: 1.62;
  min-width: 0;
}

.bi-row .col-zh {
  font-family: "KaTeX_Main", "Noto Serif CJK SC", "Source Han Serif SC", "Songti SC", serif;
  line-height: 1.78;
  min-width: 0;
}

.bi-sec-row .sec-heading,
.bi-sec-row .sec-heading-zh {
  margin-top: 1.6em;
}

.bi-subsec-row .subsec-heading,
.bi-subsec-row .subsec-heading-zh {
  margin-top: 1.2em;
}

.bi-banner-grid::after { display: none; }

.bi-row .eq-box {
  grid-template-columns: 3.4em minmax(0, 1fr) 3.4em;
}

.bi-row .eq-box.no-num {
  grid-template-columns: 0 minmax(0, 1fr) 0;
}

/* Bilingual view mode filters */
html[data-bimode="en"] .bi-row {
  grid-template-columns: minmax(0, 1fr);
}
html[data-bimode="en"] .bi-row::after,
html[data-bimode="en"] .bi-row .col-zh { display: none; }
html[data-bimode="en"] body.edition-bilingual .reader-main { max-width: 820px; }

html[data-bimode="zh"] .bi-row {
  grid-template-columns: minmax(0, 1fr);
}
html[data-bimode="zh"] .bi-row::after,
html[data-bimode="zh"] .bi-row .col-en { display: none; }
html[data-bimode="zh"] body.edition-bilingual .reader-main { max-width: 820px; }

/* ---------- Chapter Pager ---------- */
.chapter-pager {
  margin-top: 56px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  font-family: system-ui, -apple-system, sans-serif;
}

.pager-card {
  display: block;
  padding: 14px 18px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-card);
  text-decoration: none;
  color: var(--ink);
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.pager-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.pager-next { text-align: right; }

.pager-dir {
  display: block;
  font-size: 12px;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 4px;
}

.pager-title {
  display: block;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
}

/* ---------- Back to Top & Lightbox ---------- */
.back-to-top {
  position: fixed;
  right: 22px;
  bottom: 24px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--bg-topbar);
  color: var(--ink);
  font-size: 18px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 35;
}

.back-to-top.visible {
  opacity: 1;
  pointer-events: auto;
}

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 20, 0.88);
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.lightbox[hidden] { display: none; }

.lightbox-img {
  max-width: 94vw;
  max-height: 82vh;
  background: #ffffff;
  padding: 12px;
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
}

.lightbox-cap {
  margin-top: 12px;
  color: #e2e8f0;
  font-size: 14px;
  max-width: 820px;
  text-align: center;
  font-family: system-ui, -apple-system, sans-serif;
}

.lightbox-close {
  position: absolute;
  top: 16px;
  right: 22px;
  border: 0;
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  font-size: 24px;
  cursor: pointer;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.42);
  z-index: 38;
}

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .sidebar { transform: translateX(calc(-1 * var(--sidebar-w))); }
  body.sidebar-open-mobile .sidebar { transform: translateX(0); }
  body.sidebar-open-mobile .sidebar-backdrop { display: block; }
  .sidebar-close-btn { display: inline-block; }
  .app-shell { margin-left: 0 !important; }
  .reader-main, body.edition-bilingual .reader-main { padding: 22px 18px 64px; }
  .book-hero { flex-direction: column; text-align: center; padding: 22px 18px; gap: 20px; }
  .hero-cover { height: 185px; }
  .index-cols { column-count: 1; }
  .bi-row { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .bi-row::after { display: none; }
  .bi-para-row .col-zh, .bi-eq-row .col-zh { padding-left: 10px; border-left: 2px solid var(--border); }
  .chapter-pager { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .topbar { padding: 0 10px; gap: 6px; }
  .topbar-crumb { display: none; }
  .topbar-right { gap: 6px; }
  .mode-btn { padding: 4px 7px; font-size: 11.5px; }
  .fs-btn { padding: 4px 6px; font-size: 11.5px; }
  .fs-val { display: none; }
  .theme-swatches { gap: 4px; }
  .swatch { width: 17px; height: 17px; }
  .eq-box { grid-template-columns: 0 minmax(0, 1fr) 3.4em; gap: 4px; }
  .eq-pad { display: none; }
  .bi-row .eq-box { grid-template-columns: 0 minmax(0, 1fr) 3.4em; }
}
