/* =====================================================================
   Technieken in BIS — Course Viewer
   Apple-inspired design system
   ===================================================================== */

/* ─── Custom Properties ────────────────────────────────────────────── */

:root {
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Fira Mono', 'Menlo', 'Consolas', monospace;

  /* Light theme */
  --bg-primary: #ffffff;
  --bg-primary-rgb: 255, 255, 255;
  --bg-secondary: #f5f5f7;
  --bg-tertiary: #e8e8ed;
  --bg-elevated: #ffffff;
  --text-primary: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-tertiary: #86868b;
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --accent-subtle: rgba(0, 113, 227, 0.08);
  --border: #d2d2d7;
  --separator: rgba(60, 60, 67, 0.12);
  --header-bg: rgba(255, 255, 255, 0.72);
  --sidebar-bg: rgba(245, 245, 247, 0.92);
  --code-bg: #f5f5f7;
  --code-border: #e5e5ea;
  --table-stripe: #f9f9fb;
  --table-header: #f5f5f7;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 8px 28px rgba(0, 0, 0, 0.08);
  --btn-hover-bg: rgba(0, 0, 0, 0.05);

  --alert-note-bg: rgba(0, 113, 227, 0.06);
  --alert-note-border: #0071e3;
  --alert-note-text: #0055b3;
  --alert-tip-bg: rgba(52, 199, 89, 0.06);
  --alert-tip-border: #34c759;
  --alert-tip-text: #248a3d;
  --alert-important-bg: rgba(175, 82, 222, 0.06);
  --alert-important-border: #af52de;
  --alert-important-text: #8944ab;
  --alert-warning-bg: rgba(255, 149, 0, 0.06);
  --alert-warning-border: #ff9500;
  --alert-warning-text: #c93400;
  --alert-caution-bg: rgba(255, 59, 48, 0.06);
  --alert-caution-border: #ff3b30;
  --alert-caution-text: #d70015;

  --header-h: 56px;
  --sidebar-w: 272px;
  --content-max: 814px; /* Increased by 10% from 740px for more spacing */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --ease: cubic-bezier(0.25, 0.1, 0.25, 1);
}

[data-theme="dark"] {
  --bg-primary: #000000;
  --bg-primary-rgb: 0, 0, 0;
  --bg-secondary: #1c1c1e;
  --bg-tertiary: #2c2c2e;
  --bg-elevated: #1c1c1e;
  --text-primary: #f5f5f7;
  --text-secondary: #86868b;
  --text-tertiary: #6e6e73;
  --accent: #2997ff;
  --accent-hover: #40a9ff;
  --accent-subtle: rgba(41, 151, 255, 0.12);
  --border: #38383a;
  --separator: rgba(142, 142, 147, 0.2);
  --header-bg: rgba(0, 0, 0, 0.72);
  --sidebar-bg: rgba(28, 28, 30, 0.92);
  --code-bg: #1c1c1e;
  --code-border: #38383a;
  --table-stripe: #1c1c1e;
  --table-header: #2c2c2e;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 28px rgba(0, 0, 0, 0.4);
  --btn-hover-bg: rgba(255, 255, 255, 0.08);

  --alert-note-bg: rgba(41, 151, 255, 0.1);
  --alert-note-border: #2997ff;
  --alert-note-text: #64b5f6;
  --alert-tip-bg: rgba(48, 209, 88, 0.1);
  --alert-tip-border: #30d158;
  --alert-tip-text: #81c784;
  --alert-important-bg: rgba(191, 90, 242, 0.1);
  --alert-important-border: #bf5af2;
  --alert-important-text: #ce93d8;
  --alert-warning-bg: rgba(255, 159, 10, 0.1);
  --alert-warning-border: #ff9f0a;
  --alert-warning-text: #ffb74d;
  --alert-caution-bg: rgba(255, 69, 58, 0.1);
  --alert-caution-border: #ff453a;
  --alert-caution-text: #ef9a9a;
}

/* ─── Reset & Base ─────────────────────────────────────────────────── */

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

html {
  font-family: var(--font-sans);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
}

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  transition: background-color 0.3s var(--ease), color 0.3s var(--ease);
  min-height: 100vh;
  overflow-x: hidden;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
img { max-width: 100%; display: block; }

.hidden { display: none !important; }

/* ─── Header ───────────────────────────────────────────────────────── */

