/* ===== tokens ===== */
:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --text: #16181d;
  --text-2: #5b6472;
  --text-3: #8b95a3;
  --line: rgba(0, 0, 0, 0.09);
  --accent: #0f6e56;
  --accent-2: #1d9e75;
  --accent-soft: #e1f5ee;
  --warn: #a16207;
  --warn-soft: #fef3c7;
  --danger: #b3261e;
  --danger-soft: #fce8e6;
  --ok: #15803d;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.06);
  --fs: 17px;
  --radius: 14px;
}
html[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #181b21;
  --surface-2: #21252c;
  --text: #e9ecf1;
  --text-2: #a3acba;
  --text-3: #78828f;
  --line: rgba(255, 255, 255, 0.11);
  --accent: #34c79b;
  --accent-2: #2ea985;
  --accent-soft: rgba(52, 199, 155, 0.14);
  --warn: #e2b04a;
  --warn-soft: rgba(226, 176, 74, 0.14);
  --danger: #f0776c;
  --danger-soft: rgba(240, 119, 108, 0.14);
  --ok: #4ade80;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.35);
}
@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] {
    --bg: #0f1115;
    --surface: #181b21;
    --surface-2: #21252c;
    --text: #e9ecf1;
    --text-2: #a3acba;
    --text-3: #78828f;
    --line: rgba(255, 255, 255, 0.11);
    --accent: #34c79b;
    --accent-2: #2ea985;
    --accent-soft: rgba(52, 199, 155, 0.14);
    --warn: #e2b04a;
    --warn-soft: rgba(226, 176, 74, 0.14);
    --danger: #f0776c;
    --danger-soft: rgba(240, 119, 108, 0.14);
    --ok: #4ade80;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 400 var(--fs)/1.6 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Source Han Sans SC", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
[hidden] { display: none !important; }

/* ===== boot ===== */
.boot {
  position: fixed; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px; color: var(--text-3);
  font-size: 14px;
}
.boot-flask {
  width: 42px; height: 42px; border-radius: 10px; background: var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 0.35; transform: scale(0.94); } 50% { opacity: 1; transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .boot-flask { animation: none; } }

/* ===== layout ===== */
#app {
  max-width: 560px; margin: 0 auto; min-height: 100dvh;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
#topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 0.5px solid var(--line);
}
#topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
#brand { font-weight: 500; font-size: 15px; letter-spacing: 0.2px; }
#progress-tag {
  font-size: 12px; color: var(--text-2); background: var(--surface-2);
  padding: 2px 8px; border-radius: 999px; font-variant-numeric: tabular-nums;
}
#topbar-right { display: flex; gap: 4px; }
.icon-btn {
  position: relative; width: 40px; height: 40px; border-radius: 10px;
  display: grid; place-items: center; color: var(--text-2);
}
.icon-btn:active { background: var(--surface-2); }
.dot {
  position: absolute; top: 8px; right: 9px; width: 7px; height: 7px;
  border-radius: 50%; background: var(--accent-2);
}
#view { padding: 14px 16px 24px; }
#banner {
  margin: 10px 16px 0; padding: 9px 12px; border-radius: 10px;
  font-size: 13px; line-height: 1.5;
  background: var(--warn-soft); color: var(--warn);
}
#banner.info { background: var(--accent-soft); color: var(--accent); }
#banner.danger { background: var(--danger-soft); color: var(--danger); }

/* ===== tabbar ===== */
#tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; max-width: 560px; margin: 0 auto;
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-top: 0.5px solid var(--line);
}
.tab {
  position: relative; flex: 1; height: 56px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3px;
  font-size: 11px; color: var(--text-3);
}
.tab.active { color: var(--accent); }
.tab:active { opacity: 0.7; }
.badge {
  position: absolute; top: 7px; left: 50%; margin-left: 6px;
  min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px;
  background: var(--danger); color: #fff; font-size: 10px; line-height: 16px;
  text-align: center; font-variant-numeric: tabular-nums;
}

