/* Dark appearance for the existing portal. Load after the page styles.
   Shared palette and theme selection live in theme.css / theme.js. */
html[data-theme="dark"] .student-workspace {
  --line: #394432;
  --muted: #a7b49d;
}

html[data-theme="dark"] :is(.portal, .auth-page) {
  background: var(--paper);
  color: var(--ink);
}

html[data-theme="dark"] ::selection {
  background: var(--lime);
  color: var(--theme-on-accent);
}

html[data-theme="dark"] :is(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline-color: var(--lime);
}

/* Navigation and shared actions. */
html[data-theme="dark"] .sidebar {
  background: var(--theme-nav);
  border-color: var(--line);
  box-shadow: 15px 0 30px #00000025;
}

html[data-theme="dark"] .sidebar nav > a {
  color: var(--muted);
}

html[data-theme="dark"] .sidebar nav > a:hover {
  background: var(--theme-raised);
  color: var(--ink);
}

html[data-theme="dark"] .sidebar nav > a[aria-current="page"] {
  background: var(--lime-soft);
  color: var(--lime);
  border-color: var(--line);
}

html[data-theme="dark"] :is(.nav-divider, .profile-link) {
  border-color: var(--line);
}

html[data-theme="dark"] :is(.wordmark b span, .points-line > span:last-child, .next-symbol) {
  color: var(--lime);
}

html[data-theme="dark"] .avatar {
  background: var(--lime-soft);
  color: var(--theme-good);
}

html[data-theme="dark"] :is(.button.dark, .button.lime) {
  background: var(--lime);
  color: var(--theme-on-accent);
  border-color: var(--lime);
}

html[data-theme="dark"] :is(.button.dark, .button.lime):hover {
  background: #d0fa74;
  color: var(--theme-on-accent);
  border-color: #d0fa74;
}

html[data-theme="dark"] .button.outline {
  background: transparent;
  color: var(--ink);
  border-color: #738266;
}

html[data-theme="dark"] .button.outline:hover {
  background: var(--theme-raised);
  color: var(--ink);
  border-color: var(--theme-good);
}

html[data-theme="dark"] :is(.text-link, .back-link, .text-button, .auth-other a, .auth-recovery a, .resource-list > a) {
  color: var(--theme-blue);
}

html[data-theme="dark"] :is(.text-link, .back-link, .text-button, .auth-other a, .auth-recovery a, .resource-list > a):hover {
  color: #d3e9f6;
}

html[data-theme="dark"] .text-button.danger {
  color: #f0b8a1;
}

html[data-theme="dark"] .text-button.danger:hover {
  color: #ffdac9;
}

html[data-theme="dark"] .circle-link {
  color: var(--lime);
  border-color: #738266;
}

html[data-theme="dark"] .circle-link:hover,
html[data-theme="dark"] .skip-link:focus {
  background: var(--lime);
  color: var(--theme-on-accent);
}

/* Reading hierarchy remains the same at every viewport size. */
html[data-theme="dark"] :is(
  .help, .sidebar-label, .breadcrumb, .workspace-footer, .profile-link small,
  .header-profile, .logout, .next-module, .next-step p, .big-number span,
  .progress-panel p, .points-line small, .rhythm h3 > span:not(.flame),
  .day, .achievement p, .achievement-mark, .row-number, .lesson-row .row-number,
  .module-row p, .lesson-row p, .module-meta, .module-row .lock-label,
  .lock-label, .lock-label strong, .reading-action > span,
  .practice > summary > span:last-child, .resource-list small,
  .stat-card > span, .stat-card small, .queue-person small,
  .mentor-bottom p, .empty-state p, .student-progress > span,
  .compact-progress span, .grant-list > p, .route-list p, .library-list small,
  .pagination, .account-row small, .account-details dt,
  .rank, .rank-name small, .rank-row small, .auth-back, .auth-other, .auth-foot,
  .auth-bottom, .auth-story .eyebrow, .auth-story h1 + p,
  .course-stages li > div > span
) {
  color: var(--muted);
}

html[data-theme="dark"] :is(
  .module-row h2, .module-row h3, .module-row.locked h2, .module-row.locked h3,
  .lesson-row h3, .progress-panel p strong, .mentor-bottom strong,
  .submission-text, .prose, .prose p, .prose li, .prose dd,
  .prose strong, .prose h1, .prose h2, .prose h3, .prose h4, .prose h5, .prose h6
) {
  color: var(--ink);
}

