:root {
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --accent: #f59e0b;
  --good: #22c55e;
  --warn: #f97316;
  --bad: #ef4444;
  --bg: #f3f6fb;
  --card: #ffffff;
  --ink: #1f2937;
  --ink-2: #6b7280;
  --ink-3: #9ca3af;
  --line: #e5e7eb;
  --radius: 16px;
  --shadow: 0 2px 12px rgba(31, 41, 55, .06);
  --tab-h: 58px;
  safe-area-inset-bottom: env(safe-area-inset-bottom);
}

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

html,
body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  overflow: hidden;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg);
}

/* ---------- 顶部栏 ---------- */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 10px;
  background: linear-gradient(135deg, var(--primary), #60a5fa);
  color: #fff;
  flex: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo {
  font-size: 22px;
}

.brand-name {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 1px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, .18);
  padding: 5px 12px 5px 6px;
  border-radius: 999px;
  font-size: 13px;
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex: none;
}

.user-nick {
  max-width: 96px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- 页面 ---------- */
.page {
  flex: 1;
  display: none;
  overflow: hidden;
  flex-direction: column;
}

.page.active {
  display: flex;
}

.page-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 14px calc(var(--tab-h) + env(safe-area-inset-bottom) + 18px);
}

/* 非主 tab 页（单元详情、练习）隐藏底部 tab */
body.no-tab #tabbar {
  display: none;
}

body.no-tab .page-scroll {
  padding-bottom: 24px;
}

/* ---------- 首页 hero ---------- */
.hero {
  background: linear-gradient(135deg, var(--primary), #60a5fa);
  border-radius: 20px;
  padding: 18px 18px 14px;
  color: #fff;
  box-shadow: 0 6px 18px rgba(59, 130, 246, .3);
}

.hero-title {
  font-size: 20px;
  font-weight: 700;
}

.hero-sub {
  font-size: 13px;
  opacity: .9;
  margin-top: 4px;
}

.series-tabs {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.series-tabs .chip {
  flex: 1;
  text-align: center;
  padding: 7px 4px;
  border-radius: 10px;
  background: rgba(255, 255, 255, .18);
  font-size: 13px;
  color: #fff;
  border: none;
}

.series-tabs .chip.active {
  background: #fff;
  color: var(--primary-dark);
  font-weight: 700;
}

.copyright-note {
  margin-top: 18px;
  font-size: 12px;
  color: var(--ink-3);
  line-height: 1.7;
  background: #fff;
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

/* ---------- 单元卡片 ---------- */
.unit-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 14px;
}

.unit-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  text-align: left;
  border: none;
  font: inherit;
}

.unit-num {
  width: 46px;
  height: 46px;
  flex: none;
  border-radius: 14px;
  background: linear-gradient(135deg, #dbeafe, #bfdbfe);
  color: var(--primary-dark);
  font-weight: 800;
  font-size: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.unit-info {
  flex: 1;
  min-width: 0;
}

.unit-name {
  font-size: 16px;
  font-weight: 700;
}

.unit-topic {
  font-size: 12px;
  color: var(--ink-2);
  margin-top: 2px;
}

.unit-progress {
  font-size: 12px;
  color: var(--ink-3);
  margin-top: 4px;
}

.unit-progress b {
  color: var(--primary);
}

.unit-arrow {
  color: var(--ink-3);
  font-size: 18px;
  flex: none;
}

/* ---------- 子页面头 ---------- */
.sub-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.sub-title {
  font-size: 18px;
  font-weight: 700;
}

.icon-btn {
  background: #fff;
  border: none;
  border-radius: 10px;
  padding: 7px 12px;
  font-size: 15px;
  color: var(--primary-dark);
  box-shadow: var(--shadow);
  font: inherit;
}

/* ---------- 句子卡片 ---------- */
.sentence-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sentence-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}

.sentence-en {
  font-size: 17px;
  font-weight: 600;
  line-height: 1.5;
}

.sentence-zh {
  font-size: 13px;
  color: var(--ink-2);
  margin-top: 5px;
}

.sentence-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.badge-score {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  font-weight: 700;
}

.badge-score.high {
  background: #dcfce7;
  color: #16a34a;
}

.badge-score.mid {
  background: #fef3c7;
  color: #d97706;
}

.badge-score.low {
  background: #fee2e2;
  color: #dc2626;
}

.badge-done {
  font-size: 12px;
  color: var(--ink-3);
}

.mini-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.mini-btn {
  border: none;
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 700;
  font: inherit;
}

.mini-btn.listen {
  background: #eff6ff;
  color: var(--primary-dark);
}

.mini-btn.read {
  background: var(--primary);
  color: #fff;
}

/* ---------- 跟读练习 ---------- */
.practice-card {
  background: var(--card);
  border-radius: 20px;
  padding: 22px 18px;
  box-shadow: var(--shadow);
}

.sentence-en.karaoke {
  font-size: 22px;
  line-height: 1.6;
  margin-bottom: 6px;
}

.sentence-en .kw {
  transition: background .15s;
  border-radius: 6px;
  padding: 0 2px;
}

.sentence-en .kw.now {
  background: #bfdbfe;
}

.sentence-zh {
  font-size: 14px;
  color: var(--ink-2);
  margin-bottom: 14px;
}

.voice-row {
  margin-bottom: 14px;
}

.voice-tag {
  display: inline-block;
  font-size: 12px;
  color: var(--primary-dark);
  background: #eff6ff;
  padding: 4px 12px;
  border-radius: 999px;
}

.practice-actions {
  display: flex;
  gap: 12px;
  align-items: stretch;
}

.btn {
  border: none;
  border-radius: 14px;
  padding: 13px 16px;
  font-size: 15px;
  font-weight: 700;
  font: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  cursor: pointer;
  transition: transform .08s;
}

.btn:active {
  transform: scale(.96);
}

.btn-ico {
  font-size: 16px;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  flex: 1;
  box-shadow: 0 4px 12px rgba(59, 130, 246, .3);
}

.btn-accent {
  background: var(--accent);
  color: #fff;
}

.btn-ghost {
  background: #f1f5f9;
  color: var(--ink);
}

.btn-wechat {
  background: #07c160;
  color: #fff;
  width: 100%;
  margin-top: 14px;
  box-shadow: 0 4px 12px rgba(7, 193, 96, .3);
}

.btn-link {
  background: none;
  color: var(--ink-2);
  text-decoration: underline;
  width: 100%;
  margin-top: 6px;
  font-weight: 400;
}

.btn-sm {
  padding: 9px 12px;
  font-size: 13px;
  border-radius: 10px;
}

.btn-danger {
  color: var(--bad);
}

.btn.hidden {
  display: none;
}

.btn-mic.recording {
  background: var(--bad);
  animation: mic-pulse 1.2s infinite;
}

@keyframes mic-pulse {

  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, .5);
  }

  50% {
    box-shadow: 0 0 0 12px rgba(239, 68, 68, 0);
  }
}

