/* ==========================================================================
   Reference Machines — landing
   ========================================================================== */

/* All fonts are self-hosted: the site makes no third-party requests. */
@font-face {
  font-family: 'Departure Mono';
  src: url('../fonts/DepartureMono-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/* Newsreader (variable: weight + optical size), split by subset */
@font-face {
  font-family: 'Newsreader';
  src: url('../fonts/Newsreader-latin.woff2') format('woff2');
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
  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: 'Newsreader';
  src: url('../fonts/Newsreader-latin-ext.woff2') format('woff2');
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  /* Colour */
  --ink: #2D2D2D;          /* text, logo, input text */
  --hairline: #747474;     /* hairlines, input borders, tags, placeholders */
  --accent: #51080A;       /* arrow square, input focus — nothing else */
  --paper: #F5F2EC;
  --brand: #ACCFBF;        /* logo colour: icon blocks and cursor (the canvases use it too) */

  /* Type */
  --font-mono: 'Departure Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;

  /* Departure Mono is drawn on an 11px grid: only use these sizes */
  --mono-s: 11px;
  --mono-m: 22px;
  --mono-l: 33px;
  --mono-field: 16.5px;   /* 1.5× — the one off-grid size: form text, ≥16px so iOS doesn't zoom on focus */

  /* Spacing (multiples of 11) */
  --s1: 11px;
  --s2: 22px;
  --s3: 33px;
  --s4: 44px;
  --s6: 66px;
  --s8: 88px;
  --s12: 132px;

  --gutter: clamp(16px, 4vw, 44px);
  --measure: 1040px;

  --ease: cubic-bezier(0.22, 0.7, 0.2, 1);
  --dur: 480ms;
}

*,
*::before,
*::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Newsreader', Georgia, serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  min-height: 100svh;
  overflow-x: clip;   /* the full-bleed data band is 100vw wide */
}

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

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
  border-radius: 0;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, p { margin: 0; font-weight: 400; }

:focus-visible {
  outline: 1px solid var(--ink);
  outline-offset: 6px;
}

/* --------------------------------------------------------------------------
   Mono UI
   -------------------------------------------------------------------------- */

.eyebrow,
.toggle,
.close,
.field label,
.field input,
.field textarea,
.cta,
.success {
  font-family: var(--font-mono);
  text-transform: uppercase;
  font-weight: 400;
  letter-spacing: 0;
  font-variant-ligatures: none;
}

/* --------------------------------------------------------------------------
   Header
   -------------------------------------------------------------------------- */

/* Header, page and footer share one centred column; everything aligns to its left edge */
.page,
.site-footer {
  max-width: calc(var(--measure) + 2 * var(--gutter));
  margin: 0 auto;
}

/* Full width, so the logo sits in the top-left corner of the window */
.site-header {
  padding: var(--s3) var(--gutter) 0;
}

.logo {
  display: inline-block;
  line-height: 0;
}

.logo svg {
  display: block;
  width: 185.4px;          /* 0.3× the source grid (618 wide) */
  height: auto;
}

/* Build-in: each glyph's outline is traced, then filled, in reading order */
.logo .glyph {
  stroke: var(--ink);
  stroke-width: 2.5;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  fill-opacity: 0;
  animation: glyph-build 900ms var(--ease) forwards;
  animation-delay: calc(200ms + var(--i) * 70ms);
}

@keyframes glyph-build {
  60%  { stroke-dashoffset: 0; fill-opacity: 0; stroke-opacity: 1; }
  100% { stroke-dashoffset: 0; fill-opacity: 1; stroke-opacity: 0; }
}

/* Icon: its blocks pop in one by one while the letters are built, the ink ones
   flashing the logo colour as they land (delays are set per block in the markup, --d) */
.logo .px {
  opacity: 0;
  transform-box: fill-box;
  transform-origin: center;
  animation: px-build 260ms steps(4, end) forwards;
  animation-delay: var(--d);
}

.logo .px--accent { animation-name: px-build-accent; }

.logo .px--accent,
.logo .cursor { fill: var(--brand); }

@keyframes px-build {
  0%   { opacity: 1; transform: scale(0.4); fill: var(--brand); }
  50%  { opacity: 1; transform: scale(1); fill: var(--brand); }
  100% { opacity: 1; transform: scale(1); fill: var(--ink); }
}

@keyframes px-build-accent {
  0%   { opacity: 1; transform: scale(0.4); }
  100% { opacity: 1; transform: scale(1); }
}

/* Cursor: appears once the last glyph is built, then blinks on/off */
.logo .cursor {
  opacity: 0;
  animation: cursor-blink 1.1s step-end 2.2s infinite;
}

@keyframes cursor-blink {
  0%   { opacity: 1; }
  50%  { opacity: 0; }
}

/* --------------------------------------------------------------------------
   Page
   -------------------------------------------------------------------------- */

.page {
  padding: 0 var(--gutter) var(--s12);
}

/* Hero sits above the optical centre, not dead centre */
.intro {
  padding: clamp(var(--s8), 16vh, 176px) 0 var(--s8);
}

.intro .subhero { margin-top: var(--s4); }

.hero {
  font-family: 'Newsreader', Georgia, serif;
  font-weight: 400;
  font-size: clamp(2.75rem, 1.2rem + 5.4vw, 6rem);
  line-height: 1.04;
  letter-spacing: -0.022em;
  text-wrap: balance;
  max-width: 15ch;
}

/* Permanent highlight, styled like the page's text selection */
.hero__mark {
  background: var(--ink);
  color: var(--paper);
  padding: 0 0.06em;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
  position: relative;   /* anchors the decode overlay */
}

/* EXPERIMENT — on hover the highlighted word turns into flickering 0s and 1s,
   then the next word in the list appears (js/hero-decode.js). The old word
   keeps its place while the bits show (only hidden), so the highlight holds
   its size until the new word lands. */
.hero__mark.is-decoding .decode__word { color: transparent; }

.decode__bits {
  position: absolute;
  inset: 0 0.06em;      /* the highlight's inner width, inside its padding */
  display: none;
  align-items: center;
  pointer-events: none;
}

.hero__mark.is-decoding .decode__bits { display: flex; }

.decode__bit {
  flex: 1;              /* bits evenly spaced across the word */
  text-align: center;
  font-family: var(--font-mono);   /* Departure Mono */
  font-size: var(--bit-size, 0.73em);   /* the script snaps this to Departure Mono's 11px pixel grid */
  line-height: 1;
  letter-spacing: 0;
}

.subhero {
  font-family: 'Newsreader', Georgia, serif;
  font-weight: 400;
  font-size: clamp(1.1875rem, 1rem + 0.8vw, 1.625rem);
  line-height: 1.38;
  letter-spacing: -0.005em;
  text-wrap: pretty;
  max-width: 30em;
}

/* --------------------------------------------------------------------------
   Arrow — 1px #747474 line ending in a 10×10 #51080A square.
   The line is flexible; the square is fixed.
   -------------------------------------------------------------------------- */

.arrow {
  display: flex;
  align-items: center;
}

.arrow__line {
  flex: 1 1 auto;
  height: 1px;
  background: var(--hairline);
}

.arrow__head {
  flex: 0 0 10px;
  width: 10px;
  height: 10px;
  background: var(--accent);
}

/* --------------------------------------------------------------------------
   Data band — full-bleed canvas between intro and contact (data-band.js)
   -------------------------------------------------------------------------- */

.data-band {
  width: 100vw;
  margin-left: calc(50% - 50vw);
  height: 312px;          /* JS sets the real height from its config */
  margin-bottom: var(--s8);
  touch-action: pan-y;    /* horizontal finger drags reach the canvas; vertical still scrolls */
}

.data-band canvas { display: block; }

/* --------------------------------------------------------------------------
   Contact / accordion
   -------------------------------------------------------------------------- */

.eyebrow {
  font-size: var(--mono-s);
  line-height: var(--s2);
  color: var(--hairline);
  margin-bottom: var(--s3);
}

.accordion {
  display: flex;
  flex-direction: column;
  gap: var(--s2);
}

.acc-heading { margin: 0; }

.toggle {
  font-size: var(--mono-m);
  line-height: var(--s3);
  text-align: left;
  color: var(--ink);
  padding: var(--s1) 0;
  transition: color 200ms ease;
  overflow-wrap: anywhere;
}

/* When one panel is open, the other toggle recedes */
.accordion.has-open .toggle[aria-expanded="false"] { color: var(--hairline); }
.accordion.has-open .toggle[aria-expanded="false"]:hover { color: var(--ink); }

.toggle:hover,
.close:hover {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 5px;
}

/* Expand / collapse: animate grid rows 0fr → 1fr (height: auto without measuring) */
.panel {
  display: grid;
  grid-template-rows: 0fr;
  opacity: 0;
  transition:
    grid-template-rows var(--dur) var(--ease),
    opacity calc(var(--dur) * 0.6) ease;
}

.panel.is-open {
  grid-template-rows: 1fr;
  opacity: 1;
  transition:
    grid-template-rows var(--dur) var(--ease),
    opacity var(--dur) ease calc(var(--dur) * 0.2);
}

/* No JS: forms are simply open, and toggles/close buttons do nothing */
html:not(.js) .panel { grid-template-rows: 1fr; opacity: 1; }
html:not(.js) .close { display: none; }
html:not(.js) .toggle { cursor: default; text-decoration: none; }

.panel__clip {
  min-height: 0;
  overflow: hidden;
  /* bleed so focus outlines aren't clipped, without shifting content */
  margin: 0 -8px;
  padding: 0 8px;
}

.panel__inner {
  padding: var(--s3) 0 var(--s6);
}

.panel__bar {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: var(--s2);
  margin-bottom: var(--s4);
  padding-bottom: var(--s2);
  border-bottom: 1px solid var(--hairline);
}

.close {
  flex: none;
  font-size: var(--mono-s);
  line-height: var(--s2);
  color: var(--ink);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 0;
  padding: var(--s1) 0 var(--s1) var(--s1);
  margin: calc(-1 * var(--s1)) 0;
}

.close__x {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin: 0 3px 0 7px;
  shape-rendering: crispEdges;
}

/* --------------------------------------------------------------------------
   Form
   -------------------------------------------------------------------------- */

/* Two columns: short fields pair up; long answers, CTA and messages span the row */
.form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--s4) var(--s4);
  align-items: end;
}

