/* Pixel theme switch (navbar .theme-toggle, desktop only; hidden <=991px as before).

   Everything sits on the 1px grid and moves in whole frames:
   - track 36x20 pixel capsule with a 1px outline, knob 16px pixel circle;
   - glyphs are 10x10 sprites drawn 1:1 (no resampling), inlined so a frame
     can never wait on a download;
   - the switch is an 8-frame sprite (40ms each, 320ms): wind-up, travel,
     overshoot, settle, with the glyph morphing sun > core > dot > moon (and
     back), so the knob is never empty;
   - the page itself swaps theme in the
     same 8 frames: it pours down from the navbar behind a dithered edge, via
     a View Transition, so every pixel is pure old or pure new colour and
     nothing passes through grey. The toggle is lifted out of
     that dissolve and always shows its final colours.
   Toggle colours are fixed swatches keyed on html.dark-mode (not the tweened
   --color-- vars), so they snap instead of fading. */

:root {
  /* 10x10 glyph sprites (1:1 pixels) and 8x16 dither tiles, inlined. */
  --pt-g-sun: url("data:image/svg+xml,%3Csvg fill=%22%23000%22 xmlns=%22http://www.w3.org/2000/svg%22 width=%2210%22 height=%2210%22 viewBox=%220 0 10 10%22 shape-rendering=%22crispEdges%22%3E%3Crect x=%224%22 y=%220%22 width=%222%22 height=%221%22/%3E%3Crect x=%221%22 y=%221%22 width=%221%22 height=%221%22/%3E%3Crect x=%224%22 y=%221%22 width=%222%22 height=%221%22/%3E%3Crect x=%228%22 y=%221%22 width=%221%22 height=%221%22/%3E%3Crect x=%222%22 y=%222%22 width=%221%22 height=%221%22/%3E%3Crect x=%227%22 y=%222%22 width=%221%22 height=%221%22/%3E%3Crect x=%223%22 y=%223%22 width=%224%22 height=%221%22/%3E%3Crect x=%220%22 y=%224%22 width=%222%22 height=%221%22/%3E%3Crect x=%223%22 y=%224%22 width=%224%22 height=%221%22/%3E%3Crect x=%228%22 y=%224%22 width=%222%22 height=%221%22/%3E%3Crect x=%220%22 y=%225%22 width=%222%22 height=%221%22/%3E%3Crect x=%223%22 y=%225%22 width=%224%22 height=%221%22/%3E%3Crect x=%228%22 y=%225%22 width=%222%22 height=%221%22/%3E%3Crect x=%223%22 y=%226%22 width=%224%22 height=%221%22/%3E%3Crect x=%222%22 y=%227%22 width=%221%22 height=%221%22/%3E%3Crect x=%227%22 y=%227%22 width=%221%22 height=%221%22/%3E%3Crect x=%221%22 y=%228%22 width=%221%22 height=%221%22/%3E%3Crect x=%224%22 y=%228%22 width=%222%22 height=%221%22/%3E%3Crect x=%228%22 y=%228%22 width=%221%22 height=%221%22/%3E%3Crect x=%224%22 y=%229%22 width=%222%22 height=%221%22/%3E%3C/svg%3E");
  --pt-g-sun-burst: url("data:image/svg+xml,%3Csvg fill=%22%23000%22 xmlns=%22http://www.w3.org/2000/svg%22 width=%2210%22 height=%2210%22 viewBox=%220 0 10 10%22 shape-rendering=%22crispEdges%22%3E%3Crect x=%220%22 y=%220%22 width=%221%22 height=%221%22/%3E%3Crect x=%224%22 y=%220%22 width=%222%22 height=%221%22/%3E%3Crect x=%229%22 y=%220%22 width=%221%22 height=%221%22/%3E%3Crect x=%221%22 y=%221%22 width=%221%22 height=%221%22/%3E%3Crect x=%228%22 y=%221%22 width=%221%22 height=%221%22/%3E%3Crect x=%222%22 y=%222%22 width=%221%22 height=%221%22/%3E%3Crect x=%227%22 y=%222%22 width=%221%22 height=%221%22/%3E%3Crect x=%223%22 y=%223%22 width=%224%22 height=%221%22/%3E%3Crect x=%220%22 y=%224%22 width=%221%22 height=%221%22/%3E%3Crect x=%223%22 y=%224%22 width=%224%22 height=%221%22/%3E%3Crect x=%229%22 y=%224%22 width=%221%22 height=%221%22/%3E%3Crect x=%220%22 y=%225%22 width=%221%22 height=%221%22/%3E%3Crect x=%223%22 y=%225%22 width=%224%22 height=%221%22/%3E%3Crect x=%229%22 y=%225%22 width=%221%22 height=%221%22/%3E%3Crect x=%223%22 y=%226%22 width=%224%22 height=%221%22/%3E%3Crect x=%222%22 y=%227%22 width=%221%22 height=%221%22/%3E%3Crect x=%227%22 y=%227%22 width=%221%22 height=%221%22/%3E%3Crect x=%221%22 y=%228%22 width=%221%22 height=%221%22/%3E%3Crect x=%228%22 y=%228%22 width=%221%22 height=%221%22/%3E%3Crect x=%220%22 y=%229%22 width=%221%22 height=%221%22/%3E%3Crect x=%224%22 y=%229%22 width=%222%22 height=%221%22/%3E%3Crect x=%229%22 y=%229%22 width=%221%22 height=%221%22/%3E%3C/svg%3E");
  --pt-g-sun-tight: url("data:image/svg+xml,%3Csvg fill=%22%23000%22 xmlns=%22http://www.w3.org/2000/svg%22 width=%2210%22 height=%2210%22 viewBox=%220 0 10 10%22 shape-rendering=%22crispEdges%22%3E%3Crect x=%224%22 y=%221%22 width=%222%22 height=%221%22/%3E%3Crect x=%222%22 y=%222%22 width=%221%22 height=%221%22/%3E%3Crect x=%227%22 y=%222%22 width=%221%22 height=%221%22/%3E%3Crect x=%223%22 y=%223%22 width=%224%22 height=%221%22/%3E%3Crect x=%221%22 y=%224%22 width=%221%22 height=%221%22/%3E%3Crect x=%223%22 y=%224%22 width=%224%22 height=%221%22/%3E%3Crect x=%228%22 y=%224%22 width=%221%22 height=%221%22/%3E%3Crect x=%221%22 y=%225%22 width=%221%22 height=%221%22/%3E%3Crect x=%223%22 y=%225%22 width=%224%22 height=%221%22/%3E%3Crect x=%228%22 y=%225%22 width=%221%22 height=%221%22/%3E%3Crect x=%223%22 y=%226%22 width=%224%22 height=%221%22/%3E%3Crect x=%222%22 y=%227%22 width=%221%22 height=%221%22/%3E%3Crect x=%227%22 y=%227%22 width=%221%22 height=%221%22/%3E%3Crect x=%224%22 y=%228%22 width=%222%22 height=%221%22/%3E%3C/svg%3E");
  --pt-g-dot: url("data:image/svg+xml,%3Csvg fill=%22%23000%22 xmlns=%22http://www.w3.org/2000/svg%22 width=%2210%22 height=%2210%22 viewBox=%220 0 10 10%22 shape-rendering=%22crispEdges%22%3E%3Crect x=%223%22 y=%223%22 width=%224%22 height=%221%22/%3E%3Crect x=%223%22 y=%224%22 width=%224%22 height=%221%22/%3E%3Crect x=%223%22 y=%225%22 width=%224%22 height=%221%22/%3E%3Crect x=%223%22 y=%226%22 width=%224%22 height=%221%22/%3E%3C/svg%3E");
  --pt-g-moon: url("data:image/svg+xml,%3Csvg fill=%22%23000%22 xmlns=%22http://www.w3.org/2000/svg%22 width=%2210%22 height=%2210%22 viewBox=%220 0 10 10%22 shape-rendering=%22crispEdges%22%3E%3Crect x=%223%22 y=%220%22 width=%224%22 height=%221%22/%3E%3Crect x=%222%22 y=%221%22 width=%223%22 height=%221%22/%3E%3Crect x=%221%22 y=%222%22 width=%223%22 height=%221%22/%3E%3Crect x=%221%22 y=%223%22 width=%223%22 height=%221%22/%3E%3Crect x=%220%22 y=%224%22 width=%223%22 height=%221%22/%3E%3Crect x=%220%22 y=%225%22 width=%223%22 height=%221%22/%3E%3Crect x=%221%22 y=%226%22 width=%223%22 height=%221%22/%3E%3Crect x=%229%22 y=%226%22 width=%221%22 height=%221%22/%3E%3Crect x=%221%22 y=%227%22 width=%224%22 height=%221%22/%3E%3Crect x=%228%22 y=%227%22 width=%222%22 height=%221%22/%3E%3Crect x=%222%22 y=%228%22 width=%227%22 height=%221%22/%3E%3Crect x=%223%22 y=%229%22 width=%224%22 height=%221%22/%3E%3C/svg%3E");
  --pt-g-moon-star: url("data:image/svg+xml,%3Csvg fill=%22%23000%22 xmlns=%22http://www.w3.org/2000/svg%22 width=%2210%22 height=%2210%22 viewBox=%220 0 10 10%22 shape-rendering=%22crispEdges%22%3E%3Crect x=%223%22 y=%220%22 width=%224%22 height=%221%22/%3E%3Crect x=%228%22 y=%220%22 width=%221%22 height=%221%22/%3E%3Crect x=%222%22 y=%221%22 width=%223%22 height=%221%22/%3E%3Crect x=%227%22 y=%221%22 width=%223%22 height=%221%22/%3E%3Crect x=%221%22 y=%222%22 width=%223%22 height=%221%22/%3E%3Crect x=%228%22 y=%222%22 width=%221%22 height=%221%22/%3E%3Crect x=%221%22 y=%223%22 width=%223%22 height=%221%22/%3E%3Crect x=%220%22 y=%224%22 width=%223%22 height=%221%22/%3E%3Crect x=%220%22 y=%225%22 width=%223%22 height=%221%22/%3E%3Crect x=%221%22 y=%226%22 width=%223%22 height=%221%22/%3E%3Crect x=%229%22 y=%226%22 width=%221%22 height=%221%22/%3E%3Crect x=%221%22 y=%227%22 width=%224%22 height=%221%22/%3E%3Crect x=%228%22 y=%227%22 width=%222%22 height=%221%22/%3E%3Crect x=%222%22 y=%228%22 width=%227%22 height=%221%22/%3E%3Crect x=%223%22 y=%229%22 width=%224%22 height=%221%22/%3E%3C/svg%3E");
  --pt-d-2: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%228%22 height=%2216%22 shape-rendering=%22crispEdges%22%3E%3Crect x=%220%22 y=%220%22 width=%222%22 height=%222%22/%3E%3Crect x=%224%22 y=%224%22 width=%222%22 height=%222%22/%3E%3Crect x=%220%22 y=%228%22 width=%222%22 height=%222%22/%3E%3Crect x=%224%22 y=%2212%22 width=%222%22 height=%222%22/%3E%3C/svg%3E");
  --pt-d-6: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%228%22 height=%2216%22 shape-rendering=%22crispEdges%22%3E%3Crect x=%220%22 y=%220%22 width=%222%22 height=%222%22/%3E%3Crect x=%224%22 y=%220%22 width=%222%22 height=%222%22/%3E%3Crect x=%222%22 y=%222%22 width=%222%22 height=%222%22/%3E%3Crect x=%220%22 y=%224%22 width=%222%22 height=%222%22/%3E%3Crect x=%224%22 y=%224%22 width=%222%22 height=%222%22/%3E%3Crect x=%226%22 y=%226%22 width=%222%22 height=%222%22/%3E%3Crect x=%220%22 y=%228%22 width=%222%22 height=%222%22/%3E%3Crect x=%224%22 y=%228%22 width=%222%22 height=%222%22/%3E%3Crect x=%222%22 y=%2210%22 width=%222%22 height=%222%22/%3E%3Crect x=%220%22 y=%2212%22 width=%222%22 height=%222%22/%3E%3Crect x=%224%22 y=%2212%22 width=%222%22 height=%222%22/%3E%3Crect x=%226%22 y=%2214%22 width=%222%22 height=%222%22/%3E%3C/svg%3E");
  --pt-d-10: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%228%22 height=%2216%22 shape-rendering=%22crispEdges%22%3E%3Crect x=%220%22 y=%220%22 width=%222%22 height=%222%22/%3E%3Crect x=%222%22 y=%220%22 width=%222%22 height=%222%22/%3E%3Crect x=%224%22 y=%220%22 width=%222%22 height=%222%22/%3E%3Crect x=%222%22 y=%222%22 width=%222%22 height=%222%22/%3E%3Crect x=%226%22 y=%222%22 width=%222%22 height=%222%22/%3E%3Crect x=%220%22 y=%224%22 width=%222%22 height=%222%22/%3E%3Crect x=%224%22 y=%224%22 width=%222%22 height=%222%22/%3E%3Crect x=%226%22 y=%224%22 width=%222%22 height=%222%22/%3E%3Crect x=%222%22 y=%226%22 width=%222%22 height=%222%22/%3E%3Crect x=%226%22 y=%226%22 width=%222%22 height=%222%22/%3E%3Crect x=%220%22 y=%228%22 width=%222%22 height=%222%22/%3E%3Crect x=%222%22 y=%228%22 width=%222%22 height=%222%22/%3E%3Crect x=%224%22 y=%228%22 width=%222%22 height=%222%22/%3E%3Crect x=%222%22 y=%2210%22 width=%222%22 height=%222%22/%3E%3Crect x=%226%22 y=%2210%22 width=%222%22 height=%222%22/%3E%3Crect x=%220%22 y=%2212%22 width=%222%22 height=%222%22/%3E%3Crect x=%224%22 y=%2212%22 width=%222%22 height=%222%22/%3E%3Crect x=%226%22 y=%2212%22 width=%222%22 height=%222%22/%3E%3Crect x=%222%22 y=%2214%22 width=%222%22 height=%222%22/%3E%3Crect x=%226%22 y=%2214%22 width=%222%22 height=%222%22/%3E%3C/svg%3E");
  --pt-d-14: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%228%22 height=%2216%22 shape-rendering=%22crispEdges%22%3E%3Crect x=%220%22 y=%220%22 width=%222%22 height=%222%22/%3E%3Crect x=%222%22 y=%220%22 width=%222%22 height=%222%22/%3E%3Crect x=%224%22 y=%220%22 width=%222%22 height=%222%22/%3E%3Crect x=%226%22 y=%220%22 width=%222%22 height=%222%22/%3E%3Crect x=%220%22 y=%222%22 width=%222%22 height=%222%22/%3E%3Crect x=%222%22 y=%222%22 width=%222%22 height=%222%22/%3E%3Crect x=%226%22 y=%222%22 width=%222%22 height=%222%22/%3E%3Crect x=%220%22 y=%224%22 width=%222%22 height=%222%22/%3E%3Crect x=%222%22 y=%224%22 width=%222%22 height=%222%22/%3E%3Crect x=%224%22 y=%224%22 width=%222%22 height=%222%22/%3E%3Crect x=%226%22 y=%224%22 width=%222%22 height=%222%22/%3E%3Crect x=%222%22 y=%226%22 width=%222%22 height=%222%22/%3E%3Crect x=%224%22 y=%226%22 width=%222%22 height=%222%22/%3E%3Crect x=%226%22 y=%226%22 width=%222%22 height=%222%22/%3E%3Crect x=%220%22 y=%228%22 width=%222%22 height=%222%22/%3E%3Crect x=%222%22 y=%228%22 width=%222%22 height=%222%22/%3E%3Crect x=%224%22 y=%228%22 width=%222%22 height=%222%22/%3E%3Crect x=%226%22 y=%228%22 width=%222%22 height=%222%22/%3E%3Crect x=%220%22 y=%2210%22 width=%222%22 height=%222%22/%3E%3Crect x=%222%22 y=%2210%22 width=%222%22 height=%222%22/%3E%3Crect x=%226%22 y=%2210%22 width=%222%22 height=%222%22/%3E%3Crect x=%220%22 y=%2212%22 width=%222%22 height=%222%22/%3E%3Crect x=%222%22 y=%2212%22 width=%222%22 height=%222%22/%3E%3Crect x=%224%22 y=%2212%22 width=%222%22 height=%222%22/%3E%3Crect x=%226%22 y=%2212%22 width=%222%22 height=%222%22/%3E%3Crect x=%222%22 y=%2214%22 width=%222%22 height=%222%22/%3E%3Crect x=%224%22 y=%2214%22 width=%222%22 height=%222%22/%3E%3Crect x=%226%22 y=%2214%22 width=%222%22 height=%222%22/%3E%3C/svg%3E");
}

