/*
 * Syllune hero: the first screen and the bar above it. A fixed moonlit scene
 * fills the frame; the title sits beside the Moon, and scrolling cranes the
 * camera up over the sea while the bar takes over the wordmark. Where the
 * Moon and the horizon sit is set here, on two guides the scene reads.
 */

/* ----------------------------------------------------------------- tokens */

:root {
  /* Colours. The scene reads the ground and the inks: one pair for the Moon
     and stars, one for the sea, and one for the lines spoken on it. */
  --ground: #000000;
  --ink-high: #f4f4f4;
  --ink-low: #7d7d7d;
  --sea-high: #c9c9c9;
  --sea-low: #4d4d4d;
  --word-ink: #ffffff;
  --text: #ffffff;
  --text-dim: #8f8f8f;

  --font-mono: "Fragment Mono", "Cascadia Mono", Consolas, ui-monospace, monospace;

  /* The title face and its settings. */
  --font-title: "Schibsted Grotesk", "Segoe UI", system-ui, sans-serif;
  --title-weight: 800;
  --title-size: clamp(2.1rem, 0.8rem + 3.6vw, 5.25rem);
  --title-leading: 0.98;
  --title-tracking: -0.042em;

  /* Distance from the frame edge to the type. */
  --edge: clamp(1.25rem, 0.6rem + 2.2vw, 2.75rem);

  /* One easing for every transition on the page. */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);

  /* The opening: the title rises in first, the bar follows this much later. */
  --bar-delay: 650ms;

  /* The composition at rest: the Moon's centre and radius, the horizon's
     distance from the top, the light on the Moon (phase angle in degrees,
     0 full) and how far it swings over a few minutes. The title block is
     centred on the Moon's line. The scene's camera is fitted to these. */
  --moon-x: 68vw;
  --moon-y: 43svh;
  --moon-r: min(29svh, 23vw);
  --horizon: 70svh;
  --moon-phase: 40;
  --moon-swing: 18;
  --lead-y: var(--moon-y);
  --lead-shift: -50%;
}

/* Tall frames: the Moon high, the title under it, the sea at the foot. */
@media (max-aspect-ratio: 9 / 10) {
  :root {
    --moon-x: 60vw;
    --moon-y: 25svh;
    --moon-r: 36vw;
    --horizon: 78svh;
    --lead-y: calc(var(--moon-y) + var(--moon-r) + 4svh);
    --lead-shift: 0%;
  }
}

/* ------------------------------------------------------------------- base */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  background: var(--ground);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--ground);
  font-family: var(--font-title);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

main {
  position: relative;
  z-index: 1;
}

/* ------------------------------------------------------------------ scene */
/* The scene stays put behind the page while the camera cranes up, so the
   section after the hero floats on the water. Without scripts, or with
   reduced motion, it is simply the first screen. */

.scene {
  position: absolute;
  inset: 0 0 auto 0;
  z-index: 0;
  height: 100vh;
  height: 100svh;
  min-height: 30rem;
  overflow: hidden;
  background: var(--ground);
  pointer-events: none;
}

/* The scene fades to pure black over the first half of the hero's runway,
   so it is gone by the time the title starts to fade and How it works
   rises on clean ground. --scroll comes from scene.js. */
.js .hero-scene {
  opacity: clamp(0, calc(1.375 - 2.5 * var(--scroll, 0)), 1);
}

@media (prefers-reduced-motion: no-preference) {
  .js .scene {
    position: fixed;
    /* The large viewport, so no strip of ground shows as a phone's address
       bar slides away. */
    height: 100lvh;
  }
}

/* The live scene. Hidden until scripts run, so a visitor without JavaScript
   never sees an empty canvas over the still frame. */
.hero-scene {
  position: absolute;
  inset: 0;
  display: none;
  width: 100%;
  height: 100%;
}

.js .hero-scene {
  display: block;
}

.hero-no-webgl .hero-scene {
  display: none;
}

/* The still frame: the same scene as real text characters, for visitors
   with JavaScript off or without WebGL. Two cuts, wide and tall. bake.js
   writes each cut's grid on it: columns, rows, and the cell the Moon is
   centred on, so the Moon lands where the guide says. */
