:root { color-scheme: light; }

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.theme-toggle > span { font-size: 19px; line-height: 1; }
.theme-toggle:hover { background: var(--soft); }
.theme-toggle[aria-pressed="true"] { border-color: var(--teal); }
.login-form > .theme-toggle, #password-form > .theme-toggle {
  display: flex;
  width: max-content;
  margin: 0 0 24px auto;
}

@media (max-width: 760px) {
  .topbar { height: auto; min-height: 62px; padding-top: 9px; padding-bottom: 9px; }
  .topbar-right { flex-wrap: wrap; justify-content: flex-end; max-width: calc(100% - 40px); }
}

@media screen {
html[data-theme="dark"] {
  color-scheme: dark;
  --paper: #101c20;
  --white: #1b2b2f;
  --ink: #e7efee;
  --muted: #b0c2c0;
  --teal: #8dd2c7;
  --line: #3d5357;
  --soft: #243b3d;
  --orange: #eab87a;
  --shadow: 0 8px 28px #0003;
  --surface-hover: #2b4246;
  --action: #337a76;
}

html[data-theme="dark"] :is(
  .topbar, .stat, .card, .topic-card, .week-grid, .tracker-calendar,
  .calendar-head, .dialog-header, dialog, .topic-criteria-box,
  .question-item, .question-pdf-preview, .study-summary, .tutor-overview-total,
  .personal-editor-subtopic, .buddy-shop-item, .guide-course select,
  input, select, textarea, .btn, .topic-subject-tab, .skip-link
) { background-color: var(--white); color: var(--ink); }

html[data-theme="dark"] :is(
  .card-header, td, .queue-item, .activity-item, .scheme-summary,
  .topic-criteria-box, .study-summary, .study-summary-total,
  .feature-switch, .personal-editor-heading, .personal-review-heading,
  .guide-video, .guide-detail #guide-player, input, select, textarea
) { border-color: var(--line); }

html[data-theme="dark"] :is(
  th, .day.today, .feedback, .demo-logins, .workload-preview,
  .curriculum-selector, .assigned-scheme, .question-mode-option,
  .question-data, .study-summary > header, .personal-editor-heading,
  .personal-review-heading > h3, .submission-question-score,
  .leaderboard-you, .feature-switch:has(input:checked), .topic-icon,
  .buddy-shop-fitting, .buddy-completion
) { background-color: var(--soft); color: var(--ink); }

html[data-theme="dark"] :is(
  .btn:hover, tbody tr:hover, .topic-subject-tab:hover, .guide-topic:hover
) { background: var(--surface-hover); }

html[data-theme="dark"] :is(
  .btn.primary, .topic-subject-tab[aria-selected="true"]
) { background: var(--action); border-color: var(--action); color: #fff; }
html[data-theme="dark"] .btn.primary:hover { background: #3b8580; }
html[data-theme="dark"] .btn.ghost { background: transparent; color: var(--teal); }
html[data-theme="dark"] .btn.yellow { background: var(--yellow); color: #263831; }
html[data-theme="dark"] .btn.danger { color: #ffb4a4; }

html[data-theme="dark"] :is(.welcome, .login-brand, .tutor-main-review .card-header) {
  background: #214e55;
  color: #fff;
}
html[data-theme="dark"] .tutor-main-review .card-header .btn {
  background: #1b2b2f;
  color: var(--ink);
}
html[data-theme="dark"] :is(
  .curriculum-selector legend, .scheme-section-row th, .question-marks,
  .study-summary h2, .study-summary-total > strong, .personal-scheme-editor summary,
  .buddy-world-caption strong, .buddy-clock, .buddy-eyebrow, .buddy-history-row > span
) { color: var(--teal); }
html[data-theme="dark"] :is(.feature-switch small, .guide-topic small) { color: var(--muted); }

html[data-theme="dark"] .notice {
  background: #203e38;
  color: #c3e5db;
  border-color: #47685e;
}
html[data-theme="dark"] :is(.notice.warning, .preview-bar, .timer-bar, .queue-mark, .pill.demo) {
  background: #453a23;
  color: #f6db9d;
  border-color: #7c6941;
}
html[data-theme="dark"] :is(.notice.error, .form-error) {
  background: #472d30;
  color: #ffc0b5;
  border-color: #8d5553;
}
html[data-theme="dark"] .status { background: #2b3e41; color: var(--muted); }
html[data-theme="dark"] .status.complete { background: #224438; color: #afe2c1; }
html[data-theme="dark"] :is(.status.review, .status.overdue) { background: #453a23; color: #f6db9d; }
html[data-theme="dark"] :is(.status.available, .status.submitted) { background: #243e4b; color: #b6daef; }
html[data-theme="dark"] .status.requires-improvement { background: #8b1e2d; color: #fff; }
html[data-theme="dark"] .review-count-button:hover { background: #5c4a29; }

html[data-theme="dark"] :is(.lesson, .calendar-event) {
  background: #24443e;
  color: var(--ink);
  border-color: #6c9b8d;
}
html[data-theme="dark"] :is(.lesson.school, .calendar-event.school) {
  background: #283e57;
  border-color: #7b9dc2;
}
html[data-theme="dark"] .lesson.notes { background: #453e26; border-color: #b5a266; }
html[data-theme="dark"] .calendar-day {
  background: repeating-linear-gradient(to bottom, transparent 0, transparent 23px, #304448 23px, #304448 24px);
}
html[data-theme="dark"] .calendar-selection { background: #496d6280; }
html[data-theme="dark"] :is(.progress, .study-summary-bar, .scheme-goal progress::-webkit-progress-bar) {
  background: #354c4e;
}
html[data-theme="dark"] .password-display { background: var(--soft); }
html[data-theme="dark"] .guide-topic.selected { background: #2a4949; border-color: var(--teal); }

html[data-theme="dark"] .buddy-wallet { background: #453a23; color: #f6db9d; border-color: #7c6941; }
html[data-theme="dark"] .buddy-wallet > span { color: #f2ce79; }
html[data-theme="dark"] .buddy-world { background: var(--white); border-color: var(--line); }
html[data-theme="dark"] .buddy-world-caption { background: var(--white); color: var(--muted); }
html[data-theme="dark"] .buddy-shop-price { color: #f0d09b; }
html[data-theme="dark"] .buddy-focus-controls > .btn { background: #1b2b2ff2; border-color: var(--line); }
html[data-theme="dark"] .buddy-focus-timer {
  background: linear-gradient(transparent, #101c20eb 30%, #101c20fa);
  color: var(--ink);
}
html[data-theme="dark"] .buddy-focus-timer span { color: var(--muted); }
html[data-theme="dark"] .buddy-focus-sync { background: #453a23; color: #f6db9d; }

html[data-theme="dark"] :is(button, a, input, select, textarea):focus-visible {
  outline-color: #f1d86a;
}
html[data-theme="dark"] ::placeholder { color: #9eb2b0; opacity: 1; }
}

@media print {
  .theme-toggle { display: none; }
  html[data-theme="dark"] { color-scheme: light; }
}
