:root {
  --bg-page: #050507;
  --bg-section: #0A0A0D;
  --bg-surface: #101013;
  --bg-surface-2: #18181C;
  --bg-elevated: #1C1C21;

  --purple-primary: #7F05FF;
  --purple-bright: #9B30FF;
  --purple-glow: #B45CFF;
  --purple-deep: #2E0A66;

  --green-bg: #16301F;
  --green-text: #6FE38A;
  --green-accent: #6FE38A;

  --text-primary: #FFFFFF;
  --text-secondary: #ADADB8;
  --text-tertiary: #84848F;
  --text-muted: #5B5B66;

  --border-subtle: rgba(255,255,255,0.08);
  --border-medium: rgba(255,255,255,0.14);

  --topbar-bg: rgba(5,5,7,0.85);

  --radius-pill: 999px;
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 10px;

  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px;
  --sp-6: 32px; --sp-7: 48px; --sp-8: 64px; --sp-9: 96px;

  --font-body: 'Satoshi', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-accent: 'Instrument Serif', Georgia, serif;
}

[data-theme="light"] {
  --bg-page: #F4F2F8;
  --bg-section: #EFEDF5;
  --bg-surface: #FFFFFF;
  --bg-surface-2: #F3F1F8;
  --bg-elevated: #E9E4F2;

  --purple-primary: #7F05FF;
  --purple-bright: #9B30FF;
  --purple-glow: #7F05FF;
  --purple-deep: #2E0A66;

  --green-bg: #16301F;
  --green-text: #6FE38A;
  --green-accent: #1C8A4A;

  --text-primary: #17141E;
  --text-secondary: #55505F;
  --text-tertiary: #79758A;
  --text-muted: #A19DAD;

  --border-subtle: rgba(23,20,30,0.08);
  --border-medium: rgba(23,20,30,0.15);

  --topbar-bg: rgba(244,242,248,0.85);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg-page);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-weight: 400;
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: clip;   /* safety net: the page never scrolls sideways on a phone */
}
img { max-width: 100%; display: block; }
button { font-family: inherit; cursor: pointer; }
a { color: inherit; }
input, textarea { font-family: inherit; }

.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 var(--sp-5);
}

