/*
 * style.css — the layout and type of the Design Machine website (design.statemachines.app): the landing page
 * drawn as round 3, "Silent" (design/screens/site/r3-silent/), the Install docs page and the 404 page.
 *
 * Linked from every page site/build.mjs writes, after /tokens.css (brand/kit/tokens/tokens.css, copied in by the
 * build), which sets the colours as --dm-* custom properties: light by default, dark under prefers-color-scheme.
 * Measures are the drawing's, halved: it was drawn at 2x on a 1440 pt page, so 96 px there is 48 px here.
 * The page is a 1440 px column; below 900 px the grids drop columns, and below 600 px the phone layout takes over
 * (no phone layout was drawn). Departure Mono only at 11 or 22 px, its brand sizes, so its pixels stay whole.
 */

/* Departure Mono, self-hosted (SIL Open Font License, /fonts/OFL-DepartureMono.txt). Caslon comes from Google. */
@font-face {
  font-family: "Departure Mono";
  src: url("/fonts/DepartureMono-Regular.otf") format("opentype");
  font-display: swap;
}

/*
 * Page-wide measures and the two theme-dependent type settings. --m is the margin; --track opens Caslon by
 * 0.01 em on dark, where light type reads heavier, and --word-track is the wordmark's (−0.005 em plus that).
 * --strip-rule is the readout strips' rule, a 32% mix of type into ground (chart.strip in the brand kit).
 */
:root {
  --m: 48px;
  --track: 0em;
  --word-track: -0.005em;
  --strip-rule: color-mix(in srgb, var(--dm-ground), var(--dm-text) 32%);
  /* The ground's grain, a fine mono noise laid over the ground in overlay so its average colour stays the token's. */
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='g' color-interpolation-filters='sRGB'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='.5 0 0 0 .25 .5 0 0 0 .25 .5 0 0 0 .25 0 0 0 0 1'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23g)'/%3E%3C/svg%3E");
}
@media (prefers-color-scheme: dark) {
  :root { --track: 0.01em; --word-track: 0.005em; }
}

/* ---- Base ------------------------------------------------------------------------------------------------- */
* { box-sizing: border-box; }
html { background: var(--dm-ground); color: var(--dm-text); }
body {
  margin: 0;
  background-color: var(--dm-ground);
  background-image: var(--grain);
  background-blend-mode: overlay;
  color: var(--dm-text);
  font-family: var(--dm-font-text);
  font-size: 18px;
  line-height: 1.36;
  letter-spacing: var(--track);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
img { display: block; width: 100%; height: auto; }
figure { margin: 0; }
a { color: inherit; }
::selection { background: var(--dm-text); color: var(--dm-ground); }
:focus-visible { outline: 2px solid var(--dm-text); outline-offset: 3px; }

/* The 1440 px column every section sits in. */
.page { max-width: 1440px; margin: 0 auto; }

/*
 * The drawing sets every line from the top of its capitals (the engine's rule, src/engine/type.ts). Trimming each
 * line box to cap height and baseline does the same here, so the drawn offsets carry over as plain margins.
 * Browsers without text-box (Firefox, for now) set these lines a few px lower.
 */
.readout > span, .nav-docs, .foot-links a, .facts dt, .facts dd, .term code, .button > span, .lockup .word {
  text-box: trim-both cap alphabetic;
}

/* ---- The chart: mark, lockup, strips, readouts ------------------------------------------------------------ */
/* The mark stands on the wordmark's baseline (the lockup aligns baselines; an SVG's is its bottom edge), as tall
   as the capitals. */
.mark { display: block; flex: none; width: 16px; height: 16px; margin-right: 4px; }
.mark .ink { fill: var(--dm-text); }
.mark .madder { fill: var(--dm-signal); }
.lockup {
  display: inline-flex;
  align-items: baseline;
  font-family: var(--dm-font-display);
  font-size: 24px;
  line-height: 1;
  letter-spacing: var(--word-track);
  text-decoration: none;
  white-space: nowrap;
}
.lockup-foot { font-size: 22px; }

/* A readout strip: rules in --strip-rule, filled squares in the type colour, the rest bare ground. */
.strip { display: block; flex: none; }
.strip .r { fill: var(--strip-rule); }
.strip .on { fill: var(--dm-text); }
.strip .off { fill: var(--dm-ground); }

/* A readout row: Departure Mono 11 px, axis then value; "right" rows end in a strip flush right, its foot on the
   text's baseline (align-items: baseline puts an SVG's bottom edge there). */
.readout {
  display: flex;
  align-items: baseline;
  font-family: var(--dm-font-mono);
  font-size: 11px;
  line-height: 11px;
  letter-spacing: 0;
  white-space: pre;
}
.readout .axis { flex: none; width: 40px; }
.readout-right .strip { margin-left: auto; }

/* ---- Buttons --------------------------------------------------------------------------------------------- */
/* The primary button: ground-coloured Caslon on a type-coloured fill, corners a tenth of its height. */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--dm-text);
  color: var(--dm-ground);
  font-family: var(--dm-font-text);
  letter-spacing: var(--track);
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
}
.button:hover { background: color-mix(in srgb, var(--dm-text) 86%, var(--dm-ground)); }
.button-nav { width: 200px; height: 44px; border-radius: 4.5px; font-size: 15px; }
.button-big { width: 500px; height: 110px; border-radius: 11px; font-size: 44px; flex: none; }

