/* The physical model's half in the sheet (ADR 0089; motion.js holds the springs). The curves below are
   sampled from real damped springs (unit mass; settle: stiffness 200, damping 22; lift: 140, 15), so
   what CSS moves feels like what the script moves. Under reduced motion nothing here moves. */
:root {
  --settle: linear(0, .03, .093, .182, .276, .38, .475, .57, .651, .727, .789, .844, .887, .924, .952, .974, .99, 1.002, 1.01, 1.015, 1.018, 1.019, 1.019, 1.018, 1.017, 1.015, 1.013, 1.011, 1.009, 1.007, 1.006, 1.005, 1.003, 1.003, 1.002, 1.001, 1.001, 1, 1, 1, 1);
  --lift: linear(0, .04, .133, .251, .387, .523, .65, .762, .856, .928, .986, 1.027, 1.054, 1.069, 1.075, 1.074, 1.068, 1.06, 1.05, 1.039, 1.03, 1.021, 1.014, 1.007, 1.002, .999, .997, .995, .995, .994, .995, .995, .996, .997, .997, .998, .999, .999, 1, 1, 1);
  --sv: 0; --glow: 0; --lx: 50vw; --ly: 30vh;
}

/* the light: a warm point, larger and fainter than a cursor, under the text and over the pictures */
.lamp { position: fixed; left: 0; top: 0; width: 46vmax; height: 46vmax; margin: -23vmax 0 0 -23vmax; pointer-events: none; z-index: 1;
  transform: translate3d(var(--lx), var(--ly), 0); opacity: calc(var(--glow) * .55); mix-blend-mode: soft-light;
  background: radial-gradient(closest-side, rgba(255,214,170,.55), rgba(255,140,90,.18) 38%, transparent 72%); }

/* a surface the light falls on carries a soft sheen where the pointer is */
.physics .lit { position: relative; }
.physics .lit::after { content: ""; position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .5s var(--settle);
  background: radial-gradient(circle at var(--mx, 50%) var(--my, 30%), rgba(255,236,214,.16), transparent 46%); mix-blend-mode: screen; }
.physics .lit:hover::after { opacity: 1; }

/* cards lean towards the light; their shadow falls away from it */
.physics .tilt { transform: perspective(1100px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)) translateY(calc(var(--up, 0) * -6px));
  box-shadow: calc(var(--ry, 0deg) / 1deg * -2px) calc(14px + var(--up, 0) * 22px) calc(30px + var(--up, 0) * 40px) rgba(0,0,0,calc(.25 + var(--up, 0) * .25));
  will-change: transform; }

/* chips follow the hand a little */
.physics .pulled { translate: var(--px, 0) var(--py, 0); }

/* arriving on screen: the rise of pages.css, on a spring and one beat apart */
.physics.js .rise { transform: translateY(34px) scale(.985); transition: opacity .5s ease-out var(--beat, 0ms), transform .95s var(--lift) var(--beat, 0ms); }
.physics.js .rise.in { transform: none; }

/* strips you can throw lean into the scroll and give at their ends */
.physics .throw { cursor: grab; }
.physics .throw.held { cursor: grabbing; scroll-snap-type: none; }
.physics .throw.held * { user-select: none; }
.physics .throw > * { translate: var(--give, 0) 0; }
.physics .lean { transform: skewY(calc(var(--sv) * -1.6deg)); transform-origin: 50% 50%; }

/* the page leads (ADR 0089). Where nothing in particular was pressed, the next page opens out of the
   point that was: light first, then the room. */
@view-transition { navigation: auto; }
::view-transition-old(root) { animation: dim-out .55s ease-in both; }
::view-transition-new(root) { animation: bloom .85s var(--settle) both; }
@keyframes dim-out { to { opacity: 0; filter: brightness(.5); } }
@keyframes bloom { from { clip-path: circle(0 at var(--ox, 50%) var(--oy, 35%)); filter: brightness(1.6); } to { clip-path: circle(150% at var(--ox, 50%) var(--oy, 35%)); filter: none; } }
/* a card becomes the page: its picture flies to the head and grows, the page settles in round it */
::view-transition-group(morph) { z-index: 40; animation-duration: .72s; animation-timing-function: var(--settle); }
::view-transition-image-pair(morph) { isolation: isolate; }
::view-transition-old(morph), ::view-transition-new(morph) { width: 100%; height: 100%; object-fit: cover; overflow: clip; }
::view-transition-old(morph) { animation: fade-out .26s ease-in both; }
::view-transition-new(morph) { animation: fade-in .5s ease-out .08s both; }
:root.vt-morph::view-transition-old(root) { animation: dim-out .5s ease-in both; }
:root.vt-morph::view-transition-new(root) { animation: settle-in .7s var(--settle) .12s both; }
/* back goes back: the page falls away and the one before comes forward, the picture into its card */
:root.vt-back::view-transition-old(root) { z-index: 2; animation: fall-away .3s ease-in both; }
:root.vt-back::view-transition-new(root) { animation: fade-in .45s ease-out both; }
:root.vt-back::view-transition-group(morph) { animation-duration: .6s; }
@keyframes fade-out { to { opacity: 0; } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes settle-in { from { opacity: 0; transform: translateY(26px) scale(.99); } }
@keyframes fall-away { to { opacity: 0; transform: scale(.965); filter: brightness(.6); } }
.top { view-transition-name: top; }
::view-transition-group(top) { animation: none; }
.where { view-transition-name: where; }
::view-transition-group(where) { animation-duration: .5s; animation-timing-function: var(--settle); }

/* where you are on the page: a hairline under the bar, the light point at its tip */
.physics .top::after { content: ""; position: absolute; left: 0; bottom: 0; height: 1px; width: 100%; pointer-events: none; transform-origin: 0 50%;
  transform: scaleX(var(--read, 0)); background: linear-gradient(90deg, rgba(244,242,238,0), rgba(244,242,238,.32)); }

/* the phone menu grows out of its button and falls back into it; its lines arrive one beat apart */
@media (max-width: 860px) {
  .physics.js .nav { display: flex; visibility: hidden; clip-path: circle(0 at var(--bx, 92%) var(--by, 40px));
    transition: clip-path .5s cubic-bezier(.5, 0, .75, 0), visibility 0s .5s; }
  .physics.js .nav.open { visibility: visible; clip-path: circle(160vmax at var(--bx, 92%) var(--by, 40px)); transition: clip-path .8s var(--settle), visibility 0s; }
  .physics.js .nav a { opacity: 0; translate: 0 22px; transition: opacity .2s, translate .2s; }
  .physics.js .nav.open a { opacity: 1; translate: 0 0; transition: opacity .45s ease-out calc(var(--i, 0) * 55ms + 140ms), translate .9s var(--lift) calc(var(--i, 0) * 55ms + 140ms); }
}

.still .tilt { transform: none; }
@media (prefers-reduced-motion: reduce) {
  @view-transition { navigation: none; }
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
  .lamp { display: none; }
}
