/* Swarm: the shared design system. Every page loads this file; page-specific styles live in their own files. */

/* ---------- Tokens ---------- */
:root {
  --bg: #000;
  --fg: #f5f5f5;
  --mute: rgba(255, 255, 255, .64);
  --dim: rgba(255, 255, 255, .5);     /* the spec's .42 is 3.9:1 on black and fails AA for small labels */
  --line: rgba(255, 255, 255, .13);
  --red: #ff2e3e;
  --red-strong: #d6001c;              /* button fill: white on it is 5.4:1; on --red it would be 3.7:1 */
  --live: #3ddc84;
  --sans: 'Inter Tight', system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --pad: clamp(20px, 4vw, 56px);
  --nav-h: 80px;
  color-scheme: dark;
}

/* ---------- Fonts ---------- */
/* Self-hosted variable fonts (OFL, licenses next to the files): the latin subsets of @fontsource-variable 5.3.0. */
@font-face {
  font-family: 'Inter Tight';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('/assets/fonts/inter-tight-latin-wght-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
    U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 100 800;
  font-display: swap;
  src: url('/assets/fonts/jetbrains-mono-latin-wght-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
    U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

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

html {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  scroll-behavior: smooth;
  /* Whatever the page scrolls to (a deep link, a footnote, the field or link that takes keyboard focus) stops below
     the fixed nav instead of under it. The 24px clear the nav's fade, and Chrome's slack: for a text field it reveals
     the caret line, not the box, so at exactly the nav's height a field's border and focus ring stayed under it. */
  scroll-padding-top: calc(var(--nav-h) + 24px);
}

a { color: inherit; text-decoration: none; }
img, svg, video, canvas { display: block; max-width: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
::selection { background: var(--red-strong); color: #fff; }

/* The content layer: above the swarm canvas, below the nav. */
.page { position: relative; z-index: 1; }

/* ---------- Swarm ---------- */
/* One canvas behind the whole page; the engine sizes its bitmap to this box. The height is the large viewport, so
   the box stays put (and the canvas isn't cleared) while a phone's toolbars slide in and out. */
#swarm {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 0;
  width: 100%;
  height: 100vh;
  height: 100lvh;
  pointer-events: none;
}

/* Pauses and resumes the swarm (WCAG 2.2.2): a quiet mono label, in the hero foot and the footer. It stays hidden
   until site.js finds motion to pause. The padding makes a 25px-tall target. */
.swarm-toggle {
  flex: none;
  padding: 5px 0;
  border: 0;
  background: none;
  font: 11.5px/1.3 var(--mono);
  letter-spacing: .14em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--mute);
  cursor: pointer;
  transition: color .2s;
}
.swarm-toggle:hover { color: var(--fg); }

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

/* ---------- Focus and skip link ---------- */
:focus-visible { outline: 2px solid var(--red); outline-offset: 3px; }

/* Waits above the viewport and slides in just below the nav, where it covers neither the brand nor a link. */
.skip {
  position: fixed;
  top: var(--nav-h);
  left: var(--pad);
  z-index: 100;
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--fg);
  color: #000;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.2;
  transform: translateY(calc(-100% - var(--nav-h) - 10px));
  transition: transform .2s;
}
.skip:focus { transform: none; }

/* ---------- Nav ---------- */
.nav {
  position: fixed;
  inset: 0 0 auto;
  z-index: 10;
  height: var(--nav-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 var(--pad);
  line-height: 1.2;
}
/* Fades whatever scrolls underneath, so the nav stays legible without a hard edge. */
.nav::before {
  content: "";
  position: absolute;
  inset: 0 0 -40px;
  z-index: -1;
  background: linear-gradient(#000 10%, rgba(0, 0, 0, 0));
  pointer-events: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -.01em;
  white-space: nowrap;
}
.brand svg { flex: none; height: 15px; width: auto; aspect-ratio: 500 / 406; fill: var(--red); }

.nav__links {
  display: flex;
  align-items: center;
  gap: 28px;
  font-size: 13.5px;
  color: var(--mute);
}
.nav__links a { transition: color .2s, border-color .2s; }
.nav__links a:not(.pill) { padding: 8px 0; }   /* a taller hit area, no visual change */
.nav__links a:hover { color: var(--fg); }

.pill {
  padding: 8px 14px;
  border: 1px solid rgba(255, 255, 255, .28);
  border-radius: 999px;
  color: var(--fg);
  white-space: nowrap;
}
.pill:hover { border-color: rgba(255, 255, 255, .6); }

/* Phones keep the brand and the pill. */
@media (max-width: 820px) {
  .nav__links a:not(.pill) { display: none; }
}

/* ---------- Buttons ---------- */
/* The transparent border keeps the button's shape visible in forced-colors mode, which drops backgrounds. */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 21px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--red-strong);
  color: #fff;
  font: 600 14.5px/1.2 var(--sans);
  white-space: nowrap;
  cursor: pointer;
  transition: transform .2s, border-color .2s;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: none; }

.btn--ghost {
  background: transparent;
  color: var(--fg);
  border-color: rgba(255, 255, 255, .28);
}
.btn--ghost:hover { border-color: rgba(255, 255, 255, .6); }

/* ---------- Icons ---------- */
/* → and ↗ are drawn: the self-hosted latin subsets have ↑ and ↓ but no other arrows. */
.icon {
  flex: none;
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform .2s;
}
.btn:hover .icon { transform: translateX(2px); }

/* ---------- Labels ---------- */
/* The weight is set so a heading can be a label too: <h2 class="label">. */
.mono, .label {
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 400;
  line-height: 1.3;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--dim);
}

/* A section label: <p class="label"><b>01</b> Why we exist</p>. Keep the space after </b>: it is the gap,
   and it makes the label read "01 Why we exist" to screen readers and to innerText. */
.label { margin-bottom: 28px; }
.label b { margin-right: 2px; font-weight: inherit; color: var(--red); }

/* boqo stays lowercase inside uppercase labels: <span class="nocase">boqo</span>. */
.nocase { text-transform: none; }

/* ---------- Hero: the first screen of the home page and of the 404 ---------- */
/* The words sit at the bottom; the swarm gets the space above them, and draws the mark at .hero__mark, on the right.
   The eyebrow and the headline keep out of the mark's column (--mark-w plus a 2vw gap), so the particles never form
   over them, even where the window is too short for the words to stay below the mark (a phone on its side, a page
   zoomed to 400%). The mark is never wider than half the window is tall, so on a short, wide window it ends above the
   row that follows the headline, whose button sits on the right. */
.hero {
  --mark-w: min(22.5vw, 380px, 50vh);
  position: relative;
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: calc(var(--nav-h) + 48px) var(--pad) 84px;
}

.hero__mark {
  position: absolute;
  top: max(17vh, var(--nav-h) + 12px);
  right: var(--pad);
  width: var(--mark-w);
  aspect-ratio: 500 / 406;
}

.hero__eyebrow { max-width: calc(100% - var(--mark-w) - 2vw); margin-bottom: 20px; }

.hero h1 {
  max-width: min(15.5ch, 100% - var(--mark-w) - 2vw);
  font-size: clamp(44px, 7.2vw, 124px);
  font-weight: 600;
  line-height: .92;
  letter-spacing: -.048em;
  text-shadow: 0 2px 40px rgba(0, 0, 0, .6);
}

/* A phone held upright: the mark goes above the headline, in the flow, so a long headline on a short screen pushes
   past it instead of running into it. A phone on its side keeps it on the right. */
@media (max-width: 820px) and (orientation: portrait) {
  .hero { padding-top: calc(var(--nav-h) + 12px); }
  .hero__mark {
    position: static;
    flex: none;
    width: min(56vw, 360px);
    margin: auto;
  }
  .hero__eyebrow { max-width: none; margin-top: 36px; }
  .hero h1 { max-width: 15.5ch; }
}

/* ---------- Tags and chips ---------- */
.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 22px;
  list-style: none;
}
.tags li, .chip {
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(0, 0, 0, .5);
  font: 11px/1.3 var(--mono);
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--mute);
}

