/* ============================================================
   SYSTEM DESIGN CODEX — Global Stylesheet
   Editorial Typeset Textbook Theme
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,400;0,9..144,500;0,9..144,700;0,9..144,900;1,9..144,400;1,9..144,600&family=Newsreader:ital,wght@0,400;0,500;0,600;1,400;1,500&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* ── CSS Variables ─────────────────────────────────────── */
:root {
  --paper:       #f5efe4;
  --paper-deep:  #ece4d4;
  --ink:         #1a1612;
  --ink-soft:    #3d342a;
  --rule:        #2a221a;
  --accent:      #b8341f;
  --accent-soft: #d97757;
  --gold:        #a07b2c;
  --leaf:        #4a6741;
  --code-bg:     #1e1a16;
  --code-text:   #e8dfd0;
  --shadow:      rgba(26,22,18,0.08);

  --font-display: 'Fraunces', Georgia, serif;
  --font-body:    'Newsreader', Georgia, serif;
  --font-mono:    'JetBrains Mono', 'Fira Code', monospace;

  --nav-h: 64px;
  --sidebar-w: 260px;
  --content-max: 780px;
  --layout-max: 1400px;

  --radius: 4px;
  --transition: cubic-bezier(0.4,0,0.2,1);
}

[data-theme="dark"] {
  --paper:       #181512;
  --paper-deep:  #201c18;
  --ink:         #e8dfd0;
  --ink-soft:    #b0a090;
  --rule:        #38302a;
  --accent:      #e05a3a;
  --accent-soft: #f08060;
  --gold:        #c8a050;
  --leaf:        #6a9760;
  --shadow:      rgba(0,0,0,0.4);
}

/* ── Reset & Base ──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  scroll-behavior: smooth;
  font-size: 18px;
}

body {
  font-family: var(--font-body);
  background: var(--paper);
  color: var(--ink);
  line-height: 1.65;
  min-height: 100vh;
  overflow-x: hidden;
  transition: background 0.3s var(--transition), color 0.3s var(--transition);
}

/* Paper texture grain overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.35;
  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");
  background-size: 200px 200px;
}

/* Ambient glow */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(ellipse 60% 50% at 0% 0%, rgba(184,52,31,0.04) 0%, transparent 70%),
    radial-gradient(ellipse 60% 50% at 100% 100%, rgba(160,123,44,0.04) 0%, transparent 70%);
}

/* ── Typography ────────────────────────────────────────── */
h1, h2, h3, h4, h5 {
  font-family: var(--font-display);
  color: var(--ink);
  line-height: 1.1;
}

h1 {
  font-size: clamp(3rem, 8vw, 6.5rem);
  font-weight: 900;
  letter-spacing: -0.04em;
  font-variation-settings: 'opsz' 144;
}

h2 {
  font-size: clamp(2rem, 4vw, 3rem);
  font-weight: 700;
  letter-spacing: -0.03em;
}

h3 {
  font-size: 1.5rem;
  font-weight: 600;
  font-style: italic;
}

h4 {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--accent);
  font-style: normal;
}

p { font-size: 1rem; line-height: 1.75; margin-bottom: 1.25rem; }
p:last-child { margin-bottom: 0; }

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.2s;
}
a:hover { color: var(--accent-soft); }

strong { font-weight: 600; }
em { font-style: italic; }

/* ── Navigation ─────────────────────────────────────────── */
.nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  padding: 0 1.75rem;
  gap: 0;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid color-mix(in srgb, var(--rule) 50%, transparent);
  height: var(--nav-h);
  overflow: visible;
}

.nav-brand {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 900;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: -0.02em;
  white-space: nowrap;
  padding: 0 1.5rem 0 0;
  flex-shrink: 0;
  line-height: var(--nav-h);
}
.nav-brand span { color: var(--accent); }