html[data-theme="dark"] :is(.module-row h2 a, .module-row h3 a, .lesson-row h3 a, .library-list > a):hover {
  color: var(--lime);
}

html[data-theme="dark"] .library-list > a:hover strong {
  color: var(--lime);
}

/* Neutral surfaces keep the bright accent reserved for actions. */
html[data-theme="dark"] :is(
  .panel, .progress-panel, .rhythm, .next-step, .achievement, .achievement.earned,
  .module-row, .module-row.locked, .stat-card, .audit-table, .trainer-entry,
  .qr-panel, .confirm-dialog
) {
  background: var(--white);
  color: var(--ink);
  border-color: var(--line);
}

html[data-theme="dark"] .student-workspace :is(.panel, .progress-panel, .rhythm, .achievement, .next-step) {
  box-shadow: 0 3px 14px #00000018;
}

html[data-theme="dark"] .student-workspace .module-row {
  box-shadow: inset 4px 0 0 var(--stage-accent), 0 3px 12px #00000018;
}

html[data-theme="dark"] .module-row:hover {
  border-color: var(--stage-line, var(--line));
}

html[data-theme="dark"] .next-heading .eyebrow,
html[data-theme="dark"] .student-workspace .next-step .next-heading {
  color: var(--lime);
}

html[data-theme="dark"] :is(.stat-card.emphasized, .mentor-feedback) {
  background: var(--lime-soft);
  border-color: #536b3a;
  color: var(--ink);
}

html[data-theme="dark"] :is(.stat-card.emphasized > span, .stat-card.emphasized small, .mentor-feedback p) {
  color: var(--theme-good);
}

html[data-theme="dark"] .stat-card.emphasized strong {
  color: var(--lime);
}

html[data-theme="dark"] :is(.submitted-work, .recovery-codes code) {
  background: var(--theme-raised);
  color: var(--ink);
  border-color: var(--line);
}

html[data-theme="dark"] :is(.achievement.earned .achievement-mark, .empty-symbol, .mentor-bottom > span, .week-mark) {
  color: var(--theme-good);
}

html[data-theme="dark"] .day i {
  background: var(--theme-raised);
  color: var(--muted);
}

html[data-theme="dark"] .day.active i {
  background: #392f20;
  color: var(--orange);
}

html[data-theme="dark"] progress {
  background: var(--theme-raised);
}

html[data-theme="dark"] progress::-webkit-progress-bar {
  background: var(--theme-raised);
}

html[data-theme="dark"] progress::-webkit-progress-value {
  background: var(--lime);
}

html[data-theme="dark"] progress::-moz-progress-bar {
  background: var(--lime);
}

/* Semantic status colors stay distinct from the primary button. */
html[data-theme="dark"] .pill {
  background: var(--theme-raised);
  color: var(--ink);
  border-color: #56654c;
}

html[data-theme="dark"] :is(.pill.green, .notice) {
  background: #293621;
  color: var(--theme-good);
  border-color: #536b3a;
}

html[data-theme="dark"] :is(.pill.amber, .pill.pending, .notice.warning) {
  background: #392f20;
  color: var(--orange);
  border-color: #78613e;
}

html[data-theme="dark"] :is(.notice.error, .form-errors) {
  background: #38271f;
  color: #f0b8a1;
  border-color: #805b46;
}

html[data-theme="dark"] .field-errors {
  color: #f0b8a1;
}

html[data-theme="dark"] :is(.submission-state, .submission-status, .rank-row.is-me, .notice.info) {
  background: #202e33;
  color: var(--ink);
  border-color: #668da1;
}

html[data-theme="dark"] .submission-status a {
  color: var(--theme-blue);
}

html[data-theme="dark"] :is(.dark-panel, .auth-story) {
  background: var(--theme-nav);
  color: var(--ink);
  border-color: var(--line);
}

html[data-theme="dark"] .dark-panel h2 {
  color: var(--lime);
}

html[data-theme="dark"] :is(.dark-panel .eyebrow, .dark-panel p) {
  color: var(--muted);
}

