/* Night mode — paired with theme.js (localStorage key: lib-theme) */

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

html[data-theme="dark"] body {
  background: #141618;
  color: #e6e8eb;
}

/* Links: skip Calibre bodies — those use .calibre invert stack below */
html[data-theme="dark"] body:not(.zhuangzi-book):not([class*="iching-"]) a:link {
  color: #8ec8e8;
}

html[data-theme="dark"] body:not(.zhuangzi-book):not([class*="iching-"]) a:visited {
  color: #b0a8d8;
}

html[data-theme="dark"] body:not(.zhuangzi-book):not([class*="iching-"]) a:hover {
  color: #b8e8ff;
}

html[data-theme="dark"] body:not(.zhuangzi-book):not([class*="iching-"]) a:active {
  color: #d0f0ff;
}

html[data-theme="dark"] blockquote {
  border-left-color: #3a4048;
}

html[data-theme="dark"] p > code {
  background: #2a2f36;
  color: #e8ecf0;
}

html[data-theme="dark"] hr {
  border-color: #3a4048;
  color: #3a4048;
}

html[data-theme="dark"] hr.style2 {
  border-top-color: #5a6068;
}

html[data-theme="dark"] .quiet {
  color: #8a9199;
}

/* Library index */
html[data-theme="dark"] body.library-index {
  background: #121418;
}

html[data-theme="dark"] body.library-index h1 {
  color: #c5d0e0;
}

html[data-theme="dark"] body.library-index h2 {
  color: #9aacbc;
  border-bottom-color: #3a4450;
}

html[data-theme="dark"] body.library-index dd.meta {
  color: #8a96a6;
}

html[data-theme="dark"] body.library-index dd.desc {
  color: #c8d0da;
}

/*
 * Calibre exports (Zhuangzi + I Ching): invert the main column so hard-coded
 * light-theme colors read correctly in dark mode without editing merged style.css.
 * Raster media is double-inverted so illustrations stay natural.
 */
html[data-theme="dark"] body.zhuangzi-book,
html[data-theme="dark"] body[class*="iching-"] {
  background: #0a0a0a;
}

html[data-theme="dark"] body.zhuangzi-book > .calibre,
html[data-theme="dark"] body[class*="iching-"] > .calibre {
  filter: invert(1) hue-rotate(180deg);
  -webkit-filter: invert(1) hue-rotate(180deg);
}

html[data-theme="dark"] body.zhuangzi-book > .calibre img,
html[data-theme="dark"] body[class*="iching-"] > .calibre img,
html[data-theme="dark"] body.zhuangzi-book > .calibre video,
html[data-theme="dark"] body[class*="iching-"] > .calibre video {
  filter: invert(1) hue-rotate(180deg);
  -webkit-filter: invert(1) hue-rotate(180deg);
}

/* Index: floating theme control */
.lib-theme-toggle {
  position: fixed;
  top: max(0.65rem, env(safe-area-inset-top));
  right: max(0.65rem, env(safe-area-inset-right));
  z-index: 9999;
  margin: 0;
  padding: 0.45rem 0.75rem;
  font: inherit;
  font-size: 0.85rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border: 1px solid #c0c8d0;
  border-radius: 6px;
  background: rgba(250, 251, 252, 0.92);
  color: #3a4a5a;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

html[data-theme="dark"] .lib-theme-toggle {
  border-color: #4a5560;
  background: rgba(36, 40, 48, 0.92);
  color: #c8d4e0;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.lib-theme-toggle:focus-visible {
  outline: 2px solid #3a6d8c;
  outline-offset: 2px;
}
