:root,
html[data-theme="light"] {
  color-scheme: light;
  --theme-bg: #f7f7f1;
  --theme-surface: #eff7f1;
  --theme-card: #ffffff;
  --theme-raised: #e4eee6;
  --theme-text: #18332d;
  --theme-muted: #66746d;
  --theme-border: #dce7de;
  --theme-input: #ffffff;
  --theme-green: #1b5448;
  --theme-accent: #286b5a;
  --theme-shadow: 0 12px 32px rgba(24, 51, 45, .08);
  --dash-bg: #f7f7f1;
  --dash-surface: #eff7f1;
  --dash-card: #ffffff;
  --dash-elevated: #e4eee6;
  --dash-green: #1b5448;
  --dash-accent: #286b5a;
  --dash-text: #18332d;
  --dash-muted: #66746d;
  --dash-border: #dce7de;
  --pine: #1b5448;
  --pine-2: #286b5a;
  --pine-deep: #123c34;
  --sage: #d9e9df;
  --mint: #eff7f1;
  --cream: #f7f7f1;
  --paper: #ffffff;
  --ink: #18332d;
  --muted: #66746d;
  --line: #dce7de;
  --shadow: 0 18px 54px rgba(24, 51, 45, .09);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --theme-bg: #0b1513;
  --theme-surface: #101f1b;
  --theme-card: #172923;
  --theme-raised: #1d332b;
  --theme-text: #f1f5f2;
  --theme-muted: #a0b3a9;
  --theme-border: #294238;
  --theme-input: #12231d;
  --theme-green: #2d8a65;
  --theme-accent: #48b987;
  --theme-shadow: 0 12px 32px rgba(0, 0, 0, .22);
  --dash-bg: #0b1513;
  --dash-surface: #101f1b;
  --dash-card: #172923;
  --dash-elevated: #1d332b;
  --dash-green: #2d8a65;
  --dash-accent: #48b987;
  --dash-text: #f1f5f2;
  --dash-muted: #a0b3a9;
  --dash-border: #294238;
  --pine: #48b987;
  --pine-2: #48b987;
  --pine-deep: #101f1b;
  --sage: #1d332b;
  --mint: #14251f;
  --cream: #0b1513;
  --paper: #172923;
  --ink: #f1f5f2;
  --muted: #a0b3a9;
  --line: #294238;
  --red: #f2aaa5;
  --red-soft: #321f21;
  --shadow: 0 18px 54px rgba(0, 0, 0, .24);
}

html {
  background: var(--theme-bg);
}

body {
  background: var(--theme-bg);
  color: var(--theme-text);
  transition: background-color .18s ease, color .18s ease;
}

body,
body:has(.sidebar-layout),
body:has(.subject-page) {
  background: var(--theme-bg);
  color: var(--theme-text);
}

.site-header,
body:has(.sidebar-layout) .site-header {
  background: color-mix(in srgb, var(--theme-bg) 94%, transparent);
  border-bottom-color: var(--theme-border);
  color: var(--theme-text);
}

.site-header .brand-word,
body:has(.sidebar-layout) .site-header .brand-word {
  color: var(--theme-text);
}

.site-header .brand-word span,
body:has(.sidebar-layout) .site-header .brand-word span {
  color: var(--theme-accent);
}

.brand img {
  width: 38px;
  height: 38px;
  object-fit: contain;
}

.site-footer .brand img {
  width: 36px;
  height: 36px;
}

.site-header .main-nav a,
.site-header .text-link,
body:has(.sidebar-layout) .main-nav a,
body:has(.sidebar-layout) .text-link {
  color: var(--theme-muted);
}

.site-header .main-nav a:hover,
.site-header .main-nav a.is-active,
.site-header .text-link:hover,
body:has(.sidebar-layout) .main-nav a:hover,
body:has(.sidebar-layout) .main-nav a.is-active,
body:has(.sidebar-layout) .text-link:hover {
  color: var(--theme-accent);
}

.site-header .button,
body:has(.sidebar-layout) .site-header .button {
  border-color: var(--theme-green);
  background: var(--theme-green);
  color: #ffffff;
}

