/* Shared semantic palette. Dark keeps the original page art; midnight is download charcoal. */
html[data-theme="dark"] { color-scheme: dark; }
html[data-theme="midnight"] {
  color-scheme: dark;
  --theme-bg: #151515; --theme-bg-rgb:21,21,21; --theme-side: #111111; --theme-card: #1b1b1b;
  --theme-raised: #242424; --theme-text: #ffffff; --theme-muted: #999999;
  --theme-border: #2a2a2a; --theme-header: #151515; --theme-header-rgb: 21,21,21;
  --theme-hover: #303030; --theme-shadow: 0 12px 35px #0003;
}
html[data-theme="light"] {
  color-scheme: light;
  --theme-bg: #f4f5f7; --theme-bg-rgb:244,245,247; --theme-side: #eceef2; --theme-card: #ffffff;
  --theme-raised: #e9ecf1; --theme-text: #20232a; --theme-muted: #5b6472;
  --theme-border: #d7dce4; --theme-header: #ffffff; --theme-header-rgb: 255,255,255;
  --theme-hover: #e0e4eb; --theme-shadow: 0 12px 35px #1b243412;
}
/* Bridge existing page variables instead of maintaining a second set of layouts. */
html:is([data-theme="midnight"],[data-theme="light"]) body {
  --bg: var(--theme-bg); --surface: var(--theme-card); --raised: var(--theme-raised);
  --text: var(--theme-text); --muted: var(--theme-muted); --border: var(--theme-border);
  --text-main: var(--theme-text); --text-soft: var(--theme-muted);
  --panel-bg: var(--theme-card); --panel-border: var(--theme-border);
  --bg-2:var(--theme-raised);--panel:var(--theme-card);--panel-2:var(--theme-raised);
  --line:var(--theme-border);--muted-2:var(--theme-muted);--shadow:var(--theme-shadow);
  --home-background: var(--theme-bg); --hero-page-background: var(--theme-bg);
  --settings-bg: var(--theme-bg); --settings-side: var(--theme-side);
  --settings-card: var(--theme-card); --settings-card-2: var(--theme-raised);
  --settings-text: var(--theme-text); --settings-muted: var(--theme-muted); --settings-line: var(--theme-border);
  --info-bg: var(--theme-bg); --info-card: var(--theme-card); --info-muted: var(--theme-muted);
  --room-panel: var(--theme-card); --room-line: var(--theme-border); --room-muted: var(--theme-muted);
  background-color: var(--theme-bg) !important;
  background-image: none !important;
  color: var(--theme-text);
}
/* The existing settings selector is intentionally more specific than its legacy blue palette. */
html[data-theme="midnight"] body.settings-page[data-settings-theme] {
  --settings-bg:#151515;--settings-side:#111;--settings-card:#1b1b1b;--settings-card-2:#242424;--settings-line:#2a2a2a;
}
.theme-preview.midnight { background:linear-gradient(90deg,#151515 30%,#242424 30%) !important; }
.theme-picker button:focus-visible { outline:2px solid #f04a4a;outline-offset:4px; }
.theme-picker button:disabled { opacity:.45;cursor:not-allowed; }
.theme-picker .theme-unavailable { display:block;margin-top:5px;font-size:10px;font-weight:500;color:inherit; }

/* Navigation, popovers and persistent mobile chrome. */
html:is([data-theme="midnight"],[data-theme="light"]) body[class] :is(.topbar,.premium-nav),
html:is([data-theme="midnight"],[data-theme="light"]) body[class] :is(.topbar,.premium-nav).scrolled {
  background:rgba(var(--theme-header-rgb),.96) !important;
  border-color:var(--theme-border) !important;box-shadow:var(--theme-shadow) !important;
}
html:is([data-theme="midnight"],[data-theme="light"]) body[class] :is(.topbar,.premium-nav)::before,
html:is([data-theme="midnight"],[data-theme="light"]) body[class] :is(.topbar,.premium-nav)::after { background:none !important; }
html:is([data-theme="midnight"],[data-theme="light"]) :is(
 .mobile-bottom-nav,.mobile-drawer,.mobile-drawer-panel,.nav-more-panel,.profile-menu,.profile-dropdown,
 .header-profile-menu,.header-profile-dropdown,.search-results,.mobile-drawer-search-results,
 .notification-dropdown,.notifications-dropdown,.discover-select-menu,.user-list-sort-menu,
 .settings-sidebar,.footer,.info-footer
) { background:var(--theme-side) !important;color:var(--theme-text);border-color:var(--theme-border) !important; }
html:is([data-theme="midnight"],[data-theme="light"]) :is(.nav-item,.topbar button,.premium-nav a,.mobile-drawer a,.mobile-bottom-nav a,.footer a,.footer p,.footer h3,.footer h4,.footer span,.info-footer a) { color:var(--theme-text) !important; }
html:is([data-theme="midnight"],[data-theme="light"]) :is(.nav-item.is-current-page,.nav-item.active,.nav-item:hover,.search-result-item:hover,.user-list-sort-option:hover) { background:var(--theme-raised) !important;color:var(--theme-text) !important; }

/* Content surfaces: metadata, lists, filters, community and account dialogs. */
html:is([data-theme="midnight"],[data-theme="light"]) :is(
 .watch-card,.watch-comments,.comment-item,.comment-bubble,.anime-info-card,.anime-description,
 .anime-comments,.anime-details-card,.anime-details-panel,.anime-stat-card,.episode-card,
 .user-list-stats,.user-list-toolbar,.user-list-card,.user-list-sort-menu,.user-list-filter,
 .discover-controls,.discover-search,.discover-select-menu,.discover-filter-sheet,
 .feature-card,.social-network-card,.join-card,.shop-wallet-card,.shop-product-card,.shop-activity-panel,
 .shop-purchase-dialog,.premium-order-dialog,.plan-card,.faq-item,.intro-panel,
 .notifications-page-list,.notification-item,.notifications-filter,
 .profile-list-dialog,.profile-list-head,.profile-edit-dialog,.profile-editor-tabs,
 .profile-room-panel,.profile-sidebar,.profile-stats,.settings-group,.account-details,
 .search-result-item,.mobile-drawer-profile-card,.mobile-drawer-search,
 .fragment-modal-content,.video-download-dialog,.info-dialog,.platform-card,.feature-tile,.faq-card
):not(.watch-player):not(body) { background:var(--theme-card) !important;border-color:var(--theme-border) !important;color:var(--theme-text); }
html:is([data-theme="midnight"],[data-theme="light"]) :is(
 input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="submit"]),textarea,select,
 .settings-search,.discover-search,.user-list-search,.search-box,.search-input,.comment-input
) { background-color:var(--theme-raised) !important;color:var(--theme-text) !important;border-color:var(--theme-border) !important; }
html:is([data-theme="midnight"],[data-theme="light"]) :is(input,textarea)::placeholder {color:var(--theme-muted);opacity:1;}
html:is([data-theme="midnight"],[data-theme="light"]) :is(
 .section-heading,.section-title,.anime-title,.anime-name,.name,.discover-card-meta,.user-list-copy,
 .watch-current-episode-title,.watch-current-episode-label,.comment-content,.comment-text,
 .profile-list-title,.notifications-title,.shop-section-head,.filter-label,.faq-question,
 .settings-panel h1,.settings-panel h2,.settings-panel h3,.toggle-row strong,.settings-nav-item
) { color:var(--theme-text) !important; }
html:is([data-theme="midnight"],[data-theme="light"]) :is(
 .section-description,.section-subtitle,.muted,.anime-description p,.comment-date,.comment-time,
 .user-list-info,.user-list-progress-text,.footer-copy,.faq-answer,.notification-time,.toggle-row p
) { color:var(--theme-muted) !important; }
html:is([data-theme="midnight"],[data-theme="light"]) .site-loading-screen {background:var(--theme-bg);color:var(--theme-text);}
html:is([data-theme="midnight"],[data-theme="light"]) body::-webkit-scrollbar-track {background:var(--theme-bg);}
html:is([data-theme="midnight"],[data-theme="light"]) body::-webkit-scrollbar-thumb {background:var(--theme-muted);border-color:var(--theme-bg);}

/* Light surfaces need dark labels; artwork, video controls and colored action buttons stay intact. */
html[data-theme="light"] :is(.download-main,.info-dialog,.info-section,.shop-main,.notifications-main,.user-list-content,.discover-grid-section) :is(h1,h2,h3,h4,p,label) {color:var(--theme-text);}
html[data-theme="light"] :is(.feature-card,.join-card,.plan-card,.faq-item,.shop-product-card,.profile-list-dialog,.watch-card:not(.watch-player),.notification-item,.user-list-card) :is(h1,h2,h3,h4,strong,p,label,summary) {color:var(--theme-text);}
html[data-theme="light"] :is(.feature-card,.plan-card,.watch-card:not(.watch-player),.notification-item,.user-list-card) :is(small,.meta,.description) {color:var(--theme-muted);}
html[data-theme="light"] :is(.hero-section,.discover-hero,.discovery-card,.anime-banner,.profile-banner,.user-list-banner-media,.watch-player-shell,.premium-name-preview,.theme-preview) {color-scheme:dark;}
html:is([data-theme="midnight"],[data-theme="light"]) .home-page .hero-section {background-color:var(--theme-bg);}
html:is([data-theme="midnight"],[data-theme="light"]) .home-page .hero-mask {background:linear-gradient(90deg,rgba(0,0,0,.65),transparent 75%),linear-gradient(0deg,var(--theme-bg),transparent 35%) !important;}
html[data-theme="light"] .download-main :is(.device-laptop,.device-phone,.mockup-screen) {color-scheme:dark;}

/* Current discovery layout and its transition into the page background. */
html:is([data-theme="midnight"],[data-theme="light"]) body :is(.discovery-shell,.discovery,.discovery-genres,.discover-page,.discover-filter-row,.discover-genre-tabs) {
  background:var(--theme-bg);color:var(--theme-text);
}
html:is([data-theme="midnight"],[data-theme="light"]) .discovery-shade {
  background:linear-gradient(90deg,rgba(var(--theme-bg-rgb),.94),rgba(var(--theme-bg-rgb),.67) 33%,rgba(var(--theme-bg-rgb),.08) 75%),linear-gradient(0deg,var(--theme-bg) 1%,rgba(var(--theme-bg-rgb),.9) 20%,rgba(var(--theme-bg-rgb),.24) 56%,transparent 78%);
}
html:is([data-theme="midnight"],[data-theme="light"]) body.animes-page .discover-hero::after {background:linear-gradient(180deg,transparent,var(--theme-bg));}
html:is([data-theme="midnight"],[data-theme="light"]) body :is(.discovery-card,.discovery-copy h1,.discovery-shelf-head h2,.discovery-genres h2,.discovery-controls button,.discovery-position) {color:var(--theme-text);}
html:is([data-theme="midnight"],[data-theme="light"]) body :is(.discovery-description,.discovery-meta,.discovery-topnote,.discovery-card-meta,.discovery-overline,.discovery-selection-hint) {color:var(--theme-muted);}
html[data-theme="light"] .discovery-layer {background:var(--theme-bg);}
html[data-theme="light"] :is(.discovery-save,.discovery-actions .discovery-watch,.discovery-genre-chip) {background:var(--theme-card);color:var(--theme-text);border-color:var(--theme-border);}
html[data-theme="light"] .discovery-controls button {border-color:var(--theme-border);}
html[data-theme="light"] .discovery-position i {background:var(--theme-muted);}
html[data-theme="light"] :is(.discovery-score,.discovery-position > span:last-child) {color:#775b24;}

/* Match the specificity of shared desktop/mobile navigation. */
html:is([data-theme="midnight"],[data-theme="light"]) body[class] :is(.topbar,.premium-nav) > .center > .nav-item {color:var(--theme-muted) !important;}
html:is([data-theme="midnight"],[data-theme="light"]) body[class] :is(.topbar,.premium-nav) > .center > .nav-item:is(.is-current-page,:hover,:active) {background:var(--theme-raised) !important;color:var(--theme-text) !important;border-color:var(--theme-border) !important;}
html[data-theme="light"] body[class] :is(.topbar,.premium-nav) :is(.btn,.auth-header-icon,.mobile-menu-toggle) {background:var(--theme-raised) !important;color:var(--theme-text) !important;border-color:var(--theme-border) !important;}
html[data-theme="light"] :is(.topbar,.premium-nav,.footer) :is(.logo,.brand,.footer-logo) {background:#151515;border-radius:8px;}
html[data-theme="light"] :is(.topbar,.premium-nav,.mobile-drawer,.mobile-bottom-nav) img.icon {filter:brightness(.25);}

/* Calendar, informational sections and forms use the same neutral surfaces. */
html:is([data-theme="midnight"],[data-theme="light"]) body :is(
 .schedule-head,.schedule-toolbar,.schedule-editor,.schedule-card,.schedule-list-day,.schedule-day,.schedule-feature-card,
 .info-stats,.info-story,.info-partnership,.partnership-formats,.info-support,.info-community,
 .shop-overview article,.shop-activity-panel,.login-box,.register-box,.admin-sidebar,
 .notifications-card,.notifications-empty,.user-list-empty,.premium-card
) {background:var(--theme-card);color:var(--theme-text);border-color:var(--theme-border);box-shadow:var(--theme-shadow);}
html:is([data-theme="midnight"],[data-theme="light"]) body :is(.schedule-search,.schedule-status-filter,.schedule-today-card,.discover-select,.discover-select-trigger) {background:var(--theme-raised);color:var(--theme-text);border-color:var(--theme-border);}
html:is([data-theme="midnight"],[data-theme="light"]) body :is(.schedule-head,.schedule-editor,.schedule-card,.schedule-list-day,.shop-overview,.login-box,.register-box,.info-stats,.info-story,.info-partnership,.info-support,.info-community,.user-list-empty) :is(h1,h2,h3,h4,p,label,strong,small) {color:var(--theme-text);}
html[data-theme="light"] body :is(.schedule-status-filter button,.schedule-day-tab,.discover-genre-tab,.discover-select-option,.shop-product-action,.wallet-progress-copy,.shop-hero-copy p,.shop-product-info,.login-register-link,.login-card-divider,.login-recovery-links a,.forgot-link,.login-back-link) {color:var(--theme-muted);border-color:var(--theme-border);}
html[data-theme="light"] body.animes-page :is(.discover-list-tab,.discover-select-label,.discover-select-trigger,.discover-genre-tab) {color:var(--theme-text) !important;}
html[data-theme="light"] .shop-product-action {background:var(--theme-raised);}
html[data-theme="light"] .watch-card[role="alert"] {color:#a32232 !important;}
html[data-theme="light"] .site-loading-screen {backdrop-filter:blur(5px);}
html[data-theme="light"] .site-loading-screen :is(p,span,div) {color:var(--theme-text);text-shadow:none;}
/* Personal cover art and avatars remain images; only surrounding profile panels change. */
html:is([data-theme="midnight"],[data-theme="light"]) body.profile-page.profile-compact.profile-sidebar :is(.profile-room-hero,.profile-bio-block,.profile-stat-box,.profile-music-player,.profile-content-toolbar,.profile-panel,.profile-list-card) {background:var(--theme-card);color:var(--theme-text);border-color:var(--theme-border);}
html[data-theme="light"] body.profile-page.profile-compact.profile-sidebar :is(.profile-panel,.profile-bio-block,.profile-stat-box,.profile-content-toolbar) :is(h2,h3,p,strong,span,button) {color:var(--theme-text);}
html:is([data-theme="midnight"],[data-theme="light"]) body .info-hero {background:radial-gradient(circle at 78% 45%,#6d315316,transparent 32%),var(--theme-bg);}
html:is([data-theme="midnight"],[data-theme="light"]) body .schedule-list-top {background:var(--theme-raised);color:var(--theme-text);box-shadow:var(--theme-shadow);}
html[data-theme="light"] body :is(.schedule-list-top,.schedule-today-card) :is(span,h2,strong,button) {color:var(--theme-text);}
html[data-theme="light"] body .schedule-list-day .schedule-list-card :is(h3,p,strong,span,small) {color:#f5f5f5;}
html[data-theme="light"] body .info-hero-content > p,html[data-theme="light"] :is(.info-eyebrow,.section-kicker,.section-heading > span) {color:var(--theme-muted);}
html[data-theme="light"] body.animes-page .discover-select :is(button,span) {color:var(--theme-text) !important;}
html[data-theme="light"] :is(.info-btn.secondary,.discovery-genre,.discovery-genre.is-active) {background:var(--theme-raised);color:var(--theme-text);border-color:var(--theme-border);}
html[data-theme="light"] body :is(.user-list-hero-copy,.user-list-stats,.user-list-toolbar,.user-list-empty,.notifications-head,.notifications-empty) :is(h1,h2,h3,p,strong,small,span,a,button) {color:var(--theme-text) !important;}
html[data-theme="light"] body .footer :is(h2,h3,h4,h5) {color:var(--theme-text);}
html[data-theme="light"] body :is(.user-list-view-switch,.user-list-sort) img {filter:brightness(.25);}
html:is([data-theme="midnight"],[data-theme="light"]) body.premium-page .hero {background:var(--theme-bg);}
html:is([data-theme="midnight"],[data-theme="light"]) body.premium-page :is(.benefit-grid article,.plan-stage,.plan-switch,.premium-order-plan,.premium-discord-option) {background:var(--theme-card);border-color:var(--theme-border);color:var(--theme-text);}
html[data-theme="light"] body.premium-page :is(.hero-copy,.benefit-grid,.plans,.faq,.premium-order-dialog) :is(h1,h2,h3,p,small,li,summary) {color:var(--theme-text);}
html[data-theme="light"] body.premium-page :is(.text-btn,.hero-note,.plan-switch button,.premium-discord-copy strong) {color:var(--theme-muted);}