.field--wide,
.form .cta,
.form .form__error { grid-column: 1 / -1; }

/* Honeypot — off-screen (not display:none) so naive bots still fill it */
.hp {
  position: absolute !important;
  left: -10000px !important;
  top: auto !important;
  width: 1px !important;
  height: 1px !important;
  overflow: hidden !important;
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--s1);
}

.field label {
  font-size: var(--mono-s);
  line-height: var(--s2);
  color: var(--ink);
}

.tag {
  color: var(--hairline);
  white-space: nowrap;
}

.field input,
.field textarea {
  width: 100%;
  font-size: var(--mono-field);
  line-height: var(--s3);
  color: var(--ink);
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--hairline);
  border-radius: 0;
  padding: 0 0 var(--s1);
  margin: 0;
  outline: none;
  box-shadow: 0 1px 0 0 transparent;
  transition: border-color 160ms ease, box-shadow 160ms ease;
  -webkit-appearance: none;
  appearance: none;
  caret-color: var(--accent);
}

.field textarea {
  resize: none;
  overflow: hidden;
  min-height: calc(var(--s3) + var(--s1) + 1px);
  field-sizing: content;
}

.field input::placeholder,
.field textarea::placeholder {
  color: var(--hairline);
  opacity: 1;
  text-transform: none;
}

