/* ============================================================
   POWERFUL DAY / NIGHT SWITCH  —  blog-theme-switch.css
   Overrides the basic .theme-switch with a cinematic sky toggle:
   day sky -> night sky, sun -> moon with craters, drifting stars,
   clouds, glow halo, press + focus feedback.
   Default theme for the blog is LIGHT (day).
   Load AFTER blog-template.css / blog-core.css.
   ============================================================ */

body .theme-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 78px;
  height: 38px;
  flex-shrink: 0;
  padding: 0;
  margin: 0;
  border-radius: 999px;
  cursor: pointer;
  overflow: hidden;
  isolation: isolate;
  border: 1px solid rgba(148, 163, 184, 0.45);
  background: linear-gradient(160deg, #7dd3fc 0%, #bae6fd 45%, #e0f2fe 100%);
  box-shadow:
    inset 0 2px 6px rgba(255, 255, 255, 0.85),
    inset 0 -3px 10px rgba(14, 165, 233, 0.28),
    0 1px 2px rgba(15, 23, 42, 0.12);
  transition:
    background 0.55s cubic-bezier(0.4, 0, 0.2, 1),
    box-shadow 0.55s cubic-bezier(0.4, 0, 0.2, 1),
    border-color 0.55s ease,
    transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
  -webkit-tap-highlight-color: transparent;
}

body .theme-switch:hover { transform: translateY(-1px) scale(1.03); }
body .theme-switch:active { transform: scale(0.95); }

/* Night sky */
html[data-theme="dark"] body .theme-switch {
  border-color: rgba(129, 140, 248, 0.55);
  background: linear-gradient(160deg, #0b1026 0%, #1e1b4b 55%, #312e81 100%);
  box-shadow:
    inset 0 2px 8px rgba(129, 140, 248, 0.25),
    inset 0 -3px 10px rgba(0, 0, 0, 0.65),
    0 1px 3px rgba(2, 6, 23, 0.35);
}

body .theme-switch input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
  z-index: 5;
}

body .theme-switch input:focus-visible ~ .ts-thumb {
  box-shadow:
    0 0 0 3px rgba(99, 102, 241, 0.55),
    0 4px 14px rgba(0, 0, 0, 0.35);
}

/* ---------- The celestial thumb ---------- */
body .theme-switch .ts-thumb {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  z-index: 3;
  background: radial-gradient(circle at 32% 30%, #fff8dc 0%, #fde047 42%, #f59e0b 100%);
  box-shadow:
    0 0 0 4px rgba(253, 224, 71, 0.35),
    0 0 18px 4px rgba(251, 191, 36, 0.75),
    0 4px 10px rgba(180, 83, 9, 0.35);
  transform: translateX(0) rotate(0deg);
  transition:
    transform 0.6s cubic-bezier(0.68, -0.35, 0.27, 1.35),
    background 0.5s ease,
    box-shadow 0.5s ease;
}

/* Moon craters (hidden during the day) */
body .theme-switch .ts-thumb::before,
body .theme-switch .ts-thumb::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  background: rgba(100, 116, 139, 0.55);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.35);
  opacity: 0;
  transition: opacity 0.45s ease 0.15s;
}
body .theme-switch .ts-thumb::before {
  width: 8px; height: 8px; top: 7px; left: 6px;
}
body .theme-switch .ts-thumb::after {
  width: 5px; height: 5px; bottom: 6px; right: 7px;
}

