/* ============================================================
   Apple Design System · 考研刷题
   ============================================================ */

:root {
  /* 浅色主题 */
  --bg: #F5F5F7;
  --bg-elevated: #FFFFFF;
  --bg-grouped: #FFFFFF;
  --bg-secondary: #F2F2F7;
  --separator: rgba(60, 60, 67, 0.12);
  --separator-opaque: #C6C6C8;
  --label: #000000;
  --label-secondary: rgba(60, 60, 67, 0.60);
  --label-tertiary: rgba(60, 60, 67, 0.30);
  --fill: rgba(120, 120, 128, 0.20);
  --fill-secondary: rgba(120, 120, 128, 0.16);
  --fill-tertiary: rgba(118, 118, 128, 0.12);
  --tint: #007AFF;
  --tint-hover: #0051D5;
  --green: #34C759;
  --red: #FF3B30;
  --orange: #FF9500;
  --yellow: #FFCC00;
  --purple: #AF52DE;
  --pink: #FF2D55;
  --teal: #5AC8FA;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 2px 8px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.08), 0 2px 8px rgba(0,0,0,0.04);
  --shadow-xl: 0 20px 40px rgba(0,0,0,0.12), 0 8px 16px rgba(0,0,0,0.08);

  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 18px;
  --radius-xl: 24px;

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
          "PingFang SC", "HarmonyOS Sans SC", "MiSans", "Microsoft YaHei",
          "Source Han Sans CN", sans-serif;
  --font-mono: "SF Mono", Menlo, Monaco, Consolas, monospace;

  --topbar-h: 52px;
  --tabbar-h: 56px;
}

[data-theme="dark"] {
  --bg: #000000;
  --bg-elevated: #1C1C1E;
  --bg-grouped: #1C1C1E;
  --bg-secondary: #2C2C2E;
  --separator: rgba(84, 84, 88, 0.36);
  --separator-opaque: #38383A;
  --label: #FFFFFF;
  --label-secondary: rgba(235, 235, 245, 0.60);
  --label-tertiary: rgba(235, 235, 245, 0.30);
  --fill: rgba(120, 120, 128, 0.36);
  --fill-secondary: rgba(120, 120, 128, 0.32);
  --fill-tertiary: rgba(118, 118, 128, 0.24);
  --tint: #0A84FF;
  --tint-hover: #409CFF;
  --green: #30D158;
  --red: #FF453A;
  --orange: #FF9F0A;
  --yellow: #FFD60A;
  --purple: #BF5AF2;
  --pink: #FF375F;
  --teal: #64D2FF;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
  --shadow: 0 2px 8px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.5);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.5), 0 2px 8px rgba(0,0,0,0.4);
  --shadow-xl: 0 20px 40px rgba(0,0,0,0.6), 0 8px 16px rgba(0,0,0,0.5);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.47;
  letter-spacing: -0.022em;
  color: var(--label);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.25s ease, color 0.25s ease;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* ============ 顶栏 ============ */
.topbar {
  flex-shrink: 0;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--separator);
  padding-top: env(safe-area-inset-top);
  z-index: 100;
}
.topbar-inner {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 8px;
  max-width: 1200px;
  margin: 0 auto;
}
.topbar-title {
  flex: 1;
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  letter-spacing: -0.022em;
}
.topbar-actions { display: flex; gap: 4px; }

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--tint);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, transform 0.15s;
}
.icon-btn:hover { background: var(--fill-tertiary); }
.icon-btn:active { transform: scale(0.92); }

[data-theme="light"] .icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }

/* ============ 主视图 ============ */
.view {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 16px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  scroll-behavior: smooth;
}
.view.no-tabbar { padding-bottom: 24px; }

/* 页面切换动画 */
.view-fade-enter { animation: viewFadeIn 0.28s cubic-bezier(0.32, 0.72, 0, 1); }
@keyframes viewFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============ 底部 Tab Bar ============ */
.tabbar {
  flex-shrink: 0;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--bg-elevated) 85%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--separator);
  display: flex;
  z-index: 100;
}
.tab-item {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--label-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-family: inherit;
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s;
  padding: 6px 0;
}
.tab-item.active { color: var(--tint); }
.tab-item svg { transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1); }
.tab-item.active svg { transform: scale(1.05); }

/* ============ 大标题（首页） ============ */
.large-title {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.028em;
  line-height: 1.15;
  margin: 12px 4px 20px;
}
.large-subtitle {
  font-size: 15px;
  color: var(--label-secondary);
  margin: -16px 4px 24px;
}

