/* ==========================================================================
   Aethermine — Machine Learning for Mineral Exploration
   Design language: "Clear Site" (Aethermine v4) + company copper accent.
   No external requests: system font stack only, no CDN, no webfonts.
   ========================================================================== */

:root {
  /* surfaces */
  --canvas: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f3f4f6;
  --border: #e5e7eb;
  --border-strong: #d1d5db;

  /* ink */
  --ink: #111827;
  --ink-2: #6b7280;
  --ink-3: #9ca3af;

  /* company accent (copper) — site identity */
  --accent: #b45309;
  --accent-ink: #8a3f07;
  --accent-soft: #fdf3e7;

  /* actions */
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-tint: #eff6ff;

  /* semantic */
  --success: #16a34a;
  --success-tint: #ecfdf5;
  --warning: #d97706;
  --warning-tint: #fffbeb;
  --critical: #dc2626;
  --critical-tint: #fef2f2;

  /* the purple rule: AI / ML concepts only */
  --ai: #7c3aed;
  --ai-tint: #f5f3ff;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 4px 6px -1px rgba(16, 24, 40, 0.06), 0 12px 24px -8px rgba(16, 24, 40, 0.12);

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

  --sidebar-w: 286px;
  --measure: 74ch;
}

@media (prefers-color-scheme: dark) {
  :root {
    --canvas: #0e1116;
    --surface: #151a21;
    --surface-2: #1c222b;
    --border: #262d38;
    --border-strong: #38414f;
    --ink: #e8eaed;
    --ink-2: #9aa4b2;
    --ink-3: #6b7686;
    --accent: #e08540;
    --accent-ink: #f0a468;
    --accent-soft: #2a1d10;
    --primary: #60a5fa;
    --primary-hover: #93c5fd;
    --primary-tint: #14243d;
    --success: #4ade80;
    --success-tint: #10241a;
    --warning: #fbbf24;
    --warning-tint: #2a2110;
    --critical: #f87171;
    --critical-tint: #2c1618;
    --ai: #a78bfa;
    --ai-tint: #1e1836;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 12px 28px -10px rgba(0, 0, 0, 0.7);
  }
}

/* explicit toggle must beat the media query in BOTH directions */
:root[data-theme="dark"] {
  --canvas: #0e1116;
  --surface: #151a21;
  --surface-2: #1c222b;
  --border: #262d38;
  --border-strong: #38414f;
  --ink: #e8eaed;
  --ink-2: #9aa4b2;
  --ink-3: #6b7686;
  --accent: #e08540;
  --accent-ink: #f0a468;
  --accent-soft: #2a1d10;
  --primary: #60a5fa;
  --primary-hover: #93c5fd;
  --primary-tint: #14243d;
  --success: #4ade80;
  --success-tint: #10241a;
  --warning: #fbbf24;
  --warning-tint: #2a2110;
  --critical: #f87171;
  --critical-tint: #2c1618;
  --ai: #a78bfa;
  --ai-tint: #1e1836;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 28px -10px rgba(0, 0, 0, 0.7);
}