/* ---------- Header ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--topbar-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
}
.topbar-inner {
  display: flex;
  align-items: center;
  gap: var(--sp-5);
  padding: var(--sp-4) var(--sp-5);
  max-width: 1180px;
  margin: 0 auto;
}
.brand-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.brand {
  display: flex;
  align-items: center;
  cursor: pointer;
  flex-shrink: 0;
}
.brand-logo-text {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 19px;
  color: var(--text-primary);
  white-space: nowrap;
}
.brand-logo-text .accent {
  font-family: var(--font-accent);
  font-style: italic;
  font-weight: 400;
  color: var(--purple-glow);
}
.brand-edit-btn {
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  flex-shrink: 0;
}
.brand-edit-btn:hover { color: var(--text-primary); border-color: var(--border-medium); background: var(--bg-surface-2); }
.search-bar {
  width: 420px;
  max-width: 100%;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  background: var(--bg-surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  padding: 10px 18px;
}
.search-bar svg { flex-shrink: 0; opacity: 0.6; }
.search-bar input {
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 14px;
  width: 100%;
}
.search-bar input::placeholder { color: var(--text-tertiary); }
.topbar-spacer { display: flex; align-items: center; gap: 10px; margin-left: auto; flex-shrink: 0; }
.stats-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--bg-surface-2);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  border-radius: var(--radius-pill);
  padding: 7px 14px 7px 11px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}
.stats-badge .trophy-icon { color: var(--purple-glow); flex-shrink: 0; }
.stats-badge .stats-count { color: var(--green-accent); font-weight: 700; }
.stats-badge .stats-sub { color: var(--text-tertiary); }
.avatar-group { display: flex; align-items: center; gap: 8px; }
.avatar-circle {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--bg-surface-2);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: var(--text-muted);
  flex-shrink: 0;
}
.avatar-img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: var(--radius-pill);
  border: none;
  padding: 13px 26px;
  font-weight: 700;
  font-size: 14px;
  transition: background 0.15s ease, opacity 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
}
.btn-sm { padding: 8px 18px; font-size: 13px; }
.btn-icon { padding: 9px; border-radius: var(--radius-pill); }
.btn-primary { background: var(--purple-primary); color: #fff; }
.btn-primary:hover { background: var(--purple-bright); }
.btn-dark { background: var(--bg-surface-2); color: var(--text-primary); border: 1px solid transparent; }
.btn-dark:hover { background: var(--bg-elevated); border-color: var(--purple-glow); color: var(--purple-glow); }
.btn-outline { background: transparent; color: var(--text-primary); border: 1px solid var(--border-medium); }
.btn-outline:hover { border-color: var(--text-secondary); }
.btn-ghost { background: transparent; color: var(--text-secondary); padding: 8px 10px; }
.btn-ghost:hover { color: var(--text-primary); }
.btn-danger { background: transparent; color: #E8607A; padding: 8px 10px; }
.btn-danger:hover { background: rgba(232,96,122,0.1); }
.btn[disabled] { opacity: 0.4; cursor: not-allowed; }

/* ---------- Page header ---------- */
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-5);
  padding: var(--sp-7) 0 var(--sp-5);
  flex-wrap: wrap;
}
.page-head h1 {
  font-size: 40px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
}
.page-head .accent {
  font-family: var(--font-accent);
  font-style: italic;
  font-weight: 400;
  color: var(--text-secondary);
}
.course-source-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  color: var(--text-tertiary);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
}
.course-source-link:hover { color: var(--purple-glow); }
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-tertiary);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  margin-bottom: var(--sp-3);
}
.back-link:hover { color: var(--text-primary); }
.crumb-title { font-size: 13px; color: var(--text-tertiary); margin-bottom: var(--sp-2); }

