:root {
  --bg: #f7f8fa;
  --card: #ffffff;
  --ink: #1f2328;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #12836b;
  --brand-2: #0f6b57;
  --brand-weak: #e6f4f0;
  --ok: #12836b;
  --bad: #d4433a;
  --warn: #b45309;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 8px 24px rgba(16,24,40,.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }

/* ---------- 登录 ---------- */
.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 10% -10%, #e8f6f2 0%, transparent 60%),
    radial-gradient(900px 500px at 110% 10%, #eef2ff 0%, transparent 55%),
    var(--bg);
}
.auth-card {
  width: min(420px, 100%);
  background: var(--card);
  border-radius: 18px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.brand { display: flex; gap: 14px; align-items: center; margin-bottom: 22px; }
.logo {
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--brand); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 20px;
}
.logo.small { width: 30px; height: 30px; border-radius: 9px; font-size: 15px; }
.brand h1 { font-size: 19px; margin: 0; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.tabs { display: flex; gap: 6px; background: #f1f3f5; padding: 4px; border-radius: 10px; margin-bottom: 18px; }
.tab { flex: 1; padding: 9px; border-radius: 8px; color: var(--muted); font-weight: 600; }
.tab.active { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.06); }

label { display: block; margin-bottom: 14px; font-size: 13px; color: var(--muted); }
input, select {
  width: 100%; margin-top: 6px; padding: 11px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--ink); font-size: 15px; outline: none;
}
input:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-weak); }

.primary {
  width: 100%; padding: 11px 16px; border-radius: 10px;
  background: var(--brand); color: #fff; font-weight: 600;
}
.primary:hover { background: var(--brand-2); }
.primary:disabled { opacity: .55; cursor: not-allowed; }
.primary.block { width: 100%; }
.ghost {
  padding: 8px 14px; border: 1px solid var(--line); border-radius: 9px;
  background: #fff; font-weight: 500;
}
.ghost:hover { border-color: var(--brand); color: var(--brand); }
.link { color: var(--brand); font-weight: 600; padding: 6px 8px; }

.hint { color: var(--muted); font-size: 12px; margin: 14px 0 0; }
.msg { min-height: 20px; margin: 10px 0 0; font-size: 13px; color: var(--bad); }

