:root {
  --brand: #1677ff;
  --brand-dark: #0958d9;
  --brand-soft: #eef5ff;
  --bg: #f2f4f8;
  --card: #ffffff;
  --text: #18223a;
  --muted: #6b7688;
  --line: #e3e8f0;
  --ok: #0f9d58;
  --ok-soft: #e8f6ee;
  --bad: #d93025;
  --bad-soft: #fdecea;
  --warn: #b45309;
  --shadow: 0 2px 12px rgba(24, 34, 58, 0.06);
  --radius: 14px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

button, input { font-family: inherit; }
button { cursor: pointer; }

.app {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 16px 16px calc(28px + env(safe-area-inset-bottom));
}

.screen { animation: none; }
[hidden] { display: none !important; }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ---------------- 开始页 ---------------- */
.intro-top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 2px 4px;
}
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--brand), #4f93ef);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.5px;
  display: grid;
  place-items: center;
  box-shadow: 0 4px 12px rgba(22, 119, 255, 0.28);
}
.brand-text { color: var(--muted); font-size: 14px; font-weight: 600; }

.intro-title {
  margin: 18px 0 6px;
  font-size: 27px;
  line-height: 1.35;
  letter-spacing: 0.2px;
}
.intro-subtitle {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 14px;
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.chip {
  padding: 5px 12px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--line);
  color: #3c4a63;
  font-size: 13px;
  font-weight: 600;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 14px;
}
.card-title {
  margin: 0 0 10px;
  font-size: 16px;
  font-weight: 700;
}

.intro-list {
  margin: 0;
  padding: 0;
  list-style: none;
  color: #3c4a63;
  font-size: 14.5px;
}
.intro-list li {
  position: relative;
  padding-left: 18px;
  margin: 9px 0;
  line-height: 1.65;
}
.dot {
  position: absolute;
  left: 3px;
  top: 9px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--brand);
}

