/* Persistent site theme switcher. Light is the default. */
.kn-theme-toggle {
    flex: 0 0 var(--kn-header-control-size, 48px);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--kn-header-control-size, 48px);
    min-width: var(--kn-header-control-size, 48px);
    height: var(--kn-header-control-size, 48px);
    min-height: var(--kn-header-control-size, 48px);
    padding: 0;
    border: 1px solid var(--kn-line);
    border-radius: var(--kn-header-control-radius, 16px);
    background: var(--kn-surface-soft);
    background-image: none !important;
    color: var(--kn-ink);
    box-shadow: none !important;
    overflow: hidden;
    isolation: isolate;
    cursor: pointer;
    transition: background-color .2s ease, border-color .2s ease, color .2s ease;
}

.kn-theme-toggle__track {
    display: block;
    width: 34px;
    height: 20px;
    padding: 2px;
    border-radius: 999px;
    background: var(--kn-line);
}

.kn-theme-toggle__thumb {
    display: grid;
    width: 16px;
    height: 16px;
    place-items: center;
    border-radius: 50%;
    background: var(--kn-surface);
    color: var(--kn-accent-strong);
    transform: translateX(0);
    transition: transform .2s ease, background-color .2s ease, color .2s ease;
}

.kn-theme-toggle svg {
    width: 12px;
    height: 12px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.8;
}

.kn-theme-toggle__moon { display: none; }

html[data-theme="dark"] .kn-theme-toggle__thumb { transform: translateX(14px); }
html[data-theme="dark"] .kn-theme-toggle__sun { display: none; }
html[data-theme="dark"] .kn-theme-toggle__moon { display: block; }

html[data-theme="dark"] {
    --kn-bg: #111b21;
    --kn-bg-deep: #0b1217;
    --kn-surface: #1b2a31;
    --kn-surface-soft: #22353c;
    --kn-surface-glass: rgba(27, 42, 49, .78);
    --kn-ink: #edf5f2;
    --kn-ink-soft: #d3e3df;
    --kn-muted: #a9c2bf;
    --kn-slate: #c5d8d4;
    --kn-line: #3c555b;
    --kn-line-strong: #5a9b98;
    --kn-accent: #71c5bd;
    --kn-accent-strong: #70aaa6;
    --kn-accent-soft: #294a4b;
    --kn-card-status-bg: #477c7e;
    --rtb-dark-bg: var(--kn-surface);
    --rtb-dark-text: var(--kn-ink);
    color-scheme: dark;
}

html[data-theme="dark"] body {
    background: var(--kn-bg) !important;
    color: var(--kn-ink);
}

html[data-theme="dark"] .site,
html[data-theme="dark"] .site-content,
html[data-theme="dark"] .site-content.fixed,
html[data-theme="dark"] .site-content-inner,
html[data-theme="dark"] .content-area,
html[data-theme="dark"] .site-main,
html[data-theme="dark"] .home-content,
html[data-theme="dark"] .home-text,
html[data-theme="dark"] .taxonomy-description {
    background: transparent !important;
    color: var(--kn-ink) !important;
}

html[data-theme="dark"] .site-header-inner,
html[data-theme="dark"] .post-card--horizontal.kn-horizontal-card {
    border-color: rgba(113, 197, 189, .24);
    background-image: linear-gradient(135deg, rgba(61, 93, 97, .48), rgba(27, 42, 49, .88));
    box-shadow: 0 24px 60px rgba(0, 0, 0, .28), inset 0 1px 0 rgba(255, 255, 255, .06);
}

html[data-theme="dark"] .kf-list-book {
    border-color: rgba(113, 197, 189, .24);
    background:
        linear-gradient(90deg, rgba(var(--kn-accent-rgb), .12) 185px, transparent 185px),
        var(--kn-surface);
    box-shadow: 0 24px 60px rgba(0, 0, 0, .28), inset 0 1px 0 rgba(255, 255, 255, .06);
}