/* ---------- Continue watching ---------- */
.continue-watching {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--sp-4);
  margin-bottom: var(--sp-6);
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s ease;
}
.continue-watching:hover { border-color: var(--border-medium); }
.continue-thumb {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-md);
  overflow: hidden;
  flex-shrink: 0;
  background: linear-gradient(135deg, var(--purple-deep), var(--bg-surface-2));
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.9;
}
.continue-thumb img { width: 100%; height: 100%; object-fit: cover; }
.continue-info { flex: 1; min-width: 0; }
.continue-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--purple-glow);
  font-weight: 700;
  margin-bottom: 3px;
}
.continue-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.continue-sub {
  font-size: 13px;
  color: var(--text-tertiary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.continue-arrow { color: var(--text-tertiary); font-size: 20px; flex-shrink: 0; }

/* ---------- Filter chips ---------- */
/* Category filter: one compact dropdown instead of a chip for every category */
.filter-row { display: flex; align-items: center; flex-wrap: wrap; gap: var(--sp-3); padding-bottom: var(--sp-5); }
.cat-filter { position: relative; }
.cat-pill {
  display: inline-flex; align-items: stretch;
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-pill);
  background: transparent;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.cat-pill:hover { border-color: var(--text-secondary); }
.cat-pill.active { background: var(--purple-primary); border-color: var(--purple-primary); }
.cat-btn, .cat-clear {
  background: none; border: none; color: var(--text-secondary); font: inherit; font-size: 13px; font-weight: 500; cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px;
}
.cat-btn { padding: 8px 14px 8px 13px; border-radius: var(--radius-pill); max-width: 260px; }
.cat-btn:hover { color: var(--text-primary); }
.cat-btn-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-btn .caret { opacity: 0.7; flex-shrink: 0; }
.cat-pill.active .cat-btn, .cat-pill.active .cat-clear { color: #fff; }
.cat-clear { padding: 0 12px 0 4px; border-radius: 0 var(--radius-pill) var(--radius-pill) 0; opacity: 0.85; }
.cat-clear:hover { opacity: 1; }
.cat-menu {
  position: absolute; top: calc(100% + 8px); left: 0; z-index: 30;
  width: min(320px, calc(100vw - 2 * var(--sp-5)));
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  box-shadow: 0 16px 40px rgba(0,0,0,0.45);
  padding: 8px;
}
.cat-menu[hidden] { display: none; }
.cat-search {
  width: 100%; box-sizing: border-box; margin-bottom: 6px;
  background: var(--bg-surface-2); border: 1px solid var(--border-subtle); border-radius: var(--radius-pill);
  color: var(--text-primary); font-size: 13px; padding: 9px 14px; outline: none;
}
.cat-search:focus { border-color: var(--border-medium); }
.cat-list { max-height: min(320px, 50vh); overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.cat-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%;
  background: none; border: none; text-align: left; cursor: pointer;
  color: var(--text-secondary); font: inherit; font-size: 13px; padding: 9px 12px; border-radius: 8px;
}
.cat-item[hidden] { display: none; }
.cat-item > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-item:hover { background: var(--bg-surface-2); color: var(--text-primary); }
.cat-item.selected { color: var(--purple-glow); font-weight: 600; }
.cat-count { color: var(--text-muted); font-size: 12px; flex-shrink: 0; }
.cat-empty { padding: 12px; font-size: 13px; color: var(--text-muted); text-align: center; }
.filter-summary { font-size: 13px; color: var(--text-tertiary); }

/* ---------- Grid & cards ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(340px, 100%), 1fr));
  gap: var(--sp-5);
  padding-bottom: var(--sp-9);
}
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color 0.15s ease, transform 0.15s ease;
  position: relative;
}
.card:hover { border-color: var(--border-medium); }
.card.dragging {
  transform: scale(1.04) rotate(-2deg);
  box-shadow: 0 24px 48px rgba(0,0,0,0.55), 0 0 0 2px var(--purple-primary);
  z-index: 10;
}
.drag-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: var(--text-muted);
  cursor: grab;
}
.drag-handle:hover { color: var(--text-secondary); }
.drag-handle:active { cursor: grabbing; }
.card-media {
  aspect-ratio: 16/9;
  background: linear-gradient(135deg, var(--purple-deep), var(--bg-surface-2));
  position: relative;
  overflow: hidden;
  cursor: pointer;
}
.card-media img { width: 100%; height: 100%; object-fit: cover; }
.card-media .placeholder-icon {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  opacity: 0.35;
}
.play-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(5,5,7,0.55);
  backdrop-filter: blur(4px);
  border: 1.5px solid rgba(255,255,255,0.4);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.play-overlay svg { margin-left: 3px; }
.card-media:hover .play-overlay {
  background: var(--purple-primary);
  border-color: var(--purple-primary);
  transform: translate(-50%, -50%) scale(1.08);
}
.card-video-inline {
  position: absolute;
  inset: 0;
  background: #000;
  z-index: 2;
}
.card-video-inline video, .card-video-inline iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}
.video-close {
  position: absolute;
  top: var(--sp-2);
  right: var(--sp-2);
  width: 30px;
  height: 30px;
  background: rgba(5,5,7,0.75);
  backdrop-filter: blur(4px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  z-index: 3;
}
.video-close:hover { background: var(--bg-elevated); }
.card-body { padding: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-3); flex: 1; }
.card-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.card-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid var(--border-subtle);
  cursor: pointer;
}
.card-avatar-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface-2);
  color: var(--text-secondary);
  font-weight: 700;
  font-size: 13px;
}
.card-title {
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  line-height: 1.3;
}
.card-title:hover { color: var(--purple-glow); }
.card-desc {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-actions {
  position: absolute;
  top: var(--sp-2);
  right: var(--sp-2);
  display: flex;
  gap: 4px;
  z-index: 2;
}
.card-actions button {
  background: rgba(5,5,7,0.75);
  backdrop-filter: blur(4px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary);
}
.card-actions button:hover { background: var(--bg-elevated); color: var(--text-primary); }
.card-actions [data-del-course]:hover, .card-actions [data-del-module]:hover { color: #E8607A; }

/* progress bar */
.progress-track {
  width: 100%;
  height: 8px;
  background: var(--bg-surface-2);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--green-accent);
  border-radius: var(--radius-pill);
  transition: width 0.3s ease;
}
.progress-label { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-tertiary); font-weight: 500; }
.badge-complete {
  position: absolute;
  top: var(--sp-2);
  left: var(--sp-2);
  background: var(--green-bg);
  color: var(--green-text);
  font-size: 11px;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  z-index: 1;
}

/* ---------- Pagination ---------- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px;
  padding-bottom: var(--sp-9);
}
.page-nav {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 14px;
  padding: 8px 16px;
  border-radius: var(--radius-pill);
}
.page-nav:hover:not([disabled]) { background: var(--bg-surface-2); color: var(--text-primary); }
.page-nav[disabled] { opacity: 0.35; cursor: not-allowed; }
.page-num {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 50%;
  color: var(--text-tertiary);
  font-weight: 600;
  font-size: 14px;
}
.page-num:hover { background: var(--bg-surface-2); color: var(--text-primary); }
.page-num.active { background: var(--purple-primary); color: #fff; }
.page-ellipsis { color: var(--text-muted); padding: 0 4px; font-size: 14px; }

/* ---------- Empty state ---------- */
.empty-state {
  text-align: center;
  padding: var(--sp-9) var(--sp-5);
  color: var(--text-tertiary);
}
.empty-state h3 { color: var(--text-primary); font-size: 20px; margin-bottom: var(--sp-2); }
.empty-state p { font-size: 14px; margin-bottom: var(--sp-5); }
.onboarding-note {
  max-width: 440px;
  margin: var(--sp-6) auto 0;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--sp-4) var(--sp-5);
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-secondary);
}
.onboarding-note strong { color: var(--text-primary); }

