/* squaring.com — Ink on Paper. Spec: docs/design/ink-on-paper/README.md
   One stylesheet for every page. Risk red only ever marks an exception or alert;
   forest only marks primary actions (and the SQ mark). */

/* ---------- fonts (self-hosted, OFL; see src/fonts/*/OFL.txt) ---------- */

@font-face {
  font-family: 'Geist';
  src: url('fonts/geist/Geist-Regular.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Geist';
  src: url('fonts/geist/Geist-Medium.woff2') format('woff2');
  font-weight: 500; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Geist';
  src: url('fonts/geist/Geist-SemiBold.woff2') format('woff2');
  font-weight: 600; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Mono';
  src: url('fonts/ibm-plex-mono/IBMPlexMono-Regular.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Mono';
  src: url('fonts/ibm-plex-mono/IBMPlexMono-Medium.woff2') format('woff2');
  font-weight: 500; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Spectral';
  src: url('fonts/spectral/Spectral-Medium.woff2') format('woff2');
  font-weight: 500; font-style: normal; font-display: swap;
}

/* ---------- tokens ---------- */

:root {
  --paper: #F7F4ED;
  --paper-deep: #E9E2D3;
  --white: #FFFFFF;
  --hair: #E0D8C6;
  --rule: #D6CCB8;
  --ink: #211E17;      /* 15:1 on paper */
  --ink-2: #6B6354;    /* 5.4:1 on paper */
  --risk: #A3302A;     /* 6.3:1 on paper */
  --forest: #1F4733;   /* paper on forest: 9.5:1 */
  --matched: #CCC9C2;  /* ink 20% over paper */

  --pad: 80px;
  --content: 1280px;

  --sans: 'Geist', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --serif: 'Spectral', Georgia, 'Times New Roman', serif;
}

@media (max-width: 1200px) { :root { --pad: 48px } }
@media (max-width: 900px)  { :root { --pad: 32px } }
@media (max-width: 560px)  { :root { --pad: 20px } }

/* ---------- base ---------- */

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

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p, ul { margin: 0 }
ul { padding: 0; list-style: none }

a { color: inherit }

a:focus-visible, button:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

.wrap {
  max-width: calc(var(--content) + var(--pad) * 2);
  margin-inline: auto;
  padding-inline: var(--pad);
}

.vh {
  position: absolute; width: 1px; height: 1px;
  margin: -1px; padding: 0; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap; border: 0;
}

.sq { display: block; background: var(--ink); flex: none }

/* ---------- nav ---------- */

.nav {
  display: flex; align-items: center; justify-content: space-between;
  padding-block: 28px;
  border-bottom: 1px solid var(--hair);
}
.brand {
  display: flex; align-items: center; gap: 12px;
  font-family: var(--serif); font-size: 25px; font-weight: 500; letter-spacing: -.005em;
  text-decoration: none;
}
.brand img { display: block; width: 28px; height: 28px }

.btn {
  display: inline-block;
  background: var(--forest); color: var(--paper);
  text-decoration: none; padding: 18px 30px;
  font-size: 17px; font-weight: 600;
}
.btn:hover { filter: brightness(1.18) }

.eyebrow {
  font-family: var(--mono); font-size: 13px; font-weight: 400;
  letter-spacing: .1em; text-transform: uppercase; color: var(--ink-2);
}

/* ---------- footer ---------- */

.foot {
  margin-top: 104px; padding-block: 28px;
  border-top: 1px solid var(--hair);
  display: flex; justify-content: space-between; gap: 20px;
  font-size: 14px; color: var(--ink-2);
}
.foot nav { display: flex; gap: 28px }
.foot a { text-decoration: none }
.foot a:hover { color: var(--ink) }

@media (max-width: 1200px) { .foot { margin-top: 80px } }
@media (max-width: 560px) {
  .foot { margin-top: 64px; flex-direction: column; gap: 14px }
  .btn { padding: 16px 26px }
}
@media (prefers-reduced-motion: reduce) { .btn:hover { filter: none } }

/* ---------- homepage ---------- */
/* ---------- hero ---------- */

.hero { padding-block: 72px 96px }

.cred {
  display: flex; align-items: center; gap: 12px;
  font-family: var(--mono); font-size: 14px; color: var(--ink)
}
.cred .sq { width: 8px; height: 8px }
.hero-copy .cred { margin-bottom: 8px }

h1 {
  font-size: clamp(34px, 6.9vw, 100px);
  line-height: .95; font-weight: 600; letter-spacing: -.05em;
  text-wrap: balance;
}

.hero-grid {
  display: grid; grid-template-columns: minmax(0, 1fr) 572px;
  gap: 80px; align-items: center;
}
.hero-copy {
  display: flex; flex-direction: column; gap: 28px;
  align-items: flex-start;
}
.lede {
  font-size: clamp(18px, 1.75vw, 25px); line-height: 1.45;
  color: var(--ink-2); max-width: 580px; text-wrap: pretty;
}

/* ---------- hero card: the month grid ---------- */

.card {
  display: flex; flex-direction: column; gap: 14px;
  background: var(--white); border: 1px solid var(--hair); padding: 24px;
}
.card-head, .card-note, .status {
  font-family: var(--mono); font-size: 13px; color: var(--ink-2);
}
.card-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap }

.mgrid {
  display: grid;
  grid-template-columns: repeat(22, minmax(0, 1fr));
  gap: clamp(2px, .42vw, 6px);
}
.mgrid i {
  position: relative; aspect-ratio: 1;
  background: var(--matched);
  transition: background .25s;
}
/* Rewinding the run must not fade 264 cells out. Set for one frame only. */
.mgrid.no-tx i { transition: none }
/* future — not yet reached by the run */
.mgrid i[data-s="e"] { background: transparent; box-shadow: inset 0 0 0 1px var(--hair) }
/* the cell just filled */
.mgrid i[data-s="h"] { background: var(--ink) }
/* exception, surfaced */
.mgrid i[data-s="x"] {
  background: var(--risk);
  box-shadow: 0 0 0 3px rgba(163, 48, 42, .18), 0 0 26px rgba(163, 48, 42, .35);
}
/* exception, resolved — still marked on the record */
.mgrid i[data-s="r"] { background: var(--matched); box-shadow: inset 0 0 0 2px var(--risk) }

/* Non-colour cue. The exception cell is the only one carrying a ring, so it
   stays distinguishable without relying on the red. WCAG 1.4.1. */
.mgrid i[data-s="x"]::after,
.mgrid i[data-s="r"]::after {
  content: ''; position: absolute; inset: 34%;
  background: var(--paper);
}

.bar { margin-top: 18px; height: 8px; background: var(--paper-deep); position: relative; overflow: hidden }
.bar span {
  position: absolute; inset: 0 auto 0 0; width: 100%;
  background: var(--ink); transition: width 1.4s ease-out;
}
/* Rewinding is instant; only the fill-up is animated, so the bar never
   sweeps backwards when the run restarts. */
.bar[data-running] span { width: 0; transition: none }

.status { font-size: 15px; color: var(--ink); display: flex; gap: 10px; align-items: baseline }
.status .dot { width: 8px; height: 8px; background: var(--risk); flex: none; translate: 0 -2px }

/* ---------- record diagram ---------- */

.record {
  background: var(--paper-deep);
  border-block: 1px solid var(--hair);
  font-family: var(--mono);
  padding-block: 48px 44px;
}
.record .sec {
  margin-top: 14px; max-width: 22em;
  font-family: var(--sans); font-size: clamp(28px, 3.3vw, 46px); font-weight: 600;
  line-height: 1.05; letter-spacing: -.035em; color: var(--ink);
}
.canvas { margin-top: 46px }
.rails-h { display: block; width: 100%; height: auto }
.rails-v { display: none }

.rails-h .eb { font-size: 12px; letter-spacing: .1em; fill: var(--ink-2) }
.rails-h .nm { font-size: 16px; fill: var(--ink) }
.rails-h .eb.alert, .rails-h .nm.alert { fill: var(--risk) }
.rails-h .hub-name { font-family: var(--sans); font-size: 17px; font-weight: 600; letter-spacing: -.02em; fill: var(--ink) }
.rails-h .hub-op { font-size: 10px; letter-spacing: .08em; fill: var(--ink-2) }
.rail { fill: none; stroke: var(--ink); stroke-width: 1.25 }
.rail.alert { stroke: rgba(163, 48, 42, .5) }
.term { fill: var(--ink) }
.term.alert { fill: var(--risk) }
.hub-box { fill: var(--white); stroke: var(--ink); stroke-width: 2 }

.pkt {
  offset-rotate: auto;
  animation-name: pkt; animation-timing-function: linear; animation-iteration-count: infinite;
}
.pkt rect { fill: var(--ink) }
.pkt.alert rect { fill: var(--risk); filter: drop-shadow(0 0 5px rgba(163, 48, 42, .65)) }
.pkt.alert { animation-name: pkt-alert }

@keyframes pkt {
  0%   { offset-distance: 0%;   opacity: 0 }
  5%   { opacity: 1 }
  95%  { opacity: 1 }
  100% { offset-distance: 100%; opacity: 0 }
}
@keyframes pkt-alert {
  0%, 62% { offset-distance: 0%; opacity: 0 }
  64%     { opacity: 1 }
  97%     { opacity: 1 }
  100%    { offset-distance: 100%; opacity: 0 }
}

.is-paused .pkt { animation-play-state: paused }

/* ---------- proof points ---------- */

.proof {
  padding-block: 88px;
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 48px;
}
.proof li { display: flex; flex-direction: column; gap: 16px }
.count { display: flex; gap: 4px }
.count .sq { width: 12px; height: 12px }
.proof h2 { font-size: clamp(24px, 2.5vw, 34px); font-weight: 600; letter-spacing: -.03em; text-wrap: balance }
.proof p { font-size: clamp(16px, 1.3vw, 18px); line-height: 1.55; color: var(--ink-2); text-wrap: pretty }

/* ---------- trust strip ---------- */

.trust {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  border-top: 1px solid var(--ink); border-bottom: 1px solid var(--hair);
  font-family: var(--mono); font-size: 14px;
}
.trust li { padding: 20px 24px; border-left: 1px solid var(--hair) }
.trust li:first-child { padding-left: 0; border-left: 0 }
.trust .nw { white-space: nowrap }

/* ---------- closing ---------- */

.close { margin-top: 88px }
.close-card {
  background: var(--white); border: 1px solid var(--hair); padding: 56px 64px;
  display: grid; grid-template-columns: minmax(0, 1fr) auto;
  gap: 64px; align-items: end;
}
.close-card h2 { font-size: clamp(30px, 4.4vw, 60px); line-height: 1; font-weight: 600; letter-spacing: -.045em }
.close-card p { font-size: clamp(17px, 1.4vw, 19px); color: var(--ink-2); margin-top: 16px }
.close-act { display: flex; flex-direction: column; gap: 14px; align-items: flex-end }
.close-act .email { font-family: var(--mono); font-size: 14px; color: var(--ink-2); text-decoration: none }

/* ---------- responsive ---------- */

@media (max-width: 1200px) {
  .hero { padding-block: 56px 88px }
  .hero-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 44%); gap: 48px }
  .proof { padding-block: 80px; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 56px 48px }
  .close { margin-top: 80px }
}

