/* ==========================================================================
   RivetHub — design system v2
   Emerald-on-dark product identity. No build step, no frameworks, no CDN.
   Fonts are self-hosted (see site/fonts/README.md); system stacks carry the
   site until the woff2 files land.
   ========================================================================== */

/* ---------- Font faces (self-hosted; fallbacks below carry until present) */
@font-face {
  font-family: "DM Sans";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/dm-sans-400.woff2") format("woff2");
}
@font-face {
  font-family: "DM Sans";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("fonts/dm-sans-500.woff2") format("woff2");
}
@font-face {
  font-family: "DM Sans";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/dm-sans-700.woff2") format("woff2");
}
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/jetbrains-mono-400.woff2") format("woff2");
}
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/jetbrains-mono-700.woff2") format("woff2");
}

/* ---------- Tokens: dark is the primary identity */
:root {
  --font-ui: "DM Sans", system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo,
    Consolas, "Liberation Mono", monospace;

  --bg: #090d0b;
  --panel: #101713;
  --panel-2: #16211a;
  --fg: #eae6da;
  --muted: #9daaa0;
  --faint: #68766c;
  --accent: #10b981;
  --accent-hi: #34d399;
  --on-accent: #03130c;
  --link: #34d399;
  --line: #1d2a22;
  --line-strong: #2c4034;
  --grid: rgba(52, 211, 153, 0.05);
  --glow: rgba(16, 185, 129, 0.14);
  --code-bg: rgba(16, 185, 129, 0.09);
  --warn: #e7b45a;
  --warn-line: #57431f;
  --radius: 14px;
  color-scheme: dark;
}

/* Terminal blocks are "screens": dark in both color schemes, on purpose. */
:root {
  --term-bg: #070b09;
  --term-bar: #0d1410;
  --term-line: #1c2b22;
  --term-fg: #e8e4d8;
  --term-muted: #75857a;
  --term-accent: #34d399;
}

/* ---------- Light variant: emerald on paper-white, grid at lower alpha */
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f7f6f0;
    --panel: #ffffff;
    --panel-2: #f0efe6;
    --fg: #212820;
    --muted: #59665c;
    --faint: #8a958c;
    --accent: #047857;
    --accent-hi: #059669;
    --on-accent: #ffffff;
    --link: #047857;
    --line: #e3e1d2;
    --line-strong: #cdd6c9;
    --grid: rgba(4, 120, 87, 0.055);
    --glow: rgba(4, 120, 87, 0.1);
    --code-bg: rgba(4, 120, 87, 0.08);
    --warn: #9a6207;
    --warn-line: #e2c48d;
    color-scheme: light;
  }
}

/* ---------- Base */
* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: 1rem;
  line-height: 1.62;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* 64px blueprint grid + a soft emerald bloom at the top of the viewport. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(58rem 26rem at 50% -8%, var(--glow), transparent 62%),
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: auto, 64px 64px, 64px 64px;
}

::selection { background: rgba(16, 185, 129, 0.3); }

h1, h2, h3, h4 { line-height: 1.15; font-weight: 700; letter-spacing: -0.015em; }
h2 { font-size: 1.55rem; margin: 0 0 0.9rem; }
h3 { font-size: 1.08rem; margin: 0 0 0.45rem; }
p { margin: 0.55rem 0; }
ul, ol { padding-left: 1.35rem; }
li { margin: 0.32rem 0; }

a {
  color: var(--link);
  text-decoration: none;
  text-underline-offset: 3px;
}
a:hover { text-decoration: underline; }

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

code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--code-bg);
  padding: 0.08em 0.38em;
  border-radius: 5px;
  word-break: break-word;
}

/* ---------- Layout shells */
.wrap       { width: min(72ch, 100% - 2.5rem); margin-inline: auto; }
.wrap-wide  { width: min(74rem, 100% - 2.5rem); margin-inline: auto; }

section.block { padding: clamp(2.6rem, 6vh, 4.4rem) 0; }
section.block + section.block { border-top: 1px solid var(--line); }

.kicker {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 400;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 0.5rem;
}

.section-lede { color: var(--muted); max-width: 62ch; margin-top: -0.2rem; }

