:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #2b2f38;
  --muted: #8a91a0;
  --brand: #5b7cfa;
  --brand-dark: #3f5fe0;
  --ok: #2fb877;
  --bad: #ef5c6e;
  --n5: #3fb37f;
  --n4: #4aa3d8;
  --n3: #f0a03d;
  --n2: #e97b5a;
  --n1: #b06de0;
  --shadow: 0 10px 30px rgba(40, 50, 90, 0.12);
  --radius: 18px;
}

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

body {
  font-family: "Noto Sans TC", "M PLUS Rounded 1c", system-ui, sans-serif;
  background: linear-gradient(160deg, #eef1fb 0%, #f6f4fb 100%);
  color: var(--ink);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 18px 60px;
}

/* Header */
.topbar { text-align: center; margin-bottom: 22px; }
.logo {
  font-family: "M PLUS Rounded 1c", sans-serif;
  font-size: 30px; font-weight: 800;
  color: var(--brand-dark);
  letter-spacing: 1px;
}
.tagline { color: var(--muted); margin-top: 4px; font-size: 14px; }

/* Screens */
.screen { display: none; animation: fade .3s ease; }
.screen.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.intro { text-align: center; color: var(--muted); margin-bottom: 18px; }
.section-title { font-size: 17px; margin: 22px 0 12px; font-weight: 700; }

/* Home big button */
.home-actions { margin-bottom: 6px; }
.big-btn {
  width: 100%; border: none; cursor: pointer;
  border-radius: var(--radius); padding: 20px;
  display: flex; flex-direction: column; gap: 4px; align-items: flex-start;
  background: linear-gradient(120deg, var(--brand), #7b6cf5);
  color: #fff; box-shadow: var(--shadow);
  transition: transform .15s ease, box-shadow .15s ease;
}
.big-btn:hover { transform: translateY(-2px); box-shadow: 0 14px 34px rgba(91,124,250,.35); }
.big-btn-title { font-size: 20px; font-weight: 800; }
.big-btn-sub { font-size: 13px; opacity: .9; }

/* Level grid */
.level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; }
.level-card {
  border: none; cursor: pointer; text-align: left;
  border-radius: var(--radius); padding: 16px;
  background: var(--card); box-shadow: var(--shadow);
  transition: transform .15s ease;
  border-left: 6px solid var(--brand);
}
.level-card:hover { transform: translateY(-3px); }
.level-card .lv-name { font-size: 22px; font-weight: 800; font-family: "M PLUS Rounded 1c"; }
.level-card .lv-desc { font-size: 12.5px; color: var(--muted); margin: 4px 0 8px; line-height: 1.4; }
.level-card .lv-count { font-size: 12px; color: var(--brand-dark); font-weight: 700; }
.level-card.n5 { border-left-color: var(--n5); } .level-card.n5 .lv-name { color: var(--n5); }
.level-card.n4 { border-left-color: var(--n4); } .level-card.n4 .lv-name { color: var(--n4); }
.level-card.n3 { border-left-color: var(--n3); } .level-card.n3 .lv-name { color: var(--n3); }
.level-card.n2 { border-left-color: var(--n2); } .level-card.n2 .lv-name { color: var(--n2); }
.level-card.n1 { border-left-color: var(--n1); } .level-card.n1 .lv-name { color: var(--n1); }

/* Mode grid */
.mode-grid { display: grid; gap: 12px; }
.mode-card {
  border: none; cursor: pointer; text-align: left;
  border-radius: var(--radius); padding: 18px;
  background: var(--card); box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 16px;
  transition: transform .15s ease;
}
.mode-card:hover { transform: translateY(-2px); }
.mode-emoji { font-size: 32px; }
.mode-name { font-size: 17px; font-weight: 700; display: block; }
.mode-desc { font-size: 13px; color: var(--muted); }

/* Buttons */
.back-btn {
  background: none; border: none; cursor: pointer;
  color: var(--brand-dark); font-size: 15px; font-weight: 600;
  margin-bottom: 12px; padding: 4px 0;
}
.back-btn:hover { text-decoration: underline; }

/* Quiz */
.quiz-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; }
.quiz-stats { display: flex; gap: 14px; font-size: 13px; color: var(--muted); }
.quiz-stats b { color: var(--ink); }
.progress { height: 8px; background: #e6e9f3; border-radius: 99px; overflow: hidden; margin: 10px 0 18px; }
.progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--brand), #7b6cf5); transition: width .3s ease; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 26px 22px; }
.prompt-block { text-align: center; margin-bottom: 22px; }
.prompt-main { font-size: 44px; font-weight: 800; font-family: "M PLUS Rounded 1c"; line-height: 1.2; word-break: break-all; }
.prompt-main.cn { font-size: 30px; }
.prompt-reading { font-size: 18px; color: var(--muted); margin-top: 6px; min-height: 22px; }
.speak-btn {
  margin-top: 14px; cursor: pointer;
  background: #eef1fe; color: var(--brand-dark);
  border: none; border-radius: 99px; padding: 8px 18px;
  font-size: 15px; font-weight: 700; transition: background .15s;
}
.speak-btn:hover { background: #dfe5fd; }
.speak-btn:active { transform: scale(.96); }

.options { display: grid; gap: 10px; }
.opt {
  border: 2px solid #e6e9f3; background: #fbfcff; cursor: pointer;
  border-radius: 14px; padding: 14px 16px; font-size: 17px; font-weight: 600;
  text-align: left; color: var(--ink); transition: all .12s ease;
}
.opt:hover:not(:disabled) { border-color: var(--brand); background: #f2f5ff; }
.opt:disabled { cursor: default; }
.opt.correct { border-color: var(--ok); background: #e7f8f0; color: #1c8a58; }
.opt.wrong { border-color: var(--bad); background: #fdecee; color: #c5364b; }

.feedback { text-align: center; font-weight: 700; margin-top: 16px; min-height: 24px; font-size: 16px; }
.feedback.ok { color: var(--ok); }
.feedback.bad { color: var(--bad); }

.next-btn {
  width: 100%; margin-top: 16px; cursor: pointer; border: none;
  background: var(--brand); color: #fff; font-weight: 700; font-size: 16px;
  border-radius: 14px; padding: 14px; transition: background .15s;
}
.next-btn:hover { background: var(--brand-dark); }
.hidden { display: none; }

/* Flashcard */
.flashcard { perspective: 1200px; margin: 10px 0 20px; }
.flash-inner {
  position: relative; width: 100%; min-height: 260px;
  transition: transform .5s; transform-style: preserve-3d; cursor: pointer;
}
.flashcard.flipped .flash-inner { transform: rotateY(180deg); }
.flash-front, .flash-back {
  position: absolute; inset: 0; backface-visibility: hidden;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px; text-align: center;
}
.flash-back { transform: rotateY(180deg); background: linear-gradient(140deg, #f4f7ff, #efeafe); }
.flash-word { font-size: 48px; font-weight: 800; font-family: "M PLUS Rounded 1c"; word-break: break-all; }
.flash-reading { font-size: 20px; color: var(--muted); margin-top: 8px; }
.flash-hint { font-size: 12px; color: var(--muted); margin-top: 18px; }
.flash-meaning { font-size: 28px; font-weight: 700; line-height: 1.5; }
.flash-nav { display: flex; gap: 10px; justify-content: center; }
.nav-btn {
  cursor: pointer; border: none; border-radius: 12px; padding: 12px 18px;
  background: var(--brand); color: #fff; font-weight: 700; font-size: 15px;
  transition: background .15s;
}
.nav-btn:hover { background: var(--brand-dark); }
.nav-btn.ghost { background: #eef1fe; color: var(--brand-dark); }
.nav-btn.ghost:hover { background: #dfe5fd; }

/* Result */
.result-card { text-align: center; }
.result-emoji { font-size: 64px; }
.result-score { font-size: 20px; margin: 10px 0; }
.result-score b { color: var(--brand-dark); font-size: 26px; }
.result-accuracy { color: var(--muted); }
.result-suggest {
  margin: 16px auto; max-width: 420px; padding: 12px 16px;
  background: #eef1fe; border-radius: 12px; font-size: 14px; color: var(--brand-dark);
}
.result-actions { display: flex; gap: 10px; justify-content: center; margin-top: 10px; }
.result-actions .next-btn { width: auto; padding: 12px 24px; }

.footer { text-align: center; color: var(--muted); font-size: 11.5px; margin-top: 30px; line-height: 1.6; }

.loading { text-align: center; color: var(--muted); padding: 30px; }

@media (max-width: 480px) {
  .prompt-main { font-size: 36px; }
  .flash-word { font-size: 40px; }
}

/* ===== 間隔重複 / 新增元件 ===== */
.big-btn.smart { background: linear-gradient(120deg, #2fb877, #21a7a0); margin-bottom: 10px; }
.big-btn.smart:hover { box-shadow: 0 14px 34px rgba(47,184,119,.32); }
.due-badge {
  display: inline-block; background: #ef5c6e; color: #fff;
  font-size: 11px; font-weight: 700; border-radius: 99px;
  padding: 1px 8px; margin-left: 6px; vertical-align: middle;
}
.big-btn .due-badge { background: rgba(255,255,255,.28); }

.lv-progress { height: 6px; background: #eceffa; border-radius: 99px; overflow: hidden; margin: 8px 0 6px; }
.lv-progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, #2fb877, #56d3a0); transition: width .4s ease; }

.mode-stats { background: #fff; border-radius: 12px; box-shadow: var(--shadow); padding: 10px 14px; font-size: 14px; color: var(--muted); margin-bottom: 14px; }
.mode-stats b { color: var(--brand-dark); }

.mode-card span:not(.mode-emoji) { display: flex; flex-direction: column; gap: 2px; }
.mode-name { font-size: 17px; font-weight: 700; }
.mode-desc { font-size: 13px; color: var(--muted); }

.prompt-instruction { font-size: 14px; color: var(--muted); margin-bottom: 10px; }
.prompt-main.listen { font-size: 60px; }

.typing-form { display: flex; gap: 10px; margin-top: 4px; }
.typing-input {
  flex: 1; border: 2px solid #e6e9f3; border-radius: 14px;
  padding: 14px 16px; font-size: 20px; font-family: "M PLUS Rounded 1c", sans-serif;
  outline: none; transition: border-color .15s;
}
.typing-input:focus { border-color: var(--brand); }
.typing-input:disabled { background: #f4f6fb; }
.typing-submit { width: auto; margin-top: 0; padding: 14px 22px; }

.result-sr {
  background: #f0fbf5; border: 1px solid #cdeede; color: #1c8a58;
  border-radius: 12px; padding: 12px 16px; font-size: 14px; margin: 6px auto 4px;
  max-width: 460px; line-height: 1.7;
}
.result-sr b { color: #157a4c; }

.home-footer-tools { text-align: center; margin-top: 26px; }
.link-btn { background: none; border: none; color: var(--muted); font-size: 13px; cursor: pointer; text-decoration: underline; }
.link-btn:hover { color: var(--bad); }
