/* ==========================================================================
   aarongorman.dev — one stylesheet, no framework, no build step.

   Structure:
     1. Tokens (color, type, space)
     2. Reset and base elements
     3. Layout primitives
     4. Site chrome (skip link, header, footer, theme toggle)
     5. Home page
     6. Case study
     7. Utilities
   ========================================================================== */

/* 1. Tokens ================================================================ */

:root {
  /* Type roles.
     Display: a serif with real character wherever it is installed, falling
     back through the best available on each platform. Body: the platform's
     UI grotesk. Utility: mono, reserved for machine-produced facts. */
  --font-display: "Iowan Old Style", "Charter", "Constantia", "Palatino Linotype",
    Palatino, "Book Antiqua", Georgia, serif;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue",
    Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", "Cascadia Mono",
    "Roboto Mono", Menlo, Consolas, monospace;

  /* Type scale — 1.25 at small sizes, opening up on wide viewports. */
  --step--1: clamp(0.83rem, 0.80rem + 0.14vw, 0.90rem);
  --step-0: clamp(1.05rem, 1.00rem + 0.22vw, 1.19rem);
  --step-1: clamp(1.26rem, 1.18rem + 0.36vw, 1.51rem);
  --step-2: clamp(1.51rem, 1.38rem + 0.60vw, 1.91rem);
  --step-3: clamp(1.81rem, 1.60rem + 0.96vw, 2.43rem);
  --step-4: clamp(2.17rem, 1.84rem + 1.50vw, 3.08rem);

  --measure: 34rem;      /* prose column */
  --margin-col: 9.5rem;  /* editorial margin for section labels */
  --gutter: clamp(1.25rem, 4vw, 2.5rem);

  --space-1: 0.375rem;
  --space-2: 0.75rem;
  --space-3: 1.25rem;
  --space-4: 2rem;
  --space-5: 3.25rem;
  --space-6: 5rem;

  --border-thin: 1px;
  --radius: 2px;

  /* Light theme — cool offset paper, not cream. */
  --paper: #f4f4f1;
  --paper-raised: #fbfbf9;
  --ink: #1b1d1a;
  --ink-muted: #585d56;
  --rule: #d7d8d1;
  --rule-strong: #b9bbb2;
  --accent: #3f5d34;       /* moss — the colour of a run that passed */
  --accent-hover: #2e4626;
  --accent-wash: #e8ece3;
  --shadow: none;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #14171c;
    --paper-raised: #1a1e24;
    --ink: #e5e6e1;
    --ink-muted: #99a099;
    --rule: #2b3038;
    --rule-strong: #3d444d;
    --accent: #a3c48f;
    --accent-hover: #bcd8ab;
    --accent-wash: #1e2620;
    color-scheme: dark;
  }
}

/* Manual toggle wins over the OS preference in both directions. */
:root[data-theme="light"] {
  --paper: #f4f4f1;
  --paper-raised: #fbfbf9;
  --ink: #1b1d1a;
  --ink-muted: #585d56;
  --rule: #d7d8d1;
  --rule-strong: #b9bbb2;
  --accent: #3f5d34;
  --accent-hover: #2e4626;
  --accent-wash: #e8ece3;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --paper: #14171c;
  --paper-raised: #1a1e24;
  --ink: #e5e6e1;
  --ink-muted: #99a099;
  --rule: #2b3038;
  --rule-strong: #3d444d;
  --accent: #a3c48f;
  --accent-hover: #bcd8ab;
  --accent-wash: #1e2620;
  color-scheme: dark;
}

/* 2. Reset and 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(--font-body);
  font-size: var(--step-0);
  line-height: 1.7;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.012em;
  text-wrap: balance;
  margin: 0;
}

h1 {
  font-size: var(--step-4);
}
h2 {
  font-size: var(--step-2);
}
h3 {
  font-size: var(--step-1);
}

p,
ul,
ol,
dl,
figure,
blockquote,
pre {
  margin: 0 0 var(--space-3);
}

ul,
ol {
  padding-left: 1.15em;
}

li {
  margin-bottom: var(--space-1);
}

li::marker {
  color: var(--ink-muted);
}

/* The only motion on the site: the underline inks in on hover.
   Colour is deliberately not transitioned — animating it would make every
   link fade for 150ms when the theme is toggled, which reads as a fault. */
a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
  text-decoration-color: var(--rule-strong);
  transition: text-decoration-color 150ms ease;
}

a:hover {
  color: var(--accent-hover);
  text-decoration-color: currentColor;
}