#header {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  height: 120px; /* Taller height for a smoother gradient fade */
  background: linear-gradient(to bottom, 
    rgb(var(--bg-primary-rgb)) 0%, 
    rgb(var(--bg-primary-rgb)) 35%, 
    rgba(var(--bg-primary-rgb), 0.75) 55%, 
    rgba(var(--bg-primary-rgb), 0.4) 75%, 
    rgba(var(--bg-primary-rgb), 0.15) 90%, 
    rgba(var(--bg-primary-rgb), 0) 100%
  );
  border-bottom: none;
  pointer-events: none; /* Allow scroll and click through the bottom transparent fade */
}

#header.scrolled {
  /* Header background is already handled by the gradient fade above */
}

.header-inner {
  max-width: 100%;
  height: var(--header-h); /* Center clickable elements within standard height */
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  pointer-events: auto; /* Enable clicks on buttons/links */
}

.header-left, .header-right { display: flex; align-items: center; gap: 8px; min-width: 120px; }
.header-right { justify-content: flex-end; }
.header-center { flex: 1; text-align: center; }

#header-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transform: translateY(6px) translateX(0);
  transition: opacity 0.2s var(--ease), transform 0.35s var(--ease); /* Match sidebar shift transition */
}

#header.scrolled #header-title {
  opacity: 1;
  transform: translateY(0) translateX(0);
}

/* Sidebar visible shift logic: only translate the title by 136px (half of 272px sidebar width) */
body.sidebar-visible #header-title {
  transform: translateY(6px) translateX(136px);
}

body.sidebar-visible #header.scrolled #header-title {
  opacity: 1;
  transform: translateY(0) translateX(136px);
}

@media (max-width: 1024px) {
  body.sidebar-visible #header-title {
    transform: translateY(6px) translateX(0) !important;
  }
  body.sidebar-visible #header.scrolled #header-title {
    transform: translateY(0) translateX(0) !important;
  }
}

.header-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  transition: opacity 0.15s var(--ease), background-color 0.15s var(--ease), color 0.15s var(--ease), transform 0.15s var(--ease);
  cursor: pointer;
  border: none;
  background: none;
  -webkit-tap-highlight-color: transparent;
}

/* Text buttons: Back button */
#back-btn {
  gap: 4px;
  padding: 6px 8px;
  font-size: 15px;
  font-weight: 400;
  border-radius: var(--r-sm);
}

#back-btn:hover {
  opacity: 0.7;
}

#back-btn:active {
  opacity: 0.45;
}

#back-btn span {
  font-size: 15px;
}

/* Icon-only buttons: Sidebar Toggles and Sidebar Open Button */
#sidebar-toggle, #sidebar-open-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: var(--text-secondary);
}

#sidebar-toggle:hover, #sidebar-open-btn:hover {
  background-color: var(--btn-hover-bg);
  color: var(--text-primary);
}

#sidebar-toggle:active, #sidebar-open-btn:active {
  transform: scale(0.96);
}


/* ─── Home View ────────────────────────────────────────────────────── */

#home-view {
  padding-top: calc(var(--header-h) + 48px);
  padding-bottom: 80px;
  min-height: 100vh;
}

.home-container {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 24px;
}

.home-header {
  margin-bottom: 40px;
}

.home-header h1 {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.15;
  color: var(--text-primary);
}

.home-header p {
  font-size: 17px;
  color: var(--text-secondary);
  margin-top: 6px;
  font-weight: 400;
}

/* ─── Lesson List (Home) ───────────────────────────────────────────── */

.lesson-list {
  display: flex;
  flex-direction: column;
}

.lesson-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 0;
  border: none;
  border-bottom: 1px solid var(--separator);
  background-color: transparent;
  transition: border-color 0.15s var(--ease);
  cursor: pointer;
  text-decoration: none;
}

.lesson-item:last-child {
  border-bottom: none;
}

.lesson-item-number {
  width: 28px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-tertiary);
  flex-shrink: 0;
  text-align: left;
}

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

.lesson-item-title {
  font-size: 16px;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.15s var(--ease);
}

.lesson-item:hover .lesson-item-title {
  color: var(--accent);
}

.lesson-item-desc {
  font-size: 13.5px;
  color: var(--text-secondary);
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lesson-item-arrow {
  display: none;
}

/* ─── Lesson View Layout ───────────────────────────────────────────── */

#lesson-view {
  display: flex;
  min-height: 100vh;
}

/* ─── Sidebar ──────────────────────────────────────────────────────── */

