/* ==========================================================================
   A.P.E.X — Appearance control ("Key Light")
   --------------------------------------------------------------------------
   Shared across the marketing site, the product SPA and the legal/utility
   pages. Styles ONLY the switcher component — the per-page colour tokens live
   in each document's own <style> block, because every page in this project is
   deliberately self-contained.

   The control is a tri-state segmented radiogroup: Light / Auto / Dark.
   "Auto" follows the operating system and is a first-class option, not a
   hidden default — a visitor can always see which of the three is in force.

   Design language matches the product: thin technical borders, an inset
   track, a raised sliding cap, JetBrains Mono / Orbitron accents, and the
   brand cyan used sparingly as the "on" signal.
   ========================================================================== */

.apex-theme-switch {
  --ts-h: 38px;              /* control height                              */
  --ts-seg: 40px;            /* width of one segment                        */
  --ts-pad: 3px;             /* track inner padding                         */
  --ts-ease: cubic-bezier(.22, .61, .36, 1);

  position: relative;
  display: inline-grid;
  grid-template-columns: repeat(3, var(--ts-seg));
  align-items: center;
  height: var(--ts-h);
  padding: var(--ts-pad);
  border-radius: calc(var(--ts-h) / 2);
  border: 1px solid var(--ts-line, rgba(255, 255, 255, 0.14));
  background: var(--ts-track, rgba(255, 255, 255, 0.04));
  box-shadow: var(--ts-track-shadow, inset 0 1px 3px rgba(0, 0, 0, 0.32));
  -webkit-backdrop-filter: blur(10px) saturate(140%);
          backdrop-filter: blur(10px) saturate(140%);
  isolation: isolate;
  flex: none;
}

/* ── The sliding cap ─────────────────────────────────────────────────────
   One element, moved with transform so the animation stays on the
   compositor. Position is driven by --ts-i (0 | 1 | 2) set from script.

   The easing is a light overshoot rather than a plain ease-out: the cap
   settles like a physical key instead of gliding to a stop. It is applied to
   transform only — colour and shadow keep the neutral curve, because
   overshooting a colour reads as a flicker. */
