/* ═══════════════════════════════════════════════════════════════
   CS234 Reinforcement Learning — Shared Styles
   ═══════════════════════════════════════════════════════════════ */

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

:root {
  --parchment: #f6f1eb;
  --parchment-dark: #ebe4da;
  --ink: #1a1714;
  --ink-light: #4a4540;
  --ink-muted: #8a8480;
  --accent: #b44a2d;
  --accent-hover: #963d24;
  --accent-light: rgba(180, 74, 45, 0.08);
  --accent-border: rgba(180, 74, 45, 0.2);
  --rule: rgba(26, 23, 20, 0.12);
  --rule-strong: rgba(26, 23, 20, 0.25);
  --sidebar-w: 280px;
  --serif: 'Instrument Serif', 'Georgia', serif;
  --sans: 'Source Sans 3', 'Helvetica Neue', sans-serif;
  --mono: 'IBM Plex Mono', 'Menlo', monospace;
  --blue: #2563eb;
  --green: #16a34a;
  --purple: #7c3aed;
  --amber: #d97706;
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--sans);
  background: var(--parchment);
  color: var(--ink);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ── Noise texture overlay ── */
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='0.03'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 9999;
}

/* ═══════════════════════════════════════════════════════════════
   SIDEBAR (shared between index and lecture pages)
   ═══════════════════════════════════════════════════════════════ */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--ink);
  color: var(--parchment);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-header {
  padding: 32px 24px 24px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-header .course-code {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 6px;
  font-weight: 500;
}

.sidebar-header h1 {
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 400;
  line-height: 1.3;
  color: var(--parchment);
}

.sidebar-header h1 a {
  color: inherit;
  text-decoration: none;
}

.sidebar-header h1 a:hover {
  color: var(--accent);
}

.sidebar-header .term {
  font-family: var(--sans);
  font-size: 13px;
  color: rgba(246,241,235,0.45);
  margin-top: 4px;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 16px 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.15) transparent;
}

.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 2px; }

.nav-section {
  padding: 0 16px;
  margin-bottom: 4px;
}

.nav-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  color: rgba(246,241,235,0.6);
  font-size: 14px;
  line-height: 1.4;
}

.nav-item:hover {
  background: rgba(255,255,255,0.06);
  color: var(--parchment);
}

.nav-item.active {
  background: rgba(180, 74, 45, 0.15);
  color: var(--parchment);
}

.nav-item .nav-num {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--accent);
  min-width: 20px;
  padding-top: 2px;
  opacity: 0.8;
}

.nav-item.active .nav-num { opacity: 1; }

/* ToC sub-items (lecture pages) */
.nav-sub-item {
  display: block;
  padding: 6px 12px 6px 44px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  color: rgba(246,241,235,0.4);
  font-size: 13px;
  line-height: 1.35;
}

.nav-sub-item:hover {
  background: rgba(255,255,255,0.04);
  color: rgba(246,241,235,0.7);
}

.nav-sub-item.active {
  color: var(--parchment);
  background: rgba(255,255,255,0.06);
}

.sidebar-footer {
  padding: 16px 24px;
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 12px;
  color: rgba(246,241,235,0.3);
  font-family: var(--mono);
}

.sidebar-footer a {
  color: rgba(246,241,235,0.45);
  text-decoration: none;
  transition: color 0.2s;
}

.sidebar-footer a:hover { color: var(--accent); }

/* ── Mobile menu toggle ── */
.menu-toggle {
  display: none;
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 200;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: var(--ink);
  border: none;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
}

.menu-toggle span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--parchment);
  border-radius: 1px;
  transition: all 0.3s;
  position: relative;
}

.menu-toggle span::before,
.menu-toggle span::after {
  content: '';
  position: absolute;
  left: 0;
  width: 20px;
  height: 2px;
  background: var(--parchment);
  border-radius: 1px;
  transition: all 0.3s;
}

.menu-toggle span::before { top: -6px; }
.menu-toggle span::after { top: 6px; }

.menu-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 90;
  opacity: 0;
  transition: opacity 0.3s;
}

/* ── Main content ── */
.main {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
}

/* ── Scroll progress ── */
.progress-bar {
  position: fixed;
  top: 0;
  left: var(--sidebar-w);
  right: 0;
  height: 3px;
  background: transparent;
  z-index: 50;
}

.progress-bar .bar {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.1s linear;
}

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

/* ═══════════════════════════════════════════════════════════════
   INDEX PAGE — Hero, modules, lecture cards, readings, prereqs
   ═══════════════════════════════════════════════════════════════ */