/* ===== flashcard ===== */
.card {
  background: var(--surface); border: 0.5px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px 18px; min-height: 240px;
  display: flex; flex-direction: column;
  transition: transform 0.18s ease, opacity 0.18s ease;
  will-change: transform;
}
.card.swipe-left { transform: translateX(-24px); opacity: 0; }
.card-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.card-q { font-size: calc(var(--fs) + 2px); line-height: 1.7; font-weight: 500; }
/* 长公式横向可滑动，避免被卡片裁掉 */
.card-q, .answer-main, .block-body, .item-q {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.card-q::-webkit-scrollbar, .answer-main::-webkit-scrollbar,
.block-body::-webkit-scrollbar, .item-q::-webkit-scrollbar { display: none; }
.card-q.scrollable, .answer-main.scrollable, .block-body.scrollable, .item-q.scrollable {
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 26px), transparent);
  mask-image: linear-gradient(to right, #000 calc(100% - 26px), transparent);
}
.scroll-hint {
  font-size: 11px; color: var(--text-3); margin-top: 2px; letter-spacing: 0.5px;
}
.answer-main .katex { font-size: 0.97em; }
.card-hint {
  margin-top: 18px; padding: 14px; border-radius: 10px;
  border: 1px dashed var(--line); color: var(--text-3); font-size: 13px;
  text-align: center;
}
.answer { margin-top: 18px; padding-top: 16px; border-top: 0.5px solid var(--line); }
.answer-label {
  font-size: 11px; letter-spacing: 1px; color: var(--accent);
  font-weight: 500; margin-bottom: 6px;
}
.answer-main { font-size: calc(var(--fs) + 1px); line-height: 1.75; }
.block { margin-top: 16px; }
.block-label {
  font-size: 11px; color: var(--text-3); letter-spacing: 0.5px; margin-bottom: 5px;
}
.block-body { font-size: calc(var(--fs) - 1px); color: var(--text-2); line-height: 1.7; }
.block.pitfall {
  border-left: 3px solid var(--warn); padding-left: 12px;
}
.block.pitfall .block-body { color: var(--text); }
.ans-tail { height: 20px; }
.src {
  margin-top: 14px; font-size: 11px; color: var(--text-3); letter-spacing: 0.3px;
}

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; padding: 3px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-2);
}
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }

.study-wrap {
  display: flex; flex-direction: column;
  min-height: calc(100vh - 196px);
  min-height: calc(100dvh - 196px);
}
.study-wrap > .card { margin-top: 0; margin-bottom: auto; }
.study-wrap .dock { margin-top: auto; }

