/* ===== RESET ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input { font-family: inherit; border: none; outline: none; }

/* ===== TOKENS ===== */
:root {
  --green:       #00b386;
  --green-dark:  #009970;
  --green-bg:    #e6f9f4;
  --red:         #e53e3e;
  --red-bg:      #fff5f5;
  --yellow:      #d69e2e;
  --yellow-bg:   #fffff0;
  --purple-bg:   #faf5ff;
  --purple:      #7c3aed;
  --blue:        #1a365d;
  --blue-bg:     #ebf8ff;
  --blue-mid:    #3182ce;
  --text:        #1a202c;
  --text-mid:    #4a5568;
  --text-light:  #718096;
  --border:      #e2e8f0;
  --bg:          #f0f4f8;
  --card:        #ffffff;
  --shadow-sm:   0 1px 4px rgba(0,0,0,0.08);
  --shadow:      0 2px 10px rgba(0,0,0,0.1);
  --radius:      14px;
  --radius-sm:   10px;
  --radius-xs:   6px;
}

/* ===== BASE ===== */
body {
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Noto Sans SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: 80px;
}

#app { max-width: 480px; margin: 0 auto; position: relative; }

/* ===== HEADER ===== */
.app-header {
  background: linear-gradient(135deg, #00b386 0%, #007a5e 100%);
  color: white;
  padding: 14px 16px 10px;
  position: sticky;
  top: 0;
  z-index: 200;
  box-shadow: 0 2px 12px rgba(0,179,134,0.35);
}

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

.btn-back {
  color: white;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 8px;
  background: rgba(255,255,255,0.2);
  white-space: nowrap;
  flex-shrink: 0;
}

.header-title-area { flex: 1; min-width: 0; }

.header-title {
  font-size: 1rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-sub {
  font-size: 0.72rem;
  opacity: 0.8;
  margin-top: 1px;
}

.streak-chip {
  background: rgba(255,255,255,0.22);
  border-radius: 20px;
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 700;
  flex-shrink: 0;
}

.lesson-progress-bar {
  height: 4px;
  background: rgba(255,255,255,0.25);
  border-radius: 4px;
  margin-top: 10px;
  overflow: hidden;
}

.lesson-progress-fill {
  height: 100%;
  background: white;
  border-radius: 4px;
  transition: width 0.4s ease;
}

/* ===== NAV TABS ===== */
.main-nav {
  display: flex;
  background: white;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 62px;
  z-index: 100;
}

.nav-tab {
  flex: 1;
  padding: 11px 8px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-light);
  border-bottom: 3px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}

.nav-tab.active {
  color: var(--green);
  border-bottom-color: var(--green);
}

/* ===== VIEW SYSTEM ===== */
.view { display: none; }
.view.active { display: block; }
.hidden { display: none !important; }

/* ===== HOME VIEW ===== */
.home-wrap { padding: 14px 14px 20px; }

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

.op-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-mid);
  margin-bottom: 8px;
}

.op-track {
  height: 8px;
  background: var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.op-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--green), #00d4a1);
  border-radius: 8px;
  transition: width 0.5s ease;
}

.chapter-list { display: flex; flex-direction: column; gap: 10px; }

.chapter-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 14px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
  -webkit-user-select: none;
  user-select: none;
}

.chapter-card:active { transform: scale(0.98); box-shadow: var(--shadow-sm); }

.chapter-card.completed { border-color: var(--green); }
.chapter-card.current   { border-color: var(--yellow); }
.chapter-card.locked    { opacity: 0.5; cursor: not-allowed; }

.chapter-icon {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  flex-shrink: 0;
}

.icon-completed { background: var(--green-bg); }
.icon-current   { background: var(--yellow-bg); }
.icon-locked    { background: var(--bg); }

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

.chapter-num {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-light);
  margin-bottom: 2px;
}

.chapter-name {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 3px;
}

.chapter-desc {
  font-size: 0.76rem;
  color: var(--text-light);
  line-height: 1.4;
}

.chapter-score {
  font-size: 0.7rem;
  font-weight: 700;
  background: var(--green-bg);
  color: var(--green-dark);
  padding: 2px 8px;
  border-radius: 10px;
  margin-top: 4px;
  display: inline-block;
}

.chapter-badge { font-size: 1.3rem; flex-shrink: 0; }

/* ===== LESSON VIEW ===== */
.section-tabs {
  display: flex;
  overflow-x: auto;
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 0 14px;
  scrollbar-width: none;
  position: sticky;
  top: 62px;
  z-index: 100;
}
.section-tabs::-webkit-scrollbar { display: none; }

