/* Semantic theme tokens and the compact topbar control. */
:root {
  color-scheme: light;
  --surface: #fffdf8;
  --surface-alt: #ebe7df;
  --photo-surface: #ded8cb;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --paper: #151819;
  --ink: #eef0eb;
  --muted: #a5aaa6;
  --line: #3a3f40;
  --acid: #b8d63f;
  --coral: #ff8b73;
  --blue: #8aaaff;
  --surface: #1e2223;
  --surface-alt: #292e30;
  --photo-surface: #303638;
}

html,
body {
  background-color: var(--paper);
}

body {
  transition: background-color 0.5s ease, color 0.42s ease;
}

html[data-theme="dark"] ::selection {
  background: rgba(184, 214, 63, 0.3);
  color: var(--ink);
}

html[data-theme="dark"] .grain {
  opacity: 0.045;
  mix-blend-mode: screen;
}

html[data-theme="dark"] .pulse {
  background: #70d49a;
  box-shadow: 0 0 0 5px rgba(112, 212, 154, 0.18);
}

html[data-theme="dark"] .portrait-wrap,
html[data-theme="dark"] .about-image {
  background: var(--photo-surface);
  box-shadow: 10px 10px 0 rgba(0, 0, 0, 0.2);
}

html[data-theme="dark"] .portrait-wrap img,
html[data-theme="dark"] .about-image img {
  filter: grayscale(1) contrast(0.94) brightness(0.88);
  mix-blend-mode: screen;
  opacity: 0.72;
}

/* Keep the visual studies colorful, but tune their contrast for a dark canvas. */
html[data-theme="dark"] .blue-visual {
  background: #3d5f9f;
  color: #f3f6ff;
}

html[data-theme="dark"] .mint-visual {
  background: #347667;
  color: #edfff7;
}

html[data-theme="dark"] .lavender-visual {
  background: #5d5595;
  color: #f6f3ff;
}

html[data-theme="dark"] .red-visual {
  background: #a8433e;
  color: #fff0ed;
}

html[data-theme="dark"] .lesson-card {
  background: #283653;
  color: #e9efff;
  box-shadow: 11px 11px 0 rgba(5, 9, 20, 0.36);
}

html[data-theme="dark"] .route-map {
  color: #edfff7;
}

html[data-theme="dark"] .route-map span,
html[data-theme="dark"] .route-map b {
  border-color: rgba(237, 255, 247, 0.78);
}

html[data-theme="dark"] .terminal .green {
  color: #d4f5a9;
}

html[data-theme="dark"] dialog {
  box-shadow: 12px 12px 0 var(--acid);
}

html[data-theme="dark"] dialog::backdrop {
  background: rgba(3, 5, 6, 0.72);
}

html[data-theme="dark"] .ticker {
  color: var(--paper);
  border-color: var(--paper);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 15px;
}

.theme-toggle {
  appearance: none;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  position: relative;
  flex: 0 0 34px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease, transform 0.3s ease;
}

.theme-toggle:hover {
  background: var(--surface-alt);
  border-color: var(--line);
  color: var(--ink);
  transform: translateY(-1px);
}

.theme-toggle:active {
  transform: translateY(0) scale(0.94);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--coral);
  outline-offset: 3px;
}

.theme-icon {
  position: absolute;
  width: 17px;
  height: 17px;
  display: grid;
  place-items: center;
  transition: opacity 0.32s ease, transform 0.42s cubic-bezier(0.22, 1, 0.36, 1);
}

.theme-icon svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.6;
}

.theme-icon-sun {
  opacity: 1;
  transform: rotate(0) scale(1);
}

.theme-icon-moon {
  opacity: 0;
  transform: rotate(90deg) scale(0.55);
}

html[data-theme="dark"] .theme-icon-sun {
  opacity: 0;
  transform: rotate(-90deg) scale(0.55);
}

html[data-theme="dark"] .theme-icon-moon {
  opacity: 1;
  transform: rotate(0) scale(1);
}

html,
body,
.topbar,
.ticker,
.footer,
.hero-note,
.project-info,
.principle,
.about,
.closing,
.portrait-wrap,
.about-image,
dialog,
.chip {
  transition-property: background-color, color, border-color, box-shadow;
  transition-duration: 0.5s;
  transition-timing-function: ease;
}

/* Smoothly interpolate theme-dependent descendants when View Transitions are unavailable. */
body .eyebrow,
body .hero-lede,
body .hero-note,
body .hero-note p,
body .section-intro,
body .filter,
body .project-visual,
body .project-visual .visual-label,
body .project-visual .visual-caption,
body .project-visual .ticker-mini,
body .project-info,
body .project-info h3,
body .project-info p,
body .project-meta,
body .chip,
body .detail-button,
body .principle,
body .principle h3,
body .principle p,
body .about-copy,
body .about-copy h2,
body .about-copy > p,
body .text-link,
body .footer,
body .footer a {
  transition-property: background-color, color, border-color, box-shadow, fill, stroke;
  transition-duration: 0.5s;
  transition-timing-function: ease;
}

@supports (view-transition-name: root) {
  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation: none;
    mix-blend-mode: normal;
  }

  ::view-transition-old(root) {
    z-index: 1;
  }

  ::view-transition-new(root) {
    z-index: 999;
  }

}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