.field input:focus,
.field textarea:focus {
  border-bottom-color: var(--accent);
  box-shadow: 0 1px 0 0 var(--accent);   /* reads as 2px on focus */
}

/* Keep browser autofill on-palette */
.field input:-webkit-autofill {
  -webkit-text-fill-color: var(--ink);
  box-shadow: 0 0 0 1000px var(--paper) inset;
  transition: background-color 9999s ease 0s;
}

.field.is-invalid input,
.field.is-invalid textarea {
  border-bottom-style: dashed;
}

/* CTA — filled ink button, text + arrow */
.form .cta { justify-self: start; }

.cta {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  font-size: var(--mono-m);
  line-height: var(--s3);
  color: var(--paper);
  background: var(--ink);
  padding: var(--s1) var(--s2);
  margin-top: var(--s2);
}

.cta .arrow__line,
.cta .arrow__head { background: var(--paper); }   /* accent square vanishes on ink */

.arrow--cta .arrow__line {
  flex: 0 0 auto;
  width: 44px;
  transition: width 260ms var(--ease);
}

.cta:hover .arrow--cta .arrow__line,
.cta:focus-visible .arrow--cta .arrow__line {
  width: 66px;
}

.cta[aria-busy="true"] { cursor: progress; }
.cta[aria-busy="true"] .arrow--cta .arrow__line { width: 66px; }

