:root {
  --ink: #12151c;
  --muted: #6b7280;
  --faint: #9ca3af;
  --line: #e8e8e4;
  --bg: #f6f6f4;
  --card: #ffffff;
  --primary: #3b5bff;
  --primary-soft: #e9edff;
  --flame: #ff6b35;
  --flame-soft: #ffeee7;
  --good: #12a594;
  --good-soft: #e3f6f2;
  --bad: #e5484d;
  --bad-soft: #fdeaea;
  --amber: #f59e0b;
  --r: 14px;
  --shadow: 0 1px 2px rgba(18, 21, 28, 0.04), 0 8px 24px rgba(18, 21, 28, 0.05);
}

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

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

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
.hidden { display: none !important; }

#app { max-width: 520px; margin: 0 auto; min-height: 100%; position: relative; }

.screen { min-height: 100vh; }
#main-screen { display: flex; flex-direction: column; padding-bottom: 74px; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(246, 246, 244, 0.92);
  backdrop-filter: blur(10px);
  padding: 14px 18px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.topbar h1 { font-size: 17px; font-weight: 600; margin: 0; letter-spacing: -0.2px; }
.streak-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--flame-soft);
  color: #c2410c;
  border-radius: 999px;
  padding: 5px 12px 5px 9px;
  font-size: 13px;
  font-weight: 600;
}
.streak-pill i {
  width: 9px; height: 13px; border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  background: var(--flame); display: block;
}
.streak-pill.zero { background: #f1f1ee; color: var(--muted); }
.streak-pill.zero i { background: var(--faint); }

/* ---------- 通用 ---------- */
.view { padding: 4px 18px 20px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 16px;
  margin-bottom: 12px;
}
.card.tight { padding: 13px 14px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.center { text-align: center; }
h2.sec { font-size: 14px; font-weight: 600; margin: 20px 4px 10px; color: var(--muted); }
h3.sec { font-size: 15px; font-weight: 600; margin: 0 0 10px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 12px;
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 600;
  background: #eee;
  color: var(--ink);
  transition: transform 0.06s ease, opacity 0.15s;
  width: 100%;
}
.btn:active { transform: scale(0.985); }
.btn[disabled] { opacity: 0.45; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-flame { background: var(--flame); color: #fff; }
.btn-ghost { background: #fff; border: 1px solid var(--line); }
.btn-sm { padding: 8px 13px; font-size: 13.5px; width: auto; border-radius: 10px; }

.input {
  width: 100%;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 12px 13px;
  font-size: 15px;
  outline: none;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.input::placeholder { color: var(--faint); }
textarea.input { resize: vertical; min-height: 108px; line-height: 1.5; }
.field { margin-bottom: 10px; }
label.lab { display: block; font-size: 12.5px; color: var(--muted); margin: 0 0 6px 3px; }

.seg {
  display: flex; gap: 4px; background: #ececeA; padding: 4px; border-radius: 12px; margin-bottom: 16px;
}
.seg button {
  flex: 1; padding: 9px 6px; border-radius: 9px; font-size: 13.5px; font-weight: 600; color: var(--muted);
}
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,0.07); }

.bar { height: 8px; border-radius: 999px; background: #ececeA; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--primary); border-radius: 999px; transition: width 0.35s; }
.bar.thin { height: 6px; }
.bar i.good { background: var(--good); }
.bar i.flame { background: var(--flame); }

/* ---------- 登录 ---------- */
#auth-screen { display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-wrap { width: 100%; max-width: 380px; }
.brand { text-align: center; margin-bottom: 22px; }
.brand .mark {
  width: 54px; height: 54px; border-radius: 16px; background: var(--primary);
  display: inline-flex; align-items: center; justify-content: center; color: #fff;
  font-size: 24px; font-weight: 700; letter-spacing: -1px; margin-bottom: 12px;
}
.brand h1 { font-size: 21px; margin: 0 0 6px; letter-spacing: -0.3px; }
.brand p { margin: 0; color: var(--muted); font-size: 13.5px; }
.err { color: var(--bad); font-size: 13px; margin: 2px 0 10px; min-height: 18px; }
.link { color: var(--primary); font-size: 13px; font-weight: 600; }
.code-row { display: flex; gap: 8px; }
.code-row .input { flex: 1; }
.code-row .btn { width: auto; flex: 0 0 118px; }
.pwd-row { display: flex; gap: 8px; }
.pwd-row .input { flex: 1; }
.pwd-row .btn { width: auto; flex: 0 0 64px; padding-left: 0; padding-right: 0; }

/* ---------- 首页 ---------- */
.hero {
  background: linear-gradient(0deg, #fff, #fff);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  margin-bottom: 12px;
}
.hero .big { font-size: 26px; font-weight: 700; letter-spacing: -0.5px; }
.rings { display: flex; gap: 18px; margin: 14px 0 16px; }
.ring { flex: 1; }
.ring .cap { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.ring .cap b { color: var(--ink); font-weight: 600; }

.statgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.statgrid .cell { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px 10px; text-align: center; }
.statgrid .cell b { display: block; font-size: 19px; font-weight: 700; letter-spacing: -0.3px; }
.statgrid .cell span { font-size: 11.5px; color: var(--muted); }

/* ---------- 计时器 ---------- */
.timer { display: flex; align-items: center; gap: 14px; }
.timer .time { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.5px; }
.timer.running .time { color: var(--flame); }
.dot-run { width: 8px; height: 8px; border-radius: 50%; background: var(--flame); animation: pulse 1.6s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

/* ---------- 词书 ---------- */
.book { display: flex; align-items: center; gap: 12px; }
.book .glyph {
  width: 40px; height: 48px; border-radius: 7px; background: var(--primary-soft); color: var(--primary);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; flex: 0 0 auto;
}
.book .glyph.g2 { background: #fff3e6; color: #c2410c; }
.book .glyph.g3 { background: var(--good-soft); color: #0f766e; }
.book .glyph.g4 { background: #f3e9ff; color: #6d28d9; }
.book.on { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: #f1f1ee; color: var(--muted); }
.tag.on { background: var(--primary-soft); color: var(--primary); }

/* ---------- 日历 ---------- */
.cal-head { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 6px; }
.cal-head span { text-align: center; font-size: 11.5px; color: var(--faint); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-cell {
  aspect-ratio: 1 / 1; border-radius: 10px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; font-size: 12.5px; color: var(--muted); background: #f4f4f1;
}
.cal-cell.done { background: var(--primary); color: #fff; font-weight: 600; }
.cal-cell.partial { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.cal-cell.today { outline: 2px solid var(--ink); outline-offset: -2px; }
.cal-cell.empty { background: transparent; }
.cal-cell.future { color: #cfcfca; background: transparent; }

.badges { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.badge { text-align: center; padding: 12px 6px; border-radius: 12px; background: #f6f6f4; border: 1px solid var(--line); }
.badge.got { background: #fff; border-color: var(--amber); }
.badge .dot {
  width: 26px; height: 26px; border-radius: 50%; background: #e2e2de; margin: 0 auto 7px;
}
.badge.got .dot { background: var(--amber); }
.badge b { display: block; font-size: 12.5px; }
.badge span { font-size: 11px; color: var(--muted); }

/* ---------- 报告 ---------- */
.bars { display: flex; align-items: flex-end; gap: 5px; height: 96px; margin-top: 6px; }
.bars .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; height: 100%; }
.bars .col i { display: block; border-radius: 3px; }
.bars .col i.n { background: var(--primary); }
.bars .col i.r { background: #b9c6ff; }
.bars .xaxis { display: flex; gap: 5px; margin-top: 6px; }
.bars .xaxis span { flex: 1; text-align: center; font-size: 10px; color: var(--faint); }

.dist-row { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; font-size: 12px; }
.dist-row .nm { width: 62px; color: var(--muted); }
.dist-row .bx { flex: 1; height: 14px; background: #f2f2ef; border-radius: 4px; overflow: hidden; }
.dist-row .bx i { display: block; height: 100%; background: var(--good); border-radius: 4px; }
.dist-row .vl { width: 34px; text-align: right; font-variant-numeric: tabular-nums; }

.wlist { max-height: 320px; overflow: auto; }
.witem { padding: 10px 0; border-bottom: 1px solid var(--line); }
.witem:last-child { border-bottom: none; }
.witem .w { font-weight: 600; }
.witem .ipa { color: var(--muted); font-size: 12.5px; font-family: ui-monospace, monospace; }

/* ---------- 底部导航 ---------- */
.tabbar {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: 0; width: 100%; max-width: 520px;
  background: rgba(255,255,255,0.94);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  display: flex; z-index: 30;
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1; padding: 9px 2px 11px; display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--faint); font-size: 11px;
}
.tabbar button .ic { width: 20px; height: 20px; border-radius: 6px; background: #dedeD9; }
.tabbar button.on { color: var(--primary); }
.tabbar button.on .ic { background: var(--primary); }

/* ---------- 学习运行器 ---------- */
#runner {
  position: fixed; inset: 0; background: var(--bg); z-index: 60;
  display: flex; flex-direction: column; max-width: 520px; margin: 0 auto;
}
.run-head { padding: 14px 18px 8px; display: flex; align-items: center; gap: 12px; }
.run-head .close { font-size: 22px; line-height: 1; color: var(--faint); padding: 0 4px; }
.run-body { flex: 1; overflow: auto; padding: 8px 18px 18px; }
.q-type { font-size: 12px; font-weight: 600; color: var(--primary); letter-spacing: 0.4px; }
.q-prompt { font-size: 27px; font-weight: 700; letter-spacing: -0.6px; margin: 10px 0 4px; word-break: break-word; }
.q-prompt.sentence { font-size: 19px; font-weight: 600; line-height: 1.5; }
.q-hint { color: var(--muted); font-size: 13px; }
.q-sub { color: var(--muted); font-size: 13.5px; margin-top: 8px; }
.q-def { font-size: 16px; line-height: 1.6; margin: 8px 0 2px; }
.speak-btn {
  display: inline-flex; align-items: center; gap: 7px; background: #fff; border: 1px solid var(--line);
  border-radius: 999px; padding: 8px 15px; font-size: 13.5px; font-weight: 600; margin-top: 12px;
}
.speak-btn i { width: 14px; height: 14px; border-radius: 50%; background: var(--primary); display: block; }

.opts { margin-top: 18px; display: flex; flex-direction: column; gap: 9px; }
.opt {
  text-align: left; background: #fff; border: 1.5px solid var(--line); border-radius: 13px;
  padding: 14px 15px; font-size: 15.5px; font-weight: 500; display: flex; align-items: center; gap: 10px;
}
.opt .idx { width: 20px; height: 20px; border-radius: 6px; background: #f1f1ee; color: var(--muted);
  font-size: 11px; display: flex; align-items: center; justify-content: center; font-weight: 700; flex: 0 0 auto; }
.opt.ok { border-color: var(--good); background: var(--good-soft); }
.opt.no { border-color: var(--bad); background: var(--bad-soft); }
.opt[disabled] { opacity: 1; }

.feedback { margin-top: 16px; border-radius: 13px; padding: 14px; border: 1px solid var(--line); background: #fff; }
.feedback.ok { border-color: var(--good); background: var(--good-soft); }
.feedback.no { border-color: var(--bad); background: var(--bad-soft); }
.feedback .ttl { font-weight: 700; font-size: 15px; margin-bottom: 8px; }
.feedback .w { font-size: 20px; font-weight: 700; }
.feedback .ipa { font-family: ui-monospace, monospace; color: var(--muted); font-size: 13.5px; }
.feedback .def { margin-top: 8px; font-size: 14px; }
.feedback .ex { margin-top: 6px; font-size: 13.5px; color: #3f4652; }

.run-foot { padding: 12px 18px calc(14px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line); }

/* ---------- 浮层 ---------- */
#toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%) translateY(12px);
  background: rgba(18,21,28,0.92); color: #fff; padding: 10px 16px; border-radius: 11px;
  font-size: 13.5px; max-width: 84%; text-align: center; opacity: 0; pointer-events: none;
  transition: opacity 0.2s, transform 0.2s; z-index: 90;
}
#toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }

#sheet-mask { position: fixed; inset: 0; background: rgba(18,21,28,0.42); z-index: 70; display: flex; align-items: flex-end; justify-content: center; }
#sheet { background: #fff; width: 100%; max-width: 520px; border-radius: 20px 20px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); max-height: 86vh; overflow: auto; }
#sheet .sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
#sheet .sheet-head b { font-size: 16px; }

.empty { text-align: center; color: var(--faint); font-size: 13.5px; padding: 26px 10px; }
.loading { text-align: center; padding: 46px 0; color: var(--muted); font-size: 14px; }
.spin { width: 22px; height: 22px; border: 2.5px solid var(--line); border-top-color: var(--primary); border-radius: 50%; margin: 0 auto 12px; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 521px) {
  body { background: #efefec; }
  #app { background: var(--bg); box-shadow: 0 0 0 1px var(--line); min-height: 100vh; }
}

/* ---------- 跑在循词 App 壳里的微调 ---------- */
html.in-app body { overscroll-behavior-y: none; }
html.in-app button { -webkit-user-select: none; user-select: none; }