#sidebar {
  position: fixed;
  top: 16px;
  left: 16px;
  bottom: 16px;
  width: 240px; /* Offset: 16px left + 240px width + 16px right gap = 272px space */
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 20px;
  z-index: 105;
  display: flex;
  flex-direction: column;
  overflow: hidden; /* Lock header & footer, scroll nav only */
  transition: transform 0.35s var(--ease), opacity 0.35s var(--ease), border-color 0.3s;
  -webkit-overflow-scrolling: touch;
}

[data-theme="dark"] #sidebar {
  border: 1px solid var(--border);
}

#sidebar.collapsed { 
  transform: translateX(-280px); /* Fully push out of view */
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px 6px 0px; /* Align with sidebar content */
  flex-shrink: 0;
}

.sidebar-header {
  padding: 0 0 0 20px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  margin: 0;
}

#sidebar-toggle {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: none;
  background: none;
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease), transform 0.15s var(--ease);
}

#sidebar-toggle:hover {
  background-color: var(--btn-hover-bg);
  color: var(--text-primary);
}

#sidebar-toggle:active {
  transform: scale(0.95);
}

#sidebar-nav {
  display: flex;
  flex-direction: column;
  padding: 8px;
  flex: 1;
  overflow-y: auto;
  mask-image: linear-gradient(to bottom, transparent, black 16px, black calc(100% - 16px), transparent);
  -webkit-mask-image: linear-gradient(to bottom, transparent, black 16px, black calc(100% - 16px), transparent);
}

#sidebar-nav::-webkit-scrollbar {
  width: 0;
}

.sidebar-footer {
  padding: 12px;
  background: var(--bg-secondary);
  flex-shrink: 0;
}

.footer-buttons {
  display: flex;
  gap: 8px;
  width: 100%;
}

#sidebar .sidebar-footer #back-btn,
#sidebar .sidebar-footer #print-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 500;
  color: var(--accent);
  background-color: var(--bg-primary);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease), transform 0.15s var(--ease);
  cursor: pointer;
}

#sidebar .sidebar-footer #back-btn:hover,
#sidebar .sidebar-footer #print-btn:hover {
  background-color: var(--btn-hover-bg);
}

#sidebar .sidebar-footer #back-btn:active,
#sidebar .sidebar-footer #print-btn:active {
  transform: scale(0.97);
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 400;
  color: var(--text-secondary);
  border-radius: 12px;
  margin-bottom: 3px;
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease), transform 0.15s var(--ease);
  cursor: pointer;
  text-decoration: none;
}

.sidebar-item:hover { 
  background-color: rgba(0, 0, 0, 0.04); 
  color: var(--text-primary); 
}

[data-theme="dark"] .sidebar-item:hover {
  background-color: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

.sidebar-item.active {
  color: var(--accent);
  font-weight: 500;
  background-color: var(--accent-subtle);
  border: none;
}

[data-theme="dark"] .sidebar-item.active {
  background-color: var(--accent-subtle);
  color: var(--accent);
  border: none;
}

.sidebar-item-number {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.04);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
  color: var(--text-secondary);
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}

[data-theme="dark"] .sidebar-item-number {
  background: rgba(255, 255, 255, 0.08);
}

.sidebar-item.active .sidebar-item-number {
  background: rgba(0, 113, 227, 0.1);
  color: var(--accent);
}

[data-theme="dark"] .sidebar-item.active .sidebar-item-number {
  background: rgba(41, 151, 255, 0.15);
  color: var(--accent);
}

.sidebar-item-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#sidebar-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.3);
  opacity: 0;
  transition: opacity 0.3s var(--ease);
  pointer-events: none;
}

#sidebar-overlay.visible { opacity: 1; pointer-events: auto; }

/* ─── Lesson Content Wrapper ───────────────────────────────────────── */

#lesson-content-wrapper {
  flex: 1;
  margin-left: var(--sidebar-w);
  overflow-y: auto;
  height: 100vh;
  transition: margin-left 0.35s var(--ease);
  mask-image: linear-gradient(to bottom, black calc(100% - 48px), transparent);
  -webkit-mask-image: linear-gradient(to bottom, black calc(100% - 48px), transparent);
}

#lesson-content-wrapper.expanded { margin-left: 0; }

#lesson-content {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: calc(var(--header-h) + 40px) 32px 120px;
}

/* ─── Markdown Typography ──────────────────────────────────────────── */

#lesson-content h1 {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.2;
  color: var(--text-primary);
  margin-bottom: 8px;
}

#lesson-content h2 {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.25;
  color: var(--text-primary);
  margin-top: 56px;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 0.5px solid var(--separator);
}