/* ── Center group: dropdown items ───────────────────────── */
.nav-center {
  display: flex;
  align-items: stretch;
  height: var(--nav-h);
  flex: 1;
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0 0.9rem;
  height: 100%;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
  background: none;
  border: none;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s;
  position: relative;
}
.nav-btn::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0.9rem; right: 0.9rem;
  height: 2px;
  background: var(--accent);
  transform: scaleX(0);
  transition: transform 0.2s var(--transition);
}
.nav-btn:hover { color: var(--ink); }
.nav-btn:hover::after,
.nav-item.open .nav-btn::after { transform: scaleX(1); }
.nav-item.open .nav-btn { color: var(--ink); }

.nav-chevron {
  font-size: 0.5rem;
  transition: transform 0.2s;
  opacity: 0.55;
}
.nav-item.open .nav-chevron { transform: rotate(180deg); }

/* ── Dropdown panel ─────────────────────────────────────── */
.nav-dd {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  display: none;
  flex-direction: row;
  gap: 0;
  min-width: 200px;
  background: var(--paper-deep);
  border: 1px solid var(--rule);
  border-top: 2px solid var(--accent);
  border-radius: 0 4px 4px 4px;
  box-shadow: 0 16px 48px var(--shadow);
  padding: 0.75rem 0;
  z-index: 999;
}
.nav-item.open .nav-dd { display: flex; }

.nav-dd-col {
  display: flex;
  flex-direction: column;
  min-width: 175px;
  padding: 0 0.3rem;
}
.nav-dd-col + .nav-dd-col {
  border-left: 1px solid var(--rule);
}

.nav-dd-label {
  font-family: var(--font-mono);
  font-size: 0.58rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  padding: 0.25rem 0.75rem 0.5rem;
  display: block;
}

.nav-dd a {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.45rem 0.75rem;
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--ink-soft);
  text-decoration: none;
  border-radius: 3px;
  transition: color 0.12s, background 0.12s;
  white-space: nowrap;
}
.nav-dd a:hover {
  color: var(--ink);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.nav-dd .nav-dd-icon {
  font-size: 0.82rem;
  opacity: 0.65;
  width: 1.1rem;
  text-align: center;
  flex-shrink: 0;
}

/* ── Right side ─────────────────────────────────────────── */
.nav-end {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
  flex-shrink: 0;
}

.nav-search-btn {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.38rem 0.85rem;
  font-family: var(--font-mono);
  font-size: 0.67rem;
  letter-spacing: 0.07em;
  color: var(--ink-soft);
  background: var(--paper-deep);
  border: 1px solid var(--rule);
  border-radius: 20px;
  cursor: pointer;
  text-decoration: none;
  transition: border-color 0.15s, color 0.15s;
  white-space: nowrap;
}
.nav-search-btn:hover { border-color: var(--accent); color: var(--accent); }
.nav-search-btn kbd {
  font-family: var(--font-mono);
  font-size: 0.57rem;
  background: var(--rule);
  color: var(--ink-soft);
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
  opacity: 0.65;
}

/* ── Hamburger (hidden on desktop) ──────────────────────── */
.nav-hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 36px;
  height: 36px;
  background: none;
  border: 1px solid var(--rule);
  border-radius: 4px;
  cursor: pointer;
  padding: 8px;
}
.nav-hamburger span {
  display: block;
  height: 2px;
  background: var(--ink);
  border-radius: 1px;
  transition: all 0.22s;
}
.nav-hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-hamburger.open span:nth-child(2) { opacity: 0; }
.nav-hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ── Mobile panel (inside <nav>, positioned below it) ───── */
.nav-panel {
  display: none;
  position: absolute;
  top: 100%;
  left: 0; right: 0;
  background: var(--paper-deep);
  border-bottom: 2px solid var(--accent);
  box-shadow: 0 12px 40px var(--shadow);
  padding: 1.25rem 1.5rem 1.75rem;
  max-height: calc(100vh - var(--nav-h));
  overflow-y: auto;
  z-index: 997;
}
.nav-panel.open { display: block; }

