/* ============================================================
   阅读小达人 · 样式（移动端优先，兼容手机 / 平板 / 桌面）
   ============================================================ */
:root {
  --bg: #fdf6ec;
  --bg-soft: #f4ece0;
  --card: #ffffff;
  --ink: #211c16;
  --ink-2: #5b5244;
  --line: #e7ddcd;
  --brand: #e8743b;
  --brand-soft: #ffdfcd;
  --ok: #3aa76d;
  --bad: #d9534f;
  --blue: #3f8fd0;
  --read-size: 22px;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(120, 100, 70, .08);
}

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

/* 只要有 hidden 属性就一定不显示（避免 display:flex 之类把它盖掉） */
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans SC", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

.app { max-width: 1000px; margin: 0 auto; padding: 0 14px 28px; }

/* ---------------- 顶部栏 ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 2px;
  background: linear-gradient(var(--bg) 78%, rgba(253, 246, 236, 0));
}
.topbar-title { flex: 1; min-width: 0; }
.topbar-title strong { display: block; font-size: 18px; line-height: 1.25; }
.topbar-title small { display: block; color: var(--ink-2); font-size: 12px; }
.btn-icon {
  width: 42px; height: 42px; flex: 0 0 auto;
  border: 1px solid var(--line); border-radius: 13px;
  background: var(--card); color: var(--ink);
  font-size: 20px; line-height: 1; cursor: pointer;
}
.btn-icon:active { transform: scale(.96); }

/* ---------------- 通用 ---------------- */
.view[hidden] { display: none !important; }
.hint { color: var(--ink-2); font-size: 12px; }
.tip {
  margin: 10px 0 0; padding: 10px 12px;
  background: var(--bg-soft); border-radius: 12px;
  color: var(--ink-2); font-size: 13px; line-height: 1.6;
}
.tag {
  display: inline-block; padding: 2px 9px; margin: 0 6px 6px 0;
  background: var(--bg-soft); border-radius: 999px;
  color: var(--ink-2); font-size: 12px; white-space: nowrap;
}

.panel {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; margin-bottom: 14px;
}
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.panel-head h2 { margin: 0; font-size: 16px; }

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--card);
  color: var(--ink); font-size: 15px; font-weight: 600;
  padding: 10px 16px; border-radius: 12px; cursor: pointer;
  font-family: inherit; min-height: 44px;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-text { border: 0; background: none; color: var(--brand); font-size: 13px; cursor: pointer; padding: 4px 6px; font-family: inherit; }
.pulse { animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { transform: none; } 50% { transform: scale(1.05); } }

/* ---------------- 首页 ---------------- */
.hero { padding: 6px 4px 14px; }
.hero h1 { margin: 0 0 6px; font-size: 26px; letter-spacing: .5px; }
.hero p { margin: 0; color: var(--ink-2); font-size: 14px; }