/* ---------- Lesson layout ---------- */
.lesson-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: var(--sp-5);
  padding-bottom: var(--sp-9);
  align-items: start;
}
.lesson-sidebar {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: sticky;
  top: 90px;
}
.lesson-sidebar-head {
  padding: var(--sp-4);
  border-bottom: 1px solid var(--border-subtle);
}
.lesson-sidebar-head .progress-label { margin-bottom: 8px; }
.lesson-list { list-style: none; margin: 0; padding: var(--sp-2); max-height: 60vh; overflow-y: auto; }
.lesson-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3);
  border-radius: var(--radius-md);
  cursor: pointer;
}
.lesson-item:hover { background: var(--bg-surface-2); }
.lesson-item.active { background: var(--bg-surface-2); }
.lesson-item.active .lesson-item-title { color: var(--purple-glow); }
.lesson-item.dragging {
  background: var(--bg-elevated);
  transform: scale(1.02) rotate(-1deg);
  box-shadow: 0 12px 24px rgba(0,0,0,0.5), 0 0 0 2px var(--purple-primary);
  position: relative;
  z-index: 10;
}
.lesson-check {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 1.5px solid var(--border-medium);
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: transparent;
  cursor: pointer;
  transition: all 0.15s ease;
}
.lesson-check.checked {
  background: var(--green-text);
  border-color: var(--green-text);
  color: #0A0A0D;
}
.lesson-check-lg { width: 32px; height: 32px; }
.lesson-check-lg svg { width: 16px; height: 16px; }
.lesson-check:hover { border-color: var(--green-text); }
.lesson-item-title { font-size: 14px; font-weight: 500; flex: 1; line-height: 1.35; }
.lesson-item.watched .lesson-item-title { color: var(--text-tertiary); }
.lesson-rename-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}
.lesson-rename-btn:hover { color: var(--text-primary); background: var(--bg-elevated); }
.lesson-rename-input {
  flex: 1;
  min-width: 0;
  background: var(--bg-page);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  padding: 4px 8px;
  outline: none;
}
.add-lesson-row { padding: var(--sp-3); }