#lesson-content h3 {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.3;
  color: var(--text-primary);
  margin-top: 36px;
  margin-bottom: 12px;
}

#lesson-content h4 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.35;
  color: var(--text-primary);
  margin-top: 28px;
  margin-bottom: 8px;
}

#lesson-content p {
  font-size: 16px;
  line-height: 1.7;
  color: var(--text-primary);
  margin-bottom: 16px;
}

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

#lesson-content a {
  color: var(--accent);
  text-decoration: none;
  transition: opacity 0.15s;
}
#lesson-content a:hover { text-decoration: underline; opacity: 0.85; }

#lesson-content hr {
  border: none;
  height: 0.5px;
  background: var(--separator);
  margin: 40px 0;
}

/* Lists */
#lesson-content ul, #lesson-content ol {
  margin-bottom: 16px;
  padding-left: 24px;
}

#lesson-content li {
  font-size: 16px;
  line-height: 1.7;
  margin-bottom: 6px;
  color: var(--text-primary);
}

#lesson-content li > ul, #lesson-content li > ol { margin-top: 6px; margin-bottom: 6px; }

/* Inline code */
#lesson-content code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--code-bg);
  border: 0.5px solid var(--code-border);
  border-radius: 5px;
  padding: 2px 6px;
  transition: background 0.2s, border-color 0.2s;
}

/* Code blocks */
#lesson-content pre {
  background: var(--code-bg);
  border: 0.5px solid var(--code-border);
  border-radius: var(--r-md);
  padding: 18px 20px;
  overflow-x: auto;
  margin-bottom: 20px;
  -webkit-overflow-scrolling: touch;
}

#lesson-content pre code {
  background: none;
  border: none;
  padding: 0;
  border-radius: 0;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-primary);
}

/* Blockquotes (non-alert) */
#lesson-content blockquote {
  border-left: 3px solid var(--border);
  padding: 4px 0 4px 20px;
  margin: 16px 0;
  color: var(--text-secondary);
}

#lesson-content blockquote p { color: var(--text-secondary); }

/* ─── Tables ───────────────────────────────────────────────────────── */

.table-wrapper {
  overflow-x: auto;
  margin: 20px 0;
  border: 0.5px solid var(--code-border);
  border-radius: var(--r-md);
  -webkit-overflow-scrolling: touch;
}

#lesson-content table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  line-height: 1.6;
}

#lesson-content thead th {
  background: var(--table-header);
  font-weight: 600;
  font-size: 13px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-primary);
  text-align: left;
  padding: 10px 14px;
  border-bottom: 0.5px solid var(--code-border);
  white-space: nowrap;
}

#lesson-content tbody td {
  padding: 10px 14px;
  border-bottom: 0.5px solid var(--separator);
  color: var(--text-primary);
  vertical-align: top;
}

#lesson-content tbody tr:last-child td { border-bottom: none; }
#lesson-content tbody tr:nth-child(even) { background: var(--table-stripe); }

/* ─── Alerts ───────────────────────────────────────────────────────── */

#lesson-content blockquote.alert,
.alert {
  border: 1px solid;
  border-left: 1px solid; /* Explicitly override the blockquote border-left */
  border-radius: var(--r-md);
  padding: 18px 20px;
  margin: 24px 0;
  font-style: normal;
}

#lesson-content blockquote.alert p,
.alert p {
  color: var(--text-primary) !important;
  margin-bottom: 8px;
  font-size: 15px;
  line-height: 1.6;
}
#lesson-content blockquote.alert p:last-child,
.alert p:last-child {
  margin-bottom: 0;
}

