/* Default rules are the static page: no WebGL, reduced motion or no JavaScript.
   Rules under .live apply only while the effect is running (src/main.js sets that class). */
@font-face {
  font-family: 'Instrument Sans';
  src: url('../public/fonts/instrument-sans.woff2') format('woff2');
  font-weight: 400 700;
  font-display: swap;
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  --gutter: clamp(1.25rem, 4vw, 3.5rem);
  /* The hero frame: distance from the screen edges, and the headline size. The size is also capped by
     height, so the two rows never meet the shape on wide, low screens. */
  --edge: max(2.6vw, 1.25rem);
  --inset: 4.6svh;
  --head: min(11.4vw, 21svh);
  margin: 0;
  background: var(--color-dark);
  color: var(--color-chalk);
  font-family: 'Instrument Sans', system-ui, sans-serif;
  line-height: 1.5;
  overflow-x: hidden;
}

h1, h2, p, ol { margin: 0; }
ol { list-style: none; padding: 0; }

#mark, #what { font-size: 0.9375rem; line-height: 1.3; letter-spacing: 0.01em; max-width: 11rem; }
/* One element in two places: at the side of the hero, and in the corner once the page is dark. */
#mark {
  position: absolute; z-index: 2;
  top: 50svh; left: var(--edge); translate: 0 -50%;
  font-weight: 700;
  color: var(--color-dark);
}

/* ---- Hero ---- */
#hero {
  position: relative;
  display: flex; flex-direction: column; justify-content: flex-end;
  min-height: 100vh; min-height: 100svh;
  background: var(--color-light); color: var(--color-dark);
}
#intro-copy { position: absolute; inset: 0; }
#intro-copy h1 { position: absolute; inset: 0; font-size: var(--head); font-weight: 700; line-height: 0.8; letter-spacing: -0.045em; text-transform: uppercase; }
.row { position: absolute; left: var(--edge); right: var(--edge); display: flex; justify-content: space-between; }
.row-top { top: var(--inset); }
.row-bottom { bottom: var(--inset); }
.word { display: block; }
#what { position: absolute; top: 50%; right: var(--edge); translate: 0 -50%; text-align: right; font-weight: 500; }
/* Ruled edges: a fine tick every 12px and a longer one every fifth. Decoration only. */
.rule {
  --tick: clamp(0.625rem, 1.1vw, 1rem);
  position: absolute; top: 26%; bottom: 26%; width: var(--tick);
  background:
    repeating-linear-gradient(var(--color-dark) 0 1px, transparent 1px 60px) left top / 100% 100% no-repeat,
    repeating-linear-gradient(var(--color-dark) 0 1px, transparent 1px 12px) left top / 55% 100% no-repeat;
  opacity: 0.55;
}
.rule-left { left: 0; }
.rule-right { right: 0; scale: -1 1; }

/* The same artwork as the WebGL field, placed where the live shape rests. */
.shape-still {
  --side: calc(min(100vw, 100svh) / 1.2);
  position: absolute; left: 50%; top: 50%;
  width: var(--side); height: var(--side);
  translate: -50% -50%;
  background: var(--color-dark);
  mask: url('../shape/shape.svg') center / contain no-repeat;
}
@media (orientation: portrait) {
  /* Same lift as the shader: (1 - aspect) * 0.3 of the shape's own size. */
  .shape-still { translate: -50% calc(-50% - var(--side) * (1 - 100vw / 100svh) * 0.3); }
}

/* ---- Dark section ---- */
.chapter { max-width: 40rem; padding: 5rem var(--gutter) 1rem; }
.chapter span, .closing .contact span { display: block; font-size: 0.9375rem; font-weight: 700; color: var(--color-accent); }
.chapter span { margin-bottom: 0.875rem; }
.chapter h2 { font-size: clamp(2.5rem, 4.8vw, 4.5rem); font-weight: 600; line-height: 1; letter-spacing: -0.025em; text-wrap: balance; }
.chapter p { margin-top: 1.125rem; font-size: 1.125rem; max-width: 24rem; }
#chapters { padding-bottom: 4rem; }
#chapters .chapter:last-of-type { margin-bottom: 4rem; }

#media-grid {
  display: grid; gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 20rem), 1fr));
  padding: 0 var(--gutter);
}
#media-grid { align-items: start; }
#media-grid img { display: block; width: 100%; height: auto; }

#outro { display: grid; place-items: center; box-sizing: border-box; padding: 6rem var(--gutter); }
.closing { max-width: 34rem; text-align: center; }
.closing h2 { font-size: clamp(1.75rem, 3vw, 2.5rem); line-height: 1.15; }
.closing p { margin-top: 1rem; font-size: 1.0625rem; text-wrap: balance; }
.closing .contact { margin-top: 2rem; }