@media (prefers-reduced-motion: reduce) {
  a {
    transition: none;
  }
  html {
    scroll-behavior: auto;
  }
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: var(--radius);
}

strong {
  font-weight: 650;
}

code,
kbd,
samp {
  font-family: var(--font-mono);
  font-size: 0.88em;
}

hr {
  border: 0;
  border-top: var(--border-thin) solid var(--rule);
  margin: var(--space-5) 0;
}

img,
svg {
  max-width: 100%;
  height: auto;
}

/* 3. Layout primitives ===================================================== */

.wrap {
  width: 100%;
  max-width: 62rem;
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.prose {
  max-width: var(--measure);
}

/* Headings are margin-reset globally; prose subheads need their own rhythm,
   and more space above than below so they bind to the text they introduce. */
.prose h3 {
  margin-top: var(--space-4);
  margin-bottom: var(--space-2);
}

/* A page whose sections carry labels in the left margin on wide screens. */
.ruled-page > * + * {
  margin-top: var(--space-5);
}

.ruled-section {
  border-top: var(--border-thin) solid var(--rule);
  padding-top: var(--space-3);
}

.ruled-section > .section-label {
  font-family: var(--font-mono);
  font-size: var(--step--1);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin: 0 0 var(--space-2);
}

.ruled-section > h2 {
  margin-bottom: var(--space-3);
}

@media (min-width: 60rem) {
  .ruled-section {
    display: grid;
    grid-template-columns: var(--margin-col) minmax(0, var(--measure));
    column-gap: var(--space-4);
  }

  .ruled-section > .section-label {
    grid-column: 1;
    grid-row: 1 / span 99;
    margin: 0;
    /* Optical alignment with the cap-height of the heading beside it. */
    padding-top: 0.35em;
  }

  .ruled-section > *:not(.section-label) {
    grid-column: 2;
  }

  /* Diagrams and the impact strip are allowed the full width. */
  .ruled-section > .bleed {
    grid-column: 1 / -1;
    max-width: none;
  }
}

/* 4. Site chrome =========================================================== */

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--paper-raised);
  color: var(--ink);
  padding: var(--space-2) var(--space-3);
  border: var(--border-thin) solid var(--rule-strong);
  z-index: 10;
}

.skip-link:focus {
  left: var(--gutter);
  top: var(--space-2);
}

.site-header {
  /* The signature rule: evenly spaced ticks, like a schedule. Everything on
     this site runs on an interval; the header says so before the copy does. */
  border-bottom: var(--border-thin) solid var(--rule);
  background-image: repeating-linear-gradient(
    to right,
    var(--rule-strong) 0 1px,
    transparent 1px 0.75rem
  );
  background-repeat: no-repeat;
  background-position: bottom left;
  background-size: 100% 5px;
  padding-block: var(--space-3) calc(var(--space-3) + 5px);
}

.site-header > .wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-2) var(--space-4);
}

.site-id {
  font-family: var(--font-display);
  font-size: var(--step-1);
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
  text-decoration: none;
  margin-right: auto;
}

.site-id:hover {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--accent);
}

.site-nav ul {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  list-style: none;
  margin: 0;
  padding: 0;
}

.site-nav li {
  margin: 0;
}

.site-nav a {
  font-size: var(--step--1);
  letter-spacing: 0.02em;
  color: var(--ink-muted);
  text-decoration: none;
}

.site-nav a:hover {
  color: var(--ink);
  text-decoration: underline;
}

.site-nav a[aria-current="page"] {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 2px;
}

.site-nav .nav-cta a {
  color: var(--accent);
}

/* Injected by site.js — absent, and taking no space, without JS. */
.theme-toggle {
  font-family: var(--font-mono);
  font-size: var(--step--1);
  line-height: 1;
  color: var(--ink-muted);
  background: transparent;
  border: var(--border-thin) solid var(--rule-strong);
  border-radius: var(--radius);
  padding: 0.4em 0.7em;
  cursor: pointer;
}

.theme-toggle:hover {
  color: var(--ink);
  border-color: var(--ink-muted);
}

main {
  display: block;
  padding-block: var(--space-5) var(--space-6);
}

.site-footer {
  border-top: var(--border-thin) solid var(--rule);
  padding-block: var(--space-4);
  color: var(--ink-muted);
  font-size: var(--step--1);
}

.site-footer > .wrap {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-2) var(--space-4);
}

.site-footer ul {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  list-style: none;
  margin: 0;
  padding: 0;
}

.site-footer li {
  margin: 0;
}

/* 5. Home ================================================================== */

.hero {
  padding-block: var(--space-4) var(--space-5);
}