/* Box: the 36x20 track plus the old enlarged hit area (6px each side, 10px above and
   below), so the box itself is the hit area and carries the focus ring. The track sits
   exactly where it did before. Layers: ::before outline, ::after fill, knob on top. */
.theme-toggle {
  --pt-track: var(--swatch--ecru-30);
  --pt-line: var(--swatch--neutral-80);
  --pt-shade: var(--swatch--ecru-40);
  --pt-knob: var(--swatch--neutral-100);
  --pt-glyph: var(--swatch--ecru-10);
  --pt-ring: var(--swatch--neutral-80);
  box-sizing: border-box;
  width: 48px;
  height: 40px;
  margin: -10px -22px 0 0; /* grow to the right: the left edge stays where the old dot sat */
  padding: 7px 3px; /* focus brackets sit 2px clear of the outline */
  border-radius: 0;
  background: transparent none no-repeat;
  background-origin: content-box;
  background-clip: content-box;
  transform: none;
  translate: var(--pt-snap-x, 0px) var(--pt-snap-y, 0px); /* set by pixel-toggle.js to land on whole pixels */
  transition: none;
  filter: none;
  -webkit-tap-highlight-color: transparent;
}

html.dark-mode .theme-toggle {
  --pt-track: var(--swatch--neutral-90);
  --pt-line: var(--swatch--neutral-75);
  --pt-shade: var(--swatch--neutral-95);
  --pt-knob: var(--swatch--neutral-10);
  --pt-glyph: var(--swatch--neutral-100);
  --pt-ring: var(--swatch--neutral-50);
}

