/* ============================================
   DE Course — Shared Stylesheet
   ============================================ */

/* --- CSS Variables --- */
:root {
  --primary: #2563eb;
  --primary-light: #dbeafe;
  --primary-dark: #1e40af;
  --accent: #7c3aed;
  --accent-light: #ede9fe;
  --success: #059669;
  --success-light: #d1fae5;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --radius: 12px;
  --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

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

/* --- Base Typography --- */
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
}

p {
  margin-bottom: 1rem;
  line-height: 1.8;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color 0.3s;
}

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

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

ol, ul {
  margin-left: 2rem;
  margin-bottom: 1rem;
}

li {
  margin-bottom: 0.5rem;
}

/* --- Navigation (logo-div pattern: majority of pages) --- */
nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  z-index: 1000;
  box-shadow: var(--shadow);
}

.logo {
  font-weight: bold;
  font-size: 1.2rem;
  margin-right: auto;
}

.logo a {
  color: var(--primary);
  text-decoration: none;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  overflow-x: auto;
  white-space: nowrap;
  flex-wrap: wrap;
}

nav a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.95rem;
  transition: color 0.3s;
}

nav a:hover,
nav a.active {
  color: var(--primary);
  font-weight: 600;
}

/* Navigation: brand pattern (index, exam-generator, videos) */
nav .brand {
  font-weight: 800;
  color: var(--primary);
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}

/* --- Layout --- */
.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 80px 1.5rem 4rem;
}

/* --- Sections --- */
section {
  margin: 3rem 0;
  scroll-margin-top: 5rem;
}

section h1, h1 {
  color: var(--primary);
  font-size: 2.2rem;
  margin-bottom: 0.5rem;
}

section h2, h2 {
  color: var(--accent);
  font-size: 1.6rem;
  margin-top: 1.5rem;
  margin-bottom: 1rem;
  border-bottom: 2px solid var(--accent-light);
  padding-bottom: 0.5rem;
}

section h3, h3 {
  color: var(--text);
  font-size: 1.2rem;
  margin-top: 1.2rem;
  margin-bottom: 0.8rem;
}

.subtitle {
  color: var(--text-muted);
  font-size: 1.1rem;
  margin-bottom: 1rem;
  font-style: italic;
}

/* --- Content Boxes (border-left style) --- */
.definition-box,
.theorem-box,
.example-box,
.warning-box,
.tip-box {
  border-left: 5px solid;
  padding: 1.5rem;
  margin: 1.5rem 0;
  border-radius: var(--radius);
  background: var(--card);
}

.definition-box {
  border-left-color: var(--primary);
  background: var(--primary-light);
}

.theorem-box {
  border-left-color: var(--accent);
  background: var(--accent-light);
}

.example-box {
  border-left-color: #3b82f6;
  background: #eff6ff;
}

.warning-box {
  border-left-color: var(--warning);
  background: var(--warning-light);
}

.tip-box {
  border-left-color: var(--success);
  background: var(--success-light);
}

.definition-box h3,
.theorem-box h3,
.example-box h3,
.warning-box h3,
.tip-box h3 {
  margin-top: 0;
}

/* --- Content Boxes (colored-border style, used by ch5 and others) --- */
.box-primary {
  background: var(--primary-light);
  border-left: 4px solid var(--primary);
  padding: 1.5rem;
  border-radius: var(--radius);
  margin: 1.5rem 0;
}

.box-accent {
  background: var(--accent-light);
  border-left: 4px solid var(--accent);
  padding: 1.5rem;
  border-radius: var(--radius);
  margin: 1.5rem 0;
}

.box-success {
  background: var(--success-light);
  border-left: 4px solid var(--success);
  padding: 1.5rem;
  border-radius: var(--radius);
  margin: 1.5rem 0;
}

.box-warning {
  background: var(--warning-light);
  border-left: 4px solid var(--warning);
  padding: 1.5rem;
  border-radius: var(--radius);
  margin: 1.5rem 0;
}