.chip { display: inline-flex; align-items: center; gap: 8px; }
.chip__dot {
  flex: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--live);
  box-shadow: 0 0 10px var(--live);
}
.chip--link {
  border-color: rgba(255, 255, 255, .3);
  color: var(--fg);
  transition: border-color .2s;
}
.chip--link:hover { border-color: rgba(255, 255, 255, .6); }
.chip--link .icon { width: 12px; height: 12px; }
.chip--link:hover .icon { transform: translate(1px, -1px); }

/* ---------- The lab's topics and its empty state (the home page and /lab/) ---------- */
.topics {
  margin-top: 40px;
  border-top: 1px solid var(--line);
  list-style: none;
}
.topic {
  display: grid;
  grid-template-columns: 52px 1fr auto;
  align-items: baseline;
  gap: 14px;
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}
.topic__num { font: 12px/1.3 var(--mono); color: var(--red); }
.topic__name { font-size: 20px; line-height: 1.3; letter-spacing: -.015em; }
.topic__state {
  font: 10.5px/1.3 var(--mono);
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--dim);
}

/* The honest empty state, with a hollow dot: nothing is live yet. */
.lab__empty {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 26px;
  font-size: 14px;
  color: var(--dim);
}
.lab__empty::before {
  content: "";
  flex: none;
  width: 7px;
  height: 7px;
  border: 1px solid var(--dim);
  border-radius: 50%;
}

