/* ========== Tokens ========== */
:root {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --panel-2: #f1f1ee;
  --text: #1d1d1f;
  --muted: #6b6b70;
  --line: #e4e4e0;
  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --ok: #16a34a;
  --ok-soft: #e8f7ee;
  --warn: #d97706;
  --warn-soft: #fff6e5;
  --bad: #dc2626;
  --bad-soft: #fdeeee;
  --code-bg: #f3f3f0;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  --radius: 12px;
  --sidebar: 280px;
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  --mono: "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #121214;
  --panel: #1b1b1f;
  --panel-2: #232328;
  --text: #ececf0;
  --muted: #9a9aa3;
  --line: #2e2e35;
  --accent: #8b85ff;
  --accent-soft: #25234a;
  --ok: #4ade80;
  --ok-soft: #14301f;
  --warn: #fbbf24;
  --warn-soft: #33290f;
  --bad: #f87171;
  --bad-soft: #3a1818;
  --code-bg: #24242a;
  --shadow: none;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121214; --panel: #1b1b1f; --panel-2: #232328; --text: #ececf0; --muted: #9a9aa3;
    --line: #2e2e35; --accent: #8b85ff; --accent-soft: #25234a; --ok: #4ade80; --ok-soft: #14301f;
    --warn: #fbbf24; --warn-soft: #33290f; --bad: #f87171; --bad-soft: #3a1818; --code-bg: #24242a;
    --shadow: none; color-scheme: dark;
  }
}

