/* ==========================================================================
   三菱产品刷题工具 · 设计系统 (main.css)
   设计语言：Material You (Material Design 3)，种子色 = 三菱红 #e60012
   令牌来源：assets/css/md3-tokens.css（由 tools/gen-md3-tokens.mjs 生成）
   纯原生 CSS，无外部依赖，适配内网离线部署
   ========================================================================== */

/* --------------------------------------------------------------------------
   兼容映射层
   组件继续使用既有的语义变量名（--brand / --card / --text …），值改由 MD3 语义令牌提供。
   于是「切换设计语言」只发生在这张映射表里，上千行组件样式无需重写。

   ⚠️ 必须同时挂在 :root 与 body.dark 上：
   CSS 自定义变量是在**定义它的元素**上解析的，若只写在 :root，
   --bg 会被永久绑定为 :root 语境下的浅色 surface，body.dark 覆盖
   --md-sys-color-* 也无法影响它（深色模式会失效）。
   -------------------------------------------------------------------------- */
:root, body.dark {
  /* 品牌与状态色
     注意：这里只允许引用 --md-sys-color-*（语义层随主题切换）。
     早期版本引用了 --md-ref-primary-95 这类参考调色板值 —— 它们不随深浅模式变化，
     会导致深色模式下出现亮白色块。 */
  --brand: var(--md-sys-color-primary);
  --brand-600: var(--md-sys-color-primary);            /* 旧代码用它做 hover 加深；MD3 改用状态层，这里回落主色 */
  --brand-500: var(--md-sys-color-primary);
  --brand-100: var(--md-sys-color-primary-container);
  --brand-50: var(--md-sys-color-primary-container);

  --ok: var(--md-sys-color-success);
  --ok-bg: var(--md-sys-color-success-container);
  --warn: var(--md-sys-color-warning);
  --warn-bg: var(--md-sys-color-warning-container);
  --danger: var(--md-sys-color-error);
  --danger-bg: var(--md-sys-color-error-container);

  /* 文字与分隔：MD3 用色调表面区分层次，因此描边色取自 neutral-variant */
  --text: var(--md-sys-color-on-surface);
  --text-2: var(--md-sys-color-on-surface-variant);
  --muted: var(--md-sys-color-outline);
  --line: var(--md-sys-color-outline-variant);
  --line-2: var(--md-sys-color-surface-container-high);

  /* 表面：背景为色调表面（非纯白），卡片比背景深一档 —— Material You 的标志性层次 */
  --bg: var(--md-sys-color-surface);
  --card: var(--md-sys-color-surface-container-low);

  /* 高程：静止靠色调、交互靠阴影抬升 */
  --shadow-sm: var(--md-sys-elevation-1);
  --shadow: var(--md-sys-elevation-2);
  --shadow-lg: var(--md-sys-elevation-3);

  /* 形状：整体上调到 MD3 的圆角尺度（卡片 24 / 小元素 12 / 对话框 28） */
  --radius: var(--md-sys-shape-corner-lg);
  --radius-sm: var(--md-sys-shape-corner-sm);
  --radius-lg: var(--md-sys-shape-corner-xl);

  --header-h: 58px;
  --side-w: 216px;
  --ff: var(--md-sys-typescale-font);
  --ff-mono: var(--md-sys-typescale-font-mono);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--ff);
  font-size: var(--md-sys-typescale-body-medium);
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

/* --------------------------------------------------------------------------
   氛围层：画布外的有机模糊形状
   Material You 的深度来自「多层柔和色晕」而非重投影。纯装饰，对辅助技术隐藏。
   -------------------------------------------------------------------------- */
body::before,
body::after {
  content: '';
  position: fixed;
  z-index: 0;
  pointer-events: none;
  border-radius: var(--md-sys-shape-corner-full);
  filter: blur(80px);
}
body::before {
  width: min(520px, 60vw); height: min(520px, 60vw);
  top: -220px; right: -160px;
  background: radial-gradient(circle at 35% 35%, var(--md-sys-color-primary), transparent 70%);
  opacity: .22;
}
body::after {
  width: min(460px, 55vw); height: min(460px, 55vw);
  bottom: -200px; left: -140px;
  background: radial-gradient(circle at 55% 45%, var(--md-sys-color-tertiary), transparent 70%);
  opacity: .16;
}
@media (max-width: 560px) {
  body::before, body::after { filter: blur(60px); }
}

/* 内容层必须盖在氛围层之上 */
.app { position: relative; z-index: 1; }