.section-tab {
  flex-shrink: 0;
  padding: 10px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-light);
  border-bottom: 3px solid transparent;
  white-space: nowrap;
  transition: color 0.2s, border-color 0.2s;
}
.section-tab.active { color: var(--green); border-bottom-color: var(--green); }
.section-tab.done   { color: var(--green-dark); }

.lesson-body {
  padding: 16px 14px 8px;
  line-height: 1.75;
  font-size: 0.92rem;
  color: var(--text);
}

.lesson-body p { margin-bottom: 10px; }
.lesson-body p:last-child { margin-bottom: 0; }
.lesson-body h3 { font-size: 1.05rem; font-weight: 700; color: var(--blue); margin: 18px 0 10px; }
.lesson-body ul { padding-left: 20px; margin-bottom: 10px; }
.lesson-body li { margin-bottom: 5px; }

/* Content boxes */
.box-green {
  background: var(--green-bg);
  border-left: 4px solid var(--green);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 12px 14px;
  margin: 12px 0;
  font-size: 0.88rem;
}

.box-yellow {
  background: var(--yellow-bg);
  border-left: 4px solid var(--yellow);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 12px 14px;
  margin: 12px 0;
  font-size: 0.88rem;
}

.box-red {
  background: var(--red-bg);
  border-left: 4px solid var(--red);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 12px 14px;
  margin: 12px 0;
  font-size: 0.88rem;
}

.box-blue {
  background: var(--blue-bg);
  border-left: 4px solid var(--blue-mid);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 12px 14px;
  margin: 12px 0;
  font-size: 0.88rem;
}

.box-purple {
  background: var(--purple-bg);
  border-left: 4px solid var(--purple);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 12px 14px;
  margin: 12px 0;
  font-size: 0.88rem;
}

.box-title {
  font-weight: 700;
  margin-bottom: 6px;
  display: block;
}

/* Term pill inline */
.term {
  background: var(--green-bg);
  color: var(--green-dark);
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 0.88em;
}

/* Moomoo mock UI */
.moomoo-ui {
  background: #1a1a2e;
  border-radius: var(--radius);
  padding: 14px;
  margin: 12px 0;
  color: white;
  font-size: 0.82rem;
}