:root[data-theme="light"] {
  --canvas: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f3f4f6;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --ink: #111827;
  --ink-2: #6b7280;
  --ink-3: #9ca3af;
  --accent: #b45309;
  --accent-ink: #8a3f07;
  --accent-soft: #fdf3e7;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-tint: #eff6ff;
  --success: #16a34a;
  --success-tint: #ecfdf5;
  --warning: #d97706;
  --warning-tint: #fffbeb;
  --critical: #dc2626;
  --critical-tint: #fef2f2;
  --ai: #7c3aed;
  --ai-tint: #f5f3ff;
}

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { background: var(--canvas); scroll-behavior: smooth; scroll-padding-top: 1.5rem; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 16.5px;
  line-height: 1.68;
  color: var(--ink);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img, svg { max-width: 100%; height: auto; }

/* ---------- layout ---------- */
.layout { display: flex; align-items: flex-start; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 22px 18px 40px;
}
.main { flex: 1 1 auto; min-width: 0; padding: 44px 40px 96px; }
.wrap { max-width: var(--measure); margin: 0 auto; }

/* ---------- brand ---------- */
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; margin-bottom: 6px; }
.brand-mark {
  width: 30px; height: 30px; flex: 0 0 30px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  display: grid; place-items: center;
  font-family: var(--mono); font-size: 14px; font-weight: 700;
  letter-spacing: -0.5px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name {
  font-size: 13.5px; font-weight: 700; color: var(--ink);
  letter-spacing: 0.14em; text-transform: uppercase;
}
.brand-sub { font-family: var(--mono); font-size: 10.5px; color: var(--ink-3); letter-spacing: 0.04em; }

.sidebar-note {
  font-size: 12.5px; color: var(--ink-2);
  padding: 10px 10px 14px; margin: 10px 0 6px;
  border-bottom: 1px solid var(--border);
}

/* ---------- nav ---------- */
.nav { margin-top: 14px; }
.nav-group {
  font-family: var(--mono); font-size: 10.5px; font-weight: 600;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--ink-3);
  padding: 16px 10px 7px;
}
.nav a {
  display: flex; align-items: baseline; gap: 9px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  color: var(--ink-2);
  text-decoration: none;
  font-size: 14.2px;
  line-height: 1.4;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a[aria-current="page"] {
  background: var(--primary-tint);
  color: var(--primary);
  font-weight: 600;
}
.nav .num {
  font-family: var(--mono); font-size: 11px; color: var(--ink-3);
  flex: 0 0 auto; min-width: 15px;
}
.nav a[aria-current="page"] .num { color: var(--primary); }

/* ---------- typography ---------- */
.eyebrow {
  font-family: var(--mono); font-size: 11.5px; font-weight: 600;
  letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 12px;
}
h1 {
  font-size: clamp(1.95rem, 1.3rem + 2.1vw, 2.85rem);
  line-height: 1.14;
  letter-spacing: -0.024em;
  font-weight: 700;
  margin: 0 0 16px;
  text-wrap: balance;
}
h2 {
  font-size: 1.52rem; line-height: 1.26; letter-spacing: -0.016em; font-weight: 680;
  margin: 3.2rem 0 0.9rem; padding-top: 1.4rem;
  border-top: 1px solid var(--border);
  text-wrap: balance;
}
h2:first-of-type { border-top: none; padding-top: 0; margin-top: 2.4rem; }
h3 { font-size: 1.13rem; line-height: 1.35; font-weight: 650; margin: 2.1rem 0 0.6rem; letter-spacing: -0.008em; }
h4 { font-size: 0.99rem; font-weight: 650; margin: 1.5rem 0 0.4rem; color: var(--ink); }
p { margin: 0 0 1.05rem; }
.lede { font-size: 1.14rem; line-height: 1.62; color: var(--ink-2); margin-bottom: 1.8rem; }
a { color: var(--primary); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--primary-hover); }
strong { font-weight: 650; color: var(--ink); }
ul, ol { margin: 0 0 1.15rem; padding-left: 1.35rem; }
li { margin-bottom: 0.45rem; }
li::marker { color: var(--ink-3); }
hr { border: none; border-top: 1px solid var(--border); margin: 2.5rem 0; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 3px; }

code {
  font-family: var(--mono); font-size: 0.855em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 0.1em 0.36em; border-radius: 4px;
  word-break: break-word;
}
pre {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 17px;
  overflow-x: auto;
  font-size: 13.2px; line-height: 1.62;
  margin: 0 0 1.3rem;
}
pre code { background: none; border: none; padding: 0; font-size: inherit; }

/* ---------- term (glossary inline) ---------- */
.term {
  font-weight: 650; color: var(--ink);
  border-bottom: 1.5px dotted var(--accent);
}

/* ---------- callouts ---------- */
.box {
  border: 1px solid var(--border);
  border-left: 3px solid var(--ink-3);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 15px 18px;
  margin: 1.5rem 0;
  font-size: 15.2px;
}
.box > :last-child { margin-bottom: 0; }
.box-label {
  font-family: var(--mono); font-size: 10.5px; font-weight: 600;
  letter-spacing: 0.12em; text-transform: uppercase;
  display: block; margin-bottom: 7px;
}

/* purple = the ML/AI lens (Aethermine purple rule) */
.box.ml { border-left-color: var(--ai); background: var(--ai-tint); }
.box.ml .box-label { color: var(--ai); }
.box.geo { border-left-color: var(--accent); background: var(--accent-soft); }
.box.geo .box-label { color: var(--accent); }
.box.warn { border-left-color: var(--warning); background: var(--warning-tint); }
.box.warn .box-label { color: var(--warning); }
.box.trap { border-left-color: var(--critical); background: var(--critical-tint); }
.box.trap .box-label { color: var(--critical); }