h1, h2, h3, h4, h5 { margin: 0; font-weight: 600; line-height: 1.35; }
p { margin: 0 0 8px; }
a { color: var(--brand-500); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
code, pre { font-family: var(--ff-mono); }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #cbd3e0; border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #b3bdcd; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- 布局骨架 ---------- */
.app { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  height: var(--header-h);
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 18px;
  position: sticky;
  top: 0;
  z-index: 60;
  box-shadow: var(--md-sys-elevation-2);
}
/* 深色模式下 MD3 的 primary 是浅色调（tone 80），大面积铺底会过亮；
   按 top app bar 规范改用色调表面，前景色随之切到 on-surface。
   顶栏内部一律用 inherit + 白色状态层，因此两套主题都自动协调。 */
body.dark .topbar {
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface);
}

.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 16px; letter-spacing: .3px; white-space: nowrap; }
.brand .logo {
  width: 30px; height: 30px; border-radius: var(--md-sys-shape-corner-sm); flex: none;
  background: rgba(255, 255, 255, .18);       /* MD3 状态层：彩色表面上的白色叠加 */
  display: grid; place-items: center;
  border: 1px solid rgba(255, 255, 255, .30);
  font-size: 13px; font-weight: 800;
}
.brand small { font-weight: 400; font-size: 12px; opacity: .82; margin-left: 2px; }

.topbar-spacer { flex: 1; }

.topnav { display: flex; gap: 2px; }
.topnav a {
  color: inherit; opacity: .88;
  padding: 8px 14px; border-radius: var(--md-sys-shape-corner-full);
  font-size: var(--md-sys-typescale-label-large);
  display: flex; align-items: center; gap: 6px; white-space: nowrap;
  transition: background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}
.topnav a:hover { background: rgba(255, 255, 255, .14); text-decoration: none; opacity: 1; }
.topnav a.active { background: rgba(255, 255, 255, .22); font-weight: 600; opacity: 1; }

.userchip {
  display: flex; align-items: center; gap: 9px;
  background: rgba(255, 255, 255, .14);
  border: 1px solid rgba(255, 255, 255, .22);
  padding: 5px 14px 5px 5px; border-radius: var(--md-sys-shape-corner-full);
  cursor: pointer; font-size: var(--md-sys-typescale-label-large); color: inherit;
  transition: background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}
.userchip:hover { background: rgba(255, 255, 255, .24); }
.userchip:active { transform: scale(.97); }
.userchip .avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--md-sys-color-primary); color: var(--md-sys-color-on-primary);
  display: grid; place-items: center; font-weight: 700; font-size: 12px; flex: none;
}
.userchip .role { font-size: 11px; opacity: .85; }

.iconbtn {
  width: 40px; height: 40px; border-radius: var(--md-sys-shape-corner-full);
  border: none; cursor: pointer;
  background: rgba(255, 255, 255, .14); color: inherit;
  display: grid; place-items: center; flex: none;
  transition: background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard),
              transform var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}
.iconbtn:hover { background: rgba(255, 255, 255, .26); }
.iconbtn:active { transform: scale(.92); }
body:not(.dark) .iconbtn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
body.dark .iconbtn:focus-visible { outline: 2px solid var(--md-sys-color-primary); outline-offset: 2px; }

.body { flex: 1; display: flex; align-items: stretch; }

.side {
  width: var(--side-w); flex: none; background: var(--card);
  border-right: 1px solid var(--line); padding: 14px 10px 24px;
  position: sticky; top: var(--header-h); height: calc(100vh - var(--header-h));
  overflow-y: auto;
}
.side .group-title {
  font-size: 11px; color: var(--muted); font-weight: 600; letter-spacing: .8px;
  padding: 12px 12px 6px; text-transform: uppercase;
}
.side a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 8px; color: var(--text-2);
  font-size: 13.5px; margin-bottom: 2px;
}
.side a:hover { background: var(--line-2); text-decoration: none; color: var(--brand); }
.side a.active { background: var(--brand-50); color: var(--brand); font-weight: 600; }
.side a .ico { width: 17px; height: 17px; flex: none; opacity: .9; }
.side a .badge { margin-left: auto; }

.main { flex: 1; min-width: 0; padding: 20px 22px 64px; }
.page-narrow { max-width: 880px; margin: 0 auto; }

.page-head { margin-bottom: 18px; }
.page-head h2 { font-size: 20px; display: flex; align-items: center; gap: 9px; }
.page-head p { color: var(--muted); font-size: 13px; margin: 4px 0 0; }