.grade-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.grade-card {
  display: flex; flex-direction: column; gap: 4px;
  padding: 14px 12px; border-radius: 14px; cursor: pointer;
  border: 1px solid var(--line); background: #fff;
  font-family: inherit; text-align: left; color: var(--ink);
}
.grade-card b { font-size: 17px; }
.grade-card span { color: var(--ink-2); font-size: 12px; }
.grade-card:active { transform: scale(.98); }
.grade-card.g1 { background: #ffeef1; border-color: #ffd7dd; }
.grade-card.g2 { background: #fff3e0; border-color: #ffe1bd; }
.grade-card.g3 { background: #f2f8e8; border-color: #dcecc4; }
.grade-card.g4 { background: #eaf4fb; border-color: #cde4f4; }
.grade-card.g5 { background: #f1eefb; border-color: #ded7f3; }
.grade-card.g6 { background: #fdf0e6; border-color: #f6dcc8; }

.setting-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 9px 2px; border-bottom: 1px dashed var(--line);
}
.setting-row:last-of-type { border-bottom: 0; }
.setting-row > label { font-size: 15px; }
.stepper { display: flex; align-items: center; gap: 6px; background: var(--bg-soft); border-radius: 12px; padding: 4px; }
.stepper output { min-width: 84px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.btn-step {
  width: 40px; height: 36px; border-radius: 9px; border: 1px solid var(--line);
  background: #fff; font-size: 18px; cursor: pointer; line-height: 1; color: var(--ink);
}
.btn-step:active { transform: scale(.94); }
.switch-row > label { flex: 1; }
.switch { width: 52px; height: 30px; appearance: none; background: #ddd3c4; border-radius: 999px; position: relative; cursor: pointer; flex: 0 0 auto; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: .18s; }
.switch:checked { background: var(--ok); }
.switch:checked::after { left: 25px; }

.record-list { list-style: none; margin: 0; padding: 0; }
.record-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 2px; border-bottom: 1px dashed var(--line);
}
.record-item:last-child { border-bottom: 0; }
.rec-main { min-width: 0; }
.rec-main b { display: block; font-size: 14px; }
.rec-main small { color: var(--ink-2); font-size: 12px; }
.rec-right { display: flex; gap: 10px; align-items: center; font-size: 13px; flex: 0 0 auto; }
.rec-right .speed { color: var(--blue); font-weight: 700; }
.rec-right .score { color: var(--ok); font-weight: 700; }
.record-list .empty { color: var(--ink-2); font-size: 13px; padding: 6px 2px; }

/* ---------------- 年级页 ---------------- */
.tabs { display: flex; gap: 8px; margin: 4px 0 12px; }
.tab {
  flex: 1; padding: 10px 8px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--line); background: var(--card);
  font-family: inherit; font-size: 15px; font-weight: 600; color: var(--ink-2);
}
.tab.is-active { background: var(--brand); border-color: var(--brand); color: #fff; }

.card-list { display: grid; gap: 12px; }
.passage-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.p-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.p-head b { font-size: 17px; }
.diff { color: #f0a92c; font-size: 13px; letter-spacing: 1px; }
.p-meta { color: var(--ink-2); font-size: 12px; margin: 3px 0 8px; }
.p-intro { margin: 0 0 10px; padding: 8px 10px; background: var(--bg-soft); border-radius: 10px; font-size: 13px; line-height: 1.65; color: #4a4239; }
.p-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.p-est { color: var(--ink-2); font-size: 12px; }

.book-list { display: grid; gap: 12px; }
.book-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.book-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.book-head b { font-size: 16px; }
.book-card small { color: var(--ink-2); font-size: 12px; }
.book-card p { margin: 6px 0 0; font-size: 14px; color: #4a4239; }

/* ---------------- 阅读页 ---------------- */
.read-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin: 4px 0 8px; }
.read-head h2 { margin: 0; font-size: 18px; }
.read-quick { display: flex; gap: 6px; flex: 0 0 auto; flex-wrap: wrap; justify-content: flex-end; }
.chip {
  border: 1px solid var(--line); background: var(--card); color: var(--ink-2);
  border-radius: 999px; padding: 6px 11px; font-size: 12px; cursor: pointer;
  font-family: inherit; white-space: nowrap;
}

.progress { height: 8px; background: var(--bg-soft); border-radius: 999px; overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #f6b26b, var(--brand)); border-radius: 999px; transition: width .12s linear; }
.read-stats { display: flex; justify-content: space-between; gap: 8px; color: var(--ink-2); font-size: 12px; padding: 6px 2px 10px; font-variant-numeric: tabular-nums; }

.read-stage {
  position: relative;
  height: clamp(230px, 46vh, 460px);
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 16px;
  scroll-behavior: auto;
}
.read-text { font-size: var(--read-size); line-height: 2; letter-spacing: .04em; color: #1b1712; font-weight: 600; }
.read-text .para { margin: 0 0 .5em; text-indent: 2em; }
.read-text .para:last-child { margin-bottom: 0; }

.ch {
  opacity: 0; border-radius: 5px;
  transition: opacity .07s linear, background-color .07s linear;
}
.ch.on { opacity: 1; }
.ch.on { background: #ffd8a8; color: #14100b; }
.read-text.no-highlight .ch.on { background: transparent; }
.read-text.keep-read .ch.read { opacity: 1; color: #8c8578; }

.countdown {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(253, 246, 236, .94); border-radius: var(--radius);
}
.countdown span { font-size: 64px; font-weight: 800; color: var(--brand); }
.countdown span.pop { animation: pop .5s ease-out; }
@keyframes pop { 0% { transform: scale(.5); opacity: 0; } 45% { transform: scale(1.15); opacity: 1; } 100% { transform: scale(1); opacity: 1; } }

.read-controls { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin-top: 12px; }

/* ---------------- 答题页 ---------------- */
.q-block { padding: 12px 2px; border-bottom: 1px dashed var(--line); }
.q-block:last-child { border-bottom: 0; }
.q-text { margin: 0 0 10px; font-size: 15px; font-weight: 600; line-height: 1.65; }
.q-text b {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; margin-right: 6px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand); font-size: 13px; vertical-align: 1px;
}
.q-type {
  display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 999px;
  background: var(--bg-soft); color: var(--ink-2); font-size: 11px; font-weight: 500; vertical-align: 2px;
}
.opts { display: grid; gap: 8px; }
.opt {
  display: flex; align-items: center; gap: 10px; text-align: left;
  padding: 11px 12px; border: 1px solid var(--line); border-radius: 12px;
  background: #fff; font-family: inherit; font-size: 15px; color: var(--ink); cursor: pointer;
}
.opt i {
  flex: 0 0 auto; width: 24px; height: 24px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg-soft); color: var(--ink-2); font-style: normal; font-size: 13px; font-weight: 700;
}
.opt.is-picked { border-color: var(--brand); background: #fff6f1; }
.opt.is-picked i { background: var(--brand); color: #fff; }
.blank-input, .short-input {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 12px;
  font-family: inherit; font-size: 15px; background: #fff; color: var(--ink);
}
.short-input { resize: vertical; }
.blank-input:focus, .short-input:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
.quiz-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

/* ---------------- 结果页 ---------------- */
.result-top {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 14px;
}
.score-ring {
  position: relative; width: 108px; height: 108px; flex: 0 0 auto; border-radius: 50%;
  background: conic-gradient(var(--ok) var(--pct, 0%), #ece5d8 0);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.score-ring::after { content: ''; position: absolute; inset: 11px; border-radius: 50%; background: #fff; }
.score-ring span { position: relative; z-index: 1; font-size: 34px; font-weight: 800; line-height: 1; }
.score-ring small { position: relative; z-index: 1; color: var(--ink-2); font-size: 12px; }
.result-info { flex: 1; min-width: 220px; }
.result-info h3 { margin: 0 0 8px; font-size: 18px; }
.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; }
.info-grid div { background: var(--bg-soft); border-radius: 10px; padding: 8px 10px; }
.info-grid small { display: block; color: var(--ink-2); font-size: 11px; }
.info-grid b { font-size: 15px; }
.verdict { margin: 10px 0 4px; font-size: 14px; line-height: 1.6; }

.review-list { list-style: none; margin: 0; padding: 0; }
.review-item { padding: 12px 12px 12px 14px; border-radius: 12px; margin-bottom: 10px; background: var(--bg-soft); border-left: 5px solid var(--line); }
.review-item.ok { border-left-color: var(--ok); }
.review-item.no { border-left-color: var(--bad); }
.rv-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.rv-head b { font-size: 14.5px; font-weight: 600; }
.badge { font-weight: 800; color: var(--ok); }
.review-item.no .badge { color: var(--bad); }
.rv-answer { margin-top: 6px; font-size: 14px; color: var(--ink-2); }
.rv-answer em { color: var(--ink); font-style: normal; font-weight: 600; }
.ref { margin-top: 6px; font-size: 14px; background: #fff; border-radius: 10px; padding: 8px 10px; line-height: 1.7; }
.ref b { color: var(--brand); }
.self-judge { margin-top: 8px; font-size: 13px; color: var(--ink-2); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.mini { border: 1px solid var(--line); background: #fff; border-radius: 9px; padding: 6px 10px; font-size: 13px; cursor: pointer; font-family: inherit; color: var(--ink); }
.result-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; margin-bottom: 10px; }

.help-list { margin: 0; padding-left: 20px; color: #4a4239; font-size: 14px; line-height: 1.8; }
.foot { text-align: center; color: var(--ink-2); font-size: 12px; padding: 8px 4px 0; }

/* ---------------- 平板 / 桌面 ---------------- */
@media (min-width: 640px) {
  .app { padding: 0 20px 34px; }
  .grade-grid { grid-template-columns: repeat(3, 1fr); }
  .card-list { grid-template-columns: repeat(2, 1fr); }
  .book-list { grid-template-columns: repeat(2, 1fr); }
  .read-stage { padding: 22px 24px; }
  .hero h1 { font-size: 30px; }
  .topbar-title strong { font-size: 20px; }
}
@media (min-width: 900px) {
  .read-stage { height: clamp(300px, 52vh, 520px); }
}
/* 横屏（平板 / 手机横放）时把阅读区拉高一点，减少滚动 */
@media (orientation: landscape) and (max-height: 560px) {
  .read-stage { height: 60vh; }
  .hero { padding-bottom: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .ch { transition: none; }
  .pulse { animation: none; }
}