.lesson-main { min-width: 0; }
.video-frame {
  width: 100%;
  aspect-ratio: 16/9;
  background: #000;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
}
.video-frame video, .video-frame iframe { width: 100%; height: 100%; border: none; display: block; }
.video-cover { width: 100%; height: 100%; object-fit: cover; display: block; }
.video-cover-wrap { position: relative; display: block; width: 100%; height: 100%; }
.video-cover-play {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 84px; height: 84px; border-radius: 50%;
  background: var(--purple-primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 24px rgba(127,5,255,0.5);
  transition: transform .15s ease, background .15s ease, box-shadow .15s ease;
}
.video-cover-wrap:hover .video-cover-play {
  transform: translate(-50%, -50%) scale(1.1);
  background: var(--purple-bright);
  box-shadow: 0 6px 30px rgba(127,5,255,0.7);
}
.video-empty {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-tertiary); font-size: 14px; text-align: center; padding: var(--sp-5);
}
.video-error { flex-direction: column; gap: var(--sp-4); position: relative; }
.video-error-bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 0; }
.video-error::before { content: ''; position: absolute; inset: 0; background: rgba(0,0,0,0.6); z-index: 1; }
.video-error p, .video-error a { position: relative; z-index: 2; }
.video-error p { margin: 0; max-width: 320px; }
.video-fallback-row { display: flex; justify-content: flex-end; padding-top: 8px; }
.video-fallback-row a { font-size: 12px; color: var(--text-tertiary); text-decoration: none; }
.video-fallback-row a:hover { color: var(--purple-glow); text-decoration: underline; }
.lesson-title-row {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap;
  padding: 0 0 var(--sp-3);
  gap: var(--sp-3);
}
.lesson-title-row h2 { font-size: 24px; font-weight: 700; margin: 0; flex: 1 1 220px; min-width: 0; overflow-wrap: anywhere; }