.hero {
  padding: 80px 60px 60px;
  border-bottom: 1px solid var(--rule);
  position: relative;
  overflow: hidden;
  max-width: 1200px;
  margin: 0 auto;
}

.hero::after {
  content: '';
  position: absolute;
  top: -120px;
  right: -80px;
  width: 400px;
  height: 400px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(180,74,45,0.06) 0%, transparent 70%);
  pointer-events: none;
}

.hero-eyebrow {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 16px;
  font-weight: 500;
}

.hero h2 {
  font-family: var(--serif);
  font-size: 48px;
  font-weight: 400;
  line-height: 1.15;
  color: var(--ink);
  max-width: 600px;
  margin-bottom: 16px;
}

.hero p {
  font-size: 18px;
  color: var(--ink-light);
  max-width: 560px;
  line-height: 1.7;
}

.hero-stats {
  display: flex;
  gap: 40px;
  margin-top: 32px;
  padding-top: 28px;
  border-top: 1px solid var(--rule);
}

.hero-stat .stat-num {
  font-family: var(--serif);
  font-size: 32px;
  color: var(--ink);
}

.hero-stat .stat-label {
  font-size: 13px;
  color: var(--ink-muted);
  margin-top: 2px;
}

.content {
  padding: 0 60px 80px;
  max-width: 1200px;
  margin: 0 auto;
}

/* ── Module card ── */
.module {
  padding-top: 56px;
  scroll-margin-top: 24px;
}

.module-header {
  display: flex;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 2px solid var(--rule-strong);
}

.module-number {
  font-family: var(--serif);
  font-size: 56px;
  line-height: 1;
  color: var(--accent);
  opacity: 0.25;
  min-width: 60px;
}

.module-title-block { padding-top: 8px; }

.module-title {
  font-family: var(--serif);
  font-size: 30px;
  font-weight: 400;
  line-height: 1.25;
  color: var(--ink);
}

.module-subtitle {
  font-size: 15px;
  color: var(--ink-muted);
  margin-top: 4px;
}

.module-body {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 40px;
  max-width: 1200px;
}

.module-description {
  font-size: 16px;
  line-height: 1.75;
  color: var(--ink-light);
}

.module-description p + p { margin-top: 12px; }

.module-description ul {
  margin-top: 10px;
  padding-left: 20px;
}

.module-description li {
  margin-bottom: 6px;
  color: var(--ink-light);
}

/* ── Lecture cards ── */
.lectures-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lectures-panel h4 {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 4px;
  font-weight: 500;
}

.lecture-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: white;
  border: 1px solid var(--rule);
  border-radius: 10px;
  text-decoration: none;
  color: var(--ink);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.lecture-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--accent);
  transform: scaleY(0);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.lecture-card:hover {
  border-color: var(--accent-border);
  background: var(--accent-light);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(180, 74, 45, 0.08);
}

.lecture-card:hover::before { transform: scaleY(1); }

.lecture-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--accent-light);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.lecture-icon svg {
  width: 18px;
  height: 18px;
  color: var(--accent);
}

.lecture-info {
  flex: 1;
  min-width: 0;
}

.lecture-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.3;
}

.lecture-meta {
  font-size: 12px;
  color: var(--ink-muted);
  font-family: var(--mono);
}

.lecture-arrow {
  color: var(--ink-muted);
  transition: all 0.25s;
  flex-shrink: 0;
}

.lecture-card:hover .lecture-arrow {
  color: var(--accent);
  transform: translateX(3px);
}

/* ── Reading pills ── */
.readings { margin-top: 8px; }

.readings h4 {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 8px;
  font-weight: 500;
}

.reading-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.reading-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  color: var(--ink-light);
  background: var(--parchment-dark);
  border: 1px solid var(--rule);
  text-decoration: none;
  transition: all 0.2s;
}

.reading-pill:hover {
  border-color: var(--accent-border);
  color: var(--accent);
}

.reading-pill.is-link { cursor: pointer; }

.reading-pill svg {
  width: 12px;
  height: 12px;
  opacity: 0.5;
}

/* ── Prerequisites ── */
.prereqs {
  background: white;
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: 28px 32px;
  margin-top: 40px;
  max-width: 1200px;
}

.prereqs h4 {
  font-family: var(--serif);
  font-size: 20px;
  margin-bottom: 12px;
}

.prereqs-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.prereq-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 8px;
  background: var(--parchment);
  border: 1px solid var(--rule);
  text-decoration: none;
  color: var(--ink);
  transition: all 0.2s;
}