html[data-theme="dark"] .kn-single-book-card__button,
html[data-theme="dark"] .kn-single-book-card__library,
html[data-theme="dark"] .comments-area .comment-respond,
html[data-theme="dark"] .comments-area .comment-box {
    color: var(--kn-ink);
}

html[data-theme="dark"] input,
html[data-theme="dark"] textarea,
html[data-theme="dark"] select,
html[data-theme="dark"] .comment-form input,
html[data-theme="dark"] .comment-form textarea {
    border-color: var(--kn-line) !important;
    background: var(--kn-surface) !important;
    color: var(--kn-ink) !important;
}

html[data-theme="dark"] .kn-theme-toggle,
html[data-theme="dark"] .header-search .kn-search-trigger,
html[data-theme="dark"] .kn-mobile-menu-toggle {
    border-color: var(--kn-line);
    background: rgba(34, 53, 60, .86);
    color: var(--kn-ink);
}

html[data-theme="dark"] .kn-mobile-menu-toggle span {
    background: var(--kn-ink) !important;
}

html[data-theme="dark"] .kn-live-search .search-field,
html[data-theme="dark"] .kn-live-search__panel {
    border-color: rgba(113, 197, 189, .28);
    background-color: rgba(27, 42, 49, .86);
    color: var(--kn-ink);
}

html[data-theme="dark"] .kn-single-book-card__series > span,
html[data-theme="dark"] .kn-single-book-card__language > span {
    color: var(--kn-muted) !important;
}

html[data-theme="dark"] .kn-single-book-card__series strong,
html[data-theme="dark"] .kn-single-book-card__series strong a,
html[data-theme="dark"] .kn-single-book-card__series a,
html[data-theme="dark"] .kn-single-book-card__language strong,
html[data-theme="dark"] .kn-single-book-card__language strong a,
html[data-theme="dark"] .kn-single-book-card__language a {
    color: var(--kn-ink) !important;
}

html[data-theme="dark"] .kn-single-book-card__genre-list a {
    border-color: var(--kn-line) !important;
    background: var(--kn-surface-soft) !important;
    color: var(--kn-ink) !important;
}

html[data-theme="dark"] .kn-single-book-card__button {
    border-color: var(--kn-card-status-bg) !important;
    background: var(--kn-card-status-bg) !important;
    color: #ffffff !important;
}

html[data-theme="dark"] .kn-single-book-card__button:nth-child(n+2) {
    border-color: var(--kn-line) !important;
    background: var(--kn-surface-soft) !important;
    color: var(--kn-ink) !important;
}

html[data-theme="dark"] .kn-collection-card__meta span {
    border: 1px solid var(--kn-line) !important;
    background: var(--kn-surface-soft) !important;
    color: var(--kn-ink) !important;
}

html[data-theme="dark"] .kn-tax-card__meta span,
html[data-theme="dark"] .kn-follow-stats span,
html[data-theme="dark"] .kf-metric-pill {
    border-color: var(--kn-line) !important;
    background: var(--kn-surface-soft) !important;
    color: var(--kn-ink) !important;
}

html[data-theme="dark"] .page-numbers {
    border-color: var(--kn-line) !important;
    background: var(--kn-surface-soft) !important;
    color: var(--kn-ink) !important;
}

html[data-theme="dark"] .page-numbers.current,
html[data-theme="dark"] .page-numbers:hover {
    border-color: var(--kn-accent) !important;
    background: var(--kn-accent-strong) !important;
    color: #ffffff !important;
}

@media (max-width: 460px) {
    html[data-theme="dark"] .kf-list-book {
        background:
            linear-gradient(90deg, rgba(var(--kn-accent-rgb), .12) 116px, transparent 116px),
            var(--kn-surface);
    }
}