.theme-toggle:hover {
  --pt-track: var(--swatch--ecru-40);
  --pt-line: var(--swatch--neutral-100);
  width: 48px;
  height: 40px;
  right: 0;
  background-color: transparent;
  transform: none;
}

html.dark-mode .theme-toggle:hover {
  --pt-track: var(--swatch--neutral-80);
  --pt-line: var(--swatch--neutral-60);
  --pt-shade: var(--swatch--neutral-90);
}

.theme-toggle.new:hover {
  right: 15%;
}

.theme-toggle:active {
  --pt-track: var(--swatch--ecru-50);
  --pt-shade: var(--swatch--ecru-50);
  transform: none;
}

html.dark-mode .theme-toggle:active {
  --pt-track: var(--swatch--neutral-75);
  --pt-shade: var(--swatch--neutral-80);
}

/* Outline: the track grown by one pixel on each side (4-connected, like hand-drawn pixel art). */
.theme-toggle::before {
  content: "";
  position: absolute;
  top: 9px;
  left: 5px;
  width: 38px;
  height: 22px;
  background: var(--pt-line);
  clip-path: polygon(31px 0px, 31px 1px, 33px 1px, 33px 2px, 34px 2px, 34px 3px, 35px 3px, 35px 4px, 36px 4px, 36px 5px, 37px 5px, 37px 7px, 38px 7px, 38px 15px, 37px 15px, 37px 17px, 36px 17px, 36px 18px, 35px 18px, 35px 19px, 34px 19px, 34px 20px, 33px 20px, 33px 21px, 31px 21px, 31px 22px, 7px 22px, 7px 21px, 5px 21px, 5px 20px, 4px 20px, 4px 19px, 3px 19px, 3px 18px, 2px 18px, 2px 17px, 1px 17px, 1px 15px, 0px 15px, 0px 7px, 1px 7px, 1px 5px, 2px 5px, 2px 4px, 3px 4px, 3px 3px, 4px 3px, 4px 2px, 5px 2px, 5px 1px, 7px 1px, 7px 0px);
}