/* ---------- Header */
header.site {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
header.site .shell {
  width: min(74rem, 100% - 2.5rem);
  margin-inline: auto;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  padding: 0.7rem 0;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 700;
  font-size: 1.08rem;
  letter-spacing: -0.01em;
  color: var(--fg);
  margin-right: auto;
}
.brand:hover { text-decoration: none; }
.brand span { color: var(--accent); }
.brand .mark { width: 24px; height: 24px; fill: var(--accent); flex: none; }

nav.site-nav { display: flex; align-items: center; gap: 0.25rem; flex-wrap: wrap; }
nav.site-nav a {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 500;
  padding: 0.38rem 0.75rem;
  border-radius: 999px;
  transition: color 0.15s ease, background-color 0.15s ease;
}
nav.site-nav a:hover {
  color: var(--fg);
  background: var(--panel-2);
  text-decoration: none;
}
nav.site-nav a[aria-current="page"] {
  color: var(--accent);
  background: var(--code-bg);
}

/* ---------- Hero */
.hero { padding: clamp(3rem, 9vh, 6rem) 0 clamp(2.4rem, 6vh, 4rem); }
.hero .wrap-wide {
  display: grid;
  grid-template-columns: minmax(0, 1.04fr) minmax(0, 0.96fr);
  gap: clamp(2rem, 4vw, 4rem);
  align-items: center;
}
.hero .wrap-wide > * { min-width: 0; }
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 1.1rem;
}
.eyebrow::before {
  content: "";
  width: 8px; height: 8px;
  background: var(--accent);
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
}
.hero h1 {
  font-size: clamp(2.45rem, 1.7rem + 3.2vw, 3.7rem);
  line-height: 1.04;
  letter-spacing: -0.03em;
  margin: 0 0 1.1rem;
}
.hero h1 .em { color: var(--accent); font-style: normal; }
.lede {
  font-size: 1.14rem;
  color: var(--muted);
  max-width: 56ch;
  margin: 0 0 1.6rem;
}

.cta-row { display: flex; gap: 0.7rem; flex-wrap: wrap; margin: 0 0 1.8rem; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 500;
  font-size: 0.95rem;
  color: var(--on-accent);
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 0.68rem 1.15rem;
  transition: transform 0.15s ease, background-color 0.15s ease,
    border-color 0.15s ease, box-shadow 0.15s ease;
}
.btn:hover {
  background: var(--accent-hi);
  border-color: var(--accent-hi);
  text-decoration: none;
  transform: translateY(-1px);
  box-shadow: 0 10px 26px -12px var(--accent);
}
.btn--ghost {
  background: transparent;
  color: var(--fg);
  border-color: var(--line-strong);
}
.btn--ghost:hover {
  background: var(--panel-2);
  color: var(--accent);
  border-color: var(--accent);
  box-shadow: none;
}

.hero-note {
  font-size: 0.88rem;
  color: var(--faint);
  max-width: 58ch;
  margin: 0.9rem 0 0;
}
.hero-note code { font-size: 0.82em; }

/* ---------- Status strip */
.strip {
  border-block: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 55%, transparent);
}
.strip .wrap-wide {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0;
  padding-block: 0.85rem;
}
.strip .item {
  display: inline-flex;
  align-items: baseline;
  gap: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--muted);
  white-space: nowrap;
}
.strip .item b { color: var(--accent); font-weight: 700; }
.strip .item + .item::before {
  content: "·";
  color: var(--faint);
  margin: 0 1.1rem;
}

