/* ============================================================
   XYMEX STUDIO
   One stylesheet. Zero JavaScript. Zero third-party bytes.
   Fully black — there is deliberately no light-mode branch.
   ============================================================ */

/* --- Fonts ------------------------------------------------- */
@font-face {
  font-family: "Space Grotesk";
  src: url("/fonts/space-grotesk-var.woff2") format("woff2-variations");
  font-weight: 400 700;
  font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("/fonts/jetbrains-mono-var.woff2") format("woff2-variations");
  font-weight: 400 500;
  font-display: swap;
}

/* --- Tokens ------------------------------------------------ */
:root {
  --void:       #000000;
  --surface-1:  #0A0A0B;
  --surface-2:  #111113;
  --hairline:   rgba(255, 255, 255, 0.08);
  --text:       #EDEDED;
  --text-dim:   #8A8A8F;
  --signal:     #00FF9C;

  --font-display: "Space Grotesk", system-ui, sans-serif;
  --font-mono:    "JetBrains Mono", ui-monospace, monospace;

  /* Fluid type scale, 320px → 1440px viewport */
  --step-0: clamp(0.94rem, 0.90rem + 0.20vw, 1.05rem);
  --step-1: clamp(1.13rem, 1.05rem + 0.38vw, 1.38rem);
  --step-2: clamp(1.35rem, 1.21rem + 0.68vw, 1.80rem);
  --step-3: clamp(1.62rem, 1.39rem + 1.15vw, 2.37rem);
  --step-4: clamp(1.94rem, 1.58rem + 1.82vw, 3.11rem);
  --step-5: clamp(2.33rem, 1.77rem + 2.79vw, 4.09rem);

  --shell: 68rem;
  --gutter: clamp(1.25rem, 4vw, 3rem);
}

/* --- Reset ------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

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

body {
  background: var(--void);
  color: var(--text);
  font-family: var(--font-display);
  font-size: var(--step-0);
  line-height: 1.6;
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

img, svg { display: block; max-width: 100%; height: auto; }
a { color: inherit; }

/* --- Grain --------------------------------------------------
   Non-optional: true-black gradients band visibly on OLED and
   grain is the standard mitigation. Inline SVG data-URI, which
   `img-src 'self' data:` permits.
   ----------------------------------------------------------- */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

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

.mono {
  font-family: var(--font-mono);
  font-size: 0.78em;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.dim { color: var(--text-dim); }

/* --- Focus --------------------------------------------------
   Must be clearly visible on pure black.
   ----------------------------------------------------------- */
:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 3px;
  border-radius: 2px;
}

/* --- Skip link --------------------------------------------- */
.skip {
  position: absolute;
  left: -9999px;
}
.skip:focus {
  left: var(--gutter);
  top: var(--gutter);
  z-index: 10000;
  background: var(--surface-2);
  padding: 0.75rem 1.25rem;
  border: 1px solid var(--hairline);
}

/* ============================================================
   LOGO — real extruded 3D mark, rendered by self-hosted three.js
   (site/logo.js). The flat SVG below is the default, visible state:
   it stays put under reduced motion or when WebGL is unavailable,
   and three.js crossfades the canvas over it once the first frame
   has rendered.
   ============================================================ */
.mark {
  width: 15rem;
  height: 15rem;
  position: relative;
  flex: none;
}

.mark__mount {
  position: absolute;
  inset: -20%;
}

.mark__mount canvas {
  opacity: 0;
  transition: opacity 300ms ease;
}
.mark__mount--ready canvas { opacity: 1; }

.mark__fallback {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transition: opacity 300ms ease;
}
.mark__fallback--hidden { opacity: 0; }

@media (max-width: 40rem) {
  .mark { width: 10rem; height: 10rem; }
}

@media (prefers-reduced-motion: reduce) {
  .mark__mount canvas,
  .mark__fallback { transition: none; }
}

/* ============================================================
   LAYOUT
   ============================================================ */
.skip-target { outline: none; }

section { padding-block: clamp(4rem, 10vw, 8rem); }

.rule {
  border-top: 1px solid var(--hairline);
}

h1, h2, h3 { font-weight: 600; line-height: 1.08; letter-spacing: -0.02em; }
h1 { font-size: var(--step-5); }
h2 { font-size: var(--step-3); }
h3 { font-size: var(--step-2); }

p { max-width: 60ch; }

.lede { font-size: var(--step-1); color: var(--text-dim); }
.lede--spaced { margin-top: 1.5rem; }

/* View-transition hooks.
   These MUST be classes, never inline style attributes: the CSP sets
   `style-src 'self'` with no `style-src-attr` and no 'unsafe-inline',
   which blocks inline style attributes outright. */
.vt-downshift { view-transition-name: card-downshift; }
.vt-goad      { view-transition-name: card-goad; }
.vt-lucy      { view-transition-name: card-lucy; }
.vt-crew      { view-transition-name: card-crew; }

/* Section index labels — the schematic register */
.idx {
  display: block;
  margin-bottom: 1.5rem;
  color: var(--text-dim);
}

