/* Read Bean 阅豆 — mobile-first UI */

:root {
  --bg: #f6f1e8;
  --card: #ffffff;
  --ink: #2b2320;
  --muted: #8a7f76;
  --bean: #b0413e;       /* red-bean accent */
  --bean-dark: #8f312f;
  --sprout: #4caf7d;
  --gold: #e0a63c;
  --line: #e8dfd2;
  --shadow: 0 2px 10px rgba(60, 40, 20, 0.08);
  --radius: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1917;
    --card: #2a2421;
    --ink: #f0e8df;
    --muted: #a2968b;
    --line: #3a322d;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  }
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.center { text-align: center; }
.row-between { display: flex; justify-content: space-between; align-items: center; }

/* ——— App frame ——— */

.phone {
  max-width: 480px;
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.view {
  flex: 1;
  overflow-y: auto;
  padding: 20px 18px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.tabbar {
  display: flex;
  border-top: 1px solid var(--line);
  background: var(--card);
  padding-bottom: env(safe-area-inset-bottom);
}

.tab {
  flex: 1;
  padding: 10px 0 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 0.72rem;
  color: var(--muted);
}
.tab.active { color: var(--bean); font-weight: 600; }
.tab-icon { font-size: 1.25rem; }

/* ——— Shared bits ——— */

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  text-align: left;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.progress {
  height: 10px;
  border-radius: 5px;
  background: var(--line);
  margin-top: 10px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 5px;
  background: linear-gradient(90deg, var(--gold), var(--bean));
  transition: width 0.4s ease;
}

.big-btn {
  display: block;
  width: 100%;
  padding: 14px;
  border-radius: 14px;
  background: var(--bean);
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
  margin-top: 10px;
  transition: transform 0.06s ease, background 0.15s ease;
}
.big-btn:active { transform: scale(0.98); }
.big-btn.ghost {
  background: transparent;
  color: var(--bean);
  border: 1.5px solid var(--bean);
}
.big-btn.danger { color: #c0392b; border-color: #c0392b; }
.big-btn.saved { border-color: var(--sprout); color: var(--sprout); }

.tiny-btn {
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  font-size: 0.82rem;
  color: var(--muted);
}
.tiny-btn.on { border-color: var(--bean); color: var(--bean); font-weight: 600; }

.chev { font-size: 1.6rem; color: var(--muted); }

.xp-pill {
  margin-left: auto;
  background: var(--gold);
  color: #4a3305;
  font-weight: 700;
  font-size: 0.82rem;
  padding: 6px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.xp-pill.big { display: inline-block; margin: 12px auto; font-size: 1rem; }

/* ——— Home ——— */

.hero { padding: 6px 2px 0; }
.brand { font-size: 1.5rem; font-weight: 800; }
.brand-bean { filter: hue-rotate(-20deg); }
.brand-zh { color: var(--bean); font-size: 1.15rem; }
.tagline { color: var(--muted); margin-top: 2px; }

.streak-card { display: flex; align-items: center; gap: 14px; }
.streak-flame { font-size: 2.2rem; }
.streak-num { font-size: 1.15rem; font-weight: 800; }
.goal-done { margin-top: 8px; color: var(--sprout); font-weight: 600; }

.continue-card { display: flex; align-items: center; gap: 14px; width: 100%; }
.continue-info { flex: 1; }
.continue-title { font-size: 1.1rem; font-weight: 700; margin-top: 2px; }

.mini-card { display: flex; flex-direction: column; gap: 2px; align-items: flex-start; }
.mini-icon { font-size: 1.4rem; }

/* ——— Library ——— */

.page-head h1 { font-size: 1.5rem; }

.chip-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.chip {
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  white-space: nowrap;
  font-size: 0.85rem;
}
.chip-on { background: var(--bean); border-color: var(--bean); color: #fff; font-weight: 600; }

.lesson-card { display: flex; gap: 12px; align-items: center; width: 100%; }
.lesson-emoji {
  width: 52px; height: 52px;
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem;
  flex-shrink: 0;
}
.lesson-info { flex: 1; min-width: 0; }
.lesson-title { font-size: 1.15rem; font-weight: 700; }
.lesson-meta { display: flex; align-items: center; gap: 6px; margin-top: 4px; flex-wrap: wrap; }
.level-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

.badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}
.badge-read { background: #4caf7d33; color: var(--sprout); }
.badge-quiz { background: #e0a63c33; color: var(--gold); }

/* ——— Reader ——— */

.reader-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.reader-controls { display: flex; gap: 6px; }

.level-tag {
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  display: inline-block;
}
.reader-title h1 { font-size: 1.5rem; margin-top: 6px; }

.reader {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 18px;
  line-height: 2.4;
}

.sentence { padding: 4px 2px 10px; border-radius: 10px; }
.sentence.playing { background: #e0a63c22; }

.zh-line { font-size: 1.35em; }

ruby.w {
  cursor: pointer;
  border-radius: 6px;
  padding: 1px 1px 0;
  transition: background 0.12s ease;
  ruby-position: over;
}
ruby.w:hover, ruby.w:active { background: #b0413e26; }
ruby.w rt {
  font-size: 0.48em;
  color: var(--muted);
  font-weight: 400;
}
.no-pinyin ruby.w rt { display: none; }

.punct { color: var(--muted); }

.sen-tools { display: flex; gap: 6px; margin: 2px 0 4px; }
.en-line {
  color: var(--muted);
  font-size: 0.9rem;
  border-left: 3px solid var(--line);
  padding-left: 10px;
  line-height: 1.5;
  margin-bottom: 6px;
}

.reader-footer { padding-bottom: 8px; }

/* ——— Word sheet ——— */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 12, 8, 0.45);
  z-index: 40;
}

.word-sheet {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: min(480px, 100%);
  background: var(--card);
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -6px 30px rgba(0, 0, 0, 0.25);
  padding: 26px 22px calc(26px + env(safe-area-inset-bottom));
  z-index: 50;
  text-align: center;
  animation: slide-up 0.18s ease;
}
@keyframes slide-up { from { transform: translate(-50%, 40%); } to { transform: translate(-50%, 0); } }

.sheet-word { font-size: 2.6rem; font-weight: 700; }
.sheet-pinyin { color: var(--bean); font-size: 1.15rem; margin-top: 4px; }
.sheet-gloss { color: var(--muted); margin-top: 8px; font-size: 1rem; }
.sheet-actions { display: flex; gap: 10px; margin-top: 18px; }
.sheet-actions .big-btn { flex: 1; margin-top: 0; }

/* ——— Quiz ——— */

.quiz-progress { margin-top: 0; }
.quiz-card { display: flex; flex-direction: column; gap: 12px; }
.quiz-q { font-size: 1.25rem; font-weight: 600; line-height: 1.7; }
.blank {
  color: var(--bean);
  font-weight: 800;
  letter-spacing: 2px;
  border-bottom: 2px solid var(--bean);
  margin: 0 3px;
}

.quiz-opts { display: flex; flex-direction: column; gap: 10px; }
.opt {
  padding: 13px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: var(--bg);
  font-size: 1.05rem;
  text-align: left;
  transition: border-color 0.12s ease;
}
.opt:not(:disabled):hover { border-color: var(--bean); }
.opt-right { border-color: var(--sprout); background: #4caf7d1f; font-weight: 700; }
.opt-wrong { border-color: #c0392b; background: #c0392b1a; }

.quiz-feedback .ok { color: var(--sprout); font-weight: 700; }
.quiz-feedback .bad { color: #c0392b; font-weight: 600; }

.result-card, .center-card { text-align: center; padding: 30px 20px; }
.result-emoji { font-size: 3rem; }
.result-card h1 { font-size: 2rem; margin: 8px 0 4px; }

/* ——— Flashcards ——— */

.flash-card {
  min-height: 260px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
}
.flash-word { font-size: 3rem; font-weight: 700; }
.flash-back .sheet-pinyin { font-size: 1.3rem; }
.flash-back .tiny-btn { margin-top: 12px; }

.grade-row { display: flex; gap: 8px; }
.grade {
  flex: 1;
  padding: 13px 0;
  border-radius: 12px;
  font-weight: 700;
  color: #fff;
}
.g-again { background: #c0392b; }
.g-hard { background: #d98e32; }
.g-good { background: #4caf7d; }
.g-easy { background: #3b9ec9; }

.section-h { font-size: 1.05rem; margin-top: 6px; }

.vocab-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 10px 12px;
}
.vocab-word { font-size: 1.35rem; font-weight: 700; }
.vocab-mid { flex: 1; min-width: 0; }
.vocab-due { white-space: nowrap; }

/* ——— Stats ——— */

.stat-card { text-align: center; }
.stat-num { font-size: 1.45rem; font-weight: 800; }

.chart {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 110px;
  margin-top: 14px;
}
.bar-wrap {
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 3px;
}
.bar {
  width: 100%;
  border-radius: 4px 4px 0 0;
  background: var(--line);
  min-height: 3px;
}
.bar-goal { background: var(--sprout); }
.bar-today { outline: 2px solid var(--gold); }
.bar-label { font-size: 0.58rem; color: var(--muted); }

.level-rows { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.level-row { display: flex; align-items: center; gap: 10px; }
.level-row .level-tag { width: 52px; text-align: center; flex-shrink: 0; }
.level-progress { flex: 1; margin-top: 0; }

/* ——— Toast ——— */

.toast {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translate(-50%, 20px);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 60;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
