/* ==========================================================================
   samgray.work — site styles
   ========================================================================== */

:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --surface-sunk: #eeebe3;
  --text: #1c1b19;
  --text-muted: #6b675f;
  --text-faint: #9a958b;
  --border: #e2ddd2;
  --accent: #2f5d50;
  --accent-soft: #dfe9e4;
  --warn: #b5762a;
  --danger: #b2473c;

  --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-serif: "Newsreader", ui-serif, Georgia, "Times New Roman", serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --measure: 40rem;      /* reading column */
  --wide: 68rem;         /* figures */
  --gutter: 1.25rem;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141412;
    --surface: #1c1c19;
    --surface-sunk: #232320;
    --text: #ece9e2;
    --text-muted: #a29e95;
    --text-faint: #75716a;
    --border: #2f2e2a;
    --accent: #8cc2b0;
    --accent-soft: #22322d;
    --warn: #dba45f;
    --danger: #e0806f;
  }
}

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

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 1.0625rem;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; display: block; }
a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--accent); }

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

.skip-link {
  position: absolute; left: -999px; top: 0.5rem;
  background: var(--text); color: var(--bg); padding: 0.5rem 0.75rem; border-radius: 6px; z-index: 100;
}
.skip-link:focus { left: 0.5rem; }

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

.site-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s;
}
.site-header.is-scrolled { border-bottom-color: var(--border); }

.site-header__inner {
  max-width: var(--wide); margin: 0 auto; padding: 0.9rem var(--gutter);
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.wordmark { font-family: var(--font-serif); font-size: 1.25rem; font-weight: 500; text-decoration: none; letter-spacing: -0.01em; }
.site-nav { display: flex; gap: 1.25rem; font-size: 0.9375rem; }
.site-nav a { text-decoration: none; color: var(--text-muted); }
.site-nav a:hover, .site-nav a[aria-current="page"] { color: var(--text); }

/* ---------- Case study layout ---------- */

.cs { max-width: var(--wide); margin: 0 auto; padding: 0 var(--gutter); }

.cs-hero { padding: 4.5rem 0 2.5rem; max-width: 52rem; }
.eyebrow {
  font-family: var(--font-mono); font-size: 0.75rem; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-muted); margin: 0 0 1.25rem;
}
.eyebrow span { color: var(--text-faint); padding: 0 0.35em; }

.cs-hero h1 {
  font-family: var(--font-serif); font-weight: 400;
  font-size: clamp(2.25rem, 5.5vw, 3.75rem); line-height: 1.08; letter-spacing: -0.02em;
  margin: 0 0 1.5rem;
}
.cs-hero .lede { font-size: 1.1875rem; color: var(--text-muted); max-width: var(--measure); margin: 0; }

.meta {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: 1.25rem 2rem;
  margin: 2.5rem 0 0; padding: 1.25rem 0 0; border-top: 1px solid var(--border);
}
.meta dt { font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-faint); margin-bottom: 0.25rem; }
.meta dd { margin: 0; font-size: 0.9375rem; }

/* Body: TOC rail + content */
.cs-body {
  display: grid; grid-template-columns: 1fr; gap: 0;
  padding-bottom: 4rem;
}
@media (min-width: 64rem) {
  .cs-body { grid-template-columns: 11rem minmax(0, 1fr); gap: 3.5rem; }
}

.toc { display: none; }
@media (min-width: 64rem) {
  .toc { display: block; position: sticky; top: 5.5rem; align-self: start; padding-top: 0.5rem; }
}
.toc p { font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-faint); margin: 0 0 0.75rem; }
.toc ol { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--border); }
.toc a {
  display: block; padding: 0.3rem 0 0.3rem 0.9rem; margin-left: -1px;
  border-left: 1px solid transparent; font-size: 0.875rem; line-height: 1.35;
  color: var(--text-muted); text-decoration: none; transition: color 0.15s, border-color 0.15s;
}
.toc a:hover { color: var(--text); }
.toc a.is-active { color: var(--text); border-left-color: var(--text); }

.cs-content { min-width: 0; }

.section { padding: 3.5rem 0 0; scroll-margin-top: 5rem; }
.section > *:not(.figure):not(.stats):not(.features):not(.diagram) { max-width: var(--measure); }

.section-label {
  font-family: var(--font-mono); font-size: 0.75rem; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--accent); margin: 0 0 0.75rem;
}
.section h2 {
  font-family: var(--font-serif); font-weight: 400;
  font-size: clamp(1.75rem, 3.4vw, 2.375rem); line-height: 1.15; letter-spacing: -0.015em;
  margin: 0 0 1.25rem;
}
.section h3 { font-size: 1.0625rem; font-weight: 600; margin: 0 0 0.5rem; }
.section p { margin: 0 0 1.1rem; }
.section .callout-line { font-family: var(--font-serif); font-size: 1.375rem; line-height: 1.35; font-style: italic; }

/* ---------- Figures ---------- */

.figure { margin: 2rem 0 0.5rem; }
.figure img, .ph {
  width: 100%; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface);
}
.figure figcaption { font-size: 0.8125rem; color: var(--text-muted); margin-top: 0.75rem; }

