/* ==========================================================================
   题库网页 —— 样式
   设计目标：手机优先、干净、可长时间阅读；同时适配平板/桌面。
   ========================================================================== */

:root {
  color-scheme: light;
  --bg: #f4f5f9;
  --bg-blur: rgba(244, 245, 249, 0.85);
  --surface: #ffffff;
  --surface-2: #eef1f7;
  --text: #171a21;
  --text-2: #5a6373;
  --text-3: #8b94a4;
  --border: #e4e8ef;
  --border-2: #d2d9e6;
  --brand: #4f46e5;
  --brand-ink: #ffffff;
  --brand-weak: #ecebff;
  --ok: #0d8a4f;
  --ok-bg: #e8f7ef;
  --ok-border: #a8e0c1;
  --warn: #b45309;
  --mark: #ffe58a;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 10px 26px -16px rgba(16, 24, 40, 0.35);
  --radius: 14px;
  --radius-sm: 10px;
  --maxw: 880px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1117;
  --bg-blur: rgba(15, 17, 23, 0.85);
  --surface: #171a22;
  --surface-2: #1f2430;
  --text: #e8ecf4;
  --text-2: #a0a9ba;
  --text-3: #737d8f;
  --border: #262c39;
  --border-2: #333b4b;
  --brand: #8b86ff;
  --brand-ink: #14131f;
  --brand-weak: #23213d;
  --ok: #4ade9a;
  --ok-bg: #12301f;
  --ok-border: #1f5c3c;
  --warn: #fbbf24;
  --mark: #8a6d00;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 12px 30px -18px rgba(0, 0, 0, 0.9);
}

*,
*::before,
*::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Source Han Sans SC", sans-serif;
  font-size: 16px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button { cursor: pointer; }

.wrap {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 16px;
}

/* ------------------------------------------------------------------ 顶栏 */

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg-blur);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

.head-top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0 0;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand .count {
  font-size: 13px;
  color: var(--text-3);
  white-space: nowrap;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  min-width: 36px;
  padding: 0 12px;
  border: 1px solid var(--border-2);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-2);
  font-size: 14px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.icon-btn:hover { color: var(--text); border-color: var(--text-3); }
.icon-btn:active { transform: scale(0.97); }
.icon-btn svg { width: 17px; height: 17px; flex: none; }

/* ------------------------------------------------------------- 搜索框 */

.search-wrap {
  position: relative;
  margin: 12px 0 0;
}

.search-wrap .search-icon {
  position: absolute;
  left: 15px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text-3);
  pointer-events: none;
}

#search {
  width: 100%;
  height: 46px;
  padding: 0 44px 0 44px;
  border: 1px solid var(--border-2);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 16px; /* iOS 小于 16px 会触发自动放大 */
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
  appearance: none;
}

#search::placeholder { color: var(--text-3); }
#search:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent);
}
#search::-webkit-search-cancel-button { -webkit-appearance: none; }

#btnClear {
  position: absolute;
  right: 7px;
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  display: none;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 15px;
  line-height: 1;
}
#btnClear.show { display: flex; }

/* ---------------------------------------------------------- 题型筛选 */

.chips {
  display: flex;
  gap: 8px;
  padding: 12px 0;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }
.chips:empty { display: none; }

.chip {
  flex: none;
  height: 36px;
  padding: 0 15px;
  border: 1px solid var(--border-2);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-2);
  font-size: 14px;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: all 0.15s;
}

.chip .n {
  font-size: 12px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.chip:hover { border-color: var(--text-3); }

.chip[aria-pressed="true"] {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-ink);
  font-weight: 600;
}
.chip[aria-pressed="true"] .n { color: var(--brand-ink); opacity: 0.75; }

.chips.sub {
  padding-top: 0;
  padding-bottom: 12px;
}
.chips.sub .chip {
  height: 30px;
  padding: 0 12px;
  font-size: 13px;
}

/* -------------------------------------------------------------- 工具条 */

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 14px 0 6px;
  font-size: 13px;
  color: var(--text-3);
}