.nav-panel-section { margin-bottom: 1.25rem; }
.nav-panel-section:last-child { margin-bottom: 0; }
.nav-panel-head {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 0.5rem;
}
.nav-panel-links {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.2rem;
}
.nav-panel-links a {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.65rem;
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--ink-soft);
  text-decoration: none;
  border-radius: 4px;
  transition: all 0.12s;
}
.nav-panel-links a:hover {
  color: var(--ink);
  background: color-mix(in srgb, var(--accent) 9%, transparent);
}
.nav-panel-links .nav-dd-icon { font-size: 0.82rem; opacity: 0.65; }

/* ── Theme Toggle Button ───────────────────────────────── */
.theme-toggle {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
  transition: all 0.2s;
}
.theme-toggle:hover {
  background: var(--paper-deep);
  color: var(--ink);
  border-color: var(--accent);
}

/* ── Layout Wrapper ────────────────────────────────────── */
.layout {
  max-width: var(--layout-max);
  margin: 0 auto;
  padding: 3rem 2.5rem 6rem;
  padding-top: calc(var(--nav-h) + 3rem);
  position: relative;
  z-index: 1;
}

.layout-with-sidebar {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  gap: 4rem;
  align-items: start;
}

.article-body {
  max-width: var(--content-max);
}

/* ── Sidebar / TOC ─────────────────────────────────────── */
.sidebar {
  position: sticky;
  top: calc(var(--nav-h) + 2rem);
  max-height: calc(100vh - var(--nav-h) - 4rem);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--rule) transparent;
}

.toc-title {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--ink-soft);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--rule);
}

.toc-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.toc-list a {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--ink-soft);
  text-decoration: none;
  display: block;
  padding: 0.3rem 0.5rem;
  border-radius: var(--radius);
  border-left: 2px solid transparent;
  transition: all 0.2s;
  line-height: 1.4;
}
.toc-list a:hover,
.toc-list a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.toc-list .toc-sub a {
  padding-left: 1.2rem;
  font-size: 0.68rem;
}

/* ── Section Header ────────────────────────────────────── */
.section-header {
  margin-bottom: 3rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--rule);
}

.section-number {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.15em;
  color: var(--accent);
  text-transform: uppercase;
  display: block;
  margin-bottom: 0.75rem;
}

.section-header p {
  font-size: 1.1rem;
  color: var(--ink-soft);
  max-width: 60ch;
  margin-top: 0.75rem;
}

/* ── Content Sections ──────────────────────────────────── */
.content-section {
  margin-bottom: 4rem;
  scroll-margin-top: calc(var(--nav-h) + 2rem);
}

.content-section > h2 {
  margin-bottom: 0.4rem;
}
.content-section > h2 + p {
  color: var(--ink-soft);
  margin-bottom: 1.5rem;
}

.content-section h3 {
  margin-top: 2rem;
  margin-bottom: 0.75rem;
}

/* ── Drop Cap ──────────────────────────────────────────── */
.drop-cap::first-letter {
  font-family: var(--font-display);
  font-size: 4.5rem;
  font-weight: 900;
  color: var(--accent);
  float: left;
  line-height: 0.85;
  margin-right: 0.1em;
  margin-top: 0.05em;
  font-variation-settings: 'opsz' 144;
}

/* ── Ornament Divider ──────────────────────────────────── */
.ornament {
  text-align: center;
  color: var(--gold);
  font-size: 1.2rem;
  letter-spacing: 1rem;
  margin: 2.5rem 0;
  opacity: 0.7;
}

/* ── Callout Blocks ────────────────────────────────────── */
.callout {
  background: var(--paper-deep);
  border-left: 3px solid var(--accent);
  padding: 1.25rem 1.5rem;
  border-radius: 0 var(--radius) var(--radius) 0;
  margin: 1.5rem 0;
  position: relative;
}

.callout::before {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--accent);
  display: block;
  margin-bottom: 0.5rem;
}

.callout-analogy { border-color: var(--gold); }
.callout-analogy::before { content: '🔍 Analogy'; color: var(--gold); }