.apex-theme-switch::before {
  content: "";
  position: absolute;
  z-index: 0;
  top: var(--ts-pad);
  left: var(--ts-pad);
  width: var(--ts-seg);
  height: calc(var(--ts-h) - var(--ts-pad) * 2);
  border-radius: 999px;
  background: var(--ts-cap, linear-gradient(180deg, rgba(255, 255, 255, 0.17), rgba(255, 255, 255, 0.055)));
  border: 1px solid var(--ts-cap-line, rgba(255, 255, 255, 0.2));
  box-shadow: var(--ts-cap-shadow,
      0 0 0 1px color-mix(in srgb, var(--ts-on, #00F0FF) 26%, transparent),
      0 2px 5px rgba(0, 0, 0, 0.5),
      inset 0 1px 0 rgba(255, 255, 255, 0.20),
      inset 0 -1px 0 rgba(0, 0, 0, 0.28));
  transform: translateX(calc(var(--ts-i, 2) * var(--ts-seg)));
  transition: transform .42s cubic-bezier(.34, 1.32, .48, 1),
              background .3s var(--ts-ease),
              box-shadow .3s var(--ts-ease);
}
@media (prefers-reduced-motion: reduce) {
  .apex-theme-switch::before { transition: none; }
}

/* ── Segments ───────────────────────────────────────────────────────────── */
.apex-theme-switch button {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: var(--ts-seg);
  height: calc(var(--ts-h) - var(--ts-pad) * 2);
  padding: 0;
  margin: 0;
  border: 0;
  border-radius: 999px;
  background: none;
  cursor: pointer;
  color: var(--ts-idle, rgba(255, 255, 255, 0.5));
  -webkit-tap-highlight-color: transparent;
  transition: color .22s var(--ts-ease), transform .22s var(--ts-ease);
}

.apex-theme-switch button:hover { color: var(--ts-hover, rgba(255, 255, 255, 0.82)); }

/* Hover halo on the INACTIVE segments only — a hint that the whole segment is
   the target, not just the glyph. Suppressed under the cap, which already
   marks the active one. */
.apex-theme-switch button::before {
  content: "";
  position: absolute;
  inset: 2px;
  border-radius: 999px;
  background: currentColor;
  opacity: 0;
  transition: opacity .2s var(--ts-ease);
  pointer-events: none;
}
.apex-theme-switch button:hover::before { opacity: .07; }
.apex-theme-switch button[aria-checked="true"]::before { opacity: 0; }

.apex-theme-switch button[aria-checked="true"] {
  color: var(--ts-on, #00F0FF);
}

.apex-theme-switch button:active { transform: scale(.88); }

.apex-theme-switch button:focus-visible {
  outline: 2px solid var(--ts-on, #00F0FF);
  outline-offset: 2px;
}

.apex-theme-switch svg {
  width: 17px;
  height: 17px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  overflow: visible;
}

/* Sun rays retract slightly when the sun is not the active choice — a small
   piece of state feedback rather than decoration. */
.apex-theme-switch .ts-rays {
  transform-origin: center;
  transition: transform .4s var(--ts-ease), opacity .3s var(--ts-ease);
  transform: rotate(-25deg) scale(.72);
  opacity: .65;
}
.apex-theme-switch button[aria-checked="true"] .ts-rays {
  transform: rotate(0deg) scale(1);
  opacity: 1;
}

/* The moon leans upright and its stars appear only when it is the choice. */
.apex-theme-switch .ts-stars {
  transition: opacity .3s var(--ts-ease), transform .4s var(--ts-ease);
  transform-origin: 12px 12px;
  transform: scale(.6);
  opacity: 0;
}
.apex-theme-switch button[aria-checked="true"] .ts-stars {
  opacity: .92;
  transform: scale(1);
}
.apex-theme-switch .ts-moon {
  transform-origin: 12px 12px;
  transform: rotate(-14deg);
  transition: transform .42s cubic-bezier(.34, 1.32, .48, 1);
}
.apex-theme-switch button[aria-checked="true"] .ts-moon { transform: rotate(0deg); }

/* The auto disc fills from the leading edge as it becomes the choice. */
.apex-theme-switch .ts-half {
  transform-origin: 12px 12px;
  transform: scaleX(.55);
  opacity: .55;
  transition: transform .38s var(--ts-ease), opacity .3s var(--ts-ease);
}
.apex-theme-switch button[aria-checked="true"] .ts-half {
  transform: scaleX(1);
  opacity: 1;
}

/* ── Screen-reader-only label ───────────────────────────────────────────── */
.apex-theme-switch .ts-sr {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ── Light-mode skin ─────────────────────────────────────────────────────
   Tokens are re-pointed rather than the rules being duplicated. */
:root[data-theme="light"] .apex-theme-switch {
  --ts-line: rgba(15, 23, 42, 0.16);
  --ts-track: rgba(15, 23, 42, 0.045);
  --ts-track-shadow: inset 0 1px 3px rgba(15, 23, 42, 0.09);
  --ts-cap: linear-gradient(180deg, #ffffff, #f2f5fa);
  --ts-cap-line: rgba(15, 23, 42, 0.12);
  --ts-cap-shadow: 0 2px 7px rgba(15, 23, 42, 0.16), inset 0 1px 0 #fff;
  --ts-idle: rgba(15, 23, 42, 0.45);
  --ts-hover: rgba(15, 23, 42, 0.78);
  --ts-on: #067D8B;
  /* On paper the cap is a raised white key: no inner glow, a real cast
     shadow, and a hairline top highlight. The accent underline is dialled
     back because a bloom on white reads as a smudge. */
  --ts-cap-shadow: 0 1px 2px rgba(15,23,42,0.10), 0 3px 8px -2px rgba(15,23,42,0.16), inset 0 1px 0 #fff;
  --ts-underline-o: .34;
}

/* ── Compact variant — tight headers and the SPA top bar ────────────────── */
.apex-theme-switch.is-compact {
  --ts-h: 32px;
  --ts-seg: 33px;
  --ts-pad: 2.5px;
}
.apex-theme-switch.is-compact svg { width: 15px; height: 15px; }

/* ── Motion preferences ─────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .apex-theme-switch::before,
  .apex-theme-switch button,
  .apex-theme-switch .ts-rays,
  .apex-theme-switch .ts-stars { transition: none; }
}

/* ── Whole-page cross-fade ───────────────────────────────────────────────
   Done with the View Transitions API, NOT a universal `* { transition }`.
   The transition-everything approach was measured on the marketing page and
   took over 500ms to settle: it forces every element on a very long document
   to interpolate colour at once, which is the same class of repaint storm
   this project has already been bitten by twice. A view transition instead
   cross-fades two GPU snapshots of the page — constant cost regardless of
   how many nodes changed — and degrades to an instant swap where the API is
   unsupported (Firefox today) with no fallback code path to maintain. */
::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: .3s;
  animation-timing-function: cubic-bezier(.22, .61, .36, 1);
  /* Both snapshots occupy the same box; a plain opacity cross-fade avoids the
     default slide, which would read as the page jumping. */
  mix-blend-mode: normal;
}
@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root),
  ::view-transition-new(root) { animation: none; }
}
