/* Lunar Machinery ------------------------------------------------------------
   Tokens, type, layout, the instrument, and motion. Dark only, by design. */

@font-face {
  font-family: "Lunar Grotesk Text";
  src: url("fonts/lunar-grotesk-text.woff2") format("woff2");
  font-weight: 400 500;
  font-stretch: 100% 125%;
  font-display: swap;
}

@font-face {
  font-family: "Lunar Grotesk Display";
  src: url("fonts/lunar-grotesk-display.woff2") format("woff2");
  font-weight: 560 700;
  font-stretch: 85% 100%;
  font-display: swap;
}

@font-face {
  font-family: "Martian Mono";
  src: url("fonts/martian-mono.woff2") format("woff2");
  font-weight: 400;
  font-stretch: 87.5% 112.5%;
  font-display: swap;
}

/* Metric-matched fallbacks, so swapping in the web fonts barely moves anything. */
@font-face {
  font-family: "Lunar Text Fallback";
  src: local("Arial"), local("Liberation Sans"), local("Helvetica Neue"), local("Helvetica");
  size-adjust: 103.3%;
  ascent-override: 105.5%;
  descent-override: 31%;
  line-gap-override: 0%;
}

@font-face {
  font-family: "Lunar Display Fallback";
  src: local("Arial Bold"), local("Arial-BoldMT"), local("Liberation Sans Bold"), local("Helvetica Neue Bold");
  font-weight: 700;
  size-adjust: 90.5%;
  ascent-override: 120.4%;
  descent-override: 35.4%;
  line-gap-override: 0%;
}

:root {
  --basalt: #1b1a18;
  --regolith: #ece5d8;
  --dust: #a69e91;
  --sodium: #d98a43;
  --sodium-lift: #e39a58;
  --surface: #302c26;
  --night: #101215;
  --crater-shadow: #1f1d1a;
  --void: #141311;
  --hairline: rgb(236 229 216 / 0.14);

  --text: "Lunar Grotesk Text", "Lunar Text Fallback", system-ui, sans-serif;
  --display: "Lunar Grotesk Display", "Lunar Display Fallback", system-ui, sans-serif;
  --mono: "Martian Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;

  --gutter: clamp(1.25rem, 5vw, 5rem);
  --max: 1440px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --sine: cubic-bezier(0.37, 0, 0.63, 1);

  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  background: var(--basalt);
  color: var(--regolith);
  font-family: var(--text);
  font-size: 1.0625rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  overflow-x: clip;
  container-type: inline-size;
}

main {
  flex: 1;
}

::selection {
  background: var(--sodium);
  color: var(--basalt);
}

a {
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--regolith);
  outline-offset: 3px;
}

