:root {
  --primary: #2563eb;
  --primary-soft: #eff6ff;
  --sky: #38bdf8;
  --sky-soft: #e0f2fe;
  --mint: #34d399;
  --mint-soft: #ecfdf5;
  --amber: #f59e0b;
  --amber-soft: #fef3c7;
  --coral: #ff4da6;
  --coral-soft: #ffe4f1;
  --ink: #0e2639;
  --ink-soft: #64748b;
  --line: #e2e8f0;
  --paper: #ffffff;
  --shadow: 0 10px 30px rgba(14, 38, 57, 0.08);
  --radius: 8px;
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: "PingFang SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(900px 520px at 100% -10%, #dbeafe 0%, transparent 55%),
    radial-gradient(760px 520px at -12% 8%, #ffe4f1 0%, transparent 52%),
    radial-gradient(680px 480px at 55% 115%, #e0f2fe 0%, transparent 55%),
    linear-gradient(180deg, #f5f7ff 0%, #f8fafc 100%);
  background-attachment: fixed;
  font-size: 16px;
  letter-spacing: 0;
}

button {
  font-family: inherit;
  border: 0;
  cursor: pointer;
  color: inherit;
}

button:focus-visible { outline: 3px solid var(--sky); outline-offset: 2px; }

#app {
  max-width: 760px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 17px;
}

.brand-star { color: var(--amber); font-size: 20px; }

/* 页头"当前使用者"小胶囊（点一下切换使用者） */
.ffp-user-slot { flex: none; display: inline-flex; align-items: center; }
.ffp-user-slot button:hover { background: var(--line); }
.brand-text { letter-spacing: 0; }

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--sky-soft);
  color: var(--sky);
  font-size: 24px;
  line-height: 1;
  display: grid;
  place-items: center;
  transition: transform 0.08s ease, background 0.2s ease;
}

.icon-btn:active { transform: scale(0.9); }

.view {
  flex: 1;
  padding: 16px 14px 96px;
}

.tabbar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: 760px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 20;
}

.tab {
  background: transparent;
  padding: 9px 4px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--ink-soft);
  font-size: 12px;
  transition: transform 0.08s ease, color 0.2s ease;
}

.tab:active { transform: scale(0.94); }
.tab.active { color: var(--primary); font-weight: 700; }
.tab-ico { font-size: 22px; line-height: 1; }

/* 第四个入口：跳到同一域名下的「英语语法练习」独立模块 */
.tab-link {
  background: transparent;
  padding: 9px 4px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--ink-soft);
  font-size: 12px;
  text-decoration: none;
  transition: transform 0.08s ease, color 0.2s ease;
}

.tab-link:active { transform: scale(0.94); }
.tab-link:hover,
.tab-link:focus-visible { color: var(--primary); }
.tab-link .tab-ico { color: var(--primary); }

.card {
  background: var(--paper);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  padding: 14px;
  margin-bottom: 12px;
}

.hero-card {
  background:
    linear-gradient(135deg, rgba(255,201,74,0.18), rgba(143,217,194,0.16)),
    var(--paper);
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  text-align: center;
  margin-top: 12px;
}

.stat {
  background: #fff;
  border-radius: var(--radius);
  padding: 10px 6px;
  border: 1px solid var(--line);
}

.stat b { display: block; font-size: 20px; color: var(--ink); }
.stat span { font-size: 12px; color: var(--ink-soft); }
.stat.amber b { color: #e5a50a; }

.section-title {
  font-size: 15px;
  font-weight: 800;
  margin: 4px 2px 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.course-entry {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  text-align: left;
  padding: 18px 16px;
  margin-bottom: 12px;
  border-radius: var(--radius);
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  transition: transform 0.08s ease, box-shadow 0.2s ease;
}

.course-entry:active { transform: scale(0.98); box-shadow: var(--shadow); }
.course-re1 { border-left: 4px solid var(--coral); }
.course-nce2 { border-left: 4px solid var(--primary); }
/* 用 <a> 做卡片时要去掉链接默认样式，保证和上面两个按钮长得一样 */
a.course-entry { text-decoration: none; color: inherit; }
.course-speaking { border-left: 4px solid var(--mint); }
.course-grammar { border-left: 4px solid var(--amber); }
.course-ico {
  flex: none;
  width: 54px;
  height: 54px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-size: 28px;
}
.course-re1 .course-ico { background: var(--coral-soft); }
.course-nce2 .course-ico { background: var(--primary-soft); }
.course-speaking .course-ico { background: var(--mint-soft); }
.course-grammar .course-ico { background: var(--amber-soft); }
.course-body { flex: 1; min-width: 0; }
.course-name { display: block; font-weight: 800; font-size: 17px; color: var(--ink); }
.course-desc { display: block; font-size: 13px; color: var(--ink-soft); margin-top: 3px; }
.course-arrow { flex: none; font-size: 20px; color: var(--ink-soft); }

.lesson-list { display: grid; gap: 10px; }

.lesson-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: 0 3px 10px rgba(53, 66, 91, 0.06);
  text-align: left;
  transition: transform 0.08s ease, box-shadow 0.2s ease;
}

.lesson-item:active { transform: scale(0.98); box-shadow: var(--shadow); }

.lesson-num {
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 800;
  color: #fff;
  background: var(--primary);
}

.lesson-info { flex: 1; min-width: 0; }
.lesson-title { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lesson-sub { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }

.progress-bar {
  height: 6px;
  border-radius: 99px;
  background: #edf1f6;
  overflow: hidden;
  margin-top: 7px;
}

.progress-fill {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--mint), var(--amber));
  width: 0;
}