/* The horizontal diagram needs its full 1280 width to stay legible. Below
   that it swaps to the vertical variant. (Spec says 900; 1080 in practice,
   because the labels stop clearing the hub before 900.) */
@media (max-width: 1080px) {
  .rails-h { display: none }
  .rails-v { display: flex; flex-direction: column; align-items: center; gap: 28px }
}

@media (max-width: 900px) {
  .hero-grid { grid-template-columns: minmax(0, 1fr) }
  .card { max-width: 600px }
  .proof { gap: 48px 40px }
  .close-card { grid-template-columns: minmax(0, 1fr); gap: 40px; padding: 48px }
  .close-act { align-items: flex-start }
}

@media (max-width: 700px) {
  .card-head, .card-note { font-size: 12px }
  .status { font-size: 13px; flex-wrap: wrap }
}

@media (max-width: 560px) {
  .hero { padding-block: 40px 64px }
  .record { padding-block: 40px 36px }
  .canvas { margin-top: 32px }
  .proof { padding-block: 64px; grid-template-columns: minmax(0, 1fr); gap: 48px }
  .trust { grid-template-columns: minmax(0, 1fr) }
  .trust li { border-left: 0; padding-left: 0; border-top: 1px solid var(--hair) }
  .trust li:first-child { border-top: 0 }
  .close { margin-top: 64px }
  .close-card { padding: 28px }
}