/* Dark surfaces: keep the hierarchy readable across every public template. */
html[data-theme="dark"] .kn-home-gateway__lead,
html[data-theme="dark"] .kn-home-gateway__panel,
html[data-theme="dark"] .kn-home-gateway__tiles a,
html[data-theme="dark"] .kn-home-collections,
html[data-theme="dark"] .kn-collection-card,
html[data-theme="dark"] .kn-collections-hero,
html[data-theme="dark"] .kn-collection-single__hero,
html[data-theme="dark"] .kn-collection-single__meta,
html[data-theme="dark"] .kn-catalog-toolbar,
html[data-theme="dark"] .kn-archive-toolbar,
html[data-theme="dark"] .kn-top100-toolbar,
html[data-theme="dark"] .kn-author-tools,
html[data-theme="dark"] .kn-series-tools,
html[data-theme="dark"] .kn-comments__shell,
html[data-theme="dark"] .kn-site-footer__shell {
    border-color: rgba(113, 197, 189, .25) !important;
    background: var(--kn-surface) !important;
    color: var(--kn-ink) !important;
    box-shadow: 0 22px 56px rgba(0, 0, 0, .26), inset 0 1px 0 rgba(255, 255, 255, .05) !important;
}

html[data-theme="dark"] .kn-home-gateway__art::before,
html[data-theme="dark"] .kn-home-gateway .ef-intro__visual {
    background-image: linear-gradient(90deg, rgba(27, 42, 49, .98) 0%, rgba(27, 42, 49, .78) 31%, rgba(27, 42, 49, .12) 68%, transparent 78%) !important;
}

html[data-theme="dark"] .kn-home-gateway__copy,
html[data-theme="dark"] .kn-home-gateway__copy h1,
html[data-theme="dark"] .kn-home-gateway__copy p,
html[data-theme="dark"] .kn-home-gateway__panel h2,
html[data-theme="dark"] .kn-home-gateway__stat,
html[data-theme="dark"] .kn-home-gateway__tile-copy strong,
html[data-theme="dark"] .kn-collection-card h2,
html[data-theme="dark"] .kn-collection-card p {
    color: var(--kn-ink) !important;
}

html[data-theme="dark"] .kn-home-gateway__actions a:not(.is-primary),
html[data-theme="dark"] .kn-home-gateway__books-total,
html[data-theme="dark"] .kn-home-collections__arrow,
html[data-theme="dark"] .kn-collection-single__meta-item,
html[data-theme="dark"] .kn-collection-rating__stars,
html[data-theme="dark"] .kn-collection-rating > a {
    border-color: var(--kn-line) !important;
    background: var(--kn-surface-soft) !important;
    color: var(--kn-ink) !important;
}

html[data-theme="dark"] .kn-comments__shell {
    background: var(--kn-surface) !important;
}

html[data-theme="dark"] .kn-comments__form {
    background: transparent !important;
}

html[data-theme="dark"] .kn-comments__counter,
html[data-theme="dark"] .kn-comments .comment-body,
html[data-theme="dark"] .kn-comments__empty,
html[data-theme="dark"] .kn-comments .no-comments,
html[data-theme="dark"] .kn-comments .nav-links a,
html[data-theme="dark"] .kn-comments #cancel-comment-reply-link {
    border-color: var(--kn-line) !important;
    background: var(--kn-surface-soft) !important;
    color: var(--kn-ink) !important;
}

html[data-theme="dark"] .kn-comments__form-card {
    border-color: var(--kn-line) !important;
    background: transparent !important;
    box-shadow: none !important;
}

html[data-theme="dark"] .kn-comments__title,
html[data-theme="dark"] .kn-comments__form-title,
html[data-theme="dark"] .kn-comments .comment-reply-title,
html[data-theme="dark"] .kn-comments .comment-author,
html[data-theme="dark"] .kn-comments .comment-content {
    color: var(--kn-ink) !important;
}

html[data-theme="dark"] .kn-comments__subtitle,
html[data-theme="dark"] .kn-comments__counter span,
html[data-theme="dark"] .kn-comments__field label,
html[data-theme="dark"] .kn-comments .comment-time {
    color: var(--kn-muted) !important;
}

