/* Site theme. The independent reading page keeps its own paper and ink. */
html[data-site-theme="light"] {
  color-scheme: light;
}

html[data-site-theme="dark"] {
  color-scheme: dark;
  --paper: #171618;
  --paper-deep: #262226;
  --ink: #f0e9df;
  --muted: #b8aba3;
  --wine: #e5a1b5;
  --wine-dark: #542936;
  --line: #40373d;
  --site-panel: #211e22;
  --site-edge: #6e5662;
  --site-button: #74364b;
  --site-button-hover: #88445b;
  --site-accent-soft: #3a2831;
}

/* The extra header action uses the existing search/menu rhythm in both themes. */
.site-theme-toggle {
  flex-shrink: 0;
  border: 0;
}

.site-theme-toggle .icon {
  width: 20px;
  height: 20px;
}

@media (max-width: 680px) {
  .header-actions .site-theme-toggle {
    width: 37px;
    height: 37px;
  }
}

/* Shared controls: rose is a foreground accent; filled controls stay burgundy. */
html[data-site-theme="dark"] ::selection {
  background: #784354;
  color: #fff5ec;
}

html[data-site-theme="dark"] :is(button, a, input, select, textarea, summary):focus-visible {
  outline-color: #f0bacb;
}

html[data-site-theme="dark"] .text-link {
  border-color: #7e6873;
}

html[data-site-theme="dark"] .text-link:hover {
  border-color: var(--wine);
}

html[data-site-theme="dark"] .btn,
html[data-site-theme="dark"] .icon-btn.active,
html[data-site-theme="dark"] .filter-tab.active,
html[data-site-theme="dark"] .shelf-count,
html[data-site-theme="dark"] .skip-link {
  background: var(--site-button);
  border-color: var(--site-button);
  color: #fff7ef;
}

html[data-site-theme="dark"] .btn:hover,
html[data-site-theme="dark"] .icon-btn.active:hover,
html[data-site-theme="dark"] .filter-tab.active:hover {
  background: var(--site-button-hover);
  border-color: var(--site-button-hover);
}

html[data-site-theme="dark"] .btn.secondary {
  background: transparent;
  border-color: #675560;
  color: var(--ink);
}

html[data-site-theme="dark"] .btn.secondary:hover {
  background: var(--paper-deep);
  border-color: #937581;
}

html[data-site-theme="dark"] .btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--wine);
}

html[data-site-theme="dark"] .btn.ghost:hover {
  background: var(--site-accent-soft);
}

html[data-site-theme="dark"] .btn.light {
  background: #f0e7dc;
  border-color: #f0e7dc;
  color: #542936;
}

html[data-site-theme="dark"] .btn.light:hover {
  background: #dfcfc1;
  border-color: #dfcfc1;
}

/* Navigation and the fixed mobile shortcuts. */
html[data-site-theme="dark"] .site-header,
html[data-site-theme="dark"] .mobile-dock {
  background: rgba(23, 22, 24, .97);
}

html[data-site-theme="dark"] .desktop-nav a {
  color: #cbbfb5;
}

html[data-site-theme="dark"] .desktop-nav a:hover,
html[data-site-theme="dark"] .desktop-nav a.current {
  color: var(--wine);
}

html[data-site-theme="dark"] .shelf-link:hover {
  background: var(--paper-deep);
  border-color: var(--site-edge);
}

html[data-site-theme="dark"] .mobile-menu {
  background: #201d21;
  box-shadow: 0 15px 30px #0005;
}

html[data-site-theme="dark"] .mobile-menu a:hover {
  color: var(--wine);
  background: #2a2329;
}

/* Opening spread and the four-book carousel. */
html[data-site-theme="dark"] :is(.hero-description, .hero-note, .hero-edition) {
  color: var(--muted);
}

html[data-site-theme="dark"] .hero-note span + span {
  border-color: #5a474f;
}

html[data-site-theme="dark"] .hero-art::before {
  background: #2d242a;
  box-shadow: inset 0 0 70px #a56d7c13;
}

html[data-site-theme="dark"] .hero-art::after,
html[data-site-theme="dark"] .hero-ring {
  border-color: #55414b;
}

html[data-site-theme="dark"] .hero-book {
  box-shadow: 7px 22px 30px #0008;
}

html[data-site-theme="dark"] .hero-floor {
  background: #0008;
}

html[data-site-theme="dark"] .hero-feature {
  background: #272127;
  border-color: #51404a;
  box-shadow: 0 8px 28px #0004;
}

html[data-site-theme="dark"] .hero-feature:hover {
  border-color: #947080;
}

html[data-site-theme="dark"] .hero-carousel-arrow:hover,
html[data-site-theme="dark"] .hero-carousel-play:hover {
  background: #30262e;
  border-color: #6d505e;
}

html[data-site-theme="dark"] .hero-carousel-dot span {
  background: #8e7681;
}

