:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1c2430;
  --ink-2: #5a6572;
  --ink-3: #8b95a1;
  --line: #e4e8ee;
  --accent: #3f7fd0;
  --accent-soft: #eaf2fc;
  --ok: #2f9e63;
  --ok-soft: #e6f5ec;
  --warn: #b7791f;
  --warn-soft: #fdf3e0;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .05);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
}

:root[data-theme="dark"] {
  --bg: #12161c;
  --panel: #1a2029;
  --ink: #e7ebf0;
  --ink-2: #a3adb9;
  --ink-3: #6d7885;
  --line: #2a323d;
  --accent: #6ea3e6;
  --accent-soft: #1d2b3d;
  --ok: #4fbf82;
  --ok-soft: #173024;
  --warn: #d9a441;
  --warn-soft: #33290f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .35);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161c;
    --panel: #1a2029;
    --ink: #e7ebf0;
    --ink-2: #a3adb9;
    --ink-3: #6d7885;
    --line: #2a323d;
    --accent: #6ea3e6;
    --accent-soft: #1d2b3d;
    --ok: #4fbf82;
    --ok-soft: #173024;
    --warn: #d9a441;
    --warn-soft: #33290f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.6;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 20px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 700; }
.brand:hover { text-decoration: none; }
.brand-badge {
  background: linear-gradient(135deg, #3f7fd0, #6a5cd0);
  color: #fff; border-radius: 8px; padding: 3px 9px; font-size: 14px; letter-spacing: .5px;
}
.brand-text em { font-style: normal; font-weight: 500; color: var(--ink-3); font-size: 12.5px; margin-left: 6px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.progress-pill {
  font-size: 12.5px; color: var(--ink-2); background: var(--accent-soft);
  border-radius: 999px; padding: 4px 12px; white-space: nowrap;
}

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 8px; padding: 6px 13px; font-size: 13.5px; cursor: pointer;
  transition: .15s; text-decoration: none;
}
.btn:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 3px 10px; font-size: 12.5px; border-radius: 7px; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }

/* ---------- layout ---------- */
.layout { display: flex; min-height: calc(100vh - 53px); }
.sidebar {
  width: 300px; flex: none;
  border-right: 1px solid var(--line);
  padding: 16px 12px 40px;
  position: sticky; top: 53px;
  height: calc(100vh - 53px);
  overflow-y: auto;
  background: var(--panel);
}
.main { flex: 1; min-width: 0; padding: 26px 34px 80px; }

@media (max-width: 920px) {
  .layout { flex-direction: column; }
  .sidebar { position: static; width: auto; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .main { padding: 20px 16px 60px; }
}

/* ---------- sidebar ---------- */
.search-wrap { position: relative; margin-bottom: 12px; }
.search-wrap input {
  width: 100%; padding: 8px 12px 8px 32px;
  border: 1px solid var(--line); border-radius: 9px;
  background: var(--bg); color: var(--ink); font-size: 13.5px; outline: none;
}
.search-wrap input:focus { border-color: var(--accent); }
.search-wrap::before {
  content: "⌕"; position: absolute; left: 10px; top: 6px; color: var(--ink-3); font-size: 15px;
}
.side-nav { display: flex; gap: 6px; margin-bottom: 14px; }
.side-nav .btn { flex: 1; justify-content: center; }
.side-nav .btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.topic-block { margin-bottom: 14px; }
.topic-head {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; font-weight: 600; color: var(--ink-3);
  text-transform: uppercase; letter-spacing: .4px; margin: 4px 2px 6px;
}
.topic-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.lecture-link {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 9px; border-radius: 8px; color: var(--ink);
  font-size: 13.5px; cursor: pointer; border: 0; background: none; width: 100%; text-align: left;
}
.lecture-link:hover { background: var(--bg); text-decoration: none; }
.lecture-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.lecture-link .num {
  flex: none; font-size: 11px; font-variant-numeric: tabular-nums;
  color: var(--ink-3); width: 20px; text-align: right;
}
.lecture-link .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lecture-link .tick { flex: none; color: var(--ok); font-weight: 700; }
.lecture-link.no-slides { opacity: .55; }

/* ---------- cards / generic ---------- */
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px 22px; margin-bottom: 18px;
}
.card h2 { margin: 0 0 4px; font-size: 17px; }
.card h3 { margin: 0 0 10px; font-size: 15px; }
.muted { color: var(--ink-2); }
.tiny { font-size: 12.5px; color: var(--ink-3); }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 600; border-radius: 999px; padding: 2px 10px;
}
.badge.topic { color: #fff; }
.badge.hw { background: var(--warn-soft); color: var(--warn); }

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ---------- home ---------- */
.hero { padding: 26px 28px; }
.hero h1 { margin: 0 0 6px; font-size: 24px; }
.hero p { margin: 0 0 16px; color: var(--ink-2); }
.progressbar { height: 9px; border-radius: 999px; background: var(--line); overflow: hidden; margin: 10px 0 6px; }
.progressbar > div { height: 100%; background: linear-gradient(90deg, var(--accent), #6a5cd0); border-radius: 999px; transition: width .4s; }
.stat-row { display: flex; gap: 26px; flex-wrap: wrap; margin-top: 14px; }
.stat b { font-size: 20px; display: block; }
.stat span { font-size: 12.5px; color: var(--ink-3); }

.group-title { display: flex; align-items: center; gap: 8px; margin: 26px 0 10px; font-size: 16px; }
.group-title .topic-dot { width: 11px; height: 11px; }
.group-title small { color: var(--ink-3); font-weight: 400; }

.lec-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 11px 16px; margin-bottom: 8px; box-shadow: var(--shadow);
}
.lec-row .no { font-size: 13px; color: var(--ink-3); width: 42px; flex: none; font-variant-numeric: tabular-nums; }
.lec-row .body { flex: 1; min-width: 0; }
.lec-row .title { font-weight: 600; cursor: pointer; }
.lec-row .title:hover { color: var(--accent); }
.lec-row .meta { font-size: 12.5px; color: var(--ink-3); margin-top: 1px; }
.lec-row .actions { display: flex; gap: 6px; flex: none; align-items: center; }

/* ---------- lecture detail ---------- */
.lecture-head h1 { margin: 0 0 8px; font-size: 22px; line-height: 1.35; }
.lecture-head .meta-line { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 4px; }
.pager { display: flex; justify-content: space-between; gap: 10px; margin: 18px 0 26px; }

.file-list { display: flex; flex-direction: column; gap: 8px; }
.file-item {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px;
}
.file-item .icon { flex: none; font-size: 16px; width: 24px; text-align: center; }
.file-item .fi-body { flex: 1; min-width: 0; }
.file-item .fi-name { font-weight: 500; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: rtl; text-align: left; }
.file-item .fi-sub { font-size: 12px; color: var(--ink-3); }
.file-item .fi-actions { display: flex; gap: 6px; flex: none; }
.fi-name.read, .li-name.read { color: var(--ink-3); }

.pdf-frame { width: 100%; height: 78vh; border: 1px solid var(--line); border-radius: 10px; background: #3c434c; }
.embed-wrap { margin-top: 10px; }
.reading-preview { margin: 6px 0 10px; }
.reading-preview iframe {
  width: 100%; height: 75vh; display: block;
  border: 1px solid var(--line); border-radius: 10px; background: #3c434c;
}

textarea.notes {
  width: 100%; min-height: 130px; resize: vertical;
  border: 1px solid var(--line); border-radius: 10px; padding: 12px;
  font: inherit; color: var(--ink); background: var(--bg); outline: none;
}
textarea.notes:focus { border-color: var(--accent); }
.save-hint { font-size: 12px; color: var(--ok); opacity: 0; transition: opacity .3s; }
.save-hint.show { opacity: 1; }

.complete-row { display: flex; align-items: center; gap: 10px; }
.empty-tip { color: var(--ink-3); font-size: 13.5px; padding: 8px 2px; }

/* ---------- library ---------- */
.lib-row {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 4px; border-bottom: 1px solid var(--line);
}
.lib-row:last-child { border-bottom: 0; }
.lib-row .icon { width: 24px; text-align: center; flex: none; }
.lib-row .li-body { flex: 1; min-width: 0; }
.lib-row .li-name { font-weight: 500; font-size: 14px; }
.lib-row .li-sub { font-size: 12px; color: var(--ink-3); }
.lib-row .actions { display: flex; gap: 6px; flex: none; }
.filter-chips { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.filter-chips .btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.footnote { margin-top: 34px; font-size: 12.5px; color: var(--ink-3); line-height: 1.8; }
