:root {
  color-scheme: light;
}

html:not([data-biblio-theme="night"]),
html[data-biblio-theme="basic"] {
  --bg: #f6f8f6;
  --bg2: #ffffff;
  --bg3: #eef2ef;
  --gold: #8a6825;
  --gold-light: #9b752c;
  --gold-dim: rgba(138, 104, 37, 0.11);
  --cream: #202824;
  --cream-muted: #46544d;
  --border: #d8dfda;
  --border-gold: rgba(138, 104, 37, 0.34);
}

html[data-biblio-theme="night"] {
  color-scheme: dark;
}

.biblio-document-title {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.biblio-theme-control {
  display: inline-flex;
  align-items: center;
  gap: 0;
  min-height: 34px;
  border: 1px solid #d7dcd8;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 3px 14px rgba(22, 31, 27, 0.08);
  overflow: hidden;
}

.biblio-theme-control--desktop {
  position: fixed;
  top: 12px;
  right: 18px;
  z-index: 1200;
}

.biblio-theme-label {
  padding: 0 10px;
  color: #65706b;
  font: 700 9px/32px Arial, sans-serif;
  letter-spacing: 0;
  text-transform: uppercase;
}

.biblio-theme-button {
  min-width: 54px;
  height: 32px;
  padding: 0 10px;
  border: 0;
  border-left: 1px solid #d7dcd8;
  border-radius: 0;
  background: transparent;
  color: #4f5955;
  cursor: pointer;
  font: 700 10px/32px Arial, sans-serif;
  letter-spacing: 0;
}

.biblio-theme-button:hover {
  background: #f1f4f2;
}

.biblio-theme-button[aria-pressed="true"] {
  background: #315e4d;
  color: #fff;
}

.biblio-load-status {
  position: fixed;
  right: 18px;
  bottom: 20px;
  z-index: 1250;
  max-width: min(320px, calc(100vw - 32px));
  padding: 9px 12px;
  border: 1px solid #d7dcd8;
  border-radius: 5px;
  background: #fff;
  color: #3f4a45;
  box-shadow: 0 4px 18px rgba(22, 31, 27, 0.12);
  font: 600 12px/1.45 Arial, sans-serif;
}

.biblio-load-status:empty {
  display: none;
}

.biblio-fragment-error {
  display: grid;
  min-height: 55vh;
  place-items: center;
  padding: 28px;
  background: #f7f8f6;
  color: #303a35;
  text-align: center;
}

.biblio-fragment-error button {
  margin-top: 14px;
  padding: 9px 14px;
  border: 1px solid #315e4d;
  border-radius: 5px;
  background: #315e4d;
  color: #fff;
  cursor: pointer;
  font: 700 12px/1 Arial, sans-serif;
}

/*
 * The source design is the Night mode. These overrides create the public
 * Basic mode while preserving each book's green, blue, red, and gold accents.
 */
html:not([data-biblio-theme="night"]) body,
html[data-biblio-theme="basic"] body {
  background: #f6f8f6 !important;
  color: #202824 !important;
}

html:not([data-biblio-theme="night"]) .book-wrap,
html[data-biblio-theme="basic"] .book-wrap,
html:not([data-biblio-theme="night"]) .main,
html[data-biblio-theme="basic"] .main {
  background: #f8faf8 !important;
  color: #202824 !important;
}

html:not([data-biblio-theme="night"]) .sidebar,
html[data-biblio-theme="basic"] .sidebar,
html:not([data-biblio-theme="night"]) .uni-sidebar,
html[data-biblio-theme="basic"] .uni-sidebar,
html:not([data-biblio-theme="night"]) .panel,
html[data-biblio-theme="basic"] .panel,
html:not([data-biblio-theme="night"]) .panel-inner,
html[data-biblio-theme="basic"] .panel-inner,
html:not([data-biblio-theme="night"]) .panel-content,
html[data-biblio-theme="basic"] .panel-content {
  background: #fff !important;
  color: #27312d !important;
  border-color: #dbe0dc !important;
}

html:not([data-biblio-theme="night"]) .mob-header,
html[data-biblio-theme="basic"] .mob-header,
html:not([data-biblio-theme="night"]) .mob-bottom-nav,
html[data-biblio-theme="basic"] .mob-bottom-nav,
html:not([data-biblio-theme="night"]) .mob-nav-drawer,
html[data-biblio-theme="basic"] .mob-nav-drawer,
html:not([data-biblio-theme="night"]) .mob-panel-sheet,
html[data-biblio-theme="basic"] .mob-panel-sheet {
  background: #fff !important;
  color: #28322e !important;
  border-color: #d7ddd8 !important;
}

html:not([data-biblio-theme="night"]) .mob-logo,
html[data-biblio-theme="basic"] .mob-logo,
html:not([data-biblio-theme="night"]) .mob-btn,
html[data-biblio-theme="basic"] .mob-btn,
html:not([data-biblio-theme="night"]) .mob-nav-drawer-item,
html[data-biblio-theme="basic"] .mob-nav-drawer-item,
html:not([data-biblio-theme="night"]) .mob-nav-label,
html[data-biblio-theme="basic"] .mob-nav-label {
  color: #39443f !important;
}

html:not([data-biblio-theme="night"]) .mob-nav-overlay,
html[data-biblio-theme="basic"] .mob-nav-overlay {
  background: rgba(24, 34, 29, 0.34) !important;
}

html:not([data-biblio-theme="night"]) .book-title,
html[data-biblio-theme="basic"] .book-title,
html:not([data-biblio-theme="night"]) .book-title-en,
html[data-biblio-theme="basic"] .book-title-en,
html:not([data-biblio-theme="night"]) .chapter-title,
html[data-biblio-theme="basic"] .chapter-title,
html:not([data-biblio-theme="night"]) .section-title,
html[data-biblio-theme="basic"] .section-title,
html:not([data-biblio-theme="night"]) .pc-title,
html[data-biblio-theme="basic"] .pc-title,
html:not([data-biblio-theme="night"]) .formula-title,
html[data-biblio-theme="basic"] .formula-title {
  color: #17211d !important;
}

html:not([data-biblio-theme="night"]) .book-meta,
html[data-biblio-theme="basic"] .book-meta,
html:not([data-biblio-theme="night"]) .book-desc,
html[data-biblio-theme="basic"] .book-desc,
html:not([data-biblio-theme="night"]) .book-intro,
html[data-biblio-theme="basic"] .book-intro,
html:not([data-biblio-theme="night"]) .section-intro,
html[data-biblio-theme="basic"] .section-intro,
html:not([data-biblio-theme="night"]) .chapter-desc,
html[data-biblio-theme="basic"] .chapter-desc,
html:not([data-biblio-theme="night"]) .ch-body,
html[data-biblio-theme="basic"] .ch-body,
html:not([data-biblio-theme="night"]) .pane,
html[data-biblio-theme="basic"] .pane,
html:not([data-biblio-theme="night"]) .empty-txt,
html[data-biblio-theme="basic"] .empty-txt {
  color: #4c5852 !important;
}

html:not([data-biblio-theme="night"]) .formula-card,
html[data-biblio-theme="basic"] .formula-card,
html:not([data-biblio-theme="night"]) .f-card,
html[data-biblio-theme="basic"] .f-card,
html:not([data-biblio-theme="night"]) .k-pv-card,
html[data-biblio-theme="basic"] .k-pv-card,
html:not([data-biblio-theme="night"]) .mech-passage,
html[data-biblio-theme="basic"] .mech-passage,
html:not([data-biblio-theme="night"]) .ling-passage,
html[data-biblio-theme="basic"] .ling-passage,
html:not([data-biblio-theme="night"]) .passage,
html[data-biblio-theme="basic"] .passage,
html:not([data-biblio-theme="night"]) .card,
html[data-biblio-theme="basic"] .card {
  background: #fff !important;
  color: #27312d !important;
  border-color: #d8dfda !important;
  box-shadow: 0 2px 10px rgba(25, 38, 31, 0.05) !important;
}

html:not([data-biblio-theme="night"]) .formula-display,
html[data-biblio-theme="basic"] .formula-display,
html:not([data-biblio-theme="night"]) .formula-box,
html[data-biblio-theme="basic"] .formula-box,
html:not([data-biblio-theme="night"]) .pc-formula-box,
html[data-biblio-theme="basic"] .pc-formula-box,
html:not([data-biblio-theme="night"]) .k-formula,
html[data-biblio-theme="basic"] .k-formula,
html:not([data-biblio-theme="night"]) pre,
html[data-biblio-theme="basic"] pre,
html:not([data-biblio-theme="night"]) code,
html[data-biblio-theme="basic"] code {
  background: #f1f4f2 !important;
  color: #1d2923 !important;
  border-color: #d5ddd8 !important;
}

html:not([data-biblio-theme="night"]) table,
html[data-biblio-theme="basic"] table {
  background: #fff !important;
  color: #26312c !important;
  border-color: #d6ddd8 !important;
}

html:not([data-biblio-theme="night"]) th,
html[data-biblio-theme="basic"] th {
  background: #edf2ef !important;
  color: #26312c !important;
}

html:not([data-biblio-theme="night"]) td,
html[data-biblio-theme="basic"] td {
  border-color: #dce2de !important;
}

html:not([data-biblio-theme="night"]) .katex,
html[data-biblio-theme="basic"] .katex,
html:not([data-biblio-theme="night"]) .MathJax,
html[data-biblio-theme="basic"] .MathJax {
  color: #17211d !important;
}

html:not([data-biblio-theme="night"]) a,
html[data-biblio-theme="basic"] a {
  color: #285e78;
}

html:not([data-biblio-theme="night"]) .panel-empty-text,
html[data-biblio-theme="basic"] .panel-empty-text {
  color: #46544d !important;
  opacity: 0.9 !important;
}

html:not([data-biblio-theme="night"]) .panel-empty-text span,
html[data-biblio-theme="basic"] .panel-empty-text span {
  opacity: 0.82 !important;
}

/* Kleinert keeps its blue-violet identity, but Basic mode uses the public paper surface. */
html:not([data-biblio-theme="night"]) #wrap-kleinert .main,
html[data-biblio-theme="basic"] #wrap-kleinert .main {
  background: #f8faf8 !important;
}

