:root {
  --bg: #f4f7f6;
  --surface: #ffffff;
  --primary: #3d8b8b;
  --primary-dark: #2f7373;
  --primary-soft: #e8f3f3;
  --accent: #e8a87c;
  --accent-soft: #fdf4ee;
  --ok: #4caf7a;
  --ok-soft: #eaf7f0;
  --bad: #d96666;
  --bad-soft: #fceeee;
  --text: #1a2e2e;
  --muted: #7a9292;
  --line: #e2ecec;
  --r: 18px;
  --r-sm: 12px;
  --shadow: 0 8px 24px rgba(45, 90, 90, 0.08);
  --font-read: 19px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

#app { max-width: 440px; margin: 0 auto; min-height: 100dvh; }

.view { display: none; min-height: 100dvh; }
.view.active { display: flex; flex-direction: column; }

/* ===== 首页 ===== */
.home-header {
  padding: calc(20px + env(safe-area-inset-top, 0px)) 20px 16px;
  background: linear-gradient(160deg, #3d8b8b 0%, #5cadad 100%);
  color: #fff;
  border-radius: 0 0 28px 28px;
}

.home-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.greeting {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.stats-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255,255,255,0.18);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  backdrop-filter: blur(6px);
}

.stats-pill b { font-size: 16px; margin-right: 2px; }
.stats-pill .dot { width: 4px; height: 4px; border-radius: 50%; background: rgba(255,255,255,0.5); }

.home-main {
  flex: 1;
  padding: 20px 16px calc(24px + var(--safe-b));
  margin-top: -10px;
}

.start-card {
  background: var(--surface);
  border-radius: var(--r);
  padding: 18px;
  box-shadow: var(--shadow);
}

.select-field, .input-field {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: var(--r-sm);
  padding: 13px 14px;
  font: inherit;
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
  margin-bottom: 12px;
  appearance: none;
}

.settings-fold {
  margin: 14px 4px 20px;
  font-size: 13px;
  color: var(--muted);
}

.settings-fold summary {
  cursor: pointer;
  list-style: none;
  color: var(--primary);
  font-weight: 600;
  margin-bottom: 10px;
}

.settings-fold summary::-webkit-details-marker { display: none; }

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  cursor: pointer;
}

.list-head {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0 6px 10px;
}

.article-list { display: flex; flex-direction: column; gap: 8px; }

.article-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 16px;
  border: none;
  background: var(--surface);
  border-radius: var(--r-sm);
  box-shadow: 0 2px 8px rgba(45, 90, 90, 0.04);
  text-align: left;
  font: inherit;
  cursor: pointer;
  transition: transform .15s;
}

.article-item:active { transform: scale(0.98); }
.article-item.done { opacity: 0.72; }

.item-num {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--primary-soft);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.article-item.done .item-num { background: var(--ok-soft); color: var(--ok); }

.item-info { flex: 1; min-width: 0; }
.item-info h3 { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-info p { font-size: 12px; color: var(--muted); margin-top: 2px; }

.item-arrow { color: var(--muted); font-size: 18px; }

/* ===== 按钮 ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--r-sm);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .12s, opacity .12s;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-main {
  width: 100%;
  padding: 15px;
  background: linear-gradient(135deg, #4caf7a, #3d8b8b);
  color: #fff;
  box-shadow: 0 6px 16px rgba(61, 139, 139, 0.28);
}

.btn-ghost {
  width: 100%;
  padding: 11px;
  margin-top: 8px;
  background: transparent;
  color: var(--muted);
  font-weight: 500;
}

.btn-sm { padding: 10px 14px; font-size: 14px; }

/* ===== 顶栏 ===== */
.bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.bar-center { flex: 1; min-width: 0; text-align: center; }
.bar-title { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-sub { font-size: 11px; color: var(--muted); margin-top: 1px; }
.bar-spacer { width: 40px; }
.bar-badge { font-size: 13px; color: var(--muted); min-width: 40px; text-align: right; }

.icon-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 12px;
  background: var(--bg);
  font: inherit;
  font-size: 17px;
  cursor: pointer;
  color: var(--text);
}

.progress-track {
  height: 3px;
  background: var(--line);
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #4caf7a, #3d8b8b);
  transition: width .35s ease;
}

/* ===== 语音页 ===== */
.voice-stage {
  text-align: center;
  padding: 28px 20px 12px;
}

.voice-mic {
  width: 88px;
  height: 88px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: var(--primary-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.mic-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--primary);
  z-index: 1;
}

.mic-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid transparent;
}