/* ---------- 卡片 / 栅格（MD3：靠色调表面分层，静止时不投影） ---------- */
.card {
  background: var(--md-sys-color-surface-container-low);
  border: 1px solid transparent;
  border-radius: var(--md-sys-shape-corner-lg);
  padding: 20px 22px; margin-bottom: 16px;
}
.card.tight { padding: 14px 16px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.card-head h3 { font-size: 15px; }
.card-head .spacer { flex: 1; }
.card-sub { color: var(--muted); font-size: 12.5px; }

.grid { display: grid; gap: 14px; }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.c5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }

.stat {
  background: var(--md-sys-color-surface-container);
  border: 1px solid transparent;
  border-radius: var(--md-sys-shape-corner-lg);
  padding: 16px 18px; position: relative; overflow: hidden;
}
.stat .label { color: var(--muted); font-size: 12.5px; display: flex; align-items: center; gap: 6px; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 5px; line-height: 1.15; letter-spacing: -.4px; }
.stat .value small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 3px; }
.stat .foot { font-size: 12px; color: var(--muted); margin-top: 3px; }
.stat::after {
  content: ''; position: absolute; right: -26px; top: -26px; width: 76px; height: 76px;
  border-radius: 50%; background: var(--brand-50);
}
.stat.ok::after { background: var(--ok-bg); }
.stat.warn::after { background: var(--warn-bg); }
.stat.danger::after { background: var(--danger-bg); }
.stat > * { position: relative; z-index: 1; }

/* ---------- 按钮（MD3：全部药丸形 + 状态层 + 触觉反馈） ---------- */
.btn {
  position: relative; isolation: isolate;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 20px;
  border-radius: var(--md-sys-shape-corner-full);      /* MD3 按钮一律全圆角 */
  border: 1px solid var(--md-sys-color-outline);
  background: transparent; color: var(--md-sys-color-primary);
  cursor: pointer; font-size: var(--md-sys-typescale-label-large);
  font-weight: 500; letter-spacing: .01em; white-space: nowrap;
  transition: box-shadow var(--md-sys-motion-duration-medium) var(--md-sys-motion-easing-standard),
              transform var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard),
              background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}
/* 状态层：MD3 不通过改底色表达悬停，而是叠加一层当前前景色的不透明度 */
.btn::before {
  content: ''; position: absolute; inset: 0; z-index: -1;
  border-radius: inherit; background: currentColor; opacity: 0;
  transition: opacity var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}
.btn:hover::before { opacity: var(--md-sys-state-hover-opacity); }
.btn:active::before { opacity: var(--md-sys-state-pressed-opacity); }
.btn:active { transform: scale(.95); }                 /* 触觉按压反馈 */
.btn:focus-visible {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

/* 填充（主要）：主色底 + on-primary 文字 */
.btn.primary {
  background: var(--md-sys-color-primary);
  border-color: transparent;
  color: var(--md-sys-color-on-primary);
}
.btn.primary:hover { box-shadow: var(--md-sys-elevation-1); }

/* 色调（成功/危险）：容器色底 + 对应 on- 文字 */
.btn.ok {
  background: var(--md-sys-color-success);
  border-color: transparent;
  color: var(--md-sys-color-on-success);
}
.btn.danger {
  background: var(--md-sys-color-error-container);
  border-color: transparent;
  color: var(--md-sys-color-on-error-container);
}
.btn.danger:hover { box-shadow: var(--md-sys-elevation-1); }

/* 文本/幽灵：无边框、无底色，仅状态层 */
.btn.ghost {
  border-color: transparent; background: transparent;
  color: var(--md-sys-color-primary);
  padding: 6px 12px; min-height: 36px;
}
.btn.ghost.sm { padding: 4px 10px; min-height: 30px; }

.btn.sm { padding: 5px 14px; font-size: var(--md-sys-typescale-label-small); min-height: 32px; }
.btn.lg { padding: 12px 28px; font-size: var(--md-sys-typescale-title-medium); min-height: 48px; }
.btn.block { width: 100%; }
.btn[disabled], .btn.disabled {
  opacity: var(--md-sys-state-disabled-opacity);
  cursor: not-allowed; pointer-events: none; box-shadow: none;
}
.btn-row { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; }
.btn-row.end { justify-content: flex-end; }

/* ---------- 表单 ---------- */
.field { margin-bottom: 13px; }
.field > label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 5px; color: var(--text-2); }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
input[type=text], input[type=number], input[type=password], input[type=date], input[type=datetime-local], select, textarea {
  width: 100%; padding: 13px 14px 11px;
  /* MD3 填充式文本框：仅上方圆角，下方以 2px 描边收口 */
  border: none;
  border-bottom: 2px solid var(--md-sys-color-on-surface-variant);
  border-radius: var(--md-sys-shape-corner-xs) var(--md-sys-shape-corner-xs) 0 0;
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
  outline: none;
  transition: background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard),
              border-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}
