:root {
  --bg: #f4f3f8;
  --surface: #ffffff;
  --text: #1c1a24;
  --muted: #6b6878;
  --border: rgba(20, 16, 40, 0.1);
  --accent: #6750d8;
  --accent-soft: rgba(103, 80, 216, 0.1);
  --on-accent: #fff;
  --shadow: 0 1px 2px rgba(20, 16, 40, 0.06), 0 6px 20px rgba(20, 16, 40, 0.06);
  --shadow-hover: 0 2px 4px rgba(20, 16, 40, 0.08), 0 14px 34px rgba(20, 16, 40, 0.12);
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #111115;
  --surface: #1b1b21;
  --text: #ecebf2;
  --muted: #9b98a8;
  --border: rgba(255, 255, 255, 0.09);
  --accent: #b7a6ff;
  --accent-soft: rgba(183, 166, 255, 0.13);
  --on-accent: #1b1530;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-hover: 0 14px 34px rgba(0, 0, 0, 0.45);
  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.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: inherit; text-decoration: none; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Top bar */
.top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px;
  padding: 10px max(16px, calc((100vw - 1180px) / 2)); background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; white-space: nowrap; }
.brand svg { color: var(--accent); width: 24px; height: 24px; }
.search {
  flex: 1; max-width: 420px; margin-left: auto; display: flex; align-items: center; gap: 8px; padding: 0 12px; height: 40px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px; color: var(--muted);
}
.search:focus-within { border-color: var(--accent); }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; color: var(--text); font: inherit; }
.search kbd { font: 12px ui-monospace, monospace; border: 1px solid var(--border); border-radius: 5px; padding: 0 5px; }
.icon-btn {
  width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer;
}
.icon-btn:hover { color: var(--accent); }

main { max-width: 1180px; margin: 0 auto; padding: 24px 16px 64px; }