.moomoo-ui-title {
  font-size: 0.65rem;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.mui-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.mui-tab {
  padding: 3px 10px;
  border-radius: 14px;
  font-size: 0.72rem;
  font-weight: 600;
}

.mui-tab-active  { background: var(--green); color: white; }
.mui-tab-inactive{ background: rgba(255,255,255,0.1); color: #aaa; }

.mui-row {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  align-items: center;
}
.mui-row:last-child { border-bottom: none; }

.mui-label { color: #888; font-size: 0.8rem; }
.mui-val   { color: white; font-weight: 600; }
.mui-green { color: #00d4a1; font-weight: 700; }
.mui-red   { color: #ff6b6b; font-weight: 700; }
.mui-orange{ color: #f6ad55; font-weight: 700; }

.mui-stock-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.mui-stock-name { font-weight: 600; font-size: 0.84rem; }
.mui-stock-code { color: #888; font-size: 0.72rem; }

.mui-badge {
  background: var(--green);
  color: white;
  font-size: 0.68rem;
  padding: 2px 8px;
  border-radius: 10px;
}

/* Compare table */
.cmp-table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 0.83rem;
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.cmp-table th {
  background: var(--green);
  color: white;
  padding: 9px 12px;
  text-align: left;
  font-weight: 700;
}

.cmp-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  background: white;
  vertical-align: top;
}

.cmp-table tr:last-child td { border-bottom: none; }
.cmp-table tr:nth-child(even) td { background: var(--bg); }

/* Lesson nav bar */
.lesson-nav-bar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  background: white;
  border-top: 1px solid var(--border);
  padding: 10px 14px;
  display: none;
  gap: 10px;
  z-index: 150;
}
.lesson-nav-bar.visible { display: flex; }

/* ===== BUTTONS ===== */
.btn {
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: 0.9rem;
  font-weight: 700;
  transition: opacity 0.15s, transform 0.1s;
  text-align: center;
}

.btn:active { opacity: 0.82; transform: scale(0.98); }

.btn-green   { background: var(--green); color: white; flex: 1; }
.btn-ghost   { background: var(--bg); color: var(--text-mid); }
.btn-outline {
  background: white;
  color: var(--green);
  border: 2px solid var(--green);
  flex: 1;
}

.btn-full { width: 100%; display: block; }

/* ===== QUIZ VIEW ===== */
.quiz-wrap {
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-bottom: 24px;
}

.quiz-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.quiz-counter {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-light);
}

.quiz-score-live {
  background: var(--green-bg);
  color: var(--green-dark);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 14px;
}

.quiz-q {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.55;
  color: var(--blue);
}

.quiz-opts {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.quiz-opt {
  padding: 13px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  background: white;
  text-align: left;
  width: 100%;
  line-height: 1.45;
  transition: border-color 0.15s, background 0.15s;
}

.quiz-opt:hover:not(.disabled) {
  border-color: var(--green);
  background: var(--green-bg);
}

.quiz-opt.correct {
  border-color: var(--green);
  background: var(--green-bg);
  color: var(--green-dark);
  font-weight: 700;
}

.quiz-opt.wrong {
  border-color: var(--red);
  background: var(--red-bg);
  color: var(--red);
}

.quiz-opt.disabled { cursor: not-allowed; }

.quiz-explain {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 0.86rem;
  line-height: 1.6;
}

.explain-label {
  font-weight: 700;
  color: var(--green-dark);
  display: block;
  margin-bottom: 4px;
}

/* ===== RESULT VIEW ===== */
.result-wrap {
  padding: 40px 20px 30px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.result-emoji  { font-size: 4.5rem; }
.result-title  { font-size: 1.5rem; font-weight: 800; }

.result-score-display {
  font-size: 3.2rem;
  font-weight: 800;
  color: var(--green);
}

.result-msg {
  font-size: 0.92rem;
  color: var(--text-light);
  line-height: 1.6;
  max-width: 300px;
}

.result-btns {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 320px;
  margin-top: 8px;
}

/* ===== GLOSSARY VIEW ===== */
.glossary-wrap { padding: 14px; }

.glossary-search {
  width: 100%;
  background: white;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: 0.92rem;
  margin-bottom: 14px;
  display: block;
}

.glossary-search:focus { border-color: var(--green); }

.glossary-cat-title {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 8px 4px 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.glossary-item {
  background: white;
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  margin-bottom: 9px;
  box-shadow: var(--shadow-sm);
  border-left: 3px solid var(--green);
}

.glossary-term-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

.glossary-zh { font-weight: 700; font-size: 0.97rem; color: var(--text); }
.glossary-en { font-size: 0.75rem; color: var(--text-light); }

.glossary-def-text {
  font-size: 0.86rem;
  color: var(--text-mid);
  line-height: 1.65;
  margin-bottom: 6px;
}

.glossary-example {
  background: var(--green-bg);
  border-radius: var(--radius-xs);
  padding: 7px 10px;
  font-size: 0.8rem;
  color: var(--green-dark);
  line-height: 1.5;
}

/* ===== 词典图标 ===== */
.dict-icon {
  display: inline-block;
  cursor: pointer;
  font-size: 0.72em;
  margin-left: 2px;
  vertical-align: middle;
  opacity: 0.65;
  transition: opacity 0.15s, transform 0.15s;
  user-select: none;
  line-height: 1;
}
.dict-icon:hover { opacity: 1; transform: scale(1.25); }

/* ===== 词典弹窗 ===== */
.dict-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.38);
  z-index: 490;
}

.dict-popup {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  background: white;
  border-radius: 18px 18px 0 0;
  border-top: 4px solid var(--green);
  box-shadow: 0 -6px 30px rgba(0,0,0,0.14);
  padding: 18px 16px 36px;
  z-index: 500;
}

.dp-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}

.dp-title-area { flex: 1; }

.dp-zh {
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--text);
  display: block;
  margin-bottom: 2px;
}

.dp-en {
  font-size: 0.76rem;
  color: var(--text-light);
}

.dp-close {
  background: var(--bg);
  border-radius: 50%;
  width: 30px;
  height: 30px;
  font-size: 0.88rem;
  color: var(--text-light);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-left: 10px;
  border: none;
}
.dp-close:hover { background: var(--border); color: var(--text); }

.dp-def {
  font-size: 0.92rem;
  color: var(--text);
  line-height: 1.72;
  margin-bottom: 10px;
}

.dp-eg {
  background: var(--green-bg);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.83rem;
  color: var(--green-dark);
  line-height: 1.55;
}

/* ===== TOAST ===== */
.toast {
  position: fixed;
  top: 72px;
  left: 50%;
  transform: translateX(-50%) translateY(-12px);
  background: #2d3748;
  color: white;
  padding: 9px 20px;
  border-radius: 20px;
  font-size: 0.84rem;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 999;
  white-space: nowrap;
  pointer-events: none;
}

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

/* ===== UTILITY ===== */
.text-green { color: var(--green); }
.text-red   { color: var(--red); }
.text-yellow{ color: var(--yellow); }
.bold       { font-weight: 700; }
.center     { text-align: center; }
.mt8        { margin-top: 8px; }
.mt14       { margin-top: 14px; }
