/* Base: reset, layout, type, nav, buttons, focus, cursor, reduced motion. */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scrollbar-color: var(--gold-deep) var(--ink-deep);
  scrollbar-width: thin;
}

html:not(.lenis) { scroll-behavior: smooth; }
html.lenis, html.lenis body { height: auto; }
.lenis.lenis-stopped { overflow: clip; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(120% 60% at 70% 0%, oklch(0.20 0.05 265 / 0.9), transparent 60%),
    radial-gradient(90% 50% at 10% 55%, oklch(0.18 0.04 220 / 0.55), transparent 65%),
    radial-gradient(100% 60% at 50% 100%, oklch(0.19 0.045 300 / 0.6), transparent 60%),
    var(--ink);
  background-attachment: fixed;
  color: var(--bone);
  font-family: var(--f-body);
  font-size: var(--t-body);
  line-height: 1.6;
  font-weight: 400;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}

/* Static star field for the no-WebGL path: drawn once by CSS, hidden when the sky runs. */
.starfield {
  position: fixed;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  background-image:
    radial-gradient(1px 1px at 12% 18%, oklch(0.95 0.02 85 / 0.8), transparent 60%),
    radial-gradient(1px 1px at 28% 72%, oklch(0.95 0.02 85 / 0.6), transparent 60%),
    radial-gradient(1.5px 1.5px at 41% 33%, oklch(0.95 0.02 85 / 0.7), transparent 60%),
    radial-gradient(1px 1px at 57% 84%, oklch(0.95 0.02 85 / 0.5), transparent 60%),
    radial-gradient(1px 1px at 66% 12%, oklch(0.95 0.02 85 / 0.8), transparent 60%),
    radial-gradient(1.5px 1.5px at 79% 46%, oklch(0.90 0.05 85 / 0.7), transparent 60%),
    radial-gradient(1px 1px at 88% 78%, oklch(0.95 0.02 85 / 0.6), transparent 60%),
    radial-gradient(1px 1px at 94% 22%, oklch(0.95 0.02 85 / 0.5), transparent 60%),
    radial-gradient(1px 1px at 6% 52%, oklch(0.95 0.02 85 / 0.6), transparent 60%),
    radial-gradient(1px 1px at 35% 95%, oklch(0.95 0.02 85 / 0.5), transparent 60%);
  background-size: 420px 420px, 380px 380px, 520px 520px, 460px 460px, 340px 340px,
    600px 600px, 400px 400px, 300px 300px, 360px 360px, 500px 500px;
}
.sky-on .starfield { display: none; }

#sky {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  display: block;
  pointer-events: none;
}

img, svg, video, canvas { display: block; max-width: 100%; }
svg { overflow: visible; }

h1, h2, h3, h4, p, figure, blockquote, ol, ul, dl, dd { margin: 0; }
ol, ul { padding: 0; list-style: none; }

h1, h2, h3 {
  font-family: var(--f-display);
  font-weight: 400;
  line-height: 1.04;
  letter-spacing: -0.015em;
  text-wrap: balance;
  color: var(--bone);
}
p { text-wrap: pretty; }

a { color: inherit; text-decoration-color: var(--rule); text-underline-offset: 0.22em; text-decoration-thickness: 1px; }
a:hover { text-decoration-color: var(--gold); }

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }

::selection { background: var(--gold); color: var(--gold-ink); }