input[type=text]:hover, input[type=number]:hover, input[type=password]:hover,
input[type=date]:hover, input[type=datetime-local]:hover, select:hover, textarea:hover {
  background: var(--md-sys-color-surface-container-highest);
}
input[type=text]:focus, input[type=number]:focus, input[type=password]:focus,
input[type=date]:focus, input[type=datetime-local]:focus, select:focus, textarea:focus {
  border-bottom-color: var(--md-sys-color-primary);
  background: var(--md-sys-color-surface-container-highest);
}
input::placeholder, textarea::placeholder { color: var(--md-sys-color-on-surface-variant); opacity: .75; }
textarea { resize: vertical; min-height: 88px; line-height: 1.6; }
select { cursor: pointer; }
.inline-fields { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.inline-fields .field { margin-bottom: 0; flex: 1 1 150px; min-width: 130px; }

.checkline { display: flex; align-items: center; gap: 8px; font-size: 13.5px; cursor: pointer; user-select: none; }
.checkline input { width: 16px; height: 16px; accent-color: var(--brand); cursor: pointer; flex: none; }

/* 分段选择器（MD3 segmented button） */
.segment {
  display: inline-flex; background: var(--md-sys-color-surface-container-high);
  border-radius: var(--md-sys-shape-corner-full); padding: 3px; gap: 2px; flex-wrap: wrap;
}
.segment button {
  border: none; background: transparent; padding: 7px 15px;
  border-radius: var(--md-sys-shape-corner-full);
  cursor: pointer; font-size: var(--md-sys-typescale-label-large);
  color: var(--md-sys-color-on-surface-variant);
  transition: background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard),
              color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}
.segment button:hover { background: var(--md-sys-color-surface-container-highest); }
.segment button.on {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  font-weight: 500; box-shadow: var(--md-sys-elevation-1);
}

/* 多选块（chip）：MD3 filter chip —— 按设计规范统一为药丸形，选中态用 secondary-container */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--md-sys-color-outline-variant);
  background: transparent;
  border-radius: var(--md-sys-shape-corner-full);
  min-height: 34px; padding: 6px 16px;
  cursor: pointer; font-size: var(--md-sys-typescale-label-large);
  color: var(--md-sys-color-on-surface-variant);
  display: inline-flex; align-items: center; gap: 6px;
  transition: background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard),
              color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard),
              border-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}
.chip:hover { background: var(--md-sys-color-surface-container-highest); }
.chip:active { transform: scale(.96); }
.chip.on {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  border-color: transparent; font-weight: 500;
}
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .55; }

/* ---------- 标签 / 徽记 ---------- */
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 10px; border-radius: var(--md-sys-shape-corner-full);
  font-size: var(--md-sys-typescale-label-small);
  background: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-on-surface-variant);
  border: 1px solid transparent; white-space: nowrap;
}
.tag.brand { background: var(--md-sys-color-primary-container); color: var(--md-sys-color-on-primary-container); }
.tag.ok { background: var(--md-sys-color-success-container); color: var(--md-sys-color-on-success-container); }
.tag.warn { background: var(--md-sys-color-warning-container); color: var(--md-sys-color-on-warning-container); }
.tag.danger { background: var(--md-sys-color-error-container); color: var(--md-sys-color-on-error-container); }
.tag.outline { background: transparent; border-color: var(--md-sys-color-outline-variant); color: var(--md-sys-color-on-surface-variant); }
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }

.badge {
  background: var(--md-sys-color-error); color: var(--md-sys-color-on-error);
  font-size: 11px; line-height: 1; padding: 3px 7px;
  border-radius: var(--md-sys-shape-corner-full); font-weight: 600;
}
.badge.gray { background: var(--md-sys-color-outline); color: var(--md-sys-color-surface); }

.dif { display: inline-flex; gap: 2px; align-items: center; }
.dif i { width: 6px; height: 6px; border-radius: 50%; background: var(--md-sys-color-outline-variant); display: block; }
.dif i.on { background: var(--md-sys-color-warning); }

