/* COET — the menu, and the flight into it.

   Ported from coet-site (src/lib/components/nav/MenuOverlay.svelte + MenuCanvas.svelte): press Menu and the page
   you are on flies out of the middle of the screen, into a ring of page previews wrapped onto a cylinder. The warp
   itself lives in assets/menu.js; this is the two-layer camera move and the chrome around it.

   THE FLIGHT IS TWO TRANSITIONS, NOT A REDRAW. The ring is drawn once, at rest, and the camera is a plain
   transform on that one frame:

     .shell   the live page — header excepted, so the bar stays put — shrinking from full bleed onto the card
     .ring    the canvas, starting blown up so its front panel sits exactly under the page, shrinking to rest

   Both transform about their own top-left and interpolate translate-then-scale, so the registration is exact at
   every frame rather than only at the ends. Writing F for the card's top-left and s for its scale, the page runs
   identity → translate(F) scale(s) and the ring runs translate(−F/s) scale(1/s) → identity; at progress e both put
   F at eF. The −F/s is algebra, not a tuned number. See menu.js's `measure()` for where F and s come from.

   What is NOT ported: coet-site flew a captured <img> of the page, because a Svelte route cannot be transformed out
   from under its own router. Here the flat layer is the REAL page, so the first frame registers by construction and
   there is no screenshot of the live page to keep in step with it. The ring's panels are still captures — of the
   destinations, not of the page you are on — and tools/capture-panels.sh shoots them.

   The base state of both layers is the flown-OUT one, which is both where an open starts and where a close ends, so
   one pair of rules runs the move in both directions: the base carries the close timing, `.is-in` the longer open. */

/* ── the bar's menu button ── */
/* Closed, the button is just the word "Menu": no burger. Open, an X folds in beside "Close", so the way out is
   marked and the way in is not. The icon's width and the gap it needs both collapse to nothing while closed. */
.mnav__menu { gap: 0; }
.mnav__burger { position: relative; display: block; width: 0; height: 9px; margin-right: 0; opacity: 0; overflow: hidden;
  transition: width .35s var(--ml-ease), margin-right .35s var(--ml-ease), opacity .2s; }
.mnav__burger i { position: absolute; left: 0; width: 12px; height: 1px; background: currentColor; transition: transform .45s var(--ml-ease); }
.mnav__burger i:first-child { top: 1px; transform: translateY(3px) rotate(45deg); }
.mnav__burger i:last-child { bottom: 1px; transform: translateY(-3px) rotate(-45deg); }
html.menu-open .mnav__burger { width: 12px; margin-right: 6px; opacity: 1; overflow: visible; }

/* open: the bar drops its glass and runs full width, even when it was compact from scrolling (`.mnav` is in the
   selector so this beats `.mnav.is-compact .mnav__bar`). Close wears the same fill and hover as the toggles on the
   right, so the bar reads as one set of buttons. */
html.menu-open .mnav .mnav__bar { max-width: 100%; padding: 0 12px; background: rgb(0 0 0 / 0) !important; box-shadow: none !important; backdrop-filter: none !important; -webkit-backdrop-filter: none !important; }
html.menu-open .mnav .mnav__bar::before { opacity: 0; }
html.menu-open .mnav .mnav__menu { background: rgb(255 255 255 / .14); }
html.menu-open .mnav .mnav__menu:hover { background: rgb(255 255 255 / .28); }

/* ── the page, flying out ── */
/* z-index, because the page is the layer ON TOP of the ring for the whole move: a ring fading up through a page
   fading out dips to the scrim in the middle and reads as a dissolve. Nothing fades up — the neighbours sweeping in
   from the gutters as the camera pulls back is the reveal. */
html.menu-open { overflow: hidden; }
html.menu-open .shell {
  position: relative; z-index: 75; pointer-events: none;
  /* The origin is the viewport's top-left in the page's own coordinates, and the clip is the viewport rect in the
     same: scaling a document that is ten screens tall would otherwise pull all ten into the card. Both are in px
     from menu.js, which is the only thing that knows the scroll offset. */
  transform-origin: 0 var(--fly-origin, 0px);
  clip-path: inset(var(--fly-top, 0px) 0 var(--fly-bottom, 0px) 0);
  will-change: transform, opacity;
  transition: transform 480ms var(--ml-ease), opacity 300ms var(--ml-ease);
}
html.menu-in .shell {
  transform: translate(var(--card-x, 0px), var(--card-y, 0px)) scale(var(--card-s, .4));
  opacity: 0;
  /* Held opaque nearly to the end: the card is a scale model of the viewport, so the page and the panel under it
     stay locked for the whole move, and fading early just shows the panel through a page that is still travelling. */
  transition: transform 620ms var(--ml-ease), opacity 220ms var(--ml-ease) 400ms;
}

