:root {
  --brand: #2f5bea;
  --brand-dark: #2147c4;
  --brand-soft: #eaf0ff;
  --ink: #1b1f2a;
  --muted: #6b7280;
  --line: #e5e7eb;
  --canvas: #f4f5f8;
  --card: #ffffff;
  --side: #14161f;
  --side-ink: #a9adbd;
  --accent: #16a34a;
  --ok: #16a34a;
  --ok-soft: #e7f7ed;
  --warn: #b45309;
  --warn-soft: #fdf3e3;
  --danger: #dc2626;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5em; letter-spacing: -0.01em; }
h1 { font-size: 26px; font-weight: 700; }
h2 { font-size: 19px; font-weight: 600; }
h3 { font-size: 16px; font-weight: 600; }
p { margin: 0 0 1em; }
code { background: #f1f2f6; padding: 1px 5px; border-radius: 4px; font-size: 0.9em; }
.muted { color: var(--muted); }
.small, small { font-size: 13px; }
.icon { flex: none; vertical-align: -3px; }
form.inline, .row-actions form { display: inline; }

/* ---------- Controls ---------- */
input, textarea, select {
  width: 100%;
  font: inherit;
  color: inherit;
  padding: 9px 12px;
  border: 1px solid #d0d5dd;
  border-radius: 8px;
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
input.big { font-size: 18px; font-weight: 600; }
textarea { resize: vertical; }
label, .field { display: block; font-weight: 500; font-size: 14px; }
label > input, label > textarea, label > select { margin-top: 6px; font-weight: 400; }
.stack > * + * { margin-top: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid #d0d5dd;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none !important;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: #f8f9fb; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: rgba(0, 0, 0, 0.04); }
.btn.danger { color: var(--danger); border-color: #fecaca; background: #fff; }
.btn.danger:hover { background: #fef2f2; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.block { width: 100%; }
button.link { background: none; border: 0; padding: 0; color: inherit; font: inherit; cursor: pointer; opacity: 0.8; }
button.link:hover { opacity: 1; text-decoration: underline; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border: 0; border-radius: 6px;
  background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: #f1f2f6; color: var(--ink); }
.icon-btn.danger:hover { background: #fef2f2; color: var(--danger); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; text-transform: uppercase; letter-spacing: 0.03em; }
.badge.live { background: var(--ok-soft); color: var(--ok); }
.badge.draft { background: var(--warn-soft); color: var(--warn); }
.notice, .error { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.notice { background: var(--ok-soft); color: #166534; border: 1px solid #bbf7d0; }
.error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.empty { text-align: center; padding: 48px 24px; }

.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--brand); color: #fff; font-weight: 600; font-size: 13px;
}
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; color: inherit; text-decoration: none !important; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 8px; background: var(--brand); color: #fff; font-size: 15px; text-transform: uppercase;
}

.progress .bar { height: 6px; background: #e8eaf0; border-radius: 99px; overflow: hidden; margin: 6px 0 4px; }
.progress .bar span { display: block; height: 100%; background: var(--brand); border-radius: 99px; }
.progress small { color: var(--muted); }

/* ---------- Auth pages ---------- */
body.auth { background: linear-gradient(160deg, #eef2ff 0%, var(--canvas) 60%); min-height: 100vh; }
.auth-wrap { max-width: 420px; margin: 0 auto; padding: 72px 16px; }
.auth-brand { display: flex; justify-content: center; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; margin-bottom: 24px; }
.auth-card { padding: 32px; }
.auth-card h1 { font-size: 22px; }

/* ---------- Student site ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  height: 64px; padding: 0 24px; background: #fff; border-bottom: 1px solid var(--line);
}
.topbar .brand { color: var(--ink); }
.topnav { display: flex; align-items: center; gap: 20px; font-weight: 500; }
.topnav > a { color: var(--ink); }
.usermenu { position: relative; }
.usermenu summary { list-style: none; cursor: pointer; }
.usermenu summary::-webkit-details-marker { display: none; }
.usermenu .menu {
  position: absolute; right: 0; top: 44px; width: 240px; padding: 6px;
  background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 32px rgba(16, 24, 40, 0.12);
}
.menu-head { padding: 10px 12px; border-bottom: 1px solid var(--line); margin-bottom: 4px; display: flex; flex-direction: column; }
.menu-head span { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.menu a, .menu .menu-item {
  display: block; width: 100%; text-align: left; padding: 8px 12px; border-radius: 6px;
  color: var(--ink); background: none; border: 0; font: inherit; cursor: pointer;
}
.menu a:hover, .menu .menu-item:hover { background: #f4f5f8; text-decoration: none; }

.hero { background: linear-gradient(120deg, #1c2340 0%, #2f5bea 100%); color: #fff; }
.hero-inner { max-width: 1120px; margin: 0 auto; padding: 48px 24px 72px; }
.hero h1 { font-size: 32px; }
.hero p { opacity: 0.8; margin: 0; }
.container { max-width: 1120px; margin: 0 auto; padding: 32px 24px 64px; }
.hero + .container { margin-top: -48px; }

.course-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 24px; }
.course-card {
  display: flex; flex-direction: column; background: #fff; border-radius: 12px; overflow: hidden;
  border: 1px solid var(--line); box-shadow: var(--shadow); color: inherit;
  transition: transform 0.15s, box-shadow 0.15s;
}
.course-card:hover { transform: translateY(-2px); box-shadow: 0 12px 28px rgba(16, 24, 40, 0.12); text-decoration: none; }
.cover {
  position: relative; aspect-ratio: 16 / 9; background: linear-gradient(135deg, #2f5bea, #7c3aed) center / cover no-repeat;
  display: flex; align-items: center; justify-content: center; color: rgba(255, 255, 255, 0.9); font-size: 48px; font-weight: 700;
}
.cover .badge { position: absolute; top: 12px; left: 12px; font-size: 11px; }
.course-card-body { padding: 18px 20px 20px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.course-card-body h3 { font-size: 18px; margin: 0; }
.course-card-body .progress { margin-top: auto; padding-top: 8px; }
.course-card-body .btn { margin-top: 12px; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin: 0; }

/* Lesson player */
.player { display: grid; grid-template-columns: 340px 1fr; min-height: calc(100vh - 64px); }
.toc { background: #fff; border-right: 1px solid var(--line); overflow-y: auto; position: sticky; top: 64px; height: calc(100vh - 64px); }
.toc-head { padding: 20px; border-bottom: 1px solid var(--line); }
.toc-head h2 { font-size: 17px; margin: 12px 0 4px; }
.back { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); }
.eyebrow { display: block; font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin: 0; }
.eyebrow.accent { color: var(--brand); margin-bottom: 6px; }
.toc-head .eyebrow { margin-top: 14px; }
.toc-head h2 { margin-top: 4px; }
.hide-done {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--line); cursor: pointer; font-weight: 400;
}
.hide-done strong { display: block; font-size: 14px; font-weight: 600; }
.hide-done small { color: var(--muted); }
.toggle {
  appearance: none; flex: none; width: 44px; height: 24px; margin: 0; padding: 0; border-radius: 99px;
  background: #d0d5dd; border: 0; position: relative; cursor: pointer; transition: background 0.15s;
}
.toggle::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2); transition: transform 0.15s;
}
.toggle:checked { background: var(--brand); }
.toggle:checked::after { transform: translateX(20px); }
.toggle:disabled { opacity: 0.45; cursor: default; }
.toggle:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; box-shadow: none; }
.toc-module { padding: 18px 12px 4px; }
.toc-module .eyebrow { padding: 0 8px 8px; }
.toc ul { list-style: none; margin: 0; padding: 0; }
.toc li a { display: block; padding: 10px 8px; border-radius: 8px; color: var(--ink); }
.toc li a:hover { background: #f6f7fa; text-decoration: none; }
.toc li.current a { background: var(--brand-soft); }
.toc-title { display: block; font-size: 14px; font-weight: 500; line-height: 1.35; }
.toc li small { display: flex; align-items: center; gap: 8px; margin-top: 2px; color: var(--muted); font-size: 12.5px; }
.toc li.done .toc-title { color: var(--muted); }
.done-label { color: var(--accent); font-weight: 600; }
.toc.hiding-done li.done:not(.current) { display: none; }
.toc-toggle, .toc-open { display: none; }

.lesson { padding: 32px 48px 64px; max-width: 1000px; width: 100%; }
.lesson h1 { font-size: 30px; margin-bottom: 22px; letter-spacing: -0.02em; }
.video { position: relative; aspect-ratio: 16 / 9; background: #000; border-radius: 12px; overflow: hidden; box-shadow: 0 8px 24px rgba(16, 24, 40, 0.15); }
.video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.prose { margin-top: 28px; font-size: 16px; line-height: 1.7; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 28px 32px; }
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }
.prose h1, .prose h2, .prose h3 { margin-top: 1.4em; }
.prose img { max-width: 100%; border-radius: 8px; }
.prose pre { background: #0f172a; color: #e2e8f0; padding: 16px; border-radius: 8px; overflow-x: auto; }
.prose pre code { background: none; padding: 0; color: inherit; }
.prose blockquote { margin: 1em 0; padding: 4px 16px; border-left: 4px solid var(--brand); background: var(--brand-soft); border-radius: 0 8px 8px 0; }
.prose table { border-collapse: collapse; width: 100%; }
.prose th, .prose td { border: 1px solid var(--line); padding: 8px 10px; text-align: left; }
.lesson-nav { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--line); }
.lesson-nav form, .lesson-nav-right { display: flex; gap: 8px; }
.lesson-nav-right { margin-left: auto; }
.btn.done-btn { color: var(--accent); border-color: #bbf7d0; background: var(--ok-soft); }
.btn.done-btn:hover { background: #dcfce7; }

/* ---------- Admin ---------- */
body.admin { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.sidebar .brand { color: #fff; padding: 20px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; padding: 8px 12px; flex: 1; }
.sidebar nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 8px; color: var(--side-ink); font-weight: 500; }
.sidebar nav a:hover { background: rgba(255, 255, 255, 0.06); color: #fff; text-decoration: none; }
.sidebar nav a.active { background: rgba(255, 255, 255, 0.1); color: #fff; }
.sidebar-foot { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-top: 1px solid rgba(255, 255, 255, 0.08); font-size: 13px; }
.sidebar-foot strong { display: block; color: #fff; }
.canvas { padding: 28px 40px 64px; min-width: 0; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 20px; }
.page-head h1 { margin: 0; }
.page-actions { display: flex; gap: 8px; }
.crumb { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); margin-bottom: 16px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 0 12px; }

.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 20px; margin-bottom: 28px; }
.product-card { padding: 0; overflow: hidden; color: inherit; transition: box-shadow 0.15s; }
.product-card:hover { box-shadow: 0 10px 24px rgba(16, 24, 40, 0.1); text-decoration: none; }
.product-card .cover { font-size: 36px; }
.product-body { padding: 14px 16px; }
.product-title { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.product-title h3 { margin: 0; }
.product-body p { margin: 4px 0 0; }
.form-card { max-width: 720px; }
.form-card > * + * { margin-top: 14px; }

.editor-cols { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 24px; align-items: start; }
.editor-cols > div > .card + .card { margin-top: 16px; }
.module { padding: 0; margin-bottom: 16px; overflow: hidden; }
.module-head { display: flex; align-items: center; gap: 4px; padding: 10px 12px; background: #fafbfc; border-bottom: 1px solid var(--line); }
.module-rename { display: flex; flex: 1; gap: 8px; }
.module-rename input { font-weight: 600; border-color: transparent; background: transparent; }
.module-rename input:hover, .module-rename input:focus { border-color: #d0d5dd; background: #fff; }
.lesson-list { list-style: none; margin: 0; padding: 0; }
.lesson-list li { display: flex; align-items: center; gap: 10px; padding: 8px 12px 8px 16px; border-bottom: 1px solid var(--line); }
.lesson-list li.muted { padding: 14px 16px; }
.lesson-list .kind { color: var(--muted); display: inline-flex; }
.lesson-link { flex: 1; color: var(--ink); font-weight: 500; }
.add-row { display: flex; gap: 8px; padding: 12px; }
.add-row input { flex: 1; }
.cover-preview { width: 100%; border-radius: 8px; }
.danger-zone { margin-top: 16px; }
.switch { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.switch input { width: 18px; height: 18px; margin: 0; accent-color: var(--brand); }
.checks { border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; margin: 0; }
.checks legend { font-weight: 500; font-size: 14px; padding: 0 4px; }
.check-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; font-weight: 400; }
.check-row input { width: 16px; height: 16px; margin: 0; accent-color: var(--brand); }
.invites { margin-bottom: 20px; border-color: #bbf7d0; }
.invites textarea { font-family: ui-monospace, Menlo, monospace; font-size: 13px; }

.table-card { padding: 0; overflow-x: auto; margin-bottom: 24px; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; background: #fafbfc; }
th, td { padding: 12px 16px; border-bottom: 1px solid var(--line); }
tr:last-child td { border-bottom: 0; }

.EasyMDEContainer .CodeMirror { border-radius: 0 0 8px 8px; border-color: #d0d5dd; font-size: 15px; }
.EasyMDEContainer .editor-toolbar { border-radius: 8px 8px 0 0; border-color: #d0d5dd; }

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  body.admin { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; flex-wrap: wrap; }
  .sidebar nav { flex-direction: row; padding: 0 8px 8px; width: 100%; overflow-x: auto; }
  .sidebar-foot { display: none; }
  .canvas { padding: 20px 16px 48px; }
  .page-head { flex-wrap: wrap; }
  .editor-cols, .grid2 { grid-template-columns: 1fr; }

  .player { grid-template-columns: 1fr; }
  .toc { display: none; position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .toc-toggle:checked ~ .toc { display: block; }
  .toc-open { display: inline-flex; margin-bottom: 16px; }
  .lesson { padding: 20px 16px 48px; }
  .lesson h1 { font-size: 22px; }
  .prose { padding: 20px; }
  .lesson-nav { flex-wrap: wrap; }
  .hero-inner { padding: 32px 16px 64px; }
  .container { padding: 24px 16px 48px; }
  .topbar { padding: 0 16px; }
}

/* ---------- Uploads ---------- */
.upload-field { display: flex; gap: 8px; margin-top: 6px; }
.upload-field input { margin: 0; flex: 1; }
.upload-field .btn { font-weight: 600; }
.btn.busy { opacity: 0.6; pointer-events: none; }
.btn.busy::after { content: "…"; }
.cover-preview[hidden] { display: none; }
.EasyMDEContainer .editor-statusbar { font-size: 12px; color: var(--muted); }

/* ---------- Auth extras ---------- */
.label-row { display: flex; justify-content: space-between; align-items: baseline; }
.label-row a { font-weight: 500; }
.center { text-align: center; margin: 20px 0 0; }

/* ---------- Account ---------- */
.account { max-width: 640px; }
.account .card + .card { margin-top: 20px; }

/* ---------- Analytics ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 16px; margin-bottom: 28px; }
.tile { display: flex; flex-direction: column; justify-content: space-between; gap: 6px; padding: 16px 18px; }
.tile-label { font-size: 13px; color: var(--muted); }
.tile-value { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; color: var(--ink); }
.stats-cols { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 24px; align-items: start; margin-bottom: 12px; }
.stats-cols .table-card { margin-bottom: 0; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
td .badge { margin-left: 8px; }
.feed { padding: 6px 18px; max-height: 520px; overflow-y: auto; }
.feed-row { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.feed-row:last-child { border-bottom: 0; }
.feed-row small { display: block; margin-top: 2px; }
.dot { flex: none; width: 8px; height: 8px; border-radius: 50%; margin-top: 7px; background: var(--muted); }
.dot.view { background: var(--brand); }
.dot.done { background: var(--ok); }
.bar-col { width: 200px; }
th.course-head { text-transform: none; letter-spacing: 0; font-size: 14px; color: var(--ink); }
.progress.inline { display: flex; align-items: center; gap: 10px; }
.progress.inline .bar { flex: 1; margin: 0; }
.progress.inline small { width: 36px; text-align: right; font-variant-numeric: tabular-nums; }
.sidebar-link { color: var(--side-ink); }
.sidebar-foot .inline button { color: var(--side-ink); }
@media (max-width: 900px) {
  .stats-cols { grid-template-columns: 1fr; }
  .bar-col { width: 120px; }
}
.activity-title { margin-top: 28px; }
.group-row td { background: #fafbfc; font-weight: 600; font-size: 13px; }
tr.unopened td:first-child { color: var(--muted); }
.login-row { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }
.login-row + .login-row { margin-top: 8px; }