/* ============ 卡片 ============ */
.card {
  background: var(--bg-grouped);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  transition: transform 0.15s, box-shadow 0.15s;
}
.card-tappable { cursor: pointer; }
.card-tappable:hover { transform: translateY(-1px); box-shadow: var(--shadow-lg); }
.card-tappable:active { transform: scale(0.985); }

.card-title {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 4px;
  letter-spacing: -0.022em;
}
.card-subtitle {
  font-size: 13px;
  color: var(--label-secondary);
  line-height: 1.4;
}

/* 科目卡片 */
.subject-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.subject-card {
  position: relative;
  padding: 20px;
  border-radius: var(--radius-lg);
  background: var(--bg-grouped);
  box-shadow: var(--shadow);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s cubic-bezier(0.32, 0.72, 0, 1), box-shadow 0.2s;
  min-height: 140px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.subject-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.subject-card:active { transform: scale(0.98); }
.subject-card::before {
  content: '';
  position: absolute;
  top: -40px; right: -40px;
  width: 140px; height: 140px;
  border-radius: 50%;
  background: var(--subject-color, var(--tint));
  opacity: 0.12;
  transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
}
.subject-card:hover::before { transform: scale(1.15); }
.subject-icon {
  width: 44px; height: 44px;
  border-radius: 12px;
  background: var(--subject-color, var(--tint));
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 12px;
  box-shadow: 0 4px 12px color-mix(in srgb, var(--subject-color, var(--tint)) 30%, transparent);
  position: relative;
  z-index: 1;
}
.subject-name {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.022em;
  position: relative;
  z-index: 1;
}
.subject-meta {
  font-size: 13px;
  color: var(--label-secondary);
  margin-top: 4px;
  position: relative;
  z-index: 1;
}

/* ============ 分组列表 ============ */
.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--label-secondary);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  padding: 20px 16px 8px;
}
.list-group {
  background: var(--bg-grouped);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 0.5px solid var(--separator);
  cursor: pointer;
  transition: background 0.15s;
  min-height: 48px;
}
.list-item:last-child { border-bottom: none; }
.list-item:hover { background: var(--fill-tertiary); }
.list-item:active { background: var(--fill-secondary); }
.list-item-icon {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: var(--tint);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 14px;
}
.list-item-body { flex: 1; min-width: 0; }
.list-item-title { font-size: 16px; font-weight: 400; }
.list-item-desc { font-size: 13px; color: var(--label-secondary); margin-top: 2px; }
.list-item-trailing {
  color: var(--label-tertiary);
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.chevron::after {
  content: '';
  width: 8px; height: 8px;
  border-right: 2px solid var(--label-tertiary);
  border-top: 2px solid var(--label-tertiary);
  transform: rotate(45deg);
  display: inline-block;
}

/* ============ 按钮 ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: none;
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s, opacity 0.15s;
  background: var(--tint);
  color: white;
  letter-spacing: -0.01em;
  min-height: 40px;
}
.btn:hover { background: var(--tint-hover); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-secondary { background: var(--fill-secondary); color: var(--tint); }
.btn-secondary:hover { background: var(--fill); }
.btn-danger { background: var(--red); }
.btn-success { background: var(--green); }
.btn-ghost { background: transparent; color: var(--tint); }
.btn-ghost:hover { background: var(--fill-tertiary); }
.btn-lg { padding: 14px 24px; font-size: 17px; min-height: 50px; border-radius: var(--radius); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; min-height: 32px; }

/* ============ 徽章 ============ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  background: var(--fill-secondary);
  color: var(--label);
  letter-spacing: 0;
}
.badge-blue { background: rgba(0, 122, 255, 0.15); color: var(--tint); }
.badge-green { background: rgba(52, 199, 89, 0.15); color: var(--green); }
.badge-red { background: rgba(255, 59, 48, 0.15); color: var(--red); }
.badge-orange { background: rgba(255, 149, 0, 0.15); color: var(--orange); }
.badge-purple { background: rgba(175, 82, 222, 0.15); color: var(--purple); }

/* ============ 表单 ============ */
.input, .select, .textarea {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--separator);
  background: var(--bg-grouped);
  color: var(--label);
  font-family: inherit;
  font-size: 16px;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--tint);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--tint) 15%, transparent);
}
.textarea { resize: vertical; min-height: 80px; line-height: 1.5; }
.label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--label-secondary);
  margin-bottom: 6px;
}
.field { margin-bottom: 16px; }