/* ── the overlay ── */
.menu { position: fixed; inset: 0; z-index: 70; color: #fff; }
.menu[hidden] { display: none; }
.menu__scrim { position: absolute; inset: 0; background: #000; opacity: 0; transition: opacity 620ms var(--ml-ease); }
.menu.is-in .menu__scrim { opacity: 1; }
/* Dark mode's room is neutral-900. Light mode's is neutral-100 (#f5f5f5): it is set as #0a0a0a here because the
   page-wide flip inverts it. */
.menu__scrim { background: #171717; }
/* The backdrop field (menu.js): foreground-colour hairlines drawn on and wiped off top to bottom, behind the
   ring. Drawn white and NOT flipped back in light mode, so the page-wide flip makes them black there — the
   foreground in both themes. Their strength (24% at most) is in the canvas, so this layer only fades them in. */
.menu__field { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; opacity: 0;
  transition: opacity 900ms var(--ml-ease); }
.menu.is-in .menu__field { opacity: 1; }

.menu__ring {
  position: absolute; inset: 0; display: block; width: 100%; height: 100%;
  touch-action: none; cursor: grab;
  transform-origin: 0 0;
  transform: translate(var(--ring-x, 0px), var(--ring-y, 0px)) scale(var(--ring-s, 1));
  will-change: transform;
}
.menu__ring:active { cursor: grabbing; }
/* Armed only once the flight is about to start: before that the canvas is still measuring itself, and a card scale
   that lands after the first style recalc would transition the ring out of its start pose. */
.menu.is-flying .menu__ring { transition: transform 480ms var(--ml-ease); }
.menu.is-in .menu__ring { transform: translate(0px, 0px) scale(1); transition: transform 620ms var(--ml-ease); }

/* ── the dive: choosing a page ── */
/* The ring zooms until the chosen card fills the window, then the screen goes blank (the page background: black). The browser goes, and the next page opens under the
   same blank sheet (html.has-menu-cover, set in app.html before first paint). There a hairline draws a box — the
   old site's `frame` loading sequence: struck flat, blinks three times, turns a quarter circle, draws up, opens
   wide, all below the top bar — and once
   it has finished the sheet fades out over the real page (menu.js, uncover). */
.menu__dive { position: fixed; inset: 0; z-index: 2; background: var(--black); opacity: 0; pointer-events: none; transition: opacity 180ms linear; }
.menu__dive.is-on { opacity: 1; }
/* Diving, the page that was underneath stays gone: flying it back over the card it is not would be a lie. */
html.menu-dive .shell { transition: none; }
.menu.is-diving .menu__ring { transition: transform 560ms cubic-bezier(.65, 0, .25, 1); }

/* Layered just under the bar (z 80), which is on screen through the whole sequence. */
/* The box sits below the top bar (12px + 54px, plus any notch), so the bar stays clear through the whole sequence.
   --frame-mt / --frame-mb are the top and bottom insets that centre the mark in that box. */
html.has-menu-cover { --frame-mark: 24px; --frame-in: clamp(16px, 3vw, 40px); --frame-top: calc(82px + env(safe-area-inset-top, 0px));
  --frame-mt: calc(50% + var(--frame-top) / 2 - var(--frame-in) / 2 - var(--frame-mark) / 2);
  --frame-mb: calc(50% - var(--frame-top) / 2 + var(--frame-in) / 2 - var(--frame-mark) / 2);
  /* the flat mark's top and bottom insets: a 1px line through the same centre */
  --frame-hmt: calc(var(--frame-mt) + var(--frame-mark) / 2 - .5px);
  --frame-hmb: calc(var(--frame-mb) + var(--frame-mark) / 2 - .5px); }
html.has-menu-cover::before { content: ""; position: fixed; inset: 0; z-index: 79; pointer-events: none; background: var(--black); }
html.has-menu-cover::after { content: ""; position: fixed; z-index: 79; pointer-events: none; box-sizing: border-box;
  border: 1px solid var(--ink); border-radius: 1px; inset: var(--frame-top) var(--frame-in) var(--frame-in); opacity: 1;
  animation: menu-frame 1200ms linear 120ms backwards; }   /* backwards only: it ends on these base values, so the fade below can move them */
/* The sheet's fade (2026-11-14): an ease-in, so the page shows through slowly at first, with a slight tail at the
   end (the curve's last handle sits under 1), so the last of the sheet softens away rather than snapping off. */
html.has-menu-cover { --uncover-ease: cubic-bezier(.5, 0, .75, .9); }
html.has-menu-cover.is-uncovering::before, html.has-menu-cover.is-uncovering::after { opacity: 0; transition: opacity 600ms var(--uncover-ease); }
/* A jump (jump.js): the sheet slides up over the page, and on the far side fades out, frame and all, over the
   page it landed on. Same colour and layer as the cover, so the hand-over between them never shows. */
.jump { position: fixed; inset: 0; z-index: 79; background: var(--black); transform: translateY(100%); transition: transform 560ms cubic-bezier(.7, 0, .2, 1); }
.jump.is-in { transform: none; }
html.has-menu-cover[data-cover="slide"].is-uncovering::before, html.has-menu-cover[data-cover="slide"].is-uncovering::after {
  opacity: 0; transition: opacity 700ms var(--uncover-ease); }
/* The page's first line rises in as the sheet lifts. */
html.has-menu-cover main h1 { opacity: 0; transform: translateY(40px); }
html.has-menu-cover.is-uncovering main h1 { opacity: 1; transform: none;
  transition: opacity .8s cubic-bezier(.2, .7, .1, 1) .2s, transform 1s cubic-bezier(.2, .7, .1, 1) .2s; }

/* Each stop is a proportion of the 1200ms (2026-11-15: the quarter turn is back, from coet-site's `frame`). The
   mark is struck FLAT, a 24x1 hairline, and blinks three times; it turns a quarter circle to upright; it draws up
   to full height; then it opens wide into the frame. The loading clip lands on the flicker and on the opening, the
   second drawn out (datasound.js, LOAD_FLICKER / LOAD_WIDE), so keep those stops in step with it.
   The mark cannot stay rotated: every beat after the turn grows the box towards the screen's edges, and a rotated
   box grows towards the wrong two. So at 32% it blinks out, unwinds to 0 and transposes to 1x24 in the same step,
   pixel for pixel the same line, and is back at 33.5%. At full opacity a frame sampled inside that swap shows a
   small diagonal square; blinked out, the seam cannot be seen, and it reads as the mark locking on. */
@keyframes menu-frame {
  0%     { inset: var(--frame-hmt) calc(50% - var(--frame-mark) / 2) var(--frame-hmb); transform: rotate(0deg); opacity: 0; }
  1.5%   { opacity: 1; }
  4.5%   { opacity: .06; }
  7%     { opacity: 1; }
  10.5%  { opacity: .06; }
  12.5%  { opacity: 1; }
  16%    { inset: var(--frame-hmt) calc(50% - var(--frame-mark) / 2) var(--frame-hmb); transform: rotate(0deg); opacity: 1;
           animation-timing-function: cubic-bezier(.65, 0, .35, 1); }           /* the turn: in-out */
  31%    { inset: var(--frame-hmt) calc(50% - var(--frame-mark) / 2) var(--frame-hmb); transform: rotate(90deg); opacity: 1; }
  32%    { inset: var(--frame-hmt) calc(50% - var(--frame-mark) / 2) var(--frame-hmb); transform: rotate(90deg); opacity: 0; }
  32.6%  { inset: var(--frame-mt) calc(50% - .5px) var(--frame-mb); transform: rotate(0deg); opacity: 0; }
  33.5%  { inset: var(--frame-mt) calc(50% - .5px) var(--frame-mb); transform: rotate(0deg); opacity: 1;
           animation-timing-function: cubic-bezier(.55, 0, .9, .45); }          /* up: slow off the mark, fast to full height */
  57%    { inset: var(--frame-top) calc(50% - var(--frame-mark) / 2) var(--frame-in); transform: rotate(0deg); opacity: 1;
           animation-timing-function: cubic-bezier(.16, 1, .3, 1); }            /* wide: fast off the lines, slow into the frame */
  100%   { inset: var(--frame-top) var(--frame-in) var(--frame-in); transform: rotate(0deg); opacity: 1; }
}

/* ── the chrome: the real navigation, since the ring is decoration for pointer users ── */
/* It is there the moment the menu opens, with no fade or slide (2026-11-15). */
.menu__chrome { position: absolute; left: 0; right: 0; bottom: 0; display: flex; align-items: flex-end; justify-content: space-between; gap: 40px;
  padding: 0 var(--gutter) clamp(20px, 3vh, 36px); }

.menu__links { display: grid; gap: 0; justify-items: start; }
/* Orbitron, like the page titles the ring shows. It runs much wider than the body face, so it is set a step
   smaller to keep the column the same width. */
.menu__links a { font: 500 clamp(16px, 1.55vw, 22px)/1.5 "Orbitron", var(--apple); letter-spacing: 0; color: #fff; opacity: .55; transition: opacity .25s var(--ml-ease); }
.menu__links a:hover, .menu__links a:focus-visible, .menu__links a.is-aimed { opacity: 1; }

.menu__rail { max-width: min(52ch, 56vw); }
.menu__label { margin-bottom: 10px; color: var(--muted); text-align: right; }
.menu__pills { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; }
/* The same button MetaLab uses, and the same one the home pills are now cut from (metalab.css): 32px tall, 16px of
   padding, 16px type on a 50px radius over rgba(185,185,185,.2). The chip whose panel is squared up to the
   viewfinder fills in solid white — one treatment for "this is the one", in the menu and on the home stage both. */
.m-pill { position: relative; display: inline-flex; align-items: center; height: 32px; padding: 0 16px; border-radius: 50px;
  background: rgb(185 185 185 / .2); border: .1rem solid rgb(0 0 0 / 0); color: #fff; font: 400 16px/2 var(--apple); letter-spacing: -.01em;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); transform: none; opacity: 1;
  transition: background-color .25s var(--ml-ease), color .25s var(--ml-ease), border-color .25s var(--ml-ease); }
.m-pill:hover { background: rgb(185 185 185 / .3); }
.m-pill.is-aimed { background: #fff; border-color: #fff; color: #000; }

/* Between the two blocks rather than floating by the ring: it is an instruction about the control, so it belongs
   on the same line as the controls. */

.menu__links a:focus-visible, .m-pill:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }

/* ── phones: the links and the chips are the menu, and the ring is the picture above them ── */
@media (max-width: 900px) {
  .menu__chrome { flex-direction: column; align-items: stretch; gap: 18px; }
  .menu__rail { max-width: none; overflow-x: auto; scrollbar-width: none; }
  .menu__rail::-webkit-scrollbar { display: none; }
  .menu__label, .menu__pills { text-align: left; justify-content: flex-start; }
  .menu__pills { flex-wrap: nowrap; width: max-content; padding-bottom: 2px; }
  }

/* ── capture mode (tools/capture-panels.sh) ── */
/* The bar is hidden with `visibility`, never `display`: the panel has to be a picture of the page as it is laid
   out, and dropping the bar out of the flow would reflow anything that sits under it. The orb is parked on one
   still frame for the same reason a capture cannot hold motion. */
html.is-panel .mnav, html.is-panel .menu, html.is-panel .cursor { visibility: hidden; }
html.is-panel .orb__glow { display: none; }

@media (prefers-reduced-motion: reduce) {
  html.menu-open .shell, html.menu-in .shell, .menu__ring, .menu.is-in .menu__ring, .menu.is-flying .menu__ring, .menu__scrim, .menu__chrome, .menu.is-diving .menu__ring, html.has-menu-cover.is-uncovering::before, html.has-menu-cover.is-uncovering::after, html.has-menu-cover.is-uncovering main h1 { transition-duration: .01ms !important; }
  html.has-menu-cover::after { animation: none; }
  html.menu-in .shell { transform: none; }
  .menu__ring, .menu.is-in .menu__ring { transform: none; }
}

