/* Artifact Hub — shared stylesheet.
   Linked by the index, the styleguide, and every artifact page.
   Spec lives in DESIGN.md; live examples at /styleguide.html.
   Light only by design: dark text on white is a site rule. */

/* ---------- Tokens ---------- */
:root {
  color-scheme: light;

  /* Color — every text color here clears WCAG AA (4.5:1) on --paper and --surface. */
  --paper: #ffffff;
  --surface: #f7f6f3;      /* callouts, panels, zebra rows */
  --surface-2: #eeece6;    /* table headers, code, chips */
  --ink: #111111;          /* body text */
  --ink-2: #3b3b3b;        /* secondary text: meta, captions. Never lighter. */
  --rule: #d8d5cd;         /* hairlines */
  --rule-strong: #111111;  /* masthead + section rules */
  --link: #1d4ed8;
  --link-hover: #1e3a8a;
  --focus: #1d4ed8;

  /* Signal colors — use for callout edges and badges, not body text blocks. */
  --good: #166534;  --good-bg: #ecf6ef;
  --warn: #92400e;  --warn-bg: #fdf4e3;
  --bad:  #991b1b;  --bad-bg:  #fbeceb;
  --info: #1d4ed8;  --info-bg: #eef3fd;

  /* Category identity — set on <body data-cat="…"> or any element; exposed as --cat. */
  --cat: #111111;
  --cat-faith-and-ai: #7a1f3d;
  --cat-investing-and-markets: #166534;
  --cat-sports: #b4410e;
  --cat-research-and-reports: #1e40af;
  --cat-personal-projects: #0f6e6e;

  /* Type */
  --serif: "Source Serif 4", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --fs-xs: 0.78rem;
  --fs-sm: 0.875rem;
  --fs-base: 1.0625rem;  /* 17px reading size */
  --fs-lg: 1.25rem;
  --fs-h3: 1.125rem;
  --fs-h2: 1.6rem;
  --fs-h1: clamp(2rem, 1.4rem + 2.6vw, 2.9rem);

  /* Space (4px base) */
  --s1: 0.25rem; --s2: 0.5rem; --s3: 0.75rem; --s4: 1rem;
  --s5: 1.5rem;  --s6: 2rem;   --s7: 3rem;    --s8: 4.5rem;

  /* Layout */
  --measure: 70ch;     /* prose column */
  --wide: 1120px;      /* tables, grids, index */
  --gutter: clamp(1rem, 4vw, 2rem);
  --radius: 6px;
}

[data-cat="faith-and-ai"]          { --cat: var(--cat-faith-and-ai); }
[data-cat="investing-and-markets"] { --cat: var(--cat-investing-and-markets); }
[data-cat="sports"]                { --cat: var(--cat-sports); }
[data-cat="research-and-reports"]  { --cat: var(--cat-research-and-reports); }
[data-cat="personal-projects"]     { --cat: var(--cat-personal-projects); }

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: var(--s6); }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: var(--fs-base);
  line-height: 1.6;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { line-height: 1.2; margin: 0; text-wrap: balance; }
h1 { font-family: var(--serif); font-size: var(--fs-h1); font-weight: 600; letter-spacing: -0.015em; }
h2 { font-family: var(--serif); font-size: var(--fs-h2); font-weight: 600; letter-spacing: -0.01em; }
h3 { font-family: var(--sans); font-size: var(--fs-h3); font-weight: 650; }
h4 { font-family: var(--sans); font-size: var(--fs-sm); font-weight: 650; text-transform: uppercase; letter-spacing: 0.06em; }
p { margin: 0 0 var(--s4); text-wrap: pretty; }
a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
a:hover { color: var(--link-hover); text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 2px; }
strong { font-weight: 650; }
small, .small { font-size: var(--fs-sm); }
code, kbd { font-family: var(--mono); font-size: 0.86em; background: var(--surface-2); padding: 0.08em 0.35em; border-radius: 3px; }
kbd { border: 1px solid var(--rule); border-bottom-width: 2px; background: var(--paper); }
hr { border: 0; border-top: 1px solid var(--rule); margin: var(--s6) 0; }
ul, ol { margin: 0 0 var(--s4); padding-left: 1.35rem; }
li { margin: 0.3rem 0; }
li::marker { color: var(--ink-2); }
blockquote {
  margin: var(--s5) 0; padding: 0 0 0 var(--s4);
  border-left: 3px solid var(--cat); font-style: italic; font-size: var(--fs-lg);
}
blockquote cite { display: block; margin-top: var(--s2); font: normal var(--fs-sm) var(--sans); color: var(--ink-2); }
blockquote cite::before { content: "— "; }
.sans { font-family: var(--sans); }
.muted { color: var(--ink-2); }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Hub bar (top of every artifact) ---------- */
.hub-bar {
  font-family: var(--sans); font-size: var(--fs-sm);
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
}
.hub-bar > div {
  max-width: var(--wide); margin: 0 auto; padding: var(--s3) var(--gutter);
  display: flex; gap: var(--s4); align-items: center; justify-content: space-between;
}
.hub-bar a { color: var(--ink); text-decoration: none; font-weight: 600; }
.hub-bar a:hover { text-decoration: underline; }
.hub-bar .crumb { color: var(--ink-2); }
.hub-bar .crumb b { color: var(--cat); font-weight: 600; }