.secmark {
  font-size: 11px; padding: 1px 8px; border-radius: var(--md-sys-shape-corner-full);
  background: var(--md-sys-color-error-container); color: var(--md-sys-color-on-error-container);
  border: 1px solid transparent;
}
.secmark.internal { background: var(--md-sys-color-warning-container); color: var(--md-sys-color-on-warning-container); }
.secmark.public { background: var(--md-sys-color-success-container); color: var(--md-sys-color-on-success-container); }

/* ---------- 进度条 ---------- */
.bar { height: 8px; border-radius: var(--md-sys-shape-corner-full); background: var(--md-sys-color-surface-container-highest); overflow: hidden; }
.bar > i {
  display: block; height: 100%; background: var(--md-sys-color-primary); border-radius: inherit;
  transition: width var(--md-sys-motion-duration-long) var(--md-sys-motion-easing-standard);
}
.bar.ok > i { background: var(--md-sys-color-success); }
.bar.warn > i { background: var(--md-sys-color-warning); }
.bar.danger > i { background: var(--md-sys-color-error); }
.bar.thin { height: 6px; }

/* ---------- 题目卡 ---------- */
.qcard {
  background: var(--md-sys-color-surface-container-low);
  border: 1px solid transparent;
  border-radius: var(--md-sys-shape-corner-lg);
}
.qhead {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 12px 18px; border-bottom: 1px solid var(--md-sys-color-outline-variant);
  font-size: var(--md-sys-typescale-label-small); color: var(--md-sys-color-on-surface-variant);
}
.qhead .spacer { flex: 1; }
.qbody { padding: 18px; }
.qstem { font-size: var(--md-sys-typescale-body-large); line-height: 1.75; font-weight: 500; margin-bottom: 14px; white-space: pre-wrap; }
.qstem .qno { color: var(--md-sys-color-primary); font-weight: 700; margin-right: 6px; }

.opts { display: flex; flex-direction: column; gap: 9px; }
.opt {
  display: flex; gap: 11px; align-items: flex-start;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-md);
  padding: 12px 14px; cursor: pointer;
  background: var(--md-sys-color-surface-container-lowest);
  transition: background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard),
              border-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}
.opt:hover { border-color: var(--md-sys-color-primary); background: var(--md-sys-color-surface-container); }
.opt:active { transform: scale(.99); }
.opt .key {
  width: 26px; height: 26px; border-radius: var(--md-sys-shape-corner-full); flex: none;
  border: 1px solid var(--md-sys-color-outline); display: grid; place-items: center;
  font-weight: 700; font-size: 12.5px;
  color: var(--md-sys-color-on-surface-variant); background: transparent;
}
.opt .txt { flex: 1; padding-top: 2px; }
.opt.sel { border-color: var(--md-sys-color-primary); background: var(--md-sys-color-primary-container); }
.opt.sel .key { background: var(--md-sys-color-primary); border-color: transparent; color: var(--md-sys-color-on-primary); }
/* 语义类统一用 is-correct / is-wrong，避免与工具类 .right / .wrong（text-align）冲突 */
.opt.is-correct { border-color: var(--md-sys-color-success); background: var(--md-sys-color-success-container); }
.opt.is-correct .key { background: var(--md-sys-color-success); border-color: transparent; color: var(--md-sys-color-on-success); }
.opt.is-wrong { border-color: var(--md-sys-color-error); background: var(--md-sys-color-error-container); }
.opt.is-wrong .key { background: var(--md-sys-color-error); border-color: transparent; color: var(--md-sys-color-on-error); }
.opt.locked { cursor: default; }
.opt.locked:hover { border-color: var(--md-sys-color-outline-variant); background: var(--md-sys-color-surface-container-lowest); }
.opt.locked.is-correct:hover { border-color: var(--md-sys-color-success); background: var(--md-sys-color-success-container); }
.opt.locked.is-wrong:hover { border-color: var(--md-sys-color-error); background: var(--md-sys-color-error-container); }
.opt .txt { text-align: left; }

