/* ============================================================
   Tamerix -- core stylesheet
   The brand layer: variables, reset, type, layout, chrome.
   Loaded by the homepage and every issue page.

   What's here vs not:
     - HERE: theme, layout primitives, site header, hero, TOC,
             colophon, hero-cover, generic media + print.
     - HOMEPAGE-ONLY (assets/homepage.css): card grids, carousels.
     - ISSUE-SPECIFIC (issues/<name>/styles.css): prose marks,
             math visualizations, page-specific custom components.
   ============================================================ */

:root {
  /* paper */
  --bg:           #f4f1ec;
  --surface:      #ffffff;
  --ink:          #0c1c2c;
  --muted:        #6b7280;
  --subtle:       #94a3b8;
  --hairline:     #e6e1d6;
  --hairline-cool:#d9dee6;

  /* default accent (homepage uses ink as accent; essays override per body) */
  --accent:       #0c1c2c;
  --accent-soft:  #eceae4;
  --accent-ink:   #ffffff;

  /* type stacks */
  --font-display: "Iowan Old Style", "Charter", "Source Serif Pro", Georgia, ui-serif, serif;
  --font-body:    -apple-system, BlinkMacSystemFont, "Inter", "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --font-ui:      -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --font-mono:    ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;

  /* rhythm */
  --measure: 68ch;
  --gap:     24px;
  --radius:    2px;
  --radius-lg: 4px;
}

/* per-essay accent overrides -- add new issues here */
body[data-essay="transformer"] { --accent:#1e3a8a; --accent-soft:#e6ebf7; }
body[data-essay="finetuning"]  { --accent:#b45309; --accent-soft:#f7ede0; }
body[data-essay="embeddings"]  { --accent:#b45309; --accent-soft:#f7ede0; }
body[data-essay="rl"]          { --accent:#4d7c0f; --accent-soft:#eef2e1; }
body[data-essay="diffusion"]   { --accent:#7c2d12; --accent-soft:#f3e4dd; }

/* ============================================================
   Reset & base
   ============================================================ */

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.62;
  color: var(--ink);
  background: var(--bg);
  font-feature-settings: "kern" 1, "liga" 1;
  overflow-x: hidden;
}

a { color: var(--ink); }
a.subtle { color: var(--muted); }

p { margin: 0 0 14px; }

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

/* ============================================================
   Type system
   ============================================================ */

h1, h2, h3, .display {
  font-family: var(--font-display);
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.08;
  color: var(--ink);
  margin: 0 0 12px;
}
h1 { font-size: clamp(40px, 5vw, 64px); line-height: 1.05; }
h2 { font-size: clamp(26px, 2.6vw, 32px); letter-spacing: -0.015em; line-height: 1.15; }
h3 { font-family: var(--font-body); font-weight: 600; font-size: 18px; letter-spacing: 0; line-height: 1.4; }

.eyebrow,
.section-num {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
  margin: 0 0 8px;
}

.subhead {
  color: var(--muted);
  font-style: italic;
  font-family: var(--font-display);
  font-size: 18px;
  margin: 0 0 16px;
  line-height: 1.5;
}

.tabular { font-variant-numeric: tabular-nums; font-family: var(--font-mono); }

/* ============================================================
   Layout helpers
   ============================================================ */

.wrap        { max-width: 1180px; margin: 0 auto; padding: 0 32px; }
.wrap-narrow { max-width: 760px;  margin: 0 auto; padding: 0 32px; }

/* essay shell: sticky TOC + reading column */
.layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 56px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 32px;
}

main {
  min-width: 0;
  padding: 0 0 80px;
}

section {
  padding: 56px 0 64px;
  border-bottom: 1px solid var(--hairline);
  scroll-margin-top: 16px;
}
section:first-of-type { border-bottom: 1px solid var(--hairline); }

/* ============================================================
   Site header / wordmark
   ============================================================ */

.site-header {
  padding: 28px 0 0;
  display: flex;
  align-items: baseline;
  gap: 16px;
  flex-wrap: wrap;
}
.wordmark {
  font-family: var(--font-display);
  font-size: 19px;
  letter-spacing: -0.01em;
  color: var(--ink);
  text-decoration: none;
  font-weight: 500;
}
.wordmark:hover { color: var(--accent); }

/* ============================================================
   Hero (used by homepage and every issue)
   ============================================================ */

.hero { padding: 64px 0 56px; }
.hero h1 { margin-bottom: 18px; }
.hero .promise {
  font-family: var(--font-display);
  font-size: 21px;
  font-style: italic;
  color: var(--muted);
  line-height: 1.5;
  max-width: 60ch;
  margin: 0 0 8px;
  font-weight: 400;
}
.hero .eyebrow { margin-bottom: 16px; }

/* full-bleed accent strip above an essay's hero */
.hero-cover {
  background: var(--accent);
  color: var(--accent-ink);
  width: 100%;
  margin: 24px 0 0;
  padding: 56px 32px;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 200px;
}
.hero-cover svg { width: 280px; height: auto; max-width: 100%; }

/* ============================================================
   TOC (used by every issue)
   ============================================================ */

.toc {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow-y: auto;
  padding: 32px 8px 32px 0;
  font-family: var(--font-ui);
  font-size: 13px;
  border-right: 1px solid var(--hairline);
}
.toc h2 {
  font-family: var(--font-ui);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin: 0 0 14px;
  font-weight: 600;
}
.toc ol { list-style: none; padding: 0; margin: 0; }
.toc li { margin: 0; }
.toc a {
  display: block;
  padding: 5px 10px;
  color: var(--ink);
  text-decoration: none;
  border-left: 2px solid transparent;
  border-radius: 0;
  line-height: 1.35;
}
.toc a:hover { background: var(--accent-soft); }
.toc a.active {
  border-left-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

/* ============================================================
   Colophon (footer)
   ============================================================ */

.colophon {
  border-top: 1px solid var(--hairline);
  margin-top: 80px;
  padding: 32px 0 64px;
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--muted);
}
.colophon .row {
  display: flex;
  flex-wrap: wrap;
  gap: 32px;
  justify-content: space-between;
  align-items: flex-start;
  max-width: 1100px;
  margin: 0 auto;
  line-height: 1.6;
}
.colophon strong { color: var(--ink); font-weight: 600; }
.colophon a {
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid var(--hairline-cool);
}
.colophon a:hover {
  border-bottom-color: var(--accent);
  color: var(--accent);
}

/* ============================================================
   Responsive (cross-cutting)
   ============================================================ */

/* tablet / small laptop: hide TOC, collapse 2-col layout, shrink hero-cover */
@media (max-width: 1024px) {
  .layout { grid-template-columns: 1fr; gap: 0; padding: 0 18px; }
  .toc { display: none; }
  .hero-cover { padding: 32px 24px; min-height: 140px; }
  .hero-cover svg { width: 200px; }
}

/* phone: smaller body, less padding, tighter section gutters */
@media (max-width: 700px) {
  body { font-size: 16px; }
  .wrap, .wrap-narrow, .colophon .row { padding-left: 18px; padding-right: 18px; }
  section { padding: 36px 0 44px; }
  .hero { padding: 36px 0 32px; }
  /* prose containers should never overflow horizontally */
  .math-card { overflow-x: auto; padding-left: 16px; padding-right: 16px; }
  .math-card .formula { white-space: nowrap; min-width: max-content; }
  .why-card, .callout, .note, .takeaway { padding-left: 14px; padding-right: 14px; }
  /* main has no min-width: 0 by default in some browsers; explicit so children can shrink */
  main { padding-left: 0; padding-right: 0; }
  /* hero-cover even smaller */
  .hero-cover { padding: 24px 16px; min-height: 110px; }
  .hero-cover svg { width: 160px; }
}

/* small phone: drop body to 15.5px, tighten further */
@media (max-width: 480px) {
  body { font-size: 15.5px; line-height: 1.6; }
  .wrap, .wrap-narrow, .colophon .row { padding-left: 14px; padding-right: 14px; }
  section { padding: 28px 0 36px; }
  .colophon { padding: 24px 0 40px; }
}

@media print {
  .toc, .colophon, .hero-cover { display: none; }
  body { background: #fff; color: #000; }
  .layout { grid-template-columns: 1fr; }
  a { color: #000; text-decoration: none; }
  section { page-break-inside: avoid; }
}