.site-header .button-outline {
  border-color: var(--theme-border);
  background: transparent;
  color: var(--theme-text);
}

.menu-toggle span {
  background: var(--theme-text);
}

.theme-toggle {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 10px;
  border: 1px solid var(--theme-border);
  border-radius: 999px;
  background: var(--theme-surface);
  color: var(--theme-text);
  font: 650 11px/1 var(--sans, ui-sans-serif, system-ui, sans-serif);
  white-space: nowrap;
  cursor: pointer;
  transition: background-color .16s ease, border-color .16s ease, color .16s ease, transform .16s ease;
}

.theme-toggle:hover {
  transform: translateY(-1px);
  border-color: var(--theme-accent);
  background: var(--theme-raised);
}

.theme-toggle:active {
  transform: translateY(0);
}

.theme-toggle:focus-visible {
  outline: 3px solid var(--theme-accent);
  outline-offset: 3px;
}

.theme-icon {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}

html[data-theme="light"] .theme-icon-dark,
html[data-theme="dark"] .theme-icon-light {
  display: none;
}

.content-shell,
.section,
.section-tint {
  background-color: var(--theme-bg);
  color: var(--theme-text);
}

.section-tint {
  background-color: var(--theme-surface);
}

.section-heading h2,
.page-heading h1,
.dashboard-main .page-heading h1,
.dashboard-main .panel h2,
.dashboard-main .form-card h1 {
  color: var(--theme-text);
}

.section-heading p,
.page-heading p,
.dashboard-main .page-heading p {
  color: var(--theme-muted);
}

.eyebrow,
.dashboard-main .eyebrow {
  color: var(--theme-accent);
}

.site-footer,
body:has(.sidebar-layout) .site-footer {
  background: var(--theme-surface);
  border-top: 1px solid var(--theme-border);
  color: var(--theme-text);
}

.site-footer p,
.site-footer a,
.site-footer .footer-bottom {
  color: var(--theme-muted);
}

.site-footer .footer-main > div:not(.footer-brand) > a {
  color: var(--theme-green);
}

.site-footer h2 {
  color: var(--theme-text);
}

.content-shell .sidebar-layout .side-nav,
.side-nav {
  border-color: var(--theme-border);
  background: var(--theme-surface);
  color: var(--theme-text);
}

.side-nav a {
  color: var(--theme-muted);
}

.side-nav a:hover,
.side-nav a.is-active {
  background: var(--theme-raised);
  color: var(--theme-text);
}

.account-chip {
  border-bottom-color: var(--theme-border);
}

.account-chip strong,
.dashboard-main .panel h2,
.dashboard-main .form-card h1,
.dashboard-main .quiz-question {
  color: var(--theme-text);
}

.dashboard-main .panel,
.dashboard-main .metric-card,
.dashboard-main .quiz-card,
.dashboard-main .form-card,
.panel,
.form-card,
.quiz-card,
.metric-card,
.stat-card,
.quick-card,
.feature-card,
.profile-question,
.formula-card,
.comparison-list li,
.option-editor,
.journey-card,
.teacher-mini-card,
.teacher-card,
.chapter-nav,
.chapter-card,
.lesson-article {
  border-color: var(--theme-border);
  background-color: var(--theme-card);
  color: var(--theme-text);
}

.dashboard-main .panel p,
.dashboard-main .form-help,
.dashboard-main .metric-card span,
.dashboard-main .metric-card small,
.stat-card > span:not(.eyebrow),
.stat-card small,
.quick-card p,
.activity-row p,
.activity-row small,
.profile-question p,
.profile-question-meta > span:not(.badge),
.formula-card p,
.formula-card small,
.comparison-list li span,
.chapter-card p,
.lesson-article p,
.lesson-article li {
  color: var(--theme-muted);
}

.stat-note,
.activity-row p,
.comparison-list li span {
  color: var(--theme-muted);
}

.stat-card > strong,
.comparison-list li strong,
.formula-card > strong,
.formula-expression {
  color: var(--theme-accent);
}

.stat-divider,
.activity-row,
.result-item {
  border-color: var(--theme-border);
}

.dashboard-main .form-field label,
.form-field label,
.filter-form label,
.history-filters label,
.option-editor legend {
  color: var(--theme-text);
}

