/* ===== CSS Variables ===== */
:root {
  --bg: #0f1419;
  --bg-elevated: #1a2332;
  --bg-card: #1e2a3a;
  --border: #2d3a4f;
  --text: #e8edf5;
  --text-muted: #8b9bb4;
  --text-dim: #5c6b82;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-soft: rgba(59, 130, 246, 0.15);
  --success: #22c55e;
  --success-soft: rgba(34, 197, 94, 0.15);
  --warning: #f59e0b;
  --danger: #ef4444;
  --orange: #f97316;
  --sidebar-width: 300px;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 4px 20px rgba(0,0,0,0.3);
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}

[data-theme="light"] {
  --bg: #f4f6f9;
  --bg-elevated: #ffffff;
  --bg-card: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --text-dim: #94a3b8;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: rgba(37, 99, 235, 0.1);
  --success: #16a34a;
  --success-soft: rgba(22, 163, 74, 0.1);
  --shadow: 0 4px 20px rgba(0,0,0,0.08);
}

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

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }

/* ===== App Layout ===== */
.app {
  display: flex;
  min-height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: transform 0.25s ease;
}

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

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}

.logo-text { display: flex; flex-direction: column; }
.logo-title { font-weight: 700; font-size: 0.95rem; letter-spacing: -0.01em; }
.logo-sub { font-size: 0.7rem; color: var(--text-muted); }

.sidebar-close {
  display: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: 6px;
}
.sidebar-close:hover { background: var(--accent-soft); color: var(--accent); }

.nav {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0.75rem;
}

.nav-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  padding: 0 0.75rem 0.5rem;
}

.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0.75rem;
  border-radius: var(--radius-sm);
  text-align: left;
  transition: background 0.15s, color 0.15s;
  margin-bottom: 2px;
}

.nav-item:hover { background: var(--accent-soft); }
.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 500;
}

.nav-num {
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-dim);
  min-width: 1.5rem;
}
.nav-item.active .nav-num { color: var(--accent); }

.nav-title { flex: 1; font-size: 0.875rem; }

.nav-check {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-radius: 50%;
  flex-shrink: 0;
  position: relative;
}
.nav-item.completed .nav-check {
  background: var(--success);
  border-color: var(--success);
}
.nav-item.completed .nav-check::after {
  content: "✓";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 0.65rem;
  font-weight: 700;
}

.sidebar-footer {
  padding: 1rem 1.25rem 1.25rem;
  border-top: 1px solid var(--border);
}

.progress-box { margin-bottom: 0.75rem; }
.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}
.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #60a5fa);
  border-radius: 3px;
  width: 0%;
  transition: width 0.4s ease;
}

.btn-reset {
  width: 100%;
  padding: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: all 0.15s;
}
.btn-reset:hover { border-color: var(--danger); color: var(--danger); }

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  padding: 0.85rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.menu-toggle {
  display: none;
  flex-direction: column;
  gap: 5px;
  padding: 4px;
}
.menu-toggle span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text);
  border-radius: 1px;
}

.topbar-title {
  font-weight: 600;
  font-size: 0.95rem;
  flex: 1;
}

.btn-theme {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  color: var(--text-muted);
  transition: all 0.15s;
}
.btn-theme:hover { background: var(--accent-soft); color: var(--accent); }

.content {
  flex: 1;
  padding: 2rem 2.5rem 3rem;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
}

/* ===== Module Content Styles ===== */
.module-header {
  margin-bottom: 2.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.module-number {
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--accent);
  margin-bottom: 0.5rem;
  letter-spacing: 0.04em;
}

.module-title {
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
  margin-bottom: 0.75rem;
}

.module-intro {
  color: var(--text-muted);
  font-size: 1.05rem;
  line-height: 1.65;
}

.objectives {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 2.5rem;
}

.objectives h3 {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.objectives ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.objectives li {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  font-size: 0.95rem;
}

.objectives li::before {
  content: "→";
  color: var(--accent);
  font-weight: 600;
  flex-shrink: 0;
}

/* Content sections */
.section {
  margin-bottom: 2.75rem;
}

.section h2 {
  font-size: 1.35rem;
  font-weight: 650;
  margin-bottom: 1rem;
  letter-spacing: -0.015em;
  color: var(--text);
}

.section h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 1.5rem 0 0.75rem;
}

