:root {
  --site-dark-bg: #0b0f19;
  --site-dark-surface: #111827;
  --site-dark-surface-strong: #172033;
  --site-dark-line: rgba(148, 163, 184, 0.26);
  --site-dark-text: #f8fafc;
  --site-dark-muted: #a7b2c4;
  --site-light-bg: #f1f5f9;
  --site-light-surface: #ffffff;
  --site-light-surface-soft: #f8fafc;
  --site-light-line: rgba(71, 85, 105, 0.24);
  --site-light-text: #0f172a;
  --site-light-muted: #475569;
}

html[data-site-theme] body,
html[data-site-theme] header,
html[data-site-theme] footer,
html[data-site-theme] section,
html[data-site-theme] article,
html[data-site-theme] aside,
html[data-site-theme] div,
html[data-site-theme] button,
html[data-site-theme] input,
html[data-site-theme] select,
html[data-site-theme] textarea {
  transition-property: background-color, border-color, color, box-shadow;
  transition-duration: 260ms;
  transition-timing-function: ease;
}

.site-theme-toggle {
  position: relative;
  z-index: 1;
  min-width: 3.25rem;
  min-height: 2.75rem;
  border: 0;
  padding: 0.35rem;
  color: inherit;
  cursor: pointer;
  background: transparent;
}

