/* ---------- Tokens ---------- */
:root {
  --bg: #f5f3ee;
  --surface: #fbfaf7;
  --ink: #1c1b18;
  --ink-2: #4a4843;
  --ink-3: #75726b;
  --rule: #dedad1;
  --accent: #1d6a4c;
  --accent-ink: #145238;
  --accent-wash: #e3ede6;
  --code-bg: #efece5;
  --sel: #cfe3d6;

  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --measure: 40rem;
  --wide: 60rem;
  --gutter: clamp(1rem, 4vw, 2.5rem);

  color-scheme: light;
}

/* Dark is its own palette, not an inversion: lower contrast body text,
   a lifted accent, and surfaces that separate by tone rather than borders. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131514;
    --surface: #1a1d1b;
    --ink: #e6e3dc;
    --ink-2: #b5b1a8;
    --ink-3: #8a877f;
    --rule: #2c302d;
    --accent: #7cc9a2;
    --accent-ink: #a3dcbe;
    --accent-wash: #1d2a23;
    --code-bg: #1d201e;
    --sel: #2c4a3a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131514;
  --surface: #1a1d1b;
  --ink: #e6e3dc;
  --ink-2: #b5b1a8;
  --ink-3: #8a877f;
  --rule: #2c302d;
  --accent: #7cc9a2;
  --accent-ink: #a3dcbe;
  --accent-wash: #1d2a23;
  --code-bg: #1d201e;
  --sel: #2c4a3a;
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 1.0625rem/1.65 var(--sans);
  font-feature-settings: "kern", "liga";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
::selection { background: var(--sel); }

a {
  color: var(--accent-ink);
  text-decoration-line: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  text-decoration-color: color-mix(in srgb, var(--accent) 45%, transparent);
  transition: text-decoration-color 0.15s;
}
a:hover { text-decoration-color: currentColor; }
a:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}

h1, h2, h3 { color: var(--ink); font-weight: 600; letter-spacing: -0.015em; }
h1 { font-size: clamp(2rem, 5.5vw, 2.875rem); line-height: 1.1; margin: 0 0 1rem; letter-spacing: -0.03em; }
h2 { font-size: 1.375rem; line-height: 1.3; margin: 3rem 0 0.75rem; }
h3 { font-size: 1.0625rem; line-height: 1.4; margin: 2rem 0 0.4rem; }
p { margin: 0 0 1.1rem; }
ul, ol { padding-left: 1.2rem; margin: 0 0 1.1rem; }
li { margin-bottom: 0.35rem; }
li::marker { color: var(--ink-3); }
strong { font-weight: 600; }

code, pre, .mono { font-family: var(--mono); }
code { font-size: 0.88em; background: var(--code-bg); padding: 0.1em 0.35em; border-radius: 3px; }
pre {
  background: var(--code-bg);
  font-size: 0.8125rem;
  line-height: 1.6;
  padding: 1rem 1.15rem;
  border-radius: 6px;
  overflow-x: auto;
  margin: 1.25rem 0 1.5rem;
  scrollbar-color: var(--rule) transparent;
  scrollbar-width: thin;
}
pre code { background: none; padding: 0; font-size: inherit; }

.wrap { max-width: calc(var(--wide) + 2 * var(--gutter)); margin: 0 auto; padding: 0 var(--gutter); }
.measure { max-width: var(--measure); }

.skip {
  position: absolute; left: -999px; top: 0;
  background: var(--ink); color: var(--bg); padding: 0.5rem 0.75rem;
}
.skip:focus { left: 0.5rem; top: 0.5rem; z-index: 10; }

/* ---------- Top bar ---------- */
.bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: 1.25rem 0;
  font-size: 0.875rem;
}
.bar a.home { color: var(--ink); text-decoration: none; font-weight: 600; letter-spacing: -0.01em; }
.bar nav { display: flex; align-items: center; gap: 1.25rem; }
.bar nav a { color: var(--ink-2); text-decoration: none; }
.bar nav a:hover { color: var(--ink); }
.theme-toggle {
  appearance: none; border: 1px solid var(--rule); background: transparent;
  color: var(--ink-2); width: 2rem; height: 2rem; border-radius: 50%;
  display: inline-grid; place-items: center; cursor: pointer; padding: 0;
}
.theme-toggle:hover { color: var(--ink); border-color: var(--ink-3); }
.theme-toggle svg { width: 1rem; height: 1rem; }
.theme-toggle .sun { display: none; }
:root[data-theme="dark"] .theme-toggle .sun { display: block; }
:root[data-theme="dark"] .theme-toggle .moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .moon { display: none; }
}
@media (max-width: 34rem) {
  .bar nav a.opt { display: none; }
}

