/* ========== 设计变量 ========== */
:root {
  --blue: #2f6bff;
  --blue-soft: #eaf1ff;
  --ink: #1f2430;
  --ink-2: #4a5162;
  --ink-3: #9aa1b1;
  --line: #eceef3;
  --paper: #f7f8fa;
  --card: #ffffff;
  --green: #1faa6e;
  --green-soft: #e7f7f0;
  --red: #e5484d;
  --red-soft: #fdecec;
  --radius: 14px;
  --shadow-sheet: 0 -8px 30px rgba(20, 26, 40, 0.12);
}

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

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: #e9ebf0;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.6;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  background: var(--paper);
  position: relative;
  box-shadow: 0 0 40px rgba(20, 26, 40, 0.08);
  display: flex;
  flex-direction: column;
}

button { font-family: inherit; border: none; background: none; cursor: pointer; }
input { font-family: inherit; }

/* ========== 通用动画 ========== */
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheetup {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

.screen { animation: rise .35s cubic-bezier(.22,.8,.36,1) both; flex: 1; display: flex; flex-direction: column; }

/* ========== 登录页 ========== */
.login-hero {
  padding: 72px 28px 36px;
}
.login-title {
  font-size: 30px; font-weight: 700; letter-spacing: 1px;
  margin-top: 16px; line-height: 1.35;
}
.login-sub { color: var(--ink-3); font-size: 14px; margin-top: 8px; }

.login-card {
  margin: 8px 20px 0;
  background: var(--card);
  border-radius: 18px;
  padding: 26px 22px 28px;
  box-shadow: 0 6px 24px rgba(20, 26, 40, 0.06);
  animation: rise .45s .08s cubic-bezier(.22,.8,.36,1) both;
}
.field { margin-bottom: 18px; }
.field label {
  display: block; font-size: 13px; color: var(--ink-2);
  margin-bottom: 8px; font-weight: 600;
}
.field input {
  width: 100%; height: 50px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 0 14px;
  font-size: 16px; color: var(--ink);
  background: #fbfbfc;
  outline: none;
  transition: border-color .2s, background .2s, box-shadow .2s;
}
.field input:focus {
  border-color: var(--blue);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(47, 107, 255, 0.10);
}
.field .hint { font-size: 12px; color: var(--ink-3); margin-top: 6px; }

.login-error {
  display: none;
  color: var(--red); font-size: 13px;
  margin: -6px 0 12px;
}
.login-error.show { display: block; animation: shake .4s; }

.btn-primary {
  width: 100%; height: 52px;
  border-radius: 14px;
  background: linear-gradient(135deg, #4a86ff, var(--blue));
  color: #fff; font-size: 17px; font-weight: 600; letter-spacing: 4px;
  box-shadow: 0 8px 18px rgba(47, 107, 255, 0.28);
  transition: transform .12s, box-shadow .2s, opacity .2s;
}
.btn-primary:active { transform: scale(.97); box-shadow: 0 4px 10px rgba(47,107,255,.22); }
.btn-primary:disabled { opacity: .45; box-shadow: none; }

.login-tip {
  text-align: center; color: var(--ink-3); font-size: 12px;
  margin-top: 22px;
}
.login-tip code {
  background: var(--blue-soft); color: var(--blue);
  padding: 2px 8px; border-radius: 6px; font-family: inherit;
}

/* ========== 作答页：顶栏 ========== */
.topbar {
  position: sticky; top: 0; z-index: 20;
  height: 52px;
  display: flex; align-items: center;
  padding: 0 10px;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar .icon-btn {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  color: var(--ink); border-radius: 10px;
}
.topbar .icon-btn:active { background: var(--line); }
.topbar .spacer { flex: 1; }

.timer-pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: #f0f2f6; border-radius: 999px;
  padding: 5px 12px;
  font-size: 14px; font-weight: 600; color: var(--ink-2);
}
.timer-pill.paused { color: var(--red); background: var(--red-soft); }

.card-btn {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 14px; color: var(--ink-2); font-weight: 600;
  padding: 8px 6px; border-radius: 10px;
}
.card-btn:active { background: var(--line); }
.card-btn .progress { font-size: 15px; color: var(--ink); }

/* ========== 作答页：题目区 ========== */
.quiz-body {
  flex: 1; overflow-y: auto;
  padding: 18px 18px 12px;
  background: var(--card);
}
.q-meta {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 10px;
}
.q-type {
  font-size: 12px; font-weight: 600;
  color: var(--blue); background: var(--blue-soft);
  border-radius: 6px; padding: 3px 9px;
}
.q-subject { font-size: 12px; color: var(--ink-3); }

/* 材料：纯文本，不加样式 */
.material-plain {
  margin-bottom: 16px;
  font-size: 16px; line-height: 1.8; color: var(--ink);
  white-space: pre-wrap;
  word-break: break-word;
}

.q-stem {
  font-size: 17px; line-height: 1.8;
  color: var(--ink);
  margin-bottom: 20px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* 选项：字母 + 分隔线 + 内容（参考粉笔） */
.option {
  display: flex; align-items: center;
  min-height: 58px;
  border-radius: 12px;
  margin-bottom: 12px;
  padding: 8px 16px 8px 0;
  border: 1.5px solid transparent;
  background: #fff;
  box-shadow: 0 1px 4px rgba(20, 26, 40, 0.05);
  transition: background .15s, border-color .15s, transform .1s;
  user-select: none;
  text-align: left;
  width: 100%;
}
.option:active { transform: scale(.985); }
.option .letter {
  flex: 0 0 52px;
  text-align: center;
  font-size: 16px; font-weight: 600;
  color: var(--ink-3);
}
.option .divider {
  flex: 0 0 1px; align-self: stretch;
  background: var(--line);
  margin: 4px 0;
}
.option .text {
  flex: 1;
  padding: 6px 0 6px 16px;
  font-size: 16px; color: var(--ink);
  line-height: 1.6;
  word-break: break-word;
}
.option.selected {
  background: var(--blue-soft);
  border-color: rgba(47, 107, 255, .45);
}
.option.selected .letter { color: var(--blue); }
.option.selected .divider { background: rgba(47, 107, 255, .35); }

/* 富文本内容（题干/材料/解析内的图片与段落） */
.q-stem p, .material-plain p, .analysis-box p, .option .text p { margin: 0 0 .5em; }
.q-stem p:last-child, .material-plain p:last-child, .analysis-box p:last-child, .option .text p:last-child { margin-bottom: 0; }
.q-stem img, .material-plain img, .analysis-box img { max-width: 100%; height: auto; display: block; margin: 8px auto; }
.option .text img { max-width: 100%; max-height: 120px; height: auto; display: block; margin: 4px 0; }

/* 图片题 */
.stem-imgs { margin: -6px 0 18px; }
.stem-imgs img {
  display: block; max-width: 100%;
  margin: 0 auto 8px;
}
.option .text .option-img {
  display: block; max-width: 100%; max-height: 84px;
  margin: 4px 0;
}

/* 解析态配色 */
.option.correct { background: var(--green-soft); border-color: rgba(31,170,110,.4); }
.option.correct .letter { color: var(--green); }
.option.correct .divider { background: rgba(31,170,110,.35); }
.option.wrong { background: var(--red-soft); border-color: rgba(229,72,77,.4); }
.option.wrong .letter { color: var(--red); }
.option.wrong .divider { background: rgba(229,72,77,.35); }
.option.dim { opacity: .55; }

/* ========== 作答页：底栏 ========== */
.bottombar {
  position: sticky; bottom: 0; z-index: 20;
  display: flex; gap: 12px;
  padding: 12px 18px calc(12px + env(safe-area-inset-bottom));
  background: rgba(255,255,255,.95);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.nav-btn {
  flex: 1; height: 48px;
  border-radius: 12px;
  font-size: 16px; font-weight: 600;
  border: 1.5px solid var(--line);
  color: var(--ink-2); background: #fff;
  transition: opacity .2s, transform .1s;
}
.nav-btn:active { transform: scale(.97); }
.nav-btn:disabled { opacity: .35; }
.nav-btn.primary {
  background: linear-gradient(135deg, #4a86ff, var(--blue));
  border: none; color: #fff;
  box-shadow: 0 6px 14px rgba(47, 107, 255, 0.25);
}

/* ========== 答题卡弹层 ========== */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(15, 20, 32, 0.45);
  animation: fadein .2s;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 480px;
  background: #fff;
  border-radius: 20px 20px 0 0;
  box-shadow: var(--shadow-sheet);
  animation: sheetup .28s cubic-bezier(.22,.8,.36,1);
  padding: 18px 20px calc(20px + env(safe-area-inset-bottom));
}
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 6px;
}
.sheet-title { font-size: 17px; font-weight: 700; }
.sheet-close { color: var(--ink-3); font-size: 14px; padding: 6px; }
.sheet-stats { font-size: 13px; color: var(--ink-3); margin-bottom: 14px; }
.sheet-stats b { color: var(--blue); }

.grid-card {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-bottom: 18px;
  max-height: 40dvh; overflow-y: auto;
}
.grid-cell {
  height: 44px;
  border-radius: 10px;
  border: 1.5px solid var(--line);
  display: grid; place-items: center;
  font-size: 15px; font-weight: 600; color: var(--ink-2);
  background: #fff;
  transition: transform .1s;
}
.grid-cell:active { transform: scale(.92); }
.grid-cell.answered {
  background: var(--blue-soft);
  border-color: rgba(47,107,255,.4);
  color: var(--blue);
}
.grid-cell.current {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(47,107,255,.18);
}

/* ========== 弹窗 ========== */
.dialog-wrap {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(15, 20, 32, 0.45);
  display: grid; place-items: center;
  animation: fadein .18s;
  padding: 24px;
}
.dialog {
  width: 100%; max-width: 320px;
  background: #fff; border-radius: 18px;
  padding: 24px 22px 18px;
  animation: rise .25s cubic-bezier(.22,.8,.36,1);
  text-align: center;
}
.dialog h3 { font-size: 17px; margin-bottom: 8px; }
.dialog p { font-size: 14px; color: var(--ink-2); margin-bottom: 20px; line-height: 1.7; }
.dialog .row { display: flex; gap: 12px; }
.dialog .row button {
  flex: 1; height: 44px; border-radius: 12px;
  font-size: 15px; font-weight: 600;
}
.dialog .btn-ghost { background: #f0f2f6; color: var(--ink-2); }
.dialog .btn-solid { background: var(--blue); color: #fff; }

/* ========== 暂停遮罩 ========== */
.pause-mask {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(255,255,255,.96);
  backdrop-filter: blur(6px);
  display: grid; place-items: center;
  animation: fadein .2s;
}
.pause-box { text-align: center; color: var(--ink-2); }
.pause-box .pi {
  width: 72px; height: 72px; margin: 0 auto 18px;
  border-radius: 50%;
  background: var(--blue-soft); color: var(--blue);
  display: grid; place-items: center;
}
.pause-box p { font-size: 15px; }

/* ========== 结果页 ========== */
.result-hero {
  background: var(--card);
  padding: 40px 24px 34px;
  text-align: center;
  border-bottom: 1px solid var(--line);
}
.score-ring { width: 168px; height: 168px; margin: 0 auto; position: relative; }
.score-ring svg { transform: rotate(-90deg); }
.score-ring .center {
  position: absolute; inset: 0;
  display: grid; place-content: center; gap: 2px;
}
.score-ring .num { font-size: 38px; font-weight: 700; }
.score-ring .num small { font-size: 16px; color: var(--ink-3); font-weight: 500; }
.score-ring .lbl { font-size: 13px; color: var(--ink-3); }
.result-title { font-size: 19px; font-weight: 700; margin-bottom: 4px; }
.result-sub { font-size: 13px; color: var(--ink-3); margin-bottom: 24px; }

.stat-row {
  display: flex; margin-top: 28px;
  background: var(--paper);
  border-radius: var(--radius);
  padding: 16px 0;
}
.stat { flex: 1; text-align: center; }
.stat + .stat { border-left: 1px solid var(--line); }
.stat .v { font-size: 20px; font-weight: 700; }
.stat .v.green { color: var(--green); }
.stat .v.red { color: var(--red); }
.stat .k { font-size: 12px; color: var(--ink-3); margin-top: 2px; }

.result-actions { padding: 20px; display: grid; gap: 12px; }

.btn-block {
  height: 52px; border-radius: 14px;
  font-size: 16px; font-weight: 600;
  background: linear-gradient(135deg, #4a86ff, var(--blue));
  color: #fff;
  box-shadow: 0 8px 18px rgba(47, 107, 255, 0.28);
}
.btn-block.ghost {
  background: #fff; color: var(--ink-2);
  border: 1.5px solid var(--line); box-shadow: none;
}

/* ========== 解析页 ========== */
.review-head {
  position: sticky; top: 0; z-index: 20;
  height: 52px; display: flex; align-items: center;
  padding: 0 10px;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.review-head .title { flex: 1; text-align: center; font-size: 16px; font-weight: 700; }
/* 解析页顶部：对错纵览跳转条 */
.review-overview {
  position: sticky; top: 52px; z-index: 19;
  display: flex; gap: 8px;
  padding: 10px 16px;
  overflow-x: auto;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  scrollbar-width: none;
}
.review-overview::-webkit-scrollbar { display: none; }
.ov-chip {
  flex: 0 0 34px; height: 34px;
  border-radius: 10px;
  display: grid; place-items: center;
  font-size: 14px; font-weight: 600;
  border: 1.5px solid transparent;
}
.ov-chip.g-correct { background: var(--green-soft); color: var(--green); border-color: rgba(31,170,110,.35); }
.ov-chip.g-wrong { background: var(--red-soft); color: var(--red); border-color: rgba(229,72,77,.35); }
.ov-chip.g-blank { background: #f2f3f7; color: var(--ink-3); border-color: var(--line); }
.ov-chip.active { box-shadow: 0 0 0 3px rgba(47,107,255,.22); }

.review-body { padding: 16px 16px 40px; }
.review-card {
  background: var(--card);
  border-radius: 16px;
  padding: 18px 18px 16px;
  margin-bottom: 14px;
  box-shadow: 0 2px 10px rgba(20, 26, 40, 0.04);
  scroll-margin-top: 112px;
}
.answer-line {
  display: flex; gap: 16px; flex-wrap: wrap;
  font-size: 14px;
  padding: 12px 2px 0;
  border-top: 1px dashed var(--line);
  margin-top: 4px;
}
.answer-line .k { color: var(--ink-3); }
.answer-line .v-green { color: var(--green); font-weight: 700; }
.answer-line .v-red { color: var(--red); font-weight: 700; }
.answer-line .v-plain { color: var(--ink); font-weight: 700; }

.analysis-box {
  margin-top: 12px;
  background: #fafbff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 14px; color: var(--ink-2); line-height: 1.8;
}
.analysis-box .tag {
  display: inline-block;
  font-size: 12px; font-weight: 700; color: var(--blue);
  margin-bottom: 4px;
}
.time-tag {
  margin-left: auto; font-size: 12px; color: var(--ink-3);
  display: inline-flex; align-items: center; gap: 4px;
}
