/* The opening (laptop.js): in the dark, a laptop opens its lid on the desktop, and the first screen of scrolling
   brings its screen up to fill the window; the last pulls back out to it. Scoped to html.laptop, which only
   laptop.js sets, so without that script none of this applies. Our own drawing of a laptop, with no logo.
   laptop.js sets: --u, 1% of the laptop screen's width (the window on landscape screens; on portrait ones a
   landscape screen as tall as the window); --h, the laptop's height; the zoom's ends (below). --b is the bezel.
   The laptop is as tall as the large viewport (lvh), so a phone's toolbars growing and shrinking as it scrolls
   don't resize it. */

.laptop { --u: 1vw; --b: calc(1.6 * var(--u)); }
/* The zoom moves .zoom, a plain box around the 3D laptop. */
.laptop .zoom { position: fixed; inset: 0 0 auto; height: 100lvh; }
.laptop .device { position: absolute; inset: 0; transform-style: preserve-3d; perspective: 10000px; perspective-origin: 50% -20%; } /* far and a little high: the deck shows, without fanning out */
/* Portrait: the laptop's screen is landscape, as tall as the window and centred on it, so it overflows the sides. */
.laptop.portrait .zoom { left: calc(50vw - 50 * var(--u)); right: auto; width: calc(100 * var(--u)); }

/* The lid swings up on its hinge, the bezel's bottom edge. Its back is plain dark aluminium. */
.laptop .lid { position: absolute; inset: 0; transform-style: preserve-3d; transform-origin: 50% calc(100% + var(--b));
  transform: rotateX(-88deg); transition: transform 2.4s cubic-bezier(0.3, 0, 0.2, 1) 0.4s; }