html[data-site-theme="dark"] .hero-carousel-dot[aria-pressed="true"] span,
html[data-site-theme="dark"] .hero-carousel-dot:hover span {
  background: var(--wine);
}

html[data-site-theme="dark"] .hero-controls-divider {
  background: #5c4751;
}

html[data-site-theme="dark"] .intro-line {
  background: #1f1c1f;
}

html[data-site-theme="dark"] .intro-line-inner {
  color: #c1b2a9;
}

html[data-site-theme="dark"] .intro-line .divider {
  background: #9b7d89;
}

/* Collection, saved books and book-detail surfaces. */
html[data-site-theme="dark"] .book-card-media {
  background: #2d2529;
}

html[data-site-theme="dark"] .book-card:nth-child(2) .book-card-media {
  background: #272b28;
}

html[data-site-theme="dark"] .book-card:nth-child(3) .book-card-media {
  background: #2d272d;
}

html[data-site-theme="dark"] .book-card:nth-child(4) .book-card-media {
  background: #252c2f;
}

html[data-site-theme="dark"] .book-card .cover-link,
html[data-site-theme="dark"] .detail-cover-well img {
  box-shadow: 8px 14px 22px #0007;
}

html[data-site-theme="dark"] .book-card-media:hover .cover-link {
  box-shadow: 8px 20px 26px #0008;
}

html[data-site-theme="dark"] .status-tag {
  background: #1c191eea;
  color: #d7cbbf;
}

html[data-site-theme="dark"] .status-tag.ongoing {
  color: var(--wine);
}

html[data-site-theme="dark"] .book-card-media .bookmark-button {
  background: #1b181de6;
  color: #e9ded3;
}

html[data-site-theme="dark"] .bookmark-button.saved,
html[data-site-theme="dark"] .book-card-media .bookmark-button.saved {
  background: var(--site-accent-soft);
  color: var(--wine);
}

html[data-site-theme="dark"] .book-card-media .bookmark-button:hover {
  background: #49313e;
  color: #ffe4ed;
}

html[data-site-theme="dark"] :is(.book-kicker, .book-desc, .chapter-order, .preview-note) {
  color: var(--muted);
}

html[data-site-theme="dark"] .empty-state {
  border-color: #64515c;
}

html[data-site-theme="dark"] .empty-state > .icon {
  color: var(--wine);
}

html[data-site-theme="dark"] :is(.resume-banner, .reading-invite, .detail-aside) {
  background: #252025;
}

html[data-site-theme="dark"] .detail-cover-well {
  background: #2c2429;
}

html[data-site-theme="dark"] .detail-cover-well::before {
  border-color: #65505a;
}

html[data-site-theme="dark"] .chapter-row:hover {
  background: #292228;
}

/* Author, events, artwork, community and footer. No image colour filters. */
html[data-site-theme="dark"] .author-section {
  background: #211d21;
}

html[data-site-theme="dark"] .portrait-caption {
  background: #292329;
  box-shadow: 0 9px 22px #0004;
}

html[data-site-theme="dark"] .author-copy p {
  color: var(--muted);
}

html[data-site-theme="dark"] .author-years {
  border-color: var(--line);
}

html[data-site-theme="dark"] .event-empty {
  background: #252025;
  border-color: var(--line);
}

html[data-site-theme="dark"] :is(.archive-label, .past-tag, .event-note) {
  color: var(--muted);
}

html[data-site-theme="dark"] .past-tag {
  background: #231e23;
}

html[data-site-theme="dark"] .gallery-image {
  background: #292329;
}

html[data-site-theme="dark"] .gallery-card .zoom-mark {
  background: #231e23;
  color: #f6e9df;
  box-shadow: 0 0 0 1px #ffffff20;
}

html[data-site-theme="dark"] .community-card {
  background: #432631;
  color: #fff1e7;
  box-shadow: inset 0 0 0 1px #704253;
}

html[data-site-theme="dark"] .community-card::after {
  border-color: #bd889d35;
}

html[data-site-theme="dark"] .community-card p {
  color: #ddc2c7;
}

html[data-site-theme="dark"] .community-links a {
  border-color: #a77e8c;
}

html[data-site-theme="dark"] .community-links a:hover {
  background: #ffffff12;
}

html[data-site-theme="dark"] .community-links a.primary {
  background: #f0e7dc;
  border-color: #f0e7dc;
  color: #542936;
}

html[data-site-theme="dark"] .community-links a.primary:hover {
  background: #dfcfc1;
  border-color: #dfcfc1;
}

html[data-site-theme="dark"] :is(.footer-top p, .footer-bottom) {
  color: var(--muted);
}

html[data-site-theme="dark"] .footer-links a:hover {
  color: var(--wine);
}

/* Search, forms and utility dialogs share the same raised charcoal surface. */
html[data-site-theme="dark"] .search-field {
  border-color: #6e5864;
}

