/* Mechanism: the button and the cards (section #mechanism, a film drawn by popup.js).

   A short title, and under it the film, as wide as the window and as high as
   the screen less the title. There is room between the opening and the title,
   and between the title and the film (see "The room round the title"). The
   film is a live 3D picture that popup.js draws and plays by the clock (the
   button slides down, a cut, the cards rise, a cut, and again). Scrolling
   drives nothing here: it simply moves the page past.
   Where the film cannot run (no script, no WebGL, the model failed to load) a
   still picture stands in its place.
   The title's block (.popup-intro) can be taken out of the page as it is: the
   film then takes the whole screen, and its upper fade covers the navigation.
   .popup-frame is invisible: it marks where the subject sits, and popup.js
   places the camera by it. */

.popup {
  /* Where the picture melts into the page. popup.js draws the fades into the
     picture itself, by a curve that is level at both ends, so that none begins
     or ends in a line; these say where they lie. (There is none at the sides:
     the picture is as wide as the window. On a window lower than 1080 px the
     button's scene has shorter ones: see the end of this file.) */
  --popup-top: 140px;                      /* the upper fade runs from the picture's top edge down to here */
  --popup-low: 216px;                      /* the lower fade is this long (a short one over bright gold shows as a band) ... */
  --popup-low-end: 0px;                    /* ... and is over this far above the picture's bottom edge */
  /* How far the subject keeps from the picture's left and right edges. */
  --popup-side: 3%;
  --popup-edge: 3%;
  /* The room round the title (see below). */
  --popup-above: clamp(32px, 10vh, 140px);      /* between the opening and the title: the section's margin */
  --popup-below: clamp(16px, 4.5vh, 64px);      /* between the title and the film: the title block's margin, and the section is that much taller */
  position: relative;
  display: flex; flex-direction: column;
  margin-top: var(--popup-above);
  min-height: calc(100vh + var(--popup-below));
  background: var(--bg);
}
@supports (height: 100svh) {
  .popup { min-height: calc(100svh + var(--popup-below)); }
}

/* ---------- The title: above the film, centred, modest ---------- */
.popup-intro {
  flex: none;
  padding: 80px var(--gutter) 8px;      /* (its top keeps clear of the navigation; it is kept low, because the film takes what it leaves of the screen) */
  margin-bottom: var(--popup-below);
  text-align: center;
}
.popup-intro .eyebrow { margin: 0 0 6px; padding-left: var(--tracking-wide); }      /* (the padding balances the space after the last letter) */
.popup-title {
  margin: 0;
  font-size: clamp(26px, 3vw, 38px);
  font-weight: 300;
  line-height: 1.1;
  letter-spacing: -0.01em;
  white-space: nowrap;      /* one line on every screen */
}
.popup-title strong { font-weight: 600; }

/* ---------- The room round the title ----------
   The owner, 24 Nov: "increase the spacing between the eclipse at the
   beginning and the mechanism writing, and then also the space after the
   writing and the video". Both grow with the window's height: on his window
   (1230 px high) 123 and 55 px. An upright window (a phone) gets less room
   above, and a phone held sideways no room under the title at all (see the
   end of the file).
   Above the title the room lies outside the section, between the opening and
   it. Discover and the menu's "Mechanism" glide to the section's top, so they
   land as before, with the title under the navigation (MECHANISM 4 px under
   its lower edge on a wide window) and the film under the title. On his window
   the eclipse's ring now ends 418 px above MECHANISM (295 before).
   Under the title the section grows by the room it adds: the film keeps its
   height (the screen less the title, 155 px on a wide window), and with it its
   framing and how close it comes, which popup.js works out from the free area
   (.popup-frame). On his window the picture now begins 63 px under the title
   line (8 before); where Discover lands, the last 55 px of its lower fade then
   lie below the window (the picture is at 13% of its strength where the window
   cuts it).
   The 100svh line has a rule of its own: a declaration that uses var() is
   only checked when it is used, so in the same rule it would no longer leave
   the 100vh line for a browser that does not know svh. And where round() is
   known the room is taken in whole pixels, so that everything under it, the
   film's picture too, stands on the same fraction of a pixel as before. */