.hero-still {
  position: absolute;
  margin: 0;
  left: calc(var(--moon-x) - var(--moon-column) * 1ch);
  top: calc(var(--moon-y) - var(--moon-row) * 1em);
  width: calc(var(--columns) * 1ch);
  font-family: var(--font-mono);
  font-weight: 400;
  /* Cover the frame the way the canvas does. 0.618 is the width of one
     Fragment Mono character in ems. */
  font-size: max(100vw / (var(--columns) * 0.618), 100svh / var(--rows));
  /* Rows are as tall as the type size, like the live scene. */
  line-height: 1;
  white-space: pre;
  /* Every character stands alone: no joined == or -- from the font. */
  font-variant-ligatures: none;
  font-feature-settings: "liga" 0, "calt" 0;
  /* Text has one colour for every character, so it takes a tone between the
     scene's dim and bright ink. */
  color: color-mix(in srgb, var(--ink-high) 55%, var(--ink-low));
  user-select: none;
  -webkit-user-select: none;
}

.hero-still--tall {
  display: none;
}

@media (max-aspect-ratio: 9 / 10) {
  .hero-still--wide {
    display: none;
  }

  .hero-still--tall {
    display: block;
  }
}

.js .hero-still {
  display: none;
}

@media (min-aspect-ratio: 9 / 10) {
  .hero-no-webgl .hero-still--wide {
    display: block;
  }
}

@media (max-aspect-ratio: 9 / 10) {
  .hero-no-webgl .hero-still--tall {
    display: block;
  }
}

/* -------------------------------------------------------------------- bar */
/* The logo and the links arrive just after the title, once the scene has
   developed, and then stay. There is no box: the scene keeps clear of the
   bar, and once the visitor scrolls a soft fade of ground covers what
   scrolls under it. */

.bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  padding: max(var(--edge), env(safe-area-inset-top)) max(var(--edge), env(safe-area-inset-right)) 1rem max(var(--edge), env(safe-area-inset-left));
  pointer-events: none;
}

.bar > * {
  pointer-events: auto;
}

/* scene.js shows the bar once, invisibly, while the page opens. Not quite
   zero: at zero the browser skips the very work the warm-up is for. */
.bar-warm .bar {
  opacity: 0.01;
}

.bar::before {
  content: "";
  position: absolute;
  inset: 0 0 -2.5rem;
  z-index: -1;
  background: linear-gradient(var(--ground) 45%, transparent);
  opacity: 0;
  transition: opacity 700ms var(--ease-out);
  pointer-events: none;
  /* Built up front, so the bar's first appearance costs no frame. */
  will-change: opacity;
}

.bar-on .bar::before {
  opacity: 1;
}

/* The logo rises bar by bar with the opening, then stays perfectly still. */
.bar-brand {
  display: block;
  color: var(--text);
  text-decoration: none;
  visibility: hidden;
}

.hero-type-in .bar-brand,
html:not(.js) .bar-brand {
  visibility: visible;
}

/* The logo: the app icon's five bars without the tile, in pure white. Sizes
   are shares of the tallest bar, taken from overlay/assets/syllune.svg. */
.bar-logo {
  --logo: 1.75rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  width: calc(var(--logo) * 1.165);
  height: var(--logo);
}

.bar-logo > span {
  position: relative;
  width: calc(var(--logo) * 0.148);
  height: calc(var(--logo) * var(--h));
  margin-top: calc(var(--logo) * var(--top));
}

.bar-logo i {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: currentColor;
  transform: scaleY(0);
}

html:not(.js) .bar-logo i {
  transform: scaleY(1);
}

/* --bar-delay: the bar follows the title in by this much, all of it at
   once apart from a slight ripple. */
.hero-type-in .bar-logo i {
  transform: scaleY(1);
  transition: transform 900ms var(--ease-out) calc(var(--bar-delay) + var(--i) * 45ms);
}

.bar-links {
  display: flex;
  gap: 0 2em;
  margin: 0;
  padding: 0;
  list-style: none;
  font-family: var(--font-mono);
  font-size: max(var(--cell-font, 0.875rem), 13px);
  line-height: 1;
  letter-spacing: -0.01em;
}

