/*
 * Light/dark appearance layer.
 *
 * This intentionally sits on top of the legacy AcademicPages/Minimal Mistakes
 * theme rather than changing its Sass variables. That keeps the existing
 * responsive/navigation behavior intact.
 */

:root {
  --theme-bg: #f7f9fc;
  --theme-surface: #ffffff;
  --theme-surface-2: #f8fafc;
  --theme-surface-3: #eef5ff;
  --theme-text: #111827;
  --theme-text-soft: #334155;
  --theme-muted: #64748b;
  --theme-line: #dde5ef;
  --theme-link: #2563eb;
  --theme-link-hover: #174ea6;
  --theme-shadow: rgba(15, 23, 42, 0.08);
}

html[data-theme="light"] {
  color-scheme: light;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --theme-bg: #0b1120;
  --theme-surface: #111827;
  --theme-surface-2: #172033;
  --theme-surface-3: #182641;
  --theme-text: #e7edf6;
  --theme-text-soft: #c8d2e1;
  --theme-muted: #9aa8ba;
  --theme-line: #2b3a50;
  --theme-link: #8ac2ff;
  --theme-link-hover: #bddcff;
  --theme-shadow: rgba(0, 0, 0, 0.32);
}

/* Header control: separate from greedy-nav so its width math stays untouched. */
.masthead__menu--with-theme {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.masthead__menu--with-theme .greedy-nav {
  flex: 1 1 auto;
}

.theme-toggle {
  display: none;
  flex: 0 0 auto;
  width: 2.35rem;
  height: 2.35rem;
  padding: 0;
  align-items: center;
  justify-content: center;
  border: 1px solid #d4dce7;
  border-radius: 999px;
  background: #ffffff;
  color: #34445d;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(15, 23, 42, 0.04);
  transition: border-color .16s ease, background-color .16s ease, color .16s ease, transform .16s ease;
}

.js .theme-toggle {
  display: inline-flex;
}

.theme-toggle:hover {
  border-color: #9ab8df;
  color: #174ea6;
  transform: translateY(-1px);
}

.theme-toggle:focus-visible {
  outline: 3px solid rgba(59, 130, 246, .28);
  outline-offset: 2px;
}

.theme-toggle svg {
  width: 1.05rem;
  height: 1.05rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-toggle__moon {
  display: none;
}

html[data-theme="dark"] .theme-toggle__sun {
  display: none;
}

html[data-theme="dark"] .theme-toggle__moon {
  display: block;
}

/* Global dark appearance. */
html[data-theme="dark"] body,
html[data-theme="dark"] .masthead {
  background: var(--theme-bg) !important;
  color: var(--theme-text);
}

html[data-theme="dark"] body {
  scrollbar-color: #40506a var(--theme-bg);
}

html[data-theme="dark"] ::selection {
  background: #315b96;
  color: #ffffff;
}

html[data-theme="dark"] h1,
html[data-theme="dark"] h2,
html[data-theme="dark"] h3,
html[data-theme="dark"] h4,
html[data-theme="dark"] h5,
html[data-theme="dark"] h6,
html[data-theme="dark"] .page__title {
  color: var(--theme-text);
}

html[data-theme="dark"] .page__content,
html[data-theme="dark"] .page__content p,
html[data-theme="dark"] .page__content li,
html[data-theme="dark"] .page__content dl {
  color: var(--theme-text-soft);
}

html[data-theme="dark"] .page__content a,
html[data-theme="dark"] .archive a {
  color: var(--theme-link);
}

html[data-theme="dark"] .page__content a:hover,
html[data-theme="dark"] .archive a:hover {
  color: var(--theme-link-hover);
}

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

html[data-theme="dark"] code,
html[data-theme="dark"] pre,
html[data-theme="dark"] p > code,
html[data-theme="dark"] a > code,
html[data-theme="dark"] li > code,
html[data-theme="dark"] td > code {
  background: #172033;
  color: #d9e5f5;
  border-color: var(--theme-line);
}

html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea,
html[data-theme="dark"] button {
  color-scheme: dark;
}

/* Masthead / responsive navigation. */
html[data-theme="dark"] .masthead {
  border-color: var(--theme-line);
}

html[data-theme="dark"] .masthead .greedy-nav,
html[data-theme="dark"] .masthead .greedy-nav .visible-links,
html[data-theme="dark"] .masthead .greedy-nav .visible-links a {
  background: transparent !important;
}

html[data-theme="dark"] .masthead .greedy-nav a {
  color: #aebbd0;
}

html[data-theme="dark"] .masthead .greedy-nav a:hover {
  color: #ffffff;
}

html[data-theme="dark"] .greedy-nav .hidden-links {
  background: var(--theme-surface);
  border-color: var(--theme-line);
  box-shadow: 0 10px 24px rgba(0,0,0,.35);
}

html[data-theme="dark"] .greedy-nav .hidden-links li {
  border-color: var(--theme-line);
}

html[data-theme="dark"] .greedy-nav .hidden-links a:hover {
  background: #1b2a40;
  color: #ffffff;
}

html[data-theme="dark"] .greedy-nav .hidden-links::before {
  border-color: var(--theme-line) transparent;
}

html[data-theme="dark"] .greedy-nav .hidden-links::after {
  border-color: var(--theme-surface) transparent;
}

html[data-theme="dark"] .theme-toggle {
  background: #121c2d;
  border-color: #33445c;
  color: #c7d5e8;
  box-shadow: 0 3px 12px rgba(0,0,0,.25);
}

html[data-theme="dark"] .theme-toggle:hover {
  background: #18263a;
  border-color: #5c7699;
  color: #ffffff;
}

/* Footer. */
html[data-theme="dark"] .page__footer {
  background: #0f1828;
  color: #9eacbf;
  border-color: var(--theme-line);
}

html[data-theme="dark"] .page__footer a,
html[data-theme="dark"] .page__footer .fas,
html[data-theme="dark"] .page__footer .fab,
html[data-theme="dark"] .page__footer .far {
  color: #aebdd1;
}

/* Sheet-backed cards (Projects, Students, Teaching, Software). */
html[data-theme="dark"] .sheet-state {
  color: var(--theme-muted);
}

html[data-theme="dark"] .sheet-card {
  background: var(--theme-surface);
  border-color: var(--theme-line);
  box-shadow: 0 8px 22px rgba(0,0,0,.18);
}

html[data-theme="dark"] .sheet-card h3,
html[data-theme="dark"] .sheet-card p,
html[data-theme="dark"] .sheet-kv dt,
html[data-theme="dark"] .sheet-kv dd {
  color: var(--theme-text-soft);
}

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

html[data-theme="dark"] .sheet-chip {
  background: #172236;
  border-color: #34445c;
  color: #bdc9da;
}

html[data-theme="dark"] .sheet-section > h2 {
  color: #d6e0ee;
  border-left-color: #5d7494;
}

html[data-theme="dark"] .sheet-links a {
  border-color: #3a4b64;
  background: #141f31;
  color: #9fcaff;
}

/* Publications page. */
html[data-theme="dark"] .pub-toolbar {
  background: linear-gradient(180deg, #111827 0%, #121c2c 100%);
  border-color: var(--theme-line);
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
}

html[data-theme="dark"] .pub-search > i,
html[data-theme="dark"] .pub-filter > span,
html[data-theme="dark"] .pub-count,
html[data-theme="dark"] .pubs-state {
  color: var(--theme-muted);
}

html[data-theme="dark"] .pub-search input,
html[data-theme="dark"] .pub-filter select,
html[data-theme="dark"] .pub-clear {
  background: #0f1929;
  border-color: #35465e;
  color: #dbe5f2;
}

html[data-theme="dark"] .pub-search input::placeholder {
  color: #7f8da0;
}

html[data-theme="dark"] .pub-clear:hover {
  background: #17263b;
  border-color: #5f80a9;
  color: #b9d9ff;
}

html[data-theme="dark"] .pub-year-heading {
  color: #d3deec;
  border-left-color: #657c9b;
}

html[data-theme="dark"] .pubs-card {
  background: var(--theme-surface);
  border-top-color: var(--theme-line);
  border-right-color: var(--theme-line);
  border-bottom-color: var(--theme-line);
  box-shadow: 0 7px 22px rgba(0,0,0,.18);
}

html[data-theme="dark"] .pubs-card:hover {
  box-shadow: 0 12px 30px rgba(0,0,0,.26);
}

html[data-theme="dark"] .pub-title {
  color: #e5edf7;
}

html[data-theme="dark"] .pub-authors {
  color: #a8b5c8;
}

html[data-theme="dark"] .pub-chip {
  background: #182337;
  border-color: #3a4b63;
  color: #c6d2e1;
}

html[data-theme="dark"] .pub-chip--conference { background:#132a48; border-color:#365f8d; color:#8fc5ff; }
html[data-theme="dark"] .pub-chip--journal { background:#123126; border-color:#2d6a51; color:#8ee1b6; }
html[data-theme="dark"] .pub-chip--workshop { background:#352711; border-color:#7d5b24; color:#f3c96a; }
html[data-theme="dark"] .pub-chip--preprint { background:#291d43; border-color:#5f478b; color:#c4a7ff; }
html[data-theme="dark"] .pub-chip--technical-report { background:#3a1930; border-color:#824169; color:#f1a5d0; }

html[data-theme="dark"] .pub-resource,
html[data-theme="dark"] .pub-link-badge {
  background: #151f31;
  border-color: #3b4a60;
  color: #b7c5d8;
}

html[data-theme="dark"] .pub-resource--venue { background:#142942; border-color:#31577e; color:#94c5fa; }
html[data-theme="dark"] .pub-resource--pdf { background:#351b20; border-color:#70404a; color:#ffadb7; }
html[data-theme="dark"] .pub-resource--code { background:#251d3c; border-color:#57477b; color:#c7afff; }
html[data-theme="dark"] .pub-resource--dataset { background:#173126; border-color:#35654f; color:#91dcb2; }
html[data-theme="dark"] .pub-resource--slides { background:#12303c; border-color:#2e6275; color:#91d8ee; }
html[data-theme="dark"] .pub-resource--poster { background:#342a13; border-color:#74612d; color:#efd276; }
html[data-theme="dark"] .pub-resource--video { background:#351b28; border-color:#754054; color:#ffadc4; }
html[data-theme="dark"] .pub-resource--bibtex { background:#192436; border-color:#40516a; color:#b7c7dc; }
html[data-theme="dark"] .pub-link-badge--award { background:#332711; border-color:#7b6025; color:#f5d36f; }

/* Homepage refresh. */
html[data-theme="dark"] .profile-hero {
  background:
    radial-gradient(circle at 88% 18%, rgba(58,116,190,.16), transparent 29%),
    linear-gradient(135deg, #111827 0%, #111a2a 58%, #14223a 100%);
  border-color: var(--theme-line);
  box-shadow: 0 16px 38px rgba(0,0,0,.25);
}

html[data-theme="dark"] .profile-hero::after {
  background: rgba(73,124,194,.08);
}

html[data-theme="dark"] .profile-hero__eyebrow {
  color: #84b8ff;
}

html[data-theme="dark"] .profile-hero__title {
  color: #f3f7fc;
}

html[data-theme="dark"] .profile-hero__summary {
  color: #aebbd0;
}

html[data-theme="dark"] .profile-hero__keywords span {
  background: #162843;
  border-color: #36577e;
  color: #9dcaff;
}

html[data-theme="dark"] .profile-hero__links a {
  background: #121d2f;
  border-color: #34465f;
  color: #d4deeb;
}

html[data-theme="dark"] .profile-hero__links a:hover {
  background: #18273c;
  border-color: #6181aa;
}

html[data-theme="dark"] .profile-hero__portrait-frame {
  background: #111827;
  border-color: #33445b;
  box-shadow: 0 18px 38px rgba(0,0,0,.38);
}

html[data-theme="dark"] .profile-hero__location {
  background: #111b2b;
  border-color: #364a66;
  color: #9fcaff;
  box-shadow: 0 5px 16px rgba(0,0,0,.28);
}

html[data-theme="dark"] .home-panel,
html[data-theme="dark"] .home-contact-card {
  background: var(--theme-surface);
  border-color: var(--theme-line);
  box-shadow: 0 8px 24px rgba(0,0,0,.16);
}

html[data-theme="dark"] .home-panel__header,
html[data-theme="dark"] .home-background,
html[data-theme="dark"] .home-contact-card__header,
html[data-theme="dark"] .news-item,
html[data-theme="dark"] .news-more {
  border-color: #26354a;
}

html[data-theme="dark"] .home-panel__header h2,
html[data-theme="dark"] .home-contact-card h2,
html[data-theme="dark"] .home-section-heading h2 {
  color: #e4ecf7;
}

html[data-theme="dark"] .home-panel > p,
html[data-theme="dark"] .home-background p,
html[data-theme="dark"] .home-contact-card > p {
  color: #aeb9c9;
}

html[data-theme="dark"] .home-panel__intro {
  color: #9eabbd !important;
}

html[data-theme="dark"] .home-panel a,
html[data-theme="dark"] .home-background a,
html[data-theme="dark"] .home-contact-card__details a,
html[data-theme="dark"] .home-panel__more {
  color: #8bc1ff !important;
}

html[data-theme="dark"] .home-background__label,
html[data-theme="dark"] .home-contact-card__details dt,
html[data-theme="dark"] .news-date,
html[data-theme="dark"] .news-more summary span,
html[data-theme="dark"] .home-updated {
  color: #8f9caf;
}

html[data-theme="dark"] .home-contact-card__details dd,
html[data-theme="dark"] .research-focus-item strong,
html[data-theme="dark"] .news-content {
  color: #c8d3e2;
}

html[data-theme="dark"] .research-focus-item span:not(.research-focus-item__icon) {
  color: #97a5b8;
}

html[data-theme="dark"] .focus-blue,
html[data-theme="dark"] .home-panel__icon--blue,
html[data-theme="dark"] .home-section-heading__icon,
html[data-theme="dark"] .home-contact-card__icon {
  background: #142b4d;
  color: #82b9ff;
}

html[data-theme="dark"] .focus-cyan {
  background: #12313c;
  color: #79d2e8;
}

html[data-theme="dark"] .focus-amber {
  background: #372b13;
  color: #ebca6c;
}

html[data-theme="dark"] .focus-green,
html[data-theme="dark"] .home-panel__icon--green {
  background: #143126;
  color: #7dd8aa;
}

html[data-theme="dark"] .home-panel__icon--violet {
  background: #291e42;
  color: #c1a4ff;
}

html[data-theme="dark"] .news-more summary {
  color: #8bc1ff;
}

html[data-theme="dark"] .news-more summary::after {
  background: #141f31;
  border-color: #3a4d68;
  color: #9bc8ff;
}

html[data-theme="dark"] .featured-publications {
  background: linear-gradient(180deg, #111b2d 0%, #14233b 100%);
  border-color: #2c405c;
}

html[data-theme="dark"] .home-section-heading > a {
  background: #121e31;
  border-color: #496b96;
  color: #99c8ff;
}

html[data-theme="dark"] .featured-pub-card {
  background: #111827;
  border-color: #2e3e54;
  box-shadow: 0 7px 20px rgba(0,0,0,.18);
}

html[data-theme="dark"] .featured-pub-badge {
  background: #251f45;
  color: #c4b2ff;
}

html[data-theme="dark"] .featured-pub-card h3,
html[data-theme="dark"] .featured-pub-card h3 a {
  color: #e4ecf6;
}

html[data-theme="dark"] .featured-pub-authors {
  color: #9eabbc;
}

html[data-theme="dark"] .featured-pub-links a {
  background: #151f31;
  border-color: #3b4c64;
  color: #afc9ea;
}

/* Legacy author/sidebar, forms, and tables. */
html[data-theme="dark"] .sidebar,
html[data-theme="dark"] .author__content,
html[data-theme="dark"] .author__name,
html[data-theme="dark"] .author__bio,
html[data-theme="dark"] .author__urls {
  color: var(--theme-text-soft);
}

html[data-theme="dark"] .author__avatar img {
  border-color: var(--theme-line);
}

html[data-theme="dark"] .author__urls {
  background: var(--theme-surface);
  border-color: var(--theme-line);
  box-shadow: 0 10px 24px rgba(0,0,0,.32);
}

html[data-theme="dark"] .author__urls::before {
  border-color: var(--theme-line) transparent;
}

html[data-theme="dark"] .author__urls::after {
  border-color: var(--theme-surface) transparent;
}

html[data-theme="dark"] .author__urls a {
  color: #b9c7d9;
}

html[data-theme="dark"] label,
html[data-theme="dark"] legend {
  color: var(--theme-text-soft);
}

html[data-theme="dark"] input,
html[data-theme="dark"] textarea,
html[data-theme="dark"] select {
  background-color: #101a2a;
  border-color: #35475f;
  color: #dce6f3;
  box-shadow: none;
}

html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder {
  color: #8290a3;
}

html[data-theme="dark"] thead {
  background: #182337;
  border-color: var(--theme-line);
}

html[data-theme="dark"] .archive__subtitle,
html[data-theme="dark"] .page__meta {
  color: var(--theme-muted);
  border-color: var(--theme-line);
}

/* Miscellaneous theme surfaces from the legacy template. */
html[data-theme="dark"] .notice,
html[data-theme="dark"] .archive__item,
html[data-theme="dark"] .toc,
html[data-theme="dark"] .page__comments-form,
html[data-theme="dark"] table,
html[data-theme="dark"] th,
html[data-theme="dark"] td {
  border-color: var(--theme-line);
}

html[data-theme="dark"] .toc,
html[data-theme="dark"] .page__comments-form {
  background: var(--theme-surface);
  color: var(--theme-text-soft);
}

html[data-theme="dark"] table,
html[data-theme="dark"] th,
html[data-theme="dark"] td {
  color: var(--theme-text-soft);
}

@media (max-width: 600px) {
  .masthead__menu--with-theme {
    gap: 0.35rem;
  }

  .theme-toggle {
    width: 2.2rem;
    height: 2.2rem;
  }
}

@media print {
  .theme-toggle {
    display: none !important;
  }
}