@supports (width: round(1.5px, 1px)) {
  .popup { margin-top: round(var(--popup-above), 1px); min-height: calc(100svh + round(var(--popup-below), 1px)); }
  .popup-intro { margin-bottom: round(var(--popup-below), 1px); }
}
/* With the title taken out there is no room under it: the film takes the whole
   screen, as before. (A browser without :has() drops only this rule.) */
.popup:not(:has(> .popup-intro)) { min-height: 100vh; min-height: 100svh; }

/* ---------- The film ---------- */
/* It takes whatever height the title leaves of the screen. On a window too low
   for that to be a picture (a phone held sideways) it keeps a least height,
   and the section is then a little taller than the screen. */
.popup-visual { position: relative; flex: 1 1 0; min-height: 340px; overflow: hidden; overflow: clip; }
/* (With no title above it the film starts at the top of the screen, under the
   navigation, whose frosted bar reaches 110 px down on a wide window and 98 on
   a narrow one: the unfaded picture begins below that. The upper fade is only
   ever made shorter where the title stands above the film.) */
.popup-canvas, .popup-still { position: absolute; inset: 0; width: 100%; height: 100%; max-width: none; }
/* How strong the picture is (up from black, the dips at the cuts) is the film's
   own business: popup.js sets the canvas's opacity picture by picture, so
   nothing here may ease it. */
.popup-canvas { display: none; opacity: 0; pointer-events: none; }
.popup-still { object-fit: contain; object-position: 50% 30%; }      /* (on a tall box, a phone's, the still stands nearer the title than the box's foot) */
.popup[data-gl] .popup-canvas { display: block; }
.popup[data-gl] .popup-still { display: none; }
/* The free area: the part of the picture that is not faded, less 8 px. (A fade
   is 97% of the way to full strength 0.8775 of its length from where it begins.) */
.popup-frame {
  position: absolute; visibility: hidden; pointer-events: none;
  top: calc(var(--popup-top) * 0.8775 + 8px);
  right: var(--popup-edge);
  bottom: calc(var(--popup-low-end) + var(--popup-low) * 0.8775 + 8px);
  left: var(--popup-side);
}
/* The cards' scene shows the wallet from wall to wall: it may come closer to the
   sides. And nothing bright lies under its upper fade until the cards have
   risen to it (in the button's scene the gold wallet runs through it): there
   the fade is short, so that the cards may stand higher and larger. */
.popup[data-scene="rise"] { --popup-side: 2.5%; --popup-edge: 2.5%; }
.popup[data-scene="rise"] .popup-intro + .popup-visual { --popup-top: 64px; }

.popup-loading {
  position: absolute; left: 50%; top: 46%; translate: -50% -50%;
  margin: 0; padding-bottom: 14px; color: var(--text-muted);
}
.popup-loading::after {
  content: ""; position: absolute; left: 50%; bottom: 0; width: 56px; height: 1px; margin-left: -28px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  background-size: 200% 100%;
  animation: popup-wait 2.8s var(--ease-in-out) infinite;
}
.popup-loading[hidden] { display: none; }
@keyframes popup-wait { from { background-position: 100% 0; } to { background-position: -100% 0; } }
@media (prefers-reduced-motion: reduce) {
  .popup-loading::after { animation: none; background-size: 100% 100%; }
}