:focus { outline: none; }
:focus-visible {
  outline: 1.5px solid var(--gold);
  outline-offset: 4px;
  border-radius: 4px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

.skip {
  position: fixed;
  left: var(--gutter);
  top: var(--s-3);
  z-index: 100;
  padding: var(--s-3) var(--s-5);
  background: var(--gold);
  color: var(--gold-ink);
  font-family: var(--f-mono);
  font-size: var(--t-label);
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  text-decoration: none;
  border-radius: 999px;
  transform: translateY(-160%);
  transition: transform var(--d-ui) var(--ease-out);
}
.skip:focus-visible { transform: none; }

/* ---------- Layout ---------- */

.wrap {
  width: 100%;
  max-width: var(--max);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

main { display: block; }
section[id], .draw__stage, .draw__result { scroll-margin-top: 92px; }

/* ---------- Instrument labels ---------- */

.label {
  font-family: var(--f-mono);
  font-size: var(--t-label);
  line-height: 1.4;
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--mute);
  font-variant-numeric: tabular-nums;
}
.label--gold { color: var(--gold); }

/* A rule with engraved ticks, like the edge of a star chart. */
.ticks {
  height: 9px;
  background:
    linear-gradient(var(--rule), var(--rule)) left 50% / 100% 1px no-repeat,
    repeating-linear-gradient(90deg, var(--rule) 0 1px, transparent 1px 12px) left 50% / 100% 5px no-repeat,
    repeating-linear-gradient(90deg, var(--gold-deep) 0 1px, transparent 1px 60px) left 50% / 100% 9px no-repeat;
}

/* ---------- Top bar ---------- */

.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 40;
  pointer-events: none;
}
.topbar__in {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
  padding-block: var(--s-4);
}
.topbar a, .topbar button { pointer-events: auto; }
.topbar::before {
  content: "";
  position: absolute;
  inset: 0 0 -44px 0;
  background: linear-gradient(oklch(0.11 0.028 280) calc(100% - 44px), transparent);
  z-index: -1;
}

.monogram {
  display: inline-flex;
  align-items: center;
  gap: var(--s-3);
  min-height: 44px;
  text-decoration: none;
  color: var(--gold);
}
.monogram svg { width: 40px; height: 40px; }
.monogram__name {
  font-family: var(--f-mono);
  font-size: var(--t-label);
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--bone-2);
}

@media (max-width: 39.99em) { .monogram__name { display: none; } }

.topbar__actions { display: flex; align-items: center; gap: var(--s-3); }

.menu-btn {
  display: none;
  min-width: 44px;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  font-family: var(--f-mono);
  font-size: var(--t-label);
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--bone);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 0 var(--s-4);
}
.js .menu-btn { display: inline-flex; }
@media (min-width: 64em) { .js .menu-btn { display: none; } }

/* ---------- Buttons ---------- */

.btn {
  --pad-x: 1.6em;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.75em;
  min-height: 48px;
  padding: 0.85em var(--pad-x);
  border-radius: 999px;
  font-family: var(--f-mono);
  font-size: 0.8125rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  text-decoration: none;
  line-height: 1.2;
  white-space: nowrap;
  isolation: isolate;
  overflow: hidden;
  transition: color var(--d-ui) var(--ease-out), border-color var(--d-ui) var(--ease-out), transform var(--d-ui) var(--ease-out);
}
.btn svg { width: 1.1em; height: 1.1em; flex: none; }

.btn--primary {
  background: var(--gold);
  color: var(--gold-ink);
  box-shadow: 0 10px 24px -14px oklch(0.04 0.03 280 / 0.9);
}
/* The foil: only here and on cards. */
.btn--primary::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--foil);
  background-size: 250% 100%;
  background-position: 100% 0;
  opacity: 0;
  transition: opacity 0.4s var(--ease-out), background-position 1.2s var(--ease-out);
}
.btn--primary:hover::before,
.btn--primary:focus-visible::before { opacity: 1; background-position: 0 0; }
.btn--primary:active { transform: scale(0.98); }

.btn--ghost {
  color: var(--bone);
  border: 1px solid var(--rule);
  background: oklch(0.13 0.03 280 / 0.4);
}
.btn--ghost:hover { border-color: var(--gold); color: var(--gold); }

.btn--small { min-height: 44px; font-size: 0.75rem; --pad-x: 1.25em; }

.textlink {
  display: inline-flex;
  align-items: center;
  gap: 0.6em;
  min-height: 44px;
  font-family: var(--f-mono);
  font-size: 0.8125rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--bone-2);
  text-decoration: underline;
  text-decoration-color: var(--rule);
  text-underline-offset: 0.5em;
}
.textlink:hover { color: var(--gold); text-decoration-color: var(--gold); }

/* ---------- Side rail (desktop) ---------- */

