/* ===== 顏色設定（國中 = 青綠色、多益 = 商務藍；自動支援深色模式） ===== */
:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef1f7;
  --text: #1c2333;
  --muted: #677189;
  --border: #e1e6ef;
  --accent: #0e9f88;
  --accent-ink: #ffffff;
  --accent-soft: #dcf5f0;
  --good: #18a058;
  --good-soft: #e3f7eb;
  --bad: #d9463e;
  --bad-soft: #fdeaea;
  --warn: #8a5d00;
  --warn-soft: #fff4dc;
  --ai: #6b4dff;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 14px rgba(16, 24, 40, .07);
  --radius: 16px;
  color-scheme: light;
}
body[data-level="toeic"] { --accent: #3d5bd8; --accent-soft: #e5eaff; }

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f131a;
    --surface: #181d27;
    --surface-2: #222937;
    --text: #e7eaf1;
    --muted: #98a1b5;
    --border: #2a3142;
    --accent: #2fc6ae;
    --accent-ink: #06201b;
    --accent-soft: #143530;
    --good: #2ea866;
    --good-soft: #15301f;
    --bad: #f26b63;
    --bad-soft: #3a1b1a;
    --warn: #f0c25e;
    --warn-soft: #352a10;
    --ai: #9d8aff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
  body[data-level="toeic"] { --accent: #8098ff; --accent-ink: #0b1233; --accent-soft: #1e2748; }
}

/* ===== 基本 ===== */
* { 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, "Segoe UI", Roboto, "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h2 { line-height: 1.3; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--accent); color: var(--accent-ink);
}
.topbar h1 { flex: 1; margin: 0; font-size: 18px; font-weight: 700; text-align: center; }
.icon-btn {
  width: 40px; height: 40px; border: 0; border-radius: 12px;
  background: rgba(255, 255, 255, .2); color: inherit; font-size: 20px;
}
.invisible { visibility: hidden; }

main { max-width: 560px; margin: 0 auto; padding: 16px 16px calc(32px + env(safe-area-inset-bottom)); }

/* ===== 首頁 ===== */
.hero { background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: var(--surface-2); padding: 5px; border-radius: 14px; }
.seg-btn { border: 0; background: transparent; padding: 12px 8px; border-radius: 10px; font-size: 17px; font-weight: 700; color: var(--muted); }
.seg-btn.on { background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow); }
.hero-desc { margin: 12px 2px 14px; color: var(--muted); font-size: 14px; text-align: center; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; }
.stats div { background: var(--surface-2); border-radius: 12px; padding: 8px 4px; }
.stats b { display: block; font-size: 20px; color: var(--accent); }
.stats span { font-size: 12px; color: var(--muted); }

.sec { font-size: 15px; color: var(--muted); margin: 22px 4px 10px; font-weight: 700; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tiles.one { grid-template-columns: 1fr; }
.tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left;
  min-height: 104px; padding: 14px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow);
  transition: transform .1s;
}
.tile:active { transform: scale(.97); }
.tile-icon { font-size: 28px; line-height: 1.2; }
.tile-title { font-weight: 700; font-size: 16px; }
.tile-sub { font-size: 13px; color: var(--muted); }
.tile:disabled { opacity: .5; cursor: default; }
.foot { text-align: center; color: var(--muted); font-size: 12px; margin-top: 24px; }