#lesson-content blockquote.alert .alert-title,
.alert .alert-title {
  font-weight: 600;
  font-size: 12px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

#lesson-content blockquote.alert-note,
.alert-note {
  background: var(--alert-note-bg);
  border-color: rgba(0, 113, 227, 0.18);
}
#lesson-content blockquote.alert-note .alert-title,
.alert-note .alert-title {
  color: #0071e3;
}

#lesson-content blockquote.alert-tip,
.alert-tip {
  background: var(--alert-tip-bg);
  border-color: rgba(52, 199, 89, 0.18);
}
#lesson-content blockquote.alert-tip .alert-title,
.alert-tip .alert-title {
  color: #1d8a3a;
}

#lesson-content blockquote.alert-important,
.alert-important {
  background: var(--alert-important-bg);
  border-color: rgba(175, 82, 222, 0.18);
}
#lesson-content blockquote.alert-important .alert-title,
.alert-important .alert-title {
  color: #af52de;
}

#lesson-content blockquote.alert-warning,
.alert-warning {
  background: var(--alert-warning-bg);
  border-color: rgba(255, 149, 0, 0.18);
}
#lesson-content blockquote.alert-warning .alert-title,
.alert-warning .alert-title {
  color: #d77a00;
}

#lesson-content blockquote.alert-caution,
.alert-caution {
  background: var(--alert-caution-bg);
  border-color: rgba(255, 59, 48, 0.18);
}
#lesson-content blockquote.alert-caution .alert-title,
.alert-caution .alert-title {
  color: #ff3b30;
}

/* Dark mode overrides for alerts */
[data-theme="dark"] #lesson-content blockquote.alert-note,
[data-theme="dark"] .alert-note {
  border-color: rgba(41, 151, 255, 0.25);
}
[data-theme="dark"] #lesson-content blockquote.alert-note .alert-title,
[data-theme="dark"] .alert-note .alert-title {
  color: #2997ff;
}

[data-theme="dark"] #lesson-content blockquote.alert-tip,
[data-theme="dark"] .alert-tip {
  border-color: rgba(48, 209, 88, 0.25);
}
[data-theme="dark"] #lesson-content blockquote.alert-tip .alert-title,
[data-theme="dark"] .alert-tip .alert-title {
  color: #30d158;
}

[data-theme="dark"] #lesson-content blockquote.alert-important,
[data-theme="dark"] .alert-important {
  border-color: rgba(191, 90, 242, 0.25);
}
[data-theme="dark"] #lesson-content blockquote.alert-important .alert-title,
[data-theme="dark"] .alert-important .alert-title {
  color: #bf5af2;
}

[data-theme="dark"] #lesson-content blockquote.alert-warning,
[data-theme="dark"] .alert-warning {
  border-color: rgba(255, 159, 10, 0.25);
}
[data-theme="dark"] #lesson-content blockquote.alert-warning .alert-title,
[data-theme="dark"] .alert-warning .alert-title {
  color: #ff9f0a;
}

[data-theme="dark"] #lesson-content blockquote.alert-caution,
[data-theme="dark"] .alert-caution {
  border-color: rgba(255, 69, 58, 0.25);
}
[data-theme="dark"] #lesson-content blockquote.alert-caution .alert-title,
[data-theme="dark"] .alert-caution .alert-title {
  color: #ff453a;
}



/* ─── Mermaid Diagrams ─────────────────────────────────────────────── */

.mermaid-container {
  margin: 24px 0;
  padding: 24px;
  background: var(--bg-secondary);
  border: 0.5px solid var(--code-border);
  border-radius: var(--r-md);
  overflow-x: auto;
  text-align: center;
}

.mermaid-container svg { max-width: 100%; height: auto; }

.mermaid-error {
  color: var(--alert-caution-text);
  font-family: var(--font-mono);
  font-size: 13px;
  text-align: left;
}

/* ─── KaTeX overrides ──────────────────────────────────────────────── */

.katex-display { overflow-x: auto; overflow-y: hidden; padding: 8px 0; }
.katex { font-size: 1.05em; color: var(--text-primary); }

/* ─── Custom Scrollbar ─────────────────────────────────────────────── */

#lesson-content-wrapper::-webkit-scrollbar { width: 6px; }
#lesson-content-wrapper::-webkit-scrollbar-track { background: transparent; }
#lesson-content-wrapper::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
#lesson-content-wrapper::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }

/* ─── Loading state ────────────────────────────────────────────────── */

.loading-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 80px 0;
  color: var(--text-tertiary);
  font-size: 15px;
}

/* ─── Fade-in Animation ────────────────────────────────────────────── */

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

#home-view .lesson-item {
  animation: fadeIn 0.4s var(--ease) both;
}

#home-view .lesson-item:nth-child(1)  { animation-delay: 0.02s; }
#home-view .lesson-item:nth-child(2)  { animation-delay: 0.04s; }
#home-view .lesson-item:nth-child(3)  { animation-delay: 0.06s; }
#home-view .lesson-item:nth-child(4)  { animation-delay: 0.08s; }
#home-view .lesson-item:nth-child(5)  { animation-delay: 0.10s; }
#home-view .lesson-item:nth-child(6)  { animation-delay: 0.12s; }
#home-view .lesson-item:nth-child(7)  { animation-delay: 0.14s; }
#home-view .lesson-item:nth-child(8)  { animation-delay: 0.16s; }
#home-view .lesson-item:nth-child(9)  { animation-delay: 0.18s; }
#home-view .lesson-item:nth-child(10) { animation-delay: 0.20s; }