/* ---- Nav bar ---------------------------------------------------------------------------------------------- */
.nav {
  max-width: 1440px;
  height: 72px;
  margin: 0 auto;
  padding: 0 var(--m);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}
/* Cap tops as drawn: the lockup's at 26 px, Docs' at 30.5 px; the button 14 px down, centred in the bar. */
.lockup-nav { margin-top: 26px; }
.nav-links { display: flex; align-items: flex-start; gap: 28px; margin-top: 14px; }
.nav-docs { margin-top: 16.5px; }
.nav-docs { font-size: 15px; line-height: 1; text-decoration: none; }
.nav-docs:hover, .foot-links a:hover { text-decoration: underline; text-underline-offset: 3px; }

/* ---- Hero: the specimen grid with a tab per row ------------------------------------------------------------ */
.hero { position: relative; max-width: 1440px; margin: 0 auto; }
/* Each tab is the ground reaching into the grid at the top left of its row (rows start at 0, 416, 831 and 1247 px
   of the 1656 px grid). It holds the row's strip of 16, its surface and its ink share. */
.tab {
  position: absolute;
  left: 0;
  width: calc(var(--m) + 190px);
  height: 62px;
  padding: 14px 0 0 var(--m);
  background: var(--dm-ground);
}
.tab-1 { top: 25.121%; }
.tab-2 { top: 50.181%; }
.tab-3 { top: 75.302%; }
.tab-0 { top: 0; }
.tab .readout { margin-top: 9px; }
.tab .readout-ink { margin-top: 7px; }
.tab .axis { width: 28px; }
/* The ink share was measured per theme; show the figure for the plate on screen. */
.ink-dark { display: none; }
@media (prefers-color-scheme: dark) {
  .ink-dark { display: inline; }
  .ink-light { display: none; }
}

/* ---- Posters ----------------------------------------------------------------------------------------------- */
.posters {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 40px 24px;
  padding: 100px var(--m) 120px;
}
.posters figcaption, .setting figcaption { margin-top: 18px; }

/* ---- Demo still --------------------------------------------------------------------------------------------- */
.demo { padding: 100px var(--m) 100px; }
/* A hairline round the window, so its edge reads on a ground close to its own colour. */
.frame { position: relative; }
.frame::after { content: ""; position: absolute; inset: 0; border: 1px solid var(--dm-line); pointer-events: none; }

/* ---- One setting turned: the cell size ---------------------------------------------------------------------- */
.setting { padding: 102px var(--m) 125px; }
.ctl-label { color: var(--dm-muted); }
/* The track shares the tiles' columns, so each tick stands over its tile's centre; the thumb is a square. */
.track {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  column-gap: 16px;
  height: 2px;
  margin-top: 30px;
  background: var(--dm-line);
}
.tick { justify-self: center; position: relative; width: 2px; height: 14px; margin-top: -6px; background: var(--dm-line); }
.tick.at::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -4px;
  width: 22px;
  height: 22px;
  transform: translateX(-50%);
  background: var(--dm-text);
}
.tiles { display: grid; grid-template-columns: repeat(6, 1fr); gap: 40px 16px; margin-top: 46px; }

/* ---- Export sizes: one poster at four sizes, one scale ------------------------------------------------------ */
/* Each figure is its pixel width times one scale: the row's width less its gaps, over the sum of the four widths
   (4940 px). They stand on one baseline, like prints on a shelf. */
.exports {
  container-type: inline-size;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 40px 24px;
  padding: 100px var(--m) 110px;
}
.exports figure { flex: none; width: calc(var(--w) * (100cqw - 72px) / 4940); }
.exports figcaption { margin-top: 18px; color: var(--dm-muted); }
.shelf-break { display: none; flex-basis: 100%; height: 0; }

/* ---- Gallery: justified rows -------------------------------------------------------------------------------- */
/* A piece grows by its aspect ratio from zero, so the row's pieces share one height and fill the row. */
.gallery { padding: 100px var(--m) 87px; }
.row { display: flex; gap: 16px; }
.row + .row { margin-top: 31px; }
.row figure { flex: var(--r) 1 0; min-width: 0; }
.gallery figcaption { margin-top: 14px; color: var(--dm-muted); }

/* ---- Download ------------------------------------------------------------------------------------------------ */
.download { padding: 120px var(--m) 226px; }
.dl-top { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 32px 48px; }
/* The build's facts in Departure Mono 22 px: the name muted in a fixed column, the value in type colour. */
.facts { margin: 0; padding-top: 4px; font-family: var(--dm-font-mono); font-size: 22px; line-height: 1; letter-spacing: 0; }
.facts div { display: flex; }
.facts div + div { margin-top: 14px; }
.facts dt { width: 140px; flex: none; color: var(--dm-muted); }
.facts dd { margin: 0; white-space: nowrap; }