.read-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 18px;
  color: var(--bad);
  font-weight: 700;
}

.pulse-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--bad);
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0% {
    transform: scale(1);
    opacity: 1;
  }

  100% {
    transform: scale(2.2);
    opacity: 0;
  }
}

.hidden {
  display: none !important;
}

/* ---------- 结果卡 ---------- */
.result-card {
  margin-top: 22px;
  padding-top: 20px;
  border-top: 2px dashed var(--line);
  animation: pop .35s ease;
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(12px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

.score-ring-wrap {
  position: relative;
  width: 140px;
  height: 140px;
  margin: 0 auto 18px;
}

.score-ring {
  width: 140px;
  height: 140px;
  transform: rotate(-90deg);
}

.ring-bg {
  fill: none;
  stroke: #e5e7eb;
  stroke-width: 12;
}

.ring-fg {
  fill: none;
  stroke: var(--primary);
  stroke-width: 12;
  stroke-linecap: round;
  stroke-dasharray: 326.7;
  stroke-dashoffset: 326.7;
  transition: stroke-dashoffset .8s ease, stroke .4s;
}

.score-ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.score-num {
  font-size: 40px;
  font-weight: 800;
  line-height: 1;
}

.score-label {
  font-size: 13px;
  color: var(--ink-3);
  margin-top: 2px;
}

.dim-bars {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
}

.dim-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.dim-name {
  font-size: 13px;
  color: var(--ink-2);
  width: 52px;
  flex: none;
}

.dim-bar {
  flex: 1;
  height: 10px;
  background: #eef2f7;
  border-radius: 999px;
  overflow: hidden;
}

.dim-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--primary);
  transition: width .8s ease;
}

.dim-val {
  font-size: 13px;
  font-weight: 700;
  width: 38px;
  text-align: right;
  flex: none;
}

.word-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 16px;
}

.wchip {
  font-size: 14px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
}

.wchip.ok {
  background: #dcfce7;
  color: #16a34a;
}

.wchip.near {
  background: #fef3c7;
  color: #d97706;
}

.wchip.wrong {
  background: #fee2e2;
  color: #dc2626;
  text-decoration: line-through;
}

.wchip.miss {
  background: #f1f5f9;
  color: var(--ink-3);
  text-decoration: underline;
}

.wchip.extra {
  background: #ede9fe;
  color: #7c3aed;
}

.feedback {
  background: #fffbeb;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.8;
  color: #78350f;
  margin-bottom: 16px;
}

.feedback b {
  color: #b45309;
}