.callout-warning { border-color: #c0392b; }
.callout-warning::before { content: '⚠️ Watch Out'; color: #c0392b; }

.callout-tip { border-color: var(--leaf); }
.callout-tip::before { content: '💡 Pro Tip'; color: var(--leaf); }

.callout-interview { border-color: var(--accent); }
.callout-interview::before { content: '🎯 Interview Tip'; color: var(--accent); }

.callout-tradeoff { border-color: var(--gold); }
.callout-tradeoff::before { content: '⚖️ Tradeoff'; color: var(--gold); }

.callout-failure { border-color: #c0392b; }
.callout-failure::before { content: '💥 Failure Scenario'; color: #c0392b; }

.callout p { margin-bottom: 0.5rem; }
.callout p:last-child { margin-bottom: 0; }

/* ── Code Blocks ───────────────────────────────────────── */
pre {
  background: var(--code-bg);
  color: var(--code-text);
  padding: 1.5rem;
  border-radius: var(--radius);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.6;
  box-shadow: 0 8px 30px var(--shadow);
  margin: 1.5rem 0;
}

code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--paper-deep);
  color: var(--accent-soft);
  padding: 0.15em 0.4em;
  border-radius: 3px;
}

pre code {
  background: none;
  color: inherit;
  padding: 0;
  font-size: inherit;
}

/* Syntax highlight tokens */
.tok-kw    { color: #e8a87c; }
.tok-type  { color: #c8a0e0; }
.tok-str   { color: #a8c8a0; }
.tok-num   { color: #f0b878; }
.tok-cmt   { color: #6a6258; font-style: italic; }
.tok-fn    { color: #e8d088; }

/* ── Cards ─────────────────────────────────────────────── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  margin: 2rem 0;
}

.card {
  background: var(--paper-deep);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1.5rem;
  cursor: pointer;
  transition: all 0.25s var(--transition);
  text-decoration: none;
  color: var(--ink);
  display: block;
  position: relative;
  overflow: hidden;
}

.card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--ink);
  opacity: 0;
  transition: opacity 0.25s var(--transition);
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 40px var(--shadow);
  color: var(--paper);
  border-color: transparent;
}
.card:hover::before { opacity: 1; }
.card:hover * { position: relative; z-index: 1; }

.card-number {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 0.75rem;
  display: block;
}

.card h3 {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  font-style: normal;
}

.card p {
  font-size: 0.9rem;
  color: var(--ink-soft);
  line-height: 1.5;
  margin: 0;
}
.card:hover p { color: color-mix(in srgb, var(--paper) 70%, transparent); }

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 1rem;
}

/* ── Badges / Chips ────────────────────────────────────── */
.badge {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 0.2em 0.6em;
  border-radius: 20px;
  display: inline-block;
}

.badge-beginner  { background: color-mix(in srgb, var(--leaf) 15%, transparent); color: var(--leaf); }
.badge-mid       { background: color-mix(in srgb, var(--gold) 15%, transparent); color: var(--gold); }
.badge-advanced  { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }
.badge-concept   { background: color-mix(in srgb, var(--ink-soft) 12%, transparent); color: var(--ink-soft); }

/* ── Two-column comparison ─────────────────────────────── */
.compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin: 1.5rem 0;
}
.compare-col {
  background: var(--paper-deep);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.compare-col h4 {
  margin-bottom: 0.75rem;
}
.compare-col ul {
  padding-left: 1.2rem;
}
.compare-col li {
  font-size: 0.9rem;
  margin-bottom: 0.4rem;
  line-height: 1.5;
}

/* ── Topic Accordion ───────────────────────────────────── */
.topic {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  overflow: hidden;
}

.topic-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  cursor: pointer;
  background: var(--paper-deep);
  user-select: none;
  transition: background 0.2s;
  gap: 1rem;
}
.topic-header:hover { background: color-mix(in srgb, var(--accent) 6%, var(--paper-deep)); }

.topic-header h3 {
  font-size: 1.05rem;
  font-weight: 600;
  font-style: normal;
  margin: 0;
  flex: 1;
}

.topic-arrow {
  font-size: 0.8rem;
  color: var(--ink-soft);
  transition: transform 0.3s var(--transition);
  flex-shrink: 0;
}
.topic.open .topic-arrow { transform: rotate(180deg); }

.topic-body {
  display: none;
  padding: 1.5rem;
  border-top: 1px solid var(--rule);
  animation: fadeSlideIn 0.25s var(--transition);
}
.topic.open .topic-body { display: block; }

/* ── Architecture Diagram ──────────────────────────────── */
.arch-diagram {
  background: var(--paper-deep);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin: 1.5rem 0;
  overflow-x: auto;
}

.arch-diagram svg {
  width: 100%;
  height: auto;
  display: block;
}

/* ── Interactive Simulation ────────────────────────────── */
.simulation {
  background: var(--paper-deep);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
  margin: 2rem 0;
}

.simulation-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--rule);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.simulation-title {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--ink-soft);
}

.simulation-body {
  padding: 1.5rem;
}

.sim-controls {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

/* ── Buttons ───────────────────────────────────────────── */
.btn {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 0.55rem 1.2rem;
  border-radius: var(--radius);
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  transition: all 0.2s var(--transition);
  white-space: nowrap;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.btn:hover {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

.btn-primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.btn-primary:hover {
  background: var(--accent-soft);
  border-color: var(--accent-soft);
  color: white;
}

.btn-sm { padding: 0.35rem 0.8rem; font-size: 0.65rem; }

/* ── Progress Bar ──────────────────────────────────────── */
.progress-bar-wrap {
  background: var(--paper-deep);
  border-radius: 20px;
  height: 6px;
  overflow: hidden;
  margin: 0.5rem 0;
}
.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-soft));
  border-radius: 20px;
  transition: width 0.6s var(--transition);
}

/* ── Table ─────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; margin: 1.5rem 0; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
th {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
  padding: 0.6rem 1rem;
  border-bottom: 2px solid var(--rule);
  text-align: left;
  background: var(--paper-deep);
}
td {
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
  line-height: 1.5;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: color-mix(in srgb, var(--accent) 4%, transparent); }

/* ── Quiz ──────────────────────────────────────────────── */
.quiz-card {
  background: var(--paper-deep);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin: 1.5rem 0;
}

.quiz-question {
  font-weight: 600;
  margin-bottom: 1rem;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.quiz-option {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.95rem;
}
.quiz-option:hover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 5%, transparent); }
.quiz-option.correct { border-color: var(--leaf); background: color-mix(in srgb, var(--leaf) 8%, transparent); }
.quiz-option.wrong   { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }

/* ── Hero ──────────────────────────────────────────────── */
.hero {
  min-height: calc(100vh - var(--nav-h));
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: calc(var(--nav-h) + 4rem) 2.5rem 4rem;
  max-width: var(--layout-max);
  margin: 0 auto;
  position: relative;
  z-index: 1;
}

.hero-eyebrow {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--gold);
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.hero-eyebrow::before {
  content: '';
  width: 2rem;
  height: 1px;
  background: var(--gold);
}

.hero h1 {
  max-width: 14ch;
  margin-bottom: 1.5rem;
}

.hero-sub {
  font-size: clamp(1rem, 2vw, 1.25rem);
  color: var(--ink-soft);
  max-width: 50ch;
  line-height: 1.6;
  margin-bottom: 2.5rem;
}

.hero-actions {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

/* ── Stats Strip ───────────────────────────────────────── */
.stats-strip {
  display: flex;
  gap: 3rem;
  padding: 2rem 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  margin: 3rem 0;
  flex-wrap: wrap;
}
.stat { text-align: center; }
.stat-value {
  font-family: var(--font-display);
  font-size: 2.5rem;
  font-weight: 900;
  color: var(--accent);
  display: block;
  line-height: 1;
}
.stat-label {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--ink-soft);
  margin-top: 0.25rem;
  display: block;
}

/* ── Footer ────────────────────────────────────────────── */
.footer {
  border-top: 1px solid var(--rule);
  padding: 2.5rem;
  text-align: center;
  margin-top: 6rem;
  position: relative;
  z-index: 1;
}

.footer p {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin: 0;
}

/* ── Search Bar ────────────────────────────────────────── */
.search-wrap {
  position: relative;
  max-width: 400px;
}

.search-input {
  width: 100%;
  padding: 0.6rem 2.5rem 0.6rem 1rem;
  background: var(--paper-deep);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--ink);
  outline: none;
  transition: border-color 0.2s;
}
.search-input::placeholder { color: var(--ink-soft); opacity: 0.6; }
.search-input:focus { border-color: var(--accent); }

.search-icon {
  position: absolute;
  right: 0.75rem; top: 50%;
  transform: translateY(-50%);
  color: var(--ink-soft);
  font-size: 0.85rem;
}

/* ── Concept List ──────────────────────────────────────── */
.concept-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.concept-list li {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid color-mix(in srgb, var(--rule) 50%, transparent);
  font-size: 0.95rem;
}
.concept-list li:last-child { border-bottom: none; }
.concept-list li::before {
  content: '→';
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  flex-shrink: 0;
  margin-top: 0.1rem;
}

/* ── Diagram Nodes (Canvas/SVG) ────────────────────────── */
.node {
  fill: var(--paper-deep);
  stroke: var(--rule);
  stroke-width: 1.5;
}
.node-label {
  font-family: var(--font-mono);
  font-size: 11px;
  fill: var(--ink);
}
.node-highlight { stroke: var(--accent); stroke-width: 2; }
.arrow { stroke: var(--ink-soft); stroke-width: 1.5; fill: none; marker-end: url(#arrowhead); }
.arrow-active { stroke: var(--accent); stroke-width: 2; }

/* ── Canvas Simulations ────────────────────────────────── */
.sim-canvas {
  width: 100%;
  border-radius: var(--radius);
  display: block;
  background: var(--code-bg);
}

/* ── Animations ────────────────────────────────────────── */
@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}

@keyframes flow {
  from { stroke-dashoffset: 20; }
  to   { stroke-dashoffset: 0; }
}

.animate-pulse { animation: pulse 1.5s ease-in-out infinite; }

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 900px) {
  html { font-size: 16px; }

  .nav-center { display: none; }
  .nav-search-btn { display: none; }
  .nav-hamburger { display: flex; }

  .layout { padding: 1.5rem 1.25rem 4rem; padding-top: calc(var(--nav-h) + 1.5rem); }

  .layout-with-sidebar {
    grid-template-columns: 1fr;
  }
  .sidebar { position: static; max-height: none; }

  .hero { padding: calc(var(--nav-h) + 2rem) 1.25rem 2rem; }

  .compare-grid { grid-template-columns: 1fr; }

  .stats-strip { gap: 1.5rem; }

  .card-grid { grid-template-columns: 1fr; }
}

/* ── Utility Classes ───────────────────────────────────── */
.text-accent  { color: var(--accent); }
.text-gold    { color: var(--gold); }
.text-soft    { color: var(--ink-soft); }
.text-leaf    { color: var(--leaf); }
.text-mono    { font-family: var(--font-mono); }
.text-center  { text-align: center; }
.mt-1  { margin-top: 0.5rem; }
.mt-2  { margin-top: 1rem; }
.mt-3  { margin-top: 1.5rem; }
.mt-4  { margin-top: 2rem; }
.mb-1  { margin-bottom: 0.5rem; }
.mb-2  { margin-bottom: 1rem; }
.mb-3  { margin-bottom: 1.5rem; }
.mb-4  { margin-bottom: 2rem; }
.gap-1 { gap: 0.5rem; }
.flex  { display: flex; align-items: center; }
.flex-wrap { flex-wrap: wrap; }
.hidden { display: none; }
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ── Quiz Styles (global — used in 8+ module pages) ────── */
.quiz-container {
  margin-top: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}
.quiz-question {
  background: var(--paper-deep);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1.5rem;
}
.quiz-prompt {
  font-size: 0.97rem;
  line-height: 1.6;
  margin-bottom: 1rem;
  color: var(--ink);
}
.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.quiz-option {
  text-align: left;
  padding: 0.7rem 1rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink-soft);
  font-family: var(--font-body);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.15s;
  line-height: 1.5;
}
.quiz-option:hover:not([disabled]) {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 5%, var(--paper));
  color: var(--ink);
}
.quiz-option.correct {
  border-color: var(--leaf);
  background: color-mix(in srgb, var(--leaf) 10%, var(--paper));
  color: var(--ink);
}
.quiz-option.wrong {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--paper));
}
.quiz-option[disabled] { cursor: default; }
.quiz-explanation {
  margin-top: 1rem;
  padding: 0.9rem 1.1rem;
  background: color-mix(in srgb, var(--gold) 8%, var(--paper-deep));
  border-left: 3px solid var(--gold);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 0.88rem;
  line-height: 1.65;
  color: var(--ink-soft);
}