.prereq-card:hover {
  border-color: var(--accent-border);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.prereq-card .prereq-icon { font-size: 20px; }
.prereq-card .prereq-label { font-size: 13px; font-weight: 600; }
.prereq-card .prereq-sub { font-size: 11px; color: var(--ink-muted); }

/* Index page animations */
.page-index .module {
  opacity: 0;
  animation: fadeUp 0.5s ease forwards;
}

.page-index .module:nth-child(1) { animation-delay: 0.05s; }
.page-index .module:nth-child(2) { animation-delay: 0.1s; }
.page-index .module:nth-child(3) { animation-delay: 0.15s; }
.page-index .module:nth-child(4) { animation-delay: 0.2s; }
.page-index .module:nth-child(5) { animation-delay: 0.25s; }
.page-index .module:nth-child(6) { animation-delay: 0.3s; }
.page-index .module:nth-child(7) { animation-delay: 0.35s; }
.page-index .module:nth-child(8) { animation-delay: 0.4s; }

.page-index .hero { animation: fadeUp 0.6s ease forwards; }


/* ═══════════════════════════════════════════════════════════════
   LECTURE PAGES — Article content, callouts, algorithms, proofs
   ═══════════════════════════════════════════════════════════════ */

/* ── Lecture header ── */
.lecture-header {
  padding: 80px 60px 48px;
  border-bottom: 1px solid var(--rule);
  max-width: 1200px;
  margin: 0 auto;
}

.lecture-header .lecture-eyebrow {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 12px;
  font-weight: 500;
}

.lecture-header h2 {
  font-family: var(--serif);
  font-size: 42px;
  font-weight: 400;
  line-height: 1.2;
  color: var(--ink);
  margin-bottom: 12px;
}

.lecture-header .lecture-desc {
  font-size: 18px;
  color: var(--ink-light);
  line-height: 1.7;
  max-width: 640px;
}

.lecture-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 20px;
}

.lecture-tag {
  display: inline-block;
  padding: 4px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-family: var(--mono);
  font-weight: 500;
  background: var(--accent-light);
  color: var(--accent);
  border: 1px solid var(--accent-border);
}

.lecture-pdf-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 16px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-family: var(--mono);
  color: var(--ink-light);
  background: white;
  border: 1px solid var(--rule);
  text-decoration: none;
  transition: all 0.2s;
}

.lecture-pdf-link:hover {
  border-color: var(--accent-border);
  color: var(--accent);
}

.lecture-pdf-link svg {
  width: 14px;
  height: 14px;
}

/* ── Article ── */
.lecture-article {
  padding: 48px 60px 80px;
  max-width: 1200px;
  margin: 0 auto;
}

.lecture-article h2 {
  font-family: var(--serif);
  font-size: 32px;
  font-weight: 400;
  color: var(--ink);
  margin-top: 56px;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--rule-strong);
  scroll-margin-top: 24px;
}

.lecture-article h3 {
  font-family: var(--serif);
  font-size: 24px;
  font-weight: 400;
  color: var(--ink);
  margin-top: 40px;
  margin-bottom: 16px;
  scroll-margin-top: 24px;
}

.lecture-article h4 {
  font-family: var(--sans);
  font-size: 18px;
  font-weight: 600;
  color: var(--ink);
  margin-top: 28px;
  margin-bottom: 12px;
}

.lecture-article p {
  font-size: 17px;
  line-height: 1.8;
  color: var(--ink-light);
  margin-bottom: 16px;
}

.lecture-article ul,
.lecture-article ol {
  padding-left: 24px;
  margin-bottom: 16px;
}

.lecture-article li {
  font-size: 17px;
  line-height: 1.7;
  color: var(--ink-light);
  margin-bottom: 8px;
}

.lecture-article strong {
  color: var(--ink);
  font-weight: 600;
}

.lecture-article a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: var(--accent-border);
  text-underline-offset: 2px;
  transition: text-decoration-color 0.2s;
}

.lecture-article a:hover {
  text-decoration-color: var(--accent);
}

/* ── Callout boxes ── */
.callout {
  border-radius: 12px;
  padding: 24px 28px;
  margin: 24px 0;
  border-left: 4px solid;
}