.form-card { padding: 18px 18px 20px; }
.field { display: block; margin-bottom: 14px; }
.field-label {
  display: block;
  margin-bottom: 7px;
  font-size: 14px;
  font-weight: 600;
  color: #3c4a63;
}
.field-label em { color: var(--bad); font-style: normal; }
.field input {
  width: 100%;
  height: 50px;
  padding: 0 14px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: #fafbfd;
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.field input::placeholder { color: #a3adbd; }
.field input:focus {
  border-color: var(--brand);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(22, 119, 255, 0.12);
}
.form-error {
  margin: -4px 0 12px;
  color: var(--bad);
  font-size: 13.5px;
}
.field-hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.6;
}

.roster-list {
  margin-top: 8px;
  max-height: 280px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 4px 16px rgba(24, 34, 58, 0.06);
}
.roster-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 12px;
  border: 0;
  border-bottom: 1px solid #f1f4f9;
  background: #fff;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
}
.roster-item:last-child { border-bottom: 0; }
.roster-item:hover { background: #f7faff; }
.roster-item:active { background: #f0f6ff; }
.ri-name { font-size: 15px; font-weight: 700; }
.ri-meta {
  margin-left: auto;
  color: var(--muted);
  font-size: 12.5px;
  white-space: nowrap;
}
.roster-empty {
  padding: 14px 12px;
  color: var(--muted);
  font-size: 13.5px;
  text-align: center;
}
.roster-picked {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-size: 14px;
  font-weight: 600;
}
.roster-picked button {
  margin-left: auto;
  border: 0;
  background: transparent;
  color: var(--brand);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}
.intro-foot {
  text-align: center;
  color: #93a0b4;
  font-size: 12.5px;
  margin: 18px 0 0;
}

.gate-banner {
  margin: 0 0 14px;
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.5;
}
.gate-banner.live {
  background: #e8f6ee;
  color: #0b7a43;
  border: 1px solid #c6ead6;
}
.gate-banner.ended {
  background: #f1f4f9;
  color: #546176;
  border: 1px solid var(--line);
}

/* ---------------- 等待开考 ---------------- */
.wait-wrap {
  max-width: 480px;
  margin: 12vh auto 0;
  padding: 34px 24px 30px;
  background: var(--card);
  border-radius: 20px;
  box-shadow: var(--shadow);
  text-align: center;
}
.wait-wrap h1 { margin: 18px 0 8px; font-size: 23px; }
.wait-text { margin: 0; color: #3c4a63; font-size: 15px; line-height: 1.7; }
.wait-meta { margin: 14px 0 0; color: var(--muted); font-size: 13px; min-height: 20px; }
.wait-wrap .btn { margin-top: 20px; min-width: 140px; }
.wait-pulse {
  width: 62px;
  height: 62px;
  margin: 0 auto;
  border-radius: 50%;
  background: var(--brand-soft);
  display: grid;
  place-items: center;
}
.wait-pulse span {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid #bcd6fb;
  border-top-color: var(--brand);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- 成绩上传状态 ---------------- */
.upload-state {
  margin: 0 0 14px;
  padding: 11px 14px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.6;
  background: #f7f9fc;
  color: #546176;
  border: 1px solid var(--line);
}
.upload-state.ok { background: #e8f6ee; color: #0b7a43; border-color: #c6ead6; }
.upload-state.fail { background: #fdecea; color: #a5221a; border-color: #f6c9c5; }
.upload-state button {
  margin-left: 8px;
  border: 1px solid currentColor;
  background: transparent;
  color: inherit;
  border-radius: 8px;
  padding: 3px 10px;
  font-size: 12.5px;
  font-weight: 700;
}

/* ---------------- 按钮 ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 18px;
  border: 1.5px solid transparent;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  line-height: 1;
  transition: background 0.15s, border-color 0.15s, color 0.15s, filter 0.12s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { filter: brightness(0.95); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-secondary { background: var(--brand-soft); color: var(--brand-dark); }
.btn-ghost { background: #fff; border-color: var(--line); color: #3c4a63; }
.link-btn {
  border: 0;
  background: transparent;
  color: #eaf3ff;
  font-size: 14px;
  font-weight: 600;
  padding: 6px 2px;
}
.icon-btn {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: #f1f4f9;
  color: #546176;
  font-size: 16px;
  display: grid;
  place-items: center;
}

/* ---------------- 答题页 ---------------- */
.app.exam-mode { padding-bottom: 110px; }

.exam-header {
  position: sticky;
  top: 6px;
  z-index: 20;
  margin: 0 0 14px;
  padding: 10px 14px 8px;
  background: linear-gradient(135deg, #1677ff 0%, #4f93ef 100%);
  color: #fff;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 8px 20px rgba(22, 119, 255, 0.22);
}
.progress-track {
  height: 4px;
  margin: 0 -14px 8px;
  background: rgba(255, 255, 255, 0.24);
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #d6e9ff, #ffffff);
  border-radius: 0 4px 4px 0;
  transition: width 0.25s ease;
}
.exam-header-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.exam-counter { font-size: 14px; color: rgba(255, 255, 255, 0.82); white-space: nowrap; }
.exam-counter b { color: #fff; font-size: 16px; }
.exam-timer {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 16px;
  color: #fff;
  background: rgba(255, 255, 255, 0.2);
  padding: 5px 10px;
  border-radius: 999px;
}
.exam-timer.urgent { color: #fff; background: rgba(200, 30, 20, 0.55); animation: pulse 1s infinite; }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}
.timer-icon { font-size: 15px; }

.question-area { min-height: 60vh; }

.q-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 16px;
}
.q-tags {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}
.q-section-tag {
  padding: 3px 9px;
  border-radius: 6px;
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-size: 12.5px;
  font-weight: 700;
}
.q-meta { color: var(--muted); font-size: 12.5px; }
.q-type {
  padding: 3px 8px;
  border-radius: 6px;
  background: #f1f4f9;
  color: #546176;
  font-size: 12px;
  font-weight: 600;
}
.q-stem {
  margin: 0 0 18px;
  font-size: 17px;
  font-weight: 600;
  line-height: 1.7;
  letter-spacing: 0.1px;
  word-break: break-word;
}
.q-stem .blank {
  display: inline-block;
  width: 2.2em;
  border-bottom: 1px solid #b9c3d3;
  margin-left: 4px;
  color: transparent;
}

.options { display: flex; flex-direction: column; gap: 10px; }
.opt {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  width: 100%;
  padding: 13px 14px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  text-align: left;
  font-size: 16px;
  line-height: 1.55;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.opt:hover { border-color: #b9cdf0; }
.opt:active { background: #f7faff; }
.opt.selected {
  border-color: var(--brand);
  background: #f2f7ff;
  box-shadow: 0 0 0 1px var(--brand) inset;
}
.opt-letter {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #f1f4f9;
  color: #546176;
  font-size: 14px;
  font-weight: 700;
  display: grid;
  place-items: center;
  margin-top: 1px;
}
.opt.selected .opt-letter { background: var(--brand); color: #fff; }
.opt-text { flex: 1; padding-top: 1px; word-break: break-word; }
.opt-box {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  margin-top: 4px;
  border: 1.5px solid #c6cfdd;
  border-radius: 50%;
  background: #fff;
}
.opt-box.multi { border-radius: 6px; }
.opt.selected .opt-box {
  border-color: var(--brand);
  background: var(--brand);
  box-shadow: inset 0 0 0 3px #fff;
}
.opt.selected .opt-box.multi { box-shadow: inset 0 0 0 3px #fff; }

.q-hint {
  margin: 16px 0 0;
  color: #93a0b4;
  font-size: 13px;
}
.q-hint.multi-hint { color: var(--warn); }

.exam-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  gap: 10px;
  max-width: 760px;
  margin: 0 auto;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.98);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
.exam-footer .btn { flex: 1; padding: 0 10px; }
.exam-footer #btn-prev { flex: 0 0 28%; }
.exam-footer #btn-next { flex: 1; }
.exam-footer #btn-submit { flex: 0 0 24%; }

/* ---------------- 弹窗 ---------------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(16, 24, 40, 0.52);
  animation: fade-in 0.15s ease;
}
.sheet {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 760px;
  max-height: 82vh;
  margin: 0 auto;
  align-self: flex-end;
  background: #fff;
  border-radius: 20px 20px 0 0;
  padding: 16px 18px calc(16px + env(safe-area-inset-bottom));
  overflow: auto;
  animation: sheet-up 0.22s ease;
}
@keyframes sheet-up {
  from { transform: translateY(30px); opacity: 0.6; }
  to { transform: none; opacity: 1; }
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sheet-head h2 { margin: 0; font-size: 18px; }
.sheet-tip { margin: 6px 0 14px; color: var(--muted); font-size: 13px; }
.sheet-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}
.sheet-section {
  grid-column: 1 / -1;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
}
.sheet-num {
  height: 46px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: #f7f9fc;
  color: #546176;
  font-size: 15px;
  font-weight: 600;
}
.sheet-num.done { background: var(--brand); border-color: var(--brand); color: #fff; }
.sheet-num.current { outline: 2px solid #9cc2fb; outline-offset: 2px; }
.sheet-foot {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
}
.sheet-foot .btn { margin-left: auto; min-width: 110px; }
.legend { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12.5px; }
.lg { width: 12px; height: 12px; border-radius: 4px; display: inline-block; }
.lg-done { background: var(--brand); }
.lg-undone { background: #eef1f6; border: 1px solid var(--line); }

.dialog {
  position: relative;
  z-index: 1;
  width: calc(100% - 48px);
  max-width: 370px;
  background: #fff;
  border-radius: 18px;
  padding: 22px 20px 18px;
  animation: fade-in 0.18s ease;
}
.dialog h2 { margin: 0 0 8px; font-size: 18px; }
.dialog p { margin: 0 0 20px; color: var(--muted); font-size: 14.5px; }
.dialog-actions { display: flex; gap: 10px; }
.dialog-actions .btn { flex: 1; min-height: 44px; }

/* ---------------- 成绩页 ---------------- */
.result-hero {
  position: relative;
  overflow: hidden;
  border-radius: 20px;
  padding: 26px 20px 22px;
  color: #fff;
  background: linear-gradient(135deg, #1677ff, #4f93ef 60%, #7db8ff);
  box-shadow: 0 12px 30px rgba(22, 119, 255, 0.26);
  text-align: center;
  margin-bottom: 14px;
}
.result-hero::after {
  content: "";
  position: absolute;
  width: 220px;
  height: 220px;
  right: -90px;
  top: -120px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
}
.result-kicker { font-size: 13px; opacity: 0.9; letter-spacing: 1px; }
.result-score {
  font-size: 62px;
  font-weight: 800;
  line-height: 1.1;
  margin: 6px 0 0;
  font-variant-numeric: tabular-nums;
}
.result-score small { font-size: 20px; font-weight: 600; opacity: 0.85; }
.result-badge {
  display: inline-block;
  margin-top: 10px;
  padding: 5px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.35);
  font-size: 13.5px;
  font-weight: 600;
}
.result-hero.fail { background: linear-gradient(135deg, #8a4b0f, #c47a2c 60%, #d99a52); box-shadow: 0 12px 30px rgba(138, 75, 15, 0.24); }
.result-name { margin-top: 8px; font-size: 14px; opacity: 0.92; }

.result-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 14px;
}
.result-card h2 { margin: 0 0 14px; font-size: 16px; }
.result-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.result-meta div { background: #f7f9fc; border-radius: 10px; padding: 10px 12px; }
.result-meta span { display: block; color: var(--muted); font-size: 12px; }
.result-meta b { display: block; margin-top: 2px; font-size: 15px; }

.score-rows { display: flex; flex-direction: column; gap: 12px; }
.score-row { display: flex; align-items: center; gap: 12px; }
.score-row .sr-name { width: 70px; font-size: 14px; color: #3c4a63; white-space: nowrap; }
.score-row .sr-track {
  flex: 1;
  height: 9px;
  border-radius: 999px;
  background: #eef1f6;
  overflow: hidden;
}
.score-row .sr-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--brand), #6aa6f5);
}
.score-row .sr-num { width: 74px; text-align: right; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.score-row .sr-num b { color: var(--text); font-size: 14px; }

.result-actions { display: flex; gap: 10px; margin-bottom: 16px; }
.result-actions .btn { flex: 1; }

.review-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.review-toolbar h2 { margin: 0; font-size: 16px; }
.filter-btn {
  margin-left: auto;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  color: #546176;
  font-weight: 600;
}
.filter-btn.active { background: var(--brand-soft); border-color: #bcd6fb; color: var(--brand-dark); }

.review-item {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 14px 12px;
  margin-bottom: 10px;
  background: #fff;
}
.review-item.ok { border-left: 4px solid var(--ok); }
.review-item.bad { border-left: 4px solid var(--bad); }
.rv-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.rv-status {
  font-size: 12px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}
.review-item.ok .rv-status { color: #0b7a43; background: var(--ok-soft); }
.review-item.bad .rv-status { color: #a5221a; background: var(--bad-soft); }
.rv-no { font-size: 12.5px; color: var(--muted); }
.rv-points { margin-left: auto; font-size: 12.5px; color: var(--muted); }
.rv-stem { font-size: 15px; font-weight: 600; line-height: 1.65; margin: 0 0 10px; }
.rv-opts { display: flex; flex-direction: column; gap: 6px; }
.rv-opt {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.5;
  color: #3c4a63;
  background: #f8fafc;
}
.rv-opt .rvo-letter { font-weight: 700; color: #546176; }
.rv-opt.correct { background: var(--ok-soft); }
.rv-opt.correct .rvo-letter { color: #0b7a43; }
.rv-opt.wrong { background: var(--bad-soft); }
.rv-opt.wrong .rvo-letter { color: #a5221a; }
.rv-opt .rvo-mark { margin-left: auto; font-size: 12px; font-weight: 700; white-space: nowrap; }
.rv-opt.correct .rvo-mark { color: #0b7a43; }
.rv-opt.wrong .rvo-mark { color: #a5221a; }
.rv-answer { margin: 10px 0 0; font-size: 13px; color: var(--muted); }
.rv-answer b { color: var(--text); }
.empty-review { text-align: center; color: var(--muted); padding: 18px 0; font-size: 14px; }

/* ---------------- Toast ---------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 80;
  background: rgba(24, 34, 58, 0.92);
  color: #fff;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(24, 34, 58, 0.24);
  animation: fade-in 0.18s ease;
  max-width: 80vw;
  text-align: center;
}

@media (min-width: 640px) {
  .app { padding: 24px 24px 36px; }
  .exam-header { margin: -24px -24px 16px; padding: 14px 24px 10px; }
  .progress-track { margin: 0 -24px 12px; }
  .intro-title { font-size: 32px; }
  .exam-footer { padding-left: 24px; padding-right: 24px; }
  .sheet-grid { grid-template-columns: repeat(8, 1fr); }
  .result-meta { grid-template-columns: repeat(4, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
