/* MathBank — teaching workbench
   Direction: cool white surfaces, desaturated Morandi blues, one soft
   blue→lavender→rose gradient reserved for brand and AI moments. */
:root {
  --bg: #f3f5f9;
  --bg-tint: #eef2f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f1f4f9;
  --ink: #1d2738;
  --ink-2: #435066;
  --muted: #8691a5;
  --faint: #b6bfcd;
  --line: #e2e7ef;
  --line-2: #d3dae6;
  --blue: #5a7bab;
  --blue-strong: #3e5d8c;
  --blue-soft: #e5ecf6;
  --blue-wash: #f0f4fa;
  --lav: #9d97c2;
  --rose: #cfa3a8;
  --rose-soft: #f6eaeb;
  --sage: #6c9a92;
  --sage-soft: #e5f0ee;
  --ochre: #b8924f;
  --ochre-soft: #f6efe1;
  --danger: #b85d66;
  --danger-soft: #f8e7e9;
  --grad: linear-gradient(120deg, #7f9cc8 0%, #a99cc6 55%, #d4a9ae 100%);
  --grad-soft: linear-gradient(120deg, #edf2fa 0%, #f1eff8 55%, #f8eff0 100%);
  --r-sm: 8px; --r: 12px; --r-lg: 18px; --r-xl: 24px;
  --shadow-1: 0 1px 2px rgba(29, 39, 56, .05), 0 1px 1px rgba(29, 39, 56, .03);
  --shadow-2: 0 6px 20px rgba(45, 64, 99, .08), 0 1px 3px rgba(45, 64, 99, .05);
  --shadow-3: 0 18px 50px rgba(37, 54, 86, .16), 0 4px 12px rgba(37, 54, 86, .08);
  --font: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-read: "Songti SC", "Noto Serif CJK SC", "Source Han Serif SC", "SimSun", serif;
  --mono: "SF Mono", "Cascadia Code", Consolas, "Liberation Mono", monospace;
  --sidebar-w: 232px;
  --focus: 0 0 0 3px rgba(90, 123, 171, .28);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.6 var(--font); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--blue-strong); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 6px; }
::selection { background: #d9e3f2; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.noscript { padding: 2rem; text-align: center; }

/* ---------- boot ---------- */
.boot { min-height: 100vh; display: grid; place-content: center; justify-items: center; gap: 14px; color: var(--muted); }
.boot-mark { width: 52px; height: 52px; border-radius: 16px; background: var(--grad); animation: breathe 1.6s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(.92); opacity: .75; } }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px;
  padding: 18px 14px; background: var(--surface); border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand-mark { width: 34px; height: 34px; border-radius: 11px; background: var(--grad); display: grid; place-items: center; color: #fff; font-weight: 700; letter-spacing: -.02em; box-shadow: 0 4px 12px rgba(127, 156, 200, .35); }
.brand-name { font-weight: 650; font-size: 15px; letter-spacing: .01em; }
.brand-sub { font-size: 11px; color: var(--muted); letter-spacing: .06em; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label { margin: 14px 10px 6px; font-size: 11px; color: var(--faint); letter-spacing: .12em; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px;
  color: var(--ink-2); font-weight: 500; text-decoration: none; transition: background .15s, color .15s;
}
.nav a:hover { background: var(--surface-3); color: var(--ink); }
.nav a.active { background: var(--blue-soft); color: var(--blue-strong); }
.nav a .count { margin-left: auto; font-size: 11px; color: var(--muted); background: var(--surface-3); border-radius: 999px; padding: 0 7px; }
.nav a.active .count { background: #fff; color: var(--blue-strong); }
.ico { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.sidebar-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--line); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 12px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; padding: 2px; background: var(--grad); flex: none; }
.avatar span { display: grid; place-items: center; width: 100%; height: 100%; border-radius: 50%; background: #fff; color: var(--blue-strong); font-weight: 650; font-size: 13px; }
.user-chip .who { line-height: 1.25; min-width: 0; }
.user-chip .who b { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip .who small { color: var(--muted); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 12px 24px; background: rgba(243, 245, 249, .86); backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid transparent;
}
.topbar.scrolled { border-bottom-color: var(--line); }
.btn.menu-btn { display: none; }
.search-wrap { position: relative; flex: 1; max-width: 640px; }
.search-wrap .ico { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search-input {
  width: 100%; height: 42px; padding: 0 92px 0 42px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); box-shadow: var(--shadow-1); transition: border-color .15s, box-shadow .15s;
}
.search-input:focus { outline: none; border-color: #b9c8de; box-shadow: var(--focus); }
.search-hint { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); font-size: 12px; color: var(--faint); pointer-events: none; }
.topbar-actions { display: flex; gap: 8px; margin-left: auto; align-items: center; }
.page { padding: 8px 24px 96px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin: 12px 0 18px; flex-wrap: wrap; }
.page-title { margin: 0; font-size: 22px; font-weight: 650; letter-spacing: .01em; }
.page-sub { margin: 4px 0 0; color: var(--muted); }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px;
  border: 1px solid var(--line-2); border-radius: 10px; background: var(--surface); color: var(--ink);
  font-weight: 550; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, box-shadow .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); border-color: #c3ccda; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; box-shadow: 0 2px 8px rgba(90, 123, 171, .28); }
.btn.primary:hover { background: var(--blue-strong); border-color: var(--blue-strong); }
.btn.soft { background: var(--blue-soft); border-color: transparent; color: var(--blue-strong); }
.btn.soft:hover { background: #dae4f2; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-3); }
.btn.danger { color: var(--danger); border-color: #e6c4c8; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.grad { background: var(--grad); border: 0; color: #fff; box-shadow: 0 4px 14px rgba(169, 156, 198, .35); }
.btn.grad:hover { filter: saturate(1.15) brightness(1.03); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn.icon { width: 36px; padding: 0; }
.btn.sm.icon { width: 30px; }
.btn .ico { width: 16px; height: 16px; }
.btn-group { display: inline-flex; gap: 6px; flex-wrap: wrap; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 12px; color: var(--ink-2); font-weight: 550; }
.input, .select, .textarea {
  width: 100%; height: 36px; padding: 0 12px; border: 1px solid var(--line-2); border-radius: 10px; background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
.textarea { height: auto; min-height: 84px; padding: 10px 12px; resize: vertical; line-height: 1.6; }
.select { appearance: none; padding-right: 32px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M6 8l4 4 4-4' fill='none' stroke='%238691a5' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; background-size: 16px; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: #a9bcd8; box-shadow: var(--focus); }
.input.sm, .select.sm { height: 30px; font-size: 13px; border-radius: 8px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--blue); }
.seg { display: inline-flex; padding: 3px; background: var(--surface-3); border-radius: 10px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 5px 12px; border-radius: 8px; color: var(--ink-2); cursor: pointer; font-weight: 550; font-size: 13px; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }

/* ---------- surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-1); }
.card-pad { padding: 18px 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card-title { margin: 0; font-size: 15px; font-weight: 620; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.divider { height: 1px; background: var(--line); margin: 14px 0; }

.badge { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 550; background: var(--surface-3); color: var(--ink-2); white-space: nowrap; }
.badge.blue { background: var(--blue-soft); color: var(--blue-strong); }
.badge.sage { background: var(--sage-soft); color: #3f7068; }
.badge.ochre { background: var(--ochre-soft); color: #8a6a2f; }
.badge.rose { background: var(--rose-soft); color: #9a5f66; }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.outline { background: transparent; border: 1px solid var(--line-2); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; display: inline-block; }
.stars { color: #c79a52; letter-spacing: 1px; }

.chip { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: 13px; color: var(--ink-2); }
.chip.tag { border-color: transparent; background: var(--blue-wash); color: var(--blue-strong); }
.chip.tag.suggested { background: transparent; border: 1px dashed #b5c3d9; color: var(--ink-2); }
.chip .x { border: 0; background: transparent; padding: 0; margin-right: -2px; width: 18px; height: 18px; border-radius: 50%; color: inherit; opacity: .55; cursor: pointer; display: grid; place-items: center; }
.chip .x:hover { opacity: 1; background: rgba(0, 0, 0, .06); }
.chip .cat { font-size: 11px; color: var(--muted); }

/* ---------- login ---------- */
.login-page { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; background: var(--surface); }
.login-art { position: relative; overflow: hidden; background: var(--grad-soft); display: flex; flex-direction: column; justify-content: space-between; padding: 48px; }
.login-art::before, .login-art::after { content: ""; position: absolute; border-radius: 50%; filter: blur(2px); }
.login-art::before { width: 420px; height: 420px; right: -120px; top: -100px; background: radial-gradient(circle at 30% 30%, rgba(127, 156, 200, .45), rgba(127, 156, 200, 0) 70%); }
.login-art::after { width: 360px; height: 360px; left: -80px; bottom: -120px; background: radial-gradient(circle at 60% 40%, rgba(212, 169, 174, .45), rgba(212, 169, 174, 0) 70%); }
.login-art > * { position: relative; z-index: 1; }
.login-quote { max-width: 440px; }
.login-quote h1 { font-size: 34px; line-height: 1.3; margin: 0 0 14px; font-weight: 650; letter-spacing: .01em; }
.login-quote p { color: var(--ink-2); font-size: 15px; margin: 0; }
.login-sample { margin-top: 28px; padding: 18px 22px; background: rgba(255, 255, 255, .72); border: 1px solid rgba(255, 255, 255, .9); border-radius: var(--r-lg); box-shadow: var(--shadow-2); backdrop-filter: blur(6px); max-width: 440px; font-size: 16px; }
.login-stats { display: flex; gap: 28px; color: var(--ink-2); }
.login-stats b { display: block; font-size: 22px; color: var(--ink); font-weight: 650; }
.login-form-wrap { display: grid; place-items: center; padding: 48px 24px; }
.login-form { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 16px; }
.login-form h2 { margin: 0; font-size: 24px; }
.login-form .input { height: 44px; }
.login-form .btn { height: 44px; }
.form-error { display: flex; gap: 8px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; background: var(--danger-soft); color: var(--danger); font-size: 13px; }
.form-note { padding: 10px 12px; border-radius: 10px; background: var(--ochre-soft); color: #7a5c27; font-size: 13px; }

/* ---------- dashboard ---------- */
.hero { position: relative; overflow: hidden; padding: 24px 26px; border-radius: var(--r-xl); background: var(--grad-soft); border: 1px solid #e7e9f3; margin-bottom: 18px; }
.hero h2 { margin: 0 0 6px; font-size: 20px; }
.hero p { margin: 0; color: var(--ink-2); }
.hero .btn-group { margin-top: 16px; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { padding: 16px 18px; }
.stat .k { color: var(--muted); font-size: 12px; display: flex; gap: 6px; align-items: center; }
.stat .v { font-size: 26px; font-weight: 650; letter-spacing: -.01em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .s { color: var(--muted); font-size: 12px; }
.collections { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.coll-card { padding: 18px; cursor: pointer; transition: transform .15s, box-shadow .15s; display: flex; flex-direction: column; gap: 8px; }
.coll-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); }
.coll-ring { width: 46px; height: 46px; border-radius: 50%; padding: 2.5px; background: var(--grad); }
.coll-ring span { display: grid; place-items: center; width: 100%; height: 100%; border-radius: 50%; background: #fff; font-weight: 650; color: var(--blue-strong); font-size: 13px; }
.coll-card h3 { margin: 4px 0 0; font-size: 16px; }
.bar { height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--blue); border-radius: inherit; }
.two-col { display: grid; grid-template-columns: 1.3fr 1fr; gap: 14px; margin-top: 18px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
table.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: 12px; color: var(--muted); font-weight: 550; background: var(--surface-2); }
.table tr:last-child td { border-bottom: 0; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--blue-wash); }

/* ---------- browse ---------- */
.browse { display: grid; grid-template-columns: 272px minmax(0, 1fr); gap: 18px; align-items: start; }
.browse.with-detail { grid-template-columns: 272px minmax(0, 1fr) minmax(380px, 46%); }
.tree { position: sticky; top: 76px; max-height: calc(100vh - 92px); display: flex; flex-direction: column; overflow: hidden; }
.tree-head { padding: 12px 12px 8px; border-bottom: 1px solid var(--line); }
.tree-body { overflow: auto; padding: 6px; }
.tree-item { display: flex; align-items: center; gap: 6px; width: 100%; padding: 6px 8px; border: 0; background: transparent; border-radius: 8px; cursor: pointer; text-align: left; color: var(--ink-2); font-size: 13px; }
.tree-item:hover { background: var(--surface-3); color: var(--ink); }
.tree-item.active { background: var(--blue-soft); color: var(--blue-strong); font-weight: 600; }
.tree-item .caret { width: 14px; height: 14px; flex: none; transition: transform .15s; color: var(--faint); }
.tree-item.open > .caret { transform: rotate(90deg); }
.tree-item .n { margin-left: auto; font-size: 11px; color: var(--faint); font-variant-numeric: tabular-nums; }
.tree-item .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-level-0 { font-weight: 600; color: var(--ink); }
.tree-children { padding-left: 14px; }
.tree-children[hidden] { display: none; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.filters .select.sm { width: auto; min-width: 110px; }
.crumbs { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; color: var(--muted); font-size: 13px; }
.crumbs b { color: var(--ink); font-weight: 600; }
.result-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }

.qlist { display: flex; flex-direction: column; gap: 12px; }
.qcard { position: relative; padding: 16px 18px 12px; transition: box-shadow .15s, border-color .15s; }
.qcard:hover { box-shadow: var(--shadow-2); }
.qcard.active { border-color: #b8c8df; box-shadow: 0 0 0 3px rgba(90, 123, 171, .12), var(--shadow-2); }
.qcard.selected { background: linear-gradient(0deg, rgba(229, 236, 246, .55), rgba(229, 236, 246, .55)), var(--surface); }
.qcard-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; padding-right: 30px; }
.qnum { font-weight: 650; color: var(--blue-strong); font-size: 13px; }
.qsrc { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 46ch; }
.qcard-body { position: relative; max-height: 340px; overflow: hidden; cursor: pointer; }
.qcard-body.clamped::after { content: ""; position: absolute; inset: auto 0 0 0; height: 64px; background: linear-gradient(180deg, rgba(255, 255, 255, 0), #fff); pointer-events: none; }
.qcard.selected .qcard-body.clamped::after { background: linear-gradient(180deg, rgba(240, 244, 250, 0), #f1f4fa); }
.qcard-foot { display: flex; align-items: center; gap: 6px; margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); flex-wrap: wrap; }
.qsel { position: absolute; top: 14px; right: 14px; }
.pager { display: flex; align-items: center; justify-content: center; gap: 6px; margin: 18px 0 4px; flex-wrap: wrap; }
.pager .btn.on { background: var(--blue-soft); color: var(--blue-strong); border-color: transparent; }

.detail { position: sticky; top: 76px; max-height: calc(100vh - 92px); display: flex; flex-direction: column; overflow: hidden; }
.detail-head { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.detail-body { overflow: auto; padding: 18px 20px 28px; }
.detail-nav { display: flex; align-items: center; gap: 6px; }
.section { margin-top: 22px; }
.section-title { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; font-size: 13px; font-weight: 650; color: var(--ink-2); letter-spacing: .02em; }
.section-title::before { content: ""; width: 4px; height: 14px; border-radius: 4px; background: var(--grad); }
.empty-note { padding: 12px 14px; border-radius: 10px; background: var(--surface-2); border: 1px dashed var(--line-2); color: var(--muted); font-size: 13px; }
.source-box { font-size: 13px; }
.source-box code { font-family: var(--mono); font-size: 12px; background: var(--surface-3); padding: 1px 6px; border-radius: 6px; word-break: break-all; }
.latex-src { margin: 0; padding: 12px 14px; max-height: 360px; overflow: auto; background: #f7f8fb; border: 1px solid var(--line); border-radius: 10px; font: 12px/1.6 var(--mono); white-space: pre-wrap; word-break: break-word; color: #3b465a; }
.attr-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; }
.attr-grid .field > span { display: flex; gap: 6px; align-items: center; }
.origin { font-size: 10px; color: var(--muted); font-weight: 500; padding: 0 5px; border-radius: 4px; background: var(--surface-3); }
.note { padding: 10px 12px; border-radius: 10px; background: #fbfaf6; border: 1px solid #efe9da; }
.note .meta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.note p { margin: 4px 0 0; white-space: pre-wrap; }

/* ---------- question typography (rendered LaTeX) ---------- */
.qtext { font-size: 15.5px; line-height: 1.9; color: #222c3d; overflow-wrap: anywhere; }
.qtext .p { margin: 0 0 .45em; }
.qtext .math .katex { font-size: 1.05em; }
.qtext .math-d { margin: .5em 0; overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.qtext .katex-display { margin: 0; }
.qtext .q-meta { display: inline-flex; gap: 8px; align-items: center; margin: 0 14px 6px 0; font-size: 13px; color: var(--ink-2); }
.qtext .q-meta-k { font-size: 11px; color: var(--muted); padding: 0 6px; border-radius: 4px; background: var(--surface-3); }
.qtext .q-section { margin: .3em 0 .5em; font-weight: 650; color: var(--blue-strong); }
.qtext .q-kp { margin: .8em 0 .3em; font-size: 12px; font-weight: 650; color: var(--muted); letter-spacing: .06em; }
.qtext .q-label { margin-top: .6em; font-weight: 650; }
.qtext .choices { display: grid; gap: .2em 1.2em; margin: .4em 0 .5em; }
.qtext .choices.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.qtext .choices.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.qtext .choices.cols-1 { grid-template-columns: 1fr; }
.qtext .choice { min-width: 0; }
.qtext .center { text-align: center; margin: .4em 0; }
.qtext .minipage { display: inline-block; vertical-align: top; max-width: 100%; }
.qtext .minipage.center { text-align: center; }
.qtext .q-img { max-width: 100%; height: auto; vertical-align: middle; border-radius: 4px; }
.qtext .q-fig { margin: .5em 0; text-align: center; }
.qtext .q-fig figcaption { font-size: 12px; color: var(--muted); }
.qtext .blank { display: inline-block; border-bottom: 1px solid #5c677a; height: 1.1em; vertical-align: -0.15em; margin: 0 2px; }
.qtext .hs { display: inline-block; }
.qtext .hfill { display: inline-block; width: 2em; }
.qtext .stack { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; line-height: 1.3; }
.qtext .boxed { border: 1px solid currentColor; padding: 0 3px; }
.qtext .muted-ink { color: var(--ink-2); }
.qtext .scroll-x { overflow-x: auto; margin: .4em 0; }
.qtext table.q-table { border-collapse: collapse; margin: 0 auto; font-size: .95em; line-height: 1.6; }
.qtext table.q-table td { padding: 4px 10px; border-top: 1px solid transparent; }
.qtext table.q-table tr.rule td { border-top: 1px solid #9aa4b5; }
.qtext table.q-table tr:last-child td { border-bottom: 1px solid #9aa4b5; }
.qtext table.q-table.bordered td { border: 1px solid #9aa4b5; }
.qtext .xelatex-needed, .qtext .img-missing { display: block; margin: .5em 0; padding: 10px 12px; border-radius: 10px; background: var(--ochre-soft); color: #7a5c27; font-size: 13px; }
.qtext .math-error { font-family: var(--mono); font-size: 12px; color: var(--danger); background: var(--danger-soft); padding: 0 4px; border-radius: 4px; }
.qtext ol, .qtext ul { margin: .3em 0; padding-left: 1.6em; }
mark.hit { background: #fbe7b5; color: inherit; border-radius: 3px; padding: 0 1px; }

/* ---------- selection tray ---------- */
.tray {
  position: fixed; left: calc(var(--sidebar-w) + 24px); right: 24px; bottom: 18px; z-index: 30; margin: 0 auto; max-width: 860px;
  display: flex; align-items: center; gap: 12px; padding: 10px 12px 10px 18px; border-radius: 16px;
  background: rgba(29, 39, 56, .92); color: #fff; box-shadow: var(--shadow-3); backdrop-filter: blur(10px);
  transform: translateY(140%); transition: transform .25s cubic-bezier(.2, .8, .2, 1);
}
.tray.show { transform: none; }
.tray .count { font-weight: 650; }
.tray .btn { height: 34px; }
.tray .btn.ghost { color: #cfd7e6; }
.tray .btn.ghost:hover { background: rgba(255, 255, 255, .08); }

/* ---------- sets ---------- */
.set-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.set-card { padding: 18px; display: flex; flex-direction: column; gap: 10px; cursor: pointer; transition: transform .15s, box-shadow .15s; }
.set-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); }
.set-card h3 { margin: 0; font-size: 16px; }
.set-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; align-items: start; }
.set-items { display: flex; flex-direction: column; gap: 8px; }
.set-group-head { display: flex; align-items: center; gap: 8px; margin: 10px 0 2px; }
.set-group-head input { font-weight: 650; color: var(--blue-strong); border: 1px dashed transparent; background: transparent; padding: 2px 6px; border-radius: 6px; min-width: 6em; }
.set-group-head input:hover, .set-group-head input:focus { border-color: var(--line-2); background: var(--surface); outline: none; }
.set-item { display: grid; grid-template-columns: 26px 36px minmax(0, 1fr) auto; gap: 10px; align-items: start; padding: 12px 14px; }
.set-item.dragging { opacity: .45; }
.set-item.drop-before { box-shadow: 0 -3px 0 0 var(--blue) inset, var(--shadow-1); }
.set-item.drop-after { box-shadow: 0 3px 0 0 var(--blue) inset, var(--shadow-1); }
.drag-handle { cursor: grab; color: var(--faint); display: grid; place-items: center; height: 28px; border: 0; background: transparent; border-radius: 6px; }
.drag-handle:hover { color: var(--ink-2); background: var(--surface-3); }
.set-pos { font-weight: 650; color: var(--blue-strong); font-variant-numeric: tabular-nums; padding-top: 3px; }
.set-item .qtext { font-size: 14.5px; max-height: 220px; overflow: hidden; }
.set-item .meta { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; align-items: center; }
.side-panel { position: sticky; top: 76px; display: flex; flex-direction: column; gap: 14px; }
.history-item { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.history-item:last-child { border-bottom: 0; }

/* ---------- modal / toast ---------- */
.modal-backdrop { position: fixed; inset: 0; z-index: 60; background: rgba(29, 39, 56, .32); backdrop-filter: blur(3px); display: grid; place-items: center; padding: 20px; animation: fade .15s ease; }
.modal { width: 100%; max-width: 520px; max-height: calc(100vh - 40px); display: flex; flex-direction: column; background: var(--surface); border-radius: var(--r-xl); box-shadow: var(--shadow-3); animation: pop .18s cubic-bezier(.2, .8, .2, 1); }
.modal.wide { max-width: 860px; }
.modal-head { padding: 18px 22px 8px; display: flex; align-items: center; gap: 12px; }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-body { padding: 8px 22px 16px; overflow: auto; }
.modal-foot { padding: 14px 22px 18px; display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--line); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.toasts { position: fixed; top: 16px; right: 16px; z-index: 80; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { pointer-events: auto; min-width: 240px; max-width: 380px; padding: 12px 14px; border-radius: 12px; background: var(--surface); box-shadow: var(--shadow-3); border-left: 4px solid var(--blue); display: flex; gap: 10px; align-items: flex-start; animation: pop .2s ease; }
.toast.ok { border-left-color: var(--sage); }
.toast.err { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--ochre); }
.toast .t-body { flex: 1; }
.toast .t-title { font-weight: 600; }
.toast .t-msg { color: var(--ink-2); font-size: 13px; }
.toast .btn { margin-top: 6px; }

/* ---------- states ---------- */
.state { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 48px 20px; text-align: center; color: var(--muted); }
.state .ico { width: 34px; height: 34px; color: var(--faint); }
.state h4 { margin: 4px 0 0; color: var(--ink-2); font-size: 15px; }
.skeleton { border-radius: var(--r-lg); background: linear-gradient(90deg, #edf0f5 0%, #f6f8fb 50%, #edf0f5 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid rgba(90, 123, 171, .25); border-top-color: var(--blue); animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.progress { height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--grad); width: 40%; animation: indet 1.4s ease-in-out infinite; border-radius: inherit; }
@keyframes indet { 0% { transform: translateX(-100%); } 100% { transform: translateX(260%); } }

/* ---------- AI panel ---------- */
.ai-panel { position: fixed; top: 0; right: 0; bottom: 0; z-index: 50; width: min(440px, 100vw); background: var(--surface); border-left: 1px solid var(--line); box-shadow: var(--shadow-3); display: flex; flex-direction: column; transform: translateX(102%); transition: transform .25s cubic-bezier(.2, .8, .2, 1); }
.ai-panel.open { transform: none; }
.ai-head { padding: 14px 16px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); background: var(--grad-soft); }
.ai-head h3 { margin: 0; font-size: 15px; }
.ai-context { padding: 8px 16px; font-size: 12px; color: var(--ink-2); border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 6px; background: var(--surface-2); }
.ai-log { flex: 1; overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.ai-msg { max-width: 92%; padding: 10px 14px; border-radius: 16px; line-height: 1.65; white-space: pre-wrap; word-break: break-word; }
.ai-msg.user { align-self: flex-end; background: var(--blue); color: #fff; border-bottom-right-radius: 6px; }
.ai-msg.assistant { align-self: flex-start; background: var(--surface-3); border-bottom-left-radius: 6px; }
.ai-tool { align-self: stretch; font-size: 12px; border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; background: var(--surface); }
.ai-tool summary { cursor: pointer; display: flex; gap: 8px; align-items: center; list-style: none; }
.ai-tool summary::-webkit-details-marker { display: none; }
.ai-tool pre { margin: 8px 0 0; max-height: 200px; overflow: auto; font: 11px/1.5 var(--mono); white-space: pre-wrap; background: var(--surface-2); padding: 8px; border-radius: 8px; }
.ai-action { align-self: stretch; border: 1px solid #d9d3ea; background: #faf9fd; border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.ai-results { display: flex; flex-direction: column; gap: 6px; }
.ai-result { display: flex; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 8px; background: var(--surface); border: 1px solid var(--line); font-size: 12px; }
.ai-input { padding: 12px; border-top: 1px solid var(--line); display: flex; gap: 8px; align-items: flex-end; }
.ai-input .textarea { min-height: 44px; max-height: 160px; }
.ai-suggest { display: flex; flex-wrap: wrap; gap: 6px; }
.ai-suggest button { border: 1px solid var(--line); background: var(--surface); padding: 6px 10px; border-radius: 999px; font-size: 12px; color: var(--ink-2); cursor: pointer; }
.ai-suggest button:hover { border-color: #b9c8de; color: var(--blue-strong); }

/* ---------- responsive ---------- */
@media (max-width: 1600px) {
  .browse.with-detail { grid-template-columns: minmax(0, 1fr) minmax(360px, 52%); }
  .browse.with-detail .tree { display: none; }
}
@media (max-width: 1080px) {
  .two-col, .set-layout { grid-template-columns: 1fr; }
  .side-panel { position: static; }
  .login-page { grid-template-columns: 1fr; }
  .login-art { display: none; }
}
@media (max-width: 920px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 70; left: 0; width: 260px; transform: translateX(-102%); transition: transform .22s ease; box-shadow: var(--shadow-3); }
  .shell.nav-open .sidebar { transform: none; }
  .btn.menu-btn { display: inline-flex; }
  .browse, .browse.with-detail { grid-template-columns: 1fr; }
  .tree { position: static; max-height: 46vh; }
  .browse.with-detail .tree, .browse.with-detail .list-col { display: none; }
  .detail { position: static; max-height: none; }
  .tray { left: 16px; right: 16px; }
  .search-hint { display: none; }
}
@media (max-width: 600px) {
  .page { padding: 4px 14px 96px; }
  .topbar { padding: 10px 14px; }
  .qtext .choices.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .attr-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .set-item { grid-template-columns: 22px 28px minmax(0, 1fr); }
  .set-item > :last-child { grid-column: 3; }
  .tray { flex-wrap: wrap; }
  .search-input { padding-right: 16px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
