/* ==========================================================================
   The Aporia — the landing page: the knot. CONTRACTS.md §18.

   Two layouts share this file. The plain one (no script, no WebGL, or the
   script failing) is the still of the knot with the menu round it, laid out
   here. The live one (html.live) is placed by js/knot/main.js every frame;
   here it only gets its type and colour.

   The canvas is sized to the LARGE viewport (lvh) and the words to the SMALL
   one (svh): a phone's toolbar sliding away never resizes the canvas, and never
   puts a word under the toolbar.
   ========================================================================== */

:root {
  --night: #08080b;
  --ink: rgb(244, 241, 234);
  --ink-soft: rgba(244, 241, 234, 0.62);
  --ink-faint: rgba(244, 241, 234, 0.36);
  --gold: rgb(226, 176, 112);
  --didone: "Bodoni Moda", "Bodoni 72", Didot, "Times New Roman", serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
  --gutter: clamp(1.1rem, 3.4vw, 3.6rem);
  --lobe: 1.6rem;
  /* the tied knot, edge to edge: the same sum as size() in js/knot/main.js */
  --box: min(60vw, 100svh - 150px);
}
@media (max-width: 46rem) { :root { --lobe: 1.35rem; } }
@media (max-height: 460px) { :root { --box: min(60vw, 100svh - 96px); --lobe: 1.15rem; } }
@media (max-aspect-ratio: 20/23) { :root { --box: min(88vw, 54svh); } }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--night); scrollbar-width: none; }
html::-webkit-scrollbar { display: none; }
body { margin: 0; background: var(--night); color: var(--ink); font: 400 1rem/1.5 var(--didone); overflow-x: hidden; overflow-x: clip; }
a { color: inherit; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 4px; border-radius: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- the stage ------------------------------------------------------------ */

.stage { position: relative; height: 100vh; height: 100svh; min-height: 24rem; overflow: hidden; touch-action: pan-y pinch-zoom; }
.ui { position: absolute; inset: 0 0 auto; height: 100%; pointer-events: none; }
.ui a, .ui button, .ui .lobe { pointer-events: auto; }
.rope { display: none; }

/* the still: the plain layout's knot */
.still {
  position: absolute; left: 50%; top: 50%; width: var(--box); height: auto; aspect-ratio: 1;
  transform: translate(-50%, -50%); user-select: none; -webkit-user-select: none; pointer-events: none;
}

/* ---- live ------------------------------------------------------------------ */

html.js:not(.fallback) .stage { position: fixed; inset: 0 0 auto; height: 100vh; height: 100lvh; min-height: 0; }
html.js:not(.fallback) .ui { height: 100vh; height: 100svh; }
html.js:not(.fallback) .still { display: none; }
html.js:not(.fallback) .rope { display: block; position: absolute; inset: 0; width: 100%; height: 100%; }
html.js:not(.fallback) .run { height: calc(100vh + 80vh); height: calc(100lvh + 80svh); }
html.js.still-motion .run { height: 100vh; height: 100lvh; }
/* nothing shows until it has been placed */
html.js:not(.live):not(.fallback) .stage { visibility: hidden; }
html.live .stage { animation: arrive 700ms ease both; }
@keyframes arrive { from { opacity: 0; } }
html.live .rope { cursor: default; }
html.live .stage.can { cursor: grab; }
html.live .stage.has, html.live .stage.has * { cursor: grabbing !important; }

/* ---- masthead -------------------------------------------------------------- */

.masthead {
  position: absolute; left: 0; right: 0; top: 0; z-index: 3;
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.2rem 1.1rem;
  padding: max(1rem, env(safe-area-inset-top)) var(--gutter) 0;
}
.masthead > * { margin: 0; }
.masthead__mark { font: 400 1.45rem/1.1 var(--didone); letter-spacing: 0; }
.masthead__sub, .title__sub { font: 400 0.7rem/1.4 var(--mono); letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-soft); }
@media (max-width: 46rem) { .masthead__mark { font-size: 1.3rem; } .masthead__sub { font-size: 0.62rem; } }

