/* ============================================================
   THEME TOGGLE  —  Ultra-Luxury Glassmorphic Switch

   A minimalist, high-precision Swiss-horology-inspired switch.
   Features multi-layered optical glassmorphism, dynamic specular
   rim lighting, a jewel-like tactile knob with spring physics,
   celestial micro-details (pulsing lunar sparkle & solar corona),
   and subtle status dot indicators.
   ============================================================ */

.theme-btn {
  /* Minimalist, slender executive proportions */
  --tb-h: clamp(38px, 4vw, 44px);
  --tb-w: calc(var(--tb-h) * 2.4);
  --tb-pad: 3.5px;
  --tb-knob: calc(var(--tb-h) - var(--tb-pad) * 2);
  --tb-travel: calc(var(--tb-w) - var(--tb-knob) - var(--tb-pad) * 2);

  /* Direction: +1 in LTR, -1 in RTL */
  --dir: 1;

  position: fixed;
  inset-block-start: clamp(1rem, 2.5vh, 1.75rem);
  inset-inline-end: clamp(1rem, 2.5vw, 2rem);
  z-index: var(--z-menu-btn);

  inline-size: var(--tb-w);
  block-size: var(--tb-h);
  padding: 0;

  border-radius: var(--r-pill);
  border: 1px solid rgba(255, 255, 255, 0.16);

  /* Deep optical glass housing */
  background-color: rgba(12, 14, 20, 0.52);
  background-image:
    radial-gradient(circle at 82% 50%, rgba(168, 85, 247, 0.14) 0%, transparent 60%),
    linear-gradient(135deg,
      rgba(255, 255, 255, 0.14) 0%,
      rgba(255, 255, 255, 0.03) 42%,
      rgba(10, 12, 18, 0.65) 100%);
  -webkit-backdrop-filter: blur(24px) saturate(1.8);
  backdrop-filter: blur(24px) saturate(1.8);

  /* Specular rim lights and subtle depth shadows */
  box-shadow:
    0 10px 28px -4px rgba(0, 0, 0, 0.55),
    inset 0  1px 1px 0 rgba(255, 255, 255, 0.35),
    inset 0 -1px 2px 0 rgba(0, 0, 0, 0.5),
    inset 0  0 18px 0 rgba(168, 85, 247, 0.06);

  color: var(--c-on-media);
  cursor: pointer;
  overflow: clip;
  isolation: isolate;

  transition:
    background-color var(--dur-base) var(--ease),
    background-image var(--dur-base) var(--ease),
    border-color     var(--dur-base) var(--ease),
    box-shadow       var(--dur-base) var(--ease),
    transform        0.25s var(--ease-out);
}

[dir='rtl'] .theme-btn { --dir: -1; }

/* Subtle roving light sweep on hover */
.theme-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(115deg,
    transparent 15%,
    rgba(255, 255, 255, 0.20) 50%,
    transparent 85%);
  transform: translateX(calc(-120% * var(--dir)));
  transition: transform 0.65s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
  z-index: 1;
}

.theme-btn:hover::before {
  transform: translateX(calc(120% * var(--dir)));
}

.theme-btn:hover {
  border-color: rgba(255, 255, 255, 0.32);
  transform: translateY(-1px);
  box-shadow:
    0 14px 34px -4px rgba(0, 0, 0, 0.65),
    inset 0  1px 1.5px 0 rgba(255, 255, 255, 0.5),
    inset 0 -1px 2px 0 rgba(0, 0, 0, 0.5),
    inset 0  0 20px 0 rgba(168, 85, 247, 0.12);
}

.theme-btn:active {
  transform: translateY(0.5px);
}

.theme-btn:focus-visible {
  outline: none;
  border-color: rgba(168, 85, 247, 0.8);
  box-shadow:
    0 0 0 2px rgba(168, 85, 247, 0.6),
    0 0 0 5px rgba(0, 0, 0, 0.7),
    0 10px 24px rgba(0, 0, 0, 0.5);
}

/* Light Theme Styling: Frosted Pearl Crystal */
[data-theme='light'] .theme-btn {
  border-color: rgba(255, 255, 255, 0.85);
  background-color: rgba(255, 255, 255, 0.65);
  background-image:
    radial-gradient(circle at 18% 50%, rgba(245, 158, 11, 0.15) 0%, transparent 60%),
    linear-gradient(135deg,
      rgba(255, 255, 255, 0.95) 0%,
      rgba(241, 245, 249, 0.75) 45%,
      rgba(226, 232, 240, 0.85) 100%);
  box-shadow:
    0 8px 24px -4px rgba(15, 23, 42, 0.14),
    inset 0  1px 1.5px 0 #ffffff,
    inset 0 -1px 2px 0 rgba(0, 0, 0, 0.08),
    inset 0  0 18px 0 rgba(245, 158, 11, 0.08);
}

