:root,
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f8f9fa;
  --surface: #ffffff;
  --surface-soft: #f2f3f5;
  --surface-hover: #eceef2;
  --ink: #111827;
  --muted: #6b7280;
  --line: rgba(17, 24, 39, 0.09);
  --line-strong: rgba(17, 24, 39, 0.16);
  --accent: #2b5ce6;
  --accent-hover: #1e4ad1;
  --accent-soft: #ebf1ff;
  --accent-fg: #2b5ce6;
  --accent-ink: #ffffff;
  --ok: #15803d;
  --ok-soft: #ecfdf5;
  --bad: #dc2626;
  --bad-soft: #fef2f2;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 18px 40px rgba(15, 23, 42, 0.14);
  --radius: 12px;
}

:root[data-theme="paper"] {
  color-scheme: light;
  --bg: #f4f1ea;
  --surface: #fbf9f4;
  --surface-soft: #eee9de;
  --surface-hover: #e7e1d4;
  --ink: #2c2a25;
  --muted: #6e6759;
  --line: rgba(44, 42, 37, 0.10);
  --line-strong: rgba(44, 42, 37, 0.18);
  --accent: #3b6b52;
  --accent-hover: #2f5742;
  --accent-soft: #e3efe7;
  --accent-fg: #3b6b52;
  --accent-ink: #ffffff;
  --ok: #2e6f40;
  --ok-soft: #e5f3e8;
  --bad: #c2410c;
  --bad-soft: #fff1eb;
  --warn: #a16207;
  --warn-soft: #fef7e0;
  --shadow-sm: 0 1px 2px rgba(44, 42, 37, 0.05);
  --shadow-md: 0 8px 20px rgba(44, 42, 37, 0.06);
  --shadow-lg: 0 18px 40px rgba(44, 42, 37, 0.16);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #090a0d;
  --surface: #111318;
  --surface-soft: #171a21;
  --surface-hover: #1d212b;
  --ink: #f4f4f5;
  --muted: #8b919e;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.15);
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: rgba(59, 130, 246, 0.15);
  --accent-fg: #93c5fd;
  --accent-ink: #ffffff;
  --ok: #34d399;
  --ok-soft: rgba(52, 211, 153, 0.14);
  --bad: #f87171;
  --bad-soft: rgba(248, 113, 113, 0.14);
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, 0.14);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.42);
  --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.6);
}