.wrap {
  width: min(var(--max), 100% - 2 * var(--gutter));
  margin-inline: auto;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* Header ------------------------------------------------------------------ */

.site-header {
  display: flex;
  align-items: center;
  min-height: 5.5rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  border-radius: 2px;
}

.brand svg {
  width: 28px;
  height: 28px;
  flex: none;
}

.wordmark {
  font-weight: 500;
  font-stretch: 125%;
  font-size: 0.875rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  line-height: 1;
}

/* Monogram, shared by the header and the favicon source. */
.m-disc {
  fill: var(--regolith);
}

.m-letter {
  fill: none;
  stroke: var(--regolith);
  stroke-width: 4.2;
  stroke-miterlimit: 10;
}

.m-core {
  fill: var(--sodium);
}

/* Hero -------------------------------------------------------------------- */

/* The instrument's width, and where its left edge (the sphere's left limb) falls
   across the full page width. Both are shared with the first-projects paragraph. */
body {
  --inst-w: min(50cqw, var(--max) * 0.56, (100svh - 8rem) / 1.05);
  --inst-right: max(0px, (100cqw - var(--max)) / 2 - var(--gutter));
  --inst-left: calc(100cqw - var(--inst-right) - var(--inst-w));
  --content-left: calc((100cqw - min(var(--max), 100cqw - 2 * var(--gutter))) / 2);
  --text-room: calc(var(--inst-left) - var(--content-left) - 1.5rem);
}

/* Keep the paragraph and contact row clear of the moon; only the headline overlaps it. */
@media (min-width: 1024px) {
  .intro {
    max-width: min(34ch, var(--text-room));
  }

  .contact {
    max-width: var(--text-room);
  }
}

.hero {
  display: grid;
  align-items: center;
  min-height: calc(100svh - 5.5rem);
  padding-bottom: 2rem;
}

.hero > * {
  grid-area: 1 / 1;
}

.hero-text {
  position: relative;
  z-index: 1;
}

.label {
  margin: 0 0 1.75rem;
  font-family: var(--mono);
  font-size: 0.75rem;
  font-stretch: 100%;
  letter-spacing: 0.12em;
  line-height: 1.4;
  text-transform: uppercase;
  color: var(--dust);
}

h1,
.display {
  margin: 0;
  font-family: var(--display);
  font-weight: 640;
  font-stretch: 100%;
  letter-spacing: -0.012em;
  line-height: 0.94;
}

.headline {
  font-size: clamp(2.5rem, 0.8rem + 5.6cqw, 6.5rem);
}

.headline span {
  display: block;
}

.intro {
  max-width: 34ch;
  margin: 2rem 0 0;
  font-size: clamp(1.25rem, 1rem + 0.8cqw, 1.625rem);
  line-height: 1.45;
  text-wrap: pretty;
}

.contact {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem 1.5rem;
  margin-top: 2.5rem;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 0 1.75rem;
  border-radius: 999px;
  background: var(--sodium);
  color: var(--basalt);
  font-weight: 500;
  font-size: 1.0625rem;
  line-height: 1;
  text-decoration: none;
  transition: background-color 150ms ease, translate 150ms ease;
}

.button:hover {
  background: var(--sodium-lift);
}

.button:active {
  translate: 0 1px;
}

.address {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.875rem;
  margin: 0;
  font-family: var(--mono);
  font-size: 0.8125rem;
  font-stretch: 100%;
  color: var(--dust);
}

.copy {
  min-height: 32px;
  padding: 0 0.875rem;
  border: 1px solid rgb(236 229 216 / 0.24);
  border-radius: 999px;
  background: none;
  color: var(--regolith);
  font: inherit;
  cursor: pointer;
  transition: border-color 150ms ease;
}

.copy:hover {
  border-color: rgb(236 229 216 / 0.6);
}

.copy[hidden] {
  display: none;
}

/* The instrument ---------------------------------------------------------- */

.instrument {
  position: relative;
  justify-self: start;
  width: var(--inst-w);
  margin: 0 0 0 var(--inst-left);
  --k: 1;
}

.instrument svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

/* The near half of the orbit passes in front of the moon but behind the headline. */
.instrument-front {
  position: absolute;
  inset: 0 0 auto 0;
  pointer-events: none;
}

.readout {
  margin: 0.5rem 0 0;
  font-family: var(--mono);
  font-size: 0.8125rem;
  font-stretch: 100%;
  color: var(--dust);
}

.readout[hidden] {
  display: none;
}

/* The surface: drawn once in Regolith, with the night side shaded over it. */
.i-body { fill: var(--surface); }
.i-night { fill: var(--night); fill-opacity: 0.66; }
.i-mare { fill: url(#lm-stipple); }
.i-dot { fill: var(--regolith); fill-opacity: 0.2; }
.i-shadows { fill: var(--crater-shadow); }
.i-void { fill: var(--void); }
.i-hatch { fill: url(#lm-hatch); }
.i-core { fill: var(--sodium); }
.i-probe { fill: var(--sodium); }
.i-axle { fill: var(--dust); }

.i-rim,
.i-contour,
.i-mare-edge,
.i-peak-ring,
.i-rille,
.i-rays,
.i-rays-far,
.i-hachures,
.i-limb,
.i-cut,
.i-void-edge,
.i-ring,
.i-fine,
.i-carrier-track,
.i-teeth,
.i-bolts,
.i-balls,
.i-core-ring,
.i-phantom,
.i-orbit,
.i-orbit-halo,
.i-probe-ring {
  fill: none;
}

.i-rim {
  stroke: var(--regolith);
  stroke-opacity: 0.72;
  stroke-width: calc(1.3px * var(--k));
}

.i-contour {
  stroke: var(--regolith);
  stroke-opacity: 0.46;
  stroke-width: calc(1.05px * var(--k));
}

.i-hachures {
  stroke: var(--regolith);
  stroke-opacity: 0.42;
  stroke-width: calc(1px * var(--k));
}

.i-rays {
  stroke: var(--regolith);
  stroke-opacity: 0.55;
  stroke-width: calc(1.2px * var(--k));
  stroke-dasharray: 2 4;
}

.i-rays-far {
  stroke: var(--regolith);
  stroke-opacity: 0.3;
  stroke-width: calc(1px * var(--k));
  stroke-dasharray: 1.5 5.5;
}

.i-mare-edge {
  stroke: var(--regolith);
  stroke-opacity: 0.22;
  stroke-width: calc(1px * var(--k));
  stroke-dasharray: 3 4;
}

.i-peak-ring {
  stroke: var(--regolith);
  stroke-opacity: 0.5;
  stroke-width: calc(1.1px * var(--k));
  stroke-dasharray: 7 5 2 5;
}

.i-rille {
  stroke: var(--regolith);
  stroke-opacity: 0.4;
  stroke-width: calc(1px * var(--k));
}

.i-limb {
  stroke: var(--regolith);
  stroke-opacity: 0.85;
  stroke-width: calc(1.6px * var(--k));
}

/* A faint rim over the night side, so the silhouette holds against the page. */
.i-limb-night {
  fill: none;
  stroke: var(--dust);
  stroke-opacity: 0.4;
  stroke-width: calc(1.2px * var(--k));
}

.i-cut {
  stroke: var(--regolith);
  stroke-width: calc(2.2px * var(--k));
}

.i-cut-ticks {
  stroke: var(--regolith);
  stroke-opacity: 0.7;
  stroke-width: calc(1.2px * var(--k));
}

.i-hatch-line {
  stroke: var(--dust);
  stroke-opacity: 0.4;
  stroke-width: calc(1.1px * var(--k));
}

.i-void-edge {
  stroke: var(--dust);
  stroke-opacity: 0.6;
  stroke-width: calc(1.2px * var(--k));
}

.i-ring {
  stroke: var(--regolith);
  stroke-opacity: 0.6;
  stroke-width: calc(1.15px * var(--k));
}

.i-fine {
  stroke: var(--dust);
  stroke-opacity: 0.6;
  stroke-width: calc(0.95px * var(--k));
}

.i-carrier-track {
  stroke: var(--dust);
  stroke-opacity: 0.35;
  stroke-width: calc(1px * var(--k));
  stroke-dasharray: 2 5;
}

.i-teeth {
  stroke: var(--dust);
  stroke-opacity: 0.7;
  stroke-width: 10px;
}

.i-bolts {
  stroke: var(--dust);
  stroke-opacity: 0.75;
  stroke-width: 5px;
  stroke-linecap: round;
}

.i-balls {
  stroke: var(--dust);
  stroke-opacity: 0.4;
  stroke-width: 17px;
  stroke-linecap: round;
}

.i-core-ring {
  stroke: var(--sodium);
  stroke-opacity: 0.45;
  stroke-width: calc(1.25px * var(--k));
}

.i-phantom {
  stroke: var(--dust);
  stroke-width: calc(1.25px * var(--k));
  stroke-dasharray: 6 5;
}

.i-leader {
  stroke: var(--dust);
  stroke-opacity: 0.6;
  stroke-width: calc(1.2px * var(--k));
  stroke-dasharray: 2 4;
}

.i-orbit {
  stroke: var(--dust);
  stroke-width: calc(1.3px * var(--k));
}

.i-orbit-halo {
  stroke: var(--basalt);
  stroke-width: calc(8px * var(--k));
}

.i-ticks {
  stroke: var(--dust);
  stroke-width: calc(1.2px * var(--k));
}

.i-probe-ring {
  stroke: var(--sodium);
  stroke-opacity: 0.5;
  stroke-width: calc(1.3px * var(--k));
}

/* Where the probe rests when nothing moves: on the near arc, in front of the moon. */
.i-probe-x { transform: translateX(270px); }
.i-probe-y { transform: translateY(83px); }

/* Gears turn about their own centres (each sits at its group's origin). */
.i-rot {
  transform-box: view-box;
  transform-origin: 0 0;
}

/* First projects --------------------------------------------------------- */

.projects {
  padding-block: clamp(4rem, 10cqw, 9rem) clamp(5rem, 12cqw, 10rem);
}

.projects p {
  max-width: 30ch;
  margin: 0 0 0 var(--inst-left);
  font-size: clamp(1.375rem, 1rem + 1.2cqw, 2rem);
  line-height: 1.35;
  text-wrap: pretty;
}

/* Footer ------------------------------------------------------------------ */

.site-footer {
  padding-block: 2rem 2.5rem;
  border-top: 1px solid var(--hairline);
  font-size: 0.9375rem;
}

.site-footer p {
  margin: 0;
}

.footer-name {
  font-weight: 500;
}

.footer-tagline {
  color: var(--dust);
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.5rem;
  margin: 1.25rem 0 0;
  padding: 0;
  list-style: none;
}

.footer-links a,
.prose a {
  color: var(--dust);
  text-decoration: underline;
  text-decoration-color: rgb(166 158 145 / 0.5);
  text-underline-offset: 0.2em;
  transition: color 150ms ease;
}

.footer-links a:hover,
.prose a:hover {
  color: var(--regolith);
}

/* Legal pages and 404 ----------------------------------------------------- */

.prose {
  max-width: 65ch;
  padding-block: clamp(3rem, 8cqw, 6rem) clamp(4rem, 10cqw, 8rem);
}

.prose h1 {
  font-size: clamp(2.25rem, 1.4rem + 3cqw, 3.75rem);
  line-height: 1;
  text-wrap: balance;
}

.prose h2 {
  margin: 2.75rem 0 0.75rem;
  font-size: 1.1875rem;
  font-weight: 500;
  line-height: 1.3;
}

.prose p,
.prose address,
.prose ul {
  margin: 0 0 1rem;
}

.prose address {
  font-style: normal;
}

.prose ul {
  padding-left: 1.25rem;
}

.prose .meta {
  margin-top: 1.25rem;
  font-family: var(--mono);
  font-size: 0.8125rem;
  font-stretch: 100%;
  color: var(--dust);
}

.not-found h1 {
  font-size: clamp(2.5rem, 1.2rem + 5cqw, 5.5rem);
}

.not-found p {
  margin-top: 1.5rem;
  font-size: 1.25rem;
}

/* Smaller screens: text first, then the moon rising ----------------------- */

@media (max-width: 1023px) {
  .hero {
    display: block;
    min-height: 0;
    padding: clamp(1.5rem, 6cqw, 3rem) 0 0;
  }

  .instrument {
    --k: 1.4;
    width: min(100cqw, 44rem);
    margin: clamp(3rem, 10cqw, 5rem) 0 0 auto;
  }

  .instrument .readout {
    padding-inline: var(--gutter);
  }

  .projects p {
    margin-left: var(--gutter);
    margin-right: var(--gutter);
  }

  .headline {
    font-size: clamp(3.25rem, 1rem + 7.2cqw, 5.25rem);
  }
}

@media (min-width: 720px) and (max-width: 1023px) {
  .instrument {
    margin-right: 0;
  }
}

@media (max-width: 480px) {
  .headline {
    font-stretch: 88%;
    font-size: clamp(2.5rem, 1rem + 8.4cqw, 3.25rem);
  }

  .contact {
    gap: 1rem;
  }

  .button {
    width: 100%;
  }
}

/* Motion: one reveal on load, two slow loops. None of it under reduced motion. */

@media (prefers-reduced-motion: no-preference) {
  .i-draw > * {
    stroke-dasharray: 1;
    stroke-dashoffset: 1;
    animation: lm-draw 2s var(--ease) forwards;
  }

  .d1 > * { animation-delay: 150ms; }
  .d2 > * { animation-delay: 250ms; }
  .d3 > * { animation-delay: 350ms; }
  .d4 > * { animation-delay: 450ms; }
  .d5 > * { animation-delay: 550ms; }
  .d6 > * { animation-delay: 650ms; }

  .i-fade {
    animation: lm-fade 1.6s ease 900ms both;
  }

  .i-panel {
    animation: lm-lift 1.6s var(--ease) 600ms both;
  }

  .i-leader {
    animation: lm-fade 0.8s ease 1.6s both;
  }

  .i-machinery {
    animation: lm-fade 1.4s var(--ease) 800ms both;
  }

  .i-core {
    animation: lm-fade 0.9s ease 1.7s both;
  }

  /* True planetary ratios, from design/instrument.py: the ring gear is fixed. */
  .i-sun { animation: lm-spin 150s linear infinite; }
  .i-carrier { animation: lm-spin 431.2s linear infinite; }
  .i-planet { animation: lm-spin 100.6s linear infinite reverse; }

  .i-probe-x { animation: lm-orbit-x 45s var(--sine) infinite alternate; }
  .i-probe-y { animation: lm-orbit-y 45s var(--sine) -22.5s infinite alternate; }

  .instrument.is-paused * {
    animation-play-state: paused !important;
  }
}

@keyframes lm-draw {
  to { stroke-dashoffset: 0; }
}

@keyframes lm-lift {
  from { transform: translate(-26px, 26px); }
}

@keyframes lm-fade {
  from { opacity: 0; }
}

@keyframes lm-spin {
  to { transform: rotate(360deg); }
}

@keyframes lm-orbit-x {
  from { transform: translateX(-540px); }
  to { transform: translateX(540px); }
}

@keyframes lm-orbit-y {
  from { transform: translateY(-96px); }
  to { transform: translateY(96px); }
}

/* Windows high contrast and other forced palettes. */

@media (forced-colors: active) {
  .instrument { color: CanvasText; }
  .i-body, .i-void, .i-hatch, .i-mare, .i-shadows { fill: Canvas; }
  .i-night { fill: Canvas; fill-opacity: 0; }
  .instrument [class^="i-"]:not(.i-body, .i-void, .i-hatch, .i-mare, .i-shadows, .i-night, .i-core, .i-probe, .i-axle),
  .instrument ellipse { stroke: CanvasText; }
  .i-core, .i-probe, .m-core { fill: Highlight; }
  .m-disc { fill: CanvasText; }
  .m-letter { stroke: CanvasText; }
  .i-orbit-halo { stroke: Canvas; }
  .button { border: 2px solid ButtonText; }
}