.dashboard-main .form-field input,
.dashboard-main .form-field select,
.dashboard-main .form-field textarea,
.form-field input,
.form-field select,
.form-field textarea,
.filter-form select,
.history-filters select,
.history-filters input,
.filter-form input,
.answer-editor textarea,
.notebook-filter-form input,
.notebook-filter-form select {
  border-color: var(--theme-border);
  background-color: var(--theme-input);
  color: var(--theme-text);
  color-scheme: inherit;
}

.form-field input::placeholder,
.form-field textarea::placeholder,
.dashboard-main .form-field input::placeholder,
.dashboard-main .form-field textarea::placeholder {
  color: var(--theme-muted);
  opacity: .8;
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus,
.filter-form select:focus,
.history-filters select:focus,
.history-filters input:focus,
.answer-editor textarea:focus {
  border-color: var(--theme-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--theme-accent) 18%, transparent);
}

input[type="checkbox"],
input[type="radio"],
progress {
  accent-color: var(--theme-green);
}

select option {
  background: var(--theme-card);
  color: var(--theme-text);
}

.dashboard-main .button,
.button {
  border-color: var(--theme-green);
  background: var(--theme-green);
}

.button:hover,
.dashboard-main .button:hover {
  border-color: var(--theme-accent);
  background: var(--theme-accent);
}

.button-quiet,
.dashboard-main .button-quiet {
  border-color: var(--theme-border);
  background: var(--theme-raised);
  color: var(--theme-text);
}

.button-quiet:hover,
.dashboard-main .button-quiet:hover {
  background: color-mix(in srgb, var(--theme-raised) 80%, var(--theme-accent));
  color: var(--theme-text);
}

.button-outline {
  border-color: var(--theme-border);
  color: var(--theme-text);
}

.button-light {
  border-color: var(--theme-card);
  background: var(--theme-card);
  color: var(--theme-green);
}

.data-table,
.chart-summary {
  color: var(--theme-text);
}

.data-table th,
.data-table td,
.dashboard-main .data-table th,
.dashboard-main .data-table td {
  border-bottom-color: var(--theme-border);
  color: var(--theme-muted);
}

.data-table th,
.dashboard-main .data-table th {
  background: var(--theme-surface);
  color: var(--theme-text);
}

.data-table tbody tr:nth-child(even) {
  background: color-mix(in srgb, var(--theme-surface) 55%, transparent);
}

.data-table strong,
.dashboard-main .data-table strong {
  color: var(--theme-text);
}

.table-wrap {
  border-color: var(--theme-border);
}

.empty-state,
.dashboard-main .empty-state {
  border-color: var(--theme-border);
  background: var(--theme-surface);
  color: var(--theme-text);
}

.empty-state h1,
.empty-state h2,
.empty-state h3,
.dashboard-main .empty-state h3 {
  color: var(--theme-text);
}

.empty-state p {
  color: var(--theme-muted);
}

.flash,
.flash-info,
.flash-success,
.flash-error {
  border-color: var(--theme-border);
  background: var(--theme-surface);
  color: var(--theme-text);
}

.flash-success {
  border-color: #b7ddc5;
  background: #e8f5ec;
  color: #1b5448;
}

.flash-error {
  border-color: #efc7c3;
  background: #fbefed;
  color: #9b4141;
}

.flash-info {
  border-color: #c9ded2;
  background: #eff4f2;
  color: #1b5448;
}

.progress-track,
.dashboard-main .progress-track {
  background: var(--theme-raised);
}

.progress-fill,
.dashboard-main .progress-fill {
  background: var(--theme-accent);
}

.activity-row,
.dashboard-main .activity-row,
.dashboard-main .question-list .activity-row {
  border-color: var(--theme-border);
  background: var(--theme-surface);
  color: var(--theme-muted);
}

.activity-dot {
  box-shadow: 0 0 0 4px var(--theme-raised);
}

.quiz-option,
.quiz-feedback,
.callout,
.formula-expression {
  border-color: var(--theme-border);
  background: var(--theme-raised);
  color: var(--theme-text);
}

