:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6eb;
  --text: #1a1d23;
  --muted: #5d6573;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --ok: #15803d;
  --ok-soft: #e3f5e9;
  --l1: #0e7490; --l1-soft: #e0f4f8;
  --l2: #a16207; --l2-soft: #fdf3dc;
  --l3: #b91c1c; --l3-soft: #fde8e8;
  --code-bg: #0f172a;
  --code-text: #e2e8f0;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  --sidebar-w: 270px;
  --topbar-h: 56px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117; --surface: #161b22; --surface-2: #1f2630; --border: #2b333e;
    --text: #e6e9ef; --muted: #9aa4b2; --accent: #6b9bff; --accent-soft: #1b2a4a;
    --ok: #4ade80; --ok-soft: #14301f;
    --l1: #5fd0e6; --l1-soft: #10313a; --l2: #f2c35b; --l2-soft: #3a2e10; --l3: #f87171; --l3-soft: #3d1717;
    --code-bg: #0a0e14; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1117; --surface: #161b22; --surface-2: #1f2630; --border: #2b333e;
  --text: #e6e9ef; --muted: #9aa4b2; --accent: #6b9bff; --accent-soft: #1b2a4a;
  --ok: #4ade80; --ok-soft: #14301f;
  --l1: #5fd0e6; --l1-soft: #10313a; --l2: #f2c35b; --l2-soft: #3a2e10; --l3: #f87171; --l3-soft: #3d1717;
  --code-bg: #0a0e14; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-padding-top: calc(var(--topbar-h) + 16px); }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; }