.site-theme-toggle:focus-visible {
  outline: 2px solid var(--division-accent, var(--accent, #0d9488));
  outline-offset: 2px;
}

.site-theme-toggle__track {
  position: relative;
  display: grid;
  width: 3rem;
  height: 1.65rem;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  border: 1px solid currentColor;
  border-radius: 999px;
  opacity: 0.92;
}

.site-theme-toggle__thumb {
  position: absolute;
  left: 0.18rem;
  top: 0.17rem;
  width: 1.18rem;
  height: 1.18rem;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.26);
  transform: translateX(1.28rem);
  transition: transform 260ms ease, background-color 260ms ease;
}

html[data-site-theme="light"] .site-theme-toggle__thumb {
  transform: translateX(0);
}

.site-theme-toggle__sun,
.site-theme-toggle__moon {
  position: relative;
  z-index: 1;
  width: 0.8rem;
  height: 0.8rem;
  justify-self: center;
}

html[data-site-theme="dark"] .site-theme-toggle__moon,
html[data-site-theme="light"] .site-theme-toggle__sun {
  color: var(--site-dark-bg);
}

.site-theme-toggle--mobile {
  display: flex;
  width: 100%;
  min-height: 3.5rem;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border: 1px solid currentColor;
  padding: 0.7rem 1rem;
  text-align: left;
}

.site-theme-toggle--mobile .site-theme-toggle__copy {
  display: grid;
  gap: 0.18rem;
  font-size: 0.875rem;
  font-weight: 800;
}

.site-theme-toggle--mobile .site-theme-toggle__copy strong {
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.62rem;
  font-weight: 800;
  text-transform: uppercase;
}

@media (min-width: 1024px) {
  .site-theme-toggle--mobile { display: none; }
}

/* Homepage variables: the manual preference controls luminosity while hover controls division identity. */
html[data-site-theme="dark"] body {
  --page-bg: #0b0f19;
  --page-bg-soft: #111827;
  --text-main: #f8fafc;
  --text-muted: #a7b2c4;
  --surface: rgba(15, 23, 42, 0.82);
  --surface-strong: rgba(17, 24, 39, 0.97);
  --surface-soft: rgba(255, 255, 255, 0.055);
  --line: rgba(148, 163, 184, 0.25);
  --line-strong: rgba(203, 213, 225, 0.4);
  --accent: #cbd5e1;
  --accent-strong: #f8fafc;
  --grid-line: rgba(148, 163, 184, 0.12);
  --nav-bg: rgba(11, 15, 25, 0.86);
}

html[data-site-theme="dark"] body.mode-cad {
  --page-bg: #071412;
  --page-bg-soft: #0b201d;
  --surface: rgba(8, 32, 29, 0.82);
  --surface-strong: rgba(6, 28, 25, 0.97);
  --surface-soft: rgba(13, 148, 136, 0.11);
  --line: rgba(45, 212, 191, 0.27);
  --line-strong: rgba(45, 212, 191, 0.52);
  --accent: #14b8a6;
  --accent-strong: #2dd4bf;
  --grid-line: rgba(45, 212, 191, 0.15);
  --nav-bg: rgba(7, 20, 18, 0.88);
}

html[data-site-theme="dark"] body.mode-mechanical {
  --page-bg: #080d17;
  --page-bg-soft: #101827;
  --surface: rgba(12, 22, 39, 0.84);
  --surface-strong: rgba(10, 18, 32, 0.97);
  --surface-soft: rgba(37, 99, 235, 0.11);
  --line: rgba(59, 130, 246, 0.3);
  --line-strong: rgba(96, 165, 250, 0.56);
  --accent: #3b82f6;
  --accent-strong: #60a5fa;
  --grid-line: rgba(59, 130, 246, 0.16);
  --nav-bg: rgba(8, 13, 23, 0.88);
}

html[data-site-theme="dark"] body.mode-embedded {
  --page-bg: #06100c;
  --page-bg-soft: #0a1911;
  --surface: rgba(8, 29, 18, 0.84);
  --surface-strong: rgba(6, 23, 14, 0.97);
  --surface-soft: rgba(22, 163, 74, 0.11);
  --line: rgba(34, 197, 94, 0.29);
  --line-strong: rgba(74, 222, 128, 0.52);
  --accent: #22c55e;
  --accent-strong: #4ade80;
  --grid-line: rgba(34, 197, 94, 0.15);
  --nav-bg: rgba(6, 16, 12, 0.88);
}

html[data-site-theme="dark"] body.mode-ai {
  --page-bg: #120c05;
  --page-bg-soft: #1c1208;
  --surface: rgba(31, 20, 9, 0.84);
  --surface-strong: rgba(27, 17, 7, 0.97);
  --surface-soft: rgba(245, 158, 11, 0.11);
  --line: rgba(245, 158, 11, 0.3);
  --line-strong: rgba(245, 158, 11, 0.58);
  --accent: #d97706;
  --accent-strong: #f59e0b;
  --grid-line: rgba(245, 158, 11, 0.17);
  --nav-bg: rgba(18, 12, 5, 0.88);
}

html[data-site-theme="light"] body {
  --page-bg: #edf2f7;
  --page-bg-soft: #ffffff;
  --text-main: #0f172a;
  --text-muted: #475569;
  --surface: rgba(255, 255, 255, 0.86);
  --surface-strong: rgba(248, 250, 252, 0.98);
  --surface-soft: rgba(71, 85, 105, 0.07);
  --line: rgba(71, 85, 105, 0.24);
  --line-strong: rgba(71, 85, 105, 0.42);
  --accent: #334155;
  --accent-strong: #0f172a;
  --grid-line: rgba(71, 85, 105, 0.13);
  --nav-bg: rgba(248, 250, 252, 0.9);
}

html[data-site-theme="light"] body.mode-cad {
  --page-bg: #edf2f7;
  --page-bg-soft: #ffffff;
  --surface-soft: rgba(13, 148, 136, 0.09);
  --line: rgba(13, 148, 136, 0.28);
  --line-strong: rgba(13, 148, 136, 0.5);
  --accent: #0d9488;
  --accent-strong: #0f766e;
  --grid-line: rgba(13, 148, 136, 0.16);
}

html[data-site-theme="light"] body.mode-mechanical {
  --page-bg: #dfe8f2;
  --page-bg-soft: #f8fafc;
  --surface-soft: rgba(37, 99, 235, 0.09);
  --line: rgba(37, 99, 235, 0.26);
  --line-strong: rgba(37, 99, 235, 0.52);
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --grid-line: rgba(37, 99, 235, 0.14);
}

html[data-site-theme="light"] body.mode-embedded {
  --page-bg: #e4f3ea;
  --page-bg-soft: #fbfefc;
  --surface-soft: rgba(22, 163, 74, 0.09);
  --line: rgba(22, 163, 74, 0.26);
  --line-strong: rgba(22, 163, 74, 0.52);
  --accent: #16a34a;
  --accent-strong: #15803d;
  --grid-line: rgba(22, 163, 74, 0.14);
}

html[data-site-theme="light"] body.mode-ai {
  --page-bg: #f8f1e8;
  --page-bg-soft: #fffdf9;
  --surface-soft: rgba(217, 119, 6, 0.09);
  --line: rgba(217, 119, 6, 0.27);
  --line-strong: rgba(217, 119, 6, 0.52);
  --accent: #b45309;
  --accent-strong: #92400e;
  --grid-line: rgba(217, 119, 6, 0.15);
}

html[data-site-theme="dark"] .brand-logo-dark,
html[data-site-theme="light"] .brand-logo-light {
  display: block !important;
}

html[data-site-theme="dark"] .brand-logo-light,
html[data-site-theme="light"] .brand-logo-dark {
  display: none !important;
}

/* Shared light treatment for dark-first pages. */
html[data-site-theme="light"] body {
  background-color: var(--site-light-bg) !important;
  color: var(--site-light-text) !important;
}

html[data-site-theme="light"] header,
html[data-site-theme="light"] footer,
html[data-site-theme="light"] .bg-charcoal,
html[data-site-theme="light"] .bg-panel,
html[data-site-theme="light"] .bg-slate-950,
html[data-site-theme="light"] .bg-slate-900,
html[data-site-theme="light"] [class~="bg-charcoal/88"],
html[data-site-theme="light"] [class~="bg-charcoal/90"],
html[data-site-theme="light"] [class~="bg-slate-950/72"],
html[data-site-theme="light"] [class~="bg-slate-900/72"],
html[data-site-theme="light"] [class~="bg-slate-900/82"],
html[data-site-theme="light"] [class~="bg-slate-900/86"] {
  background-color: rgba(255, 255, 255, 0.94) !important;
  color: var(--site-light-text) !important;
}

html[data-site-theme="light"] .dark-grid {
  background-color: var(--site-light-bg) !important;
  background-image: linear-gradient(rgba(13, 148, 136, 0.1) 1px, transparent 1px), linear-gradient(90deg, rgba(13, 148, 136, 0.1) 1px, transparent 1px) !important;
}

html[data-site-theme="light"] .premium-hero.dark-grid::before {
  background: radial-gradient(circle at 16% 16%, rgba(13, 148, 136, 0.16), transparent 24rem), radial-gradient(circle at 84% 12%, rgba(217, 119, 6, 0.14), transparent 28rem), linear-gradient(135deg, rgba(255, 255, 255, 0.9), rgba(241, 245, 249, 0.72) 46%, rgba(255, 255, 255, 0.96)) !important;
}

html[data-site-theme="light"] .text-white,
html[data-site-theme="light"] .text-ink,
html[data-site-theme="light"] .text-slate-100,
html[data-site-theme="light"] .text-slate-200,
html[data-site-theme="light"] .text-slate-300 {
  color: var(--site-light-text) !important;
}

html[data-site-theme="light"] .text-slate-400,
html[data-site-theme="light"] .text-slate-500,
html[data-site-theme="light"] .text-slate-600 {
  color: var(--site-light-muted) !important;
}

html[data-site-theme="light"] .border-slate-700,
html[data-site-theme="light"] .border-slate-800,
html[data-site-theme="light"] .border-slate-900 {
  border-color: var(--site-light-line) !important;
}

html[data-site-theme="light"] [class~="bg-white/5"],
html[data-site-theme="light"] [class~="bg-white/10"],
html[data-site-theme="light"] [class~="bg-black/20"],
html[data-site-theme="light"] [class~="bg-black/30"] {
  background-color: rgba(15, 23, 42, 0.045) !important;
}

html[data-site-theme="light"] .bg-amber-600.text-white,
html[data-site-theme="light"] .bg-teal-600.text-white,
html[data-site-theme="light"] .bg-blue-600.text-white,
html[data-site-theme="light"] .bg-green-600.text-white,
html[data-site-theme="light"] .bg-aigold.text-white,
html[data-site-theme="light"] .bg-cadteal.text-white,
html[data-site-theme="light"] .bg-signalgreen.text-white,
html[data-site-theme="light"] .bg-mechblue.text-white {
  color: #ffffff !important;
}

/* Shared dark treatment for light-first pages. */
html[data-site-theme="dark"] body {
  background-color: var(--site-dark-bg) !important;
  color: var(--site-dark-text) !important;
}

html[data-site-theme="dark"] header,
html[data-site-theme="dark"] footer,
html[data-site-theme="dark"] .bg-white,
html[data-site-theme="dark"] .bg-slate-50,
html[data-site-theme="dark"] .bg-silver,
html[data-site-theme="dark"] [class~="bg-white/88"],
html[data-site-theme="dark"] [class~="bg-white/90"] {
  background-color: rgba(11, 15, 25, 0.95) !important;
  color: var(--site-dark-text) !important;
}

html[data-site-theme="dark"] .grid-paper {
  background-color: var(--site-dark-bg) !important;
  background-image: linear-gradient(rgba(13, 148, 136, 0.12) 1px, transparent 1px), linear-gradient(90deg, rgba(13, 148, 136, 0.12) 1px, transparent 1px) !important;
}

html[data-site-theme="dark"] .premium-hero.grid-paper::before {
  background: radial-gradient(circle at 15% 18%, rgba(13, 148, 136, 0.2), transparent 28rem), radial-gradient(circle at 84% 12%, rgba(217, 119, 6, 0.18), transparent 30rem), linear-gradient(135deg, rgba(2, 6, 23, 0.94), rgba(11, 15, 25, 0.72) 46%, rgba(2, 6, 23, 0.96)) !important;
}

html[data-site-theme="dark"] .text-ink,
html[data-site-theme="dark"] .text-slate-900,
html[data-site-theme="dark"] .text-slate-800,
html[data-site-theme="dark"] .text-slate-700 {
  color: var(--site-dark-text) !important;
}

html[data-site-theme="dark"] .text-slate-500,
html[data-site-theme="dark"] .text-slate-600 {
  color: var(--site-dark-muted) !important;
}

html[data-site-theme="dark"] .border-slate-200,
html[data-site-theme="dark"] .border-slate-300 {
  border-color: var(--site-dark-line) !important;
}

html[data-site-theme="dark"] input,
html[data-site-theme="dark"] select,
html[data-site-theme="dark"] textarea {
  color: var(--site-dark-text);
}

html[data-site-theme="dark"] .site-theme-toggle--mobile {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--site-dark-line);
}

html[data-site-theme="light"] .site-theme-toggle--mobile {
  background: rgba(15, 23, 42, 0.04);
  border-color: var(--site-light-line);
}

@media (prefers-reduced-motion: reduce) {
  html[data-site-theme] *,
  html[data-site-theme] *::before,
  html[data-site-theme] *::after {
    transition-duration: 0.001ms !important;
  }
}

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