/* Placeholder used until real screenshots land in /assets/images */
.ph {
  aspect-ratio: 16 / 10; display: grid; place-items: center; text-align: center; padding: 1.5rem;
  background:
    repeating-linear-gradient(135deg, transparent 0 14px, color-mix(in srgb, var(--border) 45%, transparent) 14px 15px),
    var(--surface-sunk);
  color: var(--text-faint); font-family: var(--font-mono); font-size: 0.75rem; letter-spacing: 0.04em;
}
.ph--wide { aspect-ratio: 21 / 9; }
.ph--square { aspect-ratio: 1 / 1; }

.figure-grid { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 40rem) { .figure-grid { grid-template-columns: 1fr 1fr; } }

/* ---------- Stats ---------- */

.stats {
  display: grid; grid-template-columns: 1fr; gap: 1px;
  background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
  margin: 1.75rem 0 0;
}
@media (min-width: 40rem) { .stats { grid-template-columns: repeat(3, 1fr); } }
.stat { background: var(--surface); padding: 1.5rem 1.5rem 1.4rem; }
.stat strong {
  display: block; font-family: var(--font-serif); font-weight: 400;
  font-size: clamp(2.25rem, 4vw, 3rem); line-height: 1; letter-spacing: -0.02em; margin-bottom: 0.6rem;
}
.stat span { font-size: 0.9375rem; color: var(--text-muted); line-height: 1.45; display: block; }

/* ---------- Quote ---------- */

.quote { margin: 2.25rem 0; padding: 0 0 0 1.5rem; border-left: 2px solid var(--accent); }
.quote p { font-family: var(--font-serif); font-size: 1.3125rem; line-height: 1.45; margin: 0 0 0.75rem; }
.quote cite { font-style: normal; font-size: 0.875rem; color: var(--text-muted); }

/* ---------- Diagram (structure change) ---------- */

.diagram {
  margin: 2rem 0 0.5rem; padding: 1.75rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); display: grid; gap: 1.5rem; align-items: center;
  grid-template-columns: 1fr;
}
@media (min-width: 48rem) { .diagram { grid-template-columns: 1fr auto 1fr; } }
.diagram__col { display: grid; gap: 0.6rem; }
.diagram__title { font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-faint); margin: 0 0 0.25rem; }
.node {
  border: 1px solid var(--border); border-radius: 8px; padding: 0.7rem 0.9rem; font-size: 0.875rem;
  display: flex; justify-content: space-between; gap: 0.75rem; background: var(--bg);
}
.node em { font-style: normal; font-family: var(--font-mono); font-size: 0.7rem; color: var(--text-faint); align-self: center; }
.node--root { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.node--child { margin-left: 1.25rem; }
.diagram__arrow { font-size: 1.5rem; color: var(--text-faint); text-align: center; }
@media (max-width: 47.99rem) { .diagram__arrow { transform: rotate(90deg); } }

/* ---------- Features ---------- */

.features { display: grid; gap: 3rem; margin-top: 2rem; }
.feature { display: grid; gap: 1.25rem; }
@media (min-width: 56rem) {
  .feature { grid-template-columns: minmax(0, 18rem) minmax(0, 1fr); gap: 2.5rem; align-items: start; }
}
.feature__num { font-family: var(--font-mono); font-size: 0.75rem; color: var(--text-faint); margin: 0 0 0.4rem; }
.feature p { color: var(--text-muted); font-size: 0.9875rem; }
.feature .figure { margin: 0; }

/* Status chips used in captions/copy */
.chip { display: inline-flex; align-items: center; gap: 0.35em; font-size: 0.8em; padding: 0.1em 0.55em; border-radius: 999px; border: 1px solid var(--border); white-space: nowrap; }
.chip::before { content: ""; width: 0.5em; height: 0.5em; border-radius: 50%; background: currentColor; }
.chip--ok { color: var(--accent); }
.chip--warn { color: var(--warn); }
.chip--risk { color: var(--danger); }

/* ---------- Credits ---------- */

.credits { display: grid; gap: 1rem; margin: 1.75rem 0 0; padding: 0; list-style: none; }
@media (min-width: 40rem) { .credits { grid-template-columns: 1fr 1fr; } }
.credits li { border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; background: var(--surface); }
.credits strong { display: block; font-weight: 600; }
.credits .role { font-size: 0.8125rem; color: var(--text-faint); display: block; margin-bottom: 0.4rem; }
.credits p { font-size: 0.9rem; color: var(--text-muted); margin: 0; }

/* ---------- Pager + footer ---------- */

.pager {
  max-width: var(--wide); margin: 0 auto; padding: 2rem var(--gutter);
  display: flex; justify-content: space-between; gap: 1rem; border-top: 1px solid var(--border);
}
.pager a { text-decoration: none; }
.pager small { display: block; font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-faint); }
.pager .next { text-align: right; }
.pager .disabled { color: var(--text-faint); }

.site-footer {
  max-width: var(--wide); margin: 0 auto; padding: 1.5rem var(--gutter) 3rem;
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.75rem;
  font-size: 0.8125rem; color: var(--text-muted);
}
.site-footer ul { list-style: none; margin: 0; padding: 0; display: flex; gap: 1.25rem; }

/* ---------- Reveal on scroll ---------- */

.js .reveal { opacity: 0; transform: translateY(12px); transition: opacity 0.6s ease, transform 0.6s ease; }
.js .reveal.is-visible { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) {
  .js .reveal { opacity: 1; transform: none; transition: none; }
}