html[data-theme="dark"] .kn-comments__field input,
html[data-theme="dark"] .kn-comments__field textarea {
    border-color: var(--kn-line) !important;
    background: #142229 !important;
    color: var(--kn-ink) !important;
}

html[data-theme="dark"] .kn-top-rank,
html[data-theme="dark"] .kn-top-row .kf-list-book {
    border-color: var(--kn-line) !important;
    background: var(--kn-surface) !important;
}

html[data-theme="dark"] .kn-controls,
html[data-theme="dark"] .kn-dock,
html[data-theme="dark"] .kn-periods,
html[data-theme="dark"] .kn-view,
html[data-theme="dark"] .kn-sort,
html[data-theme="dark"] .kn-status,
html[data-theme="dark"] .kn-author-search,
html[data-theme="dark"] .kn-load-more {
    color: var(--kn-ink) !important;
}

/* The reader has its own light/sepia/dark themes. Do not flatten them into
 * the site's dark palette when the global site theme is dark. */
html[data-theme="dark"] article.category-read .entry-content:not(.xntq-theme-dark):not(.xntq-theme-sepia) {
    background: #ffffff !important;
    color: #1d1d1f !important;
}

html[data-theme="dark"] article.category-read .entry-content:not(.xntq-theme-dark):not(.xntq-theme-sepia) :is(p, h1, h2, h3, h4, h5, h6, li, a, span) {
    color: #1d1d1f !important;
}

html[data-theme="dark"] article.category-read .entry-content.xntq-theme-sepia {
    background: #f4ead7 !important;
    color: #5a4634 !important;
}

html[data-theme="dark"] article.category-read .entry-content.xntq-theme-sepia :is(p, h1, h2, h3, h4, h5, h6, li, a, span) {
    color: #5a4634 !important;
}

html[data-theme="dark"] article.category-read .entry-content.xntq-theme-dark {
    background: var(--rtb-dark-bg) !important;
    color: var(--rtb-dark-text) !important;
}

html[data-theme="dark"] article.category-read .entry-content.xntq-theme-dark :is(p, h1, h2, h3, h4, h5, h6, li, a, span) {
    color: var(--rtb-dark-text) !important;
}

html[data-theme="dark"] article.category-read #kfrxUniqueToolbar,
html[data-theme="dark"] article.category-read #kfrxUniqueToolbar .vcrx-board-box,
html[data-theme="dark"] article.category-read #kfrxUniqueToolbar .vcrx-toc-box {
    border-color: var(--kn-line) !important;
    background: var(--kn-surface) !important;
    color: var(--kn-ink) !important;
}

html[data-theme="dark"] article.category-read #kfrxUniqueToolbar .vcrx-theme-toggle {
    border-color: var(--kn-line) !important;
    background: var(--kn-surface-soft) !important;
    color: var(--kn-ink) !important;
}

html[data-theme="dark"] article.category-read #kfrxUniqueToolbar .vcrx-theme-toggle.active {
    border-color: var(--kn-accent) !important;
    background: var(--kn-accent-strong) !important;
    color: #ffffff !important;
}

html[data-theme="dark"] article.category-read #kfrxUniqueToolbar .vcrx-reader-shell,
html[data-theme="dark"] article.category-read #kfrxUniqueToolbar .vcrx-board-box,
html[data-theme="dark"] article.category-read #kfrxUniqueToolbar .vcrx-toc-box {
    border-color: var(--kn-line) !important;
    background: var(--kn-surface) !important;
    color: var(--kn-ink) !important;
}

html[data-theme="dark"] article.category-read #kfrxUniqueToolbar .vcrx-reader-state strong,
html[data-theme="dark"] article.category-read #kfrxUniqueToolbar .vcrx-reader-state span,
html[data-theme="dark"] article.category-read #kfrxUniqueToolbar .vcrx-item-title,
html[data-theme="dark"] article.category-read #kfrxUniqueToolbar .vcrx-board-caption {
    color: var(--kn-ink) !important;
}