.toolbar .stat { flex: 1; min-width: 120px; }
.toolbar .stat b { color: var(--text); font-weight: 600; }

.link-btn {
  border: 0;
  background: none;
  padding: 4px 2px;
  color: var(--brand);
  font-size: 13px;
  border-radius: 6px;
}
.link-btn:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- 卡片 */

.list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 40px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px 16px 14px;
  scroll-margin-top: 150px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.card:hover { box-shadow: var(--shadow); }

.card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.seq {
  font-size: 12px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.3px;
}

.badge {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 9px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.2px;
}
.badge-single { background: #e8efff; color: #2b4fd8; }
.badge-multiple { background: #e6f7f1; color: #0d7a5f; }
.badge-judge { background: #fff1e3; color: #b25a09; }

:root[data-theme="dark"] .badge-single { background: #1b2450; color: #9db4ff; }
:root[data-theme="dark"] .badge-multiple { background: #10322a; color: #6ee7bf; }
:root[data-theme="dark"] .badge-judge { background: #3a2410; color: #f0b26b; }

.cat-tag {
  font-size: 12px;
  color: var(--text-3);
  padding: 0 2px;
  white-space: nowrap;
}

.card-head .spacer { flex: 1; }

.reveal-btn {
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--border-2);
  border-radius: 999px;
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
  white-space: nowrap;
  transition: all 0.15s;
}
.reveal-btn:hover { border-color: var(--brand); color: var(--brand); }

.stem {
  font-size: 16.5px;
  line-height: 1.75;
  font-weight: 500;
  color: var(--text);
  word-break: break-word;
  white-space: pre-wrap;
}

.stem .q-no {
  color: var(--text-3);
  font-weight: 400;
  margin-right: 2px;
}

/* 选项 */

.options {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.opt {
  display: flex;
  gap: 11px;
  align-items: flex-start;
  padding: 9px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  line-height: 1.65;
  word-break: break-word;
  transition: background 0.15s, border-color 0.15s;
}

.opt .key {
  flex: none;
  width: 24px;
  height: 24px;
  margin-top: 2px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border-2);
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.opt .txt { flex: 1; min-width: 0; }
.opt .tick { display: none; flex: none; margin-top: 3px; width: 18px; height: 18px; color: var(--ok); }

/* 显示答案后的正确项 */
.card.is-revealed .opt.is-correct {
  background: var(--ok-bg);
  border-color: var(--ok-border);
}
.card.is-revealed .opt.is-correct .key {
  background: var(--ok);
  border-color: var(--ok);
  color: #fff;
}
.card.is-revealed .opt.is-correct .tick { display: block; }
.card.is-revealed .opt.is-correct .txt { color: var(--ok); font-weight: 500; }

/* 判断题样式 */
.opt.is-judge .key { display: none; }
.opt.is-judge { padding-left: 12px; }
.opt.is-judge .txt { font-weight: 500; }

/* 答案区 */

.answer {
  display: none;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--border-2);
  font-size: 14.5px;
  line-height: 1.7;
}

.card.is-revealed .answer { display: block; }

.answer .ans-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.answer .label {
  color: var(--text-3);
  font-size: 13px;
  flex: none;
}

.answer .val {
  color: var(--ok);
  font-weight: 700;
  letter-spacing: 0.5px;
}

.answer .exp {
  margin-top: 8px;
  color: var(--text-2);
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
}

.answer .exp .label { margin-right: 6px; }

mark {
  background: var(--mark);
  color: inherit;
  border-radius: 3px;
  padding: 0 1px;
}

/* ---------------------------------------------------------- 空状态/底部 */

.empty {
  text-align: center;
  padding: 64px 20px 80px;
  color: var(--text-3);
  font-size: 15px;
}
.empty .big { font-size: 40px; margin-bottom: 8px; }
.empty .hint { font-size: 13px; margin-top: 6px; }

.to-top {
  position: fixed;
  right: 16px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  box-shadow: var(--shadow);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 25;
}
.to-top.show { display: flex; }
.to-top svg { width: 20px; height: 20px; }

/* ------------------------------------------------------------- 横幅提示 */

.banner {
  display: none;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 12px 0 0;
  padding: 10px 14px;
  border: 1px solid var(--border-2);
  border-left: 3px solid var(--warn);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 13.5px;
  color: var(--text-2);
}
.banner.show { display: flex; }
.banner .grow { flex: 1; min-width: 160px; }

/* ==========================================================================
   管理面板
   ========================================================================== */

.admin {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: var(--bg);
  display: none;
  flex-direction: column;
}
.admin.open { display: flex; }

.admin-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.admin-head h2 { margin: 0; font-size: 17px; flex: 1; }

.admin-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 18px 0 60px;
}

.sect {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.sect h3 {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}
.sect h3 .sub { font-weight: 400; font-size: 12.5px; color: var(--text-3); }

.field { margin-bottom: 12px; }
.field > label {
  display: block;
  font-size: 13px;
  color: var(--text-2);
  margin-bottom: 5px;
  font-weight: 500;
}

.input, .select, .textarea {
  width: 100%;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 9px 12px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 16%, transparent);
}
.textarea { resize: vertical; min-height: 72px; line-height: 1.6; }
.select { height: 40px; padding: 0 10px; }

.row2 { display: flex; gap: 10px; }
.row2 > * { flex: 1; min-width: 0; }

.opt-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.opt-row .letter {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.opt-row .del {
  flex: none;
  width: 30px;
  height: 30px;
  border: 0;
  background: none;
  color: var(--text-3);
  border-radius: 6px;
  font-size: 16px;
}
.opt-row .del:hover { background: var(--surface-2); color: var(--text); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 40px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-2);
  background: var(--surface);
  color: var(--text);
  font-size: 14.5px;
  font-weight: 500;
  transition: all 0.15s;
}
.btn:hover { border-color: var(--text-3); }
.btn:active { transform: scale(0.98); }

.btn.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-ink);
  font-weight: 600;
}
.btn.primary:hover { filter: brightness(1.06); }

.btn.ghost { border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); }

.btn.danger { color: #d33; border-color: var(--border-2); }
.btn.danger:hover { border-color: #d33; background: #fff5f5; }
:root[data-theme="dark"] .btn.danger:hover { background: #2a1414; }

.btn.sm { height: 32px; padding: 0 12px; font-size: 13px; }

.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }

.hint-text { font-size: 12.5px; color: var(--text-3); line-height: 1.6; margin-top: 6px; }

/* 管理列表 */

.q-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
}
.q-row:last-child { border-bottom: 0; }
.q-row .meta { flex: 1; min-width: 0; }
.q-row .q-text {
  font-size: 14.5px;
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.q-row .q-sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.q-row .ops { flex: none; display: flex; gap: 6px; }

.mini {
  height: 30px;
  padding: 0 10px;
  font-size: 13px;
  border-radius: 8px;
  border: 1px solid var(--border-2);
  background: transparent;
  color: var(--text-2);
}
.mini:hover { border-color: var(--text-3); color: var(--text); }

/* Toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  background: #1c1f27;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 90;
  max-width: calc(100% - 40px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ------------------------------------------------------------- 打印 */

@media print {
  .app-header, .toolbar, .to-top, .admin, .toast, .banner { display: none !important; }
  body { background: #fff; }
  .card { break-inside: avoid; box-shadow: none; border-color: #ccc; }
  .card .answer { display: block !important; }
  .reveal-btn { display: none; }
}

/* ------------------------------------------------------------- 小屏微调 */

@media (max-width: 420px) {
  .wrap { padding: 0 12px; }
  .brand h1 { font-size: 18px; }
  .card { padding: 14px 13px 12px; }
  .stem { font-size: 16px; }
  .opt { padding: 8px 10px; }
  .icon-btn .txt-label { display: none; }
  .icon-btn { padding: 0 10px; }
}