/* the name, once it is pulled out: behind the canvas, so the arms pass in front of it */
.title { position: absolute; left: 0; right: 0; top: 0; z-index: 0; margin: 0; text-align: center; opacity: 0; pointer-events: none; }
.title__name { margin: 0 0 0.16em; font: 400 clamp(3.1rem, 9.5vw, 8.6rem)/0.95 var(--didone); letter-spacing: -0.03em; }
.title__sub { margin: 0; }
html.live .title { z-index: 0; }
html.live .ui { z-index: auto; }
html.live .rope { z-index: 1; }
html.live .masthead, html.live .menu, html.live .note, html.live .hint { position: absolute; z-index: 2; }

/* ---- the menu: one item per lobe ------------------------------------------- */

.menu ul { list-style: none; margin: 0; padding: 0; }
.lobe {
  display: block; font: 400 var(--lobe)/1.05 var(--didone); letter-spacing: -0.005em; text-decoration: none; white-space: nowrap;
  padding: 0.3em 0.45em; transition: color 200ms ease;
}
a.lobe:hover, a.lobe.on { color: var(--gold); }
html.live .menu .lobe { transition: color 250ms ease; }
.lobe .nl { white-space: nowrap; }
html.tall .lobe .nl { display: block; }
.soon { font: 500 0.42em/1 var(--mono); font-style: normal; letter-spacing: 0.06em; text-transform: uppercase; margin-left: 0.55em; vertical-align: 0.22em; color: var(--ink-soft); transition: color 200ms ease; }
.lobe.is-soon { cursor: default; }
.lobe.is-off { color: var(--ink-faint); }
.lobe.is-off .soon { color: var(--ink-faint); }
.lobe.is-soon.said .soon { color: var(--ink); }
.lobe.is-soon.said { animation: say 420ms ease; }
@keyframes say { 25% { translate: -3px 0; } 50% { translate: 3px 0; } 75% { translate: -1px 0; } }

html.live .menu .lobe { position: absolute; left: 0; top: 0; transform-origin: 0 0; }

/* the plain layout: the menu round the still */
.menu { position: absolute; left: 50%; top: 50%; width: var(--box); height: var(--box); transform: translate(-50%, -50%); z-index: 2; pointer-events: none; }
html.live .menu { left: 0; top: 0; width: auto; height: auto; transform: none; }
html:not(.live) .menu li { position: absolute; }
html:not(.live) .menu li:nth-child(1) { right: 100%; top: 6%; }
html:not(.live) .menu li:nth-child(2) { left: 100%; top: 6%; }
html:not(.live) .menu li:nth-child(3) { right: 100%; bottom: 6%; }
html:not(.live) .menu li:nth-child(4) { left: 100%; bottom: 6%; }
@media (max-aspect-ratio: 20/23) {
  html:not(.live) .menu li:nth-child(1) { right: auto; left: 25%; top: auto; bottom: 100%; transform: translateX(-50%); }
  html:not(.live) .menu li:nth-child(2) { left: 75%; top: auto; bottom: 100%; transform: translateX(-50%); }
  html:not(.live) .menu li:nth-child(3) { right: auto; left: 25%; bottom: auto; top: 100%; transform: translateX(-50%); }
  html:not(.live) .menu li:nth-child(4) { left: 75%; bottom: auto; top: 100%; transform: translateX(-50%); text-align: center; }
  html:not(.live) .lobe .nl { display: block; }
}

/* ---- the button under the knot -------------------------------------------- */

