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

:root {
  --ink: #0e0e0e;
  --ink2: #333;
  --muted: #666;
  --border: #e0ddd8;
  --bg: #faf9f6;
  --card: #ffffff;
  --accent: #c0392b;
  --accent2: #2c5f8a;
  --accent3: #1a7a4a;
  --accent4: #7b4fa6;
  --code-bg: #f4f1ec;
  --tag-bg: #eef4fb;
  --tag-color: #1a4e7a;
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.7;
  font-size: 15px;
}

/* ── HERO ── */
.hero {
  background: var(--ink);
  color: #f5f0e8;
  padding: 72px 48px 64px;
  position: relative;
  overflow: hidden;
}
.hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    45deg, transparent, transparent 60px,
    rgba(255,255,255,0.015) 60px, rgba(255,255,255,0.015) 61px
  );
}
.hero-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: #c0392b;
  margin-bottom: 16px;
}
.hero h1 {
  font-family: 'Playfair Display', serif;
  font-size: clamp(36px, 5vw, 64px);
  font-weight: 700;
  line-height: 1.1;
  color: #f5f0e8;
  margin-bottom: 20px;
}
.hero h1 span { color: #c0392b; }
.hero p {
  font-size: 16px;
  color: #b0a898;
  max-width: 560px;
  line-height: 1.8;
  margin-bottom: 36px;
}
.hero-tags { display: flex; flex-wrap: wrap; gap: 10px; }
.hero-tag {
  font-size: 12px;
  font-family: 'JetBrains Mono', monospace;
  background: rgba(255,255,255,0.07);
  border: 0.5px solid rgba(255,255,255,0.15);
  color: #d0c8bc;
  padding: 6px 14px;
  border-radius: 20px;
}
.hero-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: rgba(255,255,255,0.06);
  border-top: 0.5px solid rgba(255,255,255,0.08);
  margin-top: 48px;
}
.hero-stat { padding: 20px 24px; background: var(--ink); }
.hero-stat .num {
  font-family: 'Playfair Display', serif;
  font-size: 28px;
  color: #f5f0e8;
  font-weight: 700;
}
.hero-stat .label {
  font-size: 11px;
  color: #666;
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 2px;
}

/* ── TOC ── */
.toc-wrap {
  background: var(--ink);
  border-bottom: 0.5px solid #222;
  padding: 0 48px;
  overflow-x: auto;
}
.toc { display: flex; gap: 0; list-style: none; white-space: nowrap; }
.toc li a {
  display: block;
  font-size: 12px;
  font-family: 'JetBrains Mono', monospace;
  color: #666;
  text-decoration: none;
  padding: 14px 16px;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}
.toc li a:hover { color: #f5f0e8; border-bottom-color: #c0392b; }

/* ── LAYOUT ── */
.container { max-width: 920px; margin: 0 auto; padding: 0 48px; }

/* ── SECTIONS ── */
.section {
  padding: 56px 0 40px;
  border-bottom: 0.5px solid var(--border);
}
.section:last-child { border-bottom: none; }
.section-num {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--accent);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.section h2 {
  font-family: 'Playfair Display', serif;
  font-size: 30px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 20px;
  line-height: 1.2;
}
.section p { color: var(--ink2); margin-bottom: 16px; }

/* ── MATH BLOCKS ── */
.math-block {
  background: var(--ink);
  color: #f5f0e8;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  padding: 20px 24px;
  border-radius: 6px;
  margin: 20px 0;
  line-height: 1.9;
  position: relative;
  overflow-x: auto;
}
.math-block::before {
  content: attr(data-label);
  position: absolute;
  top: 8px; right: 12px;
  font-size: 10px;
  color: #c0392b;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* ── FORMULA CARD ── */
.formula-card {
  border: 0.5px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  padding: 20px 24px;
  margin: 16px 0;
}
.formula-card .fc-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: 8px;
}
.formula-card .fc-math {
  font-family: 'JetBrains Mono', monospace;
  font-size: 15px;
  color: var(--ink);
  margin-bottom: 6px;
}
.formula-card .fc-desc { font-size: 13px; color: var(--muted); }

/* ── RULE GRID ── */
.rule-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 20px 0; }
.rule-item {
  background: var(--card);
  border: 0.5px solid var(--border);
  border-radius: 6px;
  padding: 16px 18px;
}
.rule-item .rule-name {
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  text-transform: uppercase;
  color: var(--accent2);
  letter-spacing: 0.1em;
  margin-bottom: 6px;
}
.rule-item .rule-math {
  font-family: 'JetBrains Mono', monospace;
  font-size: 14px;
  color: var(--ink);
}