html:not([data-biblio-theme="night"]) #wrap-kleinert .k-sitemap,
html[data-biblio-theme="basic"] #wrap-kleinert .k-sitemap,
html:not([data-biblio-theme="night"]) #wrap-kleinert .k-pv-bar,
html[data-biblio-theme="basic"] #wrap-kleinert .k-pv-bar,
html:not([data-biblio-theme="night"]) #wrap-kleinert .k-pv-stat,
html[data-biblio-theme="basic"] #wrap-kleinert .k-pv-stat {
  background: #eef3f5 !important;
  border-color: #d3dde3 !important;
}

html:not([data-biblio-theme="night"]) #wrap-kleinert .k-ch-card,
html[data-biblio-theme="basic"] #wrap-kleinert .k-ch-card,
html:not([data-biblio-theme="night"]) #wrap-kleinert .k-formula,
html[data-biblio-theme="basic"] #wrap-kleinert .k-formula,
html:not([data-biblio-theme="night"]) #wrap-kleinert .k-pv-card,
html[data-biblio-theme="basic"] #wrap-kleinert .k-pv-card,
html:not([data-biblio-theme="night"]) #k-panel .pc-formula-box,
html[data-biblio-theme="basic"] #k-panel .pc-formula-box,
html:not([data-biblio-theme="night"]) #k-panel .pane .pf-inline,
html[data-biblio-theme="basic"] #k-panel .pane .pf-inline {
  background: #fff !important;
  border-color: #d3dde3 !important;
}

