html {
    overflow-y: auto;
    scrollbar-gutter: stable;
}

html.toon-theme-dark {
    color-scheme: dark;
    --bg: #0f172a;
    --panel: rgba(23, 32, 51, 0.96);
    --line: #334155;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --acct-bg: #0f172a;
    --acct-panel: rgba(23, 32, 51, 0.96);
    --acct-line: #334155;
    --acct-line-strong: #475569;
    --acct-text: #e5e7eb;
    --acct-muted: #94a3b8;
    --search-line: #334155;
    --search-line-strong: #475569;
    --search-text: #e5e7eb;
    --search-muted: #94a3b8;
    --search-surface: #172033;
    --search-surface-soft: #111827;
}

body.has-action-rail {
    padding: 18px 18px 32px 84px;
    box-sizing: border-box;
}

.action-rail {
    position: fixed;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 1200;
}

.rail-link,
.rail-button {
    width: 52px;
    height: 52px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.94);
    color: #1f2937;
    box-shadow: 0 14px 32px rgba(15, 23, 42, 0.14);
    text-decoration: none;
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease, color 0.18s ease;
    position: relative;
    padding: 0;
}

.rail-link:hover,
.rail-button:hover {
    transform: translateX(2px);
    background: #111827;
    color: #fff;
    box-shadow: 0 18px 36px rgba(15, 23, 42, 0.22);
}

.rail-link.danger:hover {
    background: #b91c1c;
}

.rail-link svg,
.rail-button svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
}

.theme-toggle {
    background: #111827;
    color: #facc15;
}

.theme-icon-sun,
html.toon-theme-dark body .theme-icon-moon {
    display: none;
}

html.toon-theme-dark body .theme-icon-sun {
    display: block;
}

.rail-link::after,
.rail-button::after {
    content: attr(data-label);
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%);
    white-space: nowrap;
    padding: 7px 10px;
    border-radius: 999px;
    background: rgba(17, 24, 39, 0.94);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease;
}

.rail-link:hover::after,
.rail-button:hover::after {
    opacity: 1;
}

html.toon-theme-dark body {
    background: #0f172a !important;
    color: #e5e7eb !important;
}

html.toon-theme-dark body :where(.container, .panel, .form-section, .manual-section, .summary-card, .favorite-card, .table-wrapper, .search-form, .site-tabs-shell, .genre-block, .card, .tag-filter-bar, .search-panel, .search-shell, .filter-panel, .search-token-box, .empty-state) {
    background: #172033 !important;
    color: #e5e7eb !important;
    border-color: #334155 !important;
    box-shadow: 0 18px 42px rgba(0, 0, 0, 0.32) !important;
}

html.toon-theme-dark body :where(h1, h2, h3, h4, p, li, label, th, td, strong, .intro, .section-title, .favorite-title, .favorite-chapter, .favorite-meta, .favorite-status, .sub, .meta, .empty, .date, .read, .form-label, .title-link, .title, .summary, .filter-help, .search-help, .loading) {
    color: #e5e7eb !important;
}

html.toon-theme-dark body :where(a:not(.rail-link):not(.btn):not(.chip-btn):not(.cta-btn), code) {
    color: #93c5fd !important;
}

html.toon-theme-dark body :where(input, select, textarea) {
    background: #101827 !important;
    color: #f8fafc !important;
    border-color: #475569 !important;
}

html.toon-theme-dark body :where(input, textarea)::placeholder {
    color: #94a3b8 !important;
}

html.toon-theme-dark body :where(table, th, td) {
    border-color: #334155 !important;
}

html.toon-theme-dark body :where(th, .genre-title) {
    background: #111827 !important;
}

html.toon-theme-dark body :where(.rank-item, .tag-filter-bar a) {
    border-color: #334155 !important;
}

html.toon-theme-dark body :where(.site-switch label, .search-category-grid a, .tag-filter-bar a, .category-chip span) {
    background: linear-gradient(180deg, #253348, #172033) !important;
    color: #dbeafe !important;
    border-color: #3b4a63 !important;
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.24) !important;
    text-shadow: none !important;
}