/* ── AI BOX ── */
.ai-box {
  border-left: 3px solid var(--accent);
  background: #fff8f8;
  padding: 16px 20px;
  border-radius: 0 6px 6px 0;
  margin: 20px 0;
  font-size: 14px;
  color: #8b0000;
}
.ai-box strong {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  display: block;
  margin-bottom: 6px;
  color: var(--accent);
}

/* ── CONCEPT IMG ── */
.concept-img {
  background: var(--ink);
  border-radius: 8px;
  margin: 24px 0;
  overflow: hidden;
}
.concept-img svg { display: block; width: 100%; }

/* ── VARIANT GRID ── */
.variant-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 20px 0; }
.variant-card {
  border: 0.5px solid var(--border);
  border-radius: 6px;
  padding: 16px;
  background: var(--card);
  text-align: center;
}
.variant-card .vc-icon {
  font-family: 'JetBrains Mono', monospace;
  font-size: 18px;
  color: var(--accent);
  margin-bottom: 8px;
}
.variant-card .vc-name { font-size: 13px; font-weight: 500; color: var(--ink); margin-bottom: 4px; }
.variant-card .vc-desc { font-size: 12px; color: var(--muted); }

/* ── CRITICAL POINTS ── */
.cp-types { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 20px 0; }
.cp-type {
  border-radius: 8px;
  padding: 20px;
  text-align: center;
  border: 0.5px solid var(--border);
}
.cp-type.min { background: #f0f8f4; border-color: #1a7a4a33; }
.cp-type.max { background: #fff0f0; border-color: #c0392b33; }
.cp-type.saddle { background: #f4f0ff; border-color: #7b4fa633; }
.cp-type .cp-icon { font-size: 28px; margin-bottom: 8px; }
.cp-type .cp-name { font-size: 13px; font-weight: 500; }
.cp-type.min .cp-name { color: var(--accent3); }
.cp-type.max .cp-name { color: var(--accent); }
.cp-type.saddle .cp-name { color: var(--accent4); }
.cp-type .cp-cond {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--muted);
  margin-top: 6px;
}

/* ── WORKED EXAMPLE ── */
.example-box {
  background: linear-gradient(135deg, #0e0e0e, #1a1a2e);
  border-radius: 10px;
  padding: 36px 40px;
  margin: 32px 0;
  color: #f5f0e8;
  position: relative;
  overflow: hidden;
}
.example-box::before {
  content: 'WORKED EXAMPLE';
  position: absolute;
  top: 16px; right: 20px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.18em;
  color: #c0392b;
}
.example-box h3 {
  font-family: 'Playfair Display', serif;
  font-size: 22px;
  color: #f5f0e8;
  margin-bottom: 8px;
}
.example-box .ex-subtitle {
  font-size: 13px;
  color: #888;
  margin-bottom: 28px;
  font-family: 'JetBrains Mono', monospace;
}
.step-list { list-style: none; counter-reset: steps; }
.step-list li {
  counter-increment: steps;
  position: relative;
  padding: 20px 0 20px 52px;
  border-bottom: 0.5px solid rgba(255,255,255,0.07);
}
.step-list li:last-child { border-bottom: none; }
.step-list li::before {
  content: counter(steps);
  position: absolute;
  left: 0; top: 20px;
  width: 28px; height: 28px;
  background: #c0392b;
  border-radius: 50%;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  font-weight: 500;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
}
.step-list li .step-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #888;
  font-family: 'JetBrains Mono', monospace;
  margin-bottom: 6px;
}
.step-list li .step-body { font-size: 14px; color: #c8c0b4; line-height: 1.7; }
.step-list li .step-math {
  font-family: 'JetBrains Mono', monospace;
  background: rgba(255,255,255,0.05);
  border-radius: 4px;
  padding: 12px 16px;
  margin: 10px 0;
  font-size: 13px;
  color: #f5d4b0;
  line-height: 1.8;
}
.result-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 24px; }
.result-card {
  background: rgba(255,255,255,0.05);
  border: 0.5px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  padding: 16px;
  text-align: center;
}
.result-card .rc-label {
  font-size: 10px;
  font-family: 'JetBrains Mono', monospace;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: 8px;
}
.result-card .rc-val { font-family: 'JetBrains Mono', monospace; font-size: 16px; color: #f5f0e8; }
.result-card.local-max { border-color: #c0392b44; }
.result-card.local-min { border-color: #1a7a4a44; }
.result-card.local-max .rc-label { color: #c0392b; }
.result-card.local-min .rc-label { color: #1a7a4a; }

/* ── CHART ── */
.chart-wrap {
  background: var(--card);
  border: 0.5px solid var(--border);
  border-radius: 8px;
  padding: 24px;
  margin: 24px 0;
}

/* ── ML TABLE ── */
.ml-table { width: 100%; border-collapse: collapse; margin: 24px 0; }
.ml-table th {
  background: var(--ink);
  color: #f5f0e8;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 12px 16px;
  text-align: left;
}
.ml-table td { padding: 12px 16px; border-bottom: 0.5px solid var(--border); font-size: 14px; }
.ml-table tr:hover td { background: var(--code-bg); }
.ml-table .concept {
  font-family: 'JetBrains Mono', monospace;
  color: var(--accent2);
  font-size: 13px;
}

/* ── CHEAT GRID ── */
.cheat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 20px 0; }
.cheat-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--card);
  border: 0.5px solid var(--border);
  border-radius: 6px;
  padding: 16px;
}
.cheat-icon { font-size: 20px; flex-shrink: 0; margin-top: 2px; }
.cheat-content .cheat-title { font-size: 13px; font-weight: 500; color: var(--ink); margin-bottom: 3px; }
.cheat-content .cheat-desc { font-size: 12px; color: var(--muted); }

/* ── NEXT STEPS ── */
.next-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 20px 0; }
.next-card {
  border: 0.5px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  background: var(--card);
  text-align: center;
  transition: border-color 0.2s;
}
.next-card:hover { border-color: var(--accent2); }
.next-card .nc-icon { font-size: 24px; margin-bottom: 10px; }
.next-card .nc-title { font-size: 13px; font-weight: 500; color: var(--ink); margin-bottom: 4px; }
.next-card .nc-sub { font-size: 12px; color: var(--muted); }

/* ── FOOTER ── */
.footer {
  background: var(--ink);
  color: #555;
  text-align: center;
  padding: 40px 48px;
  font-size: 13px;
  font-family: 'JetBrains Mono', monospace;
}
.footer strong { color: #f5f0e8; }
.footer .built-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 16px;
  background: rgba(192,57,43,0.12);
  border: 0.5px solid rgba(192,57,43,0.35);
  color: #c0392b;
  padding: 10px 22px;
  border-radius: 24px;
  font-size: 12px;
  letter-spacing: 0.12em;
  transition: background 0.2s, border-color 0.2s;
}
.footer .built-tag .author-link {
  color: #f5f0e8;
  font-weight: 600;
  text-decoration: none;
  border-bottom: 1px solid rgba(245,240,232,0.3);
  padding-bottom: 1px;
  letter-spacing: 0.08em;
  transition: color 0.2s, border-color 0.2s;
  cursor: pointer;
}
.footer .built-tag .author-link:hover {
  color: #c0392b;
  border-bottom-color: #c0392b;
}
.footer .built-tag .gh-icon {
  display: inline-block;
  width: 15px;
  height: 15px;
  vertical-align: middle;
  margin-right: 2px;
  opacity: 0.7;
  transition: opacity 0.2s;
}
.footer .built-tag .author-link:hover .gh-icon { opacity: 1; }

/* ── RESPONSIVE ── */
@media (max-width: 640px) {
  .container { padding: 0 20px; }
  .hero { padding: 48px 20px 40px; }
  .hero-grid { grid-template-columns: repeat(2, 1fr); }
  .rule-grid, .result-row, .cheat-grid { grid-template-columns: 1fr; }
  .variant-grid, .cp-types, .next-grid { grid-template-columns: 1fr; }
  .toc-wrap { padding: 0 20px; }
  .example-box { padding: 24px 20px; }
}
