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

:root {
  --sidebar-width: 248px;
  --bg:            #f8f8f6;
  --surface:       #ffffff;
  --text:          #1e1e1e;
  --muted:         #5a5a5a;
  --faint:         #888;
  --border:        #e0e0dc;
  --accent:        #2563eb;
  --accent-hover:  #1d4ed8;
  --sidebar-bg:    #18192a;
  --sidebar-text:  #c8cce8;
  --sidebar-muted: #5a6080;
  --sidebar-hover: rgba(59,130,246,0.15);
  --code-bg:       #1e2030;
  --code-text:     #d0d6f0;
  --tag-bg:        #eff6ff;
  --tag-text:      #1d4ed8;
  --tag-border:    #bfdbfe;
  --ref-bg:        #f9f9f7;
}

html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  font-size: 16px;
  line-height: 1.75;
  color: var(--text);
  background: var(--bg);
}

/* ── Layout ─────────────────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0;
  z-index: 20;
  scrollbar-width: thin;
  scrollbar-color: #2a2d42 transparent;
}

.sidebar-brand {
  display: block;
  padding: 20px 18px 16px;
  color: #ffffff;
  text-decoration: none;
  font-weight: 700;
  font-size: 15px;
  line-height: 1.35;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}

.sidebar-brand span {
  display: block;
  font-size: 11px;
  font-weight: 400;
  color: var(--sidebar-muted);
  margin-top: 2px;
  letter-spacing: 0.03em;
}

.sidebar-section {
  padding: 14px 0 4px 18px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--sidebar-muted);
}

.sidebar nav a {
  display: block;
  padding: 6px 12px 6px 18px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13.5px;
  line-height: 1.45;
  border-left: 2px solid transparent;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.sidebar nav a:hover {
  background: var(--sidebar-hover);
  color: #ffffff;
  border-left-color: #3b82f6;
}

.sidebar nav a.active {
  background: rgba(59,130,246,0.2);
  color: #ffffff;
  border-left-color: #3b82f6;
  font-weight: 600;
}

.sidebar nav a .num {
  display: inline-block;
  min-width: 20px;
  color: var(--sidebar-muted);
  font-size: 12px;
}

.sidebar-footer {
  margin-top: auto;
  padding: 12px 18px 16px;
  border-top: 1px solid rgba(255,255,255,0.07);
}

.sidebar-footer a {
  display: block;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13px;
  padding: 5px 0;
}

.sidebar-footer a:hover { color: #ffffff; }

/* ── Main Content ────────────────────────────────────────────── */
.main {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
}

.content {
  max-width: 760px;
  margin: 0 auto;
  padding: 52px 40px 80px;
}

/* ── Page Header ─────────────────────────────────────────────── */
.page-header {
  margin-bottom: 40px;
  padding-bottom: 28px;
  border-bottom: 1px solid var(--border);
}

.module-badge {
  display: inline-block;
  background: var(--tag-bg);
  color: var(--tag-text);
  border: 1px solid var(--tag-border);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 3px 10px;
  border-radius: 4px;
  margin-bottom: 12px;
}

.page-header h1 {
  font-size: 32px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text);
  margin-bottom: 10px;
}

.page-header .subtitle {
  font-size: 17px;
  color: var(--muted);
  line-height: 1.5;
}

/* ── Index Hero ──────────────────────────────────────────────── */
.hero {
  background: var(--sidebar-bg);
  color: #ffffff;
  padding: 56px 40px;
  margin: 0;
}

.hero-inner { max-width: 760px; margin: 0 auto; }

.hero h1 {
  font-size: 36px;
  font-weight: 800;
  line-height: 1.15;
  margin-bottom: 14px;
  color: #ffffff;
}

.hero .tagline {
  font-size: 18px;
  line-height: 1.6;
  color: #a0a8cc;
  max-width: 560px;
  margin-bottom: 28px;
}

.hero-meta {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
}

.hero-meta-item {
  font-size: 14px;
  color: #8891b8;
}

.hero-meta-item strong { color: #c8cce8; }

/* ── Typography ──────────────────────────────────────────────── */
h2 {
  font-size: 22px;
  font-weight: 700;
  margin: 40px 0 14px;
  color: var(--text);
  line-height: 1.3;
}

h2:first-child { margin-top: 0; }

h3 {
  font-size: 17px;
  font-weight: 700;
  margin: 28px 0 10px;
  color: var(--text);
}

h4 {
  font-size: 15px;
  font-weight: 700;
  margin: 20px 0 8px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

p { margin-bottom: 16px; color: var(--text); }

ul, ol {
  margin: 0 0 16px 20px;
}

li { margin-bottom: 5px; }

strong { font-weight: 600; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; color: var(--accent-hover); }

/* ── Section Dividers ─────────────────────────────────────────── */
.section { margin-bottom: 44px; }

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 36px 0;
}

/* ── Objectives Box ──────────────────────────────────────────── */
.objectives {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 20px 22px;
  margin-bottom: 32px;
}

.objectives h3 { margin-top: 0; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 10px; }

.objectives ul { margin-bottom: 0; }

/* ── Key Concept Cards ───────────────────────────────────────── */
.concept-list {
  list-style: none;
  margin: 0 0 20px;
  padding: 0;
}

.concept-list li {
  padding: 6px 0 6px 20px;
  position: relative;
  border-bottom: 1px solid var(--border);
  margin: 0;
}

.concept-list li:last-child { border-bottom: none; }

.concept-list li::before {
  content: '→';
  position: absolute;
  left: 0;
  color: var(--accent);
  font-weight: bold;
}

/* ── Why It Matters ──────────────────────────────────────────── */
.why-matters {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 6px;
  padding: 14px 18px;
  margin-bottom: 20px;
  font-size: 15px;
}

.why-matters::before {
  content: 'Why it matters: ';
  font-weight: 700;
  color: #92400e;
}

/* ── Code Blocks ─────────────────────────────────────────────── */
pre {
  background: var(--code-bg);
  color: var(--code-text);
  border-radius: 6px;
  padding: 18px 20px;
  overflow-x: auto;
  font-size: 13.5px;
  line-height: 1.65;
  margin: 0 0 20px;
  font-family: 'JetBrains Mono', 'Fira Code', 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
}

code {
  font-family: 'JetBrains Mono', 'Fira Code', 'SF Mono', 'Consolas', monospace;
  font-size: 13.5px;
}

p code, li code {
  background: #f0f0ec;
  color: #d04040;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 13px;
}

.code-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--faint);
  margin-bottom: 5px;
}

