:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #172033;
  --muted: #667085;
  --line: #e4e7ec;
  --accent: #2563eb;
  --accent-soft: #eaf1ff;
  --code-bg: #111827;
  --code-text: #dbeafe;
  --shadow: 0 10px 35px rgba(16, 24, 40, 0.08);
  --radius: 16px;
}

[data-theme="dark"] {
  --bg: #0b1020;
  --surface: #11182a;
  --surface-soft: #161f34;
  --text: #e7ecf5;
  --muted: #9aa7bd;
  --line: #27324a;
  --accent: #7aa2ff;
  --accent-soft: #1b2b50;
  --code-bg: #090e1a;
  --code-text: #dbeafe;
  --shadow: 0 14px 38px rgba(0, 0, 0, 0.24);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 84px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15.5px/1.75 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  transition: background .2s, color .2s;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input { font: inherit; }

.progress { position: fixed; z-index: 100; inset: 0 auto auto 0; height: 3px; width: 0; background: var(--accent); }
.topbar {
  position: sticky; top: 0; z-index: 50; height: 64px; border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 90%, transparent); backdrop-filter: blur(14px);
}
.topbar-inner { height: 100%; max-width: 1500px; margin: auto; padding: 0 24px; display: flex; align-items: center; gap: 20px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 750; letter-spacing: -.02em; }
.brand:hover { text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 10px; color: white; background: var(--accent); }
.course-nav { display: flex; gap: 4px; margin-left: auto; }
.course-nav a { color: var(--muted); padding: 7px 11px; border-radius: 9px; }
.course-nav a:hover, .course-nav a.active { color: var(--accent); background: var(--accent-soft); text-decoration: none; }
.icon-button { display: grid; place-items: center; width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 10px; color: var(--text); background: var(--surface); cursor: pointer; }
.menu-button { display: none; }

.page-shell { max-width: 1500px; margin: auto; display: grid; grid-template-columns: 280px minmax(0, 860px); gap: 48px; justify-content: center; padding: 38px 32px 80px; }
.sidebar { position: sticky; top: 92px; align-self: start; max-height: calc(100vh - 116px); overflow: auto; scrollbar-width: thin; }
.side-label { margin: 0 0 12px; color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: .11em; text-transform: uppercase; }
.toc ul { margin: 0; padding: 0; list-style: none; }
.toc ul ul { margin: 3px 0 4px 12px; padding-left: 12px; border-left: 1px solid var(--line); }
.toc a { display: block; padding: 5px 9px; border-radius: 7px; color: var(--muted); line-height: 1.45; font-size: 13.5px; }
.toc a:hover, .toc a.active { color: var(--accent); background: var(--accent-soft); text-decoration: none; }

