:root { color-scheme: light; }
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101916;
  --paper: #182420;
  --ink: #e1ebe4;
  --muted: #a3b2a6;
  --line: #304139;
  --mint: #253e33;
  --blue: #26384b;
  --lavender: #383047;
  --peach: #46362b;
  --danger: #f0a49a;
  --soft: #223328;
  --success: #b8dba0;
}
.theme-toggle { width: 36px; height: 36px; padding: 7px; flex-shrink: 0; }
.theme-toggle .theme-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .theme-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .theme-moon { display: none; }
.login-layout { position: relative; }
.login-theme-toggle { position: absolute; top: 28px; right: 28px; z-index: 1; }
.appearance-panel { margin-bottom: 22px; }
.appearance-panel .field { max-width: 330px; margin-top: 18px; margin-bottom: 0; }

:root[data-theme="dark"] :is(.sidebar, .topbar, .credit-pill, .stat, .topic-card, .side-card, .topic-header, .quiz-list-item, .admin-topic, .nav .badge) {
  background: var(--paper);
}
:root[data-theme="dark"] :where(.btn:not(.primary):not(.lime):not(.ghost), .field input, .field textarea, .field select, .inline-controls select, .filter-row input, .option-editor-row input[type="text"]) {
  background: var(--paper);
  border-color: var(--line);
  color: var(--ink);
}
:root[data-theme="dark"] :is(.btn:not(.primary):not(.lime):hover, .nav a:hover) { background: #293e31; }
:root[data-theme="dark"] .btn.danger { color: var(--danger); }
:root[data-theme="dark"] .btn.lime { color: #174b43; }
:root[data-theme="dark"] :is(.field > label, .field > span, .breadcrumb b) { color: var(--ink); }
:root[data-theme="dark"] :is(input, textarea)::placeholder { color: var(--muted); opacity: 1; }
:root[data-theme="dark"] :is(.nav-label, .nav a, .workspace-pill, .topic-meta, .rank-next, .board-row .position, .footer-note, .login-foot, .table th) { color: var(--muted); }
:root[data-theme="dark"] :is(.credit-pill, .workspace-pill, .topic-bottom, .table td) { border-color: var(--line); }
:root[data-theme="dark"] :is(.nav a.active, .tabs .btn.active) { background: #293f2d; color: #d5f29d; }
:root[data-theme="dark"] :is(.section-heading a, .side-link, .board-row .score, .little-note strong, .review-banner .icon, .complete-icon, .question-panel .question-number) { color: var(--success); }
:root[data-theme="dark"] :is(.little-note, .tip-card, .review-banner, .secret, .notice) {
  background: var(--soft);
  border-color: var(--line);
  color: #bbcfb4;
}
:root[data-theme="dark"] .tip-card p { color: var(--muted); }
:root[data-theme="dark"] .avatar { background: #30482f; color: #d0e4be; }
:root[data-theme="dark"] .credit-pill .coin { background: #473e25; color: #ebd695; }
:root[data-theme="dark"] .chip { background: #2a3b2c; color: #c2d7b8; }
:root[data-theme="dark"] .chip.green { background: #2b432c; color: #c3e4ad; }
:root[data-theme="dark"] .chip.gold { background: #443c26; color: #edda9e; }
:root[data-theme="dark"] .chip.red { background: #492f2b; color: #f0b0a4; }
:root[data-theme="dark"] .chip.blue { background: var(--blue); color: #bed8f0; }
:root[data-theme="dark"] .topic-cover .chip { background: #14251bce; color: #d4e4d6; }
:root[data-theme="dark"] .topic-cover::after { border-color: #ffffff1f; }
:root[data-theme="dark"] .topic-symbol { color: #92c9ab80; }
:root[data-theme="dark"] .blue .topic-symbol { color: #a0c9ed80; }
:root[data-theme="dark"] .lavender .topic-symbol { color: #c1a7df80; }
:root[data-theme="dark"] .peach .topic-symbol { color: #ddba9380; }
:root[data-theme="dark"] :is(.stat-icon, .quiz-list-item .number) { background: #2b402d; color: #c1dca7; }
:root[data-theme="dark"] .stat:nth-child(2) .stat-icon { background: #443c26; color: #dcc784; }
:root[data-theme="dark"] .stat:nth-child(3) .stat-icon { background: #3b3049; color: #ccb8e2; }
:root[data-theme="dark"] .rank-art { background: #2b3d2c; border-color: #213124; color: #cee3a7; }
:root[data-theme="dark"] .progress { background: #314136; }
:root[data-theme="dark"] .progress > span { background: #a1c67e; }
:root[data-theme="dark"] .table .me { background: #253729; }
:root[data-theme="dark"] .report-item blockquote { background: #233029; }
:root[data-theme="dark"] :is(.answer-option:has(input:checked), .answer-option.good) { background: #29422d; border-color: #88ad72; }
:root[data-theme="dark"] .answer-option.bad { background: #452d2a; border-color: #c98d7f; }
:root[data-theme="dark"] .answer-letter { color: var(--muted); }
:root[data-theme="dark"] .feedback { background: #233c29; border-color: #456745; }
:root[data-theme="dark"] .feedback p { color: #d0e4c5; }
:root[data-theme="dark"] .feedback.wrong { background: #3f3225; border-color: #7c6545; }
:root[data-theme="dark"] .feedback.wrong p { color: #ebd5b4; }
:root[data-theme="dark"] .reward { color: #c3e4a3; }
:root[data-theme="dark"] .error-message { background: #402b28; }
:root[data-theme="dark"] :is(.answer-option input, .check input, .option-editor-row input[type="checkbox"]) { accent-color: #a9ce86; }
:root[data-theme="dark"] dialog { box-shadow: 0 25px 100px #0008; }
:root[data-theme="dark"] dialog::backdrop { background: #0009; }
:root[data-theme="dark"] ::selection { background: #496541; color: #f3f8ed; }
@media (max-width: 700px) {
  .login-theme-toggle { top: 22px; right: 18px; }
  :root[data-theme="dark"] .sidebar.open + .nav-shade { background: #0007; }
}

@media (max-width: 380px) {
  .topbar { padding: 0 12px; }
  .topbar > .row { gap: 6px; }
  .mobile-brand { font-size: 16px; }
  .credit-pill { gap: 4px; padding: 5px 7px; }
  .top-actions { gap: 6px; }
  .credit-pill .coin { width: 18px; height: 18px; }
  .theme-toggle { width: 32px; height: 32px; padding: 5px; }
}
:root[data-theme="dark"] .option-editor-row input[type="text"] { border-color: var(--line); }
