:root {
  --bg: #f3f6f4;
  --card: #ffffff;
  --ink: #1a2e28;
  --muted: #5b6b65;
  --teal: #0f766e;
  --teal-soft: #ccfbf1;
  --amber: #b45309;
  --amber-soft: #ffedd5;
  --rose: #be123c;
  --rose-soft: #ffe4e6;
  --line: #d7e0db;
  --ok: #15803d;
  --shadow: 0 8px 24px rgba(15, 50, 40, 0.08);
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", sans-serif;
  line-height: 1.45;
  min-height: 100dvh;
}
button { font: inherit; cursor: pointer; }
#app { max-width: 560px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }

.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px calc(10px + env(safe-area-inset-top, 0px));
  background: rgba(243, 246, 244, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.top-title { flex: 1; font-weight: 700; font-size: 17px; }
.ghost {
  border: none; background: transparent; color: var(--teal);
  padding: 6px 8px; border-radius: 999px; min-width: 36px;
}
.badge-btn {
  background: var(--rose-soft); color: var(--rose); font-size: 13px; font-weight: 600;
}
.badge-btn span {
  display: inline-block; min-width: 1.2em; text-align: center;
}

main { padding: 14px 14px calc(28px + var(--safe-b)); flex: 1; }

.hero {
  background: linear-gradient(145deg, #0f766e 0%, #115e59 55%, #134e4a 100%);
  color: #fff; border-radius: 18px; padding: 18px 16px; margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.hero h1 { margin: 0 0 6px; font-size: 22px; letter-spacing: 0.02em; }
.hero p { margin: 0; opacity: 0.9; font-size: 13px; }
.stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px;
}
.stat {
  background: rgba(255,255,255,0.12); border-radius: 12px; padding: 8px;
  text-align: center;
}
.stat b { display: block; font-size: 18px; }
.stat span { font-size: 11px; opacity: 0.85; }

.section-label {
  font-size: 12px; color: var(--muted); font-weight: 600;
  margin: 16px 0 8px; letter-spacing: 0.04em;
}

.unit-list { display: grid; gap: 8px; }
.unit-card {
  display: flex; gap: 10px; align-items: center;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px; text-align: left;
  box-shadow: 0 2px 8px rgba(15,50,40,0.04);
}
.unit-card .idx {
  width: 42px; height: 42px; border-radius: 12px;
  background: var(--teal-soft); color: var(--teal);
  display: grid; place-items: center; font-weight: 700; font-size: 12px; flex: none;
}
.unit-card .meta { flex: 1; min-width: 0; }
.unit-card .meta b { display: block; font-size: 15px; }
.unit-card .meta span { color: var(--muted); font-size: 12px; }
.unit-card .prog {
  font-size: 12px; color: var(--teal); font-weight: 600; white-space: nowrap;
}

.tabs {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
  margin-bottom: 12px; position: sticky; top: 56px; z-index: 5;
  background: var(--bg); padding: 4px 0 8px;
}
.tab {
  border: 1px solid var(--line); background: var(--card); color: var(--muted);
  border-radius: 999px; padding: 8px 6px; font-size: 13px; font-weight: 600;
}
.tab.active { background: var(--teal); border-color: var(--teal); color: #fff; }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px; margin-bottom: 10px;
}
.card h3 { margin: 0 0 8px; font-size: 14px; color: var(--teal); }
.goal { font-size: 13px; color: var(--muted); margin-bottom: 10px; }

.key {
  padding: 8px 0; border-bottom: 1px dashed var(--line);
}
.key:last-child { border-bottom: none; }
.key .en { font-weight: 700; font-size: 14px; }
.key .zh { color: var(--muted); font-size: 12px; margin-top: 2px; }

.grp-title {
  font-size: 13px; font-weight: 700; color: var(--amber); margin: 10px 0 6px;
}
.word {
  display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: start;
  padding: 12px 0; border-bottom: 1px solid #eef2f0;
}
.word:last-child { border-bottom: none; }
.word .w { font-weight: 700; }
.word .ipa { color: var(--muted); font-size: 12px; margin-left: 6px; font-family: "Lucida Grande", Arial, sans-serif; }
.word .zh { color: var(--muted); font-size: 12px; margin-top: 2px; }
.word.known { opacity: 0.72; }
.word.known .w { color: var(--ok); }
.word.passed { background: linear-gradient(90deg, #f0fdf4, transparent); border-radius: 10px; padding-left: 6px; padding-right: 6px; }
.vowel {
  color: #c2410c; font-weight: 800; background: #ffedd5;
  border-radius: 3px; padding: 0 1px;
}
.vhint { color: #c2410c; font-weight: 600; }
.pass-tag {
  display: inline-block; margin-left: 6px; font-size: 11px; font-weight: 700;
  color: var(--ok); background: #dcfce7; border-radius: 999px; padding: 1px 7px;
}
.say-fb { font-size: 12px; margin-top: 6px; min-height: 0; line-height: 1.4; }
.say-fb.ok { color: var(--ok); font-weight: 600; }
.say-fb.bad { color: var(--rose); font-weight: 600; }
.say-fb.listening { color: #1d4ed8; font-weight: 600; }

.btns { display: flex; gap: 6px; }
.btns.col { flex-direction: column; align-items: flex-end; }
.btns .row { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.btn {
  border: none; border-radius: 999px; padding: 7px 10px; font-size: 12px; font-weight: 700;
}
.btn.ok { background: #dcfce7; color: var(--ok); }
.btn.bad { background: var(--rose-soft); color: var(--rose); }
.btn.listen { background: #e0f2fe; color: #0369a1; }
.btn.say { background: #ede9fe; color: #6d28d9; }
.btn.rec { background: #ffe4e6; color: #be123c; }
.btn.rec.hot { background: #be123c; color: #fff; animation: pulse 1s infinite; }
.btn.play { background: #ffedd5; color: #c2410c; }
.btn.play:disabled { opacity: 0.4; }
.btn.cmp { background: #ecfdf5; color: #047857; }
.btn.primary {
  background: var(--teal); color: #fff; width: 100%;
  padding: 12px 16px; font-size: 15px; margin-top: 8px;
}
.btn.secondary {
  background: #e2e8f0; color: #334155; width: 100%;
  padding: 12px 16px; font-size: 15px; margin-top: 8px;
}
.btn.tiny { padding: 6px 10px; }
@keyframes pulse { 50% { opacity: 0.7; } }

.cap {
  font-size: 12px; line-height: 1.45; border-radius: 12px; padding: 10px 12px; margin-bottom: 10px;
}
.cap.ok { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.cap.warn { background: #fff7ed; color: #9a3412; border: 1px solid #fdba74; }

.wrong-actions { text-align: right; margin: -4px 0 10px; padding-bottom: 8px; border-bottom: 1px dashed var(--line); }

#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: rgba(15, 40, 35, 0.92); color: #fff; padding: 10px 16px; border-radius: 999px;
  font-size: 13px; font-weight: 600; z-index: 50; transition: .2s ease; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.key .en { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.g-block { background: #f0fdf4; border-radius: 12px; padding: 10px; margin-bottom: 8px; }
.g-block h4 { margin: 0 0 6px; font-size: 13px; color: var(--ok); }
.g-block ul { margin: 0; padding-left: 18px; font-size: 13px; }
.trap { background: #eff6ff; border-radius: 12px; padding: 10px; margin-top: 6px; }
.trap .lab { font-weight: 700; color: #1d4ed8; font-size: 12px; }

.q-card { margin-bottom: 12px; }
.q-card .q { font-weight: 600; font-size: 14px; margin-bottom: 8px; }
.q-card input {
  width: 100%; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font-size: 15px; background: #fff;
}
.q-card .feedback {
  margin-top: 6px; font-size: 12px; font-weight: 600; min-height: 1.2em;
}
.q-card .feedback.ok { color: var(--ok); }
.q-card .feedback.bad { color: var(--rose); }

.empty {
  text-align: center; color: var(--muted); padding: 40px 16px;
  background: var(--card); border-radius: var(--radius); border: 1px dashed var(--line);
}
.wrong-item {
  display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: start;
  padding: 12px 0; border-bottom: 1px solid #eef2f0;
}
.wrong-item:last-child { border-bottom: none; }
.tag {
  display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: var(--amber-soft); color: var(--amber); margin-bottom: 4px; font-weight: 600;
}
.tag.q { background: #ede9fe; color: #6d28d9; }

.footer-note { font-size: 11px; color: var(--muted); margin-top: 16px; line-height: 1.5; }

.gate[hidden], #app[hidden] { display: none !important; }
.gate {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px;
  background: var(--bg, #f4f7fb);
}
.gate-card {
  width: min(360px, 100%); background: #fff; border: 1px solid var(--line, #d5dee8);
  border-radius: 18px; padding: 22px 18px; box-shadow: 0 10px 30px rgba(0,0,0,.06);
  text-align: center;
}
.gate-card h1 { margin: 0 0 8px; font-size: 20px; color: var(--blue, var(--teal, #0f766e)); }
.gate-hint { margin: 0 0 16px; font-size: 13px; color: var(--muted, #5b6b7c); }
.gate-card input {
  width: 100%; border: 1px solid var(--line, #d5dee8); border-radius: 12px;
  padding: 12px; font-size: 18px; letter-spacing: 0.2em; text-align: center; margin-bottom: 10px;
}
.gate-card button {
  width: 100%; border: none; border-radius: 999px; padding: 12px;
  background: var(--blue2, var(--teal, #0f766e)); color: #fff; font-size: 15px; font-weight: 700;
}
.gate-err { min-height: 1.2em; color: #be123c; font-size: 13px; font-weight: 600; margin: 8px 0 0; }