.callout-label {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.callout p {
  margin-bottom: 8px;
}

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

/* Definition callout */
.callout.definition {
  background: rgba(37, 99, 235, 0.04);
  border-color: var(--blue);
}

.callout.definition .callout-label {
  color: var(--blue);
}

/* Theorem callout */
.callout.theorem {
  background: rgba(124, 58, 237, 0.04);
  border-color: var(--purple);
}

.callout.theorem .callout-label {
  color: var(--purple);
}

/* Example callout */
.callout.example {
  background: rgba(217, 119, 6, 0.04);
  border-color: var(--amber);
}

.callout.example .callout-label {
  color: var(--amber);
}

/* Insight callout */
.callout.insight {
  background: rgba(22, 163, 74, 0.04);
  border-color: var(--green);
}

.callout.insight .callout-label {
  color: var(--green);
}

/* Note callout */
.callout.note {
  background: rgba(100, 116, 139, 0.04);
  border-color: #64748b;
}

.callout.note .callout-label {
  color: #64748b;
}

/* ── Algorithm blocks ── */
.algorithm {
  background: white;
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: 24px 28px;
  margin: 24px 0;
  overflow-x: auto;
}

.algorithm-title {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 500;
  color: var(--accent);
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--rule);
}

.algorithm ol,
.algorithm ul {
  padding-left: 20px;
  margin-bottom: 0;
}

.algorithm li {
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.8;
  color: var(--ink-light);
  margin-bottom: 4px;
}

.algorithm .keyword {
  font-family: var(--mono);
  font-weight: 500;
  color: var(--accent);
  font-size: 14px;
}

.algorithm .comment {
  color: var(--ink-muted);
  font-style: italic;
  font-size: 14px;
}

/* ── Proof (collapsible) ── */
.proof {
  margin: 20px 0;
  border: 1px solid var(--rule);
  border-radius: 10px;
  overflow: hidden;
}

.proof summary {
  padding: 14px 20px;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-muted);
  cursor: pointer;
  background: rgba(255,255,255,0.5);
  transition: all 0.2s;
  list-style: none;
}

.proof summary::-webkit-details-marker { display: none; }

.proof summary::before {
  content: '▸';
  display: inline-block;
  margin-right: 8px;
  transition: transform 0.2s;
  color: var(--accent);
}

.proof[open] summary::before {
  transform: rotate(90deg);
}

.proof summary:hover {
  background: rgba(255,255,255,0.8);
  color: var(--ink-light);
}

.proof .proof-content {
  padding: 20px 24px;
  border-top: 1px solid var(--rule);
  font-size: 16px;
  line-height: 1.75;
  color: var(--ink-light);
}

.proof .proof-content p {
  font-size: 16px;
  margin-bottom: 12px;
}

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

/* ── Display math overflow ── */
.katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 4px 0;
}

/* ── Prev/Next footer nav ── */
.lecture-nav {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 32px 60px;
  border-top: 1px solid var(--rule);
  max-width: 1200px;
  margin: 0 auto;
}

.lecture-nav a {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 24px;
  border-radius: 10px;
  background: white;
  border: 1px solid var(--rule);
  text-decoration: none;
  transition: all 0.25s;
  min-width: 180px;
}

.lecture-nav a:hover {
  border-color: var(--accent-border);
  box-shadow: 0 4px 16px rgba(180, 74, 45, 0.08);
  transform: translateY(-1px);
}

.lecture-nav a .nav-dir {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.lecture-nav a .nav-title {
  font-family: var(--serif);
  font-size: 18px;
  color: var(--ink);
}

.lecture-nav .next {
  text-align: right;
  margin-left: auto;
}

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 960px) {
  .module-body {
    grid-template-columns: 1fr;
    gap: 24px;
  }
  .prereqs-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .menu-toggle { display: flex; }
  .menu-overlay.open { display: block; opacity: 1; }

  .main { margin-left: 0; }
  .progress-bar { left: 0; }

  .hero { padding: 80px 24px 40px; }
  .hero h2 { font-size: 32px; }
  .content { padding: 0 24px 60px; }

  .hero-stats { gap: 24px; }
  .prereqs-grid { grid-template-columns: 1fr; }

  /* Lecture pages responsive */
  .lecture-header { padding: 80px 24px 36px; }
  .lecture-header h2 { font-size: 28px; }
  .lecture-article { padding: 32px 24px 60px; }
  .lecture-article h2 { font-size: 26px; }
  .lecture-article h3 { font-size: 20px; }
  .lecture-nav { padding: 24px; flex-direction: column; }
  .lecture-nav a { min-width: unset; }
  .lecture-nav .next { text-align: left; }

  .callout { padding: 18px 20px; }
  .algorithm { padding: 18px 20px; }
}