/* 开关 */
.switch { position: relative; display: inline-block; width: 51px; height: 31px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--fill-secondary);
  border-radius: 31px;
  transition: 0.25s cubic-bezier(0.32, 0.72, 0, 1);
}
.switch-slider::before {
  position: absolute; content: "";
  height: 27px; width: 27px;
  left: 2px; top: 2px;
  background: white;
  border-radius: 50%;
  transition: 0.25s cubic-bezier(0.32, 0.72, 0, 1);
  box-shadow: 0 3px 8px rgba(0,0,0,0.15), 0 1px 1px rgba(0,0,0,0.16);
}
.switch input:checked + .switch-slider { background: var(--green); }
.switch input:checked + .switch-slider::before { transform: translateX(20px); }

/* ============ 首页统计 ============ */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}
.stat-card {
  background: var(--bg-grouped);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}
.stat-value {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.028em;
  color: var(--tint);
  line-height: 1.1;
}
.stat-label { font-size: 12px; color: var(--label-secondary); margin-top: 4px; }

/* ============ 考试界面 ============ */
.exam-header {
  position: sticky;
  top: 0;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding: 12px 4px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 0.5px solid var(--separator);
  margin-bottom: 16px;
}
.timer {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 600;
  color: var(--tint);
  letter-spacing: -0.02em;
  flex: 1;
  text-align: center;
}
.timer.warning { color: var(--orange); }
.timer.danger { color: var(--red); animation: pulse 1s infinite; }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.question-nav {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(38px, 1fr));
  gap: 6px;
  padding: 12px;
  background: var(--bg-grouped);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}
.qnav-btn {
  aspect-ratio: 1;
  border-radius: 8px;
  border: 1px solid var(--separator);
  background: var(--bg-elevated);
  color: var(--label);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.qnav-btn:hover { border-color: var(--tint); }
.qnav-btn.answered { background: var(--tint); color: white; border-color: var(--tint); }
.qnav-btn.current { box-shadow: 0 0 0 2px var(--tint); }
.qnav-btn.flagged::after {
  content: '';
  position: absolute;
  top: 3px; right: 3px;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--orange);
}
.qnav-btn.correct { background: var(--green); color: white; border-color: var(--green); }
.qnav-btn.wrong { background: var(--red); color: white; border-color: var(--red); }
.qnav-btn.blank { background: var(--fill-secondary); color: var(--label-tertiary); }

