:root {
  --whiteout: #FBFAFB;
  --live-jazz: #86819E;
  --luscious-purple: #625D73;
  --coronation-blue: #594BA0;
  --call-it-a-night: #41394F;
  --cold-steel: #261F32;
  --beige: #DDD0C8;
  --charcoal: #323232;
  --blue-grey: #96C2DB;
  --mist: #E5EDF1;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --section-ground: var(--cold-steel);
  --surface: var(--call-it-a-night);
  --raised: #514960;
  --hover: var(--luscious-purple);
  --rule: #86819E65;
  --strong-rule: var(--live-jazz);
  --surface-shadow: 0 12px 35px #140E213D;
  --action-bg: var(--coronation-blue);
  --action-hover: #6556B0;
  --action-ink: var(--whiteout);
  --paper: var(--cold-steel);
  --ink: var(--whiteout);
  --muted: #E3DFEB;
  --accent-ink: #D1C7E7;
  --stage-light: #625D735C;
  --studio-center: var(--luscious-purple);
  --model-shadow: #120E1CB3;
  --marker-base: #261F32DD;
  --marker-rim: #FBFAFBB8;
  --marker-highlight: #D1C7E7;
  --marker-halo: #D1C7E74F;
}

:root[data-theme="dark"] :is(.about, .monitoring, .project, .kitchens) {
  --section-ground: var(--call-it-a-night);
  --surface: #352E44;
}

:root[data-theme="light"] {
  color-scheme: light;
  --section-ground: var(--mist);
  --surface: #F4F7F8;
  --raised: var(--mist);
  --hover: #D6E6EF;
  --rule: #32323232;
  --strong-rule: #32323270;
  --surface-shadow: 0 12px 32px #32323217;
  --action-bg: var(--blue-grey);
  --action-hover: #A9CDE0;
  --action-ink: var(--charcoal);
  --paper: var(--mist);
  --ink: var(--charcoal);
  --muted: #454C51;
  --accent-ink: #36576E;
  --stage-light: #96C2DB76;
  --studio-center: var(--whiteout);
  --model-shadow: #32323238;
  --marker-base: #323232DE;
  --marker-rim: #E5EDF1C4;
  --marker-highlight: var(--blue-grey);
  --marker-halo: #96C2DB80;
}

:root[data-theme="light"] :is(.site-header, .about, .protection, .project, .closing, .site-footer) {
  --section-ground: var(--beige);
}

:root[data-theme] {
  --gold: var(--accent-ink);
  --light-gold: var(--accent-ink);
  --blue: var(--paper);
}

:root[data-theme] :is(.site-header, .hero, .section, .site-footer) {
  color: var(--ink);
  background: var(--section-ground);
}
:root[data-theme] :is(.site-header, .site-footer, .hero-bottom, .protection, .contact-details) { border-color: var(--rule); }
:root[data-theme] .section + .section { box-shadow: inset 0 1px var(--rule); }

:root[data-theme] :is(a, button, [tabindex], summary):focus-visible { outline-color: var(--accent-ink); }
:root[data-theme] :is(.site-header nav a, .site-footer p, .site-footer a:not(.brand)) { color: var(--muted); }
:root[data-theme] :is(h1, h2, h3) em { color: var(--gold); }
:root[data-theme] .eyebrow { color: var(--accent-ink); }
:root[data-theme] .eyebrow > span:first-child { background: var(--gold); }
:root[data-theme] :is(.hero-copy, .closing) > p:not(.eyebrow),
:root[data-theme] :is(.stage-label, .studio-controls p, .contact-details dd) { color: var(--muted); }
:root[data-theme] .contact-details dt { color: var(--ink); }