/* ========== Base ========== */
* { box-sizing: border-box; }
html { scroll-padding-top: 72px; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.75 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre { font-family: var(--mono); font-size: .88em; }
code { background: var(--code-bg); padding: .1em .4em; border-radius: 5px; overflow-wrap: anywhere; }
pre code { overflow-wrap: normal; }
pre { background: var(--code-bg); padding: 14px 16px; border-radius: 10px; overflow-x: auto; line-height: 1.55; }
pre code { background: none; padding: 0; font-size: 13.5px; }
button { font: inherit; color: inherit; }
input, select, textarea { font: inherit; color: var(--text); }
h1, h2, h3 { line-height: 1.35; }

/* ========== Topbar ========== */
.topbar { position: sticky; top: 0; z-index: 30; height: 56px; display: flex; align-items: center; gap: 14px; padding: 0 16px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.logo { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: var(--accent); color: #fff; font-size: 15px; }
.top-progress { display: flex; align-items: center; gap: 8px; margin-left: auto; font-size: 13px; color: var(--muted); }
.top-progress .bar { width: 120px; height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; }
.top-progress .bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .4s; }
.top-links { display: flex; gap: 4px; }
.top-links a { color: var(--muted); padding: 6px 10px; border-radius: 8px; font-size: 14px; }
.top-links a:hover, .top-links a.active { background: var(--panel-2); color: var(--text); text-decoration: none; }
.icon-btn { border: 1px solid var(--line); background: var(--panel); width: 34px; height: 34px; border-radius: 9px; cursor: pointer; flex: none; }
#menuBtn { display: none; }

/* ========== Layout ========== */
.layout { display: flex; }
#sidebar { position: sticky; top: 56px; height: calc(100vh - 56px); width: var(--sidebar); flex: none; overflow-y: auto; padding: 18px 12px 40px; border-right: 1px solid var(--line); }
#main { flex: 1; min-width: 0; padding: 32px 40px 80px; }
.page { max-width: 780px; margin: 0 auto; }
.scrim { display: none; }

/* Sidebar */
.nav-part { margin-bottom: 16px; }
.nav-part-title { font-size: 12px; font-weight: 600; letter-spacing: .04em; color: var(--muted); padding: 4px 10px; display: flex; justify-content: space-between; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px; color: var(--text); font-size: 14.5px; line-height: 1.4; }
.nav-item:hover { background: var(--panel-2); text-decoration: none; }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-num { width: 22px; height: 22px; flex: none; border-radius: 50%; display: grid; place-items: center; font-size: 11px; border: 1.5px solid var(--line); color: var(--muted); }
.nav-item.done .nav-num { background: var(--ok); border-color: var(--ok); color: #fff; }
.nav-item.active .nav-num { border-color: var(--accent); color: var(--accent); }
.nav-item.done.active .nav-num { color: #fff; }

/* ========== Chapter ========== */
.crumb { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.ch-title { font-size: 32px; margin: 0 0 10px; letter-spacing: -.01em; }
.ch-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 22px; }
.chip { font-size: 12.5px; padding: 2px 10px; border-radius: 99px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.chip.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.tldr { background: var(--accent-soft); border-radius: var(--radius); padding: 16px 20px; margin: 0 0 28px; border-left: 4px solid var(--accent); }
.tldr b { color: var(--accent); }
.tldr ul { margin: 6px 0 0; padding-left: 20px; }

.content h2 { font-size: 22px; margin: 40px 0 12px; padding-top: 8px; }
.content h3 { font-size: 17.5px; margin: 26px 0 8px; }
.content p { margin: 10px 0; }
.content ul, .content ol { padding-left: 22px; }
.content li { margin: 4px 0; }
.content table { width: 100%; border-collapse: collapse; margin: 14px 0; font-size: 14.5px; display: block; overflow-x: auto; }
.content th, .content td { border: 1px solid var(--line); padding: 8px 12px; text-align: left; vertical-align: top; }
.content th { background: var(--panel-2); font-weight: 600; white-space: nowrap; }
.content img { max-width: 100%; }

/* Callouts */
.note, .key, .warn, .pitfall { border-radius: 10px; padding: 12px 16px; margin: 14px 0; font-size: 15px; }
.note { background: var(--panel-2); }
.key { background: var(--ok-soft); border-left: 3px solid var(--ok); }
.warn, .pitfall { background: var(--warn-soft); border-left: 3px solid var(--warn); }
.note::before { content: "💡 "; } .key::before { content: "✅ "; font-weight: 600; } .warn::before, .pitfall::before { content: "⚠️ "; }
.analogy { border: 1px dashed var(--line); border-radius: 10px; padding: 12px 16px; margin: 14px 0; color: var(--muted); }
.analogy::before { content: "🧠 类比："; color: var(--text); font-weight: 600; }

/* Formula */
.formula { text-align: center; margin: 16px 0; padding: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow-x: auto; }

/* Grid cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin: 14px 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); font-size: 15px; }
.card h4 { margin: 0 0 6px; font-size: 15.5px; }
.card p { margin: 0; color: var(--muted); font-size: 14px; }

/* Steps / flow */
.flow { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 14px 0; }
.flow > span { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; font-size: 14px; }
.flow > i { color: var(--muted); font-style: normal; }

/* ========== Demo ========== */
.demo { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin: 20px 0; box-shadow: var(--shadow); }
.demo-title { font-weight: 700; font-size: 15px; margin-bottom: 4px; display: flex; align-items: center; gap: 8px; }
.demo-title::before { content: "▶"; font-size: 10px; color: #fff; background: var(--accent); width: 20px; height: 20px; border-radius: 6px; display: grid; place-items: center; }
.demo-hint { color: var(--muted); font-size: 13.5px; margin-bottom: 14px; }
.demo .row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 8px 0; }
.demo label { font-size: 14px; color: var(--muted); }
.demo input[type=range] { accent-color: var(--accent); width: 180px; }
.demo input[type=text], .demo textarea, .demo select { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; width: 100%; }
.demo textarea { min-height: 70px; resize: vertical; }
.btn { border: 1px solid var(--line); background: var(--panel-2); padding: 6px 14px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.mono { font-family: var(--mono); font-size: 13px; }
.out { background: var(--code-bg); border-radius: 8px; padding: 10px 12px; font-family: var(--mono); font-size: 13px; white-space: pre-wrap; word-break: break-word; margin-top: 10px; }
.tok { display: inline-block; padding: 1px 4px; margin: 2px 1px; border-radius: 4px; font-family: var(--mono); font-size: 13.5px; }
.bars { display: grid; gap: 4px; margin-top: 8px; }
.bar-row { display: grid; grid-template-columns: 90px 1fr 56px; gap: 8px; align-items: center; font-size: 13.5px; }
.bar-row .track { height: 16px; background: var(--panel-2); border-radius: 4px; overflow: hidden; }
.bar-row .fill { height: 100%; background: var(--accent); border-radius: 4px; transition: width .25s; }
.bar-row .fill.dim { opacity: .3; }
.bar-row .v { font-family: var(--mono); font-size: 12px; color: var(--muted); text-align: right; }
.heat { border-collapse: collapse; font-size: 12.5px; font-family: var(--mono); }
.heat td, .heat th { width: 46px; height: 34px; text-align: center; border: 1px solid var(--line); padding: 0; }
.heat th { font-weight: 500; color: var(--muted); background: var(--panel-2); }
.legend { font-size: 12.5px; color: var(--muted); }
svg text { fill: var(--text); }

/* ========== Interview Q&A ========== */
.qa { border: 1px solid var(--line); border-radius: 10px; margin: 8px 0; background: var(--panel); overflow: hidden; }
.qa summary { cursor: pointer; padding: 12px 16px; font-weight: 600; list-style: none; display: flex; gap: 10px; align-items: flex-start; font-size: 15px; }
.qa summary::-webkit-details-marker { display: none; }
.qa summary::before { content: "Q"; flex: none; width: 22px; height: 22px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-size: 12px; margin-top: 2px; }
.qa[open] summary { border-bottom: 1px solid var(--line); }
.qa .ans { padding: 10px 16px 14px 48px; font-size: 15px; }
.qa .ans p:first-child { margin-top: 0; }
.qa .lvl { margin-left: auto; font-size: 11.5px; font-weight: 500; color: var(--muted); white-space: nowrap; padding-top: 2px; }

/* ========== Quiz ========== */
.quiz { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin: 12px 0; }
.quiz .q { font-weight: 600; margin-bottom: 10px; }
.quiz .opt { display: block; width: 100%; text-align: left; border: 1px solid var(--line); background: var(--bg); padding: 9px 12px; border-radius: 8px; margin: 6px 0; cursor: pointer; font-size: 15px; }
.quiz .opt:hover:not(:disabled) { border-color: var(--accent); }
.quiz .opt.right { background: var(--ok-soft); border-color: var(--ok); }
.quiz .opt.wrong { background: var(--bad-soft); border-color: var(--bad); }
.quiz .explain { font-size: 14.5px; color: var(--muted); margin-top: 8px; display: none; }
.quiz.answered .explain { display: block; }

/* Chapter footer */
.ch-footer { margin-top: 48px; padding-top: 24px; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: center; }
.done-btn { padding: 10px 18px; border-radius: 10px; font-weight: 600; cursor: pointer; border: 1.5px solid var(--ok); background: transparent; color: var(--ok); }
.done-btn.is-done { background: var(--ok); color: #fff; }
.pager { display: flex; gap: 10px; flex-wrap: wrap; }
.pager a { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 8px 14px; font-size: 14px; color: var(--text); }
.pager a small { display: block; color: var(--muted); font-size: 12px; }
.pager a:hover { border-color: var(--accent); text-decoration: none; }

/* ========== Home ========== */
.hero { padding: 20px 0 10px; }
.hero h1 { font-size: 38px; margin: 0 0 10px; letter-spacing: -.02em; }
.hero h1 em { font-style: normal; color: var(--accent); }
.hero p { color: var(--muted); font-size: 17px; margin: 0 0 18px; max-width: 620px; }
.hero .cta { display: flex; gap: 10px; flex-wrap: wrap; }
.hero .cta a { padding: 10px 18px; border-radius: 10px; font-weight: 600; }
.hero .cta a.primary { background: var(--accent); color: #fff; }
.hero .cta a.ghost { border: 1px solid var(--line); color: var(--text); background: var(--panel); }
.hero .cta a:hover { text-decoration: none; opacity: .92; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 28px 0; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat b { display: block; font-size: 24px; }
.stat span { font-size: 13px; color: var(--muted); }
.road { position: relative; margin: 20px 0; }
.road-part { margin: 0 0 22px; }
.road-part h3 { margin: 0 0 4px; font-size: 18px; }
.road-part > p { margin: 0 0 10px; color: var(--muted); font-size: 14.5px; }
.road-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.road-item { display: block; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; color: var(--text); position: relative; }
.road-item:hover { border-color: var(--accent); text-decoration: none; }
.road-item .n { font-size: 12px; color: var(--muted); font-family: var(--mono); }
.road-item .t { font-weight: 600; display: block; margin: 2px 0; }
.road-item .s { font-size: 13px; color: var(--muted); line-height: 1.5; display: block; }
.road-item.done::after { content: "✓"; position: absolute; top: 10px; right: 12px; color: var(--ok); font-weight: 700; }
.howto { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin: 10px 0 30px; }

/* ========== Flashcards / glossary ========== */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 14px 0 18px; }
.toolbar input { flex: 1; min-width: 200px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; }
.toolbar select { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; }
.flash { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; min-height: 240px; box-shadow: var(--shadow); }
.flash .from { font-size: 12.5px; color: var(--muted); }
.flash .fq { font-size: 21px; font-weight: 700; margin: 8px 0 16px; }
.flash .fa { border-top: 1px dashed var(--line); padding-top: 14px; }
.gl-item { padding: 12px 0; border-bottom: 1px solid var(--line); }
.gl-item b { font-size: 15.5px; }
.gl-item p { margin: 4px 0 0; color: var(--muted); font-size: 14.5px; }
.gl-item a { font-size: 12.5px; }
.log-item { border-left: 2px solid var(--line); padding: 0 0 18px 18px; position: relative; }
.log-item::before { content: ""; position: absolute; left: -6px; top: 8px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.log-item h3 { margin: 0; font-size: 16px; }
.log-item time { font-size: 13px; color: var(--muted); }

/* ========== Responsive ========== */
@media (max-width: 960px) {
  #menuBtn { display: block; }
  #sidebar { position: fixed; left: 0; top: 56px; z-index: 25; background: var(--bg); transform: translateX(-100%); transition: transform .2s; }
  body.nav-open #sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 56px 0 0 0; background: rgba(0,0,0,.35); z-index: 20; }
  #main { padding: 24px 16px 60px; }
  .top-progress .bar { width: 60px; }
}
@media (max-width: 640px) {
  .top-links { display: none; }
  .ch-title { font-size: 26px; }
  .hero h1 { font-size: 28px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .bar-row { grid-template-columns: 70px 1fr 48px; }
  .qa .ans { padding-left: 16px; }
  .demo { padding: 14px; }
}
.mobile-links { display: none; }
@media (max-width: 640px) { .mobile-links { display: block; } }

/* ========== 手撕代码 Code Lab ========== */
.code-input { width: 100%; min-height: 260px; font-family: var(--mono); font-size: 13.5px; line-height: 1.55; background: var(--code-bg); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; resize: vertical; tab-size: 4; white-space: pre; overflow-x: auto; }
.code-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.out.pass { background: var(--ok-soft); }
.out.fail { background: var(--bad-soft); }
.part-new::after { content: "NEW"; font-size: 10px; color: #fff; background: var(--bad); border-radius: 4px; padding: 0 4px; margin-left: 6px; }