.success {
  font-size: var(--mono-m);
  line-height: var(--s3);
  outline: none;
}

.form__error {
  font-size: var(--mono-s);
  line-height: var(--s2);
}

[hidden] { display: none !important; }

/* --------------------------------------------------------------------------
   Footer
   -------------------------------------------------------------------------- */

.site-footer {
  padding: 0 var(--gutter) var(--s4);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--s1) var(--s3);
  font-family: var(--font-mono);
  font-size: var(--mono-s);
  line-height: var(--s2);
  text-transform: uppercase;
  font-variant-ligatures: none;
}

.site-footer__right {
  display: flex;
  gap: var(--s3);
}

.site-footer__place { color: var(--hairline); }

.site-footer a,
.back {
  color: var(--ink);
  text-decoration: none;
}

.site-footer a:hover,
.back:hover {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}

/* --------------------------------------------------------------------------
   Legal page (privacy) — primary font for reading, mono only for UI
   -------------------------------------------------------------------------- */

.back {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: var(--mono-s);
  line-height: var(--s2);
  text-transform: uppercase;
  font-variant-ligatures: none;
}

.legal { padding-top: var(--s3); }   /* back link sits where the logo does on home */

.legal__title {
  font-size: clamp(2.25rem, 1.6rem + 2.6vw, 3.5rem);
  line-height: 1.08;
  letter-spacing: -0.02em;
  margin-top: var(--s8);
}

.legal__meta {
  margin-top: var(--s2);
  font-size: 0.875rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--hairline);
}

.legal__body {
  max-width: 38em;
  font-size: 1.125rem;
  line-height: 1.6;
}

.legal__body h2 {
  font-size: 1.5rem;
  line-height: 1.3;
  letter-spacing: -0.01em;
  margin: var(--s8) 0 var(--s2);
}

.legal__body p,
.legal__body ul { margin: 0 0 var(--s2); }

.legal__body ul { padding-left: 1.25em; }

.legal__body li + li { margin-top: var(--s1); }

.legal__body a { color: inherit; text-underline-offset: 3px; text-decoration-thickness: 1px; }

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */

@media (max-width: 640px) {
  .site-header { padding-top: var(--s2); }
  .logo svg { width: 123.6px; }          /* 0.2× the source grid */
  .page { padding-bottom: var(--s8); }
  .intro { padding: var(--s8) 0 var(--s6); }
  .intro .subhero { margin-top: var(--s3); }
  .data-band { margin-bottom: var(--s6); }
  .eyebrow { margin-bottom: var(--s2); }
  .accordion { gap: 0; }
  .panel__inner { padding-bottom: var(--s4); }
  .panel__bar { margin-bottom: var(--s4); }
  .form { grid-template-columns: minmax(0, 1fr); gap: var(--s3); }
  .legal__title { margin-top: var(--s6); }
  .legal__body h2 { margin-top: var(--s6); }
}

/* --------------------------------------------------------------------------
   Motion
   -------------------------------------------------------------------------- */

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

  .logo .glyph { animation: none; stroke: none; fill-opacity: 1; }
  .logo .cursor { animation: none; opacity: 1; }
  .logo .px { animation: none; opacity: 1; }
}

/* --------------------------------------------------------------------------
   EXPERIMENT — soft paper dots with a click ripple (js/paper-dots.js).
   One fixed canvas behind all content; the data band keeps its own grid on a
   plain paper fill.
   -------------------------------------------------------------------------- */

html.has-paper-dots body { isolation: isolate; }   /* canvas sits above the paper, below content */

.paper-dots {
  position: fixed;
  top: 0;
  left: 0;
  z-index: -1;
  pointer-events: none;
}

/* With its grid on (showGrid in data-band.js), the band gets a paper fill that
   hides the dots, fading out at the top and bottom (--band-fade) so dots and
   grid crossfade. With the grid off, the band is transparent: the scene sits
   straight on the page's dots. */
.data-band--grid {
  background-image: linear-gradient(to bottom,
    transparent 0,
    var(--paper) var(--band-fade, 0%),
    var(--paper) calc(100% - var(--band-fade, 0%)),
    transparent 100%);
}
