:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1c1e21;
  --sub: #6b7280;
  --accent: #f97316;
  --accent-soft: #fff1e6;
  --border: #e5e7eb;
  --green: #16a34a;
  --green-soft: #e8f7ee;
  --yellow: #d97706;
  --yellow-soft: #fef3c7;
  --red: #dc2626;
  --red-soft: #fdecec;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101214;
    --card: #1b1e22;
    --text: #eceef0;
    --sub: #9aa2ad;
    --accent: #fb923c;
    --accent-soft: #33241a;
    --border: #2c3138;
    --green: #4ade80;
    --green-soft: #16311f;
    --yellow: #fbbf24;
    --yellow-soft: #33290f;
    --red: #f87171;
    --red-soft: #3a1d1d;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.65;
}

#app { max-width: 680px; margin: 0 auto; }

#views {
  padding: 12px 14px calc(84px + env(safe-area-inset-bottom));
}

.view { display: none; }
.view.active { display: block; }

/* ---------- tab bar ---------- */
#tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  max-width: 680px;
  margin: 0 auto;
  display: flex;
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 100;
}

.tab {
  flex: 1;
  border: none;
  background: none;
  color: var(--sub);
  font-size: 11px;
  padding: 8px 0 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
}
.tab-icon { font-size: 20px; line-height: 1.2; }
.tab.active { color: var(--accent); font-weight: 600; }

/* ---------- common ---------- */
.page-title {
  font-size: 21px;
  font-weight: 700;
  margin: 6px 2px 2px;
}
.page-sub { color: var(--sub); font-size: 13px; margin: 0 2px 12px; }

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 2px 10px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 999px;
  padding: 5px 13px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.chip .cnt { opacity: 0.65; font-size: 11px; margin-left: 3px; }

.search-box {
  display: flex;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 12px;
  margin-bottom: 10px;
  gap: 8px;
}
.search-box input {
  border: none;
  outline: none;
  background: none;
  color: var(--text);
  font-size: 14px;
  flex: 1;
}

/* ---------- question card ---------- */
.qcard {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 10px;
  overflow: hidden;
}

.qcard-head {
  padding: 13px 14px;
  cursor: pointer;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.qcard-head .q-text { flex: 1; font-weight: 600; font-size: 15px; }

.q-meta {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 6px;
}
.badge {
  font-size: 11px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 500;
}
.badge.hot { background: var(--red-soft); color: var(--red); }
.badge.diff { background: var(--bg); color: var(--sub); }
.badge.st-0 { background: var(--red-soft); color: var(--red); }
.badge.st-1 { background: var(--yellow-soft); color: var(--yellow); }
.badge.st-2 { background: var(--green-soft); color: var(--green); }

.star-btn {
  border: none;
  background: none;
  font-size: 18px;
  cursor: pointer;
  padding: 0;
  line-height: 1.3;
  filter: grayscale(1) opacity(0.45);
}
.star-btn.on { filter: none; }

.qcard-body {
  border-top: 1px dashed var(--border);
  padding: 12px 14px 14px;
  font-size: 14.5px;
}

.answer p { margin: 6px 0; }
.answer ul, .answer ol { margin: 6px 0; padding-left: 20px; }
.answer li { margin: 3px 0; }
.answer code {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0 5px;
  font-size: 13px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.answer strong { color: var(--accent); }

.tip-box {
  margin-top: 10px;
  background: var(--accent-soft);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13.5px;
}

.rate-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.rate-btn {
  flex: 1;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  padding: 8px 0;
  font-size: 14px;
  cursor: pointer;
}
.rate-btn.r0.on { background: var(--red-soft); border-color: var(--red); color: var(--red); font-weight: 600; }
.rate-btn.r1.on { background: var(--yellow-soft); border-color: var(--yellow); color: var(--yellow); font-weight: 600; }
.rate-btn.r2.on { background: var(--green-soft); border-color: var(--green); color: var(--green); font-weight: 600; }

.empty {
  text-align: center;
  color: var(--sub);
  padding: 48px 0;
  font-size: 14px;
}

/* ---------- drill ---------- */
.drill-progress {
  display: flex;
  justify-content: space-between;
  color: var(--sub);
  font-size: 13px;
  margin: 4px 2px 10px;
}

.flashcard {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 22px 18px;
  min-height: 240px;
  display: flex;
  flex-direction: column;
}
.flashcard .fc-q {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 8px;
}
.fc-answer { margin-top: 10px; }

.big-btn {
  width: 100%;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  padding: 13px 0;
  margin-top: 16px;
  cursor: pointer;
}
.big-btn.ghost {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  font-weight: 500;
}

.drill-done {
  text-align: center;
  padding: 40px 10px;
}
.drill-done .big-emoji { font-size: 48px; }

/* ---------- playbook ---------- */
.pb-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 10px;
  overflow: hidden;
}
.pb-head {
  padding: 14px;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.pb-head .arrow { color: var(--sub); transition: transform 0.2s; }
.pb-card.open .arrow { transform: rotate(90deg); }
.pb-body {
  display: none;
  border-top: 1px dashed var(--border);
  padding: 12px 14px 14px;
  font-size: 14.5px;
}
.pb-card.open .pb-body { display: block; }

/* ---------- stats ---------- */
.stat-hero {
  background: linear-gradient(135deg, var(--accent), #fb7185);
  color: #fff;
  border-radius: 18px;
  padding: 18px 16px;
  margin-bottom: 14px;
}
.stat-hero .big {
  font-size: 34px;
  font-weight: 800;
  line-height: 1.2;
}
.stat-hero .sub { opacity: 0.9; font-size: 13px; }

.progress-track {
  background: rgba(255, 255, 255, 0.3);
  border-radius: 99px;
  height: 8px;
  margin-top: 10px;
  overflow: hidden;
}
.progress-fill {
  background: #fff;
  height: 100%;
  border-radius: 99px;
  transition: width 0.4s;
}

.stat-row {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
}
.stat-row .top {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 7px;
}
.stat-row .top .pct { color: var(--sub); font-weight: 500; font-size: 13px; }
.seg-track {
  display: flex;
  height: 7px;
  border-radius: 99px;
  overflow: hidden;
  background: var(--bg);
}
.seg { height: 100%; }
.seg.s2 { background: var(--green); }
.seg.s1 { background: var(--yellow); }
.seg.s0 { background: var(--red); }

.legend {
  display: flex;
  gap: 14px;
  color: var(--sub);
  font-size: 12px;
  margin: 4px 2px 12px;
  flex-wrap: wrap;
}
.dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 99px;
  margin-right: 4px;
}

.danger-btn {
  width: 100%;
  margin-top: 14px;
  border: 1px solid var(--red);
  color: var(--red);
  background: none;
  border-radius: 12px;
  padding: 11px 0;
  font-size: 14px;
  cursor: pointer;
}

@media (min-width: 700px) {
  #tabbar { border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}