@media (max-width: 820px) {
  .topic { grid-template-columns: 36px 1fr; gap: 4px 10px; }
  .topic__state { grid-column: 2; }
}

/* ---------- Fig. 1: the agent loop (the home page and /lab/) ---------- */
/* The swarm runs the loop round .loop__fig (the `ring` formation). Its steps sit at four points 38% out from the
   centre, and each name sits just outside its step. */
.loop {
  --gap-x: 26px;
  --gap-y: 22px;
  justify-self: center;
  width: min(100%, 520px);
}
.loop__fig { position: relative; aspect-ratio: 1; }
/* Without the script there is no swarm to draw the loop, so a hairline ring through the four steps stands in. */
html:not(.js) .loop__fig::before {
  content: "";
  position: absolute;
  inset: 12%;
  border: 1px solid rgba(255, 255, 255, .28);
  border-radius: 50%;
}
.loop__node {
  position: absolute;
  font: 11px/1.3 var(--mono);
  letter-spacing: .16em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--mute);
}
.loop__node--observe { top: 12%; left: 50%; transform: translate(-50%, calc(-100% - var(--gap-y))); }
.loop__node--decide { top: 50%; left: 88%; transform: translate(var(--gap-x), -50%); }
.loop__node--act { top: 88%; left: 50%; transform: translate(-50%, var(--gap-y)); }
.loop__node--verify { top: 50%; left: 12%; transform: translate(calc(-100% - var(--gap-x)), -50%); color: var(--red); }
.loop__caption { margin-top: 30px; text-align: center; }

/* A narrower figure: room beside it for Decide and Verify, which stick out past its sides. The gaps keep each name
   clear of its step's cluster, 15 px round. */
@media (max-width: 1000px) {
  .loop { padding-inline: 24px; }
}
@media (max-width: 600px) {
  .loop { --gap-x: 18px; --gap-y: 16px; width: 100%; padding-inline: 48px; }
}

/* ---------- Footer ---------- */
.footer {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px 32px;
  padding: 24px var(--pad);
  border-top: 1px solid var(--line);
  background: var(--bg);
  font-size: 13px;
  color: var(--dim);
}
.footer__links { display: flex; flex-wrap: wrap; gap: 22px; }
.footer__links a { padding: 4px 0; transition: color .2s; }
.footer__links a:hover { color: var(--fg); }

@media (max-width: 820px) {
  .footer { flex-direction: column; align-items: flex-start; }
}

/* ---------- 404 ---------- */
/* The hero (above), with a label for an eyebrow and a short headline, balanced if it wraps. */
.notfound h1 { text-wrap: balance; }
.notfound__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
  margin-top: 30px;
}
.notfound__row p {
  max-width: 46ch;
  font-size: clamp(15px, 1.3vw, 18px);
  color: var(--mute);
}

/* The particle count and the pause toggle, along the bottom edge. */
.notfound__foot {
  position: absolute;
  right: var(--pad);
  bottom: 26px;
  display: flex;
  align-items: center;
  gap: 8px 24px;
}

@media (max-width: 820px) {
  .notfound__row { flex-direction: column; align-items: flex-start; }
  .notfound__foot { left: var(--pad); justify-content: space-between; }
  .notfound__foot .swarm-toggle { margin-left: auto; }   /* stays on the right when the count hides */
}