[data-theme='light'] .theme-btn:hover {
  border-color: #ffffff;
  box-shadow:
    0 12px 30px -4px rgba(15, 23, 42, 0.20),
    inset 0  1px 2px 0 #ffffff,
    inset 0 -1px 2px 0 rgba(0, 0, 0, 0.08),
    inset 0  0 22px 0 rgba(245, 158, 11, 0.14);
}

[data-theme='light'] .theme-btn:focus-visible {
  border-color: rgba(245, 158, 11, 0.8);
  box-shadow:
    0 0 0 2px rgba(245, 158, 11, 0.6),
    0 0 0 5px rgba(255, 255, 255, 0.85),
    0 8px 20px rgba(15, 23, 42, 0.15);
}

/* ---- labels ----------------------------------------------------
   Typography & Micro-Status Indicator Dots */
.theme-btn__label {
  position: absolute;
  inset-block: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  inline-size: calc(var(--tb-w) - var(--tb-knob) - var(--tb-pad) * 2);
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: rgba(215, 226, 234, 0.88);
  pointer-events: none;
  z-index: 2;
  transition:
    opacity   var(--dur-base) var(--ease),
    transform var(--dur-slow) var(--ease-out),
    filter    var(--dur-base) var(--ease);
}

/* Micro status dots beside labels */
.theme-btn__label::before {
  content: '';
  display: inline-block;
  inline-size: 4px;
  block-size: 4px;
  border-radius: 50%;
  flex-shrink: 0;
}

.theme-btn__label--dark::before {
  background-color: #a855f7;
  box-shadow: 0 0 6px rgba(168, 85, 247, 0.85);
}

.theme-btn__label--light::before {
  background-color: #f59e0b;
  box-shadow: 0 0 6px rgba(245, 158, 11, 0.9);
}

/* Dark mode resting state */
.theme-btn__label--dark {
  inset-inline-end: var(--tb-pad);
  opacity: 1;
  filter: blur(0px);
  transform: translateX(0);
}

.theme-btn__label--light {
  inset-inline-start: var(--tb-pad);
  opacity: 0;
  filter: blur(4px);
  transform: translateX(calc(10px * var(--dir) * -1));
}

[data-theme='light'] .theme-btn__label {
  color: #1e293b;
}

[data-theme='light'] .theme-btn__label--dark {
  opacity: 0;
  filter: blur(4px);
  transform: translateX(calc(10px * var(--dir)));
}

[data-theme='light'] .theme-btn__label--light {
  opacity: 1;
  filter: blur(0px);
  transform: translateX(0);
}

/* ---- the jewel knob --------------------------------------------
   Tactile spring physics with squash & stretch inertia */
.theme-btn__knob {
  --tb-x: 0px;
  --tb-scale-x: 1;
  --tb-scale-y: 1;

  position: absolute;
  inset-block-start: var(--tb-pad);
  inset-inline-start: var(--tb-pad);
  inline-size: var(--tb-knob);
  block-size: var(--tb-knob);
  border-radius: var(--r-pill);

  display: grid;
  place-items: center;
  z-index: 3;

  /* Obsidian sapphire crystal with luminous specular highlight */
  background-image:
    radial-gradient(circle at 34% 28%,
      rgba(255, 255, 255, 0.95) 0%,
      rgba(216, 226, 236, 0.45) 24%,
      rgba(35, 42, 58, 0.85) 68%,
      #0b0f17 100%);
  border: 1px solid rgba(255, 255, 255, 0.42);
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.55),
    0 0 12px rgba(168, 85, 247, 0.35),
    inset 0  1.5px 2px 0 rgba(255, 255, 255, 0.75),
    inset 0 -1px 2px 0 rgba(0, 0, 0, 0.6);
  -webkit-backdrop-filter: blur(18px) saturate(1.6);
  backdrop-filter: blur(18px) saturate(1.6);

  transform: translateX(calc(var(--tb-x) * var(--dir))) scale(var(--tb-scale-x), var(--tb-scale-y));
  transition:
    transform        0.52s cubic-bezier(0.34, 1.45, 0.64, 1),
    background-image var(--dur-base) var(--ease),
    border-color     var(--dur-base) var(--ease),
    box-shadow       var(--dur-base) var(--ease);
}

