/*
  Frosted split-wipe for a theme change, ported from omarchy.org's
  src/styles/theme-transition.css.

  A 10-degree parallelogram slit opens over 200ms through the View Transitions
  API. The old page is frosted in the snapshot the browser keeps of it, so the
  slit is what clears the frost, edge by edge. Nothing is blurred on the live
  page first: a backdrop blur is not carried into that snapshot by every
  browser, which leaves a sharp frame between the two.

  Browsers without the API, and anyone who asked for less motion, swap in one
  frame.
*/

@property --theme-wipe {
  syntax: '<length-percentage>';
  inherits: false;
  initial-value: 0px;
}

::view-transition {
  position: fixed;
  inset: 0;
  overflow: clip;
  pointer-events: none;
  filter: none;
}

::view-transition-group(root) {
  animation: none;
  position: absolute;
  inset: 0;
  overflow: hidden;
}

::view-transition-image-pair(root) {
  animation: none;
  inset: 0;
  overflow: hidden;
}

::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
  opacity: 1;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: none;
  object-position: 0 0;
  filter: none;
}

::view-transition-new(root) { z-index: 0; }

/*
  100deg = 10 degrees off vertical, top leaning right. Both leading edges
  share that lean, so the slit is a parallelogram. It starts closed and grows
  outward along the axis perpendicular to the blades. The filter is applied
  before the mask, so the blades stay sharp.
*/
::view-transition-old(root) {
  z-index: 1;
  animation: theme-split-wipe 200ms cubic-bezier(0.7, 0, 1, 1) both;
  mask-image: linear-gradient(
    100deg,
    #000 0,
    #000 calc(50% - var(--theme-wipe) + 1px),
    #0000 calc(50% - var(--theme-wipe) + 1px),
    #0000 calc(50% + var(--theme-wipe) - 1px),
    #000 calc(50% + var(--theme-wipe) - 1px),
    #000 100%
  );
  mask-mode: alpha;
  mask-size: 100% 100%;
  mask-repeat: no-repeat;
}

/* Frosted only for a wipe that starts from the picker, where the page already
   wears this blur under the panel. A theme taken from anywhere else wipes
   from a sharp page. */
:root.theme-wipe-frosted::view-transition-old(root) { filter: blur(4px); }

@keyframes theme-split-wipe {
  from { --theme-wipe: 0px; }
  to   { --theme-wipe: 80%; }
}

@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root),
  ::view-transition-new(root) { animation: none; }
}