/* ---------- vertical diagram (below 1080) ---------- */

.vnodes { display: flex; flex-direction: column; gap: 18px; width: 100% }
.vnodes li { display: flex; flex-direction: column; gap: 3px }
.vnodes .eb { font-size: 12px; letter-spacing: .1em; color: var(--ink-2) }
.vnodes .nm { font-size: clamp(13px, 3.6vw, 16px) }
.vnodes li.alert .eb, .vnodes li.alert .nm { color: var(--risk) }

.vjoin { width: 100%; max-width: 300px; height: auto; display: block }

.hub {
  width: 120px; height: 140px;
  background: var(--white); border: 2px solid var(--ink);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
}
.hub b { font-family: var(--sans); font-size: 17px; font-weight: 600; letter-spacing: -.02em }
.hub span { font-size: 10px; line-height: 1.5; letter-spacing: .08em; color: var(--ink-2); text-align: center }

/* ---------- reduced motion ----------
   Required, not optional. The page shows its finished state: the month
   squared, the exception resolved and still marked, rails with no packets. */

@media (prefers-reduced-motion: reduce) {
  .pkt { display: none }
  .mgrid i, .bar span { transition: none }
}

/* ---------- legal and error pages ---------- */
.subpage { min-height: 100vh }
.legal {
  width: 100%; padding-block: 80px 112px;
  display: grid; grid-template-columns: minmax(280px, 1fr) minmax(0, 2fr);
  gap: 80px;
}
.legal-head { align-self: start; position: sticky; top: 40px }
.legal .eyebrow { margin-bottom: 32px }
.legal h1 { font-size: clamp(64px, 8vw, 116px); margin-bottom: 32px }
.legal .intro { max-width: 440px; font-size: 20px; line-height: 1.55; color: var(--ink-2) }
.legal-body { border-top: 1px solid var(--ink) }
.legal h2 { font-size: 24px; letter-spacing: -.025em; margin-top: 0; padding-top: 32px }
.legal h2:not(:first-child) { margin-top: 40px; border-top: 1px solid var(--hair) }
.legal p, .legal li { font-size: 17px; line-height: 1.65; color: var(--ink-2) }
.legal h2 + p, .legal h2 + ul { margin-top: 12px }
.legal ul { list-style: square; padding-left: 20px }
.legal li + li { margin-top: 8px }
.legal address { font-style: normal }
.legal a { text-underline-offset: 3px }
.legal p + p { margin-top: 14px }
.error-page { min-height: 62vh; display: grid; align-content: center; gap: 28px; padding-block: 72px }
.error-page h1 { font-size: clamp(72px, 14vw, 180px) }
.error-page p { max-width: 560px; font-size: 20px; line-height: 1.55; color: var(--ink-2) }
.error-page .btn { justify-self: start }

@media (max-width: 900px) {
  .legal { grid-template-columns: minmax(0, 1fr); gap: 56px; padding-block: 64px 88px }
  .legal-head { position: static }
  .legal .intro { max-width: 680px }
}
@media (max-width: 560px) {
  .legal { gap: 40px; padding-block: 48px 64px }
  .legal .eyebrow { margin-bottom: 24px }
  .legal h1 { font-size: 56px; margin-bottom: 24px }
  .legal .intro { font-size: 18px }
  .legal h2 { font-size: 22px }
}