#lesson-content {
  animation: fadeIn 0.35s var(--ease) both;
}

/* ─── Responsive ───────────────────────────────────────────────────── */

@media (max-width: 1024px) {
  #sidebar {
    transform: translateX(calc(var(--sidebar-w) * -1));
    z-index: 55;
  }
  #sidebar.open { transform: translateX(0); }

  #lesson-content-wrapper { margin-left: 0 !important; }

  #sidebar-toggle-btn { display: flex !important; }
}

@media (max-width: 640px) {
  .home-container { padding: 0 20px; }

  .home-header h1 { font-size: 28px; }
  .home-header p { font-size: 15px; }

  #lesson-content { padding: 32px 20px 100px; }
  #lesson-content h1 { font-size: 26px; }
  #lesson-content h2 { font-size: 21px; margin-top: 40px; }
  #lesson-content h3 { font-size: 18px; margin-top: 28px; }
  #lesson-content p, #lesson-content li { font-size: 15px; }

  .lesson-item-desc { display: none; }

  --sidebar-w: 280px;
}



/* ─── ASCII diagram pre (non-code) ─────────────────────────────────── */

#lesson-content pre:has(code:empty),
#lesson-content pre:not(:has(code)) {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  white-space: pre;
}

/* ─── Theme Dropdown Selector (Apple Style) ───────────────────────── */

.home-footer {
  margin-top: 56px;
  padding-top: 24px;
  border-top: 1px solid var(--separator);
  display: flex;
  justify-content: center;
}

.theme-select-container {
  position: relative;
  display: inline-flex;
}

.theme-select-trigger {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  padding: 6px 10px;
  border-radius: 6px;
  background-color: transparent;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: color 0.15s var(--ease), background-color 0.15s var(--ease);
}

.theme-select-trigger:hover {
  background-color: var(--btn-hover-bg);
  color: var(--text-primary);
}

.theme-select-trigger .chevron {
  transition: transform 0.2s var(--ease);
}

.theme-select-container.open .theme-select-trigger .chevron {
  transform: rotate(180deg);
}

.theme-dropdown-menu {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  min-width: 120px;
  background-color: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 4px;
  z-index: 200;
  display: none;
  flex-direction: column;
  gap: 2px;
}

.theme-select-container.open .theme-dropdown-menu {
  display: flex;
}

.theme-dropdown-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-primary);
  border-radius: 6px;
  background-color: transparent;
  border: none;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}

.theme-dropdown-item:hover {
  background-color: rgba(0, 0, 0, 0.04);
}

[data-theme="dark"] .theme-dropdown-item:hover {
  background-color: rgba(255, 255, 255, 0.08);
}

.theme-check {
  display: inline-block;
  width: 12px;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.1s;
}

.theme-dropdown-item.active .theme-check {
  visibility: visible;
  opacity: 1;
}

/* Sidebar footer theme control spacing */
.sidebar-footer .theme-select-container {
  display: flex;
  margin-top: 8px;
  justify-content: center;
}

/* ─── Toegangspoort (Access Gate Modal) ───────────────────────────── */

/* ─── Toegangspoort (Access Gate Modal) ───────────────────────────── */

#access-gate {
  position: fixed;
  inset: 0;
  background-color: #ffffff;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  transition: opacity 0.35s var(--ease);
}

[data-theme="dark"] #access-gate {
  background-color: #191919;
}

#access-gate.fade-out {
  opacity: 0;
  pointer-events: none;
}

.gate-card {
  width: 90%;
  max-width: 320px;
  text-align: left;
  animation: fadeIn 0.4s var(--ease) both;
}

.gate-card h2 {
  font-size: 25px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
  letter-spacing: -0.02em;
}

.gate-card p {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 30px;
  line-height: 1.5;
}

#gate-form {
  display: flex;
  flex-direction: column;
}

.gate-input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 20px;
}

.gate-input-group label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}

#gate-name {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  font-size: 14px;
  color: var(--text-primary);
  background-color: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

#gate-name:focus {
  border-color: #2383e2;
  box-shadow: 0 0 0 3px rgba(35, 131, 226, 0.15);
}

#gate-submit-btn {
  width: 100%;
  height: 38px;
  padding: 0 16px;
  font-size: 14px;
  font-weight: 500;
  color: #ffffff;
  background-color: #191919;
  border: 1px solid rgba(0, 0, 0, 0.05);
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.15s, transform 0.1s;
}