/* Light Mode: Radiant Solar Jewel */
[data-theme='light'] .theme-btn__knob {
  --tb-x: var(--tb-travel);
  background-image:
    radial-gradient(circle at 34% 28%,
      #FFFFFF 0%,
      #FEF08A 28%,
      #F59E0B 72%,
      #D97706 100%);
  border: 1px solid rgba(255, 255, 255, 0.9);
  box-shadow:
    0 4px 14px rgba(245, 158, 11, 0.45),
    0 0 16px rgba(251, 191, 36, 0.4),
    inset 0  1.5px 2px 0 #FFFFFF,
    inset 0 -1.5px 2px 0 rgba(180, 83, 9, 0.4);
}

.theme-btn:hover  .theme-btn__knob {
  --tb-scale-x: 1.05;
  --tb-scale-y: 1.05;
}

/* Squash & stretch inertia during click */
.theme-btn:active .theme-btn__knob {
  --tb-scale-x: 1.15;
  --tb-scale-y: 0.90;
}

/* ---- sun and moon celestial icons ------------------------------ */
.theme-btn__sun,
.theme-btn__moon {
  grid-area: 1 / 1;
  inline-size: 46%;
  block-size: 46%;
  border-radius: var(--r-pill);
  position: relative;
  transition:
    opacity   var(--dur-base) var(--ease),
    transform 0.5s var(--ease-out),
    filter    var(--dur-base) var(--ease);
}

/* Lunar crescent */
.theme-btn__moon {
  background-color: #f1f5f9;
  -webkit-mask-image: radial-gradient(circle at 116% 6%, transparent 0 52%, #000 53%);
  mask-image: radial-gradient(circle at 116% 6%, transparent 0 52%, #000 53%);
  filter: drop-shadow(0 0 3px rgba(241, 245, 249, 0.7));
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

/* Delicate twinkling celestial star beside the moon */
.theme-btn__moon::after {
  content: '';
  position: absolute;
  inset-block-start: -1px;
  inset-inline-end: -1px;
  inline-size: 3px;
  block-size: 3px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow:
    0 0 4px #ffffff,
    0 0 8px rgba(168, 85, 247, 0.9);
  animation: celestial-twinkle 2.5s ease-in-out infinite alternate;
}

@keyframes celestial-twinkle {
  0% { transform: scale(0.65); opacity: 0.4; }
  100% { transform: scale(1.2); opacity: 1; }
}

/* Solar core & coronal rays */
.theme-btn__sun {
  background-color: #ffffff;
  filter: drop-shadow(0 0 4px rgba(255, 255, 255, 0.95));
  opacity: 0;
  transform: scale(0.5) rotate(-90deg);
}

.theme-btn__sun::before {
  content: '';
  position: absolute;
  inset: -34%;
  background-image: repeating-conic-gradient(from 0deg,
                      #ffffff 0deg 8deg,
                      transparent 8deg 45deg);
  -webkit-mask-image: radial-gradient(circle, transparent 0 54%, #000 55%);
  mask-image: radial-gradient(circle, transparent 0 54%, #000 55%);
}

[data-theme='light'] .theme-btn__sun {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

[data-theme='light'] .theme-btn__moon {
  opacity: 0;
  transform: scale(0.4) rotate(90deg);
}

/* ---- narrow screens -------------------------------------------- */
@media (max-width: 560px) {
  .theme-btn {
    --tb-w: calc(var(--tb-h) * 1.65);
  }

  .theme-btn__label {
    display: none;
  }
}

/* ---- reduced motion -------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .theme-btn,
  .theme-btn::before,
  .theme-btn__label,
  .theme-btn__knob,
  .theme-btn__sun,
  .theme-btn__moon,
  .theme-btn__moon::after {
    transition-duration: 1ms !important;
    animation: none !important;
  }

  .theme-btn__knob {
    transition-timing-function: linear !important;
  }

  .theme-btn:hover  .theme-btn__knob,
  .theme-btn:active .theme-btn__knob {
    --tb-scale-x: 1;
    --tb-scale-y: 1;
  }
}

/* ---- no backdrop-filter fallback ------------------------------- */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .theme-btn {
    background-color: rgb(var(--rgb-media) / 0.94);
  }
  [data-theme='light'] .theme-btn {
    background-color: rgba(255, 255, 255, 0.96);
  }
}