.hero h1 {
  max-width: 44rem;
}

.hero-sub {
  font-family: var(--font-display);
  font-size: var(--step-2);
  line-height: 1.35;
  color: var(--ink-muted);
  max-width: 30rem;
  margin-top: var(--space-3);
  text-wrap: balance;
}

.hero-cta {
  margin-top: var(--space-4);
}

.button {
  display: inline-block;
  font-size: var(--step-0);
  line-height: 1.3;
  color: var(--paper);
  background: var(--accent);
  border: var(--border-thin) solid var(--accent);
  border-radius: var(--radius);
  padding: 0.65em 1.1em;
  text-decoration: none;
}

.button:hover {
  color: var(--paper);
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

/* Proof tiles and case-study entries share one vocabulary with the impact
   strip: a mono figure, a small label under it, then the writing. No cards,
   no borders, no shadows — a hairline rule and space do the separating. */
.tiles {
  display: grid;
  /* 11rem, not 14: three tiles have to fit the bleed width, which is the
     margin column plus the measure — not the full wrap. */
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: var(--space-4);
  margin: 0;
  padding: 0;
  list-style: none;
}

.tile {
  border-top: var(--border-thin) solid var(--rule-strong);
  padding-top: var(--space-3);
  margin: 0;
}

.tile-figure {
  font-family: var(--font-mono);
  font-size: var(--step-3);
  line-height: 1.1;
  color: var(--ink);
  margin: 0;
}

.tile-label {
  font-family: var(--font-mono);
  font-size: var(--step--1);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin: var(--space-1) 0 var(--space-2);
}

.tile h3 {
  font-size: var(--step-1);
  margin-bottom: var(--space-2);
}

.tile h3 a {
  color: var(--ink);
  text-decoration-color: var(--accent);
}

.tile h3 a:hover {
  color: var(--accent-hover);
}

.tile p:last-child {
  margin-bottom: 0;
  font-size: var(--step--1);
  color: var(--ink-muted);
}

/* The case-study index: one row per study, figure in the margin on wide
   screens so the list scans as evidence rather than as titles. */
.entries {
  list-style: none;
  margin: 0;
  padding: 0;
}

.entry {
  border-top: var(--border-thin) solid var(--rule);
  padding-block: var(--space-3);
  margin: 0;
}

.entry :is(h2, h3) {
  font-size: var(--step-1);
  margin-bottom: var(--space-2);
}

.entry :is(h2, h3) a {
  color: var(--ink);
  text-decoration-color: var(--accent);
}

.entry :is(h2, h3) a:hover {
  color: var(--accent-hover);
}

.entry p {
  max-width: var(--measure);
  margin-bottom: 0;
}

.entry-figure {
  font-family: var(--font-mono);
  font-size: var(--step--1);
  color: var(--ink-muted);
  margin-bottom: var(--space-2);
}

@media (min-width: 60rem) {
  .entry {
    display: grid;
    grid-template-columns: var(--margin-col) minmax(0, var(--measure));
    column-gap: var(--space-4);
  }

  .entry-figure {
    grid-column: 1;
    grid-row: 1 / span 9;
    margin: 0;
    padding-top: 0.35em;
  }

  .entry > *:not(.entry-figure) {
    grid-column: 2;
  }
}

/* The "also built" list: one line each, no detail pages. Names are mono
   because they are identifiers; the descriptions are prose. */
.also {
  list-style: none;
  margin: 0 0 var(--space-4);
  padding: 0;
}

.also li {
  border-top: var(--border-thin) solid var(--rule);
  padding-block: var(--space-2);
  margin: 0;
  font-size: var(--step--1);
  line-height: 1.6;
}

.also-name {
  font-family: var(--font-mono);
  color: var(--ink);
  margin-right: 0.5em;
}

.stub {
  border: var(--border-thin) dashed var(--rule-strong);
  border-radius: var(--radius);
  padding: var(--space-3);
  color: var(--ink-muted);
  font-size: var(--step--1);
}

/* 6. Case study ============================================================ */

.study-header {
  padding-bottom: var(--space-4);
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: var(--step--1);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin: 0 0 var(--space-3);
}

.standfirst {
  font-family: var(--font-display);
  font-size: var(--step-2);
  line-height: 1.4;
  color: var(--ink-muted);
  max-width: 40rem;
  margin-top: var(--space-3);
  text-wrap: pretty;
}

/* The impact strip. Every figure declares how it was arrived at — measured,
   estimated, or structural. The kind is part of the design, not a footnote. */
.impact {
  margin: 0;
  padding-top: var(--space-3);
  border-top: var(--border-thin) solid var(--rule);
  background-image: repeating-linear-gradient(
    to right,
    var(--rule-strong) 0 1px,
    transparent 1px 0.75rem
  );
  background-repeat: no-repeat;
  background-position: top left;
  background-size: 100% 5px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: var(--space-3) var(--space-4);
}

.impact > div {
  padding-top: var(--space-2);
}

.impact dt {
  font-family: var(--font-mono);
  font-size: var(--step--1);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.impact dd {
  margin: var(--space-1) 0 0;
  font-family: var(--font-mono);
  font-size: var(--step-2);
  line-height: 1.2;
  color: var(--ink);
}

/* A TODO inside the strip must not be typeset like a real figure. */
.impact dd.todo {
  font-size: var(--step--1);
}

.impact .impact-note {
  display: block;
  font-family: var(--font-body);
  font-size: var(--step--1);
  line-height: 1.5;
  color: var(--ink-muted);
  margin-top: var(--space-1);
  text-transform: none;
  letter-spacing: 0;
}

.figure {
  margin: var(--space-4) 0;
  /* Never let a wide diagram push the page sideways. */
  overflow-x: auto;
}

.figure svg {
  display: block;
  width: 100%;
  height: auto;
}

/* Diagram language — shared by every case study, so ten pages read as one
   body of work. Colours come from the theme; nothing is hard-coded. */
.diagram {
  /* Below this the labels stop being legible, so the figure scrolls instead.
     Above the cap the diagram would out-shout the prose it belongs to. */
  min-width: 24rem;
  max-width: 38rem;
}

.diagram .node {
  fill: var(--paper-raised);
  stroke: var(--rule-strong);
  stroke-width: 1;
}

/* Two accented node types, and they must not be confused across case studies.
   A gate — accent stroke over an accent wash — marks a place the machine is
   structurally not allowed to pass on its own. An outcome — accent stroke,
   no fill — marks the state the whole system exists to produce. */
.diagram .node-gate {
  fill: var(--accent-wash);
  stroke: var(--accent);
  stroke-width: 1.75;
}

.diagram .node-outcome {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.75;
}

/* Something designed but not built yet. Dashes mean "not in service". */
.diagram .node-future {
  fill: none;
  stroke-dasharray: 4 3;
}

.diagram .node-title {
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 600;
  fill: var(--ink);
}

.diagram .node-sub {
  font-family: var(--font-mono);
  font-size: 11px;
  fill: var(--ink-muted);
}

.diagram .flow {
  fill: none;
  stroke: var(--ink-muted);
  stroke-width: 1.25;
  marker-end: url(#arrowhead);
}

.diagram .flow-label {
  font-family: var(--font-mono);
  font-size: 11px;
  fill: var(--ink-muted);
}

.diagram marker path {
  fill: var(--ink-muted);
  stroke: none;
}

.figure figcaption {
  font-size: var(--step--1);
  color: var(--ink-muted);
  margin-top: var(--space-2);
  max-width: var(--measure);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  list-style: none;
  margin: 0 0 var(--space-3);
  padding: 0;
}

.chips li {
  font-family: var(--font-mono);
  font-size: var(--step--1);
  color: var(--ink-muted);
  border: var(--border-thin) solid var(--rule-strong);
  border-radius: var(--radius);
  padding: 0.2em 0.6em;
  margin: 0;
}

/* A compact "elsewhere" list: a label in the margin, links running on. Kept
   deliberately plain — this is a footnote to the site, not a section of it. */
.links {
  list-style: none;
  margin: 0 0 var(--space-3);
  padding: 0;
}

.links li {
  margin-bottom: var(--space-2);
}

.links-label {
  display: inline-block;
  min-width: 5rem;
  font-family: var(--font-mono);
  font-size: var(--step--1);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.study-end {
  border-top: var(--border-thin) solid var(--rule);
  margin-top: var(--space-5);
  padding-top: var(--space-4);
}

/* 7. Utilities ============================================================= */

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

/* Unwritten content. Deliberately loud: a TODO that blends in is a TODO that
   ships. Remove the element, not the class, when the copy lands. */
.todo {
  font-family: var(--font-mono);
  font-size: var(--step--1);
  line-height: 1.55;
  display: block;
  color: var(--ink);
  background: var(--accent-wash);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-3);
}

.todo::before {
  content: "TODO — ";
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--accent-hover);
}

.note {
  font-size: var(--step--1);
  color: var(--ink-muted);
}

@media print {
  .site-nav,
  .theme-toggle,
  .skip-link {
    display: none;
  }
}
