:root {
  --bg: #f2f4f8;
  --card: #ffffff;
  --primary: #2f6df6;
  --primary-dark: #1f56d0;
  --green: #16a34a;
  --green-bg: #e7f8ee;
  --red: #dc2626;
  --red-bg: #fdecec;
  --amber: #b45309;
  --border: #e5e9f0;
  --text: #1c2430;
  --muted: #7b879b;
  --shadow: 0 4px 16px rgba(31, 45, 70, 0.07);
  --topbar-h: 52px;
  --tabbar-h: 58px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { 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, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 16px; line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}
.hidden { display: none !important; }

/* ---------------- login ---------------- */
.login-wrap {
  min-height: 100vh; min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px; background: linear-gradient(150deg, #3b7bff 0%, #1e3a8a 100%);
}
.login-card {
  width: 100%; max-width: 390px; background: #fff; border-radius: 20px;
  padding: 30px 24px calc(24px + var(--safe-bottom));
  box-shadow: 0 22px 55px rgba(8, 20, 50, 0.35);
}
.logo {
  width: 60px; height: 60px; margin: 0 auto 14px; border-radius: 16px;
  background: linear-gradient(150deg, #3b7bff, #1e3a8a); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 18px; letter-spacing: .5px;
}
.login-card h1 { margin: 0 0 4px; font-size: 21px; text-align: center; }
.login-card .sub { margin: 0 0 20px; text-align: center; color: var(--muted); font-size: 13px; }
.login-card label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.login-card input {
  width: 100%; margin-top: 6px; padding: 13px 14px;
  border: 1px solid var(--border); border-radius: 12px; font-size: 16px; outline: none; background: #fbfcfe;
}
.login-card input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47,109,246,.15); background:#fff; }
.error { color: var(--red); font-size: 13px; min-height: 18px; margin-bottom: 8px; text-align: center; }

/* ---------------- app shell (mobile H5) ---------------- */
.app { min-height: 100vh; min-height: 100dvh; }

.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  height: calc(var(--topbar-h) + var(--safe-top));
  padding: var(--safe-top) 14px 0;
  display: flex; align-items: center; justify-content: space-between;
  background: #fff; border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 17px; color: var(--primary); }
.user-box { display: flex; align-items: center; gap: 8px; }
.uname { color: var(--muted); font-size: 13px; max-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  border: 1px solid var(--border); background: #fff; color: var(--text);
  border-radius: 9px; padding: 6px 10px; font-size: 13px; cursor: pointer;
}

.scroll {
  padding: calc(var(--topbar-h) + var(--safe-top) + 12px) 12px
           calc(var(--tabbar-h) + var(--safe-bottom) + 20px);
  min-height: 100vh; min-height: 100dvh;
}

/* stats */
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; margin-bottom: 12px; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 9px 2px; text-align: center; box-shadow: var(--shadow); }
.stat .num { font-size: 16px; font-weight: 700; line-height: 1.3; }
.stat .label { font-size: 11px; color: var(--muted); }
.stat.warn .num { color: var(--amber); }
.stat.bad .num { color: var(--red); }
.stat.good .num { color: var(--green); }

/* filters */
.filters { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 12px; margin-bottom: 12px; box-shadow: var(--shadow); }
.filter-row { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; }
.filter-row label { flex: 0 0 42px; color: var(--muted); font-size: 13px; }
.filter-row select { flex: 1; padding: 10px; border: 1px solid var(--border); border-radius: 10px; background: #fbfcfe; color: var(--text); font-size: 14px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); margin: 10px 0 12px; }
.check input { width: 18px; height: 18px; }

/* card */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 16px; padding: 16px; box-shadow: var(--shadow); }
.card.empty { color: var(--muted); text-align: center; padding: 48px 20px; }

.qmeta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 12px; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: #eef2fb; color: #4a5a78; border: 1px solid #e1e8f6; }
.tag.type { background: #fff4e5; color: #9a5b00; border-color: #ffe2bd; }
.tag.wrong-tag { background: var(--red-bg); color: var(--red); border-color: #f7cccc; }

.stem { font-size: 17px; font-weight: 600; margin: 6px 0 16px; white-space: pre-wrap; }

.options { display: flex; flex-direction: column; gap: 10px; }
.option { display: flex; gap: 11px; align-items: flex-start; border: 1px solid var(--border); border-radius: 13px; padding: 12px; background: #fff; transition: all .12s; }
.option:active { transform: scale(.995); }
.option .key { flex: 0 0 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: #eef2fb; color: #4a5a78; font-weight: 700; font-size: 14px; }
.option .txt { flex: 1; white-space: pre-wrap; font-size: 15px; }
.option.selected { border-color: var(--primary); background: #eef3ff; }
.option.selected .key { background: var(--primary); color: #fff; }
.option.correct { border-color: var(--green); background: var(--green-bg); }
.option.correct .key { background: var(--green); color: #fff; }
.option.wrong { border-color: var(--red); background: var(--red-bg); }
.option.wrong .key { background: var(--red); color: #fff; }
.option.locked { cursor: default; }

.answer-box { margin-top: 16px; border-radius: 13px; padding: 12px 14px; font-size: 15px; background: var(--green-bg); border: 1px solid #c4ebd6; }
.answer-box .line { margin: 3px 0; }
.answer-box .k { color: var(--muted); }
.explain { margin-top: 10px; padding-top: 10px; border-top: 1px dashed #bfe3cf; color: #29543c; white-space: pre-wrap; font-size: 14px; }
.result-badge { font-weight: 700; }
.result-badge.ok { color: var(--green); }
.result-badge.no { color: var(--red); }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.toolbar .btn { flex: 1 1 auto; min-width: 44%; justify-content: center; text-align: center; }

/* buttons */
.btn {
  border: 1px solid var(--border); background: #fff; color: var(--text);
  padding: 11px 16px; border-radius: 11px; font-size: 15px; cursor: pointer; transition: all .12s;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.btn.primary:active { background: var(--primary-dark); }
.btn.ghost { background: #fff; }
.btn.block { width: 100%; padding: 13px; font-size: 16px; }
.btn:disabled { opacity: .45; }
.btn.danger { color: var(--red); border-color: #f2c9c9; }
.btn.ok { color: var(--green); border-color: #bfe3cf; }
.btn.on { background: #eef3ff; border-color: var(--primary); color: var(--primary); font-weight: 600; }

/* navbar */
.navbar { display: flex; align-items: center; gap: 10px; margin-top: 16px; justify-content: space-between; }
.navbar .btn { flex: 1; }
.navbar .jump { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; flex: 0 0 auto; }
.navbar .jump input { width: 56px; padding: 9px; border: 1px solid var(--border); border-radius: 9px; text-align: center; font-size: 15px; }
.hint-swipe { text-align: center; color: #aab3c2; font-size: 12px; margin: 18px 0 4px; }

/* bottom tabbar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex; background: #fff; border-top: 1px solid var(--border);
}
.mode-tab {
  flex: 1; border: none; background: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 11px; cursor: pointer; padding: 0;
}
.mode-tab .tab-ic {
  width: 24px; height: 24px; border-radius: 8px; display: flex; align-items: center; justify-content: center;
  background: #eef2fb; color: #7b879b; font-size: 13px; font-weight: 700;
}
.mode-tab.active { color: var(--primary); font-weight: 600; }
.mode-tab.active .tab-ic { background: var(--primary); color: #fff; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 18px);
  transform: translateX(-50%) translateY(16px);
  background: rgba(28,36,48,.94); color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: all .25s; max-width: 88vw; text-align: center; z-index: 40;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (min-width: 640px) {
  .scroll { max-width: 720px; margin: 0 auto; }
  .tabbar { max-width: 720px; left: 50%; transform: translateX(-50%); border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}