html.toon-theme-dark body :where(.search-category-grid a:nth-child(4n + 1), .tag-filter-bar a:nth-child(4n + 1), .category-chip:nth-child(4n + 1) span) {
    background: linear-gradient(180deg, #123b46, #102a38) !important;
    color: #a7f3d0 !important;
}

html.toon-theme-dark body :where(.search-category-grid a:nth-child(4n + 2), .tag-filter-bar a:nth-child(4n + 2), .category-chip:nth-child(4n + 2) span) {
    background: linear-gradient(180deg, #26375f, #172554) !important;
    color: #bfdbfe !important;
}

html.toon-theme-dark body :where(.search-category-grid a:nth-child(4n + 3), .tag-filter-bar a:nth-child(4n + 3), .category-chip:nth-child(4n + 3) span) {
    background: linear-gradient(180deg, #3b2f5f, #251a43) !important;
    color: #ddd6fe !important;
}

html.toon-theme-dark body :where(.search-category-grid a:nth-child(4n), .tag-filter-bar a:nth-child(4n), .category-chip:nth-child(4n) span) {
    background: linear-gradient(180deg, #4a2b35, #2f1721) !important;
    color: #fecdd3 !important;
}

html.toon-theme-dark body :where(.site-switch input:checked + label, .category-chip input:checked + span) {
    background: linear-gradient(135deg, #15803d, #0f766e) !important;
    color: #ffffff !important;
    border-color: #34d399 !important;
    box-shadow: 0 14px 30px rgba(16, 185, 129, 0.24) !important;
}

html.toon-theme-dark body :where(.tag-chip, .selected-search-chip) {
    background: linear-gradient(180deg, #1e3a5f, #172a46) !important;
    color: #dbeafe !important;
    border-color: #3b82f6 !important;
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.22) !important;
}

html.toon-theme-dark body :where(.tag-chip:hover) {
    background: linear-gradient(180deg, #255f9c, #1d4f83) !important;
    color: #ffffff !important;
}

html.toon-theme-dark body :where(.selected-search-chip) {
    background: linear-gradient(135deg, #047857, #0f766e) !important;
    color: #ffffff !important;
    border-color: transparent !important;
}

html.toon-theme-dark body :where(.toolbar-btn, .chip-btn, .cta-btn.secondary, .reset-link, .search-form button[type="button"]) {
    background: #223049 !important;
    color: #e5e7eb !important;
    border-color: #475569 !important;
    box-shadow: 0 10px 22px rgba(0, 0, 0, 0.24) !important;
}

html.toon-theme-dark body :where(.toolbar-btn.primary, .search-btn, .search-form button[type="submit"], .filter-panel button[type="submit"], .cta-btn:not(.secondary)) {
    background: linear-gradient(135deg, #15803d, #0f766e) !important;
    color: #ffffff !important;
    box-shadow: 0 14px 28px rgba(16, 185, 129, 0.2) !important;
}

html.toon-theme-dark body :where(.toolbar-btn.danger, .chip-btn.danger) {
    background: #3b1d24 !important;
    color: #fecdd3 !important;
    border-color: #7f1d1d !important;
}

html.toon-theme-dark body :where(.thumb-placeholder) {
    background: linear-gradient(135deg, #243044, #111827) !important;
    color: #cbd5e1 !important;
}

html.toon-theme-dark body :where(.rail-link, .rail-button) {
    background: rgba(17, 24, 39, 0.96);
    color: #f8fafc;
    box-shadow: 0 14px 32px rgba(0, 0, 0, 0.34);
}

html.toon-theme-dark body :where(.rail-link:hover, .rail-button:hover) {
    background: #f8fafc;
    color: #111827;
}

html.toon-theme-dark body .theme-toggle {
    background: #f8fafc;
    color: #f59e0b;
}

@media (max-width: 960px) {
    body.has-action-rail {
        padding: 12px 12px 82px;
    }

    .action-rail {
        left: 12px;
        right: 12px;
        top: auto;
        bottom: 14px;
        transform: none;
        flex-direction: row;
        justify-content: center;
    }

    .rail-link::after,
    .rail-button::after {
        display: none;
    }
}
