/* 医学生自主学习平台 — design system
   Calm, warm, readable. Light by default, dark follows the OS or the user's choice. */
:root {
  --bg: #f6f4ef; --bg-2: #efebe3; --surface: #ffffff; --surface-2: #fbfaf7; --surface-3: #f3f1eb;
  --line: rgba(28, 37, 38, .08); --line-2: rgba(28, 37, 38, .14);
  --ink: #1c2526; --ink-2: #435053; --muted: #7c8688; --faint: #a7aeaf;
  --accent: #2b8a7c; --accent-2: #3aa595; --accent-ink: #1d6a5f; --accent-soft: #e2f1ed; --accent-soft-2: #cfe8e2;
  --ok: #2c9a64; --ok-soft: #e3f4ea; --bad: #d65f4a; --bad-soft: #fbe8e3; --warn: #c98a1d; --warn-soft: #fbf1dc;
  --star: #e0a537; --ai: #6657c9; --ai-soft: #eeecfb; --ai-ink: #4c3fa8;
  --shadow-1: 0 1px 2px rgba(31, 41, 42, .05), 0 2px 8px rgba(31, 41, 42, .04);
  --shadow-2: 0 2px 6px rgba(31, 41, 42, .05), 0 12px 32px rgba(31, 41, 42, .08);
  --shadow-3: 0 18px 60px rgba(31, 41, 42, .16);
  --r-sm: 10px; --r: 14px; --r-lg: 20px; --r-xl: 28px;
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC", "MiSans", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans SC", "Segoe UI", sans-serif;
  --mono: "SF Mono", ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --fs: 16px;
  --top-h: 64px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f1415; --bg-2: #151b1c; --surface: #182021; --surface-2: #1c2526; --surface-3: #222c2d;
  --line: rgba(232, 240, 238, .07); --line-2: rgba(232, 240, 238, .13);
  --ink: #e7eeec; --ink-2: #b9c4c2; --muted: #8a9694; --faint: #5f6b6a;
  --accent: #4fb9a8; --accent-2: #63c9b8; --accent-ink: #7fd6c7; --accent-soft: rgba(79, 185, 168, .13); --accent-soft-2: rgba(79, 185, 168, .22);
  --ok: #52c08a; --ok-soft: rgba(82, 192, 138, .13); --bad: #f07f6a; --bad-soft: rgba(240, 127, 106, .13); --warn: #e8b04b; --warn-soft: rgba(232, 176, 75, .13);
  --star: #f0bb4f; --ai: #9b8ff0; --ai-soft: rgba(155, 143, 240, .14); --ai-ink: #b9b0ff;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .3); --shadow-2: 0 10px 30px rgba(0, 0, 0, .35); --shadow-3: 0 24px 70px rgba(0, 0, 0, .55);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; font-size: var(--fs); }
body {
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink);
  font-family: var(--font); font-size: 1rem; line-height: 1.6; letter-spacing: .01em;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
a { color: var(--accent-ink); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
::selection { background: var(--accent-soft-2); }
img { max-width: 100%; display: block; }
:where(svg[aria-hidden]) { width: 1.15em; height: 1.15em; flex: none; }
.countdown svg { width: 22px; height: 22px; color: var(--accent-ink); }
.soon .ic svg { width: 22px; height: 22px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- boot ---------- */
.boot { min-height: 100vh; display: grid; place-items: center; }
.boot-mark { width: 44px; height: 44px; animation: breathe 1.6s var(--ease) infinite; }
@keyframes breathe { 50% { transform: scale(.9); opacity: .6; } }

/* ---------- layout ---------- */
.shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 40; height: var(--top-h);
  display: flex; align-items: center; gap: 18px; padding: 0 clamp(16px, 3vw, 32px);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid transparent; transition: border-color .3s;
}
.topbar.scrolled { border-bottom-color: var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; color: var(--ink); white-space: nowrap; }
.brand svg { width: 30px; height: 30px; flex: none; }
.brand small { display: block; font-size: 11px; font-weight: 500; color: var(--muted); letter-spacing: .08em; }
.brand-text { line-height: 1.15; }
.topnav { display: flex; gap: 4px; margin-left: 12px; }
.topnav a {
  padding: 8px 14px; border-radius: 999px; color: var(--ink-2); font-size: .94rem; font-weight: 500;
  transition: background .2s, color .2s;
}
.topnav a:hover { background: var(--surface-3); color: var(--ink); }
.topnav a.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; font-weight: 650; font-size: .9rem;
  box-shadow: var(--shadow-1);
}
main.page { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: clamp(18px, 3vw, 36px) clamp(16px, 3vw, 32px) 120px; }
main.page.wide { max-width: 1400px; }
.tabbar { display: none; }

@media (max-width: 860px) {
  :root { --top-h: 56px; }
  .topnav { display: none; }
  .brand small { display: none; }
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: saturate(1.4) blur(16px); -webkit-backdrop-filter: saturate(1.4) blur(16px);
    border-top: 1px solid var(--line);
  }
  .tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; font-size: 11px; color: var(--muted); border-radius: 12px; }
  .tabbar a svg { width: 22px; height: 22px; }
  .tabbar a.on { color: var(--accent-ink); }
  main.page { padding-bottom: 110px; }
}