.question-card {
  background: var(--bg-grouped);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.question-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.question-stem {
  font-size: 17px;
  line-height: 1.7;
  margin-bottom: 16px;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.question-options { display: flex; flex-direction: column; gap: 8px; }
.option-item {
  display: flex;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1.5px solid var(--separator);
  background: var(--bg-elevated);
  cursor: pointer;
  transition: all 0.15s;
  align-items: flex-start;
}
.option-item:hover { border-color: var(--tint); background: color-mix(in srgb, var(--tint) 5%, var(--bg-elevated)); }
.option-item.selected {
  border-color: var(--tint);
  background: color-mix(in srgb, var(--tint) 10%, var(--bg-elevated));
}
.option-item.correct {
  border-color: var(--green);
  background: color-mix(in srgb, var(--green) 12%, var(--bg-elevated));
}
.option-item.wrong {
  border-color: var(--red);
  background: color-mix(in srgb, var(--red) 12%, var(--bg-elevated));
}
.option-letter {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--fill-secondary);
  color: var(--label);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
  transition: all 0.15s;
}
.option-item.selected .option-letter { background: var(--tint); color: white; }
.option-item.correct .option-letter { background: var(--green); color: white; }
.option-item.wrong .option-letter { background: var(--red); color: white; }
.option-content { flex: 1; line-height: 1.5; padding-top: 2px; }

/* 主观题输入 */
.subjective-input {
  width: 100%;
  min-height: 180px;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1.5px solid var(--separator);
  background: var(--bg-elevated);
  color: var(--label);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.6;
  resize: vertical;
  outline: none;
  transition: border-color 0.15s;
}
.subjective-input:focus { border-color: var(--tint); }

/* 解析块 */
.explanation {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--tint) 8%, var(--bg-elevated));
  border-left: 3px solid var(--tint);
  line-height: 1.65;
  font-size: 15px;
}
.explanation-title {
  font-weight: 600;
  color: var(--tint);
  margin-bottom: 6px;
  font-size: 14px;
}
.answer-block {
  margin-top: 12px;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--green) 8%, var(--bg-elevated));
  border-left: 3px solid var(--green);
}
.answer-block.wrong-bg {
  background: color-mix(in srgb, var(--red) 8%, var(--bg-elevated));
  border-left-color: var(--red);
}
.scoring-points {
  margin-top: 10px;
  padding: 12px 14px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
}
.scoring-points-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--label-secondary);
  margin-bottom: 8px;
}
.scoring-points ul { list-style: none; }
.scoring-points li {
  padding: 4px 0;
  font-size: 14px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.scoring-points li::before {
  content: '•';
  color: var(--tint);
  font-weight: bold;
}

/* 自评滑条 */
.self-score {
  margin-top: 16px;
  padding: 16px;
  background: var(--bg-secondary);
  border-radius: var(--radius);
}
.self-score-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.self-score-label { font-size: 14px; font-weight: 600; }
.self-score-value { font-size: 22px; font-weight: 700; color: var(--tint); font-variant-numeric: tabular-nums; }
input[type="range"] {
  width: 100%;
  height: 4px;
  background: var(--fill-secondary);
  border-radius: 2px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px; height: 24px;
  background: white;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2), 0 0 0 0.5px rgba(0,0,0,0.04);
  transition: transform 0.1s;
}
input[type="range"]::-webkit-slider-thumb:active { transform: scale(1.15); }
input[type="range"]::-moz-range-thumb {
  width: 24px; height: 24px;
  background: white;
  border-radius: 50%;
  cursor: pointer;
  border: none;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

/* 底部动作栏（考试页） */
.action-bar {
  position: sticky;
  bottom: 0;
  padding: 12px 0;
  background: linear-gradient(to top, var(--bg) 60%, transparent);
  display: flex;
  gap: 8px;
  margin-top: 16px;
  z-index: 5;
}
.action-bar .btn { flex: 1; }

/* ============ 分数结果页 ============ */
.score-hero {
  text-align: center;
  padding: 40px 20px 30px;
  background: var(--bg-grouped);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  position: relative;
  overflow: hidden;
}
.score-hero::before {
  content: '';
  position: absolute;
  top: -60px; left: 50%;
  transform: translateX(-50%);
  width: 200px; height: 200px;
  border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--score-color, var(--tint)) 20%, transparent), transparent 70%);
  z-index: 0;
}
.score-value {
  font-size: 76px;
  font-weight: 700;
  letter-spacing: -0.04em;
  color: var(--score-color, var(--tint));
  line-height: 1;
  position: relative;
  z-index: 1;
  font-variant-numeric: tabular-nums;
}
.score-total {
  font-size: 20px;
  color: var(--label-secondary);
  margin-top: 4px;
  position: relative;
  z-index: 1;
}
.score-label {
  font-size: 15px;
  color: var(--label-secondary);
  margin-top: 16px;
  position: relative;
  z-index: 1;
}
.score-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 24px;
  padding-top: 24px;
  border-top: 0.5px solid var(--separator);
  position: relative;
  z-index: 1;
}
.score-stat { text-align: center; }
.score-stat-value { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; }
.score-stat-label { font-size: 12px; color: var(--label-secondary); margin-top: 2px; }

/* ============ Toast ============ */
#toast-container {
  position: fixed;
  top: calc(var(--topbar-h) + env(safe-area-inset-top) + 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}
.toast {
  background: rgba(0, 0, 0, 0.85);
  color: white;
  padding: 10px 18px;
  border-radius: 22px;
  font-size: 14px;
  font-weight: 500;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  max-width: 80vw;
  text-align: center;
}
[data-theme="dark"] .toast { background: rgba(60, 60, 67, 0.9); }
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }
.toast.hide { animation: toastOut 0.25s forwards; }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(-20px) scale(0.9); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toastOut {
  to { opacity: 0; transform: translateY(-10px) scale(0.95); }
}

/* ============ 模态框 ============ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  max-width: 480px;
  width: 100%;
  max-height: 85vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-xl);
  animation: modalIn 0.28s cubic-bezier(0.32, 0.72, 0, 1);
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.92) translateY(20px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-header {
  padding: 16px 20px;
  border-bottom: 0.5px solid var(--separator);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-title { font-size: 17px; font-weight: 600; }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 12px 20px;
  border-top: 0.5px solid var(--separator);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* Action Sheet（移动端底部弹出） */
@media (max-width: 640px) {
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal {
    max-width: 100%;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    max-height: 90vh;
    animation: sheetIn 0.32s cubic-bezier(0.32, 0.72, 0, 1);
    padding-bottom: env(safe-area-inset-bottom);
  }
  @keyframes sheetIn {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }
}

/* ============ 空状态 ============ */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--label-secondary);
}
.empty-state-icon {
  width: 64px; height: 64px;
  margin: 0 auto 16px;
  border-radius: 20px;
  background: var(--fill-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--label-tertiary);
}
.empty-state-title { font-size: 17px; font-weight: 600; color: var(--label); margin-bottom: 4px; }
.empty-state-desc { font-size: 14px; line-height: 1.5; }