#stage, #loader { display: none; }

/* ---- While the page is starting: the loader covers everything. ---- */
.starting #loader, .live #loader {
  position: fixed; top: 0; left: 0; width: 100%; height: 100vh; height: 100lvh;
  z-index: 100; display: grid; place-items: center;
  background: var(--color-light); color: var(--color-dark); pointer-events: none;
}
#loader i {
  /* 100vh equals 100lvh on phones, which is the canvas height the shader dot is measured against. */
  width: calc(var(--seed-radius) * 200vh);
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--color-dark);
}
/* ---- Live effect ---- */
.starting #stage, .live #stage {
  display: block;
  position: fixed; top: 0; left: 0; width: 100%; height: 100vh; height: 100lvh;
  pointer-events: none;
}
.live #stage canvas { display: block; }

/* Page length drives the flight: its stops (engine/world/flight.js) are 1.8, 3.4, 5.0 and 6.4 screens down. */
.live #hero { height: 100svh; min-height: 0; background: none; }
.live #chapters { height: 480svh; padding: 0; }
.live #outro { height: 160svh; padding: 0; }
.live .shape-still, .live #media-grid { display: none; }

/* Text layers over the canvas never take the pointer, and src/overlay.js sets their opacity. */
.live #mark, .live #intro-copy, .live .chapter, .live .closing { position: fixed; pointer-events: none; }
/* The hero frame measures from the visible screen, so a phone toolbar cannot cover its lower row. */
.live #intro-copy { inset: 0 0 auto 0; height: 100svh; }
.live #mark[data-on='dark'] {
  top: var(--gutter); left: var(--gutter); translate: none; max-width: none;
  font-size: 1.0625rem; line-height: 1; letter-spacing: normal;
  color: var(--color-chalk);
}

.live .chapter { left: 0; bottom: 0; margin: 0; box-sizing: border-box; padding: var(--gutter); padding-bottom: calc(var(--gutter) + 2vh); opacity: 0; }
/* The finished outline surrounds this block, so its sizes follow the outline's (the same formula as
   uRingScale in engine/world/index.js). */
.live .closing {
  --ring: min(94svh, 104vw);
  /* Slightly above centre: the outline pinches in below the middle. */
  left: 50%; top: 50svh; translate: -50% calc(-50% - var(--ring) * 0.025);
  width: min(17rem, var(--ring) * 0.64);
  opacity: 0;
}
.live .closing h2 { font-size: clamp(1.125rem, var(--ring) * 0.055, 1.875rem); }
.live .closing p { margin-top: clamp(0.5rem, var(--ring) * 0.02, 1rem); font-size: clamp(0.8125rem, var(--ring) * 0.036, 1rem); line-height: 1.4; }
.live .closing .contact { margin-top: clamp(0.75rem, var(--ring) * 0.04, 2rem); }
.live .closing .contact span { font-size: inherit; }

/* Soft shades in the page's dark colour, never solid boxes: lines and media pass behind the words.
   Each is an oval well beyond its block, so even the corners of the text sit in the solid part. */
.live .chapter::before, .live .closing::before, .live #mark[data-on='dark']::before {
  content: ''; position: absolute; z-index: -1;
  background: radial-gradient(closest-side,
    color-mix(in srgb, var(--color-dark) 94%, transparent),
    color-mix(in srgb, var(--color-dark) 91%, transparent) 62%,
    color-mix(in srgb, var(--color-dark) 55%, transparent) 80%,
    transparent);
}
.live .chapter::before { inset: -45% -48% -42% -48%; }
.live .closing::before { inset: -34% -36%; }
/* Narrow screens: the outline is close to the words, so the shade stays tighter. */
@media (orientation: portrait) {
  .live .closing::before { inset: -12% -16%; }
}
.live #mark[data-on='dark']::before { inset: -2.25rem -3.5rem; }
.live #mark[data-on='dark'], .live .chapter, .live .closing {
  text-shadow: 0 0 0.2em var(--color-dark), 0 0 0.6em var(--color-dark), 0 0 1.4em var(--color-dark);
}

/* Tall screens: the headline stacks above and below the shape, and the name and what you do share
   the space between the shape and the lower words. */
@media (orientation: portrait) {
  body { --head: min(21vw, 12svh); --labels: calc(var(--inset) + var(--head) * 1.65 + 1.5rem); }
  .row { flex-direction: column; align-items: flex-start; gap: 0.05em; }
  #mark { max-width: 30%; }
  #what { max-width: 64%; text-wrap: balance; }
  #mark { top: calc(100svh - var(--labels)); translate: 0 -100%; }
  #what { top: auto; bottom: var(--labels); translate: none; }
  .rule { bottom: calc(var(--labels) + 2.5rem); }
}