.dock {
  position: sticky;
  bottom: calc(57px + env(safe-area-inset-bottom));
  z-index: 5;
  margin-top: 10px;
  padding: 10px 0 2px;
  background: var(--bg);
  box-shadow: 0 -10px 14px -10px rgba(0, 0, 0, 0.10);
}
.actions {
  display: grid; grid-template-columns: 1fr 1fr 44px; gap: 8px;
}
.nav { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.nav.with-fav { grid-template-columns: 1fr 1fr 44px; }
.nav-fav {
  height: 38px; border-radius: 10px; font-size: 17px;
  background: var(--surface-2); color: var(--text-3);
}
.nav-fav.on { color: var(--warn); }
.nav-btn {
  height: 38px; border-radius: 10px; font-size: 14px;
  background: var(--surface-2); color: var(--text-2);
}
.nav-btn.next { color: var(--accent); background: var(--accent-soft); }
.nav-btn:disabled { opacity: 0.38; }
.btn {
  height: 46px; border-radius: 12px; font-size: 15px; font-weight: 500;
  border: 0.5px solid var(--line); background: var(--surface);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:active { transform: scale(0.98); }
.btn-fuzzy { color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.btn-known { color: #fff; background: var(--accent-2); border-color: transparent; }
html[data-theme="dark"] .btn-known { color: #06231a; }
.btn-fav { color: var(--text-3); }
.btn-fav.on { color: var(--warn); }
.btn-primary { color: #fff; background: var(--accent); border-color: transparent; height: 48px; }
html[data-theme="dark"] .btn-primary { color: #06231a; }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); background: var(--danger-soft); border-color: transparent; }
.btn-block { width: 100%; }

/* ===== progress ===== */
.bar { height: 4px; border-radius: 2px; background: var(--surface-2); overflow: hidden; margin-top: 12px; }
.bar > i { display: block; height: 100%; background: var(--accent-2); transition: width 0.25s ease; }

/* ===== empty ===== */
.empty { text-align: center; padding: 56px 24px; color: var(--text-3); font-size: 14px; }
.empty strong { display: block; color: var(--text-2); font-weight: 500; margin-bottom: 6px; font-size: 15px; }

/* ===== list ===== */
.list { display: flex; flex-direction: column; gap: 8px; }
.item {
  background: var(--surface); border: 0.5px solid var(--line);
  border-radius: 12px; padding: 13px 14px;
}
.item-head { display: flex; flex-direction: column; gap: 6px; }
.item-q { font-size: 15px; line-height: 1.55; }
.item-sub { display: flex; gap: 8px; align-items: center; font-size: 11px; color: var(--text-3); }
.chev { margin-left: auto; font-size: 12px; color: var(--text-3); transition: transform 0.15s ease; }
.item.open .chev { transform: rotate(180deg); }
.item-head { cursor: pointer; }
.item-body { margin-top: 12px; padding-top: 12px; border-top: 0.5px solid var(--line); }
.item-actions { display: flex; gap: 8px; margin-top: 12px; }
.item-actions .btn { height: 36px; font-size: 13px; flex: 1; }

/* ===== segmented ===== */
.stylebar { margin-bottom: 8px; }
.stylebar .seg { width: 100%; }
.modebar { display: flex; gap: 6px; align-items: center; }
.picklist { display: flex; flex-direction: column; gap: 6px; }
.pick {
  display: flex; justify-content: space-between; align-items: center;
  height: 46px; padding: 0 14px; border-radius: 10px;
  background: var(--surface-2); font-size: 14px; color: var(--text); text-align: left;
}
.pick.on { background: var(--accent-soft); color: var(--accent); }
.pick .tick { font-size: 13px; }
.dock-read .nav { margin-top: 0; }
.modebar .seg { flex: 1; }
.skip-tog {
  height: 34px; padding: 0 7px; border-radius: 9px; white-space: nowrap;
  font-size: 11px; color: var(--text-3); border: 0.5px solid var(--line);
  background: var(--surface);
}
.skip-tog.on { color: var(--accent); background: var(--accent-soft); border-color: var(--accent-2); }
.fhint { font-size: 12px; color: var(--text-3); line-height: 1.7; }

.seg { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button {
  flex: 1; height: 34px; border-radius: 8px; font-size: 13px; color: var(--text-2);
}
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* ===== section ===== */
.section { margin-bottom: 22px; }
.section-title {
  font-size: 12px; color: var(--text-3); letter-spacing: 0.5px;
  margin: 0 2px 8px; font-weight: 500;
}
.panel {
  background: var(--surface); border: 0.5px solid var(--line);
  border-radius: var(--radius); overflow: hidden;
}
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 15px; min-height: 50px; border-bottom: 0.5px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row-label { font-size: 15px; }
.row-value { font-size: 13px; color: var(--text-3); display: flex; align-items: center; gap: 6px; }
.row:active { background: var(--surface-2); }
.row.danger .row-label { color: var(--danger); }

/* ===== stats ===== */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat { background: var(--surface); border: 0.5px solid var(--line); border-radius: 12px; padding: 12px 8px; text-align: center; }
.stat b { display: block; font-size: 19px; font-weight: 500; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11px; color: var(--text-3); }

/* ===== sheet ===== */
.mask {
  position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, 0.42);
  animation: fade 0.18s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  max-width: 560px; margin: 0 auto; max-height: 88dvh; overflow-y: auto;
  background: var(--surface); border-radius: 18px 18px 0 0;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  animation: up 0.22s cubic-bezier(0.2, 0.9, 0.3, 1);
  -webkit-overflow-scrolling: touch;
}
@keyframes up { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-handle { width: 36px; height: 4px; border-radius: 2px; background: var(--line); margin: 6px auto 14px; }
.sheet h3 { margin: 0 0 14px; font-size: 15px; font-weight: 500; }

/* ===== filter groups ===== */
.fgroup { margin-bottom: 18px; }
.fgroup-title { font-size: 12px; color: var(--text-3); margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.tog {
  font-size: 13px; padding: 7px 12px; border-radius: 9px;
  background: var(--surface-2); color: var(--text-2); border: 0.5px solid transparent;
  white-space: nowrap;
}
.tog.on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-2); }
.search-input {
  width: 100%; height: 42px; border-radius: 10px; border: 0.5px solid var(--line);
  background: var(--surface-2); color: var(--text); padding: 0 12px; font-size: 15px;
}
.search-input::placeholder { color: var(--text-3); }
.code-input:focus, .search-input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { outline: none; }

/* ===== activate ===== */
.activate { padding-top: 8vh; text-align: center; }
.activate .logo {
  width: 64px; height: 64px; margin: 0 auto 18px; border-radius: 16px;
  background: var(--accent); display: grid; place-items: center;
}
.activate h1 { font-size: 20px; font-weight: 500; margin: 0 0 6px; }
.activate .sub { font-size: 13px; color: var(--text-3); margin-bottom: 30px; }
.code-input {
  width: 100%; height: 54px; border-radius: 12px; text-align: center;
  border: 0.5px solid var(--line); background: var(--surface);
  color: var(--text); font-size: 22px; letter-spacing: 3px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; text-transform: uppercase;
}
.code-input::placeholder { letter-spacing: 2px; color: var(--text-3); font-size: 16px; }
.err { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 18px; }
.note { font-size: 12px; color: var(--text-3); line-height: 1.8; margin-top: 22px; text-align: left; }
.note li { margin-bottom: 2px; }
.note ul { padding-left: 18px; margin: 0; }

/* ===== toast ===== */
.toast {
  position: fixed; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 60;
  background: rgba(30, 32, 38, 0.94); color: #fff;
  padding: 9px 16px; border-radius: 999px; font-size: 13px; white-space: nowrap;
  animation: fade 0.16s ease;
}

/* ===== katex ===== */
.katex { font-size: 1.02em; }
.katex-display { margin: 0.4em 0; overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.katex-error { color: var(--danger); font-family: ui-monospace, monospace; font-size: 0.9em; }