/* ---------- tables ---------- */
.table-scroll { overflow-x: auto; margin: 0 0 1.5rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 14.4px; }
th, td { text-align: left; padding: 9px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
thead th {
  background: var(--surface-2);
  font-family: var(--mono); font-size: 10.8px; font-weight: 600;
  letter-spacing: 0.09em; text-transform: uppercase; color: var(--ink-2);
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: none; }
td code { font-size: 12.6px; }
.num-col { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- the two-column "geo term ↔ ML term" rosetta ---------- */
.rosetta td:first-child { font-weight: 650; }
.rosetta td:nth-child(2) { color: var(--ai); font-family: var(--mono); font-size: 13px; }

/* ---------- math ---------- */
.math {
  font-family: var(--mono);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 17px;
  margin: 1.2rem 0;
  /* equations are authored with literal newlines and aligned by hand, so the
     source whitespace IS the layout — preserve it and let long lines scroll
     inside the block rather than widening the page */
  white-space: pre;
  overflow-x: auto;
  font-size: 14px;
  line-height: 1.75;
}
.math .where {
  display: block;
  margin-top: 8px;
  color: var(--ink-2);
  font-size: 12.6px;
  font-family: var(--sans);
  white-space: normal; /* the explanatory note is prose — it should wrap */
}

/* ---------- cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(232px, 1fr)); gap: 14px; margin: 1.6rem 0; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 17px;
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
  display: block;
}
a.card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-lg); transform: translateY(-1px); transition: all 0.16s ease; }
.card h3 { margin: 0 0 5px; font-size: 1rem; }
.card p { margin: 0; font-size: 14px; color: var(--ink-2); line-height: 1.55; }
.card .num {
  font-family: var(--mono); font-size: 11px; color: var(--accent);
  letter-spacing: 0.1em; display: block; margin-bottom: 7px; font-weight: 600;
}

/* ---------- stat row ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 1.7rem 0; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat .v { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.1; color: var(--accent); }
.stat .k { font-size: 12.6px; color: var(--ink-2); margin-top: 5px; line-height: 1.4; }

/* ---------- pipeline / funnel ---------- */
.funnel { margin: 1.6rem 0; display: flex; flex-direction: column; gap: 3px; }
.funnel-row { display: flex; align-items: center; gap: 12px; }
.funnel-bar {
  background: var(--accent); color: #fff;
  padding: 7px 13px; border-radius: var(--radius-sm);
  font-size: 13.4px; font-weight: 600; white-space: nowrap;
  min-width: 90px;
}
.funnel-row:nth-child(2) .funnel-bar { background: #c2620c; }
.funnel-row:nth-child(3) .funnel-bar { background: #ca7016; }
.funnel-row:nth-child(4) .funnel-bar { background: #d4832c; }
.funnel-row:nth-child(5) .funnel-bar { background: #dd9648; }
.funnel-note { font-size: 13.4px; color: var(--ink-2); }

/* ---------- per-chapter source lists ---------- */
.sources { list-style: none; padding-left: 0; margin: 1.3rem 0 0; }
.sources li {
  position: relative;
  padding: 12px 0 12px 20px;
  border-top: 1px solid var(--border);
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink-2);
  margin-bottom: 0;
}
.sources li:last-child { border-bottom: 1px solid var(--border); }
.sources li::before {
  content: "▸";
  position: absolute;
  left: 0;
  top: 12px;
  color: var(--accent);
  font-size: 12px;
}
.sources strong, .sources em { color: var(--ink); }

/* ---------- prev/next ---------- */
.pager { display: flex; justify-content: space-between; gap: 14px; margin-top: 3.5rem; padding-top: 1.6rem; border-top: 1px solid var(--border); }
.pager a {
  flex: 1 1 0; padding: 13px 16px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); text-decoration: none; color: inherit;
}
.pager a:hover { border-color: var(--border-strong); box-shadow: var(--shadow); }
.pager .dir { font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-3); display: block; margin-bottom: 3px; }
.pager .ttl { font-weight: 600; font-size: 14.6px; color: var(--primary); }
.pager .next { text-align: right; }

/* ---------- footer ---------- */
.foot { margin-top: 3rem; padding-top: 1.4rem; border-top: 1px solid var(--border); font-size: 13px; color: var(--ink-3); }
.foot a { color: var(--ink-2); }

/* ---------- theme toggle + mobile ---------- */
.topbar { display: none; }
.theme-btn {
  background: var(--surface); border: 1px solid var(--border);
  color: var(--ink-2); border-radius: var(--radius-sm);
  padding: 6px 11px; font-size: 12.5px; font-family: var(--sans); cursor: pointer;
}
.theme-btn:hover { border-color: var(--border-strong); color: var(--ink); }

@media (max-width: 900px) {
  /* align-items:flex-start is what keeps the sticky sidebar from stretching on
     desktop, but once the axis flips to column it becomes a CROSS-axis rule and
     makes both children shrink-to-fit — leaving .main at its 74ch measure and
     overflowing the viewport. Stretch them explicitly here. */
  .layout { flex-direction: column; align-items: stretch; }
  .sidebar {
    width: 100%; flex: none; height: auto; position: static;
    border-right: none; border-bottom: 1px solid var(--border);
    padding: 16px 18px 20px;
  }
  /* two columns fit a 375px phone (339px of content box); capping the height
     keeps the chapter itself above the fold instead of behind a 1400px nav */
  .nav {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1px 12px;
    max-height: 40vh;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .nav-group { grid-column: 1 / -1; padding-top: 11px; }
  .nav a { font-size: 13.6px; padding: 6px 9px; }
  .sidebar-note { font-size: 12px; padding: 8px 8px 12px; margin: 8px 0 4px; }
  .main { padding: 30px 20px 70px; }
  .pager { flex-direction: column; }
  .pager .next { text-align: left; }
}