/* ── Formula Block ───────────────────────────────────────────── */
.formula {
  background: #f5f5f2;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 16px 20px;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 14px;
  line-height: 1.8;
  margin-bottom: 20px;
  overflow-x: auto;
  white-space: pre;
}

/* ── References Section ──────────────────────────────────────── */
.references {
  background: var(--ref-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 28px 28px 22px;
  margin-top: 48px;
}

.references h2 {
  font-size: 18px;
  margin-top: 0;
  margin-bottom: 20px;
  color: var(--text);
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.ref-group { margin-bottom: 24px; }
.ref-group:last-child { margin-bottom: 0; }

.ref-group h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--faint);
  font-weight: 700;
  margin: 0 0 10px;
}

.ref-item {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
}

.ref-item:last-child { border-bottom: none; padding-bottom: 0; }

.ref-item .ref-title {
  font-weight: 600;
  color: var(--text);
  display: block;
  margin-bottom: 2px;
}

.ref-item .ref-author {
  font-size: 13px;
  color: var(--muted);
  display: block;
  margin-bottom: 4px;
}

.ref-item .ref-note {
  font-size: 13px;
  color: var(--muted);
  font-style: italic;
  display: block;
  margin-bottom: 4px;
}

.ref-item a {
  font-size: 13px;
  color: var(--accent);
  word-break: break-all;
}

/* ── Module Grid (index) ──────────────────────────────────────── */
.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
  margin: 24px 0;
}

.module-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px 22px;
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.module-card:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 12px rgba(37,99,235,0.1);
  text-decoration: none;
  color: var(--text);
}

.module-card .card-num {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}

.module-card h3 {
  font-size: 16px;
  margin: 0 0 6px;
  line-height: 1.35;
}

.module-card p {
  font-size: 14px;
  color: var(--muted);
  margin: 0;
  line-height: 1.5;
}

.module-card .card-meta {
  font-size: 12px;
  color: var(--faint);
  margin-top: 10px;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

/* ── Pagination ──────────────────────────────────────────────── */
.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 52px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  gap: 16px;
}

.pagination a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  transition: border-color 0.12s, background 0.12s;
}

.pagination a:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--tag-bg);
  text-decoration: none;
}

.pagination .spacer { flex: 1; }

/* ── Info Table ──────────────────────────────────────────────── */
.info-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
  margin-bottom: 24px;
}

.info-table th {
  text-align: left;
  padding: 8px 12px;
  background: #f3f3f0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  border: 1px solid var(--border);
}

.info-table td {
  padding: 10px 12px;
  border: 1px solid var(--border);
  vertical-align: top;
}

.info-table td:first-child { font-weight: 600; white-space: nowrap; }
.info-table tr:hover td { background: #fafaf8; }

/* ── Tag Pills ───────────────────────────────────────────────── */
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }

.tag {
  display: inline-block;
  background: var(--tag-bg);
  color: var(--tag-text);
  border: 1px solid var(--tag-border);
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
}

/* ── Blockquote ──────────────────────────────────────────────── */
blockquote {
  border-left: 3px solid var(--border);
  margin: 0 0 16px;
  padding: 4px 0 4px 24px;
  color: var(--muted);
}

blockquote p { color: var(--muted); }
blockquote p:last-child { margin-bottom: 0; }

/* ── Note Box ────────────────────────────────────────────────── */
.note {
  background: #f0f9ff;
  border-left: 3px solid #38bdf8;
  padding: 12px 16px;
  margin: 16px 0 20px;
  border-radius: 0 4px 4px 0;
  font-size: 15px;
  color: #0c4a6e;
}

/* ── Checklist ───────────────────────────────────────────────── */
.checklist {
  list-style: none;
  margin: 0 0 20px;
  padding: 0;
}

.checklist li {
  padding: 5px 0 5px 26px;
  position: relative;
  border-bottom: 1px solid var(--border);
  margin: 0;
  font-size: 15px;
}

.checklist li:last-child { border-bottom: none; }

.checklist li::before {
  content: '☐';
  position: absolute;
  left: 4px;
  color: var(--accent);
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 780px) {
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
  }

  .main { margin-left: 0; }

  .content { padding: 32px 20px 60px; }

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

  .hero { padding: 40px 20px; }

  .hero h1 { font-size: 26px; }

  .layout { flex-direction: column; }
}