.quiz-option:hover {
  border-color: var(--theme-accent);
  background: var(--theme-surface);
}

.quiz-question,
.chapter-nav h2,
.chapter-nav a {
  color: var(--theme-text);
}

.chapter-nav a:hover,
.chapter-nav a.is-active {
  background: var(--theme-raised);
  color: var(--theme-accent);
}

.answer-editor,
.answer-editor > label:first-child,
.correct-choice,
.option-editor legend {
  border-color: var(--theme-border);
  color: var(--theme-text);
}

.result-item {
  border-bottom-color: var(--theme-border);
}

.site-header-premium {
  background: color-mix(in srgb, var(--theme-bg) 94%, transparent);
  border-bottom-color: var(--theme-border);
  color: var(--theme-text);
}

.site-header-premium .brand-word,
.site-header-premium .brand-word span {
  color: var(--theme-text);
}

.site-header-premium .main-nav a,
.site-header-premium .text-link {
  color: var(--theme-muted);
}

.site-header-premium .main-nav a:hover,
.site-header-premium .main-nav a.is-active,
.site-header-premium .text-link:hover {
  color: var(--theme-accent);
}

.site-header-premium .button {
  border-color: var(--theme-green);
  background: var(--theme-green);
  color: #ffffff;
  box-shadow: none;
}

.site-header-premium .button:hover {
  background: var(--theme-accent);
  color: #ffffff;
}

.section-dark {
  background: var(--theme-surface);
  color: var(--theme-text);
}

.section-dark .section-heading p,
.section-dark .teacher-card p {
  color: var(--theme-muted);
}

.section-dark .eyebrow,
.section-dark .teacher-card .subject-label {
  color: var(--theme-accent);
}

.dashboard-main .review-card,
.dashboard-main .review-card h3,
.dashboard-main .review-card p,
.dashboard-main .review-card .badge {
  color: #000;
}

.dashboard-main .review-card .badge {
  background: #1b5448;
  color: #b7e5c8;
}

html[data-theme="dark"] .dashboard-main .review-card {
  background: #d9e9df;
}

.subject-card:not(.chem) .subject-label,
.subject-card:not(.chem) .subject-symbol,
.subject-card:not(.chem) h3 {
  color: #000;
}


.section-dark .profile-copy h1,
.section-dark .profile-copy > p,
.section-dark .profile-copy .eyebrow,
.section-dark .profile-stats strong,
.section-dark .profile-stats span {
  color: #2f7b60;
}

html[data-theme="dark"] .section-dark .profile-copy h1,
html[data-theme="dark"] .section-dark .profile-copy > p,
html[data-theme="dark"] .section-dark .profile-copy .eyebrow,
html[data-theme="dark"] .section-dark .profile-stats strong,
html[data-theme="dark"] .section-dark .profile-stats span {
  color: #70c994;
}

.section-dark .profile-copy .button-light,
.section-dark .profile-copy .button-light:hover {
  border-color: #ffffff;
  background: #ffffff;
  color: #1B5448;
}

.section-dark .teacher-card {
  border-color: var(--theme-border);
  background: var(--theme-card);
}

.section-dark .teacher-card h2,
.section-dark .teacher-card h3 {
  color: var(--theme-text);
}

.section-dark .teacher-card a,
.section-dark .text-link,
.profile-publications .text-link {
  color: var(--theme-accent);
}

html[data-theme="dark"] .profile-publications .review-card,
html[data-theme="dark"] .profile-publications .review-card h3,
html[data-theme="dark"] .profile-publications .review-card p,
html[data-theme="dark"] .profile-publications .review-card .text-link,
html[data-theme="dark"] .profile-publications .review-card .badge {
  color: #000000;
}

html[data-theme="dark"] .profile-publications .review-card .badge {
  background: #eff7f1;
}

.profile-publications .review-card {
  background: #d9e9df;
}

html[data-theme="dark"] .profile-publications .profile-question,
html[data-theme="dark"] .profile-publications .profile-question:before,
html[data-theme="dark"] .profile-publications .profile-question-meta > span,
html[data-theme="dark"] .profile-publications .profile-question p,
html[data-theme="dark"] .profile-publications .profile-question .badge {
  color: #000000;
}