.bar-links a {
  display: block;
  color: var(--text);
  text-decoration: none;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px);
}

.hero-type-in .bar-links a {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition:
    opacity 900ms var(--ease-out) calc(var(--bar-delay) + 120ms + var(--i) * 45ms),
    transform 900ms var(--ease-out) calc(var(--bar-delay) + 120ms + var(--i) * 45ms),
    visibility 0s;
}

/* Without scripts the bar never changes: the word and the links both show. */
html:not(.js) .bar-links a {
  opacity: 1;
  visibility: visible;
  transform: none;
}

.bar-links a,
.hero-download,
.hero-copy {
  text-decoration-line: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.34em;
  text-decoration-color: transparent;
}

.bar-brand:focus-visible,
.bar-links a:focus-visible {
  outline: 1px solid currentColor;
  outline-offset: 0.4em;
}

@media (hover: hover) {
  .bar-links a:hover {
    text-decoration-color: color-mix(in srgb, currentColor 60%, transparent);
  }
}

/* Narrow phones keep only the two links that matter there: GitHub, which a
   phone can read, and Download. */
@media (max-width: 34rem) {
  .bar-links li:nth-child(-n + 3) {
    display: none;
  }
}

/* ------------------------------------------------------------------- hero */
/* The hero holds still for about two screens of scrolling while the camera
   rises; its first screen sticks in place over that runway. */

.hero {
  position: relative;
  height: 100vh;
  height: 100svh;
  min-height: 30rem;
}

@media (prefers-reduced-motion: no-preference) {
  .js .hero {
    height: 165vh;
    height: 165svh;
  }
}

.hero-stage {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100svh;
  min-height: 30rem;
  overflow: hidden;
}

/* The two guides: invisible boxes for the Moon's disc and the horizon. */
.hero-guide {
  position: absolute;
  visibility: hidden;
  pointer-events: none;
}

.hero-guide--moon {
  left: calc(var(--moon-x) - var(--moon-r));
  top: calc(var(--moon-y) - var(--moon-r));
  width: calc(2 * var(--moon-r));
  height: calc(2 * var(--moon-r));
}

.hero-guide--horizon {
  left: 0;
  top: var(--horizon);
  width: 100%;
  height: 1px;
}

/* As the visitor scrolls, the title travels up a little slower than the
   page. It stays fully legible until the scene has gone black, then fades
   while the next section rises. scene.js writes --scroll, from 0 at rest to
   1 at the end of the runway, in the scroll event itself. */
.hero-lift {
  position: absolute;
  inset: 0;
  transform: translateY(calc(var(--scroll, 0) * -30svh));
  opacity: calc(2.43 - 2.86 * var(--scroll, 0));
  pointer-events: none;
}

/* The title block: the line itself, then Download and its details. It is
   never wider than the room left of the Moon. scene.js nudges it by less
   than one character (--snap-x, --snap-y) so Download sits on the grid. */
.hero-lead {
  position: absolute;
  left: max(var(--edge), env(safe-area-inset-left));
  top: var(--lead-y);
  width: max-content;
  max-width: calc(var(--moon-x) - var(--moon-r) - var(--edge) - clamp(1.5rem, 3vw, 3.5rem));
  margin: 0;
  transform: translateY(var(--lead-shift));
  translate: var(--snap-x, 0) var(--snap-y, 0);
  pointer-events: auto;
}

@media (max-aspect-ratio: 9 / 10) {
  .hero-lead {
    max-width: calc(100vw - 2 * var(--edge));
  }
}

/* Each sentence of the title keeps to one line. */
.hero-title {
  margin: 0;
  font-family: var(--font-title);
  font-size: var(--title-size);
  font-weight: var(--title-weight);
  line-height: var(--title-leading);
  letter-spacing: var(--title-tracking);
}

.hero-title > span {
  display: block;
  white-space: nowrap;
}

/* The subline says plainly what Syllune is, under the tagline. It wraps
   inside the width the title already takes, so the block keeps its shape. */