[data-theme="dark"] #gate-submit-btn {
  color: #191919;
  background-color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

#gate-submit-btn:hover {
  background-color: #050505;
}

[data-theme="dark"] #gate-submit-btn:hover {
  background-color: #f0f0f0;
}

#gate-submit-btn:active {
  transform: scale(0.98);
}

/* ─── Prioritering Modal (Les 8 Custom Modal) ─────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  transition: opacity 0.3s var(--ease);
}

[data-theme="dark"] .modal-overlay {
  background-color: rgba(0, 0, 0, 0.6);
}

.modal-overlay.hidden {
  opacity: 0;
  pointer-events: none;
  display: none !important;
}

.modal-card {
  position: relative;
  background-color: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 95%;
  max-width: 580px;
  max-height: 85vh;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  animation: modalScaleUp 0.3s var(--ease) both;
  overflow: hidden;
}

[data-theme="dark"] .modal-card {
  border: 1px solid #ffffff;
}

@keyframes modalScaleUp {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

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

.modal-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s, color 0.2s;
}

.modal-close:hover {
  background-color: var(--bg-secondary);
  color: var(--text-primary);
}

.modal-body {
  padding: 20px 20px 48px;
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
}

.modal-body > p {
  margin-top: 0;
  margin-bottom: 20px;
  color: var(--text-secondary);
}

.modal-factor {
  display: flex;
  gap: 16px;
  margin-bottom: 20px;
  align-items: flex-start;
}

.modal-factor-num {
  width: 24px;
  height: 24px;
  background-color: var(--text-primary);
  color: var(--bg-primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 12px;
  flex-shrink: 0;
}

.modal-factor-content {
  flex-grow: 1;
}

.modal-factor-content strong {
  display: block;
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
}

.modal-factor-content p {
  margin: 0 0 6px 0;
}

.modal-factor-content p:last-child {
  margin-bottom: 0;
  color: var(--text-secondary);
}



.modal-fade-top {
  position: absolute;
  top: 55px;
  left: 0;
  right: 0;
  height: 32px;
  background: linear-gradient(to bottom, var(--bg-primary) 0%, rgba(var(--bg-primary-rgb), 0) 100%);
  pointer-events: none;
  z-index: 10;
}

.modal-fade-bottom {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 48px;
  background: linear-gradient(to bottom, rgba(var(--bg-primary-rgb), 0) 0%, var(--bg-primary) 100%);
  pointer-events: none;
  z-index: 10;
  border-bottom-left-radius: 15px;
  border-bottom-right-radius: 15px;
}

/* ─── Details Accordion ────────────────────────────────────────────── */
details {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  margin: 24px 0;
  background: var(--bg-secondary);
  overflow: hidden;
  transition: border-color 0.3s var(--ease), background-color 0.3s var(--ease);
}

summary {
  padding: 16px 20px;
  font-size: 15px;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  list-style: none; /* Hide standard arrow */
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
  transition: background-color 0.2s var(--ease);
}

summary::-webkit-details-marker {
  display: none; /* Hide Safari arrow */
}

summary:hover {
  background-color: var(--btn-hover-bg);
}

/* Custom chevron indicator */
summary::after {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  border-bottom: 1.5px solid var(--text-secondary);
  border-right: 1.5px solid var(--text-secondary);
  transform: rotate(45deg);
  transition: transform 0.3s var(--ease);
  transform-origin: center;
  margin-right: 4px;
  flex-shrink: 0;
}

details[open] summary::after {
  transform: rotate(-135deg);
}

.details-content {
  padding: 0 20px 20px;
  border-top: 1px solid var(--separator);
  background: transparent;
}

.details-content > *:first-child {
  margin-top: 16px;
}

.details-content > *:last-child {
  margin-bottom: 0;
}