.search-wrap { position: relative; margin-bottom: 22px; }
.search { width: 100%; padding: 10px 38px 10px 13px; border: 1px solid var(--line); border-radius: 10px; outline: 0; color: var(--text); background: var(--surface); }
.search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-hint { position: absolute; right: 9px; top: 9px; padding: 1px 6px; border: 1px solid var(--line); border-radius: 5px; color: var(--muted); font-size: 11px; }
.search-results { display: none; position: absolute; z-index: 20; top: 48px; left: 0; width: min(560px, 78vw); max-height: 440px; overflow: auto; padding: 7px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); }
.search-results.open { display: block; }
.search-result { display: block; padding: 10px; border-radius: 8px; color: var(--text); cursor: pointer; }
.search-result:hover { background: var(--surface-soft); text-decoration: none; }
.search-result strong { display: block; color: var(--accent); font-size: 13px; }
.search-result span { display: block; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.article { min-width: 0; }
.article-header { margin-bottom: 32px; padding: 30px 32px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.eyebrow { margin: 0 0 7px; color: var(--accent); font-size: 13px; font-weight: 750; letter-spacing: .08em; }
.article-header h1 { margin: 0; font-size: clamp(29px, 4vw, 44px); line-height: 1.18; letter-spacing: -.04em; }
.article-header p { margin: 10px 0 0; color: var(--muted); }
.article-body { padding: 12px 32px 46px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.article-body > h1:first-child { display: none; }
h2 { margin: 42px 0 15px; padding-bottom: 10px; border-bottom: 1px solid var(--line); font-size: 25px; line-height: 1.35; letter-spacing: -.02em; }
h3 { margin: 31px 0 10px; font-size: 20px; line-height: 1.4; }
h4 { margin: 25px 0 8px; font-size: 17px; line-height: 1.45; }
h5 { font-size: 15.5px; }
p, li { color: color-mix(in srgb, var(--text) 92%, var(--muted)); }
strong { color: var(--text); }
blockquote { margin: 20px 0; padding: 13px 18px; border-left: 4px solid var(--accent); border-radius: 0 10px 10px 0; background: var(--accent-soft); }
hr { border: 0; border-top: 1px solid var(--line); margin: 32px 0; }
.article-body ul, .article-body ol { padding-left: 24px; }
.article-body li + li { margin-top: 3px; }

.table-wrap { margin: 20px 0; overflow: auto; border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; min-width: 560px; }
th, td { padding: 10px 13px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: var(--surface-soft); color: var(--text); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }

code { padding: .12em .35em; border-radius: 5px; color: #c2410c; background: #fff2e8; font: .91em/1.5 "JetBrains Mono", "SFMono-Regular", Consolas, monospace; }
[data-theme="dark"] code { color: #fdba74; background: #2b1c19; }
.code-block { position: relative; margin: 18px 0 24px; }
pre { margin: 0; overflow: auto; padding: 20px; border: 1px solid #263247; border-radius: 12px; background: var(--code-bg); color: var(--code-text); tab-size: 2; }
pre code { display: block; min-width: max-content; padding: 0; color: inherit; background: transparent; font-size: 13.5px; line-height: 1.7; }
.code-lang { position: absolute; top: 8px; right: 54px; color: #8fa2bf; font: 11px/1.2 ui-monospace, monospace; text-transform: uppercase; }
.copy-code { position: absolute; top: 7px; right: 8px; padding: 4px 8px; border: 1px solid #35435c; border-radius: 6px; color: #b9c5d8; background: #192235; cursor: pointer; font-size: 11px; }
.copy-code:hover { color: white; border-color: #60708d; }
.tok-comment { color: #7f8ea8; font-style: italic; }
.tok-string { color: #a7d7a4; }
.tok-number { color: #f6c177; }
.tok-keyword { color: #88aaff; font-weight: 600; }
.tok-type { color: #73daca; }
.tok-literal { color: #f2a6c7; }

.flash { animation: flash 1.4s ease; }
@keyframes flash { 0%, 55% { background: color-mix(in srgb, var(--accent) 18%, transparent); } 100% { background: transparent; } }
.back-top { position: fixed; right: 24px; bottom: 24px; display: grid; place-items: center; width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 12px; color: var(--text); background: var(--surface); box-shadow: var(--shadow); cursor: pointer; opacity: 0; pointer-events: none; transform: translateY(8px); transition: .2s; }
.back-top.show { opacity: 1; pointer-events: auto; transform: none; }

.hero { max-width: 1120px; margin: auto; padding: 92px 28px 42px; text-align: center; }
.hero-badge { display: inline-flex; padding: 6px 11px; border: 1px solid var(--line); border-radius: 999px; color: var(--accent); background: var(--surface); font-size: 13px; }
.hero h1 { max-width: 760px; margin: 20px auto 14px; font-size: clamp(38px, 7vw, 70px); line-height: 1.08; letter-spacing: -.055em; }
.hero p { max-width: 650px; margin: auto; color: var(--muted); font-size: 17px; }
.course-grid { max-width: 1120px; margin: 0 auto; padding: 30px 28px 100px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.course-card { position: relative; overflow: hidden; min-height: 250px; padding: 26px; border: 1px solid var(--line); border-radius: 18px; color: var(--text); background: var(--surface); box-shadow: var(--shadow); transition: transform .2s, border-color .2s; }
.course-card:hover { transform: translateY(-4px); border-color: var(--card-accent); text-decoration: none; }
.course-card::before { content: ""; position: absolute; width: 150px; height: 150px; right: -65px; top: -65px; border-radius: 50%; background: var(--card-soft); }
.card-icon { display: grid; place-items: center; width: 45px; height: 45px; border-radius: 13px; color: var(--card-accent); background: var(--card-soft); font-weight: 800; }
.course-card h2 { margin: 40px 0 7px; padding: 0; border: 0; font-size: 24px; }
.course-card p { margin: 0; color: var(--muted); }
.card-meta { position: absolute; bottom: 24px; color: var(--card-accent); font-weight: 700; font-size: 13px; }
.hive-card { --card-accent: #0f9f70; --card-soft: #e3f8f0; }
.spark-card { --card-accent: #e85d2a; --card-soft: #fff0e9; }
.uml-card { --card-accent: #7559d9; --card-soft: #f0ecff; }
[data-theme="dark"] .hive-card { --card-soft: #153b31; }
[data-theme="dark"] .spark-card { --card-soft: #40251d; }
[data-theme="dark"] .uml-card { --card-soft: #292246; }

@media (max-width: 900px) {
  .page-shell { display: block; padding: 24px 18px 65px; }
  .sidebar { position: fixed; z-index: 70; inset: 64px auto 0 0; width: min(320px, 86vw); max-height: none; padding: 24px; border-right: 1px solid var(--line); background: var(--surface); transform: translateX(-105%); transition: transform .2s; }
  body.menu-open .sidebar { transform: none; box-shadow: var(--shadow); }
  .menu-button { display: grid; }
  .article-header, .article-body { padding-left: 22px; padding-right: 22px; }
  .course-nav { display: none; }
  .course-grid { grid-template-columns: 1fr; max-width: 650px; }
  .course-card { min-height: 220px; }
}

@media (max-width: 520px) {
  .topbar-inner { padding: 0 14px; gap: 10px; }
  .brand span:last-child { display: none; }
  .article-header { padding: 23px 20px; }
  .article-body { padding: 5px 18px 35px; }
  .hero { padding-top: 64px; }
  .hero h1 { font-size: 42px; }
}

@media print {
  .topbar, .sidebar, .back-top, .progress, .copy-code { display: none !important; }
  body { background: white; color: black; }
  .page-shell { display: block; padding: 0; }
  .article-header, .article-body { border: 0; box-shadow: none; padding: 0; }
  pre { white-space: pre-wrap; }
}