/* The Terminal line on a raised field, with its copy button. */
.term {
  display: flex;
  width: fit-content;
  align-items: center;
  gap: 24px;
  max-width: 100%;
  min-height: 48px;
  margin-top: 36px;
  padding: 0 18px;
  border-radius: 6px;
  background: var(--dm-surface-2);
  font-family: var(--dm-font-mono);
  font-size: 11px;
  line-height: 15px;
  letter-spacing: 0;
}
.term code { font: inherit; white-space: pre-wrap; overflow-wrap: anywhere; }
.copy {
  flex: none;
  margin: 0;
  padding: 6px 0;
  border: 0;
  background: none;
  color: var(--dm-muted);
  font: inherit;
  cursor: pointer;
}
.copy:hover { color: var(--dm-text); }

/* ---- Footer -------------------------------------------------------------------------------------------------- */
.foot {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  height: 110px;
  margin: 0 var(--m);
  padding-top: 40px;
  border-top: 1px solid var(--dm-line);
}
.foot-links { display: flex; flex-wrap: wrap; gap: 12px 28px; padding-top: 3px; }
.foot-links a { color: var(--dm-muted); font-size: 15px; line-height: 1; text-decoration: none; }

/* ---- Docs pages ---------------------------------------------------------------------------------------------- */
/* The column is wide enough for the Terminal line at 11 px; paragraphs keep a 640 px measure. */
.doc { max-width: 900px; padding: 72px var(--m) 120px; }
.doc h1 {
  margin: 0 0 32px;
  font-family: var(--dm-font-display);
  font-size: 52px;
  font-weight: 400;
  line-height: 1.04;
  letter-spacing: calc(-0.008em + var(--track));
}
.doc h2 {
  margin: 48px 0 12px;
  font-family: var(--dm-font-display);
  font-size: 30px;
  font-weight: 400;
  line-height: 1.04;
  letter-spacing: var(--track);
}
.doc p { max-width: 640px; margin: 0 0 14px; }
.doc p a { text-decoration-color: var(--dm-line-2); text-underline-offset: 3px; }
.doc p a:hover { text-decoration-color: currentColor; }
.doc .term { margin: 4px 0 18px; padding: 8px 18px; }

/* ---- Below 900 px: fewer columns ------------------------------------------------------------------------------ */
@media (max-width: 899px) {
  .posters { grid-template-columns: repeat(2, 1fr); }
  .tiles, .track { grid-template-columns: repeat(3, 1fr); }
  .tick:nth-child(n + 4) { display: none; }
  /* Two shelves, story and Instagram over thumbnail and X header, both at the wider shelf's scale (2780 px). */
  .shelf-break { display: block; }
  .exports figure { width: calc(var(--w) * (100cqw - 24px) / 2780); }
}

/* ---- Below 600 px: the phone ----------------------------------------------------------------------------------- */
@media (max-width: 599px) {
  :root { --m: 16px; }
  .nav { height: 56px; }
  .lockup-nav { font-size: 20px; margin-top: 21px; }
  .lockup-nav .mark { width: 14px; height: 14px; margin-right: 3px; }
  .nav-links { gap: 16px; margin-top: 11px; }
  .nav-docs { font-size: 14px; margin-top: 12px; }
  .button-nav { width: auto; height: 34px; padding: 0 12px; border-radius: 3.5px; font-size: 14px; }

  /* The grid is a quarter of the width per plate here, so each tab keeps only its surface. */
  .tab { width: auto; height: auto; padding: 5px 8px 5px var(--m); }
  .tab .strip, .tab .readout-ink { display: none; }
  .tab .readout { margin-top: 0; }

  .posters { gap: 32px 12px; padding: 64px var(--m) 48px; }
  .demo { padding: 48px var(--m); }
  .setting { padding: 48px var(--m); }
  .tiles { gap: 28px 12px; }
  .track { column-gap: 12px; }
  .setting .strip { display: none; }
  .exports { gap: 28px 12px; padding: 48px var(--m); }
  .exports figure { width: calc(var(--w) * (100cqw - 12px) / 2780); }
  .gallery { padding: 48px var(--m); }
  .row { flex-direction: column; gap: 28px; }

  .download { padding: 48px var(--m) 64px; }
  .button-big { width: 100%; height: 80px; border-radius: 8px; font-size: 30px; }
  .facts { font-size: 11px; line-height: 11px; padding-top: 0; }
  .facts div + div { margin-top: 7px; }
  .facts dt { width: 70px; }
  .term { display: flex; padding: 12px 14px; }

  .foot { flex-direction: column; height: auto; gap: 20px; padding: 28px 0 40px; }
  .doc { padding: 40px var(--m) 72px; }
  .doc h1 { font-size: 40px; }
  .doc h2 { font-size: 26px; margin-top: 36px; }
  .doc p { font-size: 17px; }
}
