/* Required by Lenis, the smooth-scroll library. */
html.lenis,
html.lenis body {
  height: auto;
}
.lenis.lenis-smooth {
  scroll-behavior: auto !important;
}
.lenis.lenis-stopped {
  overflow: hidden;
}

:root {
  --bg: #000;
  --ink: #f4f2ef;
  --muted: #8c8783;
  --line: rgb(244 242 239 / 0.22);
  --accent: #c9a9ff;
  --serif: "Playfair Display", "Times New Roman", serif;
  --sans: Inter, -apple-system, system-ui, "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  --gutter: clamp(1.25rem, 5vw, 5rem);
  /* Scroll distance given to each section. Smaller means a quicker story. */
  --section: 70vh;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-weight: 300;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* The canvas sits behind everything, pinned to the viewport. */
#field {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  color: var(--accent);
}
#field canvas {
  display: block;
}
#field svg {
  position: absolute;
  inset: 20vh 10vw;
  width: 80vw;
  height: 60vh;
}

.mark {
  position: fixed;
  top: 1.25rem;
  left: var(--gutter);
  z-index: 3;
  font-family: var(--serif);
  font-size: 1.25rem;
  color: var(--ink);
  text-decoration: none;
}

#stats {
  position: fixed;
  top: 3.6rem;
  left: var(--gutter);
  z-index: 3;
  font-family: var(--mono);
  font-size: 0.66rem;
  line-height: 1.7;
  color: var(--muted);
  pointer-events: none;
}
#readout {
  margin: 0;
  font: inherit;
}
/* One bar per frame: how long it took. */
#trace {
  display: block;
  width: 9rem;
  height: 1.5rem;
  margin: 0.4rem 0 0.5rem;
}
/* Rulers in the manner of a map's scale bar. Their widths are set by the
   script, so they grow as the camera closes in. */
.scale {
  display: flex;
  align-items: flex-end;
  gap: 0.5em;
  line-height: 1.5;
}
.scale i {
  height: 0.35rem;
  border: 1px solid currentColor;
  border-top: 0;
}

/* While the shape is being turned by hand, the drag must not select text. */
.turning {
  cursor: grabbing;
  user-select: none;
}

.formula {
  max-width: none;
  font-family: var(--mono);
  font-size: 0.68rem;
  line-height: 1.5;
  color: var(--accent);
}
.formula span {
  color: var(--muted);
  white-space: nowrap;
}
.formula span::before {
  content: "  ";
  white-space: pre;
}

main {
  position: relative;
  z-index: 1;
}

/* Each section is a stretch of scroll distance with its text in a bottom
   corner, so the field keeps the middle of the screen. */
.panel {
  min-height: var(--section);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 0 var(--gutter) 11vh;
  pointer-events: none;
}
/* The last section is the full screen that is left showing when the page
   runs out, plus a little extra scroll for the dissolve to finish in. */
.panel.last {
  min-height: calc(100vh + var(--section) * 0.3);
}

.copy {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.6rem;
  text-shadow: 0 0 1.5rem var(--bg), 0 0 0.5rem var(--bg);
}
.panel:nth-child(even) .copy {
  align-items: flex-end;
  text-align: right;
}

/* Once the script is running, the text is taken out of the scrolling page and
   held in place; the script fades each block in and out. Without the script
   the text simply scrolls. */
.pinned .copy {
  position: fixed;
  left: var(--gutter);
  right: var(--gutter);
  /* Clear of the two rows the picker can take up at the foot of the screen. */
  bottom: max(11vh, 7.25rem);
  opacity: 0;
  visibility: hidden;
}

/* The ending has the screen to itself, so it fills it: centred, with the
   heading at title size. */
.pinned .panel.last .copy {
  top: 0;
  bottom: 0;
  justify-content: center;
  align-items: center;
  text-align: center;
}
.panel.last h2 {
  font-size: clamp(2.1rem, 4.6vw, 3.6rem);
  letter-spacing: -0.02em;
}
/* On a narrow screen the open controls cover the top, so the ending is
   centred in the space below them instead. */
@media (max-width: 900px) {
  .pinned .panel.last .copy {
    top: 15rem;
  }
}

.eyebrow,
.hint {
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}
.hint {
  margin-top: 1rem;
}

h1,
h2 {
  font-family: var(--serif);
  font-weight: 400;
  line-height: 1;
}
h1 {
  font-size: clamp(2.1rem, 4.6vw, 3.6rem);
  letter-spacing: -0.02em;
}
h2 {
  font-size: clamp(1.25rem, 2.2vw, 1.7rem);
  letter-spacing: -0.01em;
}

p {
  max-width: 26rem;
  font-size: clamp(0.82rem, 1vw, 0.9rem);
  line-height: 1.55;
  color: var(--muted);
  text-wrap: pretty;
}
.lede {
  color: rgb(244 242 239 / 0.72);
}

.touch-note {
  display: none;
  font-size: 0.75rem;
}
@media (hover: none) {
  .touch-note {
    display: block;
  }
  .mouse-note {
    display: none;
  }
}

/* The shape and style switches stay at the foot of the screen the whole way
   down. The row of text options opens above the buttons, so the buttons never
   move. */
.picker {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 1.5rem;
  z-index: 3;
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  gap: 0.5rem;
  pointer-events: none;
}
/* A row that is wider than the screen scrolls sideways rather than wrapping,
   so the bar never grows taller and pushes into the text above it. */
.picker-row {
  display: flex;
  gap: 0.4rem;
  max-width: 100%;
  padding: 0 0.75rem;
  overflow-x: auto;
  scrollbar-width: none;
  pointer-events: auto;
}
.picker-row > * {
  flex-shrink: 0;
}
.picker-row[hidden] {
  display: none;
}
/* Glow is a switch, not a third shape, so it stands slightly apart. */
#glow {
  margin-left: 0.5rem;
}
.picker button,
.picker input,
.picker select {
  font: inherit;
  font-size: 0.85rem;
  color: var(--ink);
  background: rgb(0 0 0 / 0.5);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.45rem 0.8rem;
}
.picker button,
.picker select {
  cursor: pointer;
}
.picker button[aria-pressed="true"] {
  color: var(--accent);
  border-color: var(--accent);
}
.picker input {
  width: 9rem;
}
.picker :focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.signoff {
  margin-top: 1rem;
  color: var(--ink);
  pointer-events: auto;
}
.signoff a {
  color: var(--accent);
  text-underline-offset: 0.2em;
}

/* The control panel, restyled to match the page. */
.lil-gui {
  --width: 270px;
  --font-family: var(--sans);
  --font-family-mono: var(--mono);
  --background-color: #0c0c0d;
  --title-background-color: #151517;
  --widget-color: #232327;
  --hover-color: #2e2e33;
  --focus-color: #3a3a40;
  --text-color: var(--ink);
  --title-text-color: var(--ink);
  --number-color: var(--accent);
  --string-color: var(--accent);
}
.lil-gui.root {
  z-index: 4;
}

@media (prefers-reduced-motion: reduce) {
  .hint {
    display: none;
  }
}