/* 5 套可切换主题强调色 */
:root[data-accent="indigo"] { --accent: #2b5ce6; --accent-hover: #1e4ad1; --accent-soft: #ebf1ff; --accent-fg: #2b5ce6; --accent-ink: #ffffff; }
:root[data-accent="emerald"] { --accent: #0f766e; --accent-hover: #115e59; --accent-soft: #e6f6f3; --accent-fg: #0f766e; --accent-ink: #ffffff; }
:root[data-accent="amber"] { --accent: #d97706; --accent-hover: #b45309; --accent-soft: #fef3c7; --accent-fg: #b45309; --accent-ink: #ffffff; }
:root[data-accent="violet"] { --accent: #6d28d9; --accent-hover: #5b21b6; --accent-soft: #f3e8ff; --accent-fg: #6d28d9; --accent-ink: #ffffff; }
:root[data-accent="slate"] { --accent: #18181b; --accent-hover: #09090b; --accent-soft: #e4e4e7; --accent-fg: #18181b; --accent-ink: #ffffff; }

:root[data-theme="dark"][data-accent="indigo"] { --accent: #2563eb; --accent-hover: #1d4ed8; --accent-soft: rgba(59, 130, 246, 0.15); --accent-fg: #93c5fd; --accent-ink: #ffffff; }
:root[data-theme="dark"][data-accent="emerald"] { --accent: #0d9488; --accent-hover: #0f766e; --accent-soft: rgba(45, 212, 191, 0.15); --accent-fg: #2dd4bf; --accent-ink: #ffffff; }
:root[data-theme="dark"][data-accent="amber"] { --accent: #d97706; --accent-hover: #b45309; --accent-soft: rgba(251, 191, 36, 0.15); --accent-fg: #fbbf24; --accent-ink: #ffffff; }
:root[data-theme="dark"][data-accent="violet"] { --accent: #7c3aed; --accent-hover: #6d28d9; --accent-soft: rgba(167, 139, 250, 0.15); --accent-fg: #c4b5fd; --accent-ink: #ffffff; }
:root[data-theme="dark"][data-accent="slate"] { --accent: #27272a; --accent-hover: #3f3f46; --accent-soft: rgba(255, 255, 255, 0.10); --accent-fg: #e4e4e7; --accent-ink: #f4f4f5; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; background: var(--bg); }
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 999px; }
::-webkit-scrollbar-track { background: transparent; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 0.875rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.row-gap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

select, input, textarea {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 11px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
select:focus, input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input[readonly], textarea[readonly] {
  background: var(--surface-soft);
  color: var(--muted);
  cursor: default;
}
input[readonly]:focus, textarea[readonly]:focus {
  border-color: var(--line-strong);
  box-shadow: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  background: var(--surface);
  color: var(--ink);
  transition: transform 0.1s ease, background-color 0.15s ease, border-color 0.15s ease;
}
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn.ok { background: #15803d; color: #fff; }
.btn.danger { background: #dc2626; color: #fff; }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn.ghost:hover:not(:disabled) { background: var(--surface-soft); border-color: var(--line-strong); }
.btn.soft-active { background: var(--accent-soft); color: var(--accent-fg); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.btn.tiny { padding: 5px 10px; font-size: 0.75rem; border-radius: 7px; }
.btn.icon-btn { width: 32px; height: 32px; padding: 0; border-radius: 8px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}

.muted-text { color: var(--muted); font-size: 0.8125rem; }
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent-fg);
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

.progress-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-soft);
  overflow: hidden;
}
.progress-bar > span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.25s ease;
}

.table-wrap { overflow-x: auto; }
table.data-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
}
table.data-table th, table.data-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
table.data-table th { color: var(--muted); font-size: 0.75rem; font-weight: 600; }

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 0.8125rem;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-card {
  width: 100%;
  max-width: 460px;
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  background: var(--surface);
  border-radius: 16px;
  padding: 20px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
}
.modal-card.modal-shell {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
}
.modal-shell > .modal-head {
  flex: none;
  padding: 14px 20px;
  margin-bottom: 0;
  border-bottom: 1px solid var(--line);
}
.modal-shell > form {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-shell .modal-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 20px;
}
.modal-shell .modal-foot {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 20px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.modal-head h3 { margin: 0; font-size: 1rem; }
.stack-form { display: flex; flex-direction: column; gap: 12px; }
.stack-form label { display: flex; flex-direction: column; gap: 5px; font-size: 0.8125rem; font-weight: 600; }
.stack-form label.switch-row { flex-direction: row; align-items: center; justify-content: space-between; font-weight: 500; }
.stack-form label.row-gap,
.stack-form label.inline-field { flex-direction: row; align-items: center; gap: 6px; font-weight: 400; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

.toast-container {
  position: fixed;
  right: 18px;
  bottom: 52px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: #1e293b;
  color: #fff;
  padding: 10px 15px;
  border-radius: 10px;
  font-size: 0.8125rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
}
.toast.ok { background: #15803d; }
.toast.bad { background: #dc2626; }

mark { background: #fef08a; color: #111827; padding: 0 2px; border-radius: 3px; }

.dropdown-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 176px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.dropdown-item {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  padding: 8px 10px;
  border-radius: 7px;
  cursor: pointer;
}
.dropdown-item:hover { background: var(--surface-soft); }
.dropdown-item.danger { color: var(--bad); }
.dropdown-sep { height: 1px; background: var(--line); margin: 4px 6px; }

.commit-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 200px;
  overflow-y: auto;
  padding: 8px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.75rem;
}

.ai-chat-card { flex: 1; min-height: 0; height: 100%; display: flex; flex-direction: column; gap: 8px; }
.ai-head-bar { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ai-quick-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.ai-empty-state {
  margin: auto 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 16px 8px;
  text-align: center;
}
.ai-msg-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.ai-msg { display: flex; }
.ai-msg.user { justify-content: flex-end; }
.ai-msg.assistant { justify-content: flex-start; }
.ai-msg-bubble {
  max-width: 88%;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 0.8125rem;
  line-height: 1.6;
  word-break: break-word;
}
.ai-msg.user .ai-msg-bubble { background: var(--accent); color: var(--accent-ink); }
.ai-msg.user .ai-msg-text { white-space: pre-wrap; }
.ai-msg.assistant .ai-msg-bubble { max-width: 96%; background: var(--surface); border: 1px solid var(--line); color: var(--ink); }
.ai-msg-bubble p { margin: 0 0 6px; }
.ai-msg-bubble p:last-of-type { margin-bottom: 0; }
.ai-msg-bubble h4 { margin: 6px 0 4px; font-size: 0.8438rem; }
.ai-msg-bubble ul, .ai-msg-bubble ol { margin: 4px 0 6px; padding-left: 18px; }
.ai-msg-bubble li { margin: 2px 0; }
.ai-msg-bubble code { padding: 1px 5px; border-radius: 4px; background: var(--surface-soft); font-family: ui-monospace, Menlo, monospace; font-size: 0.75rem; }
.ai-msg-bubble pre { margin: 6px 0; padding: 8px 10px; border-radius: 7px; background: var(--surface-soft); border: 1px solid var(--line); overflow-x: auto; }
.ai-msg-bubble pre code { padding: 0; background: transparent; }
.ai-msg-actions { display: flex; gap: 10px; margin-top: 6px; padding-top: 5px; border-top: 1px solid var(--line); white-space: normal; }
.ai-act-btn { border: 0; background: transparent; padding: 0; font: inherit; font-size: 0.7188rem; color: var(--muted); cursor: pointer; }
.ai-act-btn:hover { color: var(--accent-fg); }
.ai-input-row { flex: none; display: flex; gap: 6px; }
.ai-input-row input { flex: 1; min-width: 0; padding: 8px 10px; font-size: 0.8125rem; }

/* 外观切换菜单（3 底色 x 5 主题色） */
.appearance-wrap { position: relative; }
.appearance-menu { width: 236px; padding: 12px; gap: 10px; }
.appearance-label { font-size: 0.6875rem; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.theme-seg {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px;
  padding: 3px; background: var(--surface-soft); border-radius: 8px;
}
.theme-seg-btn {
  border: 0; background: transparent; color: var(--muted); font: inherit;
  font-size: 0.75rem; font-weight: 600; padding: 6px 4px; border-radius: 6px; cursor: pointer;
  white-space: nowrap;
}
.theme-seg-btn.active { background: var(--surface); color: var(--accent-fg); box-shadow: var(--shadow-sm); }
.accent-dots { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 2px 0; }
.accent-dot {
  width: 24px; height: 24px; border-radius: 50%; border: 2px solid transparent; padding: 0;
  cursor: pointer; transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.accent-dot:hover { transform: scale(1.1); }
.accent-dot.active { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }
.accent-swatch { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); display: inline-block; flex: none; }

/* 通用空状态与考试组卷面板 */
.empty-state {
  max-width: 420px; margin: 48px auto; padding: 28px 20px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.empty-state-icon {
  width: 46px; height: 46px; border-radius: 12px; display: inline-flex;
  align-items: center; justify-content: center; background: var(--accent-soft); color: var(--accent-fg);
}
.exam-section-title { font-size: 0.75rem; font-weight: 700; color: var(--muted); margin: 4px 0 0; }
.exam-seg {
  display: inline-flex; gap: 4px; padding: 3px; border-radius: 9px;
  background: var(--surface-soft); border: 1px solid var(--line); align-self: flex-start;
}
.exam-seg-opt {
  position: relative; display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: 6px; font-size: 0.8125rem; font-weight: 500;
  color: var(--muted); cursor: pointer;
}
.exam-seg-opt input { margin: 0; accent-color: var(--accent); }
.exam-seg-opt:has(input:checked) { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow-sm); }
.exam-type-list { display: flex; flex-direction: column; gap: 8px; }
.exam-type-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 8px 12px; border-radius: 8px; background: var(--surface); border: 1px solid var(--line);
}
.exam-type-row input[type="number"] { width: 66px; padding: 5px 8px; text-align: center; }
.exam-switch-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.exam-switch-item {
  padding: 8px 12px !important; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface-soft); cursor: pointer;
}
@media (max-width: 600px) { .exam-switch-grid { grid-template-columns: 1fr; } }

/* 题型语义色胶囊 + 中性题库胶囊（适配浅色/纸质/深色） */
.type-pill { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; background: var(--surface-soft); color: var(--muted); white-space: nowrap; }
.type-pill[data-qtype="0"] { background: #eff6ff; color: #1d4ed8; }
.type-pill[data-qtype="1"] { background: #f5f3ff; color: #6d28d9; }
.type-pill[data-qtype="2"] { background: #fffbeb; color: #b45309; }
.type-pill[data-qtype="3"] { background: #f0fdfa; color: #0f766e; }
.type-pill[data-qtype="4"] { background: #fdf2f8; color: #be185d; }
.type-pill[data-qtype="5"] { background: #eef2ff; color: #4338ca; }
:root[data-theme="dark"] .type-pill[data-qtype="0"] { background: rgba(59, 130, 246, .16); color: #93c5fd; }
:root[data-theme="dark"] .type-pill[data-qtype="1"] { background: rgba(139, 92, 246, .18); color: #c4b5fd; }
:root[data-theme="dark"] .type-pill[data-qtype="2"] { background: rgba(245, 158, 11, .16); color: #fcd34d; }
:root[data-theme="dark"] .type-pill[data-qtype="3"] { background: rgba(20, 184, 166, .16); color: #5eead4; }
:root[data-theme="dark"] .type-pill[data-qtype="4"] { background: rgba(236, 72, 153, .16); color: #f9a8d4; }
:root[data-theme="dark"] .type-pill[data-qtype="5"] { background: rgba(99, 102, 241, .18); color: #a5b4fc; }
.bank-pill { display: inline-flex; align-items: center; padding: 1px 8px; border-radius: 999px; font-size: 0.75rem; font-weight: 500; color: var(--muted); background: transparent; border: 1px solid var(--line); white-space: nowrap; }