/* Track: pixel capsule with a 2px inner shade on top, so it reads as a groove. */
.theme-toggle::after {
  content: "";
  position: absolute;
  inset: auto;
  top: 10px;
  left: 6px;
  width: 36px;
  height: 20px;
  border-radius: 0;
  background:
    linear-gradient(var(--pt-shade) 0 2px, transparent 2px) 0 0 / 100% 100% no-repeat,
    var(--pt-track);
  clip-path: polygon(30px 0px, 30px 1px, 32px 1px, 32px 2px, 33px 2px, 33px 3px, 34px 3px, 34px 4px, 35px 4px, 35px 6px, 36px 6px, 36px 14px, 35px 14px, 35px 16px, 34px 16px, 34px 17px, 33px 17px, 33px 18px, 32px 18px, 32px 19px, 30px 19px, 30px 20px, 6px 20px, 6px 19px, 4px 19px, 4px 18px, 3px 18px, 3px 17px, 2px 17px, 2px 16px, 1px 16px, 1px 14px, 0px 14px, 0px 6px, 1px 6px, 1px 4px, 2px 4px, 2px 3px, 3px 3px, 3px 2px, 4px 2px, 4px 1px, 6px 1px, 6px 0px);
}

/* Rest: only the knob shows, like the original dot. On hover, keyboard focus or during a
   switch, the outline and track draw out from the knob toward its travel side in 4 frames
   (40ms each), and wipe back the same way on leave. The box (hit area) never changes. */