.section p {
  margin-bottom: 1rem;
  color: var(--text);
  line-height: 1.7;
}

.section ul, .section ol {
  margin: 0.75rem 0 1.25rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.section li {
  line-height: 1.6;
}

.section strong { font-weight: 600; color: var(--text); }

/* Callout boxes */
.callout {
  border-radius: var(--radius);
  padding: 1.1rem 1.35rem;
  margin: 1.5rem 0;
  border-left: 4px solid;
}

.callout-info {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.callout-warning {
  background: rgba(245, 158, 11, 0.12);
  border-color: var(--warning);
}

.callout-danger {
  background: rgba(239, 68, 68, 0.1);
  border-color: var(--danger);
}

.callout-success {
  background: var(--success-soft);
  border-color: var(--success);
}

.callout-title {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
}

.callout p { margin-bottom: 0; font-size: 0.95rem; }

/* Diagrams */
.diagram {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin: 1.75rem 0;
  overflow-x: auto;
}

.diagram-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 1rem;
  text-align: center;
}

.diagram svg {
  display: block;
  margin: 0 auto;
  max-width: 100%;
}

.diagram-caption {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 1rem;
}

/* Code / mono blocks */
.mono-block {
  font-family: var(--mono);
  font-size: 0.85rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem;
  overflow-x: auto;
  line-height: 1.55;
  margin: 1.25rem 0;
  white-space: pre;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
  margin: 1.5rem 0;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  background: var(--bg);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
}

tr:last-child td { border-bottom: none; }

/* Key takeaways */
.takeaways {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin: 2rem 0;
}

.takeaways h3 {
  font-size: 1rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.takeaways ul {
  list-style: none;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.takeaways li {
  padding-left: 1.4rem;
  position: relative;
  line-height: 1.55;
}

.takeaways li::before {
  content: "▸";
  position: absolute;
  left: 0;
  color: var(--accent);
  font-weight: 700;
}

/* Review questions */
.review {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-top: 2.5rem;
}

.review h3 {
  font-size: 1.1rem;
  margin-bottom: 1.25rem;
}

.question {
  margin-bottom: 1.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}
.question:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.question-text {
  font-weight: 500;
  margin-bottom: 0.75rem;
}

.question-options {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.option {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.15s;
  font-size: 0.9rem;
}

.option:hover { border-color: var(--accent); background: var(--accent-soft); }
.option.selected { border-color: var(--accent); background: var(--accent-soft); }
.option.correct { border-color: var(--success); background: var(--success-soft); }
.option.incorrect { border-color: var(--danger); background: rgba(239,68,68,0.1); }

.option input { accent-color: var(--accent); }

.feedback {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  display: none;
}
.feedback.show { display: block; }
.feedback.correct { color: var(--success); }
.feedback.incorrect { color: var(--danger); }

/* Footer nav */
.module-nav {
  position: sticky;
  bottom: 0;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  padding: 0.9rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.btn-nav {
  padding: 0.6rem 1.15rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  transition: all 0.15s;
}
.btn-nav:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}
.btn-nav:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-complete {
  padding: 0.65rem 1.4rem;
  background: var(--accent);
  color: white;
  font-weight: 600;
  font-size: 0.9rem;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}
.btn-complete:hover { background: var(--accent-hover); }
.btn-complete.completed {
  background: var(--success);
}
.btn-complete.completed:hover { background: #16a34a; }

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-close { display: flex; align-items: center; justify-content: center; }
  .main { margin-left: 0; }
  .menu-toggle { display: flex; }
  .content { padding: 1.5rem 1.25rem 2.5rem; }
  .module-title { font-size: 1.5rem; }
}

@media (max-width: 500px) {
  .module-nav { flex-wrap: wrap; }
  .btn-complete { order: -1; width: 100%; }
}

/* Overlay for mobile */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 90;
}
.overlay.show { display: block; }

/* Utility */
.mt-1 { margin-top: 0.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.text-muted { color: var(--text-muted); }
.text-accent { color: var(--accent); }
.font-mono { font-family: var(--mono); }
