/* Manual themes share one component palette; page geometry stays in its module. */
html[data-theme="dark"] {
  color-scheme: dark;
  --theme-color-scheme: dark;
  --bg-app: #0c0b14;
  --bg-panel: #17151f;
  --glass-card: #17151f;
  --glass-solid: #17151f;
  --glass-raised: #211e2b;
  --border-subtle: #34303f;
  --border-glow: #775366;
  --brand-start: #c57898;
  --brand-middle: #c57898;
  --brand-end: #c57898;
  --brand-primary: #a54d72;
  --brand-hover: #b75d82;
  --text-main: #f3f4f6;
  --text-narrative: #c4b5fd;
  --text-sub: #a8a4b3;
  --text-placeholder: #918b9e;
  --focus-ring: #e3acc3;
  --shadow-brand: none;
  --shadow-glow: none;
  --shadow-surface: 0 12px 40px rgba(0,0,0,.3);
  --tavern-surface: var(--bg-panel);
  --tavern-solid: var(--bg-panel);
  --tavern-raised: var(--glass-raised);
  --tavern-secondary: var(--text-sub);
  --sidebar: var(--bg-panel);
  --white: var(--bg-panel);
  --surface: var(--bg-panel);
  --panel: var(--bg-panel);
  --accent: #e3acc3;
  --accent-dark: #f0c5d7;
  --wash: #2c202b;
  --green: #8bd3aa;
  --red: #f3a4b2;
  --theme-muted-surface: #121019;
  --theme-control-border: #494252;
  --theme-border-strong: #6d6579;
  --theme-text-secondary: #d8d4e0;
  --theme-text-soft: #bdb7c9;
  --theme-accent: #e3acc3;
  --theme-accent-strong: #f0c5d7;
  --theme-accent-bg: #30222e;
  --theme-accent-soft: #261e29;
  --theme-accent-border: #513747;
  --theme-accent-border-strong: #80576d;
  --theme-narrative-bg: #211a30;
  --theme-narrative-border: #695189;
  --theme-cover-bg: #24202c;
  --theme-selection-text: #fff;
  --theme-selection-bg: #68445a;
  --theme-success-text: #8bd3aa;
  --theme-success-bg: #152b22;
  --theme-success-border: #315944;
  --theme-warning-text: #e5c17e;
  --theme-warning-bg: #30271a;
  --theme-warning-border: #655132;
  --theme-danger-text: #f3a4b2;
  --theme-danger-strong: #ffc3cc;
  --theme-danger-bg: #341e29;
  --theme-danger-border: #70404e;
  --theme-info-text: #a8bbe8;
  --theme-info-bg: #1e2535;
  --theme-overlay: rgba(0,0,0,.6);
  --theme-focus-shadow: rgba(227,172,195,.16);
  --theme-preview-shade: rgba(23,21,31,.94);
}

.theme-toggle.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  padding: 8px;
  color: var(--theme-text-secondary);
  background: var(--theme-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 9px;
  box-shadow: none;
}
.theme-toggle.icon-button:hover { color: var(--theme-accent); background: var(--theme-accent-soft); border-color: var(--theme-accent-border-strong); }
.theme-toggle:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 3px; }
.theme-toggle .icon { width: 18px; height: 18px; flex: none; }
.theme-toggle .theme-icon-sun { display: none; }
html[data-theme="dark"] .theme-toggle .theme-icon-moon { display: none; }
html[data-theme="dark"] .theme-toggle .theme-icon-sun { display: block; }
.auth-scene>.theme-toggle { position: absolute; top: 24px; right: 24px; z-index: 3; }
.chat-page .chat-header .theme-toggle { width: 30px; height: 30px; flex-basis: 30px; padding: 6px; margin-left: 5px; }