.hint {
  position: absolute; left: 50%; bottom: max(1.4rem, env(safe-area-inset-bottom)); z-index: 3;
  transform: translateX(-50%); padding: 0.6rem 0.9rem; color: var(--ink-soft);
  font: 500 0.7rem/1 var(--mono); letter-spacing: 0.24em; text-transform: uppercase; white-space: nowrap; --p: 0;
  transition: opacity 400ms ease;
}
html:not(.live) .hint { display: none; }
/* tied, it is a caption: the knot is what you pull (the keyboard can still press it) */
.hint.is-caption { pointer-events: none; cursor: default; }
.hint__text { display: block; padding-left: 0.24em; }
.hint__line { display: block; position: relative; height: 1px; margin-top: 0.7rem; background: rgba(244, 241, 234, 0.16); overflow: hidden; }
.hint__fill { position: absolute; inset: 0; background: var(--ink); transform-origin: 50% 50%; transform: scaleX(var(--p)); }
.hint:not(.is-caption):hover { color: var(--ink); }
.hint.swap .hint__text { animation: swap 520ms cubic-bezier(0.22, 1, 0.36, 1); }
@keyframes swap { from { opacity: 0; filter: blur(6px); transform: translateY(-6px); } }
@media (max-height: 460px) { .title__name { font-size: min(9.5vw, 14svh); } .hint { bottom: 0.4rem; left: var(--gutter); transform: none; } }

/* Shiny Text, after React Bits (reactbits.dev, MIT + Commons Clause, © David Haz):
   one soft band of light crossing the words, then a rest. */
.shiny {
  background-image: linear-gradient(120deg, rgba(244, 241, 234, 0.58) 0%, rgba(244, 241, 234, 0.58) 40%, rgba(255, 252, 244, 1) 50%, rgba(244, 241, 234, 0.58) 60%, rgba(244, 241, 234, 0.58) 100%);
  background-size: 250% 100%; background-repeat: no-repeat;
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; color: transparent;
  animation: shine 5.2s cubic-bezier(0.45, 0, 0.55, 1) 1.2s infinite;
}
@keyframes shine { 0% { background-position: 100% 0; } 55%, 100% { background-position: 0% 0; } }

/* Blur Text, after React Bits: the words come in a letter at a time, scrubbed by
   how far the knot is pulled (js/knot/main.js reveal()). */
.ch { display: inline-block; white-space: pre; }
html.live .menu .lobe .ch, html.live .title .ch { opacity: 0; }

/* ---- where to take hold, and how far until it gives ------------------------ */

.grip, .meter { position: absolute; left: 0; top: 0; z-index: 2; pointer-events: none; opacity: 0; }
html:not(.live) .grip, html:not(.live) .meter { display: none; }
.grip { width: 104px; height: 24px; margin: -12px 0 0 -12px; transform-origin: 12px 12px; }
.grip svg { display: block; width: 100%; height: 100%; overflow: visible; }
.grip circle, .grip path { vector-effect: non-scaling-stroke; }
/* where to take hold: a dot in a hairline ring; which way: a dimension line out
   past the ribbon, with a faint glint running along it, outwards */