.laptop.is-opening .lid { transform: rotateX(0deg); }
.laptop .bezel, .laptop .lid-back { position: absolute; inset: calc(-1 * var(--b)); border-radius: calc(var(--b) + 1.1 * var(--u)) calc(var(--b) + 1.1 * var(--u)) calc(0.5 * var(--u)) calc(0.5 * var(--u)); backface-visibility: hidden; } /* square at the hinge */
.laptop .bezel { background: #0c0c0e; box-shadow: 0 0 0 1px #2c2c31; }
.laptop .lid-back { background: linear-gradient(#36363c, #1d1d21); box-shadow: 0 0 0 1px #45454c; transform: translateZ(-1px) rotateY(180deg); }
.laptop .screen { position: absolute; inset: 0; overflow: hidden; border-radius: calc(1.1 * var(--u)) calc(1.1 * var(--u)) calc(0.4 * var(--u)) calc(0.4 * var(--u)); background: #000; backface-visibility: hidden; transform: translateZ(1px); }
.laptop .screen > .stage, .laptop .screen > .menubar, .laptop .screen > .dock { position: absolute; }
.laptop .notch { position: absolute; top: 0; left: 50%; width: calc(9 * var(--u)); height: 28px; border-radius: 0 0 9px 9px; background: #0c0c0e;
  transform: translateX(-50%) translateZ(2px); backface-visibility: hidden; } /* just in front of the screen */
/* The menu bar and Dock only show while the laptop does, there from the first moment like the notch, and fading
   with the zoom. */
.laptop .screen > .menubar, .laptop .screen > .dock { display: flex; }
/* Portrait: the screen plays its own landscape loops (laptop.js), and the full-window wallpaper behind the works
   fades in over the laptop only once the screen fills the window. */
.laptop .screen > .loop { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.laptop.portrait .stage { transition: none; }

/* The base: a deck lying back from the hinge toward you, with its keyboard and trackpad, and a thin front edge.
   Its back edge is exactly as wide as the lid, meeting the lid's bottom corners, and perspective widens it toward
   you, so from above it's a trapezoid. */
.laptop .deck, .laptop .front { position: absolute; left: calc(-1 * var(--b)); right: calc(-1 * var(--b)); top: calc(100% + var(--b)); }
.laptop .deck { height: calc(100% + 2 * var(--b)); transform-origin: top; transform: rotateX(90deg); border-radius: 0 0 calc(2 * var(--u)) calc(2 * var(--u));
  background: linear-gradient(#202024, #2a2a2f); box-shadow: inset 0 -1px 0 #4a4a52; }
/* The keys, as the gaps between them: a real laptop's layout, six rows 14.5 keys wide, each row offset like the real
   thing. The drawing's unit is a quarter of a key (58 × 24). In the five rows of letters, a row's gaps are the dashes
   of one thick line that starts at its first gap; the bottom row (space bar, arrows) is spelled out. */
.laptop .deck::before { content: ''; position: absolute; inset: 5% 11% 44%; border-radius: var(--u);
  background: #111114 url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 58 24' preserveAspectRatio='none' fill='none' stroke='%232a2a2f'><path stroke-width='.5' d='M0 4H58M0 8H58M0 12H58M0 16H58M0 20H58M50 22h4'/><path stroke-width='4' stroke-dasharray='.12 3.88' d='M5.94 2H55M3.94 6H53M5.94 10H55M6.94 14H52M8.94 18H50'/><path stroke-width='.12' d='M4 20v4M8 20v4M12 20v4M17 20v4M37 20v4M42 20v4M46 20v4M50 20v4M54 20v4'/></svg>") 0 0 / 100% 100%; }
.laptop .deck::after { content: ''; position: absolute; inset: 62% 32% 7%; border-radius: calc(1.4 * var(--u)); background: #26262b; box-shadow: inset 0 0 0 1px #34343a; }
.laptop .front { height: calc(1.6 * var(--u)); transform: translateZ(calc(var(--h, 100vh) + 2 * var(--b))); border-radius: 0 0 calc(1.6 * var(--u)) calc(1.6 * var(--u)) / 0 0 var(--u) var(--u);
  background: linear-gradient(#4a4a51, #232327 30%, #141416); }
.laptop .front::before { content: ''; position: absolute; top: 0; left: 50%; translate: -50% 0; width: 13%; height: 45%; border-radius: 0 0 var(--u) var(--u); background: #18181b; }

/* Words: the opening lines centre under the laptop, and the download screen's sit in the dark below it. */
.laptop .opening { left: 0; right: 0; bottom: 48px; align-items: center; text-align: center; }
.laptop .last { inset: auto 56px 44px; align-items: flex-end; }
@media (max-width: 699px) {
  .laptop .opening { left: 24px; right: 24px; }
  .laptop .last { inset: auto 24px 36px; align-items: stretch; }
}

/* The zoom: in over the first screen of scrolling, held, back out over the last. The scroll runs it, not a script,
   so the browser can run it off the main thread (Safari does from 26.4). Each element has one animation over every
   screen from the first to the last (--last + 1 of them): Safari 27.2 draws neither of two scroll animations of
   one property on one element (it computes them, and draws the element as if unanimated). Their keyframes depend
   on the number of screens, so laptop.js writes them: `laptop`, the laptop's scale and shift (--s0, --y0 and --x0
   at the start, --s1, --y1 and --x1 on the last screen); `frame`, the notch, menu bar and Dock fading with the
   zoom; `canvas`, on portrait screens, the full-window wallpaper taking over in the last fifth of the zoom in and
   handing back in the first fifth of the zoom out. */
.laptop .zoom, .laptop .notch, .laptop .screen > .menubar, .laptop .screen > .dock, .laptop.portrait .stage {
  animation-timeline: scroll(root); animation-fill-mode: both; animation-range: 0 calc((var(--last) + 1) * 100svh); }
.laptop .zoom { animation-name: laptop; }
.laptop .notch, .laptop .screen > .menubar, .laptop .screen > .dock { animation-name: frame; }
.laptop.portrait .stage { animation-name: canvas; }
/* The opening lines are gone a third of the way into the zoom, before it passes them (the curve is the smoothstep's
   first 38.7%, tripled). */
.laptop .opening { animation: fade-out both cubic-bezier(0.333, 0, 0.667, 0.449); animation-timeline: scroll(root); animation-range: 0 38.7svh; }
@keyframes fade-out { from { opacity: 1; } to { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .laptop .lid { transition: none; }
  /* A swap halfway through the screen, not a fade (laptop.js swaps the rest). */
  .laptop .opening { animation-timing-function: steps(2, jump-none); animation-range: 0 100svh; }
}