html:not([data-biblio-theme="night"]) #wrap-kleinert .k-ch-card:hover,
html[data-biblio-theme="basic"] #wrap-kleinert .k-ch-card:hover,
html:not([data-biblio-theme="night"]) #wrap-kleinert .k-formula:hover,
html[data-biblio-theme="basic"] #wrap-kleinert .k-formula:hover,
html:not([data-biblio-theme="night"]) #wrap-kleinert .k-formula.active,
html[data-biblio-theme="basic"] #wrap-kleinert .k-formula.active,
html:not([data-biblio-theme="night"]) #wrap-kleinert .k-pv-card:hover,
html[data-biblio-theme="basic"] #wrap-kleinert .k-pv-card:hover {
  background: #edf5fa !important;
  border-color: #6a92b5 !important;
}

html:not([data-biblio-theme="night"]) #wrap-kleinert .k-title,
html[data-biblio-theme="basic"] #wrap-kleinert .k-title,
html:not([data-biblio-theme="night"]) #wrap-kleinert .k-ch-title,
html[data-biblio-theme="basic"] #wrap-kleinert .k-ch-title,
html:not([data-biblio-theme="night"]) #wrap-kleinert .k-sec-title,
html[data-biblio-theme="basic"] #wrap-kleinert .k-sec-title,
html:not([data-biblio-theme="night"]) #wrap-kleinert .k-pv-stat-num,
html[data-biblio-theme="basic"] #wrap-kleinert .k-pv-stat-num,
html:not([data-biblio-theme="night"]) #wrap-kleinert .k-pv-card-title,
html[data-biblio-theme="basic"] #wrap-kleinert .k-pv-card-title,
html:not([data-biblio-theme="night"]) #k-panel .pc-title,
html[data-biblio-theme="basic"] #k-panel .pc-title,
html:not([data-biblio-theme="night"]) #k-panel .pane strong,
html[data-biblio-theme="basic"] #k-panel .pane strong {
  color: #243d54 !important;
}