/* ============ 分段控件 ============ */
.segmented {
  display: inline-flex;
  background: var(--fill-secondary);
  border-radius: 9px;
  padding: 2px;
  gap: 2px;
}
.segmented-item {
  padding: 6px 14px;
  border-radius: 7px;
  border: none;
  background: transparent;
  color: var(--label);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.32, 0.72, 0, 1);
}
.segmented-item.active {
  background: var(--bg-elevated);
  box-shadow: 0 3px 8px rgba(0,0,0,0.12), 0 3px 1px rgba(0,0,0,0.04);
}
[data-theme="dark"] .segmented-item.active { background: #636366; }

/* ============ 历史卡片 ============ */
.history-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--bg-grouped);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 8px;
  cursor: pointer;
  transition: transform 0.15s;
}
.history-card:hover { transform: translateX(2px); }
.history-score {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: color-mix(in srgb, var(--score-color, var(--tint)) 15%, transparent);
  color: var(--score-color, var(--tint));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.history-score-num { font-size: 20px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.history-score-total { font-size: 10px; opacity: 0.7; margin-top: 2px; }
.history-info { flex: 1; min-width: 0; }
.history-title { font-size: 15px; font-weight: 600; margin-bottom: 2px; }
.history-meta { font-size: 12px; color: var(--label-secondary); }

/* ============ 题目列表（题库） ============ */
.filter-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 0 12px;
  scrollbar-width: none;
}
.filter-bar::-webkit-scrollbar { display: none; }
.chip {
  padding: 6px 14px;
  border-radius: 16px;
  background: var(--bg-grouped);
  border: 1px solid var(--separator);
  font-size: 13px;
  font-weight: 500;
  color: var(--label);
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.chip.active {
  background: var(--tint);
  color: white;
  border-color: var(--tint);
}
.chip:hover:not(.active) { background: var(--fill-tertiary); }

.question-list-item {
  padding: 14px 16px;
  background: var(--bg-grouped);
  border-radius: var(--radius);
  margin-bottom: 8px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.question-list-item:hover { transform: translateX(2px); }
.q-num {
  width: 28px; height: 28px;
  border-radius: 8px;
  background: var(--fill-secondary);
  color: var(--label);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}
.q-content { flex: 1; min-width: 0; }
.q-stem-preview {
  font-size: 14px;
  line-height: 1.5;
  color: var(--label);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.q-meta {
  display: flex;
  gap: 8px;
  margin-top: 6px;
  align-items: center;
  flex-wrap: wrap;
}
.q-meta-item { font-size: 11px; color: var(--label-secondary); }

/* ============ KaTeX 适配 ============ */
.katex { font-size: 1.05em; }
.katex-display { margin: 12px 0; overflow-x: auto; overflow-y: hidden; }

/* ============ 响应式 ============ */
@media (min-width: 768px) {
  .view { padding: 20px 24px 40px; }
  .large-title { font-size: 40px; }
  .question-card { padding: 24px; }
  .question-stem { font-size: 17px; }
  #tabbar { display: none; }
  .topbar-inner { max-width: 900px; }
  .view { max-width: 900px; padding-bottom: 40px; }
  /* 桌面侧栏 */
  body { display: flex; }
  #app { flex: 1; }
}

@media (min-width: 1024px) {
  .subject-grid { grid-template-columns: repeat(3, 1fr); }
}

/* 桌面端侧边栏 */
.sidebar {
  display: none;
  width: 240px;
  flex-shrink: 0;
  background: var(--bg-secondary);
  border-right: 0.5px solid var(--separator);
  padding: 20px 12px;
  padding-top: calc(20px + env(safe-area-inset-top));
  flex-direction: column;
  gap: 4px;
}
@media (min-width: 768px) {
  .sidebar { display: flex; }
}
.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--label);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: background 0.15s;
}
.sidebar-item:hover { background: var(--fill-tertiary); }
.sidebar-item.active { background: var(--tint); color: white; }
.sidebar-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--label-secondary);
  padding: 16px 12px 8px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

/* ============ 加载动画 ============ */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--fill-secondary);
  border-top-color: var(--tint);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-full {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 10000;
}
.loading-full .spinner { width: 32px; height: 32px; border-width: 3px; }
.loading-text { font-size: 14px; color: var(--label-secondary); }

/* 打印样式 */
@media print {
  .topbar, .tabbar, .action-bar, .sidebar { display: none !important; }
  .view { overflow: visible; padding: 0; }
  body { overflow: visible; }
}