/* --- Hero --------------------------------------------------- */
.hero {
  min-height: min(88svh, 46rem);
  display: flex;
  align-items: center;
  padding-block: clamp(3rem, 8vw, 6rem);
}
.hero__inner {
  display: flex;
  align-items: center;
  gap: clamp(2rem, 6vw, 5rem);
  flex-wrap: wrap;
}
.hero__copy { flex: 1 1 22rem; }
.hero h1 { margin-bottom: 1.5rem; }

/* --- Status pill -------------------------------------------- */
.status {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  color: var(--text-dim);
}
.status::before {
  content: "";
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: currentColor;
}
/* --signal appears ONLY here, only on shipped products. */
.status--live {
  color: var(--signal);
  border-color: color-mix(in srgb, var(--signal) 35%, transparent);
}
.status--live::before { animation: pulse 2.4s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1;   box-shadow: 0 0 0 0 color-mix(in srgb, var(--signal) 50%, transparent); }
  50%      { opacity: 0.6; box-shadow: 0 0 0 0.35rem transparent; }
}

/* --- Product cards ------------------------------------------ */
/* Four products. Explicit breakpoints rather than auto-fit so the count is
   always even (1, then 2x2, then 4-up) and no card is ever stranded alone on
   a row stretching full width. */
.cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1px;
  background: var(--hairline);
  border: 1px solid var(--hairline);
}
@media (min-width: 32rem) { .cards { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 60rem) { .cards { grid-template-columns: repeat(4, 1fr); } }
.card {
  background: var(--surface-1);
  padding: clamp(1.5rem, 3vw, 2.25rem);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  text-decoration: none;
  transition: background 220ms steps(4, end);
}
.card:hover, .card:focus-visible { background: var(--surface-2); }
.card h3 { margin-top: 0.25rem; }
.card p { flex: 1; color: var(--text-dim); font-size: var(--step-0); }

.card__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1rem;
  color: var(--text-dim);
  border-top: 1px solid var(--hairline);
  padding-top: 1rem;
}

/* --- Footer -------------------------------------------------- */
.foot {
  border-top: 1px solid var(--hairline);
  padding-block: 3rem;
  color: var(--text-dim);
}
.foot__inner {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  justify-content: space-between;
  align-items: center;
}
.foot a { text-decoration-color: var(--hairline); text-underline-offset: 0.3em; }
.foot a:hover { color: var(--text); }

@media (prefers-reduced-motion: reduce) {
  .status--live::before { animation: none; }
  .card { transition: none; }
}

/* ============================================================
   CASE STUDY
   ============================================================ */
.case__hero { padding-block: clamp(4rem, 10vw, 7rem); }
.case__hero h1 { margin: 1rem 0 1.5rem; }

/* `block` + fit-content, NOT inline-block: as an inline-level box the
   following .status pill sat on the same line and margin-bottom collapsed
   against it, so the back link and the status pill ran together. */
.back {
  display: block;
  width: fit-content;
  margin-bottom: 2rem;
  color: var(--text-dim);
  text-decoration: none;
}
.back:hover { color: var(--text); }

.spec {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 1px;
  background: var(--hairline);
  border: 1px solid var(--hairline);
  margin-block: 2.5rem;
}
.spec > div {
  background: var(--surface-1);
  padding: 1.25rem;
}
.spec dt { color: var(--text-dim); margin-bottom: 0.4rem; }
.spec dd { margin: 0; }

.prose > * + * { margin-top: 1.25rem; }
.prose h2 { margin-top: 3rem; }

.out {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 2.5rem;
}
.out a {
  padding: 0.7rem 1.25rem;
  border: 1px solid var(--hairline);
  text-decoration: none;
  transition: background 200ms steps(4, end);
}
.out a:hover { background: var(--surface-2); }
.out a.primary {
  border-color: color-mix(in srgb, var(--signal) 40%, transparent);
  color: var(--signal);
}

@media (prefers-reduced-motion: reduce) {
  .out a { transition: none; }
}

/* ============================================================
   MOTION — pure enhancement
   The finished state is the default. Everything below may be
   deleted and the site must remain fully correct.
   ============================================================ */

/* Cross-document View Transitions. Opt-in via CSS; no JS. */
@view-transition { navigation: auto; }

::view-transition-group(*) {
  animation-duration: 320ms;
  animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
}

/* Telemetry reveal — scroll-driven, gated behind @supports so a
   browser without animation-timeline simply renders the end state. */
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {

    @keyframes settle {
      from { opacity: 0; transform: translateY(1.25rem); }
      to   { opacity: 1; transform: translateY(0); }
    }

    .card,
    .spec > div,
    .prose h2,
    .prose p {
      animation: settle linear both;
      animation-timeline: view();
      animation-range: entry 8% cover 26%;
    }

    /* Cards index in one after another, like a machine seating parts */
    .card:nth-child(2) { animation-range: entry 4% cover 24%; }
    .card:nth-child(3) { animation-range: entry 0% cover 22%; }
  }
}

@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) { animation: none !important; }
  .card, .status, .spec > div { view-transition-name: none !important; }
}