/* ---------- Hero ---------- */
.hero { padding: clamp(2.5rem, 8vw, 5rem) 0 2.5rem; }
.eyebrow {
  font-family: var(--mono); font-size: 0.8125rem; color: var(--ink-3);
  letter-spacing: 0.02em; margin: 0 0 1.25rem;
}
.lede { font-size: clamp(1.125rem, 2.4vw, 1.3125rem); line-height: 1.55; color: var(--ink-2); max-width: 38rem; }
.lede strong { color: var(--ink); font-weight: 500; }
.contact { display: flex; flex-wrap: wrap; gap: 0.5rem 1.5rem; margin-top: 1.75rem; font-size: 0.9375rem; }

/* ---------- Numbers ---------- */
.figures {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  margin: 1rem 0 0;
}
.figure { padding: 1.25rem 1.25rem 1.25rem 0; }
.figure + .figure { padding-left: 1.25rem; border-left: 1px solid var(--rule); }
.figure .n {
  display: block; font-family: var(--mono); font-weight: 500;
  font-size: clamp(1.5rem, 3.4vw, 2rem); line-height: 1.1; letter-spacing: -0.03em;
  color: var(--ink); font-variant-numeric: tabular-nums;
}
.figure .l { display: block; margin-top: 0.4rem; font-size: 0.8125rem; line-height: 1.4; color: var(--ink-3); }
@media (max-width: 44rem) {
  .figures { grid-template-columns: 1fr 1fr; }
  .figure:nth-child(3) { padding-left: 0; border-left: 0; }
  .figure:nth-child(n+3) { border-top: 1px solid var(--rule); }
}

/* ---------- Sections ---------- */
section { padding: 3.5rem 0 0; }
.section-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 1rem;
  border-bottom: 1px solid var(--rule); padding-bottom: 0.6rem; margin-bottom: 0.25rem;
}
.section-head h2 { margin: 0; font-size: 0.8125rem; font-family: var(--mono); font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); }
.section-head p { margin: 0; font-size: 0.8125rem; color: var(--ink-3); }

/* ---------- Case study list ---------- */
.cases { list-style: none; padding: 0; margin: 0; }
.cases li { margin: 0; border-bottom: 1px solid var(--rule); }
.case {
  display: grid; grid-template-columns: 2.25rem 1fr auto; gap: 0 1rem;
  padding: 1.4rem 0; text-decoration: none; color: inherit;
}
.case .idx { font-family: var(--mono); font-size: 0.8125rem; color: var(--ink-3); padding-top: 0.2rem; }
.case h3 { margin: 0 0 0.3rem; font-size: 1.1875rem; transition: color 0.15s; }
.case p { margin: 0; color: var(--ink-2); font-size: 0.975rem; max-width: 36rem; }
.case .tag {
  align-self: start; font-family: var(--mono); font-size: 0.8125rem; color: var(--accent-ink);
  background: var(--accent-wash); padding: 0.2rem 0.55rem; border-radius: 3px; white-space: nowrap;
}
.case:hover h3 { color: var(--accent-ink); }
.case .arrow { display: inline-block; transition: transform 0.15s; color: var(--ink-3); }
.case:hover .arrow { transform: translateX(3px); color: var(--accent-ink); }
@media (max-width: 40rem) {
  .case { grid-template-columns: 1.75rem 1fr; }
  .case .tag { grid-column: 2; justify-self: start; margin-top: 0.75rem; }
}

/* ---------- Apps ---------- */
.apps { display: grid; grid-template-columns: 1fr 1fr; gap: 0 2.5rem; list-style: none; padding: 0; margin: 0; }
.apps li { margin: 0; padding: 1.1rem 0; border-bottom: 1px solid var(--rule); }
.apps .name { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: 0.2rem; }
.apps .name strong { font-size: 1rem; }
.apps .name a, .apps .name span.store { font-size: 0.8125rem; font-family: var(--mono); white-space: nowrap; }
.apps .name span.store { color: var(--ink-3); }
.apps p { margin: 0; font-size: 0.9375rem; color: var(--ink-2); line-height: 1.55; }
@media (max-width: 44rem) { .apps { grid-template-columns: 1fr; } }

/* ---------- Two-column rows (measurements, background) ---------- */
.rows { margin: 0; }
.row { display: grid; grid-template-columns: 13rem 1fr; gap: 1.5rem; padding: 1.1rem 0; border-bottom: 1px solid var(--rule); }
.row dt { font-family: var(--mono); font-size: 0.9375rem; color: var(--ink); font-variant-numeric: tabular-nums; }
.row dd { margin: 0; color: var(--ink-2); font-size: 0.975rem; }
.row dd p:last-child { margin-bottom: 0; }
@media (max-width: 40rem) {
  .row { grid-template-columns: 1fr; gap: 0.3rem; }
}