@media (max-width: 820px), (max-aspect-ratio: 4/5) {
  /* Phones: a smaller title, and the picture comes nearer the screen's edges. */
  .popup { --popup-top: 96px; --popup-side: 16px; --popup-edge: 16px; }
  .popup[data-scene="rise"] { --popup-side: 6px; --popup-edge: 8px; }
  .popup-visual:first-child { --popup-top: 104px; }
  .popup-title { font-size: clamp(24px, 7.2vw, 30px); }
}
@media (max-aspect-ratio: 4/5) {
  /* An upright window (a phone, a tablet held upright): the room above the
     title grows by half as much as on a wide window. Here the eclipse is
     smaller and stands higher (hero.css, the same test), and the opening
     already ends in a long stretch of black: on 390 x 844 the ring ended 355 px
     above MECHANISM, 42% of the screen, against 24% on the owner's window.
     With 10vh it became 439 px, more than half the screen, and read as an empty
     screen; with 5vh it is 397. */
  .popup { --popup-above: clamp(24px, 5vh, 72px); }
}
@media (max-height: 520px) {
  /* A phone held sideways: everything is shorter. No room is added under the
     title: the title and the film are taller than the screen here. Where
     Discover lands (844 x 390) the free area ends 4 px above the window's foot;
     in the button's scene popup.js ends it 20 px above instead (`foot` in its
     SHOTS), and at the end of its way the button ends 29.5 px above the
     window's foot, its shadow 21. Room under the title (18 px there) would
     now make the button smaller rather than push it off the screen: 7.8 px a
     millimetre in the middle of its way instead of 8.7, the cap still 28.5 px
     above the window's foot. On a phone 360 px high, where the button is
     already held at its least size, the same room would take the end of its
     way down to 2 px above the window's foot (18 now). */
  .popup { --popup-top: 76px; --popup-low: 72px; --popup-below: 0px; }
  .popup[data-scene="rise"] .popup-intro + .popup-visual { --popup-top: 48px; }
  .popup-visual:first-child { --popup-top: 116px; }
  .popup-intro { padding: 62px var(--gutter) 8px; }
  .popup-intro .eyebrow { margin-bottom: 2px; }
  .popup-title { font-size: 24px; }
}
/* A laptop's window, lower than 1080 px. The button's scene fits the same
   stretch of the wallet (about 21 mm) into the free area, so how close it comes
   depends on what the title and the fades leave of the screen. Fades of a fixed
   length took half of a low picture (48% of it on 1440 x 900, 58% on 1366 x 768,
   against 33% on the owner's window), and there the close-up came out little
   closer than the scroll animation had been: on 1440 x 900 one millimetre at the
   button measured 20.3 px where it had been 15.9, on 1366 x 768 13.8 where it had
   been 13.2, and the whole front of the wallet was in the picture. So here the
   fades of the button's scene shrink with the picture's height (the picture is
   the window less the title's 155 px): as long as above on a window 1080 px high
   and higher, a little shorter for every pixel less. Their curve stays the same,
   level at both ends. 1440 x 900 then got 23.2 px a millimetre and 1366 x 768
   19.0 (the shot of 23 Nov, from the front at a slant). Since 24 Nov the
   button's scene looks at the side wall nearly square on, with the camera
   still: the wallet is then a gold column with dark either side of it on every
   window, and in the middle of the button's way 1440 x 900 gets 22.4 px a
   millimetre and 1366 x 768 18.3.
   Not where the film stands without the title (its upper fade must then reach
   below the navigation), not on a phone, and not in the cards' scene, whose
   framing is its own (the still picture and the picture for shared links show
   it). The scene changes while the picture is black, so the change of the
   fades' length at the cut is never seen. */
@media (min-width: 821px) and (min-aspect-ratio: 801/1000) and (min-height: 521px) {
  .popup[data-scene="press"] .popup-intro + .popup-visual {
    --popup-top: clamp(76px, calc((100vh - 155px) * 0.15136), 140px);      /* 140 px over a picture 925 px high (140 / 925, rounded up so that 1080 gets 140 exactly) */
    --popup-low: clamp(72px, calc((100vh - 155px) * 0.23352), 216px);      /* 216 / 925, likewise */
  }
}