.rail {
  display: none;
}
@media (min-width: 64em) {
  .js .rail {
    position: fixed;
    right: clamp(0.75rem, 1.4vw, 1.75rem);
    top: 50%;
    z-index: 30;
    display: flex;
    flex-direction: column;
    gap: 2px;
    transform: translateY(-50%);
  }
}
.rail a {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--s-3);
  width: 44px;
  height: 30px;
  text-decoration: none;
}
.rail a::after {
  content: "";
  width: 14px;
  height: 1px;
  background: var(--mute);
  opacity: 0.6;
  transition: width var(--d-ui) var(--ease-out), background-color var(--d-ui), opacity var(--d-ui);
}
.rail a span {
  position: absolute;
  right: 26px;
  white-space: nowrap;
  font-family: var(--f-mono);
  font-size: 0.6875rem;
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--bone-2);
  opacity: 0;
  transform: translateX(6px);
  transition: opacity var(--d-ui) var(--ease-out), transform var(--d-ui) var(--ease-out);
  pointer-events: none;
}
.rail a:hover span, .rail a:focus-visible span { opacity: 1; transform: none; }
.rail a:hover::after { width: 22px; opacity: 1; }
.rail a[aria-current="true"]::after { width: 26px; background: var(--gold); opacity: 1; }
.rail a[aria-current="true"] span { color: var(--gold); }

/* ---------- Mobile menu ---------- */

.menu {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  flex-direction: column;
  padding: var(--s-4) var(--gutter) var(--s-7);
  background:
    radial-gradient(80% 50% at 80% 0%, oklch(0.22 0.05 265), transparent 70%),
    var(--ink-deep);
  overflow-y: auto;
}
.menu.is-open { display: flex; }
.menu__top { display: flex; justify-content: space-between; align-items: center; }
.menu__list { margin-top: var(--s-7); display: grid; gap: 0; }
.menu__list a {
  display: grid;
  grid-template-columns: 3.2rem 1fr;
  align-items: baseline;
  padding-block: var(--s-3);
  border-bottom: 1px solid var(--rule-soft);
  text-decoration: none;
  font-family: var(--f-display);
  font-size: clamp(1.75rem, 7vw, 2.5rem);
  line-height: 1.15;
}
.menu__list a span:first-child {
  font-family: var(--f-mono);
  font-size: var(--t-label);
  letter-spacing: var(--track-label);
  color: var(--gold);
}
.menu__foot { margin-top: auto; padding-top: var(--s-7); }

/* ---------- Cursor ---------- */

.cursor {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 90;
  width: 28px;
  height: 28px;
  margin: -14px 0 0 -14px;
  border: 1px solid var(--gold);
  border-radius: 50%;
  pointer-events: none;
  opacity: 0;
  transition: width 0.35s var(--ease-out), height 0.35s var(--ease-out), margin 0.35s var(--ease-out), opacity 0.3s, background-color 0.35s;
}
.cursor.is-on { opacity: 0.9; }
.cursor.is-big {
  width: 56px;
  height: 56px;
  margin: -28px 0 0 -28px;
  background: oklch(0.80 0.11 85 / 0.08);
}
.cursor::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 3px;
  height: 3px;
  margin: -1.5px 0 0 -1.5px;
  border-radius: 50%;
  background: var(--gold);
}
@media (hover: none), (pointer: coarse) { .cursor { display: none; } }

/* SplitText masks: give descenders and swashes room so the clip never cuts a letter. */
.ch-mask { padding: 0 0.06em 0.32em; margin: 0 -0.06em -0.32em; }
.ln-split-mask { padding-bottom: 0.16em; margin-bottom: -0.16em; }

/* ---------- First paint before the intro runs ----------
   Hidden only under .js and only until main.js marks .motion-ready.
   If scripts never get there, the failsafe shows everything after 2.5 s. */
@keyframes failsafe { to { opacity: 1; } }
@media (prefers-reduced-motion: no-preference) {
  .js:not(.motion-ready) .hero__name,
  .js:not(.motion-ready) .hero__line,
  .js:not(.motion-ready) .hero__more,
  .js:not(.motion-ready) .hero__figure {
    opacity: 0;
    animation: failsafe 0.01s linear 2.5s forwards;
  }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  html:not(.lenis) { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