html[data-theme="dark"] body .theme-switch .ts-thumb,
body .theme-switch input:checked + .ts-thumb {
  transform: translateX(40px) rotate(360deg);
  background: radial-gradient(circle at 35% 32%, #ffffff 0%, #e2e8f0 45%, #cbd5e1 100%);
  box-shadow:
    0 0 0 4px rgba(226, 232, 240, 0.18),
    0 0 20px 5px rgba(191, 219, 254, 0.55),
    0 4px 12px rgba(2, 6, 23, 0.6);
}
html[data-theme="dark"] body .theme-switch .ts-thumb::before,
html[data-theme="dark"] body .theme-switch .ts-thumb::after,
body .theme-switch input:checked + .ts-thumb::before,
body .theme-switch input:checked + .ts-thumb::after { opacity: 1; }

/* ---------- Icons ---------- */
body .theme-switch .ts-icon {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  font-size: 0.72rem;
  line-height: 1;
  pointer-events: none;
  transition: opacity 0.4s ease, transform 0.4s ease;
}
body .theme-switch .ts-icon.ts-sun {
  left: 11px;
  color: #f59e0b;
  opacity: 0;
}
body .theme-switch .ts-icon.ts-moon {
  right: 11px;
  color: #c7d2fe;
  opacity: 0.9;
}
html[data-theme="dark"] body .theme-switch .ts-icon.ts-sun {
  opacity: 0.85;
  color: #fbbf24;
}
html[data-theme="dark"] body .theme-switch .ts-icon.ts-moon { opacity: 0; }

/* ---------- Sky layer (injected by blog-theme.js) ---------- */
.ts-sky {
  position: absolute;
  inset: 0;
  z-index: 1;
  border-radius: inherit;
  overflow: hidden;
  pointer-events: none;
}
.ts-star {
  position: absolute;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: #ffffff;
  opacity: 0;
  transform: scale(0.2);
  box-shadow: 0 0 6px 1px rgba(255, 255, 255, 0.9);
  transition: opacity 0.5s ease, transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}
html[data-theme="dark"] .ts-star {
  opacity: 1;
  transform: scale(1);
  animation: tsTwinkle 2.6s ease-in-out infinite;
}
html[data-theme="dark"] .ts-star:nth-child(2) { animation-delay: 0.5s; }
html[data-theme="dark"] .ts-star:nth-child(3) { animation-delay: 1s; }
html[data-theme="dark"] .ts-star:nth-child(4) { animation-delay: 1.5s; }
html[data-theme="dark"] .ts-star:nth-child(5) { animation-delay: 2s; }

@keyframes tsTwinkle {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.6); }
}

.ts-cloud {
  position: absolute;
  height: 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  filter: blur(0.4px);
  opacity: 1;
  transition: opacity 0.45s ease, transform 0.6s ease;
}
html[data-theme="dark"] .ts-cloud {
  opacity: 0;
  transform: translateX(-14px);
}

/* Halo pulse fired on every switch */
.ts-ripple {
  position: absolute;
  inset: 0;
  z-index: 0;
  border-radius: 999px;
  pointer-events: none;
  opacity: 0;
}
.theme-switch.ts-fired .ts-ripple {
  animation: tsPulse 0.65s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes tsPulse {
  0%   { opacity: 0.85; box-shadow: inset 0 0 0 0 rgba(255, 255, 255, 0.55); }
  100% { opacity: 0;   box-shadow: inset 0 0 0 14px rgba(255, 255, 255, 0); }
}

/* Smooth global cross-fade when the theme flips */
html.ts-switching,
html.ts-switching body,
html.ts-switching .app-header,
html.ts-switching .page-footer {
  transition: background-color 0.45s ease, color 0.45s ease, border-color 0.45s ease;
}

@media (prefers-reduced-motion: reduce) {
  body .theme-switch,
  body .theme-switch .ts-thumb,
  .ts-star,
  .ts-cloud { transition-duration: 0.01ms !important; animation: none !important; }
}

/* Mobile: keep it thumb-friendly but slightly tighter */
@media (max-width: 560px) {
  body .theme-switch { width: 66px; height: 34px; }
  body .theme-switch .ts-thumb { width: 26px; height: 26px; }
  html[data-theme="dark"] body .theme-switch .ts-thumb,
  body .theme-switch input:checked + .ts-thumb { transform: translateX(32px) rotate(360deg); }
}
