/* The account preference is rendered on <html> before the first paint. */
.theme-choices {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
}
.theme-choice { position: relative; }
.theme-choice-input {
    position: absolute;
    top: 1.1rem;
    right: 0.9rem;
    width: 1rem;
    height: 1rem;
    accent-color: #0d6efd;
}
.theme-choice-label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    height: 100%;
    padding: 1rem 2.5rem 1rem 1rem;
    border: 1px solid var(--bs-border-color);
    border-radius: 0.5rem;
    background: var(--bs-body-bg);
    cursor: pointer;
}
.theme-choice-label strong, .theme-choice-label small { display: block; }
.theme-choice-label small { margin-top: 0.2rem; color: var(--bs-secondary-color); font-size: 0.8rem; }
.theme-choice-label i { font-size: 1.4rem; }
.theme-day-icon { color: #d29500; }
.theme-night-icon { color: #8768d8; }
.theme-choice-input:checked + .theme-choice-label {
    border-color: #0d6efd;
    box-shadow: 0 0 0 1px #0d6efd;
    background: var(--bs-primary-bg-subtle);
}
.theme-choice-input:focus-visible + .theme-choice-label { outline: 2px solid #0d6efd; outline-offset: 3px; }
@media (max-width: 575.98px) {
    .theme-choices { grid-template-columns: 1fr; }
}

html[data-bs-theme="dark"] {
    --bs-body-bg: #14181e;
    --bs-body-bg-rgb: 20, 24, 30;
    --bs-body-color: #e2e7ee;
    --bs-body-color-rgb: 226, 231, 238;
    --bs-secondary-bg: #252c35;
    --bs-tertiary-bg: #1b2129;
    --bs-tertiary-bg-rgb: 27, 33, 41;
    --bs-border-color: #424c5a;
    --site-nav-bg: #252c35;
    --site-nav-border: #424c5a;
    --site-nav-color: #e2e7ee;
    --site-nav-hover-bg: #313c4a;
    --site-nav-hover-border: #61718a;
    --site-nav-hover-color: #9ec5fe;
    --site-layout-link-color: #8cbbff;
}
html[data-bs-theme="dark"] .site-navbar {
    box-shadow: 0 0.35rem 1rem #0005 !important;
}
html[data-bs-theme="dark"] .site-navbar .navbar-brand { color: #e2e7ee; }
html[data-bs-theme="dark"] .site-footer { border-color: #424c5a !important; }
html[data-bs-theme="dark"] .btn-outline-secondary {
    --bs-btn-color: #c3ccd9;
    --bs-btn-border-color: #61718a;
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: #394658;
    --bs-btn-hover-border-color: #788ba7;
    --bs-btn-active-bg: #394658;
    --bs-btn-active-border-color: #788ba7;
}
html[data-bs-theme="dark"] .book-toolbar .book-search .book-search-menu {
    background: #1b2129;
    border-color: #424c5a;
    box-shadow: 0 0.6rem 1.5rem #0007;
}
html[data-bs-theme="dark"] .book-search-menu .dropdown-item { color: #e2e7ee; border-color: #424c5a; }
html[data-bs-theme="dark"] .book-search-menu .dropdown-item:hover,
html[data-bs-theme="dark"] .book-search-menu .dropdown-item:focus,
html[data-bs-theme="dark"] .book-search-menu .book-search-active { background: #293b53; color: #fff; }
html[data-bs-theme="dark"] .book-search-detail,
html[data-bs-theme="dark"] .book-search-people-label { color: #b7c1cf; }
html[data-bs-theme="dark"] .book-search-menu mark { color: #8cbbff; }
html[data-bs-theme="dark"] .book-loading-overlay { background: #14181ed9; }
html[data-bs-theme="dark"] .book-loading-dialog { background: #1b2129; color: #e2e7ee; border-color: #424c5a; }
html[data-bs-theme="dark"] .book-loading-text { color: #b7c1cf; }
html[data-bs-theme="dark"] .book-loading-overlay.has-error .book-loading-title { color: #ea868f; }

/* These legacy surfaces use fixed light colors instead of Bootstrap variables. */
html[data-bs-theme="dark"] .tag-suggestions-list,
html[data-bs-theme="dark"] .tag-add-modal-content .modal-header,
html[data-bs-theme="dark"] .tag-add-modal-content .modal-footer { background: #252c35; border-color: #424c5a; }
html[data-bs-theme="dark"] .tag-suggestion:not(.is-exact),
html[data-bs-theme="dark"] .place-google-candidate { background: #1b2129; color: #e2e7ee; border-color: #424c5a; }
html[data-bs-theme="dark"] .place-google-candidate.is-selected { background: #293b53; border-color: #6ea8fe; }
html[data-bs-theme="dark"] .tag-suggestion:not(.is-exact) .tag-suggestion-comment,
html[data-bs-theme="dark"] .tag-suggestions-empty,
html[data-bs-theme="dark"] .place-google-candidate-address,
html[data-bs-theme="dark"] .place-google-candidate-id { color: #b7c1cf; }
html[data-bs-theme="dark"] .event-action-status,
html[data-bs-theme="dark"] .place-action-status { color: #9ec5fe; background: #172b45; border-color: #355980; }
html[data-bs-theme="dark"] .place-action-status.is-danger { color: #ea868f; background: #3c1f25; border-color: #85414b; }
html[data-bs-theme="dark"] .place-action-status.is-success { color: #8bd5b2; background: #193b2d; border-color: #3c7560; }
html[data-bs-theme="dark"] .place-action-status.is-warning { color: #ffda6a; background: #3d331c; border-color: #856a28; }
html[data-bs-theme="dark"] .place-action-status.is-muted { color: #b7c1cf; background: #252c35; border-color: #424c5a; }
html[data-bs-theme="dark"] .event-duallist-persons { background: #30232a; border-color: #71424e; }
html[data-bs-theme="dark"] .event-duallist-tags { background: #1c3025; border-color: #3e6a4a; }
html[data-bs-theme="dark"] .event-duallist-persons .event-duallist-title { color: #f1b5c2; background: #482e37; border-color: #71424e; }
html[data-bs-theme="dark"] .event-duallist-tags .event-duallist-title { color: #a1d5af; background: #2a4634; border-color: #3e6a4a; }
html[data-bs-theme="dark"] .event-duallist-move { color: #c3ccd9; }
html[data-bs-theme="dark"] .admin-table,
html[data-bs-theme="dark"] .admin-table tbody td { border-color: #424c5a; }
html[data-bs-theme="dark"] .admin-table thead th { background: #252c35; color: #e2e7ee; border-color: #61718a; }
html[data-bs-theme="dark"] .admin-table-refresh { color: #e2e7ee; }
html[data-bs-theme="dark"] .admin-table-refresh:hover,
html[data-bs-theme="dark"] .admin-table-refresh:focus { background: #313c4a; color: #e2e7ee; border-color: #61718a; }

/* This light subtree keeps Bootstrap tables, links and paper exactly as in day mode.
   Semantic button/icon colors are deliberately left unchanged; no image inversion. */
#book[data-bs-theme="light"] { color-scheme: light; }

/* Sort headings contain their own links, whose utility class overrides <th>. */
html[data-bs-theme="dark"] .admin-table thead .link-dark {
    color: #e2e7ee !important;
}
html[data-bs-theme="dark"] .admin-table thead .link-dark:hover,
html[data-bs-theme="dark"] .admin-table thead .link-dark:focus-visible {
    color: #9ec5fe !important;
}

html[data-bs-theme="dark"] .other-sites-intro,
html[data-bs-theme="dark"] .other-sites-separator { border-color: #424c5a; }
html[data-bs-theme="dark"] .other-sites-intro h1,
html[data-bs-theme="dark"] .other-sites-archive-head h2,
html[data-bs-theme="dark"] .other-site-domain { color: #e2e7ee; }
html[data-bs-theme="dark"] .other-sites-kicker,
html[data-bs-theme="dark"] .other-sites-intro p,
html[data-bs-theme="dark"] .other-sites-archive-head p:last-child,
html[data-bs-theme="dark"] .other-site-description,
html[data-bs-theme="dark"] .other-site-link-label-muted { color: #b7c1cf; }
html[data-bs-theme="dark"] .other-site-card,
html[data-bs-theme="dark"] .other-sites-archive-panel { color: #e2e7ee; background: #1b2129; border-color: #424c5a; box-shadow: 0 0.5rem 1.25rem #0003; }
html[data-bs-theme="dark"] a.other-site-card:hover,
html[data-bs-theme="dark"] a.other-site-card:focus { border-color: #6ea8fe; color: #e2e7ee; }
html[data-bs-theme="dark"] .other-site-tag,
html[data-bs-theme="dark"] .abandoned-domain { color: #d2dbe8; background: #2c3542; border-color: #536176; }
html[data-bs-theme="dark"] .other-site-link-label:not(.other-site-link-label-muted),
html[data-bs-theme="dark"] .abandoned-domain:hover,
html[data-bs-theme="dark"] .abandoned-domain:focus { color: #8cbbff; }
