/* The page snapshots and the neighboring previews sit on one plane. The controls and CRT live
   in their own groups above it. */
@media screen {
  :root {
    --portfolio-artboard-sky: radial-gradient(circle, color-mix(in srgb, var(--accent) 42%, transparent) 1px, transparent 2px), radial-gradient(circle, color-mix(in srgb, var(--accent) 30%, transparent) .85px, transparent 1.6px), radial-gradient(circle, color-mix(in srgb, var(--accent) 16%, transparent) .8px, transparent 1.15px);
  }
  html[data-route-canvas] {
    --route-board-zoom: .33;
    --route-board-depth: perspective(clamp(660px, 105vmax, 1800px));
    --route-pan-x: calc(var(--route-camera-to-x) - var(--route-camera-from-x));
    --route-pan-y: calc(var(--route-camera-to-y) - var(--route-camera-from-y));
    --route-arc-x: clamp(-42px, calc(var(--route-board-y) * -.065), 42px);
    --route-arc-y: clamp(-42px, calc(var(--route-board-x) * .055), 42px);
    --route-plane-bleed-x: 155vw;
    --route-plane-bleed-y: 155vh;
    --route-plane-source-x: calc(var(--route-plane-bleed-x) - min(0px, var(--route-board-x)));
    --route-plane-source-y: calc(var(--route-plane-bleed-y) - min(0px, var(--route-board-y)));
    --route-plane-extra-width: calc(2 * var(--route-plane-bleed-x) + max(var(--route-board-x), calc(-1 * var(--route-board-x))));
    --route-plane-extra-height: calc(2 * var(--route-plane-bleed-y) + max(var(--route-board-y), calc(-1 * var(--route-board-y))));
    --route-board-sky: var(--portfolio-artboard-sky);
    view-transition-name: root !important;
  }
  html[data-route-canvas] .site-header { transition: none !important; }
  /* Capture the controls without the moving page sampled into their glass. */
  html[data-route-canvas]:not([data-route-canvas-fallback]) :is(.site-header, .case-menu, .guide-launcher) {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  html[data-route-canvas]::view-transition {
    background-color: var(--bg);
    overflow: clip;
  }
  html[data-route-canvas][data-route-controls]::view-transition-group(root) {
    inset: 0;
    z-index: 0;
    animation: portfolio-artboard-plane var(--route-board-duration, 860ms) linear both;
    transform-origin: center;
    overflow: visible;
  }
  html[data-route-canvas]::view-transition-image-pair(root) {
    --route-grid-origin-x: calc(var(--route-plane-source-x) + var(--route-grid-offset-x, 0px));
    --route-grid-origin-y: calc(var(--route-plane-source-y) + var(--route-grid-offset-y, 0px));
    isolation: isolate;
    overflow: visible;
    inset: auto;
    left: calc(-1 * var(--route-plane-source-x));
    top: calc(-1 * var(--route-plane-source-y));
    width: calc(100% + var(--route-plane-extra-width));
    height: calc(100% + var(--route-plane-extra-height));
    background-color: var(--bg);
    background-image: var(--route-grid-outline, none), var(--route-grid-image, none), var(--route-board-sky);
    background-size:
      var(--route-grid-width, 0px) var(--route-grid-height, 0px),
      var(--route-grid-width, 0px) var(--route-grid-height, 0px),
      196px 154px, 322px 238px, 14px 14px;
    background-position:
      var(--route-grid-origin-x) var(--route-grid-origin-y),
      var(--route-grid-origin-x) var(--route-grid-origin-y),
      calc(var(--route-grid-origin-x) + 56px) calc(var(--route-grid-origin-y) + 84px),
      calc(var(--route-grid-origin-x) + 140px) calc(var(--route-grid-origin-y) + 42px),
      var(--route-grid-origin-x) var(--route-grid-origin-y);
    background-repeat: no-repeat, no-repeat, repeat, repeat, repeat;
  }
  /* On theme-preview exits, one viewport-sized layer blends the sky behind
     both boards. The atlas and camera keep their normal geometry and timing. */
  html[data-route-canvas][data-route-palette]::view-transition {
    animation: portfolio-route-palette var(--route-board-duration, 860ms) ease-in-out both;
  }
  html[data-route-canvas][data-route-palette]::view-transition-image-pair(root) {
    background-color: transparent;
  }
  html[data-route-canvas]::view-transition-old(root),
  html[data-route-canvas]::view-transition-new(root) {
    inset: auto;
    width: calc(100% - var(--route-plane-extra-width));
    height: calc(100% - var(--route-plane-extra-height));
    max-inline-size: none;
    object-fit: cover;
    transform: scale(var(--route-board-scale));
    transform-origin: top left;
    opacity: 1;
    mix-blend-mode: normal;
    animation: none;
    box-shadow: 0 14px 32px rgb(0 0 0 / .14);
  }
  html[data-route-canvas]::view-transition-old(root) {
    --route-board-scale: var(--route-board-source-scale);
    left: var(--route-plane-source-x);
    top: var(--route-plane-source-y);
  }
  html[data-route-canvas]::view-transition-new(root) {
    --route-board-scale: var(--route-board-destination-scale);
    left: calc(var(--route-plane-source-x) + var(--route-board-x));
    top: calc(var(--route-plane-source-y) + var(--route-board-y));
  }

  html[data-route-canvas]::view-transition-group(route-header) {
    animation-duration: 460ms;
    animation-timing-function: cubic-bezier(.2, 0, .2, 1);
  }
  html[data-route-canvas]::view-transition-old(route-header) { display: none; }
  html[data-route-canvas]::view-transition-new(route-header) {
    animation: none;
    mix-blend-mode: normal;
  }
  html[data-route-canvas]::view-transition-old(route-header):only-child {
    display: block;
    mix-blend-mode: normal;
    animation: portfolio-route-header-leave 460ms ease-in-out both;
  }
  html[data-route-canvas]::view-transition-new(route-header):only-child {
    animation: portfolio-route-header-arrive 460ms ease-in-out both;
  }
  html[data-route-canvas]::view-transition-group(route-header) { z-index: 10; }
  html[data-route-canvas]::view-transition-group(route-nav-work),
  html[data-route-canvas]::view-transition-group(route-nav-outside),
  html[data-route-canvas]::view-transition-group(route-nav-about),
  html[data-route-canvas]::view-transition-group(route-menu),
  html[data-route-canvas]::view-transition-group(route-ask) { z-index: 20; }
  html[data-route-canvas]::view-transition-group(route-nav-label-work),
  html[data-route-canvas]::view-transition-group(route-nav-label-outside),
  html[data-route-canvas]::view-transition-group(route-nav-label-about) { z-index: 21; }
  /* Let the captured surfaces change size, while their contents stay
     centred and never grow larger than their original typography. */
  html[data-route-canvas]::view-transition-old(route-nav-work),
  html[data-route-canvas]::view-transition-new(route-nav-work),
  html[data-route-canvas]::view-transition-old(route-nav-outside),
  html[data-route-canvas]::view-transition-new(route-nav-outside),
  html[data-route-canvas]::view-transition-old(route-nav-about),
  html[data-route-canvas]::view-transition-new(route-nav-about),
  html[data-route-canvas]::view-transition-old(route-nav-label-work),
  html[data-route-canvas]::view-transition-new(route-nav-label-work),
  html[data-route-canvas]::view-transition-old(route-nav-label-outside),
  html[data-route-canvas]::view-transition-new(route-nav-label-outside),
  html[data-route-canvas]::view-transition-old(route-nav-label-about),
  html[data-route-canvas]::view-transition-new(route-nav-label-about),
  html[data-route-canvas]::view-transition-old(route-menu),
  html[data-route-canvas]::view-transition-new(route-menu) {
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: scale-down;
    object-position: center;
  }
  html[data-route-canvas]::view-transition-group(route-submenu) {
    z-index: 30;
    pointer-events: none;
    animation: none;
  }
  html[data-route-canvas]::view-transition-old(route-submenu) {
    display: block;
    mix-blend-mode: normal;
    animation: portfolio-route-submenu-leave var(--route-board-duration, 860ms) ease-in-out both;
  }
  html[data-route-canvas]::view-transition-new(route-submenu) {
    mix-blend-mode: normal;
    animation: portfolio-route-submenu-arrive var(--route-board-duration, 860ms) ease-in-out both;
  }
  /* Capture the complete CRT above the artboards. Sampling filters would
     otherwise pull fragments of the page into the screen's own snapshot. */
  html[data-route-canvas]:not([data-route-canvas-fallback]) body > .crt-screen { view-transition-name: route-crt; }
  html[data-route-canvas]:not([data-route-canvas-fallback]) body > .crt-screen > .crt-glass { view-transition-name: none; }
  html[data-route-canvas]:not([data-route-canvas-fallback]) body > .crt-mobile-roll { view-transition-name: route-crt-roll; }
  html[data-route-canvas]:not([data-route-canvas-fallback]) body > .crt-screen :is(.crt-edge),
  html[data-route-canvas]:not([data-route-canvas-fallback]) body > .crt-screen::after {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  html[data-route-canvas]::view-transition-old(route-crt),
  html[data-route-canvas]::view-transition-old(route-crt-roll) { display: none; }
  html[data-route-canvas]::view-transition-new(route-crt),
  html[data-route-canvas]::view-transition-new(route-crt-roll) { animation: none; mix-blend-mode: normal; }
  html[data-route-canvas]::view-transition-group(route-crt),
  html[data-route-canvas]::view-transition-group(route-crt-roll) {
    z-index: 100;
    pointer-events: none;
    animation: none;
  }

  /* The fade fallback keeps the controls and CRT outside the fading content. */
  html[data-route-canvas-fallback]::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background-color: var(--bg);
    background-image: var(--route-board-sky);
    background-size: 196px 154px, 322px 238px, 14px 14px;
    background-position: 56px 84px, 140px 42px, center;
  }
  html[data-route-canvas-fallback] .guide-page > :is(main, footer) {
    position: relative;
    z-index: 1;
  }
}

@keyframes portfolio-route-palette {
  0%, 9% { background-color: var(--route-board-source-bg, var(--bg)); }
  55%, 100% { background-color: var(--bg); }
}
@keyframes portfolio-route-header-leave {
  0%, 8% { opacity: 1; }
  78%, 100% { opacity: 0; }
}
@keyframes portfolio-route-header-arrive {
  0%, 15% { opacity: 0; }
  86%, 100% { opacity: 1; }
}
@keyframes portfolio-route-submenu-arrive {
  0%, 30% { opacity: 0; }
  80%, 100% { opacity: 1; }
}
@keyframes portfolio-route-submenu-leave {
  0%, 18% { opacity: 1; }
  66%, 100% { opacity: 0; }
}

/* Move in the plane's coordinates and tilt about the viewport centre.
   Each endpoint offsets its board's position and restores full-size content. */
@keyframes portfolio-artboard-plane {
  0% {
    transform: var(--route-board-depth) rotateX(0) rotateY(0) rotateZ(0)
      scale(calc(1 / var(--route-board-source-scale)))
      translate3d(var(--route-camera-from-x), var(--route-camera-from-y), 0);
    animation-timing-function: ease-out;
  }
  9% {
    transform: var(--route-board-depth) rotateX(0) rotateY(0) rotateZ(0)
      scale(calc(.982 / var(--route-board-source-scale)))
      translate3d(var(--route-camera-from-x), calc(var(--route-camera-from-y) + 3px), 0);
    animation-timing-function: cubic-bezier(.24, .12, .46, .75);
  }
  17% {
    transform: var(--route-board-depth)
      rotateX(calc(var(--route-board-pitch) * .13))
      rotateY(calc(var(--route-board-yaw) * -.13))
      rotateZ(calc(var(--route-board-roll) * -.13)) scale(calc(1.006 / var(--route-board-source-scale)))
      translate3d(
        calc(var(--route-camera-from-x) + var(--route-pan-x) * .018),
        calc(var(--route-camera-from-y) + var(--route-pan-y) * .018), 0);
    animation-timing-function: cubic-bezier(.36, .10, .70, .58);
  }
  43% {
    transform: var(--route-board-depth)
      rotateX(calc(var(--route-board-pitch) * .87))
      rotateY(calc(var(--route-board-yaw) * -.87))
      rotateZ(calc(var(--route-board-roll) * -.92)) scale(var(--route-board-zoom))
      translate3d(
        calc(var(--route-camera-from-x) + var(--route-pan-x) * .36 + var(--route-arc-x)),
        calc(var(--route-camera-from-y) + var(--route-pan-y) * .36 + var(--route-arc-y)), 0);
  }
  62% {
    transform: var(--route-board-depth)
      rotateX(calc(var(--route-board-pitch) * .74))
      rotateY(calc(var(--route-board-yaw) * -.74))
      rotateZ(calc(var(--route-board-roll) * -.64)) scale(calc(var(--route-board-zoom) + .055))
      translate3d(
        calc(var(--route-camera-from-x) + var(--route-pan-x) * .72 + var(--route-arc-x) * .60),
        calc(var(--route-camera-from-y) + var(--route-pan-y) * .72 + var(--route-arc-y) * .60), 0);
    animation-timing-function: cubic-bezier(.24, .40, .62, 1);
  }
  89% {
    transform: var(--route-board-depth)
      rotateX(calc(var(--route-board-pitch) * -.025))
      rotateY(calc(var(--route-board-yaw) * .025))
      rotateZ(calc(var(--route-board-roll) * .03)) scale(calc(1.007 / var(--route-board-destination-scale)))
      translate3d(
        calc(var(--route-camera-to-x) + var(--route-pan-x) * .005),
        calc(var(--route-camera-to-y) + var(--route-pan-y) * .005), 0);
    animation-timing-function: ease-in-out;
  }
  100% {
    transform: var(--route-board-depth) rotateX(0) rotateY(0) rotateZ(0)
      scale(calc(1 / var(--route-board-destination-scale)))
      translate3d(var(--route-camera-to-x), var(--route-camera-to-y), 0);
  }
}

@media screen and (max-width: 720px) {
  html[data-route-canvas] {
    --route-board-zoom: .36;
    --route-arc-x: clamp(-24px, calc(var(--route-board-y) * -.045), 24px);
    --route-arc-y: clamp(-24px, calc(var(--route-board-x) * .045), 24px);
  }
}
@media (prefers-reduced-motion: reduce) {
  html[data-route-canvas]::view-transition-old(root) { display: none; }
  html[data-route-canvas]::view-transition-old(route-submenu) { display: none; }
  html[data-route-canvas]::view-transition-new(route-submenu) { animation: none; opacity: 1; }
  html[data-route-canvas]::view-transition-group(root) {
    animation: none !important;
    transform: scale(calc(1 / var(--route-board-destination-scale)))
      translate3d(var(--route-camera-to-x), var(--route-camera-to-y), 0);
  }
  html[data-route-canvas-fallback]::before { display: none; }
  html[data-route-canvas-fallback] .guide-page > :is(main, footer) {
    opacity: 1 !important;
  }
}
