/* ============================================================================
   Notely shared theme transition
   ---------------------------------------------------------------------------
   The circular reveal is driven by JS (js/notely-theme.js) using the View
   Transitions API and falls back to a clip-path overlay. Both mechanisms need
   these rules on every page that has a theme toggle, otherwise the animation
   silently does nothing.

   Keep in sync with src/index.css (the React workspace uses the same port).
   ========================================================================== */

::view-transition-old(root),
::view-transition-new(root) {
  animation: none !important;
  mix-blend-mode: normal;
}

/* Expanding (light -> dark): new snapshot paints over the old one. */
html.rev::view-transition-old(root) {
  z-index: 2;
}

/* Shrinking (dark -> light): the moving circle is the outgoing snapshot. */
html.rev::view-transition-new(root) {
  z-index: 1;
}

/* Fallback for browsers without the View Transitions API. */
.notely-theme-fallback {
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  pointer-events: none;
  background: var(--notely-reveal-color, #0a0c11);
  clip-path: circle(0px at var(--notely-theme-x, 50vw) var(--notely-theme-y, 50vh));
}

@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation-duration: 0s !important;
  }

  .notely-theme-fallback {
    display: none !important;
  }
}

/* ----------------------------------------------------------------------------
   Icon swap. The toggle shows a moon in dark mode and a sun in light mode,
   rotating and scaling between the two instead of hard-cutting.
   -------------------------------------------------------------------------- */
.n-theme-btn {
  position: relative;
  overflow: hidden;
}

.n-theme-btn svg {
  transition: transform 420ms cubic-bezier(0.16, 1, 0.3, 1),
              opacity 260ms ease;
  transform-origin: 50% 50%;
}

html[data-theme='dark'] .n-theme-btn .n-sun {
  display: grid;
  opacity: 0;
  transform: rotate(90deg) scale(0.4);
}

html[data-theme='dark'] .n-theme-btn .n-moon {
  display: grid;
  opacity: 1;
  transform: rotate(0) scale(1);
}

html[data-theme='light'] .n-theme-btn .n-moon {
  display: grid;
  opacity: 0;
  transform: rotate(-90deg) scale(0.4);
}

html[data-theme='light'] .n-theme-btn .n-sun {
  display: grid;
  opacity: 1;
  transform: rotate(0) scale(1);
}

/* Both icons occupy the same box so the button never changes size. */
.n-theme-btn .n-sun,
.n-theme-btn .n-moon {
  grid-area: 1 / 1;
}

.n-theme-btn:hover svg {
  transform: scale(1.12);
}

@media (prefers-reduced-motion: reduce) {
  .n-theme-btn svg {
    transition: none;
  }

  html[data-theme='dark'] .n-theme-btn .n-sun,
  html[data-theme='light'] .n-theme-btn .n-moon {
    transform: none;
  }
}