html[data-site-theme="dark"] :is(.search-field input, .global-search-field input) {
  color: var(--ink);
  caret-color: var(--wine);
}

html[data-site-theme="dark"] :is(input, textarea)::placeholder {
  color: #ab9d95;
  opacity: 1;
}

html[data-site-theme="dark"] .contact-form {
  background: var(--site-panel);
}

html[data-site-theme="dark"] :is(.field input, .field select, .field textarea, .note-textarea) {
  background: #19171b;
  border-color: #61505a;
  color: var(--ink);
  caret-color: var(--wine);
}

html[data-site-theme="dark"] :is(.field input, .field select, .field textarea):hover {
  border-color: #8b6c7c;
}

html[data-site-theme="dark"] .minimal-select {
  color: #d7c9bf;
  border-color: #66515e;
  background: #211c22;
}

html[data-site-theme="dark"] select option {
  background: #211e22;
  color: #f0e9df;
}

html[data-site-theme="dark"] input:-webkit-autofill {
  -webkit-box-shadow: 0 0 0 40px #211e22 inset;
  -webkit-text-fill-color: #f0e9df;
  caret-color: var(--wine);
}

html[data-site-theme="dark"] dialog {
  color-scheme: dark;
  background: var(--site-panel);
  color: var(--ink);
  border-color: #57454f;
  box-shadow: 0 24px 85px #0008;
}

html[data-site-theme="dark"] dialog::backdrop {
  background: #09070bce;
}

html[data-site-theme="dark"] .search-result:hover {
  background: #30262f;
}

html[data-site-theme="dark"] .global-search-field kbd {
  background: #2b242b;
  border-color: #67515e;
}

html[data-site-theme="dark"] :is(.font-control, .draft-preview) {
  background: #292329;
}

html[data-site-theme="dark"] .font-control button:hover:not(:disabled) {
  background: #44313e;
  border-radius: 4px;
}

html[data-site-theme="dark"] .theme-options button.active {
  border-color: #b86e87;
  outline: 2px solid var(--wine);
  outline-offset: 3px;
}

html[data-site-theme="dark"] .theme-options button[data-theme="light"],
html[data-site-theme="dark"] .theme-options button[data-theme="sepia"] {
  color-scheme: light;
}

html[data-site-theme="dark"] .theme-options button[data-theme="dark"] {
  color-scheme: dark;
  box-shadow: 0 0 0 1px #67535f;
}

html[data-site-theme="dark"] .lightbox {
  background: #151316;
  border-color: #4e3e48;
  color: #f4eae0;
}

html[data-site-theme="dark"] :is(.lightbox-close, .lightbox-arrow) {
  background: #251e26e8;
  border-color: #79616e;
  color: #f4eae0;
}

html[data-site-theme="dark"] :is(.lightbox-close, .lightbox-arrow):hover {
  background: #45313e;
}

html[data-site-theme="dark"] .lightbox-caption {
  border-color: #44353e;
}

html[data-site-theme="dark"] .toast {
  background: #382a33;
  color: #fff0e5;
  border: 1px solid #806171;
  box-shadow: 0 8px 28px #0006;
}

/* A retained data-reader-theme must not affect normal pages after leaving a book. */
body.reader-mode[data-reader-theme="dark"] {
  color-scheme: dark;
}

body.reader-mode[data-reader-theme="light"],
body.reader-mode[data-reader-theme="sepia"] {
  color-scheme: light;
}

/* Keep the viewport scrollbar in the reading page's chosen native colour scheme. */
@supports selector(:has(*)) {
  html:has(> body.reader-mode[data-reader-theme="dark"]) {
    color-scheme: dark;
  }

  html:has(> body.reader-mode:is([data-reader-theme="light"], [data-reader-theme="sepia"])) {
    color-scheme: light;
  }
}

/* Only the reader content gets its paper-friendly accent; dialogs stay site-themed. */
html[data-site-theme="dark"] body.reader-mode:is([data-reader-theme="light"], [data-reader-theme="sepia"]) #main {
  --wine: #762f40;
  --wine-dark: #522432;
  --muted: #75665d;
}

html[data-site-theme="dark"] body.reader-mode #main .reader-tools .bookmark-button.saved {
  background: var(--reader-soft);
  border-color: var(--reader-border);
  color: var(--wine);
}

html[data-site-theme="dark"] body.reader-mode #main .reader-toc .preview-note {
  color: inherit;
}

html[data-site-theme="dark"] body.reader-mode:is([data-reader-theme="light"], [data-reader-theme="sepia"]) #main :is(button, a, input, select, textarea, summary):focus-visible {
  outline-color: #9a3e58;
}

/* A light site still uses light dialogs when the reader itself is in night mode. */
html[data-site-theme="light"] dialog {
  color-scheme: light;
}