/* ---------- type ---------- */
h1, h2, h3, h4 { margin: 0; line-height: 1.3; font-weight: 650; letter-spacing: .005em; }
.h-display { font-size: clamp(1.7rem, 3.4vw, 2.5rem); font-weight: 700; letter-spacing: -.005em; }
.h1 { font-size: clamp(1.45rem, 2.6vw, 1.9rem); }
.h2 { font-size: 1.25rem; }
.h3 { font-size: 1.06rem; }
.eyebrow { font-size: .78rem; font-weight: 600; letter-spacing: .12em; color: var(--accent-ink); text-transform: uppercase; }
.muted { color: var(--muted); }
.ink2 { color: var(--ink-2); }
.small { font-size: .86rem; }
.tiny { font-size: .76rem; }
.num { font-variant-numeric: tabular-nums; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: var(--gap, 16px); }

/* ---------- surfaces ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-1); padding: clamp(16px, 2.2vw, 24px);
}
.card.flat { box-shadow: none; }
.card.hover { transition: transform .35s var(--ease), box-shadow .35s var(--ease), border-color .3s; }
.card.hover:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); border-color: var(--line-2); }
.grid { display: grid; gap: clamp(12px, 1.6vw, 18px); }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 960px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 600px) { .g2, .g3 { grid-template-columns: minmax(0, 1fr); } }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 44px; padding: 0 20px;
  border-radius: 999px; font-weight: 600; font-size: .95rem; white-space: nowrap;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line-2);
  transition: transform .15s var(--ease), background .2s, box-shadow .2s, border-color .2s, opacity .2s;
}
.btn svg { width: 18px; height: 18px; }
.btn:hover { border-color: var(--faint); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 32%, transparent); }
.btn.primary:hover { background: var(--accent-ink); }
.btn.ai { background: var(--ai); color: #fff; border-color: transparent; box-shadow: 0 6px 18px color-mix(in srgb, var(--ai) 30%, transparent); }
.btn.soft { background: var(--accent-soft); color: var(--accent-ink); border-color: transparent; }
.btn.ai-soft { background: var(--ai-soft); color: var(--ai-ink); border-color: transparent; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-3); }
.btn.sm { height: 34px; padding: 0 14px; font-size: .86rem; }
.btn.lg { height: 52px; padding: 0 28px; font-size: 1.02rem; }
.btn.block { width: 100%; }
.btn.icon { width: 40px; padding: 0; }
.btn.icon.sm { width: 34px; }
.btn[disabled] { opacity: .45; pointer-events: none; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-2); font-size: .88rem; font-weight: 500;
  transition: all .2s var(--ease); user-select: none;
}
.chip:hover { border-color: var(--faint); color: var(--ink); }
.chip.on { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 40%, transparent); color: var(--accent-ink); }
.chip svg { width: 15px; height: 15px; }
.tag { display: inline-flex; align-items: center; gap: 4px; height: 24px; padding: 0 9px; border-radius: 999px; font-size: .74rem; font-weight: 600; background: var(--surface-3); color: var(--ink-2); white-space: nowrap; }
.tag.accent { background: var(--accent-soft); color: var(--accent-ink); }
.tag.ai { background: var(--ai-soft); color: var(--ai-ink); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.stars { color: var(--star); letter-spacing: -.08em; font-size: .9em; }

/* ---------- forms ---------- */
.field { display: block; }
.field > span { display: block; font-size: .84rem; font-weight: 600; color: var(--ink-2); margin-bottom: 8px; }
.input {
  width: 100%; height: 50px; padding: 0 16px; border-radius: var(--r); border: 1px solid var(--line-2);
  background: var(--surface-2); color: var(--ink); outline: none; transition: border-color .2s, box-shadow .2s, background .2s;
}
.input:focus { border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 4px var(--accent-soft); }
textarea.input { height: auto; padding: 14px 16px; resize: none; line-height: 1.6; }
.input-wrap { position: relative; }
.input-wrap .btn { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); }
.form-error { color: var(--bad); font-size: .88rem; min-height: 1.4em; }

/* ---------- progress ---------- */
.bar { height: 6px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--accent), var(--accent-2)); width: 0; transition: width .8s var(--ease); }
.ring { --p: 0; --size: 64px; --w: 7px; width: var(--size); height: var(--size); border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--surface-3) 0); position: relative; flex: none; }
.ring::before { content: ""; position: absolute; inset: var(--w); border-radius: 50%; background: var(--surface); }
.ring > span { position: relative; font-weight: 700; font-size: .95rem; }