/* ---------- Document layout ---------- */
.doc { max-width: var(--wide); margin: 0 auto; padding: var(--s6) var(--gutter) var(--s8); }
.doc > *, .prose > * { max-width: var(--measure); }
.doc > .wide, .doc > .table-wrap, .doc > .grid-2, .doc > .grid-3, .doc > .doc-foot { max-width: none; }
.doc > h2 { margin: var(--s7) 0 var(--s4); padding-top: var(--s4); border-top: 1px solid var(--rule); }
.doc > h3 { margin: var(--s5) 0 var(--s3); }
.doc > h2 + h3 { margin-top: var(--s3); }
.doc h2 .aside { font: 400 var(--fs-sm) var(--sans); color: var(--ink-2); letter-spacing: 0; }

/* Header block: kicker → title → dek → meta */
.doc-header { margin-bottom: var(--s6); padding-bottom: var(--s5); border-bottom: 2px solid var(--rule-strong); max-width: none !important; }
.doc-header > * { max-width: var(--measure); }
.kicker {
  font-family: var(--sans); font-size: var(--fs-xs); font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.09em; color: var(--cat);
  margin: 0 0 var(--s3); display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap;
}
.doc-header h1 { margin-bottom: var(--s3); }
.dek { font-size: var(--fs-lg); line-height: 1.45; color: var(--ink); margin: 0 0 var(--s4); }
.meta {
  font-family: var(--sans); font-size: var(--fs-sm); color: var(--ink-2);
  display: flex; flex-wrap: wrap; gap: var(--s1) var(--s3); margin: 0;
}
.meta > :not(:last-child)::after { content: "·"; margin-left: var(--s3); color: var(--ink-2); }

/* ---------- Badges, tags ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 0.35em;
  font: 700 0.7rem/1 var(--sans); text-transform: uppercase; letter-spacing: 0.08em;
  padding: 0.3em 0.55em; border-radius: 999px; border: 1px solid currentColor; color: var(--ink);
  white-space: nowrap;
}
.badge--living { color: var(--good); }
.badge--living::before { content: ""; width: 0.5em; height: 0.5em; border-radius: 50%; background: currentColor; }
.badge--draft { color: var(--warn); }
.badge--archived { color: var(--ink-2); }

.tags { display: flex; flex-wrap: wrap; gap: var(--s1) var(--s2); margin: 0; padding: 0; list-style: none; }
.tag {
  display: inline-block; font: 500 var(--fs-xs)/1.5 var(--sans); color: var(--ink);
  background: var(--surface-2); padding: 0.1em 0.55em; border-radius: 4px;
  border: 0; text-decoration: none; white-space: nowrap;
}
button.tag { cursor: pointer; }
button.tag:hover, a.tag:hover { background: var(--ink); color: var(--paper); }

/* ---------- Callouts ---------- */
.callout {
  background: var(--surface); border-left: 4px solid var(--cat);
  padding: var(--s4) var(--s5); margin: var(--s5) 0; border-radius: 0 var(--radius) var(--radius) 0;
}
.callout > :last-child { margin-bottom: 0; }
.callout-label {
  display: block; font: 700 var(--fs-xs) var(--sans); text-transform: uppercase;
  letter-spacing: 0.09em; color: var(--cat); margin-bottom: var(--s2);
}
.callout--lead { font-size: var(--fs-lg); line-height: 1.5; }
.callout--good { --cat: var(--good); background: var(--good-bg); }
.callout--warn { --cat: var(--warn); background: var(--warn-bg); }
.callout--bad  { --cat: var(--bad);  background: var(--bad-bg); }
.callout--info { --cat: var(--info); background: var(--info-bg); }
/* Instructions for future agents/editors. Visible, but visually quiet. */
.callout--meta {
  --cat: var(--ink-2); background: var(--paper); border: 1px dashed var(--rule);
  border-left: 1px dashed var(--rule); border-radius: var(--radius);
  font: var(--fs-sm)/1.55 var(--sans);
}

.pullquote {
  font-size: var(--fs-h2); line-height: 1.3; font-weight: 500; letter-spacing: -0.01em;
  margin: var(--s6) 0; padding: var(--s5) 0; border-top: 2px solid var(--rule-strong); border-bottom: 1px solid var(--rule);
}