/* ---------- Terminal blocks */
.term {
  position: relative;
  border: 1px solid var(--term-line);
  border-radius: var(--radius);
  background: var(--term-bg);
  overflow: hidden;
  box-shadow: 0 24px 48px -28px rgba(0, 0, 0, 0.7);
  margin: 1rem 0;
}
.term__bar {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.6rem 0.9rem;
  background: var(--term-bar);
  border-bottom: 1px solid var(--term-line);
}
.term__bar i {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--term-line);
  flex: none;
}
.term__bar i:first-child { background: rgba(52, 211, 153, 0.55); }
.term__title {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  color: var(--term-muted);
  margin-left: 0.4rem;
  padding-right: 3.6rem; /* room for the JS-injected copy button */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.term pre {
  margin: 0;
  padding: 1rem 1.15rem;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  line-height: 1.75;
  color: var(--term-fg);
}
.term pre code {
  background: none;
  padding: 0;
  font-size: inherit;
  color: inherit;
  word-break: normal;
}
.term .ps {
  color: var(--term-accent);
  user-select: none;
  -webkit-user-select: none;
}
.term .c { color: var(--term-muted); }

.copy {
  position: absolute;
  top: 0.45rem;
  right: 0.55rem;
  z-index: 2;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  color: var(--term-muted);
  background: transparent;
  border: 1px solid var(--term-line);
  border-radius: 6px;
  padding: 0.22rem 0.6rem;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.copy:hover { color: var(--term-accent); border-color: var(--term-accent); }

/* ---------- Steps */
.steps {
  list-style: none;
  padding: 0;
  margin: 1.8rem 0 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1.2rem;
  counter-reset: step;
}
.step {
  counter-increment: step;
  display: flex;
  flex-direction: column;
  min-width: 0;
  margin: 0;
  padding: 1.4rem 1.4rem 1.5rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.step::before {
  content: "0" counter(step);
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--accent);
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.75rem;
  margin-bottom: 0.9rem;
}
.step p { color: var(--muted); font-size: 0.94rem; }
.step .term { margin: auto 0 0.8rem; }
.step .term pre { font-size: 0.8rem; padding: 0.85rem 0.95rem; }
.step .more { font-size: 0.9rem; font-weight: 500; margin-top: 0.2rem; }

/* ---------- Cards */
.cards {
  list-style: none;
  padding: 0;
  margin: 1.8rem 0 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(250px, 100%), 1fr));
  gap: 1.2rem;
}
.card {
  margin: 0;
  padding: 1.5rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: transform 0.16s ease, border-color 0.16s ease,
    box-shadow 0.16s ease;
}
.card:hover {
  transform: translateY(-3px);
  border-color: var(--line-strong);
  box-shadow: 0 18px 40px -22px var(--glow), 0 0 0 1px var(--glow);
}
.card .icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px; height: 40px;
  border-radius: 10px;
  background: var(--code-bg);
  color: var(--accent);
  margin-bottom: 0.9rem;
}
.card .icon svg { width: 21px; height: 21px; }
.card p { color: var(--muted); font-size: 0.93rem; margin-bottom: 0; }

/* ---------- Diagram */
.diagram { margin: 0; }
.diagram svg { display: block; width: 100%; height: auto; }
.diagram figcaption {
  font-size: 0.85rem;
  color: var(--faint);
  margin-top: 0.9rem;
  max-width: 60ch;
}
/* SVG palette hooks — the diagram follows the page theme. */
.diagram .d-link   { stroke: var(--accent); stroke-width: 1.6; opacity: 0.6; }
.diagram .d-flow   { stroke: var(--accent-hi); stroke-width: 1.6; fill: none;
                     stroke-dasharray: 1.5 9; stroke-linecap: round;
                     animation: flow 1.4s linear infinite; }
.diagram .d-chan   { stroke: var(--faint); stroke-width: 1.4;
                     stroke-dasharray: 4 5; opacity: 0.8; }
.diagram .d-box    { fill: var(--panel); stroke: var(--line-strong);
                     stroke-width: 1.4; }
.diagram .d-hub    { fill: var(--panel-2); stroke: var(--accent);
                     stroke-width: 1.8; }
.diagram .d-label  { fill: var(--fg); font-family: var(--font-ui);
                     font-weight: 700; font-size: 15px; }
.diagram .d-sub    { fill: var(--faint); font-family: var(--font-mono);
                     font-size: 10.5px; }
.diagram .d-tls    { fill: var(--accent); font-family: var(--font-mono);
                     font-size: 10px; letter-spacing: 0.04em; }
@keyframes flow { to { stroke-dashoffset: -10.5; } }

/* ---------- Fact lists (custom square markers, blueprint feel) */
.facts { list-style: none; padding: 0; margin: 1.2rem 0; }
.facts li {
  position: relative;
  padding-left: 1.5rem;
  margin: 0.55rem 0;
  color: var(--muted);
}
.facts li::before {
  content: "";
  position: absolute;
  left: 0.1rem;
  top: 0.52em;
  width: 7px; height: 7px;
  border: 1.5px solid var(--accent);
  border-radius: 2px;
}
.facts li strong, .facts li code { color: var(--fg); }

