/* Shared site appearance. Light retains the existing palette. */
.site-theme-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-bottom: 16px;
  font-size: 14px;
  color: #637282;
}
.site-theme-switch { display: inline-flex; gap: 2px; padding: 3px; border: 1px solid #ccccd4; border-radius: 8px; }
.site-theme-switch button { border: 0; border-radius: 5px; padding: 5px 13px; background: transparent; color: #637282; font: inherit; }
.site-theme-switch button[aria-pressed="true"] { background: #e7f1ff; color: #0757a6; }
.site-theme-switch button:focus-visible { outline: 2px solid #0066cc; outline-offset: 3px; }

html[data-site-theme="dark"] {
  color-scheme: dark;
  --background-color: #141a22;
  --color-text: #e2e8f0;
  --color-text-secondary: #a8b5c6;
  --color-link: #8bbdff;
  --color-inline-code: #e2e8f0;
  --color-inline-code-bg: #252f3d;
  --color-border: #435165;
  --color-border-heavy: #60718a;
  --color-table-heading: #252f3d;
  --theme-surface: #1c2531;
  --theme-blue: #22364f;
  --theme-green-bg: #20392d;
  --theme-green: #acd4a2;
  --theme-red-bg: #442b2b;
  --theme-red: #ffb3a5;
  background: var(--background-color);
}
html[data-site-theme="dark"] body { background: var(--background-color); color: var(--color-text); }
html[data-site-theme="dark"] :is(h1, h2, h3, h4, h5, h6) { color: var(--color-text); }
html[data-site-theme="dark"] :is(a, a:visited, a code) { color: var(--color-link); }
html[data-site-theme="dark"] :is(.site-nav, .accordion-item, #pt-badge, .pt-bulk-btn, .pt-check, .pt-flag, .timed-button) {
  background: var(--theme-surface); color: var(--color-text); border-color: var(--color-border);
}
html[data-site-theme="dark"] .accordion-button { background: var(--theme-surface); color: var(--color-link); }
html[data-site-theme="dark"] .accordion-button:not(.collapsed) { background: var(--theme-blue); box-shadow: inset 0 -1px 0 var(--color-border); }
html[data-site-theme="dark"] .accordion-button::after { filter: brightness(0) invert(0.85); }
html[data-site-theme="dark"] .accordion-button:focus { border-color: var(--color-link); box-shadow: 0 0 0 .2rem #8bbdff40; }
html[data-site-theme="dark"] :is(.site-theme-controls, .site-theme-switch button, #timed-note) { color: var(--color-text-secondary); }
html[data-site-theme="dark"] .site-theme-switch { border-color: var(--color-border); background: var(--theme-surface); }
html[data-site-theme="dark"] .site-theme-switch button[aria-pressed="true"] { background: var(--theme-blue); color: var(--color-link); }
html[data-site-theme="dark"] :focus-visible { outline-color: var(--color-link); }
html[data-site-theme="dark"] :is(.timed-bar, [style*="background:#e8eaff"]) {
  background: var(--theme-blue) !important; border-color: #8bbdff !important;
}
html[data-site-theme="dark"] .timed-button:hover { background: var(--theme-blue); }
html[data-site-theme="dark"] .timed-track { fill: var(--theme-surface); stroke: var(--theme-blue); }
html[data-site-theme="dark"] .timed-fill { stroke: var(--color-link); }
html[data-site-theme="dark"] .timed-timer.low :is(.timed-fill, #timed-clock) { stroke: var(--theme-red); color: var(--theme-red); }
html[data-site-theme="dark"] .timed-timer.paused :is(.timed-fill, #timed-clock) { stroke: var(--color-text-secondary); color: var(--color-text-secondary); }
html[data-site-theme="dark"] :is(.pt-check:hover, .pt-check.pt-check-on, .pt-bulk-btn:hover, .pt-bulk-undo, .pt-item-done) {
  background: var(--theme-green-bg); color: var(--theme-green); border-color: #587c53;
}
html[data-site-theme="dark"] :is(.pt-flag:hover, .pt-flag.pt-flag-on) { background: var(--theme-red-bg); color: var(--theme-red); border-color: #b4776e; }
html[data-site-theme="dark"] :is(.pt-badge-flags, .pt-item-flag-icon) { color: var(--theme-red); }
html[data-site-theme="dark"] .pt-item:hover { background: #303c4c; color: var(--color-text); }
html[data-site-theme="dark"] .pt-bar-track { background: #354252; }
html[data-site-theme="dark"] .pt-bar-fill { background: #90ba83; }
html[data-site-theme="dark"] .pt-badge-list { border-color: var(--color-border); }
html[data-site-theme="dark"] #pt-badge.pt-celebrate .pt-badge-pct::after { color: var(--theme-green); }
html[data-site-theme="dark"] .pill-lecture { background: var(--theme-blue); color: var(--color-link); border-color: #557aa5; }
html[data-site-theme="dark"] :is(table, .table) { color: var(--color-text); border-color: var(--color-border); }
html[data-site-theme="dark"] th { background: var(--color-table-heading); }
html[data-site-theme="dark"] :is(td, th) { border-color: var(--color-border); }
html[data-site-theme="dark"] pre { background: var(--theme-surface); color: var(--color-text); }
html[data-site-theme="dark"] code { color: var(--color-inline-code); background-color: var(--color-inline-code-bg); }
html[data-site-theme="dark"] pre code { color: inherit; background-color: inherit; }
html[data-site-theme="dark"] code span { color: var(--color-text); }
html[data-site-theme="dark"] code :is(.kw, .cf, .im, .bu) { color: #b6a9ff; }
html[data-site-theme="dark"] code :is(.st, .ch, .vs, .ss) { color: #acd4a2; }
html[data-site-theme="dark"] code :is(.dv, .fl, .bn, .cn) { color: #ffca8a; }
html[data-site-theme="dark"] code :is(.co, .an, .cv) { color: #a8b5c6; }
html[data-site-theme="dark"] code :is(.fu, .dt, .at) { color: #8bd5e8; }
html[data-site-theme="dark"] code :is(.al, .er) { color: #ffb3a5; }

/* Keep all instructional image pixels intact, including diagrams and datasets. */
html[data-site-theme] img { max-width: 100%; height: auto; }
/* Small screens need space for the fixed navigation and progress badge. */
@media (max-width: 600px) {
  html[data-site-theme] body { padding-left: 5%; padding-right: 5%; padding-bottom: 150px; }
  html[data-site-theme] table { min-width: 0; max-width: 100%; }
  html[data-site-theme] div.sourceCode { overflow-x: auto; }
  html[data-site-theme] pre > code { white-space: pre; }
  html[data-site-theme] .accordion-body { padding: 1rem .75rem; }
  html[data-site-theme] #pt-badge { right: 12px; bottom: 12px; min-width: 190px; padding: 10px 12px; }
}

/* Homepage dashboard and review lists. */
html[data-site-theme="dark"] {
  --color-text-primary: #e2e8f0;
  --color-sidenote: #a8b5c6;
  --highlight-red: #593336;
  --highlight-yellow: #514323;
  --highlight-green: #29442f;
  --highlight-blue: #294264;
  --highlight-purple: #40345e;
}
html[data-site-theme="dark"] :is(.hp-card, .hp-review-card, .btn-light) {
  background: var(--theme-surface); border-color: var(--color-border); color: var(--color-text);
}
html[data-site-theme="dark"] :is(.btn-light:hover, .btn-light:focus, .hp-bylec-row:hover) { background: #303c4c; border-color: var(--color-border-heavy); color: var(--color-link); }
html[data-site-theme="dark"] :is(.hp-card-label:hover, .hp-lec-started, .pt-all-hidden) { color: var(--theme-green); }
html[data-site-theme="dark"] :is(.hp-lec-progress, .hp-bylec-topic) { color: var(--color-text-secondary); }
html[data-site-theme="dark"] :is(.hp-ex-flag, .hp-review-label, .hp-review-count, .hp-review-col-count, .hp-bylec-count, .hp-lec-flag) { color: var(--theme-red); }
html[data-site-theme="dark"] :is(.hp-ex-bar, .hp-bar-track, .hp-lec-bar) { background: #354252; }
html[data-site-theme="dark"] :is(.hp-ex-fill, .hp-bar-fill, .hp-lec-bar > span) { background: #90ba83; }
html[data-site-theme="dark"] .hp-bylec-bar { background: var(--theme-red-bg); }
html[data-site-theme="dark"] .hp-bylec-bar > span { background: #e49687; }
html[data-site-theme="dark"] .hp-review-chip { background: var(--theme-red-bg); border-color: #b4776e; color: var(--theme-red); }
html[data-site-theme="dark"] .hp-review-chip:hover { background: #583737; border-color: var(--theme-red); }
html[data-site-theme="dark"] :is(.hp-ex-list, .hp-review-list, .hp-review-col-head, .hp-review-bylec, .pt-hide-toggle) { border-color: var(--color-border); }
html[data-site-theme="dark"] :is(.hp-card-caret, .hp-review-caret, .pt-expand) { filter: brightness(0) invert(.85); }
html[data-site-theme="dark"] .hp-review-empty { opacity: 1; }

/* Lecture pages and Bootstrap controls. */
html[data-site-theme="dark"] .lec-sort-box { background: var(--theme-blue); border-color: var(--color-border); }
html[data-site-theme="dark"] .lec-sort-box label { color: var(--color-link); }
html[data-site-theme="dark"] .form-select {
  color: var(--color-text); background-color: var(--theme-surface); border-color: var(--color-border);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='%23e2e8f0' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3E%3C/svg%3E");
}
html[data-site-theme="dark"] .pt-all-hidden { background: var(--theme-green-bg); }
html[data-site-theme="dark"] .table {
  --bs-table-bg: transparent;
  --bs-table-striped-bg: #202b39;
  --bs-table-striped-color: #e2e8f0;
  --bs-table-hover-bg: #303c4c;
  --bs-table-hover-color: #e2e8f0;
  --bs-table-active-bg: #303c4c;
  --bs-table-active-color: #e2e8f0;
}
/* Existing authored inline notices are themed without asking tutors to edit Markdown. */
html[data-site-theme="dark"] [style*="color:#5c636a"] { color: var(--color-text-secondary) !important; }
html[data-site-theme="dark"] [style*="color:red"] { color: var(--theme-red) !important; }
html[data-site-theme="dark"] :is(.text-muted, blockquote) { color: var(--color-text-secondary) !important; }
html[data-site-theme="dark"] input { accent-color: #8bbdff; }
@media (max-width: 600px) {
  html[data-site-theme] table { display: block; width: 100% !important; overflow-x: auto; }
  html[data-site-theme] .katex-display { overflow-x: auto; overflow-y: hidden; padding-block: 3px; }
  html[data-site-theme] :is(.hp-card[data-cat="midterm"], .hp-card[data-cat="final"]) .hp-ex-list { columns: 2; }
}