/* ---------- Panels & grids ---------- */
.grid-2, .grid-3 { display: grid; gap: var(--s4); margin: var(--s5) 0; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 760px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
.panel { border: 1px solid var(--rule); border-radius: var(--radius); padding: var(--s4) var(--s5); background: var(--paper); }
.panel > h3:first-child, .panel > h4:first-child { margin: 0 0 var(--s3); }
.panel > :last-child { margin-bottom: 0; }
.panel--accent { border-top: 3px solid var(--cat); }
.panel ul, .panel ol { font-size: 0.97em; }

/* Stat tiles */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--s3); margin: var(--s5) 0; max-width: none !important; }
.stat { border-top: 2px solid var(--rule-strong); padding: var(--s3) 0 0; }
.stat .value { font: 600 1.8rem/1.1 var(--serif); font-variant-numeric: tabular-nums; display: block; }
.stat .label { font: var(--fs-sm)/1.35 var(--sans); color: var(--ink-2); display: block; margin-top: var(--s1); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; margin: var(--s4) 0 var(--s5); border: 1px solid var(--rule); border-radius: var(--radius); -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font: var(--fs-sm)/1.5 var(--sans); }
.table-wrap table { margin: 0; }
caption { caption-side: top; text-align: left; font-weight: 650; padding: var(--s3) var(--s4); border-bottom: 1px solid var(--rule); }
th, td { padding: var(--s3) var(--s4); text-align: left; vertical-align: top; border-bottom: 1px solid var(--rule); }
th { background: var(--surface-2); font-weight: 650; font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.05em; white-space: nowrap; }
tbody tr:last-child > * { border-bottom: 0; }
tbody tr:nth-child(even) > td { background: var(--surface); }
tbody tr:hover > td { background: var(--info-bg); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.date { white-space: nowrap; font-variant-numeric: tabular-nums; font-weight: 600; }
td .sub, th .sub { display: block; font-weight: 400; font-size: var(--fs-xs); color: var(--ink-2); text-transform: none; letter-spacing: 0; margin-top: 2px; }
td .tags { gap: 4px; }
td > p:last-child { margin-bottom: 0; }

/* .stack: on phones each row becomes a labeled card. hub.js copies <th> text into data-label. */
@media (max-width: 700px) {
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: auto; }
  table.stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.stack tr { padding: var(--s3) var(--s4); border-bottom: 1px solid var(--rule); }
  table.stack tbody tr:last-child { border-bottom: 0; }
  table.stack td, table.stack tbody tr:nth-child(even) > td, table.stack tbody tr:hover > td { border: 0; padding: var(--s1) 0; background: none; }
  table.stack td[data-label]::before {
    content: attr(data-label); display: block; font-size: var(--fs-xs); font-weight: 650;
    text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-2); margin-bottom: 2px;
  }
  table.stack td.date::before { display: none; }
  table.stack td.date { font-size: var(--fs-base); }
  table.stack td.num { text-align: left; }
}

/* ---------- Ordered steps / timeline ---------- */
.steps { list-style: none; padding: 0; counter-reset: step; }
.steps > li { counter-increment: step; position: relative; padding-left: 2.6rem; margin: var(--s4) 0; }
.steps > li::before {
  content: counter(step); position: absolute; left: 0; top: 0.1em;
  width: 1.8rem; height: 1.8rem; border-radius: 50%; background: var(--ink); color: var(--paper);
  font: 700 var(--fs-sm)/1.8rem var(--sans); text-align: center;
}

/* ---------- Table of contents (filled by hub.js) ---------- */
.toc { font-family: var(--sans); font-size: var(--fs-sm); margin: 0 0 var(--s6); padding: var(--s4) var(--s5); background: var(--surface); border-radius: var(--radius); }
.toc:empty { display: none; }
.toc h4 { margin: 0 0 var(--s2); color: var(--ink-2); }
.toc ol { margin: 0; padding-left: 1.2rem; columns: 2 16rem; column-gap: var(--s6); }
.toc li { margin: 0; padding: 0.15rem 0; break-inside: avoid; }
.toc a { color: var(--ink); text-decoration: none; }
.toc a:hover { color: var(--link); text-decoration: underline; }

/* Section anchors (added by hub.js) */
.anchor { margin-left: 0.35em; font: 400 0.7em var(--sans); color: var(--ink-2); text-decoration: none; opacity: 0; }
h2:hover .anchor, h3:hover .anchor, .anchor:focus { opacity: 1; }

/* ---------- Footer / sources ---------- */
.doc-foot {
  margin-top: var(--s7); padding-top: var(--s4); border-top: 2px solid var(--rule-strong);
  font: var(--fs-sm)/1.55 var(--sans); color: var(--ink);
}
.doc-foot h4 { margin: var(--s4) 0 var(--s2); }
.sources { padding-left: 1.4rem; columns: 2 24rem; column-gap: var(--s6); }
.sources li { break-inside: avoid; overflow-wrap: anywhere; }
.back-top { font: 600 var(--fs-sm) var(--sans); }

/* ---------- Print ---------- */
@media print {
  .hub-bar, .toc, .anchor, .back-top, .callout--meta { display: none !important; }
  body { font-size: 11pt; }
  .doc { padding: 0; max-width: none; }
  a { color: var(--ink); }
  .doc a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 0.8em; word-break: break-all; }
  .table-wrap { overflow: visible; border: 0; }
  tr, .panel, .callout { break-inside: avoid; }
  h2, h3 { break-after: avoid; }
}

@media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }
