/* ==========================================================================
   SPACeR project site — Applied Intuition brand design system
   Adapted from the TerraZero technical-report site so the two read as one.
   Type: Applied Sans (Display for title/headings, Text for body/labels),
   XCharter serif for body/figure surfaces. Color: Applied Blue #006CFA,
   ink #111, gray #767676. Motifs: black-square eyebrow marker, ~720px
   reading column, full-width figure bands, blue caption labels.
   ========================================================================== */

/* ----- Fonts (vendored, local; siblings of this file under static/) ------ */
@font-face {
  font-family: "Applied Sans Display";
  src: url("../fonts/AppliedSansDisplay-Bold.ttf") format("truetype");
  font-weight: 700; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Applied Sans Display";
  src: url("../fonts/AppliedSansDisplay-SemiBold.ttf") format("truetype");
  font-weight: 600; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Applied Sans Text";
  src: url("../fonts/AppliedSansText-Regular.ttf") format("truetype");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Applied Sans Text";
  src: url("../fonts/AppliedSansText-Italic.ttf") format("truetype");
  font-weight: 400; font-style: italic; font-display: swap;
}
@font-face {
  font-family: "Applied Sans Text";
  src: url("../fonts/AppliedSansText-SemiBold.ttf") format("truetype");
  font-weight: 600; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Applied Sans Text";
  src: url("../fonts/AppliedSansText-SemiBoldItalic.ttf") format("truetype");
  font-weight: 600; font-style: italic; font-display: swap;
}
@font-face {
  font-family: "XCharter";
  src: url("../fonts/XCharter-Roman.otf") format("opentype");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "XCharter";
  src: url("../fonts/XCharter-Italic.otf") format("opentype");
  font-weight: 400; font-style: italic; font-display: swap;
}

/* ----- Design tokens ----------------------------------------------------- */
:root {
  /* brand color */
  --blue: #006CFA;
  --blue-dark: #0052bd;
  --blue-muted: #3d7fc4;
  --blue-wash: #eef4ff;
  --blue-wash-2: #e0ecff;
  --ink: #111111;
  --gray: #767676;
  --gray-line: #e4e4e4;
  --gray-soft: #f6f7f9;
  --white: #ffffff;

  /* type */
  --font-display: "Applied Sans Display", "Helvetica Neue", Arial, sans-serif;
  --font-sans: "Applied Sans Text", "Helvetica Neue", Arial, sans-serif;
  --font-serif: "XCharter", Georgia, "Times New Roman", serif;
  --font-mono: "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, monospace;

  /* type scale */
  --fs-eyebrow: 0.72rem;
  --fs-meta: 0.82rem;
  --fs-body: 1.0625rem;
  --fs-lead: 1.3rem;
  --fs-h3: 1.18rem;
  --fs-h2: 2.2rem;
  --fs-title: clamp(2.05rem, 5vw, 3.6rem);

  /* spacing */
  --space-1: 0.5rem;
  --space-2: 1rem;
  --space-3: 1.5rem;
  --space-4: 2.5rem;
  --space-5: 4rem;
  --space-6: 6rem;

  /* layout */
  --reading: 720px;
  --wide: 1280px;
  --header-h: 60px;
  --header-gap: 14px;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(17,17,17,.04), 0 8px 28px rgba(17,17,17,.07);
  --shadow-lift: 0 2px 6px rgba(17,17,17,.06), 0 18px 48px rgba(0,108,250,.10);
}

/* ----- Reset / base ------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--header-h) + var(--header-gap) + 16px); }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}
body {
  margin: 0;
  font-family: var(--font-serif);
  font-size: var(--fs-body);
  line-height: 1.62;
  color: var(--ink);
  background: var(--white);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}
img, svg { max-width: 100%; height: auto; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
strong, b { font-weight: 600; }

/* ----- Layout primitives ------------------------------------------------- */
.reading { max-width: var(--reading); margin-inline: auto; padding-inline: 24px; }
.wide { max-width: var(--wide); margin-inline: auto; padding-inline: 24px; }
.bleed { width: min(1680px, 96vw); margin-inline: auto; padding-inline: 24px; }
/* Body text fills the wide band by default, aligning with the figure/table
   edges; only constrain the measure when text shares a row with a figure.
   Justified with automatic hyphenation (LaTeX-style) so the right edge stays
   even rather than ragged. (hyphens: auto relies on the <html lang="en">.) */
.prose {
  max-width: none;
  text-align: justify;
  text-justify: inter-word;
  -webkit-hyphens: auto;
  hyphens: auto;
}

/* big stat callouts */
.statline {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
  margin: var(--space-3) 0;
}
.statline .stat-num {
  font-family: var(--font-display); font-weight: 700;
  font-size: clamp(2rem, 4vw, 3rem); line-height: 1; color: var(--blue);
  letter-spacing: -0.02em;
}
.statline .stat-cap {
  font-family: var(--font-sans); font-size: var(--fs-meta);
  color: var(--gray); margin-top: 0.35em;
}
.statline > div { border-top: 2px solid var(--ink); padding-top: 0.6rem; }

@media (max-width: 860px) {
  .statline { grid-template-columns: 1fr 1fr; }
}
/* On very small screens cap long inline formulas and let them scroll. */
@media (max-width: 480px) {
  mjx-container[display="true"] { overflow-x: auto; overflow-y: hidden; }
}

section { padding-block: var(--space-6); }
section + section { border-top: 1px solid var(--gray-line); }
/* Content sections alternate tint automatically by position; the hero stays
   plain, so add/remove a section and the rhythm fixes itself. */
main > section:not(.hero):nth-of-type(odd) { background: var(--gray-soft); }

/* eyebrow + black square motif */
.eyebrow {
  font-family: var(--font-mono);
  font-size: 0.86rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gray);
  display: flex;
  align-items: center;
  gap: 0.6em;
  margin: 0 0 var(--space-2);
}
.eyebrow::before {
  content: "";
  display: inline-block;
  width: 0.5em; height: 0.5em;
  background: var(--ink);
  flex: 0 0 auto;
}

/* ----- Typography -------------------------------------------------------- */
h1, h2, h3 { font-family: var(--font-display); color: var(--ink); line-height: 1.12; }
h2 {
  font-weight: 600;
  font-size: var(--fs-h2);
  letter-spacing: -0.01em;
  margin: 0 0 var(--space-3);
}
h3 {
  font-weight: 600;
  font-size: var(--fs-h3);
  letter-spacing: -0.005em;
  margin: var(--space-4) 0 var(--space-1);
}
p { margin: 0 0 var(--space-2); }
ul, ol { margin: 0 0 var(--space-2); padding-left: 1.3em; }
li { margin-bottom: 0.35em; }
.lead {
  font-size: var(--fs-lead);
  line-height: 1.5;
  color: #2a2a2a;
}
.muted { color: var(--gray); }

/* editorial highlight: a soft marker swipe under the lower half of the text */
mark.hl {
  background: linear-gradient(transparent 56%, var(--blue-wash-2) 56%);
  color: inherit;
  padding: 0 0.05em;
}
.lead mark.hl { background: linear-gradient(transparent 60%, var(--blue-wash-2) 60%); }

/* SPACeR acronym accent — Applied Blue (was the template's orange) */
.spacer-brand { color: var(--blue); font-weight: 700; }

/* display-equation wrapper: scroll only when an equation is too wide */
.eq-block { margin: var(--space-3) 0; overflow-x: auto; overflow-y: hidden; }
.eq-block mjx-container { margin: 0 !important; }

/* ----- Header / nav ------------------------------------------------------ */
/* Floating frosted-glass "pill" header (Applied Intuition style): fixed and
   inset from the edges, fully rounded; stays fully visible at all scroll
   positions. On mobile it collapses to a brand circle + hamburger overlay. */
.site-header {
  position: fixed; inset: 0 0 auto 0; z-index: 50;
  padding: var(--header-gap) 16px;
  pointer-events: none;
}
.header-pill {
  position: relative;
  pointer-events: auto;
  max-width: var(--wide); margin-inline: auto;
  height: var(--header-h);
  display: flex; align-items: center; gap: var(--space-3);
  padding-inline: 22px;
}
.header-pill::before {
  content: ""; position: absolute; inset: 0; z-index: 0;
  border-radius: 999px;
  background: rgba(255,255,255,.72);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  backdrop-filter: saturate(160%) blur(14px);
  border: 1px solid rgba(17,17,17,.07);
  box-shadow: var(--shadow);
}