/* Older workshop/editor rules hardcode their surfaces outside phase3-light. */
.workshop-page, .workshop-detail, .workshop-contents, .preset-editor-modal { color: var(--text-main); }
.workshop-page .btn, .preset-editor .btn, .workshop-rule-form .btn,
.workshop-search, .workshop-sort select, .workshop-card, .preset-editor-modal,
.preset-step-tabs, .preset-editor-footer, .preset-character-row {
  color: var(--theme-text-secondary); background: var(--theme-surface); border-color: var(--border-subtle); box-shadow: none;
}
.workshop-page .btn:hover, .preset-editor .btn:hover { color: var(--theme-accent-strong); background: var(--theme-accent-soft); border-color: var(--theme-accent-border-strong); }
.workshop-page .btn.primary, .preset-editor .btn.primary, .workshop-rule-form .btn.primary { color: var(--theme-on-brand); background: var(--brand-primary); border-color: var(--brand-start); }
.workshop-page .btn.primary:hover, .preset-editor .btn.primary:hover, .workshop-rule-form .btn.primary:hover { color: var(--theme-on-brand); background: var(--brand-hover); }
.workshop-page .btn.danger, .preset-editor .btn.danger { color: var(--theme-danger-text); border-color: var(--theme-danger-border); }
.workshop-categories>.btn { background: transparent; border-color: transparent; }
.workshop-categories>.btn.active, .workshop-rating .btn.active { color: var(--theme-accent-strong); background: var(--theme-accent-bg); border-color: var(--theme-accent-border-strong); }
.workshop-card:hover { border-color: var(--theme-accent-border-strong); box-shadow: none; }
.workshop-card-copy h3, .workshop-contents h4, .preset-character-name { color: var(--text-main); }
.workshop-search>input, .preset-editor input, .preset-editor textarea, .preset-editor select, .workshop-rule-form input, .workshop-rule-form textarea { color: var(--text-main); background: var(--theme-surface); border-color: var(--theme-control-border); caret-color: var(--text-main); }
.workshop-search>input { background: transparent; }
.preset-editor input:focus, .preset-editor textarea:focus, .preset-editor select:focus { border-color: var(--focus-ring); box-shadow: 0 0 0 3px var(--theme-focus-shadow); }
.preset-editor .field>label, .workshop-rule-form .field>label { color: var(--theme-text-secondary); }
.workshop-thumbnail, .workshop-tags span, .preset-cover-empty { color: var(--text-sub); background: var(--theme-raised); border-color: var(--border-subtle); }
.workshop-thumbnail>small { color: var(--theme-on-brand); background: var(--brand-primary); }
.workshop-card-footer, .workshop-library-tabs, .workshop-contents section, .workshop-rating, .preset-editor-footer { border-color: var(--border-subtle); }
.workshop-card-footer .btn, .workshop-contents li { color: var(--theme-text-secondary); background: var(--theme-muted-surface); }
.workshop-contents li small { color: var(--text-sub); }
.workshop-empty { color: var(--text-sub); background: var(--theme-muted-surface); border-color: var(--border-subtle); }
.workshop-error { color: var(--theme-danger-text); background: var(--theme-danger-bg); border-color: var(--theme-danger-border); }
.preset-recovered { color: var(--theme-accent); background: var(--theme-accent-soft); border-color: var(--theme-accent-border); }
.preset-cover-field>img { border-color: var(--border-subtle); background: var(--theme-cover-bg); }
.preset-character-row .btn { color: var(--theme-accent); }
.feed-card-type, .feed-preset-badge { background: var(--brand-primary); }
html[data-theme="dark"] .feed-card-rating { color: var(--theme-warning-text); }

/* RoleplayText escapes content before rendering; these selectors match its
   nested DOM in messages, opening previews and the shared asset details. */
.roleplay-text .roleplay-dialogue, .message-text .roleplay-text .roleplay-dialogue {
  color: var(--text-main); font-weight: 700; font-style: normal;
}
.roleplay-text .roleplay-narration, .message-text .roleplay-text .roleplay-narration {
  color: var(--text-narrative); font-style: italic; border-inline-start-color: var(--theme-narrative-border);
}
.roleplay-text .roleplay-dialogue em, .message-text .roleplay-dialogue em { color: inherit; font-style: normal; }
.roleplay-text code, .roleplay-text .roleplay-code-block { color: var(--theme-text-secondary); background: var(--theme-muted-surface); border-color: var(--border-subtle); }
.roleplay-text .roleplay-code-block code { background: transparent; }

html[data-theme="dark"] :is(input, textarea, select):disabled { color: var(--text-sub); background-color: var(--theme-muted-surface); }
html[data-theme="dark"] input:-webkit-autofill,
html[data-theme="dark"] input:-webkit-autofill:hover,
html[data-theme="dark"] input:-webkit-autofill:focus { -webkit-text-fill-color: var(--text-main); -webkit-box-shadow: 0 0 0 1000px var(--theme-surface) inset; caret-color: var(--text-main); }
html[data-theme="dark"] :is(.stat-compact,.subscription-card,.model-radio,.grant-option) { background-color: var(--theme-surface); color: var(--text-main); border-color: var(--border-subtle); }
html[data-theme="dark"] :is(.model-radio:has(input:checked),.grant-option:has(input:checked)) { background-color: var(--theme-accent-bg); border-color: var(--theme-accent-border-strong); }
html[data-theme="dark"] :is(.tier-card h3,.tier-price strong,.user-admin-row strong) { color: var(--text-main); }
html[data-theme="dark"] :is(.payment-secret-grid p,.payment-secret-grid small,.model-radio small,.grant-option small,.tier-features) { color: var(--text-sub); }
html[data-theme="dark"] :is(.form-error,.message-error) { color: var(--theme-danger-text); }
html[data-theme="dark"] :is(.divider,.user-admin-row,.archive-row,.aside-fact) { border-color: var(--border-subtle); }
html[data-theme="dark"] tr:hover td { background: var(--theme-muted-surface); }
html[data-theme="dark"] :is(.tooltip,[role="tooltip"]) { color: var(--text-main); background: var(--theme-raised); border-color: var(--border-subtle); }
html[data-theme="dark"] :is(.card-favorite,.gallery-stats,.card-author,.favorite-count) { color: var(--text-sub); }
html[data-theme="dark"] .card-favorite.is-favorite { color: var(--theme-accent); }
html[data-theme="dark"] .card-favorite { background: var(--theme-surface); border-color: var(--border-subtle); }

@media(max-width:760px) {
  .topbar-actions .theme-toggle { width: 33px; height: 33px; flex-basis: 33px; padding: 7px; }
  .auth-scene>.theme-toggle { top: 18px; right: 18px; }
}