/* ---------- Callouts */
.note, .warn {
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  background: var(--panel);
  padding: 0.9rem 1.15rem;
  margin: 1.1rem 0;
  color: var(--muted);
  font-size: 0.95rem;
}
.note strong, .warn strong { color: var(--fg); }
.warn { border-left-color: var(--warn); border-color: var(--warn-line); }

/* ---------- Requirements panel */
.req {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 1.3rem 1.5rem 1.1rem;
  margin: 1.2rem 0;
}
.req h3 {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 400;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.7rem;
}
.req ul { margin: 0; }

/* ---------- Definition lists ("what gets installed where", pin fields) */
dl.what { margin: 1.2rem 0; border-top: 1px solid var(--line); }
dl.what > div {
  display: grid;
  grid-template-columns: minmax(13rem, 21rem) 1fr;
  gap: 0.4rem 1.4rem;
  padding: 0.75rem 0.2rem;
  border-bottom: 1px solid var(--line);
}
dl.what dt { min-width: 0; }
dl.what dt code { word-break: break-all; }
dl.what dd { margin: 0; color: var(--muted); font-size: 0.95rem; }

/* ---------- Page hero (subpages) */
.page-head { padding: clamp(2.6rem, 7vh, 4.2rem) 0 0.6rem; }
.page-head h1 {
  font-size: clamp(2rem, 1.5rem + 2.2vw, 2.8rem);
  letter-spacing: -0.025em;
  margin: 0 0 0.8rem;
}

/* ---------- Creed band */
.creed {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px),
    var(--panel);
  background-size: 32px 32px, 32px 32px, auto;
  padding: clamp(1.6rem, 4vw, 2.6rem);
}
.creed h2 { font-size: clamp(1.4rem, 1.1rem + 1.4vw, 1.9rem); margin-bottom: 0.6rem; }
.creed p { color: var(--muted); max-width: 64ch; margin-bottom: 0; }

/* ---------- Footer */
footer.site {
  border-top: 1px solid var(--line);
  margin-top: 1rem;
  padding: 2.4rem 0 2.8rem;
}
footer.site .shell {
  width: min(74rem, 100% - 2.5rem);
  margin-inline: auto;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1.6rem;
  flex-wrap: wrap;
}
.foot-brand { max-width: 34ch; }
.foot-brand .brand { margin-right: 0; font-size: 1rem; }
.foot-brand .brand .mark { width: 20px; height: 20px; }
.foot-brand p { color: var(--faint); font-size: 0.88rem; margin: 0.7rem 0 0; }
.foot-links {
  display: flex;
  gap: 1.4rem;
  flex-wrap: wrap;
  font-size: 0.92rem;
  font-weight: 500;
}
.foot-links a { color: var(--muted); }
.foot-links a:hover { color: var(--accent); }

/* ---------- Responsive */
@media (max-width: 62em) {
  .hero .wrap-wide { grid-template-columns: 1fr; }
  .steps { grid-template-columns: 1fr; }
  .diagram { max-width: 34rem; }
}
@media (max-width: 40em) {
  dl.what > div { grid-template-columns: 1fr; gap: 0.15rem; }
  header.site .shell { gap: 0.6rem; }
  .strip .item + .item::before { margin: 0 0.7rem; }
}

/* ---------- Motion preferences */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .diagram .d-flow { animation: none; stroke-dasharray: none; opacity: 0.35; }
}

/* ---------- Print: paper-legible, no chrome */
@media print {
  :root {
    --bg: #ffffff; --panel: #ffffff; --panel-2: #ffffff;
    --fg: #111111; --muted: #333333; --faint: #555555;
    --accent: #047857; --accent-hi: #047857; --link: #047857;
    --line: #cccccc; --line-strong: #999999;
    --code-bg: #f0f0f0;
  }
  body::before { display: none; }
  header.site { position: static; backdrop-filter: none; background: #fff; }
  nav.site-nav, .copy, .cta-row { display: none !important; }
  .term { box-shadow: none; border-color: #999; background: #fff; }
  .term__bar { background: #f4f4f4; border-color: #ccc; }
  .term pre, .term .ps, .term .c { color: #111; }
  .card, .step, .req, .creed, .note, .warn { box-shadow: none; }
  a[href^="http"]::after {
    content: " <" attr(href) ">";
    font-size: 0.8em;
    color: #555;
  }
}