.grip__ring { fill: rgba(8, 8, 11, 0.22); stroke: rgba(244, 241, 234, 0.7); stroke-width: 1; }
.grip__dot { fill: var(--ink); }
.grip__shade { fill: none; stroke: rgba(8, 8, 11, 0.38); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.grip__line { fill: none; stroke: rgba(244, 241, 234, 0.82); stroke-width: 1; stroke-linecap: round; stroke-linejoin: round; }
.grip__run { fill: none; stroke: #fffaf0; stroke-width: 1.4; stroke-linecap: round; stroke-dasharray: 0.16 1.2; stroke-dashoffset: 0.16; animation: run 2.6s cubic-bezier(0.45, 0, 0.25, 1) infinite; }
@keyframes run { 0% { stroke-dashoffset: 0.16; opacity: 0; } 15% { opacity: 1; } 70% { stroke-dashoffset: -1.04; opacity: 0.9; } 71%, 100% { stroke-dashoffset: -1.04; opacity: 0; } }
/* ( · ): the hand's mark. Two hairline arcs round a dot; held, the arcs part
   as far as the pull has gone (--s, 0 to 1), so the mark itself is pulled apart. */
.arcs svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; filter: drop-shadow(0 0 1px rgba(8, 8, 11, 0.7)) drop-shadow(0 0 3px rgba(8, 8, 11, 0.35)); }
.arcs path { fill: none; stroke: var(--ink); stroke-width: 1.2; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.arcs__dot { fill: var(--ink); }
.arcs__l, .arcs__r { transition: transform 260ms cubic-bezier(0.22, 1, 0.36, 1); }
.arcs__l { transform: translateX(calc(-16px * var(--s, 0))); }
.arcs__r { transform: translateX(calc(16px * var(--s, 0))); }
html.tall .arcs svg { transform: rotate(90deg); }
.meter { width: 96px; height: 96px; margin: -48px 0 0 -48px; --s: 0; }

/* ---- the gesture, shown: "hint motion" -------------------------------------
   Two fingertips land on the grips, press, and draw the lobes apart; the rope
   really stretches with them, then they let go. js/knot/main.js demo(). */

.ghost, .trail { position: absolute; left: 0; top: 0; z-index: 2; pointer-events: none; opacity: 0; }
html:not(.live) .ghost, html:not(.live) .trail, html:not(.live) .cursor { display: none; }
.ghost {
  width: 30px; height: 30px; margin: -15px 0 0 -15px; border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 252, 244, 0.95) 0 2.4px, rgba(255, 252, 244, 0.14) 3px, rgba(255, 252, 244, 0.05) 70%);
  border: 1px solid rgba(255, 252, 244, 0.75);
  box-shadow: 0 0 0 6px rgba(255, 252, 244, 0.05);
}
.trail { height: 1px; margin-top: -0.5px; transform-origin: 0 50%; background: linear-gradient(90deg, rgba(244, 241, 234, 0), rgba(244, 241, 234, 0.55)); }

/* the pointer over the knot: the word "pull" on it, and one arrow beside it
   pointing the way to pull (--a), which eases further out as you pull (--push) */
.cursor { position: absolute; left: 0; top: 0; z-index: 4; width: 0; height: 0; pointer-events: none; opacity: 0; transition: opacity 200ms ease; --a: 0deg; --push: 0px; --off: 24px; }
.cursor.on { opacity: 1; }
.cursor__label {
  position: absolute; left: 0; top: 0; transform: translate(-50%, -54%);
  font: italic 400 1.02rem/1 var(--didone); letter-spacing: 0.02em; color: var(--ink); white-space: nowrap;
  text-shadow: 0 0 2px rgba(8, 8, 11, 0.65), 0 0 10px rgba(8, 8, 11, 0.4);
}
.cursor__way { position: absolute; left: 0; top: 0; width: 0; height: 0; transform: rotate(var(--a)); transition: transform 280ms cubic-bezier(0.22, 1, 0.36, 1); }
.cursor__arrow {
  position: absolute; left: 0; top: -7px; width: 26px; height: 14px; overflow: visible;
  transform: translateX(calc(var(--off) + var(--push))); transition: transform 160ms ease-out;
  filter: drop-shadow(0 0 1px rgba(8, 8, 11, 0.7)) drop-shadow(0 0 4px rgba(8, 8, 11, 0.35));
}
.cursor__arrow path { fill: none; stroke: var(--ink); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
html.live .stage.pointer-pull, html.live .stage.pointer-pull * { cursor: none !important; }

/* ---- the menu, live: only once the knot is out ---------------------------- */

html.live:not(.menu-on) .menu, html.live:not(.menu-on) .menu * { pointer-events: none !important; cursor: default; }
html.live .lobe__in { display: inline-block; will-change: transform; }

@media (prefers-reduced-motion: reduce) {
  html.live .stage { animation: none; }
  .lobe.is-soon.said, .shiny, .hint.swap .hint__text, .grip__run { animation: none; }
  .grip__run { opacity: 0; }
  .cursor, .cursor__way, .cursor__arrow, .arcs__l, .arcs__r { transition: none; }
  .shiny { background-position: 100% 0; }
}