html:not([data-biblio-theme="night"]) #wrap-kleinert .k-subtitle,
html[data-biblio-theme="basic"] #wrap-kleinert .k-subtitle,
html:not([data-biblio-theme="night"]) #wrap-kleinert .k-intro,
html[data-biblio-theme="basic"] #wrap-kleinert .k-intro,
html:not([data-biblio-theme="night"]) #wrap-kleinert .k-sec-kor,
html[data-biblio-theme="basic"] #wrap-kleinert .k-sec-kor,
html:not([data-biblio-theme="night"]) #wrap-kleinert .k-sec-intro,
html[data-biblio-theme="basic"] #wrap-kleinert .k-sec-intro,
html:not([data-biblio-theme="night"]) #wrap-kleinert .k-ch-kor,
html[data-biblio-theme="basic"] #wrap-kleinert .k-ch-kor,
html:not([data-biblio-theme="night"]) #wrap-kleinert .k-pv-card-note,
html[data-biblio-theme="basic"] #wrap-kleinert .k-pv-card-note,
html:not([data-biblio-theme="night"]) #k-panel .empty-txt,
html[data-biblio-theme="basic"] #k-panel .empty-txt,
html:not([data-biblio-theme="night"]) #k-panel .pane p,
html[data-biblio-theme="basic"] #k-panel .pane p,
html:not([data-biblio-theme="night"]) #k-panel .lineage-text,
html[data-biblio-theme="basic"] #k-panel .lineage-text {
  color: #4b6172 !important;
}

html:not([data-biblio-theme="night"]) #wrap-kleinert .k-sitemap-title,
html[data-biblio-theme="basic"] #wrap-kleinert .k-sitemap-title,
html:not([data-biblio-theme="night"]) #wrap-kleinert .k-ch-num,
html[data-biblio-theme="basic"] #wrap-kleinert .k-ch-num,
html:not([data-biblio-theme="night"]) #wrap-kleinert .k-pv-bar-hint,
html[data-biblio-theme="basic"] #wrap-kleinert .k-pv-bar-hint,
html:not([data-biblio-theme="night"]) #wrap-kleinert .k-pv-stat-label,
html[data-biblio-theme="basic"] #wrap-kleinert .k-pv-stat-label {
  color: #5b6875 !important;
}