.box-danger {
  background: var(--danger-light);
  border-left: 4px solid var(--danger);
  padding: 1.5rem;
  border-radius: var(--radius);
  margin: 1.5rem 0;
}

.box-label {
  font-weight: bold;
  color: var(--primary);
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  font-size: 0.85rem;
  letter-spacing: 0.05em;
}

/* --- Math Display --- */
.math-display {
  overflow-x: auto;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.02);
  border-radius: var(--radius);
  margin: 1rem 0;
  text-align: center;
}

.katex-display {
  overflow-x: auto;
  padding: 1rem;
  margin: 1.5rem 0 !important;
}

.highlight {
  background: #fef08a;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
}

/* --- Quote Styles --- */
.historical-quote {
  border-left: 5px solid var(--warning);
  padding: 1.5rem;
  margin: 2rem 0;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #fef3c7, #fcd34d);
  font-style: italic;
  font-size: 1.1rem;
}

.islamic-verse {
  border-left: 5px solid var(--success);
  padding: 1.5rem;
  margin: 2rem 0;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #d1fae5, #a7f3d0);
  text-align: right;
  font-size: 1.05rem;
}

.islamic-verse .arabic {
  font-size: 1.3rem;
  color: var(--text);
  margin-bottom: 0.5rem;
  font-weight: 500;
}