/* ---------- 主界面 ---------- */
.topbar {
  height: 58px; display: flex; align-items: center; gap: 16px;
  padding: 0 18px; background: #fff; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand-mini { display: flex; align-items: center; gap: 9px; font-weight: 700; }
.topstats { display: flex; gap: 18px; color: var(--muted); font-size: 13px; flex: 1; }
.topstats b { color: var(--ink); }
.userbox { display: flex; align-items: center; gap: 8px; font-size: 13px; }

.layout { display: grid; grid-template-columns: 250px 1fr; gap: 18px; padding: 18px; max-width: 1280px; margin: 0 auto; }

.panel { background: #fff; border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); margin-bottom: 14px; }
.panel h3 { margin: 0 0 10px; font-size: 13px; color: var(--muted); font-weight: 600; letter-spacing: .3px; }
.modes { display: grid; gap: 6px; }
.mode {
  text-align: left; padding: 9px 12px; border-radius: 9px;
  color: var(--ink); border: 1px solid transparent;
}
.mode:hover { background: #f5f7f8; }
.mode.active { background: var(--brand-weak); color: var(--brand-2); font-weight: 600; }
.round { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-bottom: 0; }
.filter-row { display: flex; gap: 8px; margin-bottom: 8px; }
.filter-row select { margin-top: 0; flex: 1; min-width: 0; }

.content { min-width: 0; }
.empty {
  background: #fff; border-radius: var(--radius); padding: 60px 24px;
  text-align: center; box-shadow: var(--shadow);
}

.card { background: #fff; border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.qhead { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.badge {
  font-size: 12px; padding: 3px 9px; border-radius: 999px;
  background: var(--brand); color: #fff; font-weight: 600;
}
.ghost-badge { background: #f1f3f5; color: var(--muted); font-weight: 500; }
.progress-text { margin-left: auto; color: var(--muted); font-size: 13px; }

.stem { font-size: 17px; line-height: 1.7; margin: 0 0 16px; font-weight: 600; }

.options { display: grid; gap: 9px; }
.opt {
  display: flex; gap: 11px; align-items: flex-start;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: 11px;
  background: #fff; text-align: left; transition: .12s;
}
.opt:hover { border-color: var(--brand); background: #fbfefd; }
.opt .tick {
  flex: 0 0 22px; height: 22px; border-radius: 6px; border: 1.5px solid var(--line);
  display: grid; place-items: center; font-size: 12px; font-weight: 700; color: var(--muted);
}
.opt.sel { border-color: var(--brand); background: var(--brand-weak); }
.opt.sel .tick { background: var(--brand); border-color: var(--brand); color: #fff; }
.opt.correct { border-color: var(--ok); background: #eaf7f2; }
.opt.correct .tick { background: var(--ok); border-color: var(--ok); color: #fff; }
.opt.wrong { border-color: var(--bad); background: #fdeeed; }
.opt.wrong .tick { background: var(--bad); border-color: var(--bad); color: #fff; }

.result { margin-top: 16px; padding: 14px; border-radius: 11px; background: #f8fafb; border: 1px solid var(--line); }
.result.ok { background: #eaf7f2; border-color: #b7e3d4; }
.result.bad { background: #fdeeed; border-color: #f3c3bf; }
.result h4 { margin: 0 0 6px; font-size: 15px; }
.result p { margin: 4px 0; font-size: 14px; }

.actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.actions .primary { width: auto; }

.ai { margin-top: 16px; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.ai-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; background: #f8fafb; border-bottom: 1px solid var(--line); font-size: 13px; }
.ai-body { padding: 14px; max-height: 420px; overflow: auto; font-size: 14px; line-height: 1.75; white-space: pre-wrap; }
.ai-ask { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.ai-ask input { margin: 0; }
.ai-ask .primary { width: auto; }

/* ---------- 抽屉 ---------- */
.drawer { position: fixed; inset: 0; background: rgba(17,24,39,.35); display: grid; place-items: center; z-index: 50; padding: 20px; }
.drawer-body { width: min(920px, 100%); max-height: 86vh; overflow: auto; background: #fff; border-radius: 16px; padding: 22px; box-shadow: var(--shadow); }
.drawer-body.narrow { width: min(460px, 100%); }
.drawer-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.drawer-head h2 { margin: 0; font-size: 18px; }

.stats .kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: #f8fafb; border-radius: 12px; padding: 14px; }
.kpi .v { font-size: 22px; font-weight: 700; color: var(--brand-2); }
.kpi .k { font-size: 12px; color: var(--muted); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; }
.bar { height: 6px; background: #eef1f3; border-radius: 3px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand); }

/* ==================== 移动端适配 ==================== */
@media (max-width: 860px) {
  body {
    font-size: 15px;
    padding-bottom: env(safe-area-inset-bottom);
  }

  /* 顶栏压缩 */
  .topbar {
    height: auto;
    min-height: 52px;
    padding: 8px 12px;
    gap: 8px;
    flex-wrap: nowrap;
  }
  .brand-mini span { display: none; }
  .topstats {
    display: flex;
    gap: 10px;
    font-size: 11px;
    overflow: hidden;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
  }
  .topstats span:not(:first-child) { display: none; }
  .userbox { gap: 4px; }
  .userbox #whoami { display: none; }
  .userbox .ghost { padding: 7px 10px; font-size: 13px; }

  /* 布局：单列，侧栏变顶栏横条 */
  .layout {
    display: block;
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
  }
  .sidebar { margin-bottom: 10px; }
  .panel {
    padding: 12px;
    margin-bottom: 10px;
  }

  /* 模式：横向滑动的胶囊 */
  .modes {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
  }
  .modes::-webkit-scrollbar { display: none; }
  .mode {
    flex: 0 0 auto;
    padding: 8px 14px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #fff;
    font-size: 14px;
    white-space: nowrap;
  }
  .mode.active {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
    font-weight: 600;
  }

  /* 筛选 + 开始按钮 */
  .filter-row select { padding: 9px 8px; font-size: 14px; }
  #startBtn { padding: 11px; font-size: 15px; }
  .round-panel { display: none; }
  .panel h3 { font-size: 12px; margin-bottom: 8px; }

  /* 题卡 */
  .card { padding: 16px 14px 18px; border-radius: 14px; }
  .stem { font-size: 16.5px; line-height: 1.65; margin-bottom: 14px; }
  .qhead { gap: 6px; margin-bottom: 12px; }
  .badge { font-size: 11px; padding: 3px 8px; }
  .progress-text { font-size: 12px; }

  /* 选项：更大更好点 */
  .opt {
    padding: 14px 13px;
    font-size: 15px;
    line-height: 1.55;
    border-radius: 12px;
  }
  .opt .tick { flex: 0 0 24px; height: 24px; }

  /* 操作按钮：底部吸附，拇指可及 */
  .actions {
    position: sticky;
    bottom: 0;
    z-index: 10;
    gap: 8px;
    margin: 14px -14px -18px;
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
    background: #fff;
    border-top: 1px solid var(--line);
    border-radius: 0 0 14px 14px;
  }
  .actions .primary,
  .actions .ghost {
    flex: 1 1 auto;
    min-height: 44px;
    padding: 11px 12px;
    font-size: 15px;
    text-align: center;
  }
  .actions .primary { flex: 1.4 1 auto; }
  .nav-actions {
    position: static;
    margin: 10px 0 0;
    padding: 0;
    border: none;
    background: transparent;
  }

  /* AI 面板 */
  .ai-body { max-height: 46vh; font-size: 14px; }
  .ai-ask { padding: 8px; }
  .ai-ask input { font-size: 15px; }
  .ai-ask .primary { min-height: 44px; padding: 0 16px; }

  /* 抽屉全屏 */
  .drawer { padding: 0; align-items: flex-end; }
  .drawer-body {
    width: 100%;
    max-height: 92vh;
    border-radius: 16px 16px 0 0;
    padding: 18px 14px calc(18px + env(safe-area-inset-bottom));
  }
  .stats .kpis { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .kpi { padding: 11px; }
  .kpi .v { font-size: 19px; }
  table { font-size: 12.5px; }
  th, td { padding: 7px 4px; }

  /* 登录卡片 */
  .auth { padding: 16px; }
  .auth-card { padding: 22px 18px; }
  input, select { font-size: 16px; } /* 防 iOS 聚焦放大 */
}

@media (max-width: 380px) {
  .topstats { display: none; }
  .stem { font-size: 16px; }
  .actions .ghost { font-size: 14px; padding: 10px 8px; }
}

/* 背题卡片 */
.study-opt { cursor: default; }
.study-opt:hover { border-color: var(--line); background: #fff; }
.study-opt.correct:hover { border-color: var(--ok); background: #eaf7f2; }
.actions .ok-btn { border-color: #b7e3d4; color: var(--ok); font-weight: 600; }
.actions .ok-btn:not(:disabled):hover { background: #eaf7f2; }
.actions .bad-btn { border-color: #f3c3bf; color: var(--bad); font-weight: 600; }
.actions .bad-btn:not(:disabled):hover { background: #fdeeed; }
.actions .ghost:disabled { opacity: .45; cursor: not-allowed; }
.nav-actions .ghost { flex: 1; }


/* AI 输出排版 */
.ai-body h2, .ai-body h3, .ai-body h4, .ai-body h5 { margin: 14px 0 6px; font-size: 15px; line-height: 1.5; }
.ai-body p { margin: 6px 0; }
.ai-body ul { margin: 6px 0 6px 18px; padding: 0; }
.ai-body li { margin: 3px 0; }
.ai-body strong { color: #0f6b57; }
.ai-body code { background: #f1f3f5; padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.ai-body blockquote { margin: 8px 0; padding: 6px 12px; border-left: 3px solid var(--brand); background: #f8fafb; color: #374151; }
/* 背题按钮组：手机上 2x2 排布，避免挤压 */
@media (max-width: 860px) {
  .study-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .study-actions .primary,
  .study-actions .ghost { width: 100%; min-height: 44px; }
  .nav-actions {
    border: none !important;
    background: transparent !important;
    padding: 0 !important;
    margin-top: 10px !important;
    box-shadow: none;
  }
  .nav-actions .ghost { background: #fff; border: 1px solid var(--line); }
}