.voice-mic.speaking { background: #eef6ff; }
.voice-mic.speaking .mic-dot { background: #5cadad; }
.voice-mic.speaking .mic-ring { border-color: #5cadad; animation: pulse 1.4s infinite; }

.voice-mic.listening { background: var(--ok-soft); }
.voice-mic.listening .mic-dot { background: var(--ok); animation: blink 1s infinite; }
.voice-mic.listening .mic-ring { border-color: var(--ok); animation: pulse 0.9s infinite; }

.voice-mic.ready { background: var(--accent-soft); }
.voice-mic.ready .mic-dot { background: var(--accent); }

@keyframes pulse {
  0% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1.2); opacity: 0; }
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.voice-countdown {
  width: 56px;
  height: 56px;
  margin: -8px auto 12px;
  border-radius: 50%;
  border: 3px solid var(--ok);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 700;
  color: var(--primary);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.voice-countdown[hidden] { display: none !important; }

.voice-status {
  font-size: 20px;
  font-weight: 700;
  padding: 0 24px;
  min-height: 1.4em;
}

.voice-substatus {
  font-size: 14px;
  color: var(--muted);
  padding: 4px 24px 0;
  min-height: 1.2em;
}

.voice-substatus:empty { display: none; }

#view-voice.phase-quiz .voice-stage {
  padding: 10px 16px 6px;
}

#view-voice.phase-quiz .voice-mic {
  width: 52px;
  height: 52px;
  margin-bottom: 6px;
}

#view-voice.phase-quiz .voice-mic .mic-dot {
  width: 10px;
  height: 10px;
}

#view-voice.phase-quiz .voice-status {
  font-size: 16px;
}

.voice-panels {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  margin: 0 16px 8px;
  gap: 8px;
}

.panel-scroll {
  padding: 14px;
  background: var(--surface);
  border-radius: var(--r-sm);
  box-shadow: 0 2px 8px rgba(45, 90, 90, 0.04);
  overflow-y: auto;
  font-size: 16px;
  line-height: 1.85;
}

.panel-article {
  flex: 1;
  min-height: 120px;
}

.voice-panels.has-question .panel-article {
  flex: 0 1 auto;
  max-height: 40vh;
  font-size: 14px;
  line-height: 1.75;
  border-bottom: 2px solid var(--primary-soft);
}

.panel-question {
  flex: 1;
  min-height: 0;
}

.panel-question[hidden] { display: none !important; }