.lesson-badge {
  flex: none;
  font-size: 12px;
  padding: 4px 7px;
  border-radius: 999px;
  background: var(--amber-soft);
  color: #b77d00;
  font-weight: 700;
}

.module-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.module-tab {
  padding: 9px 4px;
  border-radius: var(--radius);
  background: #fff;
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: transform 0.08s ease, background 0.2s ease;
}

.module-tab:active { transform: scale(0.95); }
.module-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.module-tab.done::after { content: " ✓"; color: var(--mint); }
.module-tab.active.done::after { color: #fff; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.pill-sky { background: var(--primary-soft); color: var(--primary); }
.pill-mint { background: var(--mint-soft); color: #059669; }
.pill-amber { background: var(--amber-soft); color: #b45309; }
.pill-coral { background: var(--coral-soft); color: #db2777; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-weight: 800;
  font-size: 15px;
  transition: transform 0.08s ease, filter 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.06);
}

.btn:active { transform: scale(0.94); filter: brightness(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-mint { background: var(--mint); color: #064e3b; }
.btn-amber { background: var(--amber); color: #7c2d12; }
.btn-coral { background: var(--coral); color: #fff; }
.btn-ghost { background: #fff; color: var(--ink); border: 1px solid var(--line); box-shadow: none; }

.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 7px 12px; font-size: 13px; }

.reading-line {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 11px 10px;
  border-radius: var(--radius);
  border: 1px solid transparent;
}

.reading-line:nth-child(odd) { background: #fbfdff; }
.reading-line.active { background: var(--sky-soft); border-color: #c7e4fb; }

.reading-play {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--mint-soft);
  color: var(--mint);
  display: grid;
  place-items: center;
  font-size: 16px;
  transition: transform 0.08s ease;
}

.reading-play:active { transform: scale(0.88); }
.reading-en { font-size: 16px; line-height: 1.5; word-break: break-word; }
.reading-zh { font-size: 14px; line-height: 1.55; color: var(--ink-soft); margin-top: 4px; word-break: break-word; }

.re1-sentence-card { text-align: center; }
.re1-sentence {
  font-size: 22px;
  line-height: 1.55;
  font-weight: 700;
  padding: 20px 16px;
  background: var(--primary-soft);
  border: 1px solid #dbeafe;
  border-radius: var(--radius);
  color: var(--ink);
  word-break: break-word;
}

.re1-sentence-hidden {
  color: var(--ink-soft);
  font-style: italic;
  background: var(--amber-soft);
  border-color: var(--amber);
}

.hold-btn {
  position: fixed;
  left: 50%;
  bottom: calc(74px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background: var(--coral);
  color: #fff;
  font-weight: 800;
  font-size: 16px;
  z-index: 32;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  box-shadow: 0 10px 26px rgba(255, 77, 166, 0.38);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.08s ease;
}

.hold-btn.recording {
  transform: translateX(-50%) scale(0.9);
  animation: holdPulse 1s ease-in-out infinite;
}

.hold-label { font-size: 15px; }
.hold-caption {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.85);
  max-width: 132px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

@keyframes holdPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 77, 166, 0.45); }
  50% { box-shadow: 0 0 0 16px rgba(255, 77, 166, 0); }
}

.word-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 4px;
  border-bottom: 1px dashed var(--line);
}

.word-row:last-child { border-bottom: 0; }
.word-main { flex: 1; min-width: 0; }
.word-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.word-en { font-size: 17px; font-weight: 800; }
.word-phon { color: var(--ink-soft); font-size: 13px; }
.word-pos { color: var(--coral); font-size: 12px; font-weight: 700; }
.word-mean { color: var(--ink-soft); font-size: 14px; margin-top: 2px; }
.word-example { font-size: 12px; color: #8a94a8; margin-top: 4px; font-style: italic; }

.choice {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 13px;
  margin: 8px 0;
  border-radius: var(--radius);
  background: #fff;
  border: 1px solid var(--line);
  font-size: 15px;
  transition: transform 0.08s ease, background 0.2s ease, border-color 0.2s ease;
}

.choice:active { transform: scale(0.98); }
.choice.correct { background: var(--mint-soft); border-color: var(--mint); }
.choice.wrong { background: var(--coral-soft); border-color: var(--coral); }

.input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 16px;
  font-family: inherit;
  color: var(--ink);
  background: #fff;
}

.input:focus { outline: 3px solid #c7e4fb; border-color: var(--sky); }

.score-ring {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin: 10px 0;
}

.score {
  text-align: center;
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  padding: 10px 14px;
  min-width: 88px;
}

.score b { display: block; font-size: 28px; line-height: 1; }
.score span { font-size: 12px; color: var(--ink-soft); }
.score.good b { color: #16a34a; }
.score.mid b { color: #d97706; }
.score.low b { color: #e11d48; }

.feedback {
  padding: 12px;
  border-radius: var(--radius);
  background: var(--amber-soft);
  color: #7a5a00;
  font-size: 14px;
  line-height: 1.6;
}

.quiz-progress { font-size: 13px; color: var(--ink-soft); margin: 6px 0 10px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 88px;
  transform: translateX(-50%) translateY(20px);
  background: rgba(53, 66, 91, 0.94);
  color: #fff;
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 60;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  max-width: 86vw;
  text-align: center;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(35, 45, 65, 0.42);
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border-radius: 14px;
  padding: 20px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
  animation: pop 0.22s ease;
}

.modal h3 { margin: 0 0 12px; font-size: 18px; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.modal-actions .btn { flex: 1; }

/* Recording indicator: a compact bottom bar so the sentence stays visible. */
.modal-backdrop.mic {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: transparent;
  padding: 0 16px calc(22px + env(safe-area-inset-bottom));
  pointer-events: none;
}

.modal-backdrop.mic .mic-modal {
  width: 100%;
  max-width: 420px;
  background: rgba(14, 38, 57, 0.92);
  color: #fff;
  border-radius: 16px;
  padding: 14px 18px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.22);
  text-align: center;
  pointer-events: auto;
  animation: pop 0.22s ease;
}

.modal-backdrop.mic h3 { margin: 0 0 6px; font-size: 16px; color: #fff; }
.mic-live { min-height: 22px; font-size: 14px; color: #dbeafe; margin-bottom: 9px; }

/* Recorder modal: level meter + explicit stop button */
.modal-backdrop.recorder .capture-target {
  background: var(--sky-soft);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
}
.rec-meter {
  height: 8px;
  border-radius: 99px;
  background: #e6eef7;
  overflow: hidden;
  margin: 4px 0 2px;
}
.rec-meter span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--mint), var(--coral));
  transition: width 0.08s linear;
}
.mic-pulse {
  width: 56px;
  height: 4px;
  margin: 0 auto;
  border-radius: 99px;
  background: var(--coral);
  animation: micPulse 1s ease-in-out infinite;
}

@keyframes micPulse {
  0%, 100% { opacity: 0.35; transform: scaleX(0.6); }
  50% { opacity: 1; transform: scaleX(1); }
}

@keyframes pop {
  from { transform: scale(0.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.star-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
  overflow: hidden;
}

.falling-star {
  position: absolute;
  top: -8%;
  animation: starFall linear forwards;
  color: var(--amber);
  font-size: 22px;
}

@keyframes starFall {
  to { transform: translateY(115vh) rotate(360deg); opacity: 0.1; }
}

.encourage {
  text-align: center;
  font-size: 18px;
  font-weight: 800;
  line-height: 1.6;
  margin: 8px 0 4px;
}

.empty {
  text-align: center;
  color: var(--ink-soft);
  padding: 40px 20px;
  font-size: 14px;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.cal-head { text-align: center; font-size: 12px; color: var(--ink-soft); padding: 4px 0; }

.cal-day {
  aspect-ratio: 1;
  border-radius: 9px;
  background: #fff;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-soft);
}

.cal-day.checked {
  background: var(--amber);
  border-color: var(--amber);
  color: #7a5400;
}

.cal-day.today { border: 2px solid var(--coral); color: var(--coral); }
.cal-day.empty { background: transparent; border-color: transparent; }

.medal-row { display: flex; gap: 10px; margin-top: 12px; }
.medal {
  flex: 1;
  text-align: center;
  padding: 12px 6px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #fff;
}

.medal .m-ico { font-size: 30px; }
.medal .m-label { font-size: 12px; color: var(--ink-soft); margin-top: 4px; }
.medal.locked { opacity: 0.5; filter: grayscale(0.7); }
.medal.unlocked { border-color: var(--amber); background: var(--amber-soft); }

.hidden { display: none !important; }

@media (min-width: 640px) {
  .module-tabs { grid-template-columns: repeat(6, 1fr); }
  .tabbar { border-radius: 16px 16px 0 0; }
}