.brand-mark, .nav, .nav-toggle { position: relative; z-index: 1; }

.brand-mark {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  color: var(--ink);
  display: flex; align-items: center; gap: 0.55em;
  flex: 0 0 auto;
  height: 100%;
  border-radius: 999px;
  background: transparent;
  border: 1px solid transparent;
  box-shadow: none;
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  backdrop-filter: saturate(160%) blur(14px);
  transition: background-color .4s ease, border-color .4s ease,
              box-shadow .4s ease, width .4s cubic-bezier(.22,.61,.36,1),
              gap .4s cubic-bezier(.22,.61,.36,1);
}
.brand-mark::before {
  content: ""; width: 1.15em; height: 1.15em; display: inline-block;
  flex: 0 0 auto;
  background: var(--ink);
  -webkit-mask: url(../brand/icon.svg) center / contain no-repeat;
  mask: url(../brand/icon.svg) center / contain no-repeat;
}
.brand-mark:hover { text-decoration: none; }
.brand-word {
  max-width: 12em; overflow: hidden; white-space: nowrap;
  transition: max-width .4s cubic-bezier(.22,.61,.36,1), opacity .3s ease, margin .4s ease;
}
.site-footer .brand-mark::before { background: #fff; }

.nav { margin-left: auto; display: flex; gap: var(--space-3); align-items: center;
  transition: opacity .3s ease; }
.nav a {
  font-family: var(--font-sans);
  font-size: var(--fs-meta);
  color: var(--gray);
  letter-spacing: 0.01em;
}
.nav a:hover { color: var(--ink); text-decoration: none; }
.nav a.active { color: var(--ink); font-weight: 600; }
.nav-toggle { display: none; }

/* ----- Hero -------------------------------------------------------------- */
.hero { padding-top: calc(var(--header-h) + var(--header-gap) + var(--space-4)); padding-bottom: var(--space-4); }

.hero-intro { max-width: 60rem; }
.hero h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--fs-title);
  letter-spacing: -0.02em;
  line-height: 1.04;
  color: var(--ink);
  margin: 0 0 var(--space-3);
  overflow-wrap: break-word;
  hyphens: auto;
}
.byline, .affil { overflow-wrap: break-word; }
.hero h1 .accent { color: var(--blue); }

.hero .lead {
  max-width: 56ch;
  font-size: clamp(1.25rem, 2.2vw, 1.5rem);
  line-height: 1.45;
  color: #2a2a2a;
  margin-bottom: var(--space-4);
}

/* masthead metadata, set off from the lead by a thin editorial rule */
.hero-meta {
  border-top: 1px solid var(--gray-line);
  padding-top: var(--space-3);
}
.hero-meta > :first-child { margin-top: 0; }
.byline {
  font-family: var(--font-mono);
  font-size: var(--fs-meta);
  color: var(--gray);
  margin: var(--space-3) 0 var(--space-1);
  line-height: 1.7;
}
.byline .names { color: var(--ink); }
.byline a { color: var(--ink); }
.affil { font-family: var(--font-mono); font-size: var(--fs-eyebrow); color: var(--gray); }

/* action buttons */
.actions { display: flex; flex-wrap: wrap; gap: 0.7rem; margin-top: var(--space-3); }
.btn {
  font-family: var(--font-sans);
  font-size: var(--fs-meta);
  font-weight: 600;
  display: inline-flex; align-items: center; gap: 0.45em;
  padding: 0.6em 1.05em;
  border-radius: 8px;
  border: 1px solid var(--gray-line);
  background: var(--white);
  color: var(--ink);
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .05s;
}
.btn:hover { border-color: var(--blue); color: var(--blue); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--blue); border-color: var(--blue); color: var(--white); }
.btn-primary:hover { background: var(--blue-dark); border-color: var(--blue-dark); color: var(--white); }
.btn svg { width: 1em; height: 1em; }

/* greyed-out actions for resources not available yet */
.btn-disabled {
  color: var(--gray); background: var(--gray-soft);
  border-color: var(--gray-line); cursor: not-allowed; opacity: 0.75;
  user-select: none;
}
.btn-disabled:hover { color: var(--gray); border-color: var(--gray-line); }
.foot-pending { color: var(--gray); cursor: not-allowed; }