.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  margin-top: var(--sp-5);
}
.panel h3 {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  font-weight: 500;
  margin: 0 0 var(--sp-3);
}
.notes-textarea {
  width: 100%;
  min-height: 140px;
  background: var(--bg-surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  padding: var(--sp-4);
  font-size: 14px;
  line-height: 1.6;
  resize: none;
  overflow: hidden;
  outline: none;
}
.notes-textarea:focus { border-color: var(--border-medium); }
.notes-display {
  width: 100%;
  min-height: 140px;
  background: var(--bg-surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  padding: var(--sp-4);
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  cursor: text;
}
.notes-display:hover { border-color: var(--border-medium); }
.notes-display:focus { outline: none; border-color: var(--border-medium); }
.notes-display a { color: var(--purple-glow); text-decoration: underline; text-underline-offset: 2px; }
.notes-display a:hover { color: var(--purple-bright); }
.notes-placeholder { color: var(--text-tertiary); }
.save-hint { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

.link-list { list-style: none; margin: 0 0 var(--sp-3); padding: 0; display: flex; flex-direction: column; gap: 8px; }
.link-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px 14px;
}
.link-item a { flex: 1; font-size: 14px; color: var(--purple-glow); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-item a:hover { text-decoration: underline; }
.link-item .link-label { font-size: 13px; color: var(--text-secondary); font-weight: 500; }
.link-item.editing { flex-wrap: wrap; }
.link-item.editing input {
  background: var(--bg-page);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  color: var(--text-primary);
  padding: 8px 14px;
  font-size: 13px;
  outline: none;
}
.link-item.editing input:focus { border-color: var(--border-medium); }
.link-item.editing input[data-field="label"] { width: 140px; }
.link-item.editing input[data-field="url"] { flex: 1; min-width: 160px; }
.add-link-form { display: flex; gap: 8px; flex-wrap: wrap; }
.add-link-form input {
  background: var(--bg-surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  color: var(--text-primary);
  padding: 9px 16px;
  font-size: 13px;
  outline: none;
}
.add-link-form input:focus { border-color: var(--border-medium); }
.add-link-form input[data-field="label"] { width: 160px; }
.add-link-form input[data-field="url"] { flex: 1; min-width: 180px; }

.resource-list { list-style: none; margin: 0 0 var(--sp-3); padding: 0; display: flex; flex-direction: column; gap: 8px; }
.resource-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px 12px;
}
.resource-icon { color: var(--purple-glow); flex-shrink: 0; display: flex; }
.resource-info { flex: 1; min-width: 0; }
.resource-label { font-size: 14px; font-weight: 500; color: var(--text-primary); }
.resource-desc { font-size: 12px; color: var(--text-tertiary); margin-top: 2px; }
.add-resource-form { display: flex; gap: 8px; flex-wrap: wrap; }
.add-resource-form input {
  background: var(--bg-surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  color: var(--text-primary);
  padding: 9px 16px;
  font-size: 13px;
  outline: none;
}
.add-resource-form input:focus { border-color: var(--border-medium); }
.add-resource-form input#resource-label { width: 160px; }
.add-resource-form input#resource-url { flex: 1; min-width: 200px; }
.add-resource-form input#resource-desc { flex: 1; min-width: 200px; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(5,5,7,0.7);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: var(--sp-5);
}
.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  padding: var(--sp-6);
  max-height: 88vh;
  overflow-y: auto;
}
.modal h2 { font-size: 22px; font-weight: 700; margin: 0 0 var(--sp-5); }

/* Confirm / alert dialogs (replace the browser pop-ups; sit above open windows) */
.dialog-overlay {
  position: fixed; inset: 0;
  background: rgba(5,5,7,0.72);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 150;
  padding: var(--sp-5);
}
.dialog {
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-lg);
  width: 100%; max-width: 420px;
  padding: var(--sp-6);
  box-shadow: 0 24px 48px rgba(0,0,0,0.5);
}
.dialog h2 { font-size: 20px; font-weight: 700; margin: 0 0 var(--sp-3); }
.dialog-body p { margin: 0 0 var(--sp-3); font-size: 14px; line-height: 1.55; color: var(--text-secondary); }
.dialog-body p:last-child { margin-bottom: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: var(--sp-5); }
.btn-danger-solid { background: #E8607A; color: #fff; }
.btn-danger-solid:hover { background: #F0748C; }
.field { margin-bottom: var(--sp-4); }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
  margin-bottom: 8px;
}
.field input[type="text"], .field input[type="url"], .field input[type="email"], .field input[type="password"], .field textarea {
  width: 100%;
  background: var(--bg-surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  padding: 12px 14px;
  font-size: 14px;
  outline: none;
}
.field input:focus, .field textarea:focus { border-color: var(--border-medium); }
.field-hint { font-size: 12px; color: var(--text-muted); margin-top: 6px; }
.tag-input-box {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  background: var(--bg-surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 8px 10px;
}
.tag-input-box:focus-within { border-color: var(--border-medium); }
.tag-chips { display: contents; }
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--purple-primary);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 6px 5px 12px;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}
.tag-chip button {
  background: rgba(255,255,255,0.2);
  border: none;
  color: #fff;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.tag-chip button:hover { background: rgba(255,255,255,0.35); }
.tag-chip button svg { width: 9px; height: 9px; }
.tag-input-box input {
  flex: 1;
  min-width: 120px;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 14px;
  padding: 4px 2px;
}
.tag-suggestions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag-suggestion {
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  padding: 5px 12px;
  border-radius: var(--radius-pill);
}
.tag-more { align-self: center; font-size: 12px; color: var(--text-muted); padding: 0 4px; }
.tag-suggestion:hover { border-color: var(--border-medium); color: var(--text-primary); background: var(--bg-elevated); }
.file-drop {
  border: 1.5px dashed var(--border-medium);
  border-radius: var(--radius-md);
  padding: var(--sp-5);
  text-align: center;
  cursor: pointer;
  color: var(--text-tertiary);
  font-size: 13px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.file-drop img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.file-drop input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.file-drop .file-drop-label { position: relative; z-index: 1; pointer-events: none; }
.file-drop.has-image .file-drop-label { display: none; }
.file-drop.drag-over {
  border-color: var(--purple-glow);
  background: rgba(127,5,255,0.12);
}
.file-drop.has-image.drag-over::after {
  content: '';
  position: absolute; inset: 0;
  background: rgba(5,5,7,0.55);
  border: 1.5px dashed var(--purple-glow);
  z-index: 1;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: var(--sp-6); }

/* ---------- Footer ---------- */
.footer {
  border-top: 1px solid var(--border-subtle);
  padding: var(--sp-6) 0;
  text-align: center;
}
.footer-actions { display: flex; justify-content: center; gap: 10px; margin-bottom: var(--sp-3); }
.backup-status { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.backup-status.urgent { color: #E8A23D; }
.footer small { color: var(--text-muted); font-size: 12px; }

/* ---------- Login / account ---------- */
body.auth-open { overflow: hidden; }
.auth-screen {
  position: fixed; inset: 0; z-index: 300;
  display: flex; align-items: center; justify-content: center;
  padding: var(--sp-5);
  background: var(--bg-page);
  overflow-y: auto;
}
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--sp-6);
  box-shadow: 0 24px 48px rgba(0,0,0,0.35);
}
.auth-brand { display: block; text-align: center; margin-bottom: var(--sp-5); font-size: 22px; }
.auth-card h1 { font-size: 22px; font-weight: 700; margin: 0 0 var(--sp-2); }
.auth-sub { color: var(--text-secondary); font-size: 14px; line-height: 1.5; margin: 0 0 var(--sp-5); }
.auth-card .btn { width: 100%; }
.auth-loading { text-align: center; margin: 0; padding: var(--sp-2) 0; }
.auth-error { color: #E8607A; font-size: 13px; min-height: 18px; margin: 0 0 var(--sp-3); }
.auth-links { display: flex; justify-content: space-between; gap: var(--sp-3); margin-top: var(--sp-4); }
.auth-link-btn {
  background: none; border: none; padding: 0; font: inherit; font-size: 13px;
  color: var(--text-tertiary); cursor: pointer;
}
.auth-link-btn:hover { color: var(--purple-glow); text-decoration: underline; }
.account-value { font-size: 15px; color: var(--text-primary); }
.account-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: var(--sp-5);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--border-medium);
  color: var(--text-primary);
  padding: 12px 22px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 500;
  z-index: 200;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; }

/* iPhones zoom the whole page when you tap a text box whose text is under 16px (and often stay zoomed).
   On touch screens every text box uses 16px so that never happens. */
@media (pointer: coarse), (max-width: 760px) {
  input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="range"]),
  textarea, select { font-size: 16px !important; }
}

@media (max-width: 760px) {
  .lesson-layout { grid-template-columns: 1fr; }
  .lesson-sidebar { position: static; }
  .topbar-inner { flex-wrap: wrap; gap: var(--sp-3); }
  .search-bar { width: 100%; max-width: none; order: 3; }
  /* On a phone keep just theme, account and photo in the top row (the account button holds sign out) */
  .topbar-spacer { gap: 8px; }
  .stats-badge, .avatar-group .brand-edit-btn { display: none !important; }
  .page-head h1 { font-size: 30px; }
}