/* ===== 按鈕 ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 10px 16px;
  border-radius: 14px; border: 1px solid var(--border);
  background: var(--surface); font-weight: 700;
  transition: transform .08s, opacity .2s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .6; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.good { background: var(--good); border-color: var(--good); color: #fff; }
.btn.bad { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
.btn.ai { background: linear-gradient(135deg, #7b5cff, #3d8bff); border: 0; color: #fff; }
.btn.block { width: 100%; margin-top: 12px; }
.btn.big { font-size: 18px; min-height: 56px; padding: 12px 28px; }
.actions.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.actions .btn { min-height: 58px; font-size: 17px; }

.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-bottom: 8px; }
.bar > div { height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }
.count { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 12px; }
.badge { display: inline-block; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 99px; }

/* ===== 記憶卡 ===== */
.flashcard { perspective: 1200px; cursor: pointer; outline: none; }
.fc-inner { display: grid; min-height: 340px; transition: transform .5s cubic-bezier(.2, .7, .2, 1); transform-style: preserve-3d; }
.flashcard.flipped .fc-inner { transform: rotateY(180deg); }
.fc-face {
  grid-area: 1 / 1;
  -webkit-backface-visibility: hidden; backface-visibility: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  padding: 24px 20px; text-align: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 22px; box-shadow: var(--shadow);
}
.fc-back { transform: rotateY(180deg); }
.fc-word { font-size: 40px; font-weight: 800; line-height: 1.2; word-break: break-word; }
.fc-word.sm { font-size: 22px; color: var(--muted); }
.fc-phon { font-size: 18px; color: var(--muted); }
.fc-pos { background: var(--accent-soft); color: var(--accent); padding: 2px 12px; border-radius: 99px; font-size: 14px; font-weight: 700; }
.fc-hint { font-size: 13px; color: var(--muted); margin-top: 10px; }
.fc-meaning { font-size: 30px; font-weight: 800; color: var(--accent); line-height: 1.3; }
.fc-ex { display: flex; align-items: center; justify-content: center; gap: 4px; font-size: 17px; margin-top: 6px; }
.fc-exzh { color: var(--muted); font-size: 15px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 8px; }
.chip { background: var(--surface-2); border-radius: 99px; padding: 4px 12px; font-size: 14px; }

.speak {
  flex: none; border: 0; width: 64px; height: 64px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-size: 28px; margin-top: 8px;
}
.speak.sm { width: 36px; height: 36px; font-size: 16px; margin: 0 0 0 6px; vertical-align: middle; }

