:root {
  --bg: #050816;
  --bg-gradient: radial-gradient(circle at top, #1d1b4b 0, #050816 45%, #020617 100%);
  --text: #e4e7f5;
  --heading-text: #f8fafc;
  --subtext: rgba(228, 231, 245, 0.9);
  --link-color: #a5b4fc;
  --section-heading: #c4b5fd;
  --card-bg: rgba(15, 23, 42, 0.9);
  --card-border: rgba(148, 163, 184, 0.12);
  --card-hover-border: rgba(148, 163, 184, 0.22);
  --accent: #4f46e5;
  --accent-light: #8b5cf6;
  --overlay-top: rgba(79, 70, 229, 0.35);
  --overlay-bottom: rgba(139, 92, 246, 0.35);
  --nav-bg: linear-gradient(to right, rgba(15, 23, 42, 0.85), rgba(15, 23, 42, 0.6));
  --nav-brand: #e5e7eb;
  --nav-link: #cbd5f5;
  --nav-link-hover-bg: rgba(148, 163, 184, 0.25);
  --nav-link-hover-text: #f9fafb;
  --switcher-bg: rgba(15, 23, 42, 0.85);
  --switcher-text: #e5e7eb;
  --surface-muted: rgba(15, 23, 42, 0.7);
  --surface-soft: rgba(15, 23, 42, 0.8);
  --input-bg: rgba(15, 23, 42, 0.8);
  --input-border: rgba(148, 163, 184, 0.6);
  --header-image-border: rgba(248, 250, 252, 0.8);
  --footer-text: #9ca3af;
  --particle-color: rgba(148, 163, 255, 0.5);
  --shadow: rgba(0, 0, 0, 0.4);
}

body.light {
  --bg: #f8fbff;
  --bg-gradient: radial-gradient(circle at top, #ffffff 0, #eef4ff 38%, #dde9ff 100%);
  --text: #172033;
  --heading-text: #101828;
  --subtext: #4a5a72;
  --link-color: #1d4ed8;
  --section-heading: #2448b8;
  --card-bg: #ffffff;
  --card-border: rgba(148, 163, 184, 0.26);
  --card-hover-border: rgba(37, 99, 235, 0.25);
  --accent: #2563eb;
  --accent-light: #4f46e5;
  --overlay-top: rgba(96, 165, 250, 0.2);
  --overlay-bottom: rgba(167, 139, 250, 0.18);
  --nav-bg: linear-gradient(to right, rgba(255, 255, 255, 0.92), rgba(239, 246, 255, 0.84));
  --nav-brand: #172033;
  --nav-link: #42526b;
  --nav-link-hover-bg: rgba(37, 99, 235, 0.12);
  --nav-link-hover-text: #1d4ed8;
  --switcher-bg: rgba(226, 232, 240, 0.9);
  --switcher-text: #334155;
  --surface-muted: rgba(226, 232, 240, 0.92);
  --surface-soft: rgba(241, 245, 249, 0.95);
  --input-bg: #f8fafc;
  --input-border: rgba(148, 163, 184, 0.45);
  --header-image-border: rgba(255, 255, 255, 0.98);
  --footer-text: #64748b;
  --particle-color: rgba(59, 130, 246, 0.22);
  --shadow: rgba(15, 23, 42, 0.15);
}

body.dark {
  --bg: #050816;
  --text: #e4e7f5;
  --card-bg: rgba(15, 23, 42, 0.9);
  --accent: #4f46e5;
  --accent-light: #8b5cf6;
  --shadow: rgba(0, 0, 0, 0.4);
}

@media (prefers-color-scheme: dark) {
  body.system {
    --bg: #050816;
    --bg-gradient: radial-gradient(circle at top, #1d1b4b 0, #050816 45%, #020617 100%);
    --text: #e4e7f5;
    --heading-text: #f8fafc;
    --subtext: rgba(228, 231, 245, 0.9);
    --link-color: #a5b4fc;
    --section-heading: #c4b5fd;
    --card-bg: rgba(15, 23, 42, 0.9);
    --card-border: rgba(148, 163, 184, 0.12);
    --card-hover-border: rgba(148, 163, 184, 0.22);
    --accent: #4f46e5;
    --accent-light: #8b5cf6;
    --overlay-top: rgba(79, 70, 229, 0.35);
    --overlay-bottom: rgba(139, 92, 246, 0.35);
    --nav-bg: linear-gradient(to right, rgba(15, 23, 42, 0.85), rgba(15, 23, 42, 0.6));
    --nav-brand: #e5e7eb;
    --nav-link: #cbd5f5;
    --nav-link-hover-bg: rgba(148, 163, 184, 0.25);
    --nav-link-hover-text: #f9fafb;
    --switcher-bg: rgba(15, 23, 42, 0.85);
    --switcher-text: #e5e7eb;
    --surface-muted: rgba(15, 23, 42, 0.7);
    --surface-soft: rgba(15, 23, 42, 0.8);
    --input-bg: rgba(15, 23, 42, 0.8);
    --input-border: rgba(148, 163, 184, 0.6);
    --header-image-border: rgba(248, 250, 252, 0.8);
    --footer-text: #9ca3af;
    --particle-color: rgba(148, 163, 255, 0.5);
    --shadow: rgba(0, 0, 0, 0.4);
  }
}

@media (prefers-color-scheme: light) {
  body.system {
    --bg: #f8fbff;
    --bg-gradient: radial-gradient(circle at top, #ffffff 0, #eef4ff 38%, #dde9ff 100%);
    --text: #172033;
    --heading-text: #101828;
    --subtext: #4a5a72;
    --link-color: #1d4ed8;
    --section-heading: #2448b8;
    --card-bg: #ffffff;
    --card-border: rgba(148, 163, 184, 0.26);
    --card-hover-border: rgba(37, 99, 235, 0.25);
    --accent: #2563eb;
    --accent-light: #4f46e5;
    --overlay-top: rgba(96, 165, 250, 0.2);
    --overlay-bottom: rgba(167, 139, 250, 0.18);
    --nav-bg: linear-gradient(to right, rgba(255, 255, 255, 0.92), rgba(239, 246, 255, 0.84));
    --nav-brand: #172033;
    --nav-link: #42526b;
    --nav-link-hover-bg: rgba(37, 99, 235, 0.12);
    --nav-link-hover-text: #1d4ed8;
    --switcher-bg: rgba(226, 232, 240, 0.9);
    --switcher-text: #334155;
    --surface-muted: rgba(226, 232, 240, 0.92);
    --surface-soft: rgba(241, 245, 249, 0.95);
    --input-bg: #f8fafc;
    --input-border: rgba(148, 163, 184, 0.45);
    --header-image-border: rgba(255, 255, 255, 0.98);
    --footer-text: #64748b;
    --particle-color: rgba(59, 130, 246, 0.22);
    --shadow: rgba(15, 23, 42, 0.15);
  }
}

body {
  background: var(--bg-gradient);
  color: var(--text);
  transition: background 0.4s ease, color 0.4s ease;
}

#bg-canvas {
  position: fixed;
  inset: 0;
  z-index: -2;
}

.gradient-overlay {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at top left, var(--overlay-top), transparent 55%),
              radial-gradient(circle at bottom right, var(--overlay-bottom), transparent 55%);
  mix-blend-mode: screen;
  pointer-events: none;
  z-index: -1;
}

.theme-switcher {
  display: flex;
  gap: 0.25rem;
  background: var(--switcher-bg);
  padding: 0.2rem;
  border-radius: 999px;
  box-shadow: 0 8px 24px var(--shadow);
}

.theme-switcher button {
  border: none;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  cursor: pointer;
  background: transparent;
  color: var(--switcher-text);
  font-size: 0.75rem;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  transition: background 0.2s ease, color 0.2s ease;
}

.theme-switcher button.active {
  background: var(--accent);
  color: #f9fafb;
}