.answer-panel {
  margin-top: 14px; border-radius: var(--md-sys-shape-corner-md); padding: 14px 16px;
  font-size: var(--md-sys-typescale-body-medium); line-height: 1.7;
  text-align: left;   /* 防御：解析与参考答案始终左对齐，不受外部工具类影响 */
}
.answer-panel.is-correct { background: var(--md-sys-color-success-container); border: 1px solid transparent; }
.answer-panel.is-wrong { background: var(--md-sys-color-error-container); border: 1px solid transparent; }
.answer-panel .title { font-weight: 700; display: flex; align-items: center; gap: 7px; margin-bottom: 7px; }
.answer-panel.is-correct .title { color: var(--md-sys-color-on-success-container); }
.answer-panel.is-wrong .title { color: var(--md-sys-color-on-error-container); }
.answer-panel .ana { color: var(--md-sys-color-on-surface-variant); white-space: pre-wrap; text-align: left; }
.answer-panel .src {
  margin-top: 9px; padding-top: 9px; border-top: 1px dashed var(--md-sys-color-outline-variant);
  font-size: var(--md-sys-typescale-label-small); color: var(--md-sys-color-on-surface-variant); text-align: left;
}
.ref-answer {
  background: var(--md-sys-color-surface-container-lowest);
  border: 1px dashed var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-sm);
  padding: 10px 12px; margin: 6px 0; white-space: pre-wrap; text-align: left;
}

.selfjudge { display: flex; gap: 9px; flex-wrap: wrap; margin-top: 10px; }

/* ---------- 填空题 ---------- */
.fill-box { display: flex; flex-direction: column; gap: 10px; }
.fill-item { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.fill-item .k { font-size: var(--md-sys-typescale-label-small); color: var(--md-sys-color-on-surface-variant); flex: none; width: 50px; }
.fill-item input {
  flex: 1 1 240px; max-width: 340px;
  padding: 12px 14px 10px;
  border: none;
  border-bottom: 2px solid var(--md-sys-color-on-surface-variant);
  border-radius: var(--md-sys-shape-corner-xs) var(--md-sys-shape-corner-xs) 0 0;
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
  outline: none; text-align: left;
  transition: background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard),
              border-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}
.fill-item input:focus { border-bottom-color: var(--md-sys-color-primary); background: var(--md-sys-color-surface-container-highest); }
.fill-item input[readonly] { background: var(--md-sys-color-surface-container); cursor: default; }
.fill-item.is-correct input {
  border-bottom-color: var(--md-sys-color-success);
  background: var(--md-sys-color-success-container);
  color: var(--md-sys-color-on-success-container); font-weight: 600;
}
.fill-item.is-wrong input {
  border-bottom-color: var(--md-sys-color-error);
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
}
.fill-item .std { font-size: var(--md-sys-typescale-label-small); color: var(--md-sys-color-success); flex: none; }
.fill-item.is-wrong .std { color: var(--md-sys-color-error); }

/* ---------- 表格（MD3：色调表头 + 无竖线） ---------- */
.table-wrap {
  overflow-x: auto; border: 1px solid transparent;
  border-radius: var(--md-sys-shape-corner-lg);
  background: var(--md-sys-color-surface-container-low);
}
table.tbl { width: 100%; border-collapse: collapse; font-size: var(--md-sys-typescale-body-medium); min-width: 560px; }
table.tbl th, table.tbl td {
  padding: 11px 14px; text-align: left;
  border-bottom: 1px solid var(--md-sys-color-outline-variant); vertical-align: middle;
}
table.tbl th {
  background: var(--md-sys-color-surface-container-high);
  font-weight: 600; color: var(--md-sys-color-on-surface-variant);
  white-space: nowrap; font-size: var(--md-sys-typescale-label-small); position: sticky; top: 0;
}
table.tbl tbody tr { transition: background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard); }
table.tbl tbody tr:hover { background: var(--md-sys-color-surface-container-high); }
table.tbl tbody tr:last-child td { border-bottom: none; }
table.tbl td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.tbl td.center, table.tbl th.center { text-align: center; }
.cell-stem { max-width: 430px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 列表 ---------- */
.list { display: flex; flex-direction: column; gap: 9px; }
.list-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  border: 1px solid transparent;
  border-radius: var(--md-sys-shape-corner-md);
  background: var(--md-sys-color-surface-container-lowest);
  transition: box-shadow var(--md-sys-motion-duration-medium) var(--md-sys-motion-easing-standard),
              background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}
.list-item:hover { box-shadow: var(--md-sys-elevation-1); background: var(--md-sys-color-surface-container-low); }
.list-item .spacer { flex: 1; }
.list-item .ttl { font-weight: 600; font-size: var(--md-sys-typescale-label-large); }
.list-item .sub { font-size: var(--md-sys-typescale-label-small); color: var(--md-sys-color-on-surface-variant); margin-top: 2px; }

