/* Lynent light/dark theme.
   Light is the base (tokens.css). Dark swaps the tokens on <html data-theme="dark">.
   Dark mode is fully dark: the black "inverse" bands become a slightly raised charcoal band instead of
   flipping to light, so nothing on the page is bright. */

:root[data-theme="dark"] {
  --bg: #0A0A0A;
  --bg-2: #141414;
  --ink: #FFFFFF;
  --ink-2: #A3A3A3;
  --ink-3: #8A8A8A;
  --rule: #262626;
  --rule-strong: #FFFFFF;
  --rule-input: #737373;
  --code-bg: #111111;
  --inverse-bg: #141414;
  --inverse-ink: #FFFFFF;
  --inverse-rule: #262626;
  --scrim: rgba(0, 0, 0, 0.64);
  color-scheme: dark;
}
:root[data-theme="dark"] body { background: var(--bg); color: var(--ink); }

:root[data-theme="dark"] .inverse {
  --bg: #141414;
  --bg-2: #1C1C1C;
  --ink: #FFFFFF;
  --ink-2: #A3A3A3;
  --ink-3: #8A8A8A;
  --rule: #2A2A2A;
  --rule-strong: #FFFFFF;
  --rule-input: #737373;
  --code-bg: #0E0E0E;
  color-scheme: dark;
}

/* Fallback animation when the View Transitions API is not available. */
:root.theme-fading,
:root.theme-fading *,
:root.theme-fading *::before,
:root.theme-fading *::after {
  transition: background-color 420ms cubic-bezier(.2, .7, .2, 1), color 420ms cubic-bezier(.2, .7, .2, 1),
    border-color 420ms cubic-bezier(.2, .7, .2, 1), fill 420ms cubic-bezier(.2, .7, .2, 1) !important;
}

/* Circular reveal from the switch (View Transitions API). */
::view-transition-old(root),
::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
::view-transition-new(root) { z-index: 2; }
::view-transition-old(root) { z-index: 1; }

/* ------------------------------------------------------------------ the switch */
.theme-switch {
  --w: 52px; --h: 28px; --pad: 3px; --knob: calc(var(--h) - var(--pad) * 2);
  position: relative;
  display: inline-flex;
  align-items: center;
  flex: none;
  width: var(--w);
  height: var(--h);
  padding: 0;
  border: 1px solid var(--rule-strong);
  border-radius: 999px;
  background: var(--bg);
  color: var(--ink);
  cursor: pointer;
  overflow: hidden;
  transition: background-color 360ms cubic-bezier(.2, .7, .2, 1), border-color 360ms;
  -webkit-tap-highlight-color: transparent;
}
.theme-switch:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
.theme-switch[aria-checked="true"] { background: var(--ink); }

/* Track icons: sun on the right (visible in dark), moon on the left (visible in light). */
.theme-switch .ts-icon {
  position: absolute;
  top: 50%;
  width: 14px;
  height: 14px;
  margin-top: -7px;
  transition: opacity 300ms, transform 520ms cubic-bezier(.3, 1.4, .5, 1);
}
.theme-switch .ts-moon { right: 8px; color: var(--ink); opacity: 1; transform: rotate(0) scale(1); }
.theme-switch .ts-sun { left: 8px; color: var(--bg); opacity: 0; transform: rotate(-90deg) scale(.4); }
.theme-switch[aria-checked="true"] .ts-moon { opacity: 0; transform: rotate(90deg) scale(.4); }
.theme-switch[aria-checked="true"] .ts-sun { opacity: 1; transform: rotate(0) scale(1); }

/* Knob slides with a little squash and overshoot. */
.theme-switch .ts-knob {
  position: absolute;
  top: var(--pad);
  left: var(--pad);
  width: var(--knob);
  height: var(--knob);
  border-radius: 999px;
  background: var(--ink);
  transform: translateX(0);
  transition: transform 520ms cubic-bezier(.3, 1.4, .5, 1), background-color 360ms, width 220ms ease;
}
.theme-switch[aria-checked="true"] .ts-knob {
  background: var(--bg);
  transform: translateX(calc(var(--w) - var(--knob) - var(--pad) * 2 - 2px));
}
.theme-switch:active .ts-knob { width: calc(var(--knob) + 6px); }
.theme-switch[aria-checked="true"]:active .ts-knob { transform: translateX(calc(var(--w) - var(--knob) - var(--pad) * 2 - 8px)); }

/* Crater detail on the knob in dark mode, so it reads as a moon. */
.theme-switch .ts-knob::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset -5px -3px 0 0 var(--ink);
  opacity: 0;
  transform: scale(.6);
  transition: opacity 300ms 120ms, transform 420ms 120ms cubic-bezier(.3, 1.4, .5, 1);
}
.theme-switch[aria-checked="true"] .ts-knob::after { opacity: .18; transform: scale(1); }

.theme-switch .sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Floating placement for pages without a header slot (checkout, auth). */
.theme-switch.theme-switch-floating { position: fixed; right: 16px; bottom: 16px; z-index: 50; }

@media (prefers-reduced-motion: reduce) {
  .theme-switch, .theme-switch .ts-knob, .theme-switch .ts-icon, .theme-switch .ts-knob::after { transition: none; }
}

/* ------------------------------------------------------------------ dark theme: component fixes */
/* Status colours: lighter on the dark page so badges, notices and toasts keep their contrast;
   light bands inside the dark page keep the light-theme values. */
:root[data-theme="dark"] { --ok: #47CD89; --warn: #F5A524; --bad: #F97066; }
:root[data-theme="dark"] .btn-danger:hover { --btn-ink: #0A0A0A; }

/* Select chevron drawn in the current ink colour. */
:root[data-theme="dark"] select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23FFFFFF' stroke-width='1.5' stroke-linecap='square'%3E%3Cpath d='M6.75 9.5 12 14.75l5.25-5.25'/%3E%3C/svg%3E");
}

/* Loading skeletons: dark shimmer on the dark page, light shimmer in light bands. */
:root[data-theme="dark"] .skeleton {
  background: linear-gradient(90deg, #1A1A1A 0%, #1A1A1A 35%, #2A2A2A 50%, #1A1A1A 65%, #1A1A1A 100%);
  background-size: 300% 100%;
}
@media (prefers-reduced-motion: reduce) {
  :root[data-theme="dark"] .skeleton { background: #1A1A1A; }
}

/* The home page checkout illustration goes dark too. */
:root[data-theme="dark"] .cp-card { background: #141414; color: #FFFFFF; box-shadow: 0 0 0 1px #2A2A2A, 0 24px 48px -24px rgba(0, 0, 0, .8); }
:root[data-theme="dark"] .cp-logo, :root[data-theme="dark"] .cp-wallet, :root[data-theme="dark"] .cp-pay { background: #FFFFFF; color: #0A0A0A; }
:root[data-theme="dark"] .cp-total-label, :root[data-theme="dark"] .cp-secure { color: #A3A3A3; }
:root[data-theme="dark"] .cp-items { border-top-color: #2A2A2A; }
:root[data-theme="dark"] .cp-items li { border-bottom-color: #2A2A2A; }
:root[data-theme="dark"] .cp-field { border-color: #3A3A3A; }
:root[data-theme="dark"] .cp-qty, :root[data-theme="dark"] .cp-ph { color: #737373; }

/* Phones: a slightly smaller switch so it fits next to the header links. */
@media (max-width: 420px) {
  .site-header .theme-switch, .topbar .theme-switch { --w: 46px; --h: 26px; }
}