.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* ---------- 学情 ---------- */
.stat-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  text-align: center;
}

.stat-num {
  font-size: 26px;
  font-weight: 800;
  color: var(--primary-dark);
}

.stat-name {
  font-size: 12px;
  color: var(--ink-2);
  margin-top: 2px;
}

.panel {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.panel-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 12px;
}

.trend-chart svg {
  width: 100%;
  height: auto;
  display: block;
}

.error-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 9px;
}

.error-ipa {
  font-size: 15px;
  font-weight: 700;
  color: var(--bad);
  width: 64px;
  flex: none;
}

.error-bar {
  flex: 1;
  height: 12px;
  background: #fee2e2;
  border-radius: 999px;
  overflow: hidden;
}

.error-fill {
  height: 100%;
  background: var(--bad);
  border-radius: 999px;
}

.error-cnt {
  font-size: 12px;
  color: var(--ink-2);
  width: 24px;
  text-align: right;
  flex: none;
}

.empty-tip {
  font-size: 13px;
  color: var(--ink-3);
  text-align: center;
  padding: 18px 0;
}

.history-item {
  border-top: 1px solid var(--line);
  padding: 12px 0;
}

.history-item:first-child {
  border-top: none;
  padding-top: 0;
}

.history-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-text {
  font-size: 13px;
  font-weight: 600;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-score {
  font-size: 13px;
  font-weight: 800;
  flex: none;
}

.history-time {
  font-size: 11px;
  color: var(--ink-3);
  margin-top: 3px;
}

.history-acts {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

/* ---------- 我的 ---------- */
.profile-card {
  background: linear-gradient(135deg, var(--primary), #60a5fa);
  border-radius: 20px;
  padding: 20px;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
  box-shadow: 0 6px 18px rgba(59, 130, 246, .3);
}

.profile-card .avatar {
  width: 54px;
  height: 54px;
  font-size: 30px;
}

.profile-name {
  font-size: 18px;
  font-weight: 700;
}

.profile-sub {
  font-size: 12px;
  opacity: .9;
  margin-top: 3px;
}

.profile-login {
  margin-left: auto;
  background: #fff;
  color: var(--primary-dark);
  border: none;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 700;
}

.voice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.voice-card {
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 12px 10px;
  text-align: center;
  background: #fff;
  font: inherit;
}

.voice-card.active {
  border-color: var(--primary);
  background: #eff6ff;
}

.voice-emoji {
  font-size: 24px;
}

.voice-name {
  font-size: 13px;
  font-weight: 700;
  margin-top: 4px;
}

.voice-sub {
  font-size: 11px;
  color: var(--ink-3);
  margin-top: 2px;
}

.speed-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}

.speed-row input[type=range] {
  flex: 1;
  accent-color: var(--primary);
}

.hint {
  font-size: 12px;
  color: var(--ink-3);
  margin-top: 10px;
  line-height: 1.6;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
  font-size: 14px;
}

.setting-row:first-of-type {
  border-top: none;
  padding-top: 0;
}

.setting-row select {
  font: inherit;
  font-size: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 10px;
  background: #fff;
}

.about p {
  font-size: 13px;
  color: var(--ink-2);
  margin-top: 5px;
  line-height: 1.7;
}

/* ---------- 底部 Tab ---------- */
#tabbar {
  height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  flex: none;
  display: flex;
  background: #fff;
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}

.tab {
  flex: 1;
  border: none;
  background: none;
  font: inherit;
  font-size: 11px;
  color: var(--ink-3);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
}

.tab .btn-ico {
  font-size: 20px;
}

.tab.active {
  color: var(--primary);
  font-weight: 700;
}

/* ---------- 弹窗 / Toast ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .5);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal-card {
  background: #fff;
  width: 100%;
  max-width: 480px;
  border-radius: 22px 22px 0 0;
  padding: 26px 22px calc(22px + env(safe-area-inset-bottom));
  animation: sheet-up .3s ease;
}

@keyframes sheet-up {
  from {
    transform: translateY(40px);
    opacity: 0;
  }

  to {
    transform: none;
    opacity: 1;
  }
}

.modal-title {
  font-size: 19px;
  font-weight: 800;
  text-align: center;
}

.modal-desc {
  font-size: 13px;
  color: var(--ink-2);
  text-align: center;
  margin-top: 6px;
  line-height: 1.6;
}

.login-hint {
  font-size: 11px;
  color: var(--ink-3);
  text-align: center;
  margin-top: 12px;
  line-height: 1.6;
}

.toast {
  position: fixed;
  bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 24px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, .88);
  color: #fff;
  font-size: 13px;
  padding: 10px 18px;
  border-radius: 999px;
  z-index: 200;
  max-width: 86%;
  text-align: center;
  line-height: 1.5;
}