/* ─── Print Modal Styles ─────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.4);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  transition: opacity 0.25s var(--ease);
}

[data-theme="dark"] .modal-overlay {
  background-color: rgba(0, 0, 0, 0.6);
}

.modal-overlay.hidden {
  display: none !important;
}

.modal-card {
  background-color: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  width: 90%;
  max-width: 440px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: modalSlideIn 0.3s var(--ease) both;
}

@keyframes modalSlideIn {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--separator);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.modal-header h3 {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-close-btn {
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  transition: background-color 0.15s, color 0.15s;
}

.modal-close-btn:hover {
  background-color: var(--btn-hover-bg);
  color: var(--text-primary);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-intro {
  font-size: 13.5px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 20px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14.5px;
  color: var(--text-primary);
  cursor: pointer;
  user-select: none;
  margin-bottom: 12px;
}

.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.select-all-label {
  border-bottom: 1px solid var(--separator);
  padding-bottom: 12px;
  margin-bottom: 16px;
}

.print-lessons-list {
  display: flex;
  flex-direction: column;
  max-height: 220px;
  overflow-y: auto;
  padding-right: 4px;
  margin-bottom: 20px;
}

.print-lessons-list::-webkit-scrollbar {
  width: 5px;
}
.print-lessons-list::-webkit-scrollbar-thumb {
  background-color: var(--border);
  border-radius: 10px;
}

.print-settings {
  border-top: 1px solid var(--separator);
  padding-top: 16px;
  margin-top: 16px;
}

.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--separator);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-shrink: 0;
}

.modal-btn {
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 500;
  border-radius: 8px;
  transition: opacity 0.15s, background-color 0.15s, transform 0.15s;
  cursor: pointer;
}

.modal-btn.primary {
  background-color: var(--accent);
  color: #ffffff;
}

.modal-btn.primary:hover {
  opacity: 0.9;
}

.modal-btn.primary:active {
  transform: scale(0.98);
}

.modal-btn.secondary {
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.modal-btn.secondary:hover {
  background-color: var(--btn-hover-bg);
}

.modal-btn.secondary:active {
  transform: scale(0.98);
}

/* ─── Print Styles ─────────────────────────────────────────────────── */
@media print {
  /* Force light theme variables for printing to avoid invisible text (white text on white paper) in dark mode */
  :root, [data-theme="dark"] {
    --bg-primary: #ffffff;
    --bg-primary-rgb: 255, 255, 255;
    --bg-secondary: #f5f5f7;
    --bg-tertiary: #e8e8ed;
    --bg-elevated: #ffffff;
    --text-primary: #1d1d1f;
    --text-secondary: #6e6e73;
    --text-tertiary: #86868b;
    --accent: #0071e3;
    --accent-hover: #0077ed;
    --accent-subtle: rgba(0, 113, 227, 0.08);
    --border: #d2d2d7;
    --separator: rgba(60, 60, 67, 0.12);
    --header-bg: rgba(255, 255, 255, 0.72);
    --sidebar-bg: rgba(245, 245, 247, 0.92);
    --code-bg: #f5f5f7;
    --code-border: #e5e5ea;
    --table-stripe: #f9f9fb;
    --table-header: #f5f5f7;
    --btn-hover-bg: rgba(0, 0, 0, 0.05);

    --alert-note-bg: rgba(0, 113, 227, 0.06);
    --alert-note-border: #0071e3;
    --alert-note-text: #0055b3;
    --alert-tip-bg: rgba(52, 199, 89, 0.06);
    --alert-tip-border: #34c759;
    --alert-tip-text: #248a3d;
    --alert-important-bg: rgba(175, 82, 222, 0.06);
    --alert-important-border: #af52de;
    --alert-important-text: #8944ab;
    --alert-warning-bg: rgba(255, 149, 0, 0.06);
    --alert-warning-border: #ff9500;
    --alert-warning-text: #c93400;
    --alert-caution-bg: rgba(255, 59, 48, 0.06);
    --alert-caution-border: #ff3b30;
    --alert-caution-text: #d70015;
  }

  body {
    background: var(--bg-primary) !important;
    color: var(--text-primary) !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  
  /* Hide the entire application UI */
  #header, #access-gate, #home-view, #lesson-view, #print-modal, #sidebar-overlay {
    display: none !important;
  }
  
  /* Show print wrapper */
  #print-wrapper {
    display: block !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    background: var(--bg-primary) !important;
    color: var(--text-primary) !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  
  /* Override layout of #lesson-content inside print wrapper to fit nicely on page margins */
  #print-wrapper #lesson-content {
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }
  
  .print-page {
    page-break-after: always;
    break-after: page;
    padding: 2cm !important;
    background: var(--bg-primary) !important;
    color: var(--text-primary) !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  
  .print-page:last-child {
    page-break-after: avoid;
    break-after: auto;
  }
  
  /* Keep details layout identical to browser and print background graphics */
  .print-page details {
    break-inside: avoid;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .print-page details .details-content {
    display: block !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .mermaid-container {
    break-inside: avoid;
  }

  .print-lesson-header {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    border-bottom: 1.5px solid var(--separator);
    padding-bottom: 8px;
    margin-bottom: 32px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
}

/* Hide print wrapper in screen mode */
#print-wrapper {
  display: none;
}