/* Forms, account management and authentication. QR pixels remain untouched. */
html[data-theme="dark"] :is(
  .field input:not([type="checkbox"]), .field select, .field textarea,
  .search-form input, .inline-form select, textarea[data-copy-source]
) {
  background: var(--theme-nav);
  color: var(--ink);
  border-color: #738266;
  caret-color: var(--lime);
}

html[data-theme="dark"] :is(input, textarea)::placeholder {
  color: var(--muted);
  opacity: 1;
}

html[data-theme="dark"] .field :is(input, textarea, select)[aria-invalid="true"] {
  border-color: #f0b8a1;
}

html[data-theme="dark"] .checkbox-field input {
  accent-color: var(--lime);
}

html[data-theme="dark"] .password-toggle {
  color: var(--muted);
}

html[data-theme="dark"] .password-toggle:hover,
html[data-theme="dark"] .password-toggle[aria-pressed="true"] {
  background: var(--theme-raised);
  color: var(--lime);
}

html[data-theme="dark"] .auth-other a {
  border-color: #668da1;
}

html[data-theme="dark"] .qr-panel summary {
  color: var(--theme-blue);
}

html[data-theme="dark"] .qr-panel img {
  background: #fff;
}

html[data-theme="dark"] .account-filters a {
  background: var(--white);
  color: var(--ink);
  border-color: #738266;
}

html[data-theme="dark"] .account-filters a:hover {
  background: var(--theme-raised);
}

html[data-theme="dark"] .account-filters a[aria-current="page"] {
  background: var(--lime-soft);
  color: var(--lime);
  border-color: var(--lime);
}

html[data-theme="dark"] .account-danger {
  border-color: #805b46;
}

html[data-theme="dark"] .confirm-dialog::backdrop {
  background: #050904b3;
}

/* Four course stages retain their own hues in badges and number tiles. */
html[data-theme="dark"] .stage-foundation {
  --stage-ink: #b4dc90;
  --stage-wash: #293621;
  --stage-line: #536b3a;
  --stage-accent: #a4c976;
}

html[data-theme="dark"] .stage-practice {
  --stage-ink: #a5cbe2;
  --stage-wash: #202e33;
  --stage-line: #486a7d;
  --stage-accent: #88b7d0;
}

html[data-theme="dark"] .stage-project {
  --stage-ink: #d3aed9;
  --stage-wash: #302737;
  --stage-line: #6c527b;
  --stage-accent: #b69acb;
}

html[data-theme="dark"] .stage-concurrency {
  --stage-ink: #ebbd78;
  --stage-wash: #392f20;
  --stage-line: #78613e;
  --stage-accent: #d5aa6b;
}

html[data-theme="dark"] .module-row .row-number,
html[data-theme="dark"] .module-row.locked .row-number {
  color: var(--stage-ink, var(--muted));
}

/* Material prose: readable headings, tables, callouts and code. */
html[data-theme="dark"] .prose a {
  color: var(--theme-blue);
}

html[data-theme="dark"] .prose a:hover {
  color: #d3e9f6;
}

html[data-theme="dark"] .prose li::marker {
  color: var(--theme-good);
}

html[data-theme="dark"] :is(.prose h2, .prose th, .prose td, .prose hr) {
  border-color: var(--line);
}

html[data-theme="dark"] :is(.prose th, .prose td) {
  color: var(--ink);
}

html[data-theme="dark"] :is(.prose th, .audit-table th) {
  background: var(--theme-raised);
  color: var(--ink);
}

html[data-theme="dark"] .prose tbody tr:nth-child(even) {
  background: #262e22;
}

html[data-theme="dark"] .prose :not(pre) > code {
  background: var(--theme-raised);
  color: var(--theme-good);
  border-color: #56654c;
}

html[data-theme="dark"] .prose blockquote {
  background: var(--lime-soft);
  border-color: var(--theme-good);
  color: var(--ink);
}

html[data-theme="dark"] .prose blockquote p {
  color: var(--ink);
}

html[data-theme="dark"] :is(.prose pre, .prose .codehilite) {
  background: var(--theme-code);
  color: var(--ink);
  border-color: var(--line);
  box-shadow: none;
}

html[data-theme="dark"] .prose .codehilite pre {
  background: transparent;
  color: var(--ink);
}

html[data-theme="dark"] .code-language {
  background: var(--theme-raised);
  color: var(--muted);
  border-color: var(--line);
}

html[data-theme="dark"] .code-language::before {
  color: var(--lime);
}