/* ── Tabs (used in databases.html, interviews.html) ─────── */
.tabs { margin: 1.5rem 0; }
.tab-bar {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--rule);
  margin-bottom: 1.5rem;
  overflow-x: auto;
}
.tab-btn {
  padding: 0.55rem 1.1rem;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-soft);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}
.tab-btn:hover { color: var(--ink); }
.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.tab-panel { display: block; }
.tab-panel.hidden { display: none; }

/* ── btn-leaf (used by app.js for completed mark-read btns) */
.btn-leaf {
  background: color-mix(in srgb, var(--leaf) 12%, var(--paper-deep));
  color: var(--leaf);
  border-color: color-mix(in srgb, var(--leaf) 40%, transparent);
}
.btn-leaf:hover {
  background: color-mix(in srgb, var(--leaf) 20%, var(--paper-deep));
  color: var(--leaf);
  border-color: var(--leaf);
}

/* ── Callout insight (used in incidents.html) ───────────── */
.callout-insight { border-color: var(--gold); }
.callout-insight::before { content: '💡 Key Insight'; color: var(--gold); }

/* ── Filter chips (used in search.html, bookmarks.html) ─── */
.filter-chip {
  padding: 0.3rem 0.85rem;
  border: 1px solid var(--rule);
  border-radius: 20px;
  background: transparent;
  font-family: var(--font-mono);
  font-size: 0.64rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.filter-chip:hover,
.filter-chip.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* ── Empty state (used in bookmarks.html, search.html) ──── */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--ink-soft);
}
.empty-state .big-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.4;
  display: block;
}
.empty-state h3 {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-style: normal;
  margin-bottom: 0.5rem;
  color: var(--ink-soft);
}
.empty-state p { font-size: 0.9rem; }

/* ── color-mix() fallbacks for older Safari/Firefox ─────── */
@supports not (color: color-mix(in srgb, red, blue)) {
  .nav-dd a:hover { background: rgba(184,52,31,0.08); }
  .nav-btn:hover { background: rgba(26,22,18,0.06); }
  .toc-list a.active { background: rgba(184,52,31,0.08); }
  .topic-header:hover { background: rgba(184,52,31,0.06); }
  .quiz-option:hover:not([disabled]) { background: rgba(184,52,31,0.05); }
  .quiz-option.correct { background: rgba(74,103,65,0.10); }
  .quiz-option.wrong { background: rgba(184,52,31,0.10); }
  .badge-beginner { background: rgba(74,103,65,0.15); }
  .badge-mid { background: rgba(160,123,44,0.15); }
  .badge-advanced { background: rgba(184,52,31,0.15); }
  .nav-panel-links a:hover { background: rgba(184,52,31,0.09); }
  .filter-chip.active { background: var(--accent); }
}