/* ===== 單字配對 ===== */
.match-top {
  display: flex; justify-content: space-between; gap: 8px;
  background: var(--surface); border-radius: 12px; padding: 10px 14px; box-shadow: var(--shadow); font-size: 14px;
}
.hint { text-align: center; color: var(--muted); font-size: 13px; margin: 10px 0; }
.match-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.col { display: flex; flex-direction: column; gap: 10px; }
.m-card {
  min-height: 58px; padding: 8px 10px; border-radius: 14px;
  border: 2px solid var(--border); background: var(--surface);
  font-weight: 700; font-size: 16px; word-break: break-word;
  transition: border-color .15s, background .15s;
}
.m-card.zh { font-weight: 600; font-size: 15px; }
.m-card.sel { border-color: var(--accent); background: var(--accent-soft); }
.m-card.wrong { border-color: var(--bad); background: var(--bad-soft); animation: shake .4s; }
.m-card.matched {
  border-color: var(--good); background: var(--good-soft); pointer-events: none;
  animation: vanish .6s forwards;
}
@keyframes vanish { 0% { transform: scale(1); opacity: 1; } 40% { transform: scale(1.06); opacity: 1; } 100% { transform: scale(.85); opacity: 0; } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

/* ===== 測驗 ===== */
.q-meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.passage {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: 12px; padding: 14px; margin-bottom: 12px; white-space: pre-line; line-height: 1.75;
}
.blank { display: inline-block; min-width: 3em; border-bottom: 2px solid var(--accent); color: transparent; line-height: 1.1; }
.q-text { font-size: 19px; font-weight: 700; margin: 6px 2px 14px; }
.options { display: flex; flex-direction: column; gap: 10px; }
.opt {
  display: flex; align-items: center; gap: 12px; text-align: left;
  min-height: 56px; padding: 10px 14px; border-radius: 14px;
  border: 2px solid var(--border); background: var(--surface); font-size: 17px;
}
.opt:disabled { cursor: default; color: inherit; }
.opt-l { flex: none; width: 30px; height: 30px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; font-weight: 800; font-size: 14px; }
.opt.correct { border-color: var(--good); background: var(--good-soft); }
.opt.correct .opt-l { background: var(--good); color: #fff; }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); animation: shake .4s; }
.opt.wrong .opt-l { background: var(--bad); color: #fff; }
.opt.dim { opacity: .55; }

.listen {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  background: var(--surface); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 14px;
}
.listen-accent { font-size: 13px; color: var(--muted); }

.feedback { margin-top: 16px; border-radius: var(--radius); padding: 14px 16px; border: 1px solid var(--border); }
.feedback.ok { border-color: var(--good); background: var(--good-soft); }
.feedback.no { border-color: var(--bad); background: var(--bad-soft); }
.fb-title { font-weight: 800; font-size: 17px; }
.fb-exp, .fb-script { margin-top: 8px; font-size: 15px; }
.fb-note { font-size: 13px; color: var(--muted); margin: 6px 0 10px; }

.ai-box { margin-top: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; font-size: 15px; }
.ai-box p { margin: 4px 0; }
.ai-head { font-weight: 800; margin-bottom: 6px; color: var(--ai); }
.ai-box.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; white-space: pre-line; }
.ai-box.loading { color: var(--muted); display: flex; align-items: center; gap: 10px; }
.spin { flex: none; width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--ai); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== 成績 / 空白頁 ===== */
.result { text-align: center; background: var(--surface); border-radius: 22px; padding: 28px 20px; box-shadow: var(--shadow); margin-top: 8px; }
.result-emoji { font-size: 64px; line-height: 1.2; }
.result h2 { margin: 8px 0 12px; }
.result p { margin: 4px 0; color: var(--muted); }
.big-num { font-size: 44px; font-weight: 800; color: var(--accent); }
.result-btns { margin-top: 16px; }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.e-icon { font-size: 56px; }
.empty h2 { color: var(--text); }

/* ===== 錯題本 ===== */
.mk-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; font-weight: 700; }
.tip { background: var(--warn-soft); color: var(--warn); border-radius: 12px; padding: 10px 14px; font-size: 14px; margin-bottom: 12px; }
.mk-list { display: flex; flex-direction: column; gap: 14px; }
.mk { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.mk .q-text { font-size: 17px; margin: 4px 0 10px; }
.mk-ans { font-size: 15px; padding: 6px 10px; border-radius: 10px; margin-top: 6px; }
.mk-ans.no { background: var(--bad-soft); color: var(--bad); }
.mk-ans.ok { background: var(--good-soft); color: var(--good); }
.mk-btns { display: grid; grid-template-columns: 1fr auto; gap: 10px; margin-top: 12px; }
.mk-passage { background: var(--surface-2); border-radius: 10px; padding: 8px 12px; margin-bottom: 8px; font-size: 15px; }
.mk-passage summary { cursor: pointer; font-weight: 700; color: var(--muted); }

/* ===== 設定頁 ===== */
.panel { background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.panel h2 { font-size: 17px; margin: 0 0 4px; }
label { display: block; font-weight: 700; font-size: 14px; margin: 14px 0 6px; }
input[type="text"], input[type="password"], input[type="url"], select {
  width: 100%; min-height: 48px; padding: 10px 12px;
  border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); font-size: 16px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.row { display: flex; gap: 8px; align-items: center; }
.row input { flex: 1; min-width: 0; }
.row.wrap { flex-wrap: wrap; }
.help { font-size: 13px; color: var(--muted); margin: 6px 2px 0; white-space: pre-line; }
.panel .btn { margin-top: 12px; }
.panel .row .btn { margin-top: 0; }
.panel .row.wrap .btn { margin-top: 8px; }

/* ===== AI 智慧出題 ===== */
.kind-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 8px; scrollbar-width: none; }
.kind-row::-webkit-scrollbar { display: none; }
.kind-chip {
  flex: none; border: 1px solid var(--border); background: var(--surface);
  padding: 8px 14px; border-radius: 99px; font-size: 14px; font-weight: 700; color: var(--muted);
}
.kind-chip.on { background: var(--ai); border-color: var(--ai); color: #fff; }
.ai-score { font-size: 13px; color: var(--muted); margin: 2px 2px 12px; }
.ai-score b { color: var(--accent); }
.ai-loading { text-align: center; padding: 48px 16px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.ai-loading p { margin: 12px 0 0; font-weight: 700; }
.ai-loading .help { font-weight: 400; margin-top: 4px; }
.spin.big { display: inline-block; width: 40px; height: 40px; border-width: 4px; }

/* ===== 拍照建庫 ===== */
label.check { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 16px; margin: 10px 0; }
label.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.preview { display: block; width: 100%; max-height: 360px; object-fit: contain; margin-top: 12px; border-radius: 12px; background: var(--surface-2); }
.pv-list { display: flex; flex-direction: column; gap: 10px; }
.pv {
  display: flex; gap: 12px; align-items: flex-start; margin: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px;
  font-weight: 400; font-size: 15px; cursor: pointer;
}
.pv input { flex: none; width: 22px; height: 22px; margin-top: 2px; accent-color: var(--accent); }
.pv:has(input:not(:checked)) { opacity: .5; }
.pv-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.pv-word { font-size: 18px; }
.pv-mean { color: var(--accent); font-weight: 700; }
.pv-q { font-weight: 700; }
.pv-passage { background: var(--surface-2); border-radius: 8px; padding: 6px 10px; margin: 0; }
.pv-opts { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 14px; }
.pv-right { color: var(--good); font-weight: 800; }
.sticky-save {
  position: sticky; bottom: 0; margin: 16px -16px 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--bg); border-top: 1px solid var(--border);
}
.sticky-save .btn.block:first-child { margin-top: 0; }
.steps { margin: 8px 0 12px; padding-left: 22px; font-size: 15px; }
.steps li { margin: 4px 0; }
.copy-box { width: 100%; min-height: 140px; margin-top: 12px; padding: 10px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); font-size: 13px; }

/* ===== 打卡列（首頁最上方） ===== */
.streak-row {
  width: 100%; display: flex; align-items: center; gap: 12px; text-align: left;
  margin-bottom: 12px; padding: 12px 14px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow);
}
.streak-row.done { background: linear-gradient(135deg, #fff1e0, #ffe2e2); border-color: transparent; }
.streak-fire { font-size: 30px; line-height: 1; }
.streak-row:not(.done) .streak-fire { filter: grayscale(.6); }
.streak-text { flex: 1; display: flex; flex-direction: column; }
.streak-text b { font-size: 17px; }
.streak-text small { font-size: 13px; color: var(--muted); }
.streak-row.done .streak-text b, .streak-row.done .streak-text small { color: #8a3b00; }
.streak-badges { font-size: 14px; font-weight: 700; color: var(--muted); white-space: nowrap; }
.tile-sub .due { color: var(--bad); }

/* ===== 祝賀彈窗 ===== */
.celebrate {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 24px;
  background: rgba(10, 14, 22, .55); animation: fadeIn .2s;
}
.cel-card {
  position: relative; overflow: hidden; width: 100%; max-width: 340px; text-align: center;
  background: var(--surface); border-radius: 24px; padding: 28px 22px 20px; box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
  animation: popIn .45s cubic-bezier(.2, 1.4, .4, 1);
}
.cel-icon { font-size: 72px; line-height: 1.1; animation: bounce 1.2s ease-in-out infinite; }
.cel-kicker { margin-top: 6px; font-size: 13px; font-weight: 800; letter-spacing: 1px; color: var(--accent); }
.cel-card h2 { margin: 6px 0 4px; font-size: 24px; }
.cel-card p { margin: 0 0 8px; color: var(--muted); }
.confetti { position: absolute; inset: 0; pointer-events: none; }
.confetti i { position: absolute; top: -12px; width: 8px; height: 14px; border-radius: 2px; opacity: .9; animation: fall 2s ease-in forwards; }
@keyframes fall { to { transform: translateY(420px) rotate(540deg); opacity: 0; } }
@keyframes popIn { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }

/* ===== 錯題特訓 ===== */
.drill-intro { text-align: center; }
.drill-fire { font-size: 56px; line-height: 1.1; }
.drill-intro h2 { font-size: 22px; margin: 4px 0 12px; }
.drill-nums { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.drill-nums div { background: var(--surface-2); border-radius: 12px; padding: 8px 4px; }
.drill-nums b { display: block; font-size: 24px; color: var(--accent); }
.drill-nums span { font-size: 12px; color: var(--muted); }
.srs-steps { text-align: left; margin: 14px 0 0; padding-left: 22px; font-size: 14px; color: var(--muted); }
.srs-steps li { margin: 3px 0; }
.srs-steps b { color: var(--text); }
.srs { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-size: 13px; color: var(--muted); margin: -2px 0 6px; }
.srs.now { color: var(--bad); }
.srs.grad { color: var(--good); font-weight: 700; }
.dots { letter-spacing: 2px; color: var(--good); font-size: 12px; }
.srs-note { margin: 8px 0 4px; padding: 8px 12px; border-radius: 10px; background: var(--surface); font-size: 14px; font-weight: 700; }
.srs-note.grad { background: var(--good); color: #fff; }
.srs-note.bad { color: var(--bad); }

/* ===== 打卡與成就頁 ===== */
.streak-hero { text-align: center; }
.streak-big { font-size: 28px; font-weight: 800; }
.streak-big b { font-size: 52px; color: #ff7a00; }
.streak-sub { margin: 4px 0 14px; color: var(--muted); font-size: 14px; }
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.wday { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0; border-radius: 12px; background: var(--surface-2); font-size: 12px; color: var(--muted); }
.wday b { font-size: 20px; line-height: 1.2; }
.wday.on { background: #fff1e0; color: #8a3b00; }
.wday.today { outline: 2px solid var(--accent); }
.stats.totals { margin-top: 12px; }
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.badge-card {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px;
  padding: 14px 10px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border);
}
.badge-card:not(.got) .b-icon { filter: grayscale(1); opacity: .35; }
.badge-card.got { border-color: #ffc56b; background: linear-gradient(180deg, #fff8e8, var(--surface)); }
.b-icon { font-size: 40px; line-height: 1.2; }
.b-name { font-weight: 800; font-size: 15px; }
.b-desc { font-size: 12px; color: var(--muted); }
.b-date { font-size: 12px; color: var(--muted); margin-top: 2px; }
.badge-card.got .b-date { color: #a05a00; font-weight: 700; }
.b-prog { width: 80%; height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin-top: 6px; }
.b-prog div { height: 100%; background: var(--accent); }

@media (prefers-color-scheme: dark) {
  .streak-row.done { background: linear-gradient(135deg, #3a2412, #3a1a1a); }
  .streak-row.done .streak-text b, .streak-row.done .streak-text small { color: #ffc58f; }
  .wday.on { background: #3a2412; color: #ffc58f; }
  .badge-card.got { border-color: #7a5520; background: linear-gradient(180deg, #2e2414, var(--surface)); }
  .badge-card.got .b-date { color: #ffc58f; }
}

/* ===== 今日單字目標 ===== */
.goal-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 12px;
}
.goal-card.finished { border-color: var(--good); background: linear-gradient(180deg, var(--good-soft), var(--surface)); }
.goal-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.goal-head b { font-size: 16px; }
.goal-edit { border: 0; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 13px; padding: 6px 12px; border-radius: 99px; }
.goal-picker { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; }
.goal-picker[hidden] { display: none; }
.goal-picker .kind-chip.on { background: var(--accent); border-color: var(--accent); }
.goal-picker .help { width: 100%; margin: 0; }
.goal-num { margin-top: 8px; font-size: 15px; color: var(--muted); }
.goal-num b { font-size: 32px; color: var(--accent); }
.goal-ok { margin-left: 8px; color: var(--good); font-weight: 800; font-size: 14px; }
.goal-bar { height: 12px; margin: 6px 0; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.goal-bar div { height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--accent), #ffb020); transition: width .4s; }
.goal-card.finished .goal-bar div { background: var(--good); }
.goal-meta { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); }
.goal-card .btn.block { margin-top: 12px; }
.goal-val { font-size: 22px; color: var(--accent); }
.range-marks { position: relative; height: 18px; margin: 0 8px; font-size: 12px; color: var(--muted); }
.range-marks span { position: absolute; transform: translateX(-50%); }
.badge.new { background: #fff1d6; color: #9a5b00; }
@media (prefers-color-scheme: dark) { .badge.new { background: #3a2a10; color: #ffc97a; } }

/* ===== 記憶卡評分按鈕 ===== */
.flip-btn { margin-top: 16px; }
.actions .btn small, .actions .btn span { display: block; font-weight: 600; }
.actions .btn small { font-size: 11px; opacity: .8; margin-top: 2px; }
.actions .btn span { font-size: 13px; }
.actions.two .btn, .actions.three .btn { flex-direction: column; gap: 0; line-height: 1.25; padding: 8px 6px; }
.actions.three { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.actions.three .btn { min-height: 76px; font-size: 16px; }
.grade-q { text-align: center; color: var(--muted); font-size: 14px; margin: 14px 0 0; }
.grade-in { animation: gradeIn .3s ease-out; }
@keyframes gradeIn { from { opacity: 0; transform: translateY(10px); } }
.btn.g-easy { background: var(--good-soft); border-color: var(--good); color: var(--good); }
.btn.g-fuzzy { background: #fff6d8; border-color: #e0a800; color: #8a6400; }
.btn.g-hard { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
@media (prefers-color-scheme: dark) { .btn.g-fuzzy { background: #362c0e; border-color: #c99a1e; color: #f3cf6a; } }

/* ===== 語速（國中／多益分開） ===== */
.rate-row { border: 1px solid var(--border); border-radius: 14px; padding: 10px 12px; margin-top: 8px; }
.rate-row.current { border-color: var(--accent); background: var(--accent-soft); }
.rate-head { display: flex; align-items: center; gap: 8px; }
.rate-head b { font-size: 15px; }
.panel .btn.rate-try { margin: 0 0 0 auto; min-height: 36px; padding: 4px 12px; font-size: 14px; }
.rate-chips { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin-top: 8px; }
.rate-chips .kind-chip { padding: 8px 0; text-align: center; }
.rate-chips .kind-chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* ===== 儲存空間提醒 ===== */
.storage-banner {
  position: fixed; left: 12px; right: 12px; top: calc(64px + env(safe-area-inset-top)); z-index: 90;
  max-width: 536px; margin: 0 auto; display: flex; flex-direction: column; gap: 6px;
  padding: 14px 16px; border-radius: 16px; background: var(--bad-soft); color: var(--bad);
  border: 1px solid var(--bad); box-shadow: 0 10px 30px rgba(0, 0, 0, .18); animation: popIn .3s;
}
.storage-banner span { color: var(--text); font-size: 14px; }
.storage-banner .row .btn { min-height: 40px; flex: 1; }
.store-num { font-size: 14px; color: var(--muted); margin-top: 4px; }
.store-num b { font-size: 22px; color: var(--text); }
.store-bar.full div { background: var(--bad); }
.store-list { list-style: none; padding: 0; margin: 8px 0; font-size: 14px; }
.store-list li { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px dashed var(--border); }

/* ===== 首頁：程度細分、今日單字拆分 ===== */
.sub-line { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 8px; margin: -6px 0 12px; }
.sub-line .help { margin: 0; }
.sub-chip { border: 1px solid var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 13px; padding: 4px 12px; border-radius: 99px; }
.sub-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.sub-chips .kind-chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.sub-desc { margin-top: 6px; }
.goal-split { display: flex; gap: 8px; margin: 6px 0 4px; font-size: 13px; }
.goal-split span { flex: 1; background: var(--surface-2); border-radius: 10px; padding: 6px 10px; color: var(--muted); }
.goal-split b { color: var(--text); font-size: 15px; }
.goal-note { margin: 8px 0 0; font-size: 13px; color: var(--warn); background: var(--warn-soft); border-radius: 10px; padding: 6px 10px; }
.goal-card .btn.block:disabled { opacity: .5; }

/* ===== 閱讀測驗、長篇聽力 ===== */
.passage.long { font-size: 15px; line-height: 1.7; max-height: 46vh; overflow-y: auto; }
.fb-script-head { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.fb-script .line, .mk-passage-text .line { margin: 2px 0; }
.mk-passage-text { white-space: pre-line; margin-top: 6px; }

/* ===== ✍️ 聽寫拼字 ===== */
.spell-card { background: var(--surface); border: 1px solid var(--border); border-radius: 22px; box-shadow: var(--shadow); padding: 20px 16px; text-align: center; }
.spell-play { display: flex; align-items: center; justify-content: center; gap: 12px; }
.spell-play .speak { margin: 0; width: 72px; height: 72px; font-size: 32px; }
.spell-zh { font-size: 28px; font-weight: 800; color: var(--accent); }
.spell-hint { color: var(--muted); margin-top: 8px; font-size: 15px; }
.slots { display: flex; justify-content: center; flex-wrap: wrap; gap: 5px; margin: 16px 0 2px; }
.slot { width: 24px; height: 32px; border-bottom: 3px solid var(--border); font-size: 20px; font-weight: 800; line-height: 30px; }
.slot.on { border-color: var(--accent); color: var(--accent); }
.slot.sep { border-color: transparent; width: 12px; }
.help.center { text-align: center; }
.spell-input {
  width: 100%; min-height: 56px; margin-top: 12px; padding: 10px 14px; text-align: center;
  font-size: 24px; font-weight: 700; letter-spacing: 2px; border-radius: 14px;
  border: 2px solid var(--border); background: var(--surface-2); color: var(--text);
}
.spell-input:focus { outline: none; border-color: var(--accent); }
.spell-card .feedback { text-align: left; }
.spell-diff { margin: 6px 0 2px; }
.diff { font-size: 22px; font-weight: 800; letter-spacing: 2px; }
.d-ok { color: var(--good); }
.d-bad { color: var(--bad); text-decoration: underline; text-decoration-thickness: 3px; }
.spell-word { margin-top: 8px; }

/* ===== 📖 單字表 ===== */
.wl-search input {
  width: 100%; min-height: 48px; padding: 10px 14px; border-radius: 14px;
  border: 1px solid var(--border); background: var(--surface); font-size: 16px; color: var(--text);
}
.kind-row.wrap { flex-wrap: wrap; overflow: visible; margin-top: 10px; }
.wl-bar { display: flex; justify-content: space-between; align-items: center; margin: 6px 2px 10px; }
.wl-bar select { width: auto; min-height: 36px; padding: 4px 10px; font-size: 14px; }
.wl-list { display: flex; flex-direction: column; gap: 8px; }
.wl-item { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--border); border-radius: 14px; }
.wl-item.st-weak { border-left-color: var(--bad); }
.wl-item.st-due { border-left-color: #e0a800; }
.wl-item.st-learning { border-left-color: var(--accent); }
.wl-item.st-master { border-left-color: var(--good); }
.wl-item summary { display: flex; align-items: center; gap: 10px; padding: 10px 12px; cursor: pointer; list-style: none; }
.wl-item summary::-webkit-details-marker { display: none; }
.wl-main { flex: 1; min-width: 0; }
.wl-word { font-size: 17px; }
.wl-mean { display: block; color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wl-st { text-align: right; flex: none; }
.wl-badge { display: block; font-size: 12px; font-weight: 700; }
.wl-st small { font-size: 11px; color: var(--muted); }
.wl-detail { padding: 0 12px 12px; font-size: 15px; }
.wl-detail p { margin: 6px 0; }
.chips.left { justify-content: flex-start; }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.empty-sm { text-align: center; color: var(--muted); padding: 20px 0; }

/* ===== 📊 學習統計（圖表顏色：已通過色盲辨識檢查） ===== */
.viz { --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-0: #c9ccd3; --grid: #e6e8ec; --axis: #c3c2b7; }
@media (prefers-color-scheme: dark) {
  .viz { --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-0: #3a4152; --grid: #2a3142; --axis: #3d4556; }
}
.stat-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.stat-tile { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; display: flex; flex-direction: column; }
.stat-tile span { font-size: 13px; color: var(--muted); }
.stat-tile b { font-size: 30px; line-height: 1.2; color: var(--text); }
.stat-tile b small { font-size: 15px; color: var(--muted); }
.stat-tile .delta { font-size: 12px; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--muted); margin: 6px 0; }
.legend.wrap { flex-wrap: wrap; gap: 6px 14px; }
.legend b { color: var(--text); }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.sw.s1, .mseg.s1 { background: var(--series-1); }
.sw.s2, .mseg.s2 { background: var(--series-2); }
.sw.s3, .mseg.s3 { background: var(--series-3); }
.sw.s0, .mseg.s0 { background: var(--series-0); }
.viz-box { position: relative; }
.viz-svg { width: 100%; height: auto; display: block; overflow: visible; }
.viz-svg .grid { stroke: var(--grid); stroke-width: 1; }
.viz-svg .axis { stroke: var(--axis); stroke-width: 1; }
.viz-svg .tick { fill: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.viz-svg .s1 { fill: var(--series-1); }
.viz-svg .s2 { fill: var(--series-2); }
.viz-svg .s3 { fill: var(--series-3); }
.viz-svg .line1 { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.viz-svg .dot1 { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.viz-svg .hit { fill: transparent; cursor: pointer; }
.viz-svg .hit.tip-on { fill: var(--grid); fill-opacity: .45; }
.viz-tip {
  position: fixed; z-index: 60; pointer-events: none; max-width: 260px;
  background: #1c2333; color: #fff; font-size: 13px; padding: 6px 10px; border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .25);
}
.viz-table { margin-top: 8px; font-size: 13px; }
.viz-table summary { cursor: pointer; color: var(--muted); }
.viz-table table { width: 100%; border-collapse: collapse; margin-top: 6px; font-variant-numeric: tabular-nums; }
.viz-table th, .viz-table td { padding: 4px 6px; border-bottom: 1px solid var(--border); text-align: right; }
.viz-table th:first-child, .viz-table td:first-child { text-align: left; }
.hbars { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.hb-row { display: grid; grid-template-columns: 110px 1fr 64px; align-items: center; gap: 8px; cursor: pointer; }
.hb-name { font-size: 14px; }
.hb-name em { font-style: normal; font-size: 11px; font-weight: 700; color: var(--bad); margin-left: 4px; }
.hb-track { height: 14px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.hb-fill { display: block; height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; }
.hb-row.tip-on .hb-track { outline: 2px solid var(--grid); }
.hb-val { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.hb-val small { display: block; font-size: 11px; font-weight: 400; color: var(--muted); }
.mbar { display: flex; gap: 2px; height: 22px; margin: 10px 0 8px; }
.mseg { border-radius: 4px; min-width: 4px; cursor: pointer; }
.mseg.tip-on { outline: 2px solid var(--text); outline-offset: 1px; }

/* ===== 底部分頁列 ===== */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
  box-shadow: 0 -2px 12px rgba(16, 24, 40, .06);
}
.tabbar[hidden] { display: none; }
.tab {
  position: relative; border: 0; background: transparent;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 60px; padding: 6px 0; color: var(--muted); font-size: 12px; font-weight: 700;
}
.tab-icon { position: relative; font-size: 23px; line-height: 1.1; transition: transform .15s; }
.tab-emoji { filter: grayscale(.8); opacity: .75; }   /* 只有圖示變灰，紅色數字不受影響 */
.tab.on { color: var(--accent); }
.tab.on .tab-icon { transform: translateY(-1px) scale(1.08); }
.tab.on .tab-emoji { filter: none; opacity: 1; }
.tab.on::after { content: ''; position: absolute; top: 0; left: 28%; right: 28%; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent); }
.tab-badge {
  position: absolute; top: -4px; left: 70%; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 99px; background: var(--bad); color: #fff; font-size: 11px; font-style: normal;
  font-weight: 800; line-height: 18px; text-align: center; box-shadow: 0 0 0 2px var(--surface);
}
body.has-tabs main { padding-bottom: calc(92px + env(safe-area-inset-bottom)); }
body.has-tabs #toast { bottom: calc(84px + env(safe-area-inset-bottom)); }

/* 背單字、練習分頁上方的程度切換 */
.seg.mini { margin-bottom: 10px; }
.seg.mini .seg-btn { padding: 8px; font-size: 15px; }
.seg.mini + .sub-line { margin: 0 0 12px; }

/* 首頁「今天建議做的事」 */
.todo-list { display: flex; flex-direction: column; gap: 8px; }
.todo-row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 12px 14px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface); box-shadow: var(--shadow); transition: transform .1s;
}
.todo-row:active { transform: scale(.98); }
.todo-icon { font-size: 26px; line-height: 1; }
.todo-text { flex: 1; display: flex; flex-direction: column; }
.todo-text b { font-size: 16px; }
.todo-text small { color: var(--muted); font-size: 13px; }
.todo-row.hot { border-color: var(--bad); }
.todo-row.hot small { color: var(--bad); font-weight: 700; }
.chev { color: var(--muted); font-size: 24px; line-height: 1; }
.goal-card + .sec { margin-top: 18px; }

#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 50;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: calc(100% - 32px); padding: 10px 18px; border-radius: 99px;
  background: #1c2333; color: #fff; font-size: 14px; text-align: center;
  transition: opacity .25s, transform .25s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

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