html[data-theme="dark"] .profile-publications .profile-question .badge {
  background: #eff7f1;
}

.profile-publications .profile-question {
  background: #d9e9df;
}

.subject-page {
  min-height: calc(100vh - 82px);
  background: var(--theme-bg);
  color: var(--theme-text);
}

.subject-page:before {
  background: color-mix(in srgb, var(--theme-accent) 12%, transparent);
}

.subject-page:after {
  background: color-mix(in srgb, var(--theme-green) 9%, transparent);
}

.subject-page .subject-hero {
  background: linear-gradient(120deg, var(--theme-surface), var(--theme-card));
  border-color: var(--theme-border);
  color: var(--theme-text);
  box-shadow: var(--theme-shadow);
}

.subject-page .subject-hero:before {
  background: linear-gradient(125deg, transparent 45%, color-mix(in srgb, var(--theme-accent) 9%, transparent));
}

.subject-page .subject-hero .eyebrow,
.subject-page .eyebrow,
.subject-page .subject-hero-meta,
.subject-page .subject-hero-copy > p,
.subject-page .subject-hero-meta strong,
.subject-page .subject-hero h1 {
  color: var(--theme-text);
}

.subject-page .subject-hero-meta,
.subject-page .subject-hero-copy > p {
  color: var(--theme-muted);
}

.subject-page .subject-hero-art,
.subject-page .chapters-panel,
.subject-page .chapter-card,
.subject-page .journey-card,
.subject-page .teacher-mini-card,
.subject-page .study-tips {
  border-color: var(--theme-border);
  background: var(--theme-card);
  color: var(--theme-text);
  box-shadow: var(--theme-shadow);
}

.subject-page .subject-hero-art {
  background-color: var(--theme-raised);
}

.subject-page .chapter-card h3,
.subject-page .journey-card h2,
.subject-page .teacher-mini-profile h3,
.subject-page .study-tips h3 {
  color: var(--theme-text);
}

.subject-page .chapter-card p,
.subject-page .journey-card > p:not(.form-help),
.subject-page .teacher-mini-card > p,
.subject-page .study-tips p,
.subject-page .journey-card .form-help {
  color: var(--theme-muted);
}

.subject-page .chapter-access,
.subject-page .teacher-mini-profile span,
.subject-page .teacher-mini-card > .text-link {
  border-top-color: var(--theme-border);
  color: var(--theme-accent);
}

.subject-page .study-tips-icon {
  background: var(--theme-raised);
  color: var(--theme-accent);
}

.subject-page .empty-state {
  border-color: var(--theme-border);
  background: var(--theme-surface);
  color: var(--theme-text);
}

.site-header-premium .main-nav a.is-active:after {
  background: var(--theme-accent);
  box-shadow: 0 0 10px color-mix(in srgb, var(--theme-accent) 50%, transparent);
}

.form-card,
.auth-card,
.login-card {
  border-color: var(--theme-border);
  background: var(--theme-card);
  color: var(--theme-text);
}

.form-card h1,
.form-card h2,
.form-card h3 {
  color: var(--theme-text);
}

.form-card > p {
  color: var(--theme-muted);
}

.status-pill,
.badge,
.chapter-count-badge {
  border-color: var(--theme-border);
}

dialog,
[role="dialog"],
.modal,
.modal-content,
.dropdown-menu,
.menu-dropdown {
  border-color: var(--theme-border);
  background: var(--theme-card);
  color: var(--theme-text);
  color-scheme: inherit;
}

dialog::backdrop,
.modal-backdrop {
  background: rgba(0, 0, 0, .55);
}

::selection {
  background: color-mix(in srgb, var(--theme-accent) 35%, transparent);
  color: var(--theme-text);
}

@media (max-width: 620px) {
  .site-header {
    gap: 8px;
    padding-inline: 16px;
  }

  .theme-toggle {
    min-height: 34px;
    gap: 5px;
    padding: 0 8px;
    font-size: 10px;
  }

  .theme-icon {
    width: 15px;
    height: 15px;
  }
}

@media (prefers-reduced-motion: reduce) {
  body,
  .theme-toggle {
    transition: none;
  }
}