.theme-picker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: .85rem;
  white-space: nowrap;
}
.theme-input { position: relative; display: inline-flex; }
.theme-icon, .theme-input::after { position: absolute; pointer-events: none; }
.theme-icon {
  width: 16px;
  height: 16px;
  inset: 50% auto auto 8px;
  transform: translateY(-50%);
  color: var(--gold);
  stroke: currentColor;
  stroke-width: 1.2;
  fill: none;
}
.theme-icon path { fill: currentColor; stroke: none; }
.theme-input::after {
  content: "";
  width: 6px;
  height: 6px;
  inset: 50% 10px auto auto;
  transform: translateY(-70%) rotate(45deg);
  border: solid currentColor;
  border-width: 0 1.5px 1.5px 0;
}
#theme-choice {
  appearance: none;
  min-width: 95px;
  min-height: 40px;
  padding: 0 23px 0 29px;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 4px;
  font: inherit;
  cursor: pointer;
}
#theme-choice:hover { border-color: var(--gold); }
#theme-choice:focus-visible { outline-offset: 4px; }
:root[data-theme] :is(.language-picker summary, .language-options) { border-color: var(--rule); }
:root[data-theme] .language-options { background: var(--surface); color: var(--ink); }
:root[data-theme] :is(.menu-toggle, .language-picker summary):hover,
:root[data-theme] .language-picker[open] summary,
:root[data-theme] .language-options a:is(:hover, [aria-current="true"]) { background: var(--raised); }
:root:lang(ar) #theme-choice { padding-inline: 29px 23px; }

:root[data-theme] :is(.button-gold, .contact-link) {
  background: var(--action-bg);
  color: var(--action-ink);
  border-color: transparent;
}
:root[data-theme] :is(.button-gold, .contact-link):hover { background: var(--action-hover); }
:root[data-theme] .button-outline { border-color: var(--strong-rule); }
:root[data-theme] .button-outline:hover { background: var(--hover); border-color: var(--gold); }

:root[data-theme] .hero-features {
  --feature-icon: var(--accent-ink);
  --feature-glow: transparent;
}
:root[data-theme] .scan-copy {
  background-image: repeating-linear-gradient(0deg, var(--muted) 0 1px, var(--accent-ink) 1px 4px, var(--ink) 4px 5px);
}
:root[data-theme] .stage::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 4% 0 6%;
  background: radial-gradient(ellipse at 50% 53%, var(--stage-light), transparent 69%);
  pointer-events: none;
}
:root[data-theme] :is(.stage-grid, .stage-orbit) { opacity: .24; }
:root[data-theme] #kitchen-canvas { filter: drop-shadow(0 16px 18px var(--model-shadow)); }
:root[data-theme] .stage-status {
  background: var(--surface);
  color: var(--muted);
  border-color: var(--rule);
}

:root[data-theme] :is(.reveal-figure, .studio-figure) {
  outline: 1px solid var(--rule);
  box-shadow: var(--surface-shadow);
}
:root[data-theme] .reveal-figure {
  background: radial-gradient(ellipse at 52% 42%, var(--luscious-purple), var(--cold-steel) 88%);
}
:root[data-theme] :is(.reveal-figure, .studio-figure) figcaption {
  background: #261F32EB;
  color: var(--whiteout);
}
:root[data-theme] #studio-dialog {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--strong-rule);
  box-shadow: var(--surface-shadow);
}
:root[data-theme] .studio-view {
  background: radial-gradient(ellipse at 51% 43%, var(--studio-center), var(--section-ground));
}
:root[data-theme] #studio-canvas { filter: drop-shadow(0 12px 13px var(--model-shadow)); }