html[data-theme="dark"] article.category-read #kfrxUniqueToolbar .vcrx-main-trigger,
html[data-theme="dark"] article.category-read #kfrxUniqueToolbar .vcrx-stepper-box,
html[data-theme="dark"] article.category-read #kfrxUniqueToolbar .vcrx-dropdown-field,
html[data-theme="dark"] article.category-read #kfrxUniqueToolbar .vcrx-switch-holder {
    border-color: var(--kn-line) !important;
    background: var(--kn-surface-soft) !important;
    color: var(--kn-ink) !important;
}

html[data-theme="dark"] article.category-read #kfrxUniqueToolbar .vcrx-main-trigger.is-active,
html[data-theme="dark"] article.category-read #kfrxUniqueToolbar .vcrx-theme-toggle.active {
    border-color: var(--kn-accent) !important;
    background: var(--kn-accent-strong) !important;
    color: #ffffff !important;
}

html[data-theme="dark"] article.category-read #kfrxUniqueToolbar .vcrx-main-trigger:hover,
html[data-theme="dark"] article.category-read #kfrxUniqueToolbar .vcrx-stepper-btn:hover {
    background: var(--kn-accent-soft) !important;
    color: var(--kn-ink) !important;
}

html[data-theme="dark"] .comments-area .comment-respond {
    border-color: var(--kn-line) !important;
    background: transparent !important;
    color: var(--kn-ink) !important;
}

html[data-theme="dark"] .comments-area .comment-respond > .comment-form,
html[data-theme="dark"] .comments-area .comment-respond .comment-form > p,
html[data-theme="dark"] .comments-area .comment-respond .comment-form-comment {
    background: transparent !important;
}

html[data-theme="dark"] .comments-area .comment-respond :is(p, label, .logged-in-as, .comment-notes, .comment-form-comment, h2, h3, h4, .comment-reply-title) {
    color: var(--kn-ink) !important;
}

html[data-theme="dark"] .comments-area .comment-respond a {
    color: var(--kn-accent) !important;
}

html[data-theme="dark"] .comments-area .comment-respond :is(input, textarea)::placeholder {
    color: var(--kn-muted) !important;
    opacity: 1 !important;
}

html[data-theme="dark"] .kn-comments {
    --kn-comment-ink: var(--kn-ink);
    --kn-comment-muted: var(--kn-muted);
    --kn-comment-line: rgba(113, 197, 189, .28);
    --kn-comment-accent: var(--kn-accent);
}

html[data-theme="dark"] .kn-page :is(.kn-controls, .kn-catalog-toolbar, .kn-archive-toolbar, .kn-top100-toolbar, .kn-author-tools, .kn-series-tools) :is(button, a, select, input) {
    border-color: var(--kn-line) !important;
    background-color: var(--kn-surface-soft) !important;
    color: var(--kn-ink) !important;
}

html[data-theme="dark"] .kn-page :is(.kn-controls, .kn-catalog-toolbar, .kn-archive-toolbar, .kn-top100-toolbar, .kn-author-tools, .kn-series-tools) :is(button, a):hover,
html[data-theme="dark"] .kn-page :is(.kn-controls, .kn-catalog-toolbar, .kn-archive-toolbar, .kn-top100-toolbar, .kn-author-tools, .kn-series-tools) :is(button, a).is-active,
html[data-theme="dark"] .kn-page :is(.kn-controls, .kn-catalog-toolbar, .kn-archive-toolbar, .kn-top100-toolbar, .kn-author-tools, .kn-series-tools) :is(button, a)[aria-current="page"] {
    background-color: var(--kn-accent-strong) !important;
    color: #ffffff !important;
}

html[data-theme="dark"] .kn-page :is(h1, h2, h3, h4, h5, h6) {
    text-shadow: 0 1px 12px rgba(0, 0, 0, .16);
}