.islamic-verse .translation {
  font-style: italic;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

/* --- Collapsible Sections --- */
.collapsible {
  margin: 1rem 0;
}

/* Blue outlined toggle (used by many chapter pages) */
.collapsible-toggle {
  width: 100%;
  padding: 1rem;
  background: var(--primary-light);
  border: 2px solid var(--primary);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  font-size: 1rem;
  font-weight: 600;
  color: var(--primary);
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: all 0.3s;
}

.collapsible-toggle:hover {
  background: var(--primary);
  color: white;
}

/* White card-style toggle (used by ch3-inverse worked examples) */
.collapsible-header {
  background-color: var(--card);
  color: var(--text);
  cursor: pointer;
  padding: 1rem 1.5rem;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: left;
  font-size: 1rem;
  font-weight: 600;
  margin: 0.5rem 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: all 0.3s;
}

.collapsible-header:hover {
  background-color: var(--primary-light);
  border-color: var(--primary);
}

.collapsible-header.active {
  background-color: var(--primary);
  color: white;
  border-color: var(--primary);
}

.collapsible-arrow {
  display: inline-block;
  margin-left: 1rem;
  transition: transform 0.3s;
  font-size: 1.2rem;
}

.collapsible-header.active .collapsible-arrow {
  transform: rotate(180deg);
}

.arrow {
  display: inline-block;
  transition: transform 0.3s;
  font-size: 1.2rem;
}

.collapsible-toggle.active .arrow {
  transform: rotate(90deg);
}

.collapsible-content {
  display: none;
  background: var(--card);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
}

.collapsible-content.active {
  display: block;
  padding: 1.5rem;
}

.solution-step {
  margin: 1rem 0;
  padding: 0.75rem;
  background: rgba(37, 99, 235, 0.05);
  border-radius: 6px;
  font-family: 'Courier New', monospace;
}

/* Toggle button pattern (ch5 style) */
.toggle-btn {
  background: var(--primary);
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 1rem;
  transition: background 0.3s;
  width: 100%;
  text-align: left;
  font-weight: 600;
}

.toggle-btn:hover {
  background: var(--accent);
}

.toggle-btn.active {
  background: var(--accent);
}

.toggle-content {
  display: none;
  padding: 1.5rem;
  border: 1px solid var(--border);
  border-top: none;
  border-bottom-left-radius: var(--radius);
  border-bottom-right-radius: var(--radius);
  background: rgba(37, 99, 235, 0.02);
}

.toggle-content.active {
  display: block;
}

/* Practice problem toggle */
.example-header {
  background: linear-gradient(135deg, #7c3aed, #6d28d9);
  padding: 1rem;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: white;
  font-weight: 600;
  font-size: 1rem;
  transition: opacity 0.2s;
}

.example-header:hover {
  opacity: 0.92;
}

.example-item {
  margin-top: 1.5rem;
}

.example-content {
  display: none;
  padding: 0;
}

.example-content.active {
  display: block;
  padding: 1.5rem;
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 8px 8px;
  background: var(--card);
}

/* --- Step Lists --- */
.step-list {
  list-style: none;
  counter-reset: step-counter;
}

.step-list li {
  counter-increment: step-counter;
  margin-bottom: 1.2rem;
  padding-left: 3rem;
  position: relative;
}

.step-list li::before {
  content: counter(step-counter);
  position: absolute;
  left: 0;
  top: 0;
  background: var(--accent);
  color: white;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
}

/* --- Tables --- */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

thead {
  background: var(--primary);
  color: white;
}

th {
  background: var(--primary);
  color: white;
  padding: 1rem;
  text-align: left;
  font-weight: 600;
}

td {
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--border);
}

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

tbody tr:nth-child(even) {
  background: rgba(37, 99, 235, 0.03);
}

tbody tr:hover {
  background: rgba(37, 99, 235, 0.08);
}

/* --- Quiz Styles --- */
.quiz-question,
.quiz-problem {
  margin: 2rem 0;
  padding: 1.5rem;
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
}

.quiz-problem h4 {
  color: var(--primary);
  margin-bottom: 1rem;
}

.choice-btn {
  display: block;
  width: 100%;
  padding: 0.75rem 1rem;
  margin: 0.5rem 0;
  text-align: left;
  background: var(--primary-light);
  color: #1e293b;
  border: 2px solid var(--primary);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 1rem;
}

.choice-btn:hover {
  background: var(--primary);
  color: white;
}

.choice-btn.selected {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.choice-btn.correct {
  background: var(--success);
  color: white;
  border-color: var(--success);
}

.choice-btn.incorrect,
.choice-btn.selected-wrong {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}

.choice-btn.selected-correct {
  background: var(--success);
  color: white;
  border-color: var(--success);
}

.quiz-feedback {
  margin-top: 1rem;
  padding: 1rem;
  border-radius: 8px;
  display: none;
}

.quiz-feedback.show {
  display: block;
}

.quiz-feedback.correct {
  background: var(--success-light);
  color: var(--text);
  border-left: 4px solid var(--success);
}

.quiz-feedback.incorrect {
  background: var(--danger-light);
  color: var(--text);
  border-left: 4px solid var(--danger);
}

/* --- Progress Bar --- */
.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  margin: 1rem 0;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--success);
  transition: width 0.3s;
}

/* --- Visualizer Controls --- */
.visualizer-controls {
  display: flex;
  gap: 2rem;
  margin: 2rem 0;
  flex-wrap: wrap;
}

.control-group {
  flex: 1;
  min-width: 200px;
}

.control-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 600;
}

.control-group select,
.control-group input {
  width: 100%;
  padding: 0.5rem;
  border: 2px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
}

.plot-container {
  margin: 2rem 0;
  min-height: 300px;
}

.plots-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  margin: 2rem 0;
}

/* --- Footer --- */
footer {
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 3rem;
  border-top: 1px solid var(--border);
}

/* --- Responsive --- */
@media (max-width: 768px) {
  nav {
    flex-wrap: wrap;
    height: auto;
    padding: 0.75rem 1rem;
  }

  .nav-links {
    gap: 0.75rem;
    font-size: 0.85rem;
  }

  .container {
    padding: 70px 1rem 2rem;
  }

  h1, section h1 {
    font-size: 1.8rem;
  }

  h2, section h2 {
    font-size: 1.3rem;
  }

  section {
    padding: 1.5rem;
  }

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