.hero-sub {
  width: 0;
  min-width: 100%;
  max-width: 34em;
  margin: clamp(0.75rem, 2svh, 1.25rem) 0 0;
  font-size: var(--t-lead);
  font-weight: var(--t-lead-weight);
  line-height: var(--t-lead-leading);
  letter-spacing: var(--t-lead-tracking);
  text-wrap: pretty;
}

/* Download and its details are set like the art: the same monospace at the
   size of one character cell. */
.hero-action {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5em 1ch;
  margin: clamp(1.25rem, 3svh, 2.25rem) 0 0;
  font-family: var(--font-mono);
  font-size: max(var(--cell-font, 0.9375rem), 13px);
  line-height: 1;
  letter-spacing: 0;
  font-variant-ligatures: none;
}

/* The details are the same text as Download, same colour and size: only
   the underline marks the link. A short hairline stands between items in
   place of a separator character. */
.hero-meta {
  display: inline-flex;
  align-items: baseline;
  gap: 0 1.5ch;
  margin-left: 0.5ch;
  white-space: nowrap;
}

.hero-meta > span::before {
  content: "";
  display: inline-block;
  width: 1px;
  height: 0.9em;
  margin-right: 1.5ch;
  vertical-align: -0.12em;
  background: currentColor;
  opacity: 0.35;
}

/* The Windows mark, drawn at cap height beside its version. */
.hero-os svg {
  width: 0.78em;
  height: 0.78em;
  margin-right: 0.55ch;
  vertical-align: -0.02em;
  fill: currentColor;
}

/* Download: a plain underlined word. Hover firms up the underline and nothing else. */
.hero-download,
.hero-copy {
  color: inherit;
  text-decoration-color: color-mix(in srgb, currentColor 42%, transparent);
  transition: text-decoration-color 150ms var(--ease-out);
}

.hero-copy {
  display: none;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  letter-spacing: inherit;
  cursor: pointer;
}

.hero-download:focus-visible,
.hero-copy:focus-visible {
  outline: 1px solid currentColor;
  outline-offset: 0.4em;
}

@media (hover: hover) {
  .hero-download:hover,
  .hero-copy:hover {
    text-decoration-color: currentColor;
  }
}

.hero-download:active,
.hero-copy:active {
  text-decoration-color: currentColor;
}

/* Phones cannot run Syllune, so Download gives way to Copy link. The note
   beside it says why. Copying needs a script. */
@media (hover: none) and (pointer: coarse) {
  .js .hero-download {
    display: none;
  }

  .js .hero-copy {
    display: inline;
  }
}

/* ---------------------------------------------------------------- opening */
/* The type arrives last, once the scene has developed: each line of the
   title rises a little out of a soft blur, the details follow, then the bar.
   scene.js sets .hero-type-in; an inline timer in the page sets it too if
   the scene fails. */

.js .hero-title > span,
.js .hero-sub,
.js .hero-action {
  opacity: 0;
  transform: translateY(0.45em);
  filter: blur(8px);
}

.js .hero-action {
  transform: translateY(0.8em);
}

.js.hero-type-in .hero-title > span,
.js.hero-type-in .hero-sub,
.js.hero-type-in .hero-action {
  opacity: 1;
  transform: none;
  filter: blur(0);
  transition:
    opacity 1400ms var(--ease-out) var(--rise-delay, 0ms),
    transform 1600ms var(--ease-out) var(--rise-delay, 0ms),
    filter 1200ms var(--ease-out) var(--rise-delay, 0ms);
}

.js .hero-title > span + span {
  --rise-delay: 140ms;
}

.js .hero-sub {
  --rise-delay: 260ms;
}

.js .hero-action {
  --rise-delay: 380ms;
}

@media (prefers-reduced-motion: reduce) {
  .js .hero-title > span,
  .js .hero-sub,
  .js .hero-action {
    opacity: 1;
    transform: none;
    filter: none;
    transition: none !important;
  }

  .bar::before,
  .bar-brand,
  .bar-logo i,
  .bar-links a,
  .hero-download,
  .hero-copy {
    transition: none !important;
  }

  .hero-lift {
    transform: none;
    opacity: 1;
  }
}
