:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c1e21;
  --muted: #65676b;
  --line: #e4e6ea;
  --hover: #f0f2f5;
  --done: #22a06b;
  --accent-soft: color-mix(in srgb, var(--accent) 12%, transparent);
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 2px 8px rgba(0, 0, 0, .04);
  --error-bg: #fdecec;
  --error-text: #b42318;
  color-scheme: light;
}
/* dark: follows the system unless the visitor picked a theme with the button */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111214;
    --surface: #1b1c1f;
    --text: #e8e9eb;
    --muted: #a0a3a8;
    --line: #2c2e33;
    --hover: #24262a;
    --done: #3cc28a;
    --shadow: none;
    --error-bg: #3a1d1d;
    --error-text: #ffb4ab;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111214;
  --surface: #1b1c1f;
  --text: #e8e9eb;
  --muted: #a0a3a8;
  --line: #2c2e33;
  --hover: #24262a;
  --done: #3cc28a;
  --shadow: none;
  --error-bg: #3a1d1d;
  --error-text: #ffb4ab;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: inherit; text-decoration: none; }
img { max-width: 100%; }
.muted { color: var(--muted); }
code { font: 13px ui-monospace, Menlo, monospace; background: var(--hover); padding: 1px 5px; border-radius: 4px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn:focus-visible, a:focus-visible, summary:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.link-btn { white-space: nowrap; background: none; border: 0; color: var(--muted); font: inherit; cursor: pointer; padding: 4px; }
.link-btn:hover { color: var(--text); }

/* ---------- header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px;
  height: 60px; padding: 0 24px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; min-width: 0; }
.brand-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  display: inline-grid; place-items: center; flex: none;
  width: 34px; height: 34px; border-radius: 8px;
  background: var(--accent); color: #fff; font-weight: 800;
}
.badge.big { width: 56px; height: 56px; font-size: 26px; border-radius: 14px; }
.tabs a { display: inline-block; padding: 18px 2px; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; }
.tabs a.active { color: var(--text); border-bottom-color: var(--text); }
.userbox { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.avatar {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-weight: 700;
}

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 380px; display: grid; gap: 14px; justify-items: center;
  padding: 36px 28px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; box-shadow: var(--shadow); text-align: center;
}
.login-card h1 { margin: 4px 0 0; font-size: 22px; }
.login-card p { margin: 0; }
.login-card label { width: 100%; display: grid; gap: 6px; text-align: left; font-weight: 600; font-size: 14px; }
.login-card input {
  height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--text); font: inherit;
}
.login-card .btn { width: 100%; height: 44px; margin-top: 6px; }
.error { width: 100%; padding: 10px 12px; border-radius: 8px; background: var(--error-bg); color: var(--error-text); font-size: 14px; }

/* ---------- classroom ---------- */
.page { max-width: 1120px; margin: 0 auto; padding: 32px 24px 64px; }
.page.narrow { max-width: 640px; }
.page-title { margin: 0 0 24px; font-size: 26px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px; }
.card {
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); transition: transform .15s ease, box-shadow .15s ease;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 4px 16px rgba(0, 0, 0, .1); }
.cover { aspect-ratio: 1460 / 752; background: var(--accent-soft); display: grid; place-items: center; }
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover span { font-size: 40px; font-weight: 800; color: var(--accent); }
.card-body { display: flex; flex-direction: column; gap: 8px; padding: 16px; flex: 1; }
.card-body h2 { margin: 0; font-size: 16px; line-height: 1.35; }
.card-body p { margin: 0; font-size: 14px; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .progress-row { margin-top: auto; padding-top: 6px; }

.progress-row { display: flex; align-items: center; gap: 10px; }
.bar { flex: 1; height: 8px; border-radius: 99px; background: var(--hover); overflow: hidden; }
.bar > div { height: 100%; background: var(--done); border-radius: inherit; transition: width .3s ease; }
.pct { font-size: 13px; font-weight: 600; color: var(--muted); min-width: 36px; text-align: right; }

/* ---------- course ---------- */
.course { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 24px; max-width: 1320px; margin: 0 auto; padding: 24px; }
.sidebar {
  position: sticky; top: 84px; align-self: start;
  max-height: calc(100vh - 108px); overflow-y: auto;
  padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.back { display: inline-block; color: var(--muted); font-size: 14px; margin-bottom: 8px; }
.back:hover { color: var(--text); }
.course-title { margin: 0 0 10px; font-size: 18px; line-height: 1.3; }
.sidebar .progress-row { margin-bottom: 14px; }
.outline details { border-top: 1px solid var(--line); }
.outline details:last-child { border-bottom: 1px solid var(--line); }
.outline summary {
  list-style: none; cursor: pointer; padding: 12px 4px; font-weight: 700; font-size: 14px;
  display: flex; justify-content: space-between; gap: 8px;
}
.outline summary::-webkit-details-marker { display: none; }
.outline summary::after { content: "▾"; color: var(--muted); transition: transform .15s; }
.outline details:not([open]) summary::after { transform: rotate(-90deg); }
.outline details[open] { padding-bottom: 8px; }
.lesson-link {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 8px 8px; border-radius: 8px; font-size: 14px; color: var(--muted);
}
.lesson-link:hover { background: var(--hover); color: var(--text); }
.lesson-link.current { background: var(--accent-soft); color: var(--text); font-weight: 600; }
.check {
  flex: none; width: 20px; height: 20px; margin-top: 1px; border-radius: 50%;
  border: 2px solid var(--line); display: grid; place-items: center;
}
.check svg { width: 14px; height: 14px; fill: none; stroke: #fff; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; opacity: 0; }
.lesson-link.done .check { background: var(--done); border-color: var(--done); }
.lesson-link.done .check svg { opacity: 1; }

.lesson { min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; }
.lesson-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.lesson-head h2 { margin: 0; font-size: 22px; line-height: 1.3; }
.complete svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.complete.is-done { background: var(--done); border-color: var(--done); color: #fff; }
.player { position: relative; aspect-ratio: 16 / 9; background: #000; border-radius: 10px; overflow: hidden; margin-bottom: 18px; }
.player video, .player iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.lesson-text { max-width: 760px; }
.lesson-text img { border-radius: 8px; margin: 8px 0; }
.lesson-text ul, .lesson-text ol { padding-left: 22px; }
.lesson-text a { color: var(--accent); text-decoration: underline; }
.pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--line); }

/* ---------- small screens ---------- */
@media (max-width: 900px) {
  .course { grid-template-columns: 1fr; padding: 16px; gap: 16px; }
  .sidebar { position: static; max-height: none; order: 2; }
  .lesson { order: 1; padding: 16px; }
  .lesson-head { flex-direction: column; }
  .lesson-head .btn { width: 100%; }
}
@media (max-width: 640px) {
  .topbar { padding: 0 16px; gap: 12px; }
  .tabs { display: none; }
  .page { padding: 20px 16px 48px; }
  .pager .btn { flex: 1; }
}

/* ---------- theme button ---------- */
.theme-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px;
  border: 1px solid var(--line); border-radius: 50%;
  background: var(--surface); color: var(--muted); cursor: pointer;
}
.theme-btn:hover { color: var(--text); background: var(--hover); }
.theme-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.theme-btn .sun { display: none; }
:root[data-theme="dark"] .theme-btn .sun { display: block; }
:root[data-theme="dark"] .theme-btn .moon { display: none; }
.login-wrap .theme-btn { position: fixed; top: 16px; right: 16px; }

/* ---------- auto-complete hint ---------- */
.auto-hint { margin: -8px 0 16px; font-size: 13px; color: var(--muted); }
