/* Day and night on every page of roadmarker.cc (shell/theme.js): the switch and the sweep from one to the other. */
:root {
  --sweep-angle: to bottom left;   /* day and night both come in from the top right */
  --dur: 3000ms;
  --well: var(--switch-well); --key: var(--switch-key); --beam-hi: var(--switch-beam-hi); --beam-lo: var(--switch-beam-lo);
}
/* The dimmer switch from a handlebar: rocker up = high beam (night), down = low beam (day) */
.switch {
  position: relative; flex: none; width: 38px; height: 44px; padding: 0; border: 0; border-radius: 10px;
  background: transparent; cursor: pointer; perspective: 90px; view-transition-name: switch;
}
.switch .well { position: absolute; left: 6px; top: 6px; width: 12px; height: 30px; border-radius: 5px; background: var(--well); }
.switch .key {
  position: absolute; left: 7px; top: 7px; width: 10px; height: 28px; border-radius: 4px; background: var(--key);
  transform: rotateX(-18deg); transition: transform .3s cubic-bezier(.3, 1.6, .5, 1);
}
[data-theme="night"] .switch .key { transform: rotateX(18deg); }
.switch svg {
  position: absolute; right: 5px; width: 12px; height: 9px; fill: none; stroke: currentColor;
  stroke-width: 1.6; stroke-linecap: round; transition: color .3s;
}
.switch .hi { top: 11px; color: var(--beam-hi); }
.switch .lo { bottom: 11px; color: var(--beam-lo); }

/* Day/night sweep. --edge runs from fully outside one corner to fully outside the other, with a soft band. */
@property --edge { syntax: "<percentage>"; inherits: false; initial-value: 0%; }
::view-transition-old(root), ::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
::view-transition-new(root) {
  -webkit-mask-image: linear-gradient(var(--sweep-angle), var(--secondary) calc(var(--edge) - 22%), transparent calc(var(--edge) + 22%));
          mask-image: linear-gradient(var(--sweep-angle), var(--secondary) calc(var(--edge) - 22%), transparent calc(var(--edge) + 22%));
  /* Fast, calm, fast: a quick start so the click is answered at once, a calm middle over the page,
     and a quick finish so it does not linger; the cubic-bezier is the fallback for browsers without linear() */
  animation: sweep var(--dur) cubic-bezier(.15, .6, .85, .4) both, dusk var(--dur) ease-in-out both;
  animation: sweep var(--dur) linear(0, .12 4%, .2 9%, .27 15%, .4 30%, .5 45%, .6 60%, .73 82%, .8 88%, .88 94%, 1) both,
             dusk var(--dur) ease-in-out both;
}
::view-transition-old(root) { animation: dusk var(--dur) ease-in-out both; }
@keyframes sweep { from { --edge: -22%; } to { --edge: 122%; } }
/* Warm light while the line crosses the page, on both sides, like dusk and dawn */
@keyframes dusk {
  0%, 100% { filter: none; }
  45% { filter: sepia(.38) saturate(1.5) hue-rotate(-14deg) brightness(.94); }   /* when the sweep is halfway */
}
/* The switch flips at once instead of waiting for the sweep */
::view-transition-group(switch) { animation-duration: 0s; }
::view-transition-old(switch) { display: none; }
::view-transition-new(switch) { animation: none; }
@media (prefers-reduced-motion: reduce) {
  ::view-transition-new(root) { -webkit-mask-image: none; mask-image: none; animation: fade 400ms both; }
  ::view-transition-old(root) { animation: none; }
  @keyframes fade { from { opacity: 0; } }
}