code, pre { font-family: ui-monospace, SFMono-Regular, "JetBrains Mono", Consolas, monospace; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20; height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px; padding: 0 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; color: var(--text); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logo { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 7px; background: var(--accent); color: #fff; font-family: ui-monospace, monospace; font-size: 13px; flex: none; }
.top-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.btn { border: 1px solid var(--accent); background: var(--accent); color: #fff; padding: 7px 14px; border-radius: 8px; font-weight: 550; white-space: nowrap; }
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--accent); }
.icon-btn { border: 1px solid var(--border); background: var(--surface); width: 36px; height: 36px; border-radius: 8px; display: grid; place-items: center; }
.icon-btn:hover { background: var(--surface-2); }
.menu-btn { display: none; border: 0; background: none; font-size: 20px; padding: 4px 6px; }
.link-btn { border: 0; background: none; color: var(--muted); font-size: 13px; padding: 8px 12px; text-decoration: underline; }

/* Layout */
.layout { display: flex; max-width: 1280px; margin: 0 auto; }
.sidebar {
  position: sticky; top: var(--topbar-h); align-self: flex-start;
  width: var(--sidebar-w); flex: none; height: calc(100vh - var(--topbar-h));
  overflow-y: auto; padding: 16px 12px; border-right: 1px solid var(--border);
}
.content { flex: 1; min-width: 0; padding: 28px 32px 80px; }

.progress-card { padding: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 14px; }
.progress-label { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.progress-label b { color: var(--text); font-variant-numeric: tabular-nums; }
.progress-bar { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress-bar div { height: 100%; width: 0; background: var(--ok); transition: width .3s; }

#topicNav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--text); text-decoration: none; font-size: 14px;
}
#topicNav a:hover { background: var(--surface-2); }
#topicNav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
#topicNav .ico { width: 22px; text-align: center; opacity: .8; flex: none; }
#topicNav .count { margin-left: auto; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
#topicNav a.active .count { color: var(--accent); }

/* Home */
.hero h1 { font-size: 28px; line-height: 1.25; margin: 0 0 8px; letter-spacing: -.01em; }
.hero p { color: var(--muted); margin: 0 0 24px; max-width: 70ch; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.card {
  display: block; text-align: left; padding: 16px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); text-decoration: none; color: var(--text);
}
.card:hover { border-color: var(--accent); }
.card .ico { font-size: 20px; color: var(--accent); }
.card h3 { margin: 6px 0 4px; font-size: 16px; }
.card p { margin: 0 0 10px; color: var(--muted); font-size: 13.5px; }
.card .mini-bar { height: 4px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.card .mini-bar div { height: 100%; background: var(--ok); }
.card small { color: var(--muted); font-size: 12px; }

.tips { margin-top: 32px; padding: 18px 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.tips h2 { margin: 0 0 8px; font-size: 17px; }
.tips ol { margin: 0; padding-left: 20px; }
.tips li { margin: 4px 0; }

/* Topic page */
.topic-head h1 { font-size: 26px; margin: 0 0 6px; display: flex; gap: 10px; align-items: center; }
.topic-head p { color: var(--muted); margin: 0 0 18px; max-width: 75ch; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 18px; }
.search {
  flex: 1 1 240px; min-width: 0; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit;
}
.search:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.chip { border: 1px solid var(--border); background: var(--surface); padding: 6px 12px; border-radius: 99px; font-size: 13px; white-space: nowrap; }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }

.qa { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 10px; box-shadow: var(--shadow); }
.qa.done { border-left: 3px solid var(--ok); }
.qa summary {
  list-style: none; display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; cursor: pointer;
}
.qa summary::-webkit-details-marker { display: none; }
.qa summary .num { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; padding-top: 2px; min-width: 22px; }
.qa summary .qtext { flex: 1; font-weight: 600; }
.qa summary .caret { color: var(--muted); transition: transform .2s; padding-top: 2px; }
.qa[open] summary .caret { transform: rotate(90deg); }
.lvl { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; white-space: nowrap; margin-top: 2px; }
.lvl.l1 { background: var(--l1-soft); color: var(--l1); }
.lvl.l2 { background: var(--l2-soft); color: var(--l2); }
.lvl.l3 { background: var(--l3-soft); color: var(--l3); }

.answer { padding: 0 16px 16px 50px; }
.answer p { margin: 8px 0; }
.answer ul, .answer ol { margin: 8px 0; padding-left: 20px; }
.answer li { margin: 4px 0; }
.answer code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: .9em; }
.answer table { border-collapse: collapse; margin: 10px 0; font-size: 14px; display: block; overflow-x: auto; }
.answer th, .answer td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; vertical-align: top; }
.answer th { background: var(--surface-2); }
.code-wrap { position: relative; margin: 12px 0 4px; }
.code-wrap pre {
  margin: 0; background: var(--code-bg); color: var(--code-text); padding: 14px 16px; border-radius: 8px;
  overflow-x: auto; font-size: 13px; line-height: 1.55;
}
.copy-btn {
  position: absolute; top: 8px; right: 8px; font-size: 12px; padding: 3px 9px; border-radius: 6px;
  border: 1px solid #334155; background: #1e293b; color: #cbd5e1;
}
.copy-btn:hover { background: #334155; }
.tok-k { color: #93c5fd; } .tok-s { color: #86efac; } .tok-c { color: #64748b; font-style: italic; } .tok-a { color: #fcd34d; }

.qa-foot { display: flex; justify-content: flex-end; margin-top: 12px; }
.done-btn { border: 1px solid var(--border); background: var(--surface); padding: 6px 12px; border-radius: 8px; font-size: 13px; }
.qa.done .done-btn { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); font-weight: 600; }
.empty { color: var(--muted); padding: 24px; text-align: center; border: 1px dashed var(--border); border-radius: var(--radius); }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .5); display: grid; place-items: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal-box { width: min(760px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; background: var(--surface); border-radius: 14px; padding: 20px; border: 1px solid var(--border); }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-head h2 { margin: 0; font-size: 19px; }
.mock-filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.mock-q { font-size: 18px; font-weight: 650; margin: 8px 0 12px; }
.mock-meta { color: var(--muted); font-size: 13px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.timer { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text); margin-left: auto; }
.mock-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0; }
.mock-answer { border-top: 1px solid var(--border); padding-top: 4px; }
.mock-answer .answer { padding: 0; }

/* Responsive */
@media (max-width: 860px) {
  .menu-btn { display: block; }
  .sidebar {
    position: fixed; z-index: 30; left: 0; top: var(--topbar-h); background: var(--bg);
    transform: translateX(-100%); transition: transform .2s; box-shadow: 4px 0 20px rgba(0,0,0,.15);
  }
  .sidebar.open { transform: none; }
  .content { padding: 20px 16px 60px; }
  .answer { padding: 0 16px 16px; }
  #mockBtn { padding: 7px 10px; }
  .brand { font-size: 14px; }
}
@media (max-width: 420px) {
  .brand .txt { display: none; }
}