/* ---------- toast & modal ---------- */
.toasts { position: fixed; left: 50%; top: 18px; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { pointer-events: auto; padding: 12px 18px; border-radius: 999px; background: var(--ink); color: var(--bg); font-size: .92rem; box-shadow: var(--shadow-3);
  animation: toastIn .4s var(--ease); }
.toast.bad { background: var(--bad); color: #fff; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-10px) scale(.96); } }
.scrim { position: fixed; inset: 0; z-index: 100; background: rgba(15, 20, 21, .38); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); animation: fade .25s; }
@keyframes fade { from { opacity: 0; } }
.drawer {
  position: fixed; z-index: 110; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); background: var(--surface);
  box-shadow: var(--shadow-3); display: flex; flex-direction: column; animation: slideIn .4s var(--ease);
}
@keyframes slideIn { from { transform: translateX(40px); opacity: 0; } }
.drawer-head { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.drawer-body { flex: 1; overflow-y: auto; padding: 18px 20px 28px; }
.drawer-foot { padding: 12px 14px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
@media (max-width: 640px) {
  .drawer { top: auto; height: 88vh; width: 100vw; border-radius: 22px 22px 0 0; animation: sheetIn .45s var(--ease); }
  @keyframes sheetIn { from { transform: translateY(60px); opacity: 0; } }
}
.lightbox { position: fixed; inset: 0; z-index: 120; display: grid; place-items: center; padding: 24px; background: rgba(10, 14, 15, .82); animation: fade .2s; cursor: zoom-out; }
.lightbox img { max-height: 92vh; border-radius: 12px; background: #fff; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; }
.login-art {
  position: relative; overflow: hidden; padding: 48px clamp(32px, 5vw, 72px); display: flex; flex-direction: column; justify-content: space-between;
  background: radial-gradient(120% 90% at 0% 0%, #3aa595 0%, #2b8a7c 38%, #1d5f56 100%); color: #f3fbf9;
}
.login-art::after { content: ""; position: absolute; inset: 0; background:
  radial-gradient(40% 30% at 80% 20%, rgba(255, 255, 255, .16), transparent 70%),
  radial-gradient(50% 40% at 10% 90%, rgba(255, 214, 150, .18), transparent 70%); pointer-events: none; }
.login-art .brand { color: #fff; }
.login-art .brand small { color: rgba(255, 255, 255, .7); }
.login-quote { position: relative; z-index: 1; max-width: 460px; }
.login-quote h1 { font-size: clamp(1.9rem, 3.2vw, 2.7rem); font-weight: 700; line-height: 1.3; letter-spacing: .01em; }
.login-quote p { margin: 18px 0 0; color: rgba(255, 255, 255, .82); font-size: 1.02rem; line-height: 1.8; }
.login-orbs { position: absolute; right: -60px; bottom: -60px; width: 420px; height: 420px; opacity: .55; }
.login-form-wrap { display: grid; place-items: center; padding: 32px 20px; }
.login-form { width: min(380px, 100%); }
.login-form h2 { font-size: 1.6rem; }
.login-foot { margin-top: 26px; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .8rem; }
.login-foot svg { width: 14px; height: 14px; }
@media (max-width: 860px) {
  .login { grid-template-columns: 1fr; }
  .login-art { min-height: 260px; padding: 28px 24px; }
  .login-quote h1 { font-size: 1.6rem; }
  .login-orbs { width: 260px; height: 260px; }
}

/* ---------- home ---------- */
.hello { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin: 6px 0 26px; }
.countdown { display: flex; align-items: center; gap: 12px; white-space: nowrap; color: var(--ink-2); padding: 10px 16px 10px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-1); }
.countdown b { font-size: 1.4rem; color: var(--accent-ink); font-variant-numeric: tabular-nums; }
.course-hero {
  position: relative; overflow: hidden; border-radius: var(--r-xl); padding: clamp(22px, 3.4vw, 40px); color: #fff; min-height: 280px;
  background: linear-gradient(135deg, #2b8a7c 0%, #2f7d8c 55%, #3c6e9b 100%); box-shadow: var(--shadow-2);
  display: flex; flex-direction: column; justify-content: space-between; gap: 24px;
}
.course-hero .art { position: absolute; right: -20px; top: -10px; width: min(48%, 420px); opacity: .9; pointer-events: none; }
.course-hero h2 { font-size: clamp(1.6rem, 3vw, 2.2rem); font-weight: 700; }
.course-hero p { margin: 8px 0 0; color: rgba(255, 255, 255, .85); max-width: 520px; }
.course-hero .btn { background: #fff; color: #1d6a5f; border-color: transparent; }
.course-hero .btn.glass { background: rgba(255, 255, 255, .16); color: #fff; }
.hero-stats { display: flex; gap: clamp(18px, 4vw, 44px); flex-wrap: wrap; }
.hero-stats b { display: block; font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.hero-stats span { font-size: .8rem; color: rgba(255, 255, 255, .78); }
.soon { display: flex; align-items: center; gap: 14px; color: var(--muted); }
.soon .ic { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; background: var(--surface-3); }

/* ---------- course overview ---------- */
.quick { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 1060px) { .quick { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 520px) { .quick { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.quick a {
  display: flex; flex-direction: column; gap: 14px; padding: 18px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line);
  box-shadow: var(--shadow-1); color: var(--ink); transition: transform .35s var(--ease), box-shadow .35s var(--ease);
}
.quick a:hover { transform: translateY(-3px); box-shadow: var(--shadow-2); }
.quick .ic { width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-ink); }
.quick .ic svg { width: 22px; height: 22px; }
.quick .ic.ai { background: var(--ai-soft); color: var(--ai-ink); }
.quick .ic.bad { background: var(--bad-soft); color: var(--bad); }
.quick .ic.warn { background: var(--warn-soft); color: var(--warn); }
.quick b { font-size: .98rem; }
.quick span { font-size: .8rem; color: var(--muted); margin-top: -10px; }
.chapters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
@media (max-width: 760px) { .chapters { grid-template-columns: 1fr; } }
.chapter { display: flex; gap: 16px; align-items: center; padding: 18px 20px; }
.chapter .idx { width: 46px; height: 46px; border-radius: 14px; flex: none; display: grid; place-items: center; font-weight: 700; color: var(--accent-ink); background: var(--accent-soft); }
.chapter.histo .idx { background: #f6ecfa; color: #8a4ea6; }
.chapter.embryo .idx { background: #fdf0e3; color: #b8692b; }
:root[data-theme="dark"] .chapter.histo .idx { background: rgba(178, 120, 210, .15); color: #d2a7ea; }
:root[data-theme="dark"] .chapter.embryo .idx { background: rgba(232, 150, 80, .15); color: #f0b37c; }
.chapter .meta { flex: 1; min-width: 0; }
.chapter .meta b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chapter .meta .bar { margin-top: 10px; }
.spark { display: flex; align-items: flex-end; gap: 5px; height: 56px; }
.spark i { flex: 1; border-radius: 5px 5px 2px 2px; background: var(--accent-soft-2); min-height: 4px; transition: height .8s var(--ease); }
.spark i.today { background: var(--accent); }

/* ---------- reader ---------- */
.reader { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 28px; align-items: start; }
.toc { position: sticky; top: calc(var(--top-h) + 16px); max-height: calc(100vh - var(--top-h) - 32px); overflow-y: auto; padding: 8px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line); scrollbar-width: thin; }
.toc details { border-radius: 12px; }
.toc summary { list-style: none; cursor: pointer; padding: 10px 12px; border-radius: 12px; font-weight: 600; font-size: .9rem; display: flex; align-items: center; gap: 8px; }
.toc summary::-webkit-details-marker { display: none; }
.toc summary:hover { background: var(--surface-3); }
.toc summary svg { width: 14px; height: 14px; color: var(--muted); transition: transform .25s; flex: none; }
.toc details[open] summary svg { transform: rotate(90deg); }
.toc a { display: flex; align-items: center; gap: 8px; padding: 8px 12px 8px 34px; border-radius: 10px; color: var(--ink-2); font-size: .88rem; line-height: 1.4; }
.toc a:hover { background: var(--surface-3); color: var(--ink); }
.toc a.on { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.toc a .pc { margin-left: auto; font-size: .72rem; color: var(--faint); font-variant-numeric: tabular-nums; }
.toc-mobile { display: none; }
@media (max-width: 980px) {
  .reader { grid-template-columns: 1fr; }
  .toc { display: none; }
  .toc-mobile { display: flex; }
}
.read-tools { position: sticky; top: var(--top-h); z-index: 20; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 10px 0; margin-bottom: 8px; background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.doc { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl); padding: clamp(20px, 3.6vw, 44px); box-shadow: var(--shadow-1); }
.doc-title { margin-bottom: 18px; }
.doc-title .crumb { font-size: .82rem; color: var(--muted); margin-bottom: 6px; }
.frame { margin: 8px 0 22px; padding: 16px 18px; border-radius: var(--r); background: linear-gradient(135deg, var(--accent-soft), transparent 140%); border: 1px solid color-mix(in srgb, var(--accent) 18%, transparent); color: var(--ink); line-height: 1.85; }
.frame b { color: var(--accent-ink); }
.topic { margin: 34px 0 10px; font-size: 1.12rem; display: flex; align-items: center; gap: 10px; scroll-margin-top: calc(var(--top-h) + 70px); }
.topic::before { content: ""; width: 4px; height: 1.1em; border-radius: 4px; background: var(--accent); }
.pt { position: relative; display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; gap: 6px; align-items: start; padding: 12px 12px 12px 8px; margin: 2px -8px; border-radius: var(--r); line-height: 1.9; transition: background .25s; scroll-margin-top: calc(var(--top-h) + 70px); }
.pt:hover { background: var(--surface-2); }
.pt.flash { animation: flash 2.2s var(--ease); }
@keyframes flash { 0%, 40% { background: var(--accent-soft-2); } }
.pt .lv { padding-top: 2px; text-align: center; font-size: .78rem; line-height: 1.6; }
.pt .lv .stars { display: block; font-size: .86rem; }
.pt .tx { color: var(--ink); }
.pt .tx b { font-weight: 650; color: var(--ink); background: linear-gradient(transparent 62%, color-mix(in srgb, var(--star) 28%, transparent) 0); }
.pt.s3 .tx { color: var(--ink); }
.pt.s1 .tx, .pt.s0 .tx { color: var(--ink-2); }
.pt.done .tx { opacity: .55; }
.pt-acts { display: flex; gap: 2px; opacity: 0; transition: opacity .2s; }
.pt:hover .pt-acts, .pt:focus-within .pt-acts, .pt.open .pt-acts { opacity: 1; }
@media (hover: none) { .pt-acts { opacity: 1; } }
.pt-acts .btn { height: 32px; width: 32px; padding: 0; color: var(--muted); }
.pt-acts .btn.on { color: var(--ok); }
.pt-acts .btn.ask:hover { color: var(--ai); }
.mastered-badge { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; background: var(--ok); color: #fff; margin-top: 4px; }
.mastered-badge svg { width: 12px; height: 12px; }
.cloze b { color: transparent !important; background: var(--surface-3) !important; border-radius: 6px; cursor: pointer; transition: color .25s, background .25s; padding: 0 2px; user-select: none; }
.cloze b.peek { color: var(--accent-ink) !important; background: var(--accent-soft) !important; }
.tbl-wrap { margin: 14px 0 18px; overflow-x: auto; border-radius: var(--r); border: 1px solid var(--line); -webkit-overflow-scrolling: touch; }
table.tbl { width: 100%; border-collapse: collapse; font-size: .92rem; line-height: 1.7; min-width: 520px; }
.tbl th, .tbl td { padding: 10px 14px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.tbl th { background: var(--surface-3); font-weight: 650; color: var(--ink); white-space: nowrap; position: sticky; top: 0; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr:nth-child(even) td { background: var(--surface-2); }
.tbl td:first-child { font-weight: 600; color: var(--ink); }
.tbl b { color: var(--accent-ink); }
.doc-img { margin: 18px auto; border-radius: var(--r); border: 1px solid var(--line); background: #fff; cursor: zoom-in; max-height: 520px; object-fit: contain; }
.doc-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 22px; }
.doc-nav a { padding: 16px 18px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line); color: var(--ink); transition: box-shadow .3s, transform .3s var(--ease); }
.doc-nav a:hover { box-shadow: var(--shadow-2); transform: translateY(-2px); }
.doc-nav a.next { text-align: right; }
.doc-nav small { display: block; color: var(--muted); font-size: .78rem; margin-bottom: 4px; }

/* ---------- quiz ---------- */
.quiz { max-width: 780px; margin: 0 auto; }
.quiz-top { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.quiz-top .bar { flex: 1; height: 8px; }
.qcard { padding: clamp(20px, 3.4vw, 34px); border-radius: var(--r-xl); animation: qIn .45s var(--ease); }
@keyframes qIn { from { opacity: 0; transform: translateY(10px); } }
.qmeta { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.qstem { font-size: 1.16rem; line-height: 1.8; font-weight: 550; margin-bottom: 20px; }
.qstem .blank { display: inline-block; min-width: 4em; border-bottom: 2px solid var(--line-2); margin: 0 4px; }
.opts { display: grid; gap: 10px; }
.opt {
  display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 12px; text-align: left; width: 100%;
  padding: 13px 16px; border-radius: var(--r); border: 1.5px solid var(--line-2); background: var(--surface); line-height: 1.6;
  transition: border-color .2s, background .2s, transform .15s var(--ease);
}
.opt:hover:not([disabled]) { border-color: var(--accent); background: var(--surface-2); }
.opt:active:not([disabled]) { transform: scale(.99); }
.opt .k { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; font-weight: 700; font-size: .88rem; background: var(--surface-3); color: var(--ink-2); transition: all .2s; }
.opt.sel { border-color: var(--accent); background: var(--accent-soft); }
.opt.sel .k { background: var(--accent); color: #fff; }
.opt.right { border-color: var(--ok); background: var(--ok-soft); }
.opt.right .k { background: var(--ok); color: #fff; }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt.wrong .k { background: var(--bad); color: #fff; }
.opt[disabled] { cursor: default; }
.opt .mk svg { width: 20px; height: 20px; }
.opt.right .mk { color: var(--ok); } .opt.wrong .mk { color: var(--bad); }
.blanks { display: grid; gap: 10px; }
.blanks label { display: flex; align-items: center; gap: 12px; }
.blanks label > span { font-size: .84rem; color: var(--muted); flex: none; white-space: nowrap; min-width: 3.6em; }
.blanks .input.right { border-color: var(--ok); background: var(--ok-soft); }
.blanks .input.wrong { border-color: var(--bad); background: var(--bad-soft); }
.qactions { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; align-items: center; }
.verdict { margin-top: 20px; border-radius: var(--r-lg); padding: 18px 20px; animation: qIn .4s var(--ease); }
.verdict.ok { background: var(--ok-soft); }
.verdict.bad { background: var(--bad-soft); }
.verdict-head { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; }
.verdict.ok .verdict-head { color: var(--ok); }
.verdict.bad .verdict-head { color: var(--bad); }
.verdict-head svg { width: 24px; height: 24px; }
.verdict .ans { margin-top: 8px; font-weight: 600; }
.verdict .exp { margin-top: 10px; color: var(--ink-2); line-height: 1.85; }
.source { margin-top: 14px; padding: 12px 14px; border-radius: var(--r); background: var(--surface); border: 1px dashed var(--line-2); font-size: .9rem; line-height: 1.8; color: var(--ink-2); }
.source .crumb { font-size: .76rem; color: var(--muted); margin-bottom: 4px; display: flex; align-items: center; gap: 6px; }
.source .crumb svg { width: 13px; height: 13px; }
.pop { animation: pop .5s var(--ease); }
@keyframes pop { 30% { transform: scale(1.06); } }
.shake { animation: shake .45s; }
@keyframes shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
.kbd { display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 6px; border: 1px solid var(--line-2); border-bottom-width: 2px; font-size: .72rem; color: var(--muted); font-family: var(--mono); }
.result-hero { text-align: center; padding: 34px 20px; }
.result-hero .ring { --size: 150px; --w: 12px; margin: 0 auto 18px; }
.result-hero .ring > span { font-size: 2rem; }

/* flashcards */
.card-face { padding: 8px 0 4px; }
.card-q { font-size: 1.3rem; margin: 10px 0 6px; }
.card-back { margin-top: 14px; padding: 18px 20px; border-radius: var(--r-lg); background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent); }
.card-ans { margin-top: 6px; font-size: 1.15rem; font-weight: 650; color: var(--accent-ink); line-height: 1.7; }

/* setup */
.setup { max-width: 860px; margin: 0 auto; }
.opt-group { padding: 18px 0; border-bottom: 1px solid var(--line); }
.opt-group:last-of-type { border-bottom: 0; }
.opt-group > b { display: block; margin-bottom: 12px; font-size: .92rem; }
.setup-foot { position: sticky; bottom: 0; display: flex; align-items: center; gap: 14px; padding: 14px 0 6px; background: linear-gradient(transparent, var(--bg) 30%); }
@media (max-width: 860px) { .setup-foot { bottom: 64px; } }

/* ---------- wrong book ---------- */
.wrong-item { display: grid; grid-template-columns: 1fr auto; gap: 12px; padding: 16px 18px; border-radius: var(--r); border: 1px solid var(--line); background: var(--surface); }
.wrong-item p { margin: 4px 0 0; line-height: 1.7; }

/* ---------- AI / markdown ---------- */
.md { line-height: 1.85; word-wrap: break-word; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: .6em 0; }
.md h1, .md h2, .md h3, .md h4 { margin: 1.1em 0 .5em; font-size: 1.05rem; }
.md h1, .md h2 { font-size: 1.12rem; }
.md ul, .md ol { margin: .5em 0; padding-left: 1.4em; }
.md li { margin: .25em 0; }
.md strong { font-weight: 650; color: var(--ink); }
.md code { font-family: var(--mono); font-size: .88em; padding: .1em .4em; border-radius: 6px; background: var(--surface-3); }
.md pre { padding: 12px 14px; border-radius: 12px; background: var(--surface-3); overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md blockquote { margin: .8em 0; padding: .4em 1em; border-left: 3px solid var(--ai); background: var(--ai-soft); border-radius: 0 10px 10px 0; color: var(--ink-2); }
.md table { border-collapse: collapse; width: 100%; margin: .8em 0; font-size: .92em; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line-2); padding: 7px 10px; text-align: left; vertical-align: top; }
.md th { background: var(--surface-3); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1.2em 0; }
.caret { display: inline-block; width: .55em; height: 1.1em; vertical-align: -.18em; border-radius: 2px; background: var(--ai); animation: blink 1s steps(1) infinite; margin-left: 2px; }
@keyframes blink { 50% { opacity: 0; } }
.thinking { display: flex; align-items: center; gap: 10px; color: var(--ai-ink); font-size: .9rem; }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: dot 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .15s; } .dots i:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
details.think { margin-bottom: 10px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); font-size: .86rem; color: var(--muted); }
details.think summary { cursor: pointer; padding: 8px 12px; }
details.think div { padding: 0 12px 10px; white-space: pre-wrap; max-height: 240px; overflow-y: auto; }
.refs { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.refs a { display: inline-flex; align-items: center; gap: 4px; max-width: 100%; padding: 4px 10px; border-radius: 999px; background: var(--surface-3); color: var(--ink-2); font-size: .76rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.refs a:hover { color: var(--accent-ink); }
.refs svg { width: 12px; height: 12px; flex: none; }

.tutor { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 20px; height: calc(100vh - var(--top-h) - 56px); }
.tutor-side { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.tutor-side .list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; padding: 6px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line); }
.tutor-side .list a { display: flex; align-items: center; gap: 8px; padding: 9px 12px; border-radius: 10px; color: var(--ink-2); font-size: .88rem; }
.tutor-side .list a span { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.tutor-side .list a:hover { background: var(--surface-3); }
.tutor-side .list a.on { background: var(--ai-soft); color: var(--ai-ink); font-weight: 600; }
.tutor-side .list a .del { opacity: 0; color: var(--muted); }
.tutor-side .list a:hover .del { opacity: 1; }
.tutor-side .list a .del svg { width: 14px; height: 14px; }
.tutor-main { display: flex; flex-direction: column; min-height: 0; border-radius: var(--r-xl); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-1); overflow: hidden; }
.tutor-modes { display: flex; gap: 6px; padding: 12px 14px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.msgs { flex: 1; overflow-y: auto; padding: 22px clamp(14px, 3vw, 34px); scroll-behavior: smooth; }
.msg { display: flex; gap: 12px; margin-bottom: 22px; animation: qIn .35s var(--ease); }
.msg .who { width: 32px; height: 32px; border-radius: 10px; flex: none; display: grid; place-items: center; }
.msg.ai .who { background: var(--ai-soft); color: var(--ai-ink); }
.msg.ai .who svg { width: 18px; height: 18px; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble { max-width: 82%; padding: 12px 16px; border-radius: 18px 18px 4px 18px; background: var(--accent); color: #fff; line-height: 1.7; white-space: pre-wrap; }
.msg.ai .body { flex: 1; min-width: 0; }
.composer { padding: 12px 14px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--surface); }
.composer-box { display: flex; align-items: flex-end; gap: 8px; padding: 6px 6px 6px 16px; border-radius: 22px; border: 1px solid var(--line-2); background: var(--surface-2); transition: border-color .2s, box-shadow .2s; }
.composer-box:focus-within { border-color: var(--ai); box-shadow: 0 0 0 4px var(--ai-soft); }
.composer textarea { flex: 1; border: 0; outline: 0; background: transparent; resize: none; padding: 9px 0; max-height: 180px; line-height: 1.6; }
.composer-opts { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: .8rem; color: var(--muted); }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.switch input { appearance: none; -webkit-appearance: none; width: 34px; height: 20px; border-radius: 99px; background: var(--line-2); position: relative; transition: background .2s; cursor: pointer; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform .25s var(--ease); }
.switch input:checked { background: var(--ai); }
.switch input:checked::after { transform: translateX(14px); }
.empty-chat { max-width: 620px; margin: 6vh auto 0; text-align: center; }
.empty-chat .orb { width: 68px; height: 68px; margin: 0 auto 18px; border-radius: 22px; display: grid; place-items: center; color: #fff; background: linear-gradient(135deg, #7b6ee0, #4fb9a8); box-shadow: 0 12px 30px color-mix(in srgb, var(--ai) 35%, transparent); }
.empty-chat .orb svg { width: 34px; height: 34px; }
.suggest { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 26px; text-align: left; }
.suggest button { padding: 14px 16px; border-radius: var(--r); border: 1px solid var(--line); background: var(--surface-2); color: var(--ink-2); font-size: .9rem; line-height: 1.6; transition: all .2s; text-align: left; }
.suggest button:hover { border-color: var(--ai); color: var(--ink); background: var(--ai-soft); }
@media (max-width: 860px) {
  .tutor { grid-template-columns: 1fr; height: calc(100vh - var(--top-h) - 96px); }
  .tutor-side { display: none; }
  .suggest { grid-template-columns: 1fr; }
}

/* ---------- settings ---------- */
.settings { max-width: 760px; margin: 0 auto; }
.set-row { display: flex; align-items: center; gap: 16px; padding: 16px 0; border-bottom: 1px solid var(--line); }
.set-row:last-child { border-bottom: 0; }
.set-row .l { flex: 1; min-width: 0; }
.set-row .l b { display: block; }
.seg { display: inline-flex; padding: 3px; border-radius: 999px; background: var(--surface-3); }
.seg button { height: 32px; padding: 0 14px; border-radius: 999px; font-size: .86rem; color: var(--ink-2); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); font-weight: 600; }
.log-row { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; padding: 10px 0; font-size: .86rem; border-bottom: 1px solid var(--line); }
.dot { width: 8px; height: 8px; border-radius: 50%; }
.dot.ok { background: var(--ok); } .dot.bad { background: var(--bad); }

.fade-in { animation: qIn .5s var(--ease) both; }
.stagger > * { animation: qIn .55s var(--ease) both; }
.stagger > *:nth-child(2) { animation-delay: .04s; } .stagger > *:nth-child(3) { animation-delay: .08s; }
.stagger > *:nth-child(4) { animation-delay: .12s; } .stagger > *:nth-child(5) { animation-delay: .16s; }
.stagger > *:nth-child(6) { animation-delay: .2s; } .stagger > *:nth-child(n+7) { animation-delay: .24s; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* ---------- AI modes ---------- */
.tutor-modes { scrollbar-width: none; }
.tutor-modes::-webkit-scrollbar { display: none; }
.tutor-modes .chip { flex: none; }
.mode-intro { max-width: 760px; margin: 4px auto 18px; display: grid; grid-template-columns: 48px minmax(0, 1fr); gap: 4px 14px; align-items: start; }
.mode-intro > .mode-form { grid-column: 1 / -1; }
.mi-icon { width: 48px; height: 48px; border-radius: 15px; display: grid; place-items: center; color: #fff; background: linear-gradient(135deg, #7b6ee0, #4fb9a8); box-shadow: 0 8px 22px color-mix(in srgb, var(--ai) 28%, transparent); }
.mi-icon svg { width: 24px; height: 24px; }
.mode-intro h2 { margin-top: 2px; }
.mode-intro p { margin: 4px 0 0; }
.mode-form { display: flex; flex-direction: column; gap: 14px; margin-top: 14px; padding: 18px; border-radius: var(--r-lg); background: var(--surface-2); border: 1px solid var(--line); }
.msgs > .msg, .msgs > div > .msg { max-width: 860px; margin-left: auto; margin-right: auto; }
.new-chat { display: flex; align-items: center; gap: 8px; padding: 9px 12px; border-radius: 10px; color: var(--ai-ink); font-size: .88rem; font-weight: 600; text-align: left; }
.new-chat:hover { background: var(--ai-soft); }
.spoiler { margin: 14px 0 4px; border-radius: var(--r); border: 1px dashed color-mix(in srgb, var(--ai) 45%, transparent); background: var(--ai-soft); }
.spoiler > summary { cursor: pointer; padding: 12px 16px; font-weight: 600; color: var(--ai-ink); display: flex; align-items: center; gap: 8px; list-style: none; }
.spoiler > summary::-webkit-details-marker { display: none; }
.spoiler[open] > summary { border-bottom: 1px dashed color-mix(in srgb, var(--ai) 30%, transparent); }
.spoiler > .md { padding: 12px 16px 14px; }
.spoiler-wait { margin-top: 12px; display: flex; align-items: center; gap: 8px; color: var(--ai-ink); font-size: .9rem; }
.preset-row { display: flex; gap: 6px; overflow-x: auto; padding: 0 2px 10px; scrollbar-width: none; }
.preset-row::-webkit-scrollbar { display: none; }
.sm-chip { height: 30px; font-size: .8rem; flex: none; }
.ai-card { background: var(--ai-soft) !important; border: 0 !important; }
.ai-tools { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.ai-tools .chip { height: 30px; font-size: .82rem; }

/* settings: AI key */
.key-status { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; padding: 14px 16px; border-radius: var(--r); background: var(--surface-2); border: 1px solid var(--line); }
.key-status code { font-family: var(--mono); font-size: .9rem; }
@media (max-width: 700px) { .key-status { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.secure-note { display: flex; gap: 12px; padding: 14px 16px; border-radius: var(--r); background: var(--accent-soft); color: var(--ink-2); font-size: .86rem; line-height: 1.7; }
.secure-note > svg { width: 20px; height: 20px; color: var(--accent-ink); flex: none; margin-top: 2px; }
.secure-note b { color: var(--ink); }
.secure-note ul { margin: 6px 0 0; padding-left: 1.2em; }
details.more { border-top: 1px solid var(--line); padding-top: 10px; }
details.more > summary { cursor: pointer; font-weight: 600; font-size: .9rem; color: var(--ink-2); padding: 4px 0 10px; }