.panel-scroll p { margin-bottom: 0.85em; text-indent: 2em; }
.panel-scroll p.highlight { background: var(--accent-soft); border-radius: 8px; padding: 6px 8px; }
.panel-scroll .q-title { font-weight: 600; text-indent: 0; margin-bottom: 10px; font-size: 15px; }
.panel-scroll .q-opt {
  text-indent: 0;
  padding: 10px 12px;
  margin-bottom: 6px;
  border-radius: 10px;
  border: 1.5px solid var(--line);
  font-size: 14px;
}
.panel-scroll .q-hint { text-indent: 0; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.panel-scroll .q-your-answer { text-indent: 0; color: var(--text); font-size: 15px; margin-bottom: 8px; }
.panel-scroll .q-open-input-wrap .btn { margin-top: 10px; width: 100%; }
.panel-scroll .q-ref { text-indent: 0; color: var(--muted); font-size: 14px; line-height: 1.6; }
.panel-scroll .q-open-input-wrap textarea {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  font: inherit;
  font-size: 14px;
  resize: vertical;
  margin-top: 8px;
}
.panel-scroll .q-opt.correct { border-color: var(--ok); background: var(--ok-soft); }
.panel-scroll .q-opt.wrong { border-color: var(--bad); background: var(--bad-soft); }

.bar-footer {
  padding: 12px 16px calc(12px + var(--safe-b));
  background: linear-gradient(transparent, var(--bg) 40%);
}

/* ===== 阅读 ===== */
.article-body {
  flex: 1;
  padding: 20px 20px 100px;
  font-size: var(--font-read);
  line-height: 2;
}

.article-body.font-lg { --font-read: 22px; }
.article-body.font-sm { --font-read: 17px; }
.article-body p { margin-bottom: 1em; text-indent: 2em; }

/* ===== 答题 ===== */
.quiz-scroll {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.quiz-article {
  flex: 0 1 auto;
  max-height: 38vh;
  margin: 8px 16px 0;
  font-size: 14px;
  line-height: 1.75;
  border-bottom: 2px solid var(--primary-soft);
}

.quiz-article p { margin-bottom: 0.75em; text-indent: 2em; }

.quiz-body { flex: 1; padding: 16px 16px 100px; overflow-y: auto; min-height: 0; }

.quiz-q {
  font-size: 17px;
  font-weight: 600;
  line-height: 1.65;
  margin-bottom: 18px;
}

.quiz-options { display: flex; flex-direction: column; gap: 8px; }

.quiz-option {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  padding: 14px 14px;
  border: 1.5px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
  font: inherit;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
  color: var(--text);
}

.quiz-option .opt-label {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: var(--primary-soft);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.quiz-option.correct { border-color: var(--ok); background: var(--ok-soft); }
.quiz-option.correct .opt-label { background: var(--ok); color: #fff; }
.quiz-option.wrong { border-color: var(--bad); background: var(--bad-soft); }
.quiz-option.wrong .opt-label { background: var(--bad); color: #fff; }

.input-area {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: var(--r-sm);
  padding: 12px;
  font: inherit;
  font-size: 15px;
  line-height: 1.7;
  resize: vertical;
  min-height: 96px;
  background: var(--surface);
}

.row-btns { display: flex; gap: 10px; margin-top: 12px; }
.row-btns .btn { flex: 1; }

.feedback-box {
  margin-top: 16px;
  padding: 14px;
  border-radius: var(--r-sm);
  background: var(--primary-soft);
}

.feedback-box.correct-fb { background: var(--ok-soft); }
.feedback-box.wrong-fb { background: var(--bad-soft); }

.feedback-title { font-weight: 600; margin-bottom: 6px; }
.feedback-body { font-size: 14px; color: var(--muted); line-height: 1.6; }

/* ===== 结果 ===== */
.result-sheet {
  text-align: center;
  padding: 32px 20px calc(24px + var(--safe-b));
}

.result-sheet-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.result-emoji { font-size: 52px; margin-bottom: 8px; }
.result-heading { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.result-score { font-size: 44px; font-weight: 800; color: var(--primary); margin: 8px 0; }
.result-msg { font-size: 14px; color: var(--muted); margin-bottom: 20px; }

.result-detail {
  width: 100%;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
  max-height: 40vh;
  overflow-y: auto;
}

.result-item {
  background: var(--surface);
  border-radius: var(--r-sm);
  padding: 12px 14px;
  box-shadow: 0 2px 8px rgba(45, 90, 90, 0.04);
}

.result-item .q-num { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.result-item .q-text { font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.result-item .q-answer { font-size: 13px; color: var(--muted); line-height: 1.55; }

.tag {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  margin-right: 4px;
}

.tag-right { background: var(--ok-soft); color: var(--ok); }
.tag-wrong { background: var(--bad-soft); color: var(--bad); }
.tag-open { background: var(--accent-soft); color: #b07840; }

#voice-step { display: none; }
#stat-total { display: none; }
#feedback-icon { display: none; }
#quiz-open-hint { display: none; }