/* Home */
.hero { padding: 20px 0 28px; }
.hero h1 { margin: 0; font-size: clamp(28px, 4vw, 40px); letter-spacing: -0.02em; line-height: 1.15; }
.hero p { margin: 8px 0 0; color: var(--muted); font-size: 17px; max-width: 640px; }
.hero .stats { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; align-items: center; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 13px; }
.btn {
  display: inline-flex; align-items: center; gap: 8px; height: 42px; padding: 0 18px; border-radius: 999px; border: 0; cursor: pointer;
  background: var(--accent); color: var(--on-accent); font: 600 15px system-ui, sans-serif;
}
.btn:hover { filter: brightness(1.07); }
.btn.ghost { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn svg { width: 18px; height: 18px; }

.grid { display: grid; gap: 18px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.card {
  display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; overflow: hidden;
  box-shadow: var(--shadow); transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover); }
.cover { position: relative; aspect-ratio: 16 / 9; background: var(--bg); overflow: hidden; border-bottom: 1px solid var(--border); }
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover .initials {
  position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: 44px; font-weight: 800; letter-spacing: -0.03em;
}
.cover .badge {
  position: absolute; right: 8px; bottom: 8px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: rgba(20, 18, 30, 0.72); color: #fff; backdrop-filter: blur(4px);
}
.cover .seen {
  position: absolute; left: 8px; top: 8px; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: var(--on-accent);
}
.cover .seen svg { width: 14px; height: 14px; stroke-width: 3; }
.card .body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.card h3 { margin: 0; font-size: 16px; line-height: 1.3; }
.card .desc { color: var(--muted); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .meta { color: var(--muted); font-size: 13px; margin-top: auto; padding-top: 4px; }
.num { color: var(--accent); font-weight: 700; margin-right: 6px; font-variant-numeric: tabular-nums; }
.card-wrap { position: relative; display: flex; }
.card-wrap > .card { flex: 1; min-width: 0; }
.yt {
  position: absolute; right: 8px; top: 8px; z-index: 1; display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px 3px 7px;
  border-radius: 999px; background: #e62117; color: #fff; font-size: 12px; font-weight: 700; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}
.yt:hover { filter: brightness(1.1); }
.yt { transition: transform 0.15s ease; }
.card-wrap:hover .yt { transform: translateY(-2px); }
.yt svg { width: 16px; height: 16px; }

/* Course */
.crumbs { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 14px; }
.crumbs a:hover { color: var(--accent); }
.crumbs svg { width: 16px; height: 16px; }
.course-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px 24px; justify-content: space-between; padding: 8px 0 24px; }
.course-head h1 { margin: 6px 0 0; font-size: clamp(26px, 3.6vw, 36px); letter-spacing: -0.02em; line-height: 1.15; }
.course-head p { margin: 6px 0 0; color: var(--muted); max-width: 680px; }
.course-head .stats { margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; }
.chapter { margin-top: 28px; }
.chapter > header { display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.chapter h2 { margin: 0; font-size: 20px; }
.chapter h2 .num { font-size: 15px; }
.chapter header small { color: var(--muted); }

/* Search results */
.results { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex; gap: 14px; align-items: center; padding: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
}
.row:hover { border-color: var(--accent); }
.row .cover { width: 128px; flex: none; border-radius: 10px; border: 1px solid var(--border); }
.row h3 { margin: 0; font-size: 16px; line-height: 1.3; }
.row-body { flex: 1; min-width: 0; }
.row > svg { color: var(--muted); margin-right: 6px; }
.row-wrap { position: relative; display: flex; }
.row-wrap > .row { flex: 1; min-width: 0; padding-right: 48px; }
.row-wrap > .yt { top: 50%; right: 12px; transform: translateY(-50%); }
.folder-icon {
  width: 56px; height: 56px; flex: none; display: grid; place-items: center; border-radius: 12px; background: var(--accent-soft); color: var(--accent);
}
.folder-icon svg { width: 26px; height: 26px; }
.yt.small { padding: 5px; }
.yt.small svg { width: 18px; height: 18px; }
.section-desc { margin: -4px 0 12px; color: var(--muted); }
.chapter h2 a:hover { color: var(--accent); }
.crumbs .sep { opacity: 0.6; }
.crumbs .home { display: inline-flex; align-items: center; gap: 4px; }

/* View switch */
.toolbar { display: flex; justify-content: flex-end; margin: -8px 0 16px; }
.views { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; }
.views button {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border: 0; border-radius: 999px; cursor: pointer;
  background: none; color: var(--muted); font: 600 13px system-ui, sans-serif;
}
.views button svg { width: 16px; height: 16px; }
.views button.on { background: var(--accent-soft); color: var(--accent); }
.btn.small { height: 32px; padding: 0 12px; font-size: 13px; }

/* Tree */
.tree-tools { display: flex; gap: 8px; margin-bottom: 10px; }
.tree { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 8px; }
.tree summary, .tnote {
  display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 8px; cursor: pointer; min-width: 0;
}
.tree summary { list-style: none; font-weight: 600; }
.tree summary::-webkit-details-marker { display: none; }
.tree summary:hover, .tnote:hover { background: var(--accent-soft); }
.tree summary > svg:first-child { width: 16px; height: 16px; color: var(--muted); transition: transform 0.15s ease; }
.tree details[open] > summary > svg:first-child { transform: rotate(90deg); }
.tree summary > svg + svg { width: 18px; height: 18px; color: var(--accent); }
.tree small { color: var(--muted); font-weight: 400; font-size: 13px; white-space: nowrap; }
.tt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tkids { margin-left: 15px; padding-left: 10px; border-left: 1px solid var(--border); }
.topen { margin-left: auto; color: var(--accent); font-size: 13px; font-weight: 600; padding: 0 4px; }
.tline { display: flex; align-items: center; gap: 6px; }
.tline > .tnote { flex: 1; }
.tline > .tnote small { margin-left: auto; }
.tline > .yt { position: static; }
.tick { width: 18px; height: 18px; flex: none; display: grid; place-items: center; border-radius: 50%; border: 1.5px solid var(--border); }
.tick.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.tick svg { width: 12px; height: 12px; stroke-width: 3; }
.row .where { color: var(--muted); font-size: 13px; }
.row mark { background: var(--accent-soft); color: var(--accent); border-radius: 3px; }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.empty h2 { color: var(--text); margin: 0 0 6px; }
.empty code { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 1px 6px; }

footer.foot { margin-top: 48px; color: var(--muted); font-size: 13px; text-align: center; }

@media (max-width: 560px) {
  .brand span { display: none; }
  .search kbd { display: none; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
  .row .cover { width: 96px; }
  .views button span { display: none; }
  .tline > .tnote small { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .card { transition: none; }
  .card:hover { transform: none; }
  .card-wrap:hover .yt { transform: none; }
}
