/* ============================================================
   theme.css — "Sparkle eclipse" theme toggle + theme-switch rules
   (pairs with js/theme.js; THEME_SOUND.md §A1)
   Tokens are read with fallbacks so the toggle works in either theme
   even before styles.css defines them.
   ============================================================ */

/* ---------------- toggle button ---------------- */
.theme-toggle {
  --tt-size: 40px;             /* = .kbd-btn / .icon-btn; styles.css raises it to 44px for touch */
  position: relative;
  display: inline-grid; place-items: center; flex: none;
  width: var(--tt-size); height: var(--tt-size);
  padding: 0; margin: 0;
  border-radius: 50%;
  border: 1px solid var(--glass-line, rgb(21 17 20 / .08));
  background: var(--glass, rgb(255 255 255 / .72));
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  backdrop-filter: blur(14px) saturate(1.4);
  color: var(--text, #151114);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 1px 2px rgb(var(--fg-rgb, 21 17 20) / .06);
  transition: transform .35s cubic-bezier(.34, 1.56, .64, 1), box-shadow .35s ease,
    border-color .25s ease, background-color .25s ease;
}
html[data-theme="dark"] .theme-toggle {
  border-color: var(--glass-line, rgb(255 255 255 / .07));
  background: var(--glass, rgb(22 24 28 / .72));
  color: var(--text, #ecedf0);
}
@media (hover: hover) {
  .theme-toggle:hover {
    transform: translateY(-2px);
    border-color: rgb(255 90 60 / .28);
    box-shadow:
      0 0 0 1px rgb(255 27 141 / .10),
      0 8px 22px -10px rgb(255 27 141 / .45),
      0 6px 20px -12px rgb(255 194 60 / .55);
  }
  html[data-theme="dark"] .theme-toggle:hover {
    box-shadow:
      0 0 0 1px rgb(255 27 141 / .14),
      0 8px 24px -10px rgb(255 27 141 / .32),
      0 0 18px -6px rgb(255 120 60 / .28);
  }
}
.theme-toggle:active { transform: scale(.96); transition-duration: .12s; }
.theme-toggle:focus { outline: none; }
.theme-toggle:focus-visible {
  outline: 2px solid var(--g1, #ff1b8d);
  outline-offset: 3px;
}

/* ---------------- eclipse icon ----------------
   LIGHT: gradient sun + 8 rays, moon parked outside the box.
   DARK : the moon slides over the sun, rays retract into a glowing corona
          ring with a little ✦ "diamond ring" glint; the icon turns 90°. */
.theme-toggle .tt-icon {
  display: block; width: 22px; height: 22px;
  overflow: hidden;            /* hides the parked moon */
  pointer-events: none;
}
.tt-icon * { transform-box: view-box; transform-origin: 12px 12px; }
.tt-rot { transition: transform .65s cubic-bezier(.34, 1.56, .64, 1); }
.tt-ray {
  transition: transform .5s cubic-bezier(.34, 1.56, .64, 1), opacity .3s ease;
  transition-delay: calc(var(--i, 0) * 16ms);
}
.tt-sun { transition: transform .65s cubic-bezier(.34, 1.56, .64, 1); }
.tt-bite, .tt-moon {
  transform: translate(10px, -10px);
  transition: transform .65s cubic-bezier(.34, 1.56, .64, 1), opacity .4s ease;
}
.tt-moon { fill: currentColor; opacity: 0; transition: transform .65s cubic-bezier(.34, 1.56, .64, 1), opacity .18s ease; }
.tt-corona {
  opacity: 0; transform: scale(.62);
  transition: transform .65s cubic-bezier(.34, 1.56, .64, 1) .06s, opacity .35s ease .08s;
}
.tt-bead {
  fill: #fff4dc; opacity: 0; transform-origin: 6.77px 6.77px; transform: scale(0) rotate(-45deg);
  transition: transform .45s cubic-bezier(.34, 1.56, .64, 1) .32s, opacity .25s ease .3s;
}

html[data-theme="dark"] .tt-rot { transform: rotate(90deg); }
html[data-theme="dark"] .tt-ray { transform: scale(.55); opacity: 0; transition-delay: calc((7 - var(--i, 0)) * 12ms); }
html[data-theme="dark"] .tt-sun { transform: scale(.94); }
html[data-theme="dark"] .tt-bite,
html[data-theme="dark"] .tt-moon { transform: translate(0, 0); }
html[data-theme="dark"] .tt-moon { opacity: .1; transition-delay: 0s, .18s; }
html[data-theme="dark"] .tt-corona { opacity: 1; transform: scale(1); }
html[data-theme="dark"] .tt-corona-glow { opacity: .75; }
html[data-theme="dark"] .tt-bead { opacity: 1; transform: scale(1) rotate(0deg); }
/* reversing (dark → light): the bead leaves first, rays come back after the moon */
html[data-theme="light"] .tt-bead { transition-delay: 0s, 0s; }
html[data-theme="light"] .tt-ray { transition-delay: calc(120ms + var(--i, 0) * 16ms); }

/* ---------------- star-iris view transition ----------------
   theme.js sets html[data-theme-wipe] only while the switch runs and drives
   clip-path on ::view-transition-new(root) with WAAPI. */
html[data-theme-wipe]::view-transition { pointer-events: none; }   /* clicks reach the page (re-press = restart) */
html[data-theme-wipe]::view-transition-group(root) { animation: none; }
html[data-theme-wipe]::view-transition-old(root),
html[data-theme-wipe]::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
}
/* hidden until the WAAPI star takes over (if it never does, the switch is instant) */
html[data-theme-wipe]::view-transition-new(root) { clip-path: polygon(0 0, 0 0, 0 0); }
html[data-theme-wipe]::view-transition-group(theme-fx),
html[data-theme-wipe]::view-transition-old(theme-fx),
html[data-theme-wipe]::view-transition-new(theme-fx) { animation: none; }
html[data-theme-wipe]::view-transition-old(theme-fx) { display: none; }

/* the live overlay (glow edge + sparkles); inline styles in theme.js mirror this */
.theme-fx {
  position: fixed; left: 0; top: 0;
  pointer-events: none;
  z-index: 2147483000;
  view-transition-name: theme-fx;
}

/* while the star crosses, the revealed (new) page must show its final colours at once:
   no colour transitions catching up inside the star. The toggle keeps its spring. */
html[data-theme-wipe] *:not(.theme-toggle, .theme-toggle *),
html[data-theme-wipe] *::before, html[data-theme-wipe] *::after { transition: none !important; }

/* ---------------- cross-fade fallback (no View Transitions) ----------------
   Colours fade over 450ms; transforms/opacity keep a transition so hover lifts
   in flight are not snapped. The eclipse icon keeps its own spring. */
html.theme-switching,
html.theme-switching *:not(.tt-icon, .tt-icon *),
html.theme-switching *:not(.tt-icon *)::before,
html.theme-switching *:not(.tt-icon *)::after {
  transition-property: background-color, color, border-color, outline-color, fill, stroke, box-shadow, text-decoration-color, transform, opacity !important;
  transition-duration: .45s, .45s, .45s, .45s, .45s, .45s, .45s, .45s, .35s, .35s !important;
  transition-timing-function: ease !important;
  transition-delay: 0s !important;
}

/* ---------------- reduced motion: instant, no spin ---------------- */
@media (prefers-reduced-motion: reduce) {
  .theme-toggle, .tt-rot, .tt-ray, .tt-sun, .tt-bite, .tt-moon, .tt-corona, .tt-bead { transition: none !important; }
  html[data-theme="dark"] .tt-rot { transform: none; }
  .theme-toggle:hover { transform: none; }
}
