/* ============================================================
   topic1.css — Topic page, matching website4 theme.
   Typst converts native markup to semantic HTML:
     = Heading  →  <h1>
     == Section →  <h2>
     paragraph  →  <p>
     - list     →  <ul><li>
     + list     →  <ol><li>
   Math is rendered as inline SVG via html.frame().
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ── Tokens ─────────────────────────────────────────────────── */
:root {
  --accent:        #2563eb;
  --accent-faint:  rgba(37, 99, 235, 0.07);
  --accent-border: rgba(37, 99, 235, 0.2);

  --bg:            #ffffff;
  --bg-subtle:     #fafafa;

  --text:          #111111;
  --text-muted:    #6b6b6b;
  --text-faint:    #aaaaaa;

  --border:        #e5e5e5;
  --border-mid:    #d4d4d4;

  --example-bg:    #f8f8ff;
  --example-border:#c8d0f0;
  --theorem-bg:    #fafaf5;
  --theorem-border:#d0c890;
  --key-bg:        #f0f5ff;
  --key-border:    var(--accent-border);

  --nav-h:         52px;
  --content-w:     720px;
  --radius:        8px;
  --transition:    0.18s ease;
}

[data-theme="dark"] {
  --bg:            #111111;
  --bg-subtle:     #161616;
  --text:          #f0f0f0;
  --text-muted:    #888888;
  --text-faint:    #444444;
  --border:        #272727;
  --border-mid:    #333333;
  --example-bg:    #13151f;
  --example-border:#252b42;
  --theorem-bg:    #17160e;
  --theorem-border:#302b18;
  --key-bg:        #111825;
  --key-border:    rgba(37, 99, 235, 0.25);
  --accent-faint:  rgba(59, 130, 246, 0.1);
}

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px;
  line-height: 1.7;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  transition: background var(--transition), color var(--transition);
}

a { color: inherit; text-decoration: none; }

/* ── Navigation bar ─────────────────────────────────────────── */
.page-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--nav-h);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  transition: background var(--transition), border-color var(--transition);
}

/* Typst wraps html.elem content in <p> — strip that margin in nav */
.page-nav p { margin: 0; display: contents; }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  transition: color var(--transition);
}
.back-link:hover { color: var(--accent); }

.nav-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.nav-label {
  font-size: 12px;
  color: var(--text-faint);
}

.theme-btn {
  font-size: 12px;
  font-weight: 500;
  font-family: 'Inter', sans-serif;
  color: var(--text-muted);
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 12px;
  cursor: pointer;
  transition: all var(--transition);
}
.theme-btn:hover { color: var(--text); border-color: var(--border-mid); }

/* ── Content wrapper ────────────────────────────────────────── */
.content-wrap {
  max-width: var(--content-w);
  margin: 0 auto;
  padding: 48px 32px 96px;
}

/* ── Topic eyebrow ──────────────────────────────────────────── */
.topic-eyebrow {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-faint);
  margin-bottom: 10px;
}

/* Typst may wrap spans in <p>, undo that */
.content-wrap > p:has(.topic-eyebrow) {
  margin: 0;
}

/* ── Page title (= Heading → <h2> in Typst HTML export) ────── */
/* Typst maps: = → h2, == → h3, === → h4                       */
.content-wrap h2 {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.18;
  color: var(--text);
  margin-top: 0;
  margin-bottom: 20px;
  text-transform: none;
  border-bottom: none;
  padding-bottom: 0;
}

/* First <p> after the page title acts as the lead paragraph */
.content-wrap h2 + p {
  font-size: 15.5px;
  color: var(--text-muted);
  line-height: 1.75;
  margin-bottom: 40px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 40px;
}

/* ── Section headers (== Section → <h3>) ───────────────────── */
.content-wrap h3 {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  margin-top: 48px;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

/* ── Body text ──────────────────────────────────────────────── */
.content-wrap p {
  font-size: 15px;
  color: var(--text);
  line-height: 1.75;
  margin-bottom: 16px;
}

.content-wrap p:last-child { margin-bottom: 0; }

strong { font-weight: 600; }

/* ── Lists ──────────────────────────────────────────────────── */
.content-wrap ul,
.content-wrap ol {
  padding-left: 20px;
  margin-bottom: 16px;
}

.content-wrap li {
  font-size: 15px;
  color: var(--text);
  line-height: 1.7;
  margin-bottom: 7px;
}

/* Numbered list for row operations — styled with accent dots */
.content-wrap ol {
  list-style: none;
  padding-left: 0;
  counter-reset: op;
}

.content-wrap ol li {
  counter-increment: op;
  display: flex;
  gap: 14px;
  align-items: baseline;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.content-wrap ol li:last-child { border-bottom: none; }

.content-wrap ol li::before {
  content: counter(op);
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-faint);
  border-radius: 50%;
  min-width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

/* ── Display math ───────────────────────────────────────────── */
.display-math {
  text-align: center;
  margin: 28px 0;
  overflow-x: auto;
}

.display-math svg {
  display: inline-block;
  max-width: 100%;
  height: auto;
}

/* Inline math — align SVG with surrounding text */
p svg, li svg, span svg {
  display: inline-block;
  vertical-align: middle;
  position: relative;
  top: -1px;
}

/* ── Example boxes ──────────────────────────────────────────── */
.example-box {
  background: var(--example-bg);
  border: 1px solid var(--example-border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin: 24px 0;
}

/* Strip extra margins from Typst-generated <p> inside boxes */
.example-box p:last-child,
.theorem-box p:last-child,
.key-points p:last-child { margin-bottom: 0; }

/* ── Theorem boxes ──────────────────────────────────────────── */
.theorem-box {
  background: var(--theorem-bg);
  border: 1px solid var(--theorem-border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin: 24px 0;
}

.theorem-box ul {
  margin-top: 8px;
}

/* ── Box labels ─────────────────────────────────────────────── */
.box-label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  margin-bottom: 12px;
}

.example-box .box-label { color: var(--accent); }

/* ── Key points ─────────────────────────────────────────────── */
.key-points {
  background: var(--key-bg);
  border: 1px solid var(--key-border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-top: 48px;
}

.key-points .box-label { color: var(--accent); }

.key-points ul { margin: 0; }

.key-points li {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 7px;
}

/* ── Footer navigation ──────────────────────────────────────── */
.topic-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 32px;
  margin-top: 40px;
  border-top: 1px solid var(--border);
}

/* Typst may wrap in <p> */
.topic-footer p { margin: 0; display: contents; }

.footer-link {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  transition: color var(--transition);
}
.footer-link:hover { color: var(--accent); }

.footer-next {
  font-size: 13px;
  color: var(--text-faint);
}

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 640px) {
  .content-wrap { padding: 32px 20px 72px; }
  .page-nav { padding: 0 20px; }
  .nav-label { display: none; }
  .content-wrap h1 { font-size: 24px; }
}