/* ----- Figure bands / captions ------------------------------------------ */
.figure-band { padding-block: var(--space-5); }
.figure {
  margin: var(--space-3) 0;
  background: var(--white);
  border: 1px solid var(--gray-line);
  border-radius: var(--radius);
  overflow: hidden;
}
.figure-stage {
  padding: var(--space-3);
  display: flex; justify-content: center; align-items: center;
  background: linear-gradient(var(--gray-soft), var(--gray-soft));
}
.figure-stage svg, .figure-stage img { display: block; max-width: 100%; }
figcaption {
  font-family: var(--font-sans);
  font-size: var(--fs-meta);
  color: #333;
  line-height: 1.5;
  padding: var(--space-2) var(--space-3);
  border-top: 1px solid var(--gray-line);
}
figcaption .fig-label {
  font-family: var(--font-sans);
  font-weight: 600;
  color: var(--blue);
  margin-right: 0.5em;
}

/* ----- Tables ------------------------------------------------------------ */
.table-wrap { overflow-x: auto; margin: var(--space-3) 0; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-sans);
  font-size: var(--fs-meta);
}
table.data caption {
  caption-side: bottom;
  text-align: left;
  color: #333;
  font-size: var(--fs-meta);
  line-height: 1.5;
  padding-top: var(--space-2);
}
table.data caption .fig-label { color: var(--blue); font-weight: 600; margin-right: 0.4em; }
table.data th, table.data td {
  padding: 0.55em 0.85em;
  text-align: right;
  border-bottom: 1px solid var(--gray-line);
  white-space: nowrap;
}
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data thead th {
  color: var(--ink);
  font-weight: 600;
  border-bottom: 2px solid var(--ink);
  user-select: none;
}
table.data tbody tr:hover { background: var(--blue-wash); }
table.data tbody tr.is-best td { font-weight: 600; }
table.data .group-row th {
  text-align: left;
  background: var(--gray-soft);
  font-family: var(--font-mono);
  font-size: var(--fs-eyebrow);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gray);
}