.empty { text-align: center; padding: 48px 20px; color: var(--md-sys-color-outline); }
.empty .big { font-size: 34px; margin-bottom: 8px; opacity: .5; }
.empty p { font-size: var(--md-sys-typescale-body-medium); }

/* ---------- 考试 ---------- */
.exam-top {
  position: sticky; top: var(--header-h); z-index: 40;
  background: var(--md-sys-color-surface-container);
  border: 1px solid transparent;
  border-radius: var(--md-sys-shape-corner-lg);
  padding: 12px 18px; display: flex; align-items: center; gap: 14px; margin-bottom: 15px;
  box-shadow: var(--md-sys-elevation-2); flex-wrap: wrap;
}
.timer { font-family: var(--ff-mono); font-size: 19px; font-weight: 700; color: var(--md-sys-color-primary); letter-spacing: .5px; }
.timer.danger { color: var(--md-sys-color-error); animation: blink 1.1s infinite; }
@keyframes blink { 50% { opacity: .42; } }

.qnav { display: flex; flex-wrap: wrap; gap: 7px; }
.qnav button {
  width: 36px; height: 36px;
  border-radius: var(--md-sys-shape-corner-full);
  border: 1px solid var(--md-sys-color-outline-variant);
  background: transparent; cursor: pointer;
  font-size: var(--md-sys-typescale-label-small);
  color: var(--md-sys-color-on-surface-variant); position: relative;
  transition: background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}
.qnav button:hover { background: var(--md-sys-color-surface-container-highest); }
.qnav button:active { transform: scale(.94); }
.qnav button.cur { outline: 2px solid var(--md-sys-color-primary); outline-offset: 1px; font-weight: 700; }
.qnav button.done {
  background: var(--md-sys-color-primary-container);
  border-color: transparent; color: var(--md-sys-color-on-primary-container);
}
.qnav button.mark::after {
  content: ''; position: absolute; top: 2px; right: 2px; width: 7px; height: 7px;
  border-radius: 50%; background: var(--md-sys-color-warning);
}

/* ---------- 图表 ---------- */
.chart { width: 100%; overflow: visible; }
.chart .axis { stroke: var(--md-sys-color-outline-variant); stroke-width: 1; }
.chart .grid-line { stroke: var(--md-sys-color-surface-container-high); stroke-width: 1; }
.chart text { font-size: 11px; fill: var(--md-sys-color-outline); font-family: var(--ff); }
.chart .lbl { fill: var(--md-sys-color-on-surface-variant); font-size: 12px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: var(--md-sys-typescale-label-small); color: var(--md-sys-color-on-surface-variant); margin-top: 8px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 5px; }

.donut-wrap { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.donut-center { font-size: 22px; font-weight: 700; }

/* ---------- 模态框（MD3 dialog：28px 圆角 + 色调表面 + 遮罩） ---------- */
.modal-mask {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, .32);
  z-index: 200;
  display: grid; place-items: center; padding: 20px;
  backdrop-filter: blur(3px);
  animation: fadein var(--md-sys-motion-duration-medium) var(--md-sys-motion-easing-standard);
}
@keyframes fadein { from { opacity: 0; } }
.modal {
  background: var(--md-sys-color-surface-container-high);
  border-radius: var(--md-sys-shape-corner-xl);
  box-shadow: var(--md-sys-elevation-5);
  width: 100%; max-width: 560px; max-height: 88vh; display: flex; flex-direction: column;
  animation: pop var(--md-sys-motion-duration-medium) var(--md-sys-motion-easing-standard);
}
.modal.wide { max-width: 820px; }
@keyframes pop { from { transform: translateY(14px) scale(.97); opacity: 0; } }
.modal-head { padding: 18px 22px 12px; display: flex; align-items: center; gap: 10px; }
.modal-head h3 { font-size: var(--md-sys-typescale-title-large); font-weight: 500; }
.modal-head .spacer { flex: 1; }
.modal-body { padding: 4px 22px 18px; overflow-y: auto; }
.modal-foot { padding: 12px 22px 20px; display: flex; gap: 10px; justify-content: flex-end; }