.theme-toggle::before,
.theme-toggle::after {
  -webkit-mask: linear-gradient(#000, #000) 0 0 / 0px 100% no-repeat;
  mask: linear-gradient(#000, #000) 0 0 / 0px 100% no-repeat;
  transition: -webkit-mask-size 160ms steps(4, start), mask-size 160ms steps(4, start);
}
html.dark-mode .theme-toggle::before,
html.dark-mode .theme-toggle::after {
  -webkit-mask-position: 100% 0;
  mask-position: 100% 0;
}
.theme-toggle:hover::before,
.theme-toggle:focus-visible::before,
html[data-pt-switch] .theme-toggle::before {
  -webkit-mask-size: 40px 100%;
  mask-size: 40px 100%;
}
.theme-toggle:hover::after,
.theme-toggle:focus-visible::after,
html[data-pt-switch] .theme-toggle::after {
  -webkit-mask-size: 36px 100%;
  mask-size: 36px 100%;
}

.theme-toggle:focus {
  outline: none;
}

/* Focus: four 2px pixel corner brackets, drawn only for keyboard focus. */
.theme-toggle:focus-visible {
  --b: var(--pt-ring);
  background-image:
    linear-gradient(var(--b), var(--b)), linear-gradient(var(--b), var(--b)),
    linear-gradient(var(--b), var(--b)), linear-gradient(var(--b), var(--b)),
    linear-gradient(var(--b), var(--b)), linear-gradient(var(--b), var(--b)),
    linear-gradient(var(--b), var(--b)), linear-gradient(var(--b), var(--b));
  background-size: 6px 2px, 2px 6px, 6px 2px, 2px 6px, 6px 2px, 2px 6px, 6px 2px, 2px 6px;
  background-position: 0 0, 0 0, 100% 0, 100% 0, 0 100%, 0 100%, 100% 100%, 100% 100%;
  animation: pt-lock 120ms steps(1, end) both;
}

/* Brackets lock on: two frames further out, then snap into place. */
@keyframes pt-lock {
  0%   { padding: 5px 1px; }
  50%  { padding: 6px 2px; }
  100% { padding: 7px 3px; }
}

/* Knob: 16px pixel circle, 2px inside the track. State is a whole-pixel left: 8px light, 24px dark. */
.theme-toggle .toggle-circle,
.theme-toggle .toggle-circle:hover {
  position: absolute;
  top: 12px;
  left: 8px;
  width: 16px;
  height: 16px;
  margin: 0;
  border-radius: 0;
  background-color: var(--pt-knob);
  transform: none;
  translate: 0 0;
  transition: none;
  clip-path: polygon(11px 0px, 11px 1px, 13px 1px, 13px 2px, 14px 2px, 14px 3px, 15px 3px, 15px 5px, 16px 5px, 16px 11px, 15px 11px, 15px 13px, 14px 13px, 14px 14px, 13px 14px, 13px 15px, 11px 15px, 11px 16px, 5px 16px, 5px 15px, 3px 15px, 3px 14px, 2px 14px, 2px 13px, 1px 13px, 1px 11px, 0px 11px, 0px 5px, 1px 5px, 1px 3px, 2px 3px, 2px 2px, 3px 2px, 3px 1px, 5px 1px, 5px 0px);
  z-index: 1;
}

html.dark-mode .theme-toggle .toggle-circle {
  left: 24px;
}

/* Glyph: one 10x10 sprite, centred with a 3px margin. */
.theme-toggle .toggle-circle::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 10px;
  height: 10px;
  background-color: var(--pt-glyph);
  -webkit-mask: var(--pt-g) 0 0 / 10px 10px no-repeat;
  mask: var(--pt-g) 0 0 / 10px 10px no-repeat;
  --pt-g: var(--pt-g-sun);
}

html.dark-mode .theme-toggle .toggle-circle::before {
  --pt-g: var(--pt-g-moon);
}

.theme-toggle .toggle-circle::after {
  content: none;
}

/* Hover: the knob leans 2px toward where it will go (2 frames), and the glyph idles:
   the sun's rays flicker, the moon's star twinkles. */
html.pt-ready .theme-toggle:not([data-pt-fresh]):hover .toggle-circle {
  translate: 2px 0;
  transition: translate 80ms steps(2, end);
}

html.pt-ready.dark-mode .theme-toggle:not([data-pt-fresh]):hover .toggle-circle {
  translate: -2px 0;
}

html.pt-ready:not([data-pt-switch]) .theme-toggle:hover .toggle-circle::before {
  animation: pt-idle-sun 960ms steps(1, end) infinite;
}

html.pt-ready.dark-mode:not([data-pt-switch]) .theme-toggle:hover .toggle-circle::before {
  animation-name: pt-idle-moon;
}

@keyframes pt-idle-sun {
  0%, 62.5% { -webkit-mask-image: var(--pt-g-sun); mask-image: var(--pt-g-sun); }
  75%, 100% { -webkit-mask-image: var(--pt-g-sun-burst); mask-image: var(--pt-g-sun-burst); }
}

@keyframes pt-idle-moon {
  0%, 62.5% { -webkit-mask-image: var(--pt-g-moon); mask-image: var(--pt-g-moon); }
  75%, 100% { -webkit-mask-image: var(--pt-g-moon-star); mask-image: var(--pt-g-moon-star); }
}

/* Press: the knob flattens to an 18px pill toward its travel direction. */
.theme-toggle:active .toggle-circle {
  width: 18px;
  clip-path: polygon(13px 0px, 13px 1px, 15px 1px, 15px 2px, 16px 2px, 16px 3px, 17px 3px, 17px 5px, 18px 5px, 18px 11px, 17px 11px, 17px 13px, 16px 13px, 16px 14px, 15px 14px, 15px 15px, 13px 15px, 13px 16px, 5px 16px, 5px 15px, 3px 15px, 3px 14px, 2px 14px, 2px 13px, 1px 13px, 1px 11px, 0px 11px, 0px 5px, 1px 5px, 1px 3px, 2px 3px, 2px 2px, 3px 2px, 3px 1px, 5px 1px, 5px 0px);
}

html.dark-mode .theme-toggle:active .toggle-circle {
  left: 22px;
}

.theme-toggle:active .toggle-circle::before {
  left: 4px;
}

/* The switch, 8 frames x 40ms. Values are the knob's left edge in px (track starts at 6px). */
html[data-pt-switch="to-dark"] .theme-toggle .toggle-circle {
  animation: pt-knob-dark 320ms steps(1, end) both;
}
html[data-pt-switch="to-dark"] .theme-toggle .toggle-circle::before {
  animation: pt-glyph-dark 320ms steps(1, end) both;
}
html[data-pt-switch="to-light"] .theme-toggle .toggle-circle {
  animation: pt-knob-light 320ms steps(1, end) both;
}
html[data-pt-switch="to-light"] .theme-toggle .toggle-circle::before {
  animation: pt-glyph-light 320ms steps(1, end) both;
}

@keyframes pt-knob-dark {
  0%    { left: 7px; }   /* wind-up */
  12.5% { left: 9px; }
  25%   { left: 12px; }
  37.5% { left: 16px; }
  50%   { left: 20px; }
  62.5% { left: 23px; }
  75%   { left: 25px; }  /* overshoot */
  87.5%, 100% { left: 24px; } /* settle */
}

@keyframes pt-knob-light {
  0%    { left: 25px; }
  12.5% { left: 23px; }
  25%   { left: 20px; }
  37.5% { left: 16px; }
  50%   { left: 12px; }
  62.5% { left: 9px; }
  75%   { left: 7px; }
  87.5%, 100% { left: 8px; }
}

@keyframes pt-glyph-dark {
  0%            { -webkit-mask-image: var(--pt-g-sun-tight); mask-image: var(--pt-g-sun-tight); } /* rays pull in */
  12.5%, 25%    { -webkit-mask-image: var(--pt-g-dot); mask-image: var(--pt-g-dot); }
  37.5%, 62.5%  { -webkit-mask-image: var(--pt-g-moon); mask-image: var(--pt-g-moon); }
  75%           { -webkit-mask-image: var(--pt-g-moon-star); mask-image: var(--pt-g-moon-star); } /* lands with a glint */
  87.5%, 100%   { -webkit-mask-image: var(--pt-g-moon); mask-image: var(--pt-g-moon); }
}

@keyframes pt-glyph-light {
  0%, 12.5%     { -webkit-mask-image: var(--pt-g-moon); mask-image: var(--pt-g-moon); }
  25%           { -webkit-mask-image: var(--pt-g-dot); mask-image: var(--pt-g-dot); }
  37.5%, 62.5%  { -webkit-mask-image: var(--pt-g-sun-tight); mask-image: var(--pt-g-sun-tight); }
  75%           { -webkit-mask-image: var(--pt-g-sun-burst); mask-image: var(--pt-g-sun-burst); } /* rays burst out on landing */
  87.5%, 100%   { -webkit-mask-image: var(--pt-g-sun); mask-image: var(--pt-g-sun); }
}

/* Page: the new theme pours down from the navbar in the same 8 frames. Above the
   edge it is solid new colour, below it the old page, and the edge is a 64px band of
   ordered dither (Bayer 4x4, 2px cells: 14/16, 10/16, 6/16, 2/16), so every pixel is
   either fully old or fully new and text outside the band stays readable.
   Band rows snap to a 16px grid. */
::view-transition-group(root) {
  animation-duration: 320ms;
}
::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
}
::view-transition-new(root) {
  -webkit-mask-image: linear-gradient(#000, #000), var(--pt-d-14), var(--pt-d-10), var(--pt-d-6), var(--pt-d-2);
  mask-image: linear-gradient(#000, #000), var(--pt-d-14), var(--pt-d-10), var(--pt-d-6), var(--pt-d-2);
  -webkit-mask-repeat: no-repeat, repeat-x, repeat-x, repeat-x, repeat-x;
  mask-repeat: no-repeat, repeat-x, repeat-x, repeat-x, repeat-x;
  animation: pt-pour 320ms steps(1, end) both;
}
@keyframes pt-pour {
  0% { -webkit-mask-size: 100% round(down, 100vh * 0, 16px), 8px 16px, 8px 16px, 8px 16px, 8px 16px; mask-size: 100% round(down, 100vh * 0, 16px), 8px 16px, 8px 16px, 8px 16px, 8px 16px;
    -webkit-mask-position: 0 0, 0 round(down, 100vh * 0, 16px), 0 calc(round(down, 100vh * 0, 16px) + 16px), 0 calc(round(down, 100vh * 0, 16px) + 32px), 0 calc(round(down, 100vh * 0, 16px) + 48px); mask-position: 0 0, 0 round(down, 100vh * 0, 16px), 0 calc(round(down, 100vh * 0, 16px) + 16px), 0 calc(round(down, 100vh * 0, 16px) + 32px), 0 calc(round(down, 100vh * 0, 16px) + 48px); }
  12.5% { -webkit-mask-size: 100% round(down, 100vh * 0.06, 16px), 8px 16px, 8px 16px, 8px 16px, 8px 16px; mask-size: 100% round(down, 100vh * 0.06, 16px), 8px 16px, 8px 16px, 8px 16px, 8px 16px;
    -webkit-mask-position: 0 0, 0 round(down, 100vh * 0.06, 16px), 0 calc(round(down, 100vh * 0.06, 16px) + 16px), 0 calc(round(down, 100vh * 0.06, 16px) + 32px), 0 calc(round(down, 100vh * 0.06, 16px) + 48px); mask-position: 0 0, 0 round(down, 100vh * 0.06, 16px), 0 calc(round(down, 100vh * 0.06, 16px) + 16px), 0 calc(round(down, 100vh * 0.06, 16px) + 32px), 0 calc(round(down, 100vh * 0.06, 16px) + 48px); }
  25% { -webkit-mask-size: 100% round(down, 100vh * 0.16, 16px), 8px 16px, 8px 16px, 8px 16px, 8px 16px; mask-size: 100% round(down, 100vh * 0.16, 16px), 8px 16px, 8px 16px, 8px 16px, 8px 16px;
    -webkit-mask-position: 0 0, 0 round(down, 100vh * 0.16, 16px), 0 calc(round(down, 100vh * 0.16, 16px) + 16px), 0 calc(round(down, 100vh * 0.16, 16px) + 32px), 0 calc(round(down, 100vh * 0.16, 16px) + 48px); mask-position: 0 0, 0 round(down, 100vh * 0.16, 16px), 0 calc(round(down, 100vh * 0.16, 16px) + 16px), 0 calc(round(down, 100vh * 0.16, 16px) + 32px), 0 calc(round(down, 100vh * 0.16, 16px) + 48px); }
  37.5% { -webkit-mask-size: 100% round(down, 100vh * 0.3, 16px), 8px 16px, 8px 16px, 8px 16px, 8px 16px; mask-size: 100% round(down, 100vh * 0.3, 16px), 8px 16px, 8px 16px, 8px 16px, 8px 16px;
    -webkit-mask-position: 0 0, 0 round(down, 100vh * 0.3, 16px), 0 calc(round(down, 100vh * 0.3, 16px) + 16px), 0 calc(round(down, 100vh * 0.3, 16px) + 32px), 0 calc(round(down, 100vh * 0.3, 16px) + 48px); mask-position: 0 0, 0 round(down, 100vh * 0.3, 16px), 0 calc(round(down, 100vh * 0.3, 16px) + 16px), 0 calc(round(down, 100vh * 0.3, 16px) + 32px), 0 calc(round(down, 100vh * 0.3, 16px) + 48px); }
  50% { -webkit-mask-size: 100% round(down, 100vh * 0.46, 16px), 8px 16px, 8px 16px, 8px 16px, 8px 16px; mask-size: 100% round(down, 100vh * 0.46, 16px), 8px 16px, 8px 16px, 8px 16px, 8px 16px;
    -webkit-mask-position: 0 0, 0 round(down, 100vh * 0.46, 16px), 0 calc(round(down, 100vh * 0.46, 16px) + 16px), 0 calc(round(down, 100vh * 0.46, 16px) + 32px), 0 calc(round(down, 100vh * 0.46, 16px) + 48px); mask-position: 0 0, 0 round(down, 100vh * 0.46, 16px), 0 calc(round(down, 100vh * 0.46, 16px) + 16px), 0 calc(round(down, 100vh * 0.46, 16px) + 32px), 0 calc(round(down, 100vh * 0.46, 16px) + 48px); }
  62.5% { -webkit-mask-size: 100% round(down, 100vh * 0.63, 16px), 8px 16px, 8px 16px, 8px 16px, 8px 16px; mask-size: 100% round(down, 100vh * 0.63, 16px), 8px 16px, 8px 16px, 8px 16px, 8px 16px;
    -webkit-mask-position: 0 0, 0 round(down, 100vh * 0.63, 16px), 0 calc(round(down, 100vh * 0.63, 16px) + 16px), 0 calc(round(down, 100vh * 0.63, 16px) + 32px), 0 calc(round(down, 100vh * 0.63, 16px) + 48px); mask-position: 0 0, 0 round(down, 100vh * 0.63, 16px), 0 calc(round(down, 100vh * 0.63, 16px) + 16px), 0 calc(round(down, 100vh * 0.63, 16px) + 32px), 0 calc(round(down, 100vh * 0.63, 16px) + 48px); }
  75% { -webkit-mask-size: 100% round(down, 100vh * 0.82, 16px), 8px 16px, 8px 16px, 8px 16px, 8px 16px; mask-size: 100% round(down, 100vh * 0.82, 16px), 8px 16px, 8px 16px, 8px 16px, 8px 16px;
    -webkit-mask-position: 0 0, 0 round(down, 100vh * 0.82, 16px), 0 calc(round(down, 100vh * 0.82, 16px) + 16px), 0 calc(round(down, 100vh * 0.82, 16px) + 32px), 0 calc(round(down, 100vh * 0.82, 16px) + 48px); mask-position: 0 0, 0 round(down, 100vh * 0.82, 16px), 0 calc(round(down, 100vh * 0.82, 16px) + 16px), 0 calc(round(down, 100vh * 0.82, 16px) + 32px), 0 calc(round(down, 100vh * 0.82, 16px) + 48px); }
  87.5%, 100% { -webkit-mask-image: none; mask-image: none; }
}

/* The toggle is lifted out of the dissolve: only its live, final state is shown. */
::view-transition-group(pt-toggle) {
  animation: none;
}
::view-transition-old(pt-toggle) {
  display: none;
}
::view-transition-new(pt-toggle) {
  animation: none;
}

/* While colours swap, nothing else may run its own colour transition. */
html.pt-switching *:not(.theme-toggle, .theme-toggle *),
html.pt-switching *:not(.theme-toggle *)::before,
html.pt-switching *:not(.theme-toggle *)::after {
  transition: none !important;
}

@media (prefers-reduced-motion: reduce) {
  .theme-toggle .toggle-circle,
  .theme-toggle .toggle-circle::before,
  .theme-toggle:focus-visible,
  .theme-toggle::before,
  .theme-toggle::after {
    animation: none !important;
    transition: none !important;
  }
  html.pt-ready .theme-toggle:hover .toggle-circle,
  html.pt-ready.dark-mode .theme-toggle:hover .toggle-circle {
    translate: 0 0;
  }
}