/* ----- Three-up synchronized video comparison ---------------------------- */
.threeup { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-2); }
.threeup-cell { min-width: 0; }
.threeup-vid {
  position: relative; border: 1px solid var(--gray-line); border-radius: var(--radius);
  overflow: hidden; background: #0d1117;
}
.threeup-vid video { display: block; width: 100%; height: auto; }
.threeup-cap { text-align: center; font-weight: 600; font-size: var(--fs-meta); margin: 0.4rem 0 0; }
.threeup-score { text-align: center; font-size: var(--fs-eyebrow); color: var(--gray); margin: 0.2rem 0 0; }
.threeup-legend {
  position: absolute; top: 8px; right: 8px; z-index: 2;
  background: rgba(255,255,255,.92); border: 1px solid var(--gray-line);
  border-radius: 6px; padding: 6px 9px; font-size: 12px;
  display: flex; flex-direction: column; gap: 5px;
}
.threeup-legend .row { display: flex; align-items: center; gap: 7px; }
.threeup-legend .sw { width: 16px; height: 11px; border: 1px solid #333; }
@media (max-width: 640px) { .threeup { grid-template-columns: 1fr; } }

/* row caption sitting above each comparison grid */
.row-note {
  font-family: var(--font-serif);
  font-style: italic;
  color: #555;
  text-align: center;
  max-width: 80ch;
  margin: var(--space-3) auto var(--space-2);
}

/* divider between comparison rows */
.row-sep { border: none; border-top: 1px solid var(--gray-line); margin: var(--space-4) 0; }

/* ----- Playback-speed segmented control (replaces the template's .select) - */
.speed-control {
  display: flex; align-items: center; justify-content: center; gap: 0.75rem;
  flex-wrap: wrap;
  margin: var(--space-3) 0;
  font-family: var(--font-sans);
}
.speed-control .speed-label {
  font-weight: 600; font-size: var(--fs-meta); color: var(--gray);
  text-transform: uppercase; letter-spacing: 0.08em;
}
/* one rounded track holding the speed options; a blue thumb slides behind the
   active option (its size/position are set in JS from the active button). */
.segmented {
  position: relative;
  display: inline-flex; gap: 4px; padding: 4px;
  background: var(--gray-soft);
  border: 1px solid var(--gray-line);
  border-radius: 999px;
}
.seg-slider {
  position: absolute; top: 0; left: 0; z-index: 0;
  border-radius: 999px; background: var(--blue); box-shadow: var(--shadow);
  transition: transform .28s cubic-bezier(.4, 0, .2, 1),
              width .28s cubic-bezier(.4, 0, .2, 1), height .28s;
}
.segmented .seg {
  position: relative; z-index: 1;
  border: 0; background: transparent; cursor: pointer;
  font-family: var(--font-sans); font-size: var(--fs-meta); font-weight: 600;
  color: var(--ink); padding: 0.4em 0.95em; border-radius: 999px;
  transition: color .2s;
}
.segmented .seg:hover:not(.is-active) { color: var(--blue); }
.segmented .seg.is-active { color: #fff; }

/* ----- Footer ------------------------------------------------------------ */
.site-footer {
  border-top: 1px solid var(--gray-line);
  background: var(--ink);
  color: #cfd3da;
  padding-block: var(--space-4);
  font-family: var(--font-sans);
  font-size: var(--fs-meta);
}
.site-footer a { color: #fff; }
.site-footer .foot-grid { display: flex; flex-wrap: wrap; gap: var(--space-4); justify-content: space-between; }
.site-footer .copyright { color: var(--gray); margin-top: var(--space-3); font-family: var(--font-mono); font-size: var(--fs-eyebrow); }

/* ----- Scroll reveal (progressive enhancement: hidden only when JS is on) - */
.js .reveal { opacity: 0; transform: translateY(14px); transition: opacity .5s ease, transform .5s ease; }
.js .reveal.in { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) {
  .js .reveal { opacity: 1; transform: none; transition: none; }
}

/* ----- Responsive: mobile header ----------------------------------------- */
@media (max-width: 820px) {
  :root { --header-h: 52px; }
  /* applied.co-style mobile: no connecting bar — two standalone frosted
     circles (brand left, menu right) with a full-screen overlay menu. */
  .header-pill::before { opacity: 0 !important; }
  .header-pill { padding-inline: 6px; gap: 0; }

  .brand-mark {
    width: var(--header-h); justify-content: center; gap: 0; z-index: 2;
    background: rgba(255,255,255,.82); border-color: rgba(17,17,17,.07);
    box-shadow: var(--shadow);
  }
  .brand-word { max-width: 0; opacity: 0; margin: 0; }

  .nav-toggle {
    display: inline-flex; margin-left: auto; z-index: 2;
    width: var(--header-h); height: var(--header-h); border-radius: 999px;
    align-items: center; justify-content: center; flex-direction: column; gap: 5px;
    background: rgba(255,255,255,.82); border: 1px solid rgba(17,17,17,.07);
    box-shadow: var(--shadow); cursor: pointer; padding: 0;
    -webkit-backdrop-filter: saturate(160%) blur(14px);
    backdrop-filter: saturate(160%) blur(14px);
  }
  .nav-toggle span {
    width: 20px; height: 2px; background: var(--ink); display: block; border-radius: 2px;
    transition: transform .25s ease, opacity .2s ease;
  }
  .nav-toggle[aria-expanded="true"] span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
  .nav-toggle[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
  .nav-toggle[aria-expanded="true"] span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

  .nav {
    position: fixed; inset: 0; margin: 0; z-index: 0;
    flex-direction: column; align-items: stretch; justify-content: center; gap: 0;
    padding: max(16vh, 110px) 34px calc(env(safe-area-inset-bottom) + 32px);
    background: rgba(255,255,255,.88);
    -webkit-backdrop-filter: saturate(160%) blur(22px);
    backdrop-filter: saturate(160%) blur(22px);
    opacity: 0; visibility: hidden; pointer-events: none;
    transition: opacity .28s ease, visibility 0s linear .28s;
  }
  .nav.open {
    opacity: 1; visibility: visible; pointer-events: auto;
    transition: opacity .28s ease;
  }
  .nav a {
    font-family: var(--font-display); font-size: 1.7rem; font-weight: 600;
    color: var(--ink); padding: 0.55em 0; border-bottom: 1px solid var(--gray-line);
  }
  .nav a:last-child { border-bottom: none; }

  section { padding-block: var(--space-5); }
  .hero { padding-top: calc(var(--header-h) + var(--header-gap) + var(--space-3)); }
}
body.nav-open { overflow: hidden; }
