:root {
  --bg: #0a0a0a;
  --surface: #111111;
  --surface2: #181818;
  --accent: #FF5C00;
  --accent2: #d4773a;
  --text: #e8e4dc;
  --muted: #6b6b6b;
  --border: #252525;
}

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

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-weight: 300;
  line-height: 1.7;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='1'/%3E%3C/svg%3E");
  opacity: 0.03;
  pointer-events: none;
  z-index: 999;
}

a { color: var(--accent); }

/* ── NAV ── */
nav.top {
  position: sticky;
  top: 0;
  z-index: 100;
  padding: 1.2rem 3rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(10,10,10,0.88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.nav-logo {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.4rem;
  letter-spacing: 0.12em;
  color: var(--accent);
  text-decoration: none;
}

.nav-logo img { height: 32px; width: 32px; object-fit: contain; }

.nav-crumb {
  color: var(--muted);
  font-family: 'DM Sans', sans-serif;
  font-weight: 300;
}

.nav-back {
  font-family: 'Space Mono', monospace;
  font-size: 0.72rem;
  color: var(--muted);
  text-decoration: none;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: color 0.2s;
}
.nav-back:hover { color: var(--accent); }

/* ── SUBNAV (topic pills) ── */
.subnav {
  position: sticky;
  top: 68px;
  z-index: 90;
  display: flex;
  gap: 0.3rem;
  overflow-x: auto;
  padding: 0.9rem 3rem;
  background: rgba(10,10,10,0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  scrollbar-width: thin;
}
.subnav::-webkit-scrollbar { height: 4px; }
.subnav::-webkit-scrollbar-thumb { background: var(--border); }

.subnav a {
  flex-shrink: 0;
  font-family: 'Space Mono', monospace;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  text-decoration: none;
  padding: 0.4rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 2px;
  white-space: nowrap;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.subnav a:hover { color: var(--text); border-color: var(--accent2); }
.subnav a.active { color: var(--bg); background: var(--accent); border-color: var(--accent); font-weight: 700; }

/* ── MAIN ── */
main {
  flex: 1;
  max-width: 860px;
  margin: 0 auto;
  padding: 4rem 3rem 6rem;
  width: 100%;
}

.section-label {
  font-family: 'Space Mono', monospace;
  font-size: 0.68rem;
  color: var(--accent);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  margin-bottom: 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.8rem;
}
.section-label::before {
  content: '';
  display: inline-block;
  width: 28px;
  height: 1px;
  background: var(--accent);
}

h1.page-title {
  font-family: 'Bebas Neue', sans-serif;
  font-size: clamp(2.4rem, 6vw, 4rem);
  line-height: 1;
  letter-spacing: 0.03em;
  margin-bottom: 1rem;
}

.page-sub {
  color: var(--muted);
  font-size: 1rem;
  max-width: 640px;
  margin-bottom: 3rem;
}

article h2 {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.9rem;
  letter-spacing: 0.02em;
  color: var(--text);
  margin: 3.2rem 0 1.1rem;
  padding-top: 0.4rem;
  border-top: 1px solid var(--border);
  scroll-margin-top: 150px;
}
article h2:first-of-type { border-top: none; padding-top: 0; margin-top: 0; }

article h3 {
  font-family: 'DM Sans', sans-serif;
  font-weight: 500;
  font-size: 1.05rem;
  color: var(--accent2);
  letter-spacing: 0.02em;
  margin: 2.2rem 0 0.8rem;
}

article p { margin-bottom: 1.1rem; color: var(--text); }
article p.muted, .muted { color: var(--muted); font-size: 0.92rem; }

article ul, article ol {
  margin: 0 0 1.2rem 1.4rem;
  color: var(--text);
}
article li { margin-bottom: 0.5rem; }

article strong { color: #fff; font-weight: 500; }

code, .const {
  font-family: 'Space Mono', monospace;
  font-size: 0.86em;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.1em 0.4em;
  color: #ffcfa8;
}

/* ── FORMULA BLOCKS ── */
.formula {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 2px solid var(--accent);
  padding: 1.3rem 1.6rem;
  margin: 1.2rem 0 1.6rem;
  overflow-x: auto;
}
.formula .katex-display { margin: 0.2rem 0; }
.formula-caption {
  font-family: 'Space Mono', monospace;
  font-size: 0.65rem;
  color: var(--muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 0.6rem;
}

/* ── CALLOUTS ── */
.callout {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 2px solid var(--accent2);
  padding: 1.1rem 1.4rem;
  margin: 1.4rem 0;
  font-size: 0.92rem;
  color: var(--text);
}
.callout-label {
  font-family: 'Space Mono', monospace;
  font-size: 0.62rem;
  color: var(--accent2);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  margin-bottom: 0.5rem;
  display: block;
}
.callout.warn { border-left-color: var(--accent); }
.callout.warn .callout-label { color: var(--accent); }

/* ── TABLES ── */
.table-wrap { overflow-x: auto; margin: 1.2rem 0 1.6rem; border: 1px solid var(--border); }
table {
  border-collapse: collapse;
  width: 100%;
  font-family: 'Space Mono', monospace;
  font-size: 0.82rem;
}
th, td {
  padding: 0.55rem 0.9rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
th {
  background: var(--surface);
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 0.68rem;
}
td { color: var(--text); background: var(--surface2); }
tr:last-child td { border-bottom: none; }

/* ── CITATIONS ── */
sup.cite a {
  text-decoration: none;
  color: var(--accent2);
  font-family: 'Space Mono', monospace;
  font-size: 0.75em;
}
sup.cite a:hover { color: var(--accent); }

/* ── CARD GRID (index) ── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.5px;
  background: var(--border);
  border: 1px solid var(--border);
  margin: 2rem 0;
}
.card {
  background: var(--surface);
  padding: 1.6rem 1.8rem;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  position: relative;
  overflow: hidden;
  transition: background 0.2s;
}
.card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 3px; height: 0;
  background: var(--accent);
  transition: height 0.3s ease;
}
.card:hover { background: var(--surface2); }
.card:hover::before { height: 100%; }
.card-num {
  font-family: 'Space Mono', monospace;
  font-size: 0.65rem;
  color: var(--accent);
  letter-spacing: 0.1em;
}
.card-title {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.5rem;
  letter-spacing: 0.03em;
  color: var(--text);
  line-height: 1.15;
}
.card-desc {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.5;
}

/* ── PAGE NAV (prev/next) ── */
.page-nav {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}
.page-nav a {
  text-decoration: none;
  font-family: 'Space Mono', monospace;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 0.7rem 1.1rem;
  transition: color 0.2s, border-color 0.2s;
  max-width: 48%;
}
.page-nav a:hover { color: var(--accent); border-color: var(--accent2); }
.page-nav .dir { display: block; color: var(--accent2); font-size: 0.62rem; margin-bottom: 0.3rem; }
.page-nav .next { text-align: right; margin-left: auto; }

/* ── FOOTER ── */
footer {
  border-top: 1px solid var(--border);
  padding: 2rem 3rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
  flex-wrap: wrap;
  gap: 1rem;
}
footer p {
  font-family: 'Space Mono', monospace;
  font-size: 0.65rem;
  color: var(--muted);
  letter-spacing: 0.06em;
}

/* ── RESPONSIVE ── */
@media (max-width: 768px) {
  nav.top { padding: 1rem 1.5rem; }
  .subnav { padding: 0.8rem 1.5rem; top: 61px; }
  main { padding: 2.5rem 1.5rem 4rem; }
  footer { padding: 1.5rem; }
  .card-grid { grid-template-columns: 1fr; }
  .page-nav a { max-width: 100%; }
}