.stack { columns: 2; column-gap: 2.5rem; list-style: none; padding: 0; margin: 1rem 0 0; font-size: 0.9375rem; }
.stack li { break-inside: avoid; margin: 0 0 0.9rem; color: var(--ink-2); }
.stack li b { display: block; font-weight: 500; color: var(--ink); font-size: 0.8125rem; font-family: var(--mono); margin-bottom: 0.1rem; }
@media (max-width: 40rem) { .stack { columns: 1; } }

/* ---------- Footer ---------- */
footer { margin-top: 5rem; padding: 2.5rem 0 3rem; border-top: 1px solid var(--rule); font-size: 0.9375rem; color: var(--ink-2); }
footer .cta { font-size: 1.25rem; color: var(--ink); font-weight: 500; letter-spacing: -0.01em; margin-bottom: 0.75rem; }
footer .small { font-size: 0.8125rem; color: var(--ink-3); margin-top: 2rem; }

/* ---------- Case study pages ---------- */
.article-head { padding: clamp(2rem, 7vw, 4.5rem) 0 1.5rem; }
.article-head .back { font-size: 0.875rem; text-decoration: none; color: var(--ink-3); }
.article-head .back:hover { color: var(--ink); }
.article-head h1 { margin-top: 1.5rem; max-width: 46rem; }
.article-head .lede { margin-bottom: 0; }

.facts {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr));
  gap: 1rem 2rem; padding: 1.25rem 0; margin: 2rem 0 0;
  border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule);
}
.facts div { font-size: 0.875rem; }
.facts dt { font-family: var(--mono); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); margin-bottom: 0.2rem; }
.facts dd { margin: 0; color: var(--ink); }

.prose { max-width: var(--measure); padding-top: 0.5rem; }
.prose h2 { font-size: 1.25rem; }
.prose h2 .k { font-family: var(--mono); font-size: 0.8125rem; font-weight: 400; color: var(--ink-3); margin-right: 0.6rem; letter-spacing: 0; }
.prose p, .prose li { color: var(--ink-2); }
.prose strong { color: var(--ink); }
.note { font-size: 0.8125rem; color: var(--ink-3); margin-top: -0.75rem; }

.callout {
  border-left: 2px solid var(--accent); background: var(--accent-wash);
  padding: 0.9rem 1.1rem; margin: 1.5rem 0; border-radius: 0 4px 4px 0;
}
.callout p { margin: 0; color: var(--ink); }

table.results { width: 100%; border-collapse: collapse; margin: 1.25rem 0 1.5rem; font-size: 0.9375rem; }
table.results th, table.results td { text-align: left; padding: 0.65rem 0.75rem 0.65rem 0; border-bottom: 1px solid var(--rule); }
table.results th { font-family: var(--mono); font-weight: 500; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-3); }
table.results td.num { font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
table.results td.win { color: var(--accent-ink); font-weight: 500; }
.table-scroll { overflow-x: auto; }

.bars { margin: 1.5rem 0; }
.bars .b { display: grid; grid-template-columns: 9rem 1fr; gap: 0.75rem; align-items: center; margin-bottom: 0.6rem; font-size: 0.8125rem; }
.bars .b span { color: var(--ink-3); }
.bars .track { position: relative; height: 1.4rem; }
.bars .fill { position: absolute; inset: 0 auto 0 0; background: var(--rule); border-radius: 2px; display: flex; align-items: center; padding-left: 0.5rem; font-family: var(--mono); color: var(--ink); white-space: nowrap; min-width: 3.5rem; }
.bars .fill.after { background: var(--accent); color: var(--bg); }
@media (max-width: 34rem) { .bars .b { grid-template-columns: 1fr; gap: 0.2rem; } }

.flow { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; margin: 1.25rem 0 1.5rem; font-family: var(--mono); font-size: 0.8125rem; }
.flow span.s { border: 1px solid var(--rule); background: var(--surface); padding: 0.3rem 0.6rem; border-radius: 3px; color: var(--ink); }
.flow span.s.end { border-color: var(--accent); color: var(--accent-ink); }
.flow span.a { color: var(--ink-3); }

.next { display: flex; justify-content: space-between; gap: 1rem; margin-top: 4rem; padding-top: 1.5rem; border-top: 1px solid var(--rule); font-size: 0.9375rem; }
.next a { text-decoration: none; }
.next small { display: block; font-family: var(--mono); font-size: 0.75rem; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 0.2rem; }
.next .r { text-align: right; margin-left: auto; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

@media print {
  .bar nav, .theme-toggle, .next { display: none; }
  body { background: #fff; color: #000; }
}
.apps p.more { margin-top: 0.35rem; font-size: 0.8125rem; color: var(--ink-3); }
