/* Shared appearance tokens and controls for the portal, course pages and HTML seminar work. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #070918;
  --panel: rgba(18, 21, 49, .78);
  --panel2: rgba(12, 15, 40, .9);
  --line: rgba(161, 151, 255, .19);
  --text: #f3f2ff;
  --muted: #aaa9d0;
  --cyan: #7ce7ff;
  --purple: #a78bfa;
  --pink: #e879f9;
  --theme-control-bg: #11152d;
  --theme-control-border: rgba(161,151,255,.3);
  --theme-control-text: #f3f2ff;
  --color-bg: #0f1a0f;
  --color-bg-deep: #080f08;
  --color-surface: #162016;
  --color-text: #e8f0e8;
  --color-text-secondary: #b8ccb8;
  --color-text-muted: #7a987a;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f8f1e2;
  --panel: rgba(242, 230, 204, .8);
  --panel2: rgba(237, 220, 184, .95);
  --line: rgba(112, 82, 43, .21);
  --text: #3a2b1d;
  --muted: #6f5c47;
  --cyan: #946018;
  --purple: #875b37;
  --pink: #ad6650;
  --theme-control-bg: #f1e5c9;
  --theme-control-border: #d6c298;
  --theme-control-text: #3a2b1d;
  --color-bg: #faf4e6;
  --color-bg-deep: #efdfbe;
  --color-surface: #f0e3c7;
  --color-text: #382919;
  --color-text-secondary: #70543a;
  --color-text-muted: #8b7354;
}

.theme-control {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
  padding: 5px 8px 5px 10px;
  border: 1px solid var(--theme-control-border, rgba(161,151,255,.3));
  border-radius: 11px;
  background: var(--theme-control-bg, #11152d);
  color: var(--theme-control-text, #f3f2ff);
  font: 700 11px/1.2 Inter, ui-sans-serif, system-ui, sans-serif;
}
.theme-control select {
  max-width: 142px;
  border: 0;
  outline: 0;
  padding: 6px 22px 6px 7px;
  border-radius: 7px;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}
.theme-control select option { background: var(--theme-control-bg, #11152d); color: var(--theme-control-text, #f3f2ff); }
.hero-actions .theme-control { margin: 0 2px; }
.topbar .theme-control { margin-left: auto; }
.topbar #accountActions { margin-left: 0; }

/* Use one shape, height, spacing and interaction style for page-level return controls. */
:where(.back-main, .back-link, .portal-back, .db-back, .menu-toolbar .mini-home) {
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--line) !important;
  border-radius: 10px !important;
  padding: 9px 13px !important;
  background: rgba(124,231,255,.08) !important;
  background: color-mix(in srgb, var(--cyan) 8%, transparent) !important;
  color: var(--text) !important;
  font: 750 12px/1.25 Inter, ui-sans-serif, system-ui, sans-serif !important;
  text-decoration: none !important;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color .18s, background .18s, transform .18s;
}
:where(.back-link, .portal-back, .db-back, .menu-toolbar .mini-home) { display: inline-flex; }
:where(.back-main, .back-link, .portal-back, .db-back, .menu-toolbar .mini-home):hover {
  border-color: rgba(148,96,24,.65) !important;
  border-color: color-mix(in srgb, var(--cyan) 62%, var(--line)) !important;
  background: rgba(124,231,255,.14) !important;
  background: color-mix(in srgb, var(--cyan) 14%, transparent) !important;
  transform: translateY(-1px);
}