:root[data-theme] :is(.monitoring, .project) {
  --panel-ink: var(--ink);
  --panel-muted: var(--muted);
  --panel-accent: var(--accent-ink);
  --panel-line: var(--rule);
  --panel-base: var(--surface);
  --panel-raised: var(--raised);
  --panel-hover: var(--hover);
}
:root[data-theme="light"] .monitoring .monitor-pill.operational { color: #285C3C; background: #E7F4EB; border-color: #39734C44; }
:root[data-theme="light"] .monitoring :is(.monitor-pill.warning, .hardware-stale) { color: #74460B; background: #FCF0DC; border-color: #94642255; }
:root[data-theme="light"] .monitoring .monitor-pill.critical { color: #882936; background: #FBE8EC; border-color: #A53E4A55; }
:root[data-theme] :is(.monitor-board, .project-method-grid article, .project-circuit) { box-shadow: var(--surface-shadow); }
:root[data-theme] :is(.monitor-board, .hardware-dialog) {
  --hw-accent: var(--action-bg);
  --hw-primary-ink: var(--action-ink);
  --hw-rule: var(--rule);
  --hw-surface: var(--surface);
  --hw-raised: var(--raised);
  --hw-ink: var(--ink);
  --hw-muted: var(--muted);
}
:root[data-theme] .hw-primary:hover { background: var(--action-hover); border-color: transparent; filter: none; }
:root[data-theme] .hw-secondary:hover { background: var(--hover); border-color: var(--gold); filter: none; }
:root[data-theme] .hw-guides a { color: var(--accent-ink); }
:root[data-theme] .monitor-camera-frame img { background: var(--raised); }

:root[data-theme] .protection-demo {
  --demo-surface: var(--surface);
  --demo-ink: var(--ink);
  --demo-muted: var(--muted);
  --demo-rule: var(--rule);
  --demo-gold: var(--gold);
  --demo-selected: var(--action-bg);
  --demo-selected-ink: var(--action-ink);
  --demo-sim-ink: var(--muted);
  --demo-sim-bg: var(--raised);
  box-shadow: var(--surface-shadow);
}
:root[data-theme] .services {
  --cap-ivory: var(--section-ground);
  --cap-navy: var(--ink);
  --cap-muted: var(--muted);
  --cap-gold: var(--gold);
  --cap-gold-ink: var(--accent-ink);
  --cap-border: var(--rule);
  --cap-card: var(--surface);
}
:root[data-theme] .capability-card {
  box-shadow: var(--surface-shadow);
}
:root[data-theme] .capability-card:is(:hover, :focus-within) { border-color: var(--gold); }
:root[data-theme] .capability-card > picture img { background: var(--raised); }

:root[data-theme] #exploration-tools {
  --explore-line: var(--rule);
  --explore-text: var(--muted);
  --explore-title: var(--ink);
  --explore-accent: var(--gold);
  --explore-surface: var(--surface);
  --explore-active: var(--action-bg);
  --explore-active-text: var(--action-ink);
}
:root[data-theme] .exploration-toolbar button:is(#show-labels, #hide-labels)[aria-pressed="true"] {
  background: var(--raised);
  border-color: var(--strong-rule);
  color: var(--ink);
}
:root[data-theme] .exploration-marker { color: var(--marker-rim); }
:root[data-theme] .exploration-marker::before {
  width: 10px;
  height: 10px;
  background: var(--marker-base);
  box-shadow: 0 0 0 1px var(--marker-base);
}
:root[data-theme] .exploration-marker::after { width: 3px; height: 3px; }
:root[data-theme] .exploration-marker.is-highlighted { color: var(--marker-highlight); }
:root[data-theme] .exploration-marker.is-highlighted::before { animation: none; }
:root[data-theme] .exploration-marker:is(:hover, :focus-visible, [aria-expanded="true"])::before {
  box-shadow: 0 0 0 2px var(--marker-halo);
}
:root[data-theme] .exploration-connector { stroke: var(--accent-ink); stroke-opacity: .32; }
:root[data-theme] .exploration-connector.is-highlighted { stroke: var(--marker-highlight); stroke-opacity: .84; }
:root[data-theme] .exploration-tooltip {
  background: var(--surface);
  color: var(--muted);
  border-color: var(--rule);
}
@media (prefers-reduced-motion: no-preference) {
  :root[data-theme="light"] .exploration-marker.is-highlighted::before {
    animation: exploration-marker-pulse 2.5s ease-in-out infinite;
  }
}
@keyframes exploration-marker-pulse {
  50% { box-shadow: 0 0 0 3px var(--marker-halo); }
}

@media (max-width: 980px) {
  .theme-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }
}
@media (max-width: 860px) {
  :root[data-theme] .site-header nav {
    background: var(--section-ground);
    border-color: var(--rule);
  }
}
@media (max-width: 380px) {
  :root:lang(ar) #theme-choice { padding-inline: 7px 19px; }
}
@media (forced-colors: active) {
  #theme-choice { border-color: ButtonText; }
}

@media (max-width: 1040px) {
  .site-header :is(.brand, .menu-toggle, #theme-choice, .language-picker summary, .language-options a) {
    min-height: 44px;
  }
  .site-header .language-picker summary {
    min-width: 44px;
  }
}