/* ---------- Toast（MD3 snackbar 风格：反色表面） ---------- */
.toasts { position: fixed; top: 70px; right: 20px; z-index: 300; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--md-sys-color-inverse-surface);
  color: var(--md-sys-color-inverse-on-surface);
  padding: 12px 20px;
  border-radius: var(--md-sys-shape-corner-sm);
  box-shadow: var(--md-sys-elevation-3);
  font-size: var(--md-sys-typescale-body-medium);
  animation: slidein var(--md-sys-motion-duration-medium) var(--md-sys-motion-easing-standard);
  max-width: 340px;
}
.toast.ok { border-left: 4px solid var(--md-sys-color-success); }
.toast.err { border-left: 4px solid var(--md-sys-color-error); }
.toast.warn { border-left: 4px solid var(--md-sys-color-warning); }
@keyframes slidein { from { transform: translateX(24px); opacity: 0; } }

/* ---------- 其它 ---------- */
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: var(--ff-mono); }
.center { text-align: center; }
.right { text-align: right; }
.mt0 { margin-top: 0; } .mt8 { margin-top: 8px; } .mt12 { margin-top: 12px; } .mt16 { margin-top: 16px; } .mt24 { margin-top: 24px; }
.mb0 { margin-bottom: 0; } .mb8 { margin-bottom: 8px; } .mb12 { margin-bottom: 12px; } .mb16 { margin-bottom: 16px; }
.flex { display: flex; } .aic { align-items: center; } .jcb { justify-content: space-between; }
.gap6 { gap: 6px; } .gap10 { gap: 10px; } .gap14 { gap: 14px; }
.wrap { flex-wrap: wrap; }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.divider { height: 1px; background: var(--md-sys-color-outline-variant); margin: 14px 0; }
.kbd {
  font-family: var(--ff-mono); font-size: 11.5px;
  background: var(--md-sys-color-surface-container-highest);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-bottom-width: 2px; border-radius: 5px; padding: 1px 6px;
}
.note {
  background: var(--md-sys-color-primary-container);
  border: 1px solid transparent;
  border-radius: var(--md-sys-shape-corner-md);
  padding: 12px 16px; font-size: var(--md-sys-typescale-body-medium);
  color: var(--md-sys-color-on-primary-container);
}
.note.warn { background: var(--md-sys-color-warning-container); color: var(--md-sys-color-on-warning-container); }
.note.danger { background: var(--md-sys-color-error-container); color: var(--md-sys-color-on-error-container); }

/* 打印 */
@media print {
  .topbar, .side, .btn, .toasts { display: none !important; }
  .main { padding: 0; }
  .card { box-shadow: none; break-inside: avoid; }
}

/* --------------------------------------------------------------------------
   深色模式
   已完全由 md3-tokens.css 的语义令牌驱动（body.dark 重定义 --md-sys-color-*）。
   组件层因此不再需要任何夜间配色覆盖 —— 少维护约 60 行硬编码色值，
   新增组件只要引用语义令牌就自动获得深浅两套配色。
   -------------------------------------------------------------------------- */

/* ---------- 响应式 ---------- */
@media (max-width: 1100px) {
  .grid.c5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid.c4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  :root { --side-w: 0px; }
  .side {
    position: fixed; left: 0; top: var(--header-h); bottom: 0; width: 232px; z-index: 80;
    transform: translateX(-100%); transition: transform .22s ease; box-shadow: var(--shadow-lg);
    height: auto;
  }
  .side.open { transform: none; }
  .main { padding: 15px 14px 80px; }
  .grid.c2, .grid.c3 { grid-template-columns: 1fr; }
  .grid.c4, .grid.c5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topnav { display: none; }
}

@media (max-width: 560px) {
  .grid.c4, .grid.c5 { grid-template-columns: 1fr; }
  .stat .value { font-size: 22px; }
  .brand small { display: none; }
  .qstem { font-size: 15px; }
  .modal { max-height: 92vh; }
  .modal-foot { flex-direction: column-reverse; }
  .modal-foot .btn { width: 100%; }
  .toasts { left: 12px; right: 12px; top: 66px; }
  .toast { max-width: none; }
}

/* 移动端底部导航 */
.tabbar { display: none; }
@media (max-width: 900px) {
  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; height: 60px;
    background: var(--md-sys-color-surface-container);
    border-top: 1px solid var(--md-sys-color-outline-variant);
    z-index: 70; box-shadow: var(--md-sys-elevation-2);
  }
  .tabbar a {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; font-size: var(--md-sys-typescale-label-small);
    color: var(--md-sys-color-on-surface-variant); text-decoration: none;
    transition: color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
  }
  .tabbar a.active { color: var(--md-sys-color-primary); font-weight: 600; }
  .tabbar a .ico { width: 20px; height: 20px; }
}

.ico { width: 16px; height: 16px; display: inline-block; vertical-align: -2px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