/* Main portal light palette. */
html[data-theme="light"] body.studyguide-portal {
  background: radial-gradient(ellipse at 12% 2%, #f2dfb9 0, transparent 39%), radial-gradient(ellipse at 92% 78%, #e8d9bc 0, transparent 40%), #f8f1e2 !important;
  color: #3a2b1d !important;
}
html[data-theme="light"] body.studyguide-portal:before {
  opacity: .4 !important;
  background-image: url("dog-theme-paws.svg") !important;
  background-size: 205px 205px !important;
  background-repeat: repeat !important;
}
html[data-theme="light"] body.studyguide-portal:after {
  content: "";
  position: fixed;
  z-index: 0;
  right: clamp(-30px, 1vw, 18px);
  bottom: -12vh;
  width: clamp(260px, 29vw, 455px);
  height: clamp(420px, 76vh, 780px);
  pointer-events: none;
  opacity: .13;
  background: url("dog-golden-retriever.png") center bottom / contain no-repeat;
}
html[data-theme="light"] body.studyguide-portal > .wrap { position: relative; z-index: 1; }
/* Keep the large page regions open against the page background. */
html[data-theme="light"] body.studyguide-portal :is(.panel, .home-screen, .semester-hub, .course-hub, .db-portal, .db-library, .menu, .main) {
  border-color: transparent !important;
  background: transparent !important;
  color: #3a2b1d !important;
  box-shadow: none !important;
  backdrop-filter: none !important;
}
/* Dialogs remain distinct, but use a soft tinted surface instead of stark white. */
html[data-theme="light"] body.studyguide-portal :is(.auth-card, .auth-dialog, .user-menu-panel) {
  border-color: #d5c49e !important;
  background: rgba(244,234,211,.97) !important;
  color: #3a2b1d !important;
  box-shadow: 0 18px 48px rgba(86,60,25,.16) !important;
}
html[data-theme="light"] body.studyguide-portal :is(.sheet, .db-entry-card, .db-summary-stat, .db-detail-panel, .db-doc-panel, .db-handout-card, .db-schema-card, .db-tool-card, .db-practice-card, .guide-card, .tile, .mini-stat, .term-card) {
  border-color: #d8c9a9 !important;
  background: rgba(242,232,210,.88) !important;
  color: #3a2b1d !important;
}
html[data-theme="light"] body.studyguide-portal :is(.option-card, .course-card, .semester-card, .semester-card.current) {
  border-color: #d5c49e !important;
  background: linear-gradient(145deg, #f4ead4, #ebdbb9) !important;
  color: #3a2b1d !important;
  box-shadow: 0 10px 25px rgba(86,60,25,.08) !important;
}
html[data-theme="light"] body.studyguide-portal :is(.section-title, .course-description, .option-card p, .semester-intro, .semester-status, .group-note, .guide-card p, .guide-head p, .section-intro p, .section-intro, .db-note, .db-reading, .db-detail-panel p, .db-handout-card small, .db-schema-card small, .home-hint, .auth-card-intro, .auth-field label, .auth-local-note, .course-card-footer, .tile span, .mini-stat span) {
  color: #6b5945 !important;
}
html[data-theme="light"] body.studyguide-portal :is(.welcome h2, .home-screen h2, .semester-hub h2, .course-hub h2, .db-portal h2, .db-library h2, .db-entry-card strong, .course-card strong, .guide-card h3, .db-detail-panel h3, .db-library-title, .auth-card h2) {
  color: #392a1d !important;
}
html[data-theme="light"] body.studyguide-portal :is(.ex-btn, .db-nav-btn, .db-subtab, .db-relation-btn, .db-practice-actions button, .navrow button, .guide-content-nav button) {
  color: #57452f !important;
  background-color: #eee2c8 !important;
}
html[data-theme="light"] body.studyguide-portal :is(.search, .auth-field input, .auth-password-row input, .db-filter-row input, .db-filter-row select, .db-practice-input, .db-code-output) {
  border-color: #d0bd96 !important;
  background: #fbf5e9 !important;
  color: #392a1d !important;
}
html[data-theme="light"] body.studyguide-portal .grad { background-image: linear-gradient(100deg, #684b2b 5%, #a66b21 48%, #7c623e 95%) !important; }
html[data-theme="light"] body.studyguide-portal :is(.description, .whybox, .quicklinks, .db-callout, .db-note, .tools-note) {
  border-color: #dfc99d !important;
  background: linear-gradient(120deg, #f1e4c8, #f3e8d8) !important;
  color: #59462e !important;
}
html[data-theme="light"] body.studyguide-portal .description .desc-label,
html[data-theme="light"] body.studyguide-portal .answer b,
html[data-theme="light"] body.studyguide-portal .block-title,
html[data-theme="light"] body.studyguide-portal .guide-card h3,
html[data-theme="light"] body.studyguide-portal .db-label { color: #8d5c18 !important; }
html[data-theme="light"] body.studyguide-portal :is(.math, .guide-formula, .db-code-wrap pre, .worked-example pre, .solution pre, .work-item pre) {
  border-color: #d7c69e !important;
  background: #efe5d0 !important;
  color: #493a29 !important;
}
html[data-theme="light"] body.studyguide-portal .semester-card.locked { background: #eee8dc !important; }
html[data-theme="light"] body.studyguide-portal .semester-status { color: #75634d !important; }
html[data-theme="light"] body.studyguide-portal .foot { color: #8a775d !important; }
html[data-theme="light"] body.studyguide-portal .orb { display: none !important; }
html[data-theme="light"] .theme-control::before { content: "🐾"; color: #946018; font-size: 13px; }

/* Replace the login screen's celestial motion with a quiet dog illustration. */
html[data-theme="light"] body.studyguide-portal .auth-screen {
  background: radial-gradient(ellipse at 12% 14%, #f0dfbc 0, transparent 38%), radial-gradient(ellipse at 88% 82%, #ead9b8 0, transparent 36%), #f8f1e2 !important;
  color: #3a2b1d !important;
}
html[data-theme="light"] body.studyguide-portal .auth-screen::before,
html[data-theme="light"] body.studyguide-portal .auth-screen::after {
  border: 0 !important;
  box-shadow: none !important;
  background: radial-gradient(closest-side, rgba(199,150,68,.12), transparent) !important;
  filter: blur(18px) !important;
}
html[data-theme="light"] body.studyguide-portal .auth-celestial {
  opacity: .2;
  background-image: url("dog-golden-retriever.png"), url("dog-samoyed-ink.png");
  background-repeat: no-repeat, no-repeat;
  background-position: left clamp(14px, 4vw, 76px) bottom -5vh, right clamp(0px, 3vw, 54px) bottom -10vh;
  background-size: clamp(250px, 27vw, 420px) auto, clamp(340px, 37vw, 570px) auto;
}
html[data-theme="light"] body.studyguide-portal :is(.auth-planet, .auth-moon, .nebula-planet-art, .auth-comet, .auth-comet-canvas) { display: none !important; }
html[data-theme="light"] body.studyguide-portal .auth-intro h1 { color: #49351f !important; }
html[data-theme="light"] body.studyguide-portal .auth-spark {
  border-color: #dcc695 !important;
  border-left-color: #a26e24 !important;
  background: linear-gradient(110deg, #f1e3c5, #f4ead7) !important;
}
html[data-theme="light"] body.studyguide-portal .auth-spark p { color: #66543d !important; }
html[data-theme="light"] body.studyguide-portal .auth-points span { border-color: #d8c8a8; background: #f2e7d0; color: #65533d; }
html[data-theme="light"] body.studyguide-portal .auth-card {
  border-color: #d4c093 !important;
  background: linear-gradient(145deg, rgba(247,239,222,.98), rgba(239,225,197,.98)) !important;
  box-shadow: 0 24px 70px rgba(87,61,27,.16) !important;
  backdrop-filter: blur(14px);
}
html[data-theme="light"] body.studyguide-portal :is(.auth-field label, .auth-local-note, .auth-local-note b, .auth-show-password) { color: #59462e !important; }
html[data-theme="light"] body.studyguide-portal .auth-local-note { border-top-color: #d9c9a9 !important; }
html[data-theme="light"] body.studyguide-portal .auth-password-row .auth-show-password { border-color: #d3c29d !important; background: #eee2c8 !important; }
html[data-theme="light"] body.studyguide-portal .auth-submit {
  border-color: #8b5b20 !important;
  background: linear-gradient(100deg, #b47a25, #99602b 58%, #79523a) !important;
  color: #fffaf0 !important;
  box-shadow: 0 10px 24px rgba(131,86,30,.2) !important;
}
html[data-theme="light"] body.studyguide-portal .auth-message { color: #8b3540 !important; }
html[data-theme="light"] body.studyguide-portal .user-menu-toggle { border-color: #d0bc91; background: #f0e4ca; color: #45341f; }
html[data-theme="light"] body.studyguide-portal .user-avatar { background: linear-gradient(135deg, #c28a35, #98632a); }
html[data-theme="light"] body.studyguide-portal .auth-modal { background: rgba(67,48,25,.34); }
html[data-theme="light"] body.studyguide-portal .auth-dialog { border-color: #d5c39a; background: #f5ecd8; color: #3a2b1d; box-shadow: 0 24px 70px rgba(74,52,26,.2); }
html[data-theme="light"] body.studyguide-portal .auth-dialog-actions button { border-color: #d4c39e; background: #eee2c8; color: #59462e; }
html[data-theme="light"] body.studyguide-portal .auth-dialog-actions .auth-submit { color: #fffaf0; }
html[data-theme="light"] body.studyguide-portal .account-row { border-color: #d8c8a8; background: #f0e5ce; }
html[data-theme="light"] body.studyguide-portal .account-row button { border-color: #c88d61; background: #f3e2d1; color: #78492d; }
html[data-theme="light"] body.studyguide-portal .course-progress,
html[data-theme="light"] body.studyguide-portal .material-progress {
  border-color: #d7c69f;
  background: rgba(239,226,199,.8);
  box-shadow: 0 9px 24px rgba(86,60,25,.06);
}
html[data-theme="light"] body.studyguide-portal .course-progress-label { color: #59462e; }
html[data-theme="light"] body.studyguide-portal .course-progress-track { background: #d7c8a8; }
html[data-theme="light"] body.studyguide-portal .course-progress-track>span { background: linear-gradient(90deg,#bc8128,#9d6530); }
html[data-theme="light"] body.studyguide-portal .course-progress-row[data-progress-row="exam"] .course-progress-track>span { background: linear-gradient(90deg,#cc9650,#b76b50); }
html[data-theme="light"] body.studyguide-portal .material-progress button { border-color: #cfbc91; background: #f5ead2; color: #59462e; }
html[data-theme="light"] body.studyguide-portal .material-progress button[aria-pressed="true"] { border-color: #a7792d; background: #e7d3a8; color: #513b1d; }
html[data-theme="light"] body.studyguide-portal .progress-storage-note { border-color: #d5bd88; background: #f1e4c7; color: #59462e; box-shadow: 0 12px 30px rgba(74,52,26,.15); }
html[data-theme="light"] body.studyguide-portal .welcome-splash {
  background: radial-gradient(ellipse at center, #f8efd9, #f2e3c5 72%) !important;
  color: #3a2b1d !important;
  overflow: hidden;
}
html[data-theme="light"] body.studyguide-portal .welcome-splash::after {
  content: "";
  position: absolute;
  right: max(2vw, env(safe-area-inset-right));
  bottom: -20vh;
  width: min(44vw, 620px);
  height: 94vh;
  opacity: .13;
  background: url("dog-samoyed-ink.png") center bottom / contain no-repeat;
  pointer-events: none;
}
html[data-theme="light"] body.studyguide-portal .welcome-splash-inner {
  position: relative;
  z-index: 1;
}
html[data-theme="light"] body.studyguide-portal .welcome-splash-orb {
  width: clamp(190px, 24vw, 290px);
  height: clamp(270px, 43vh, 380px);
  border-radius: 0;
  background: url("dog-golden-retriever.png") center / contain no-repeat;
  box-shadow: none;
  animation: dog-greeting-float 1.4s ease-in-out infinite alternate;
}
html[data-theme="light"] body.studyguide-portal .welcome-splash p { color: #6f5c47 !important; }
@keyframes dog-greeting-float { 0%,100% { transform: translateY(0) } 50% { transform: translateY(-5px) } }
@media (max-width: 760px) {
  html[data-theme="light"] body.studyguide-portal .auth-celestial {
    opacity: .13;
    background-position: left -50px bottom -3vh, right -110px bottom -5vh;
    background-size: 230px auto, 290px auto;
  }
  html[data-theme="light"] body.studyguide-portal .auth-screen { padding-top: 96px; }
}
@media (min-width: 761px) and (max-width: 1100px) {
  html[data-theme="light"] body.studyguide-portal .auth-celestial {
    opacity: .15;
    background-position: left -20px bottom -4vh, right -42px bottom -7vh;
    background-size: 310px auto, 390px auto;
  }
}
@media (max-width: 480px) {
  html[data-theme="light"] body.studyguide-portal .welcome-splash::after { opacity: .08; width: 72vw; }
}

/* Economics and Programming course libraries. */
html[data-theme="light"] body.course-library-page {
  --bg: #f8f1e2;
  --panel: rgba(242,230,204,.8);
  --panel2: rgba(237,220,184,.95);
  --line: rgba(112,82,43,.21);
  --text: #3a2b1d;
  --muted: #6f5c47;
  --cyan: #946018;
  --purple: #875b37;
  --pink: #ad6650;
  background: radial-gradient(ellipse at 12% 2%, #f2dfb9 0, transparent 39%), radial-gradient(ellipse at 92% 78%, #e8d9bc 0, transparent 40%), #f8f1e2 !important;
  color: #3a2b1d;
}
html[data-theme="light"] body.course-library-page:before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: .4;
  background: url("dog-theme-paws.svg") repeat 0 0 / 205px 205px;
}
html[data-theme="light"] body.course-library-page .course-shell { position: relative; z-index: 1; }
html[data-theme="light"] body.course-library-page::after {
  content: "";
  position: fixed;
  z-index: 0;
  right: clamp(-40px, 1vw, 20px);
  bottom: -14vh;
  width: clamp(320px, 39vw, 610px);
  height: clamp(260px, 48vh, 500px);
  pointer-events: none;
  opacity: .105;
  background: url("dog-samoyed-ink.png") center bottom / contain no-repeat;
}
html[data-theme="light"] body.course-library-page .course-hero::after { display: none !important; }
@media (max-width: 650px) {
  html[data-theme="light"] body.course-library-page::after { opacity: .075; right: -90px; width: 360px; height: 310px; }
}
/* Hero and reading canvas should blend into the page, not form giant white slabs. */
html[data-theme="light"] body.course-library-page :is(.course-hero, .course-panel, .topic-detail) {
  border-color: transparent !important;
  background: transparent !important;
  color: #3a2b1d !important;
  box-shadow: none !important;
}
html[data-theme="light"] body.course-library-page :is(.progress-panel, .stat-panel, .auth-panel) {
  border-color: #d7c69f !important;
  background: rgba(241,230,206,.82) !important;
  color: #3a2b1d !important;
  box-shadow: 0 9px 24px rgba(86,60,25,.07) !important;
}
html[data-theme="light"] body.course-library-page .stat {
  border-color: #d9c9a8 !important;
  background: rgba(235,220,189,.76) !important;
}
html[data-theme="light"] body.course-library-page .progress-track { background: #d7c8a8 !important; }
html[data-theme="light"] body.course-library-page :is(.overview-card, .topic-card, .seminar-card, .practice-card, .material-card, .tool-card, .reference-card, .work-item, .term, .question-list details, .solution) {
  border-color: #d8c8a5 !important;
  background: linear-gradient(145deg, rgba(246,237,216,.98), rgba(239,224,192,.94)) !important;
  color: #3a2b1d !important;
  box-shadow: 0 8px 22px rgba(86,60,25,.065) !important;
}
html[data-theme="light"] body.course-library-page :is(.course-tabs, .topic-nav, .tool-result, .tool-chart, .table-scroll, .tool-field input, .tool-field select, .tool-input-group, .diagram-card) {
  border-color: #d8c8a5 !important;
  background: rgba(241,231,208,.96) !important;
  color: #59462e !important;
}
html[data-theme="light"] body.course-library-page :is(.course-hero p, .panel-heading p, .overview-card p, .topic-card p, .seminar-card p, .practice-card p, .material-card p, .tool-card-head p, .reference-card p, .topic-summary, .topic-section p, .topic-section li, .tool-result p, .tool-hint, .question-list p, .solution p, .work-item p, .auth-panel p, .coverage-note, .progress-caption) {
  color: #6b5945 !important;
}
html[data-theme="light"] body.course-library-page :is(.course-hero h1, .panel-heading h2, .tool-card h3, .reference-card h3, .topic-detail h3, .seminar-card h3, .practice-card h3, .material-card h3, .work-item h4) { color: #392a1d !important; }
html[data-theme="light"] body.course-library-page :is(.term b, .question-list summary, .solution summary) { color: #493821 !important; }
html[data-theme="light"] body.course-library-page .formula {
  border-color: #c6a66b !important;
  background: #efe2c5 !important;
  color: #543d20 !important;
}
html[data-theme="light"] body.course-library-page .worked-example {
  border-color: #d7c193 !important;
  background: #f1e5cd !important;
}
html[data-theme="light"] body.course-library-page .worked-example p { color: #5a4934 !important; }
html[data-theme="light"] body.course-library-page .empty-note {
  border-color: #d9c99e !important;
  background: #eee8d6 !important;
  color: #5d4d2b !important;
}
html[data-theme="light"] body.course-library-page .progress-control {
  border-color: #d8c8a5 !important;
  background: rgba(235,220,189,.76) !important;
}
html[data-theme="light"] body.course-library-page :is(.topic-nav button, .course-tab, .progress-control button, .source-links a, .material-actions a, .tool-action, .account-action, .back-link) {
  border-color: #d2bd91 !important;
  background: #eee1c5 !important;
  color: #59442a !important;
}
html[data-theme="light"] body.course-library-page :is(.topic-nav button.active, .course-tab.active, .progress-control button[aria-pressed="true"]) {
  border-color: #aa782b !important;
  background: #dfc891 !important;
  color: #4d3519 !important;
}
html[data-theme="light"] body.course-library-page :is(.tool-result .result-summary, .result-metrics b, .topic-section h4, .eyebrow, .course-kicker, .progress-control-label) { color: #8d5c18 !important; }
html[data-theme="light"] body.course-library-page .tool-error { color: #a5233d !important; }
html[data-theme="light"] body.course-library-page .tool-table th { color: #8d5c18 !important; }
html[data-theme="light"] body.course-library-page .tool-table th, html[data-theme="light"] body.course-library-page .tool-table td { border-color: #d8c8a5 !important; }
html[data-theme="light"] body.course-library-page :is(.account-badge, .back-link) { background: #eee1c5 !important; color: #3a2b1d !important; }
html[data-theme="light"] body.course-library-page .auth-message { color: #842a3b !important; background: #f1e2e7 !important; }
html[data-theme="light"] body.course-library-page .coverage-note { border-color: #d9c99e !important; background: #eee8d6 !important; color: #5d4d2b !important; }
html[data-theme="light"] body.course-library-page .diagram-card img { background: #eee7d8 !important; }
html[data-theme="light"] body.course-library-page .toast { border-color: #d9c99e; background: #eee8d6; color: #59472a; }
html[data-theme="light"] body.course-library-page .chart-gridline { stroke: #705a3a26 !important; }
html[data-theme="light"] body.course-library-page .chart-axis { stroke: #806a4b !important; }
html[data-theme="light"] body.course-library-page .chart-demand { stroke: #a46a24 !important; }
html[data-theme="light"] body.course-library-page .chart-supply { stroke: #b45b38 !important; }
html[data-theme="light"] body.course-library-page .chart-price { stroke: #79573d !important; }
html[data-theme="light"] body.course-library-page .chart-label { fill: #5f4c35 !important; }
html[data-theme="light"] body.course-library-page .chart-demand-label { fill: #8d5c18 !important; }
html[data-theme="light"] body.course-library-page .chart-supply-label { fill: #994c2e !important; }

/* Matching Economics and Programming navigation in the dog-themed palette. */
html[data-theme="light"] body.course-library-page .course-sidebar {
  border-color: #d8c8a5 !important;
  background: linear-gradient(155deg, rgba(246,237,216,.98), rgba(239,224,192,.96)) !important;
  box-shadow: 0 10px 28px rgba(86,60,25,.075) !important;
}
html[data-theme="light"] body.course-library-page .course-menu-toolbar {
  border-color: #d8c8a5 !important;
  background: rgba(243,232,210,.97) !important;
}
html[data-theme="light"] body.course-library-page .course-tabs {
  display: grid !important;
  gap: 10px !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
}
html[data-theme="light"] body.course-library-page .course-nav-group + .course-nav-group,
html[data-theme="light"] body.course-library-page .course-subnav,
html[data-theme="light"] body.course-library-page .course-menu-foot {
  border-color: #d8c8a5 !important;
}
html[data-theme="light"] body.course-library-page .course-nav-group > summary { color: #705b41 !important; }
html[data-theme="light"] body.course-library-page .course-nav-group > summary::after,
html[data-theme="light"] body.course-library-page .course-nav-group > summary small { color: #846d4d !important; }
html[data-theme="light"] body.course-library-page .course-nav-icon,
html[data-theme="light"] body.course-library-page .course-nav-index,
html[data-theme="light"] body.course-library-page .course-menu-home {
  border-color: #d2bd91 !important;
  background: #f1e5ca !important;
  color: #8d5c18 !important;
}
html[data-theme="light"] body.course-library-page .course-nav-links .course-tab {
  border-color: transparent !important;
  background: transparent !important;
  color: #6f5c47 !important;
}
html[data-theme="light"] body.course-library-page .course-nav-links .course-tab:hover,
html[data-theme="light"] body.course-library-page .course-nav-links .course-tab.active,
html[data-theme="light"] body.course-library-page .course-subnav-item:hover,
html[data-theme="light"] body.course-library-page .course-subnav-item.active {
  border-color: #d2bd91 !important;
  background: #eee1c5 !important;
  color: #493821 !important;
}
html[data-theme="light"] body.course-library-page .course-subnav-item small,
html[data-theme="light"] body.course-library-page .course-subnav-heading b { color: #8d5c18 !important; }
html[data-theme="light"] body.course-library-page .course-subnav-heading b small,
html[data-theme="light"] body.course-library-page .course-subnav-empty,
html[data-theme="light"] body.course-library-page .course-menu-foot { color: #806a4b !important; }
html[data-theme="light"] body.course-library-page .course-material-search input {
  border-color: #d2bd91 !important;
  background: #f6eedc !important;
  color: #493821 !important;
}
html[data-theme="light"] body.course-library-page .portal-wordmark { color: #392a1d !important; }
html[data-theme="light"] body.course-library-page .portal-wordmark-icon {
  border-color: #d2bd91 !important;
  background: linear-gradient(140deg,#e9d5ad,#f1e6d0) !important;
  color: #946018 !important;
}

/* Light theme tokens for the Uber case study, which has its own palette. */
html[data-theme="light"] body.uber-case {
  --bg: #f8f1e2;
  --bg2: #efe0c2;
  --panel: #f3e8d1;
  --panel2: #efe2c8;
  --text: #3a2b1d;
  --muted: #6f5c47;
  --muted2: #8b7354;
  --line: #d8c8a7;
  --line2: #c8b48a;
  --white: #3a2b1d;
  --coral: #a56528;
  --coral2: #bd8748;
  --blue: #92704a;
  --cyan: #a77932;
  --green: #737747;
  --amber: #c28a35;
  --violet: #8c6e54;
  --red: #9f4d3d;
  --shadow: 0 22px 70px rgba(86,60,25,.12);
  background: radial-gradient(1200px 600px at 15% -10%, rgba(194,133,48,.12), transparent 55%), radial-gradient(900px 500px at 90% 0%, rgba(162,103,47,.09), transparent 55%), url("dog-theme-paws.svg") repeat 0 0 / 205px 205px, var(--bg) !important;
}
html[data-theme="light"] body.uber-case .topbar { background: rgba(243,232,209,.92) !important; border-color: #d8c8a7 !important; }
html[data-theme="light"] body.uber-case .hero-grid { opacity: .025 !important; }
html[data-theme="light"] body.uber-case .hero:before {
  background: linear-gradient(180deg,rgba(248,241,226,.02),rgba(248,241,226,.9) 88%),
    radial-gradient(circle at 65% 40%,rgba(194,133,48,.13),transparent 22%),
    radial-gradient(circle at 30% 55%,rgba(162,103,47,.1),transparent 25%) !important;
}
html[data-theme="light"] body.uber-case :is(.hero-copy, .detail p, .comparison ul, .bar-label) { color: #6f5c47 !important; }
html[data-theme="light"] body.uber-case :is(.stat, .model-card, .comparison, .team-card) { background: #f1e5cd !important; }
html[data-theme="light"] body.uber-case :is(.evidence-row, .metric, .team-row, .competitor.active, .competitor:hover) { background: #ebddc0 !important; }
html[data-theme="light"] body.uber-case :is(.chip, .bar-value, .competitor .mini-stat) { color: #59462e !important; }
html[data-theme="light"] body.uber-case .callout { color: #854c2c !important; }
html[data-theme="light"] .theme-control { box-shadow: 0 4px 14px rgba(86,60,25,.1); }
html[data-theme="light"] body.uber-case .hero-actions .theme-control {
  position: fixed;
  z-index: 150;
  top: 12px;
  right: 18px;
  margin: 0;
  box-shadow: 0 6px 22px rgba(86,60,25,.16);
}

/* The standalone Week 4 case presentation follows the same selected theme. */
html[data-theme="dark"] body.starbucks-case {
  --cream: #14221b;
  --green: #43b78c;
  --deep: #e1f1e8;
  --ink: #e0ebe4;
  --muted: #a5b9ad;
  --sage: #21382e;
  --white: #17261f;
  --line: #3a584b;
  --shadow: 0 8px 26px rgba(0,0,0,.28);
}
html[data-theme="dark"] body.starbucks-case .app { background: #0e1712 !important; }
html[data-theme="dark"] body.starbucks-case .stage .slide { border-color: #344c40 !important; }
html[data-theme="dark"] body.starbucks-case .human-card { background: #254b3d !important; }
html[data-theme="light"] body.starbucks-case .theme-control { box-shadow: 0 4px 14px rgba(86,60,25,.1); }

/* CampusFix uses a compact, full-screen slide deck with its own color tokens. */
html[data-theme="light"] body.campusfix-deck {
  --color-bg: #f8f1e2;
  --color-bg-deep: #efdfbe;
  --color-surface: #f0e3c7;
  --color-text: #382919;
  --color-text-secondary: #70543a;
  --color-text-muted: #8b7354;
  --color-glass-bg: rgba(112,82,43,.08);
  --color-glass-border: rgba(112,82,43,.18);
  --color-vignette: rgba(248,241,226,.15);
  --glow-color-rgb: 148,96,24;
}
html[data-theme="light"] body.campusfix-deck .slide { color: #382919; }
html[data-theme="light"] body.campusfix-deck .slide .content :is(p,span,div,h1,h2,h3,li,strong) { color: #382919 !important; }
html[data-theme="light"] body.campusfix-deck .slide .content :is(.stage-chip, .seq-arrow, .click-hint) { color: #8d5c18 !important; }
html[data-theme="light"] body.campusfix-deck .slide .expandable { background: rgba(241,230,206,.82) !important; border-color: rgba(112,82,43,.2) !important; }
html[data-theme="light"] body.campusfix-deck .expand-card { background: linear-gradient(160deg,#f7efde,#efe1c5); color: #382919; }
html[data-theme="light"] body.campusfix-deck .expand-card :is(h2,p,span,div,strong) { color: #382919 !important; }
html[data-theme="light"] body.campusfix-deck .expand-close { color: #382919; background: rgba(112,82,43,.08); border-color: rgba(112,82,43,.2); }
html[data-theme="light"] body.campusfix-deck .expand-overlay { background: rgba(248,241,226,.84); }
html[data-theme="light"] body.campusfix-deck .nav-controls { box-shadow: 0 8px 28px rgba(86,60,25,.14); }
html[data-theme="dark"] .deck > .theme-control,
html[data-theme="light"] .deck > .theme-control {
  position: fixed;
  z-index: 200;
  top: 16px;
  right: 18px;
  box-shadow: 0 8px 28px rgba(0,0,0,.2);
}
html[data-theme="light"] .deck > .theme-control { box-shadow: 0 8px 28px rgba(86,60,25,.14); }

/* Shared focus and reduced-motion behavior. */
:where(.theme-control select, .back-main, .back-link, .portal-back, .db-back, .mini-home):focus-visible {
  outline: 3px solid var(--cyan, #7ce7ff);
  outline-offset: 3px;
}
@media (max-width: 650px) {
  .theme-control { padding: 4px 6px 4px 8px; font-size: 10px; }
  .theme-control select { max-width: 126px; }
  .hero-actions .theme-control { order: 20; }
  .topbar .theme-control { margin-left: 0; }
  .deck > .theme-control { top: 8px; right: 8px; }
  html[data-theme="light"] body.uber-case .hero-actions .theme-control { top: 8px; right: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  .theme-control *, :where(.back-main, .back-link, .portal-back, .db-back, .mini-home) { transition: none !important; }
}

/* Quiet release marker, shared by the portal and standalone course pages. */
.studyguide-version-counter {
  position: fixed;
  left: max(12px, env(safe-area-inset-left));
  bottom: max(10px, env(safe-area-inset-bottom));
  z-index: 80;
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border: 1px solid var(--line, rgba(150,160,190,.22));
  border-radius: 999px;
  background: rgba(12,16,34,.72);
  color: rgba(220,226,242,.7);
  font: 700 9px/1.2 Inter, ui-sans-serif, system-ui, sans-serif;
  letter-spacing: .07em;
  pointer-events: none;
  user-select: none;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
html[data-theme="light"] .studyguide-version-counter {
  border-color: rgba(126,91,45,.2);
  background: rgba(244,234,211,.82);
  color: #80613b;
}

/* A deeper, more dimensional nebula treatment for dark mode. */
html[data-theme="dark"] body.studyguide-portal .auth-screen {
  background:
    radial-gradient(ellipse at 18% 78%, rgba(50,28,132,.56), transparent 38%),
    radial-gradient(ellipse at 84% 18%, rgba(13,83,132,.26), transparent 39%),
    radial-gradient(ellipse at 53% 53%, rgba(27,19,72,.38), transparent 53%),
    #050714 !important;
}
html[data-theme="dark"] body.studyguide-portal .auth-celestial {
  background-image:
    radial-gradient(1.5px 1.5px at 12% 18%, rgba(240,238,255,.88) 98%, transparent),
    radial-gradient(1px 1px at 73% 12%, rgba(153,222,255,.76) 98%, transparent),
    radial-gradient(2px 2px at 89% 42%, rgba(255,255,255,.72) 98%, transparent),
    radial-gradient(1px 1px at 56% 83%, rgba(188,168,255,.68) 98%, transparent),
    radial-gradient(1px 1px at 31% 55%, rgba(255,255,255,.58) 98%, transparent);
  background-size: 307px 283px, 379px 331px, 457px 397px, 293px 347px, 421px 367px;
  opacity: .9;
}
html[data-theme="dark"] body.studyguide-portal .nebula-planet-art {
  position: absolute;
  z-index: 1;
  left: clamp(-145px, calc(50vw - 1040px), -40px);
  bottom: clamp(-145px, -12vh, -70px);
  width: min(69vw, 850px);
  height: auto;
  opacity: .88;
  filter: saturate(1.08) drop-shadow(0 0 38px rgba(115,81,255,.2));
  transform-origin: 50% 52%;
  animation: nebula-planet-drift 28s ease-in-out infinite alternate;
}
html[data-theme="dark"] body.studyguide-portal .auth-moon {
  position: absolute;
  z-index: 1;
  top: clamp(34px, 8vh, 84px);
  right: clamp(40px, 8vw, 132px);
  width: clamp(42px, 5vw, 70px);
  aspect-ratio: 1;
  border-radius: 50%;
  background:
    radial-gradient(circle at 67% 62%, transparent 0 7%, rgba(12,12,38,.42) 7.5% 9%, transparent 10%),
    radial-gradient(circle at 34% 37%, #d8d1ff 0 4%, transparent 5%),
    radial-gradient(circle at 30% 27%, #e9e3ff, #9c8ee5 42%, #38336f 77%, #11142f 100%);
  box-shadow: inset -10px -7px 20px rgba(3,5,20,.55), 0 0 32px rgba(147,130,255,.27);
  opacity: .76;
  animation: auth-planet-float 9s ease-in-out infinite;
}
html[data-theme="dark"] body.studyguide-portal .orb,
html[data-theme="dark"] body.studyguide-portal .welcome-splash-orb {
  border-radius: 0;
  background: url("nebula-planet.svg") center / contain no-repeat;
  box-shadow: none;
  filter: drop-shadow(0 0 28px rgba(129,92,255,.36));
}
html[data-theme="dark"] body.studyguide-portal .orb {
  width: 164px;
  height: 138px;
  animation: nebula-planet-drift 10s ease-in-out infinite alternate;
}
html[data-theme="dark"] body.studyguide-portal .orb::after { display: none; }
html[data-theme="dark"] body.studyguide-portal .welcome-splash-orb {
  width: clamp(150px, 21vw, 230px);
  height: clamp(130px, 19vw, 200px);
}
@keyframes nebula-planet-drift {
  from { transform: translate3d(0,0,0) rotate(-1deg); }
  to { transform: translate3d(0,-12px,0) rotate(1.2deg); }
}
@media (max-width: 760px) {
  html[data-theme="dark"] body.studyguide-portal .nebula-planet-art {
    left: -145px;
    bottom: -78px;
    width: min(104vw, 570px);
    opacity: .48;
  }
  html[data-theme="dark"] body.studyguide-portal .auth-moon { top: 18px; right: 20px; width: 42px; }
}
@media (prefers-reduced-motion: reduce) {
  html[data-theme="dark"] body.studyguide-portal :is(.nebula-planet-art, .auth-moon, .orb) { animation: none !important; }
}

/* Clear any leftover nebula surfaces inside the study portal in light mode. */
html[data-theme="light"] body.studyguide-portal :is(.section-intro, .tools-hero, .source-pdf-section, .db-nav-group, .db-overview-topic, .be-week-subnav, .be-guide-check) {
  border-color: #d8c8a5 !important;
  background: linear-gradient(135deg, #f5ecd9, #eee0c2) !important;
  color: #59462e !important;
  box-shadow: 0 8px 20px rgba(86,60,25,.055) !important;
}
html[data-theme="light"] body.studyguide-portal :is(.tool-card, .db-learning-card, .be-guide-card, .unit-value, .formula-row, .be-guide-chain span) {
  border-color: #d8c8a5 !important;
  background: linear-gradient(145deg, #f7efdf, #efe2c8) !important;
  color: #59462e !important;
  box-shadow: 0 7px 18px rgba(86,60,25,.05) !important;
}
html[data-theme="light"] body.studyguide-portal .unit-svg-wrap {
  border-color: #d8c8a5 !important;
  background: radial-gradient(circle at 50% 40%, #f8efd9, #eee1c6 72%) !important;
}
html[data-theme="light"] body.studyguide-portal :is(.source-pdf-link, .crosslink) {
  border-color: #d2bd91 !important;
  background: linear-gradient(120deg, #f5ecd8, #eee0c2) !important;
  color: #59442a !important;
}
html[data-theme="light"] body.studyguide-portal :is(.source-pdf-link:hover, .crosslink:hover) {
  border-color: #ad823d !important;
  background: linear-gradient(120deg, #f2e3c4, #ead6aa) !important;
  color: #49351f !important;
}
html[data-theme="light"] body.studyguide-portal :is(.db-doc-actions a, .db-tool-tab, .db-copy-btn, .db-lesson-links button, .db-inline-link, .db-reveal-btn, .unit-angle-chip, .be-download-link) {
  border-color: #d2bd91 !important;
  background: #f1e5cd !important;
  color: #59442a !important;
}
html[data-theme="light"] body.studyguide-portal :is(.db-tool-tab:hover, .db-tool-tab.active, .db-doc-actions a:hover, .db-reveal-btn:hover, .unit-angle-chip:hover, .unit-angle-chip.active, .be-download-link:hover) {
  border-color: #aa782b !important;
  background: #e9d6ad !important;
  color: #49351f !important;
}
html[data-theme="light"] body.studyguide-portal :is(.pill, .section-chip, .option-icon, .sheet-icon, .course-icon) {
  border-color: #d8c8a5 !important;
  background: linear-gradient(135deg, #f1e3c5, #ead8b2) !important;
  color: #80591e !important;
}
html[data-theme="light"] body.studyguide-portal .option-card::before {
  background: radial-gradient(circle, rgba(195,143,55,.18), transparent 70%) !important;
}
html[data-theme="light"] body.studyguide-portal :is(.sheet-head:hover, .ex-btn:hover, .ex-btn.active, .db-doc-btn:hover, .db-doc-btn.active) {
  background: #ead9b8 !important;
  color: #49351f !important;
}
html[data-theme="light"] body.studyguide-portal :is(.steps li, .unit-controls input[type="number"], .uploaded-diagram img) {
  border-color: #d7c69e !important;
  background: #f4ead4 !important;
  color: #59462e !important;
}
html[data-theme="light"] body.studyguide-portal :is(.unit-value b, .formula-row code, .db-schema-keys span, .be-guide-check summary, .be-guide-chain span) { color: #59462e !important; }
html[data-theme="light"] body.studyguide-portal :is(.formula-row b, .formula-row p, .unit-exact, .uploaded-diagram summary, .be-guide-check details p) { color: #80591e !important; }
html[data-theme="light"] body.studyguide-portal :is(.db-warning, .db-hint, .tools-note) {
  border-color: #dec8a0 !important;
  background: #f1e5cd !important;
  color: #654d32 !important;
}
html[data-theme="light"] body.studyguide-portal .db-warning { border-left-color: #b66848 !important; }
html[data-theme="light"] body.studyguide-portal .db-hint { color: #59462e !important; }
html[data-theme="light"] body.studyguide-portal .answer {
  border-color: #d5bd88 !important;
  background: linear-gradient(120deg, #f2e5c9, #ead8b3) !important;
  color: #493a29 !important;
}
html[data-theme="light"] body.studyguide-portal .answer div { color: #493a29 !important; }
html[data-theme="light"] body.studyguide-portal :is(.db-chip, .db-schema-keys span) {
  border-color: #d8c8a5 !important;
  background: #eee2c8 !important;
  color: #59462e !important;
}
html[data-theme="light"] body.studyguide-portal .semester-card.current::after { background: rgba(180,126,39,.12) !important; }