html:not([data-biblio-theme="night"]) #wrap-kleinert .k-banner,
html[data-biblio-theme="basic"] #wrap-kleinert .k-banner,
html:not([data-biblio-theme="night"]) #wrap-kleinert .k-section-head,
html[data-biblio-theme="basic"] #wrap-kleinert .k-section-head,
html:not([data-biblio-theme="night"]) #k-panel .tabs,
html[data-biblio-theme="basic"] #k-panel .tabs,
html:not([data-biblio-theme="night"]) #k-panel .lineage-step:not(:last-child),
html[data-biblio-theme="basic"] #k-panel .lineage-step:not(:last-child) {
  border-color: #d5dee3 !important;
}

html:not([data-biblio-theme="night"]) #k-panel,
html[data-biblio-theme="basic"] #k-panel {
  background: #fff !important;
  border-color: #d5dee3 !important;
}

html:not([data-biblio-theme="night"]) #wrap-kleinert .kf-display .katex,
html[data-biblio-theme="basic"] #wrap-kleinert .kf-display .katex,
html:not([data-biblio-theme="night"]) #wrap-kleinert .k-pv-card-latex .katex,
html[data-biblio-theme="basic"] #wrap-kleinert .k-pv-card-latex .katex,
html:not([data-biblio-theme="night"]) #k-panel .pc-formula-box .katex,
html[data-biblio-theme="basic"] #k-panel .pc-formula-box .katex,
html:not([data-biblio-theme="night"]) #k-panel .pane .pf-inline .katex,
html[data-biblio-theme="basic"] #k-panel .pane .pf-inline .katex {
  color: #1e3040 !important;
}

html:not([data-biblio-theme="night"]) #wrap-kleinert .k-pv-card-latex,
html[data-biblio-theme="basic"] #wrap-kleinert .k-pv-card-latex {
  background: #eef3f5 !important;
}

html:not([data-biblio-theme="night"]) .zijie-grid,
html[data-biblio-theme="basic"] .zijie-grid {
  background: #f1f5f2 !important;
  border-color: #d7dfda !important;
}

html[data-biblio-theme="night"] .biblio-theme-control {
  border-color: #3a3935;
  background: rgba(17, 17, 16, 0.96);
  box-shadow: 0 3px 16px rgba(0, 0, 0, 0.3);
}

html[data-biblio-theme="night"] .biblio-theme-label,
html[data-biblio-theme="night"] .biblio-theme-button {
  color: #bcb7aa;
  border-color: #3a3935;
}

html[data-biblio-theme="night"] .biblio-theme-button:hover {
  background: #292823;
}

html[data-biblio-theme="night"] .biblio-theme-button[aria-pressed="true"] {
  background: #b18b42;
  color: #111;
}

html[data-biblio-theme="night"] .biblio-load-status {
  border-color: #3a3935;
  background: #171715;
  color: #d8d2c4;
}

@media (max-width: 760px) {
  .biblio-theme-control--desktop {
    display: none;
  }

  #mob-bottom-nav {
    display: none !important;
  }

  .book-wrap {
    bottom: 0 !important;
  }

  .book-wrap > .main,
  .book-wrap > main {
    padding-bottom: 7rem !important;
  }

  .biblio-theme-control--mobile {
    margin-left: auto;
    margin-right: 4px;
    min-height: 30px;
    box-shadow: none;
  }

  .biblio-theme-control--mobile .biblio-theme-label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
  }

  .biblio-theme-control--mobile .biblio-theme-button {
    min-width: 42px;
    height: 28px;
    padding: 0 6px;
    font-size: 9px;
    line-height: 28px;
  }

  .biblio-load-status {
    right: 12px;
    bottom: 66px;
  }

  .main,
  .book-wrap,
  .book-inner,
  .chapter,
  .formula-card,
  .panel-content,
  .pane {
    min-width: 0 !important;
    max-width: 100% !important;
    overflow-wrap: anywhere;
  }

  .formula-display,
  .formula-box,
  .pc-formula-box,
  .k-formula,
  .table-wrap,
  .equation-wrap,
  pre {
    max-width: 100% !important;
    overflow-x: auto !important;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
  }

  table {
    width: max-content;
    min-width: 100%;
  }
}

@media (min-width: 761px) {
  .biblio-theme-control--mobile {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .biblio-theme-control *,
  .biblio-load-status {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
