:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --line: #e4e6eb;
  --text: #111827;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --danger: #b91c1c;
  --danger-bg: #fee2e2;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 18px;
  height: 54px;
  overflow-x: auto;
}

.brand { font-weight: 700; white-space: nowrap; }
.brand span { color: var(--primary); }

.nav { display: flex; gap: 4px; flex: 1; }
.nav a {
  padding: 6px 10px;
  border-radius: 8px;
  color: var(--muted);
  white-space: nowrap;
  font-size: 13px;
}
.nav a:hover { background: #f1f3f5; text-decoration: none; }
.nav a.active { background: #e8f0fe; color: var(--primary); font-weight: 600; }

.userbox { font-size: 13px; color: var(--muted); white-space: nowrap; }
.userbox button { margin-left: 8px; }

.container { max-width: 1180px; margin: 0 auto; padding: 20px 16px 60px; }

h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 15px; margin: 0 0 12px; }
.page-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .sub { color: var(--muted); font-size: 13px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: 1.1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 860px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }

input[type="text"], input[type="password"], input[type="date"], input[type="number"], select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font: inherit;
  color: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--primary); }
textarea { resize: vertical; min-height: 60px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  color: var(--text);
  white-space: nowrap;
}
.btn:hover { background: #f8fafc; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ok { background: var(--ok-bg); border-color: #bbf7d0; color: var(--ok); }
.btn-danger { background: var(--danger-bg); border-color: #fecaca; color: var(--danger); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }
.btn.on { box-shadow: inset 0 0 0 2px var(--primary); font-weight: 600; }

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: #f1f3f5;
  color: var(--muted);
  white-space: nowrap;
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.info { background: #e8f0fe; color: var(--primary); }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.right { margin-left: auto; }
.spacer { flex: 1; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); font-size: 13px; vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
tbody tr:hover { background: #fafbfc; }

.thumb {
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafafa;
  cursor: zoom-in;
}

.q-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; background: #fff; }
.q-card.changed { border-color: #fcd34d; box-shadow: 0 0 0 3px #fef3c7 inset; }
.q-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.q-no { font-weight: 700; }
.q-body { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 760px) { .q-body { grid-template-columns: 1fr; } }
.q-block { background: #fafbfc; border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.q-block h4 { margin: 0 0 6px; font-size: 12px; color: var(--muted); font-weight: 600; }
.q-text { white-space: pre-wrap; word-break: break-word; }
.answer-line { margin-top: 8px; }
.answer-line b { font-weight: 600; }

.kv { display: flex; gap: 6px; align-items: baseline; font-size: 13px; }
.kv .k { color: var(--muted); min-width: 62px; }

.drop {
  border: 1.5px dashed #cbd5e1;
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  background: #fbfcfd;
}
.drop:hover, .drop.over { border-color: var(--primary); background: #f5f9ff; }

.previews { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 8px; margin-top: 10px; }
.previews figure { margin: 0; position: relative; }
.previews img { width: 100%; height: 80px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.previews figcaption { font-size: 11px; color: var(--muted); }
.previews .rm {
  position: absolute; top: 2px; right: 2px; background: rgba(0,0,0,.6); color: #fff;
  border: 0; border-radius: 4px; width: 18px; height: 18px; line-height: 1; cursor: pointer;
}

.toast-wrap { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 999; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #111827; color: #fff; padding: 9px 16px; border-radius: 8px; font-size: 13px; box-shadow: 0 6px 20px rgba(0,0,0,.18); }
.toast.error { background: var(--danger); }
.toast.ok { background: #166534; }

.empty { text-align: center; color: var(--muted); padding: 28px 12px; font-size: 13px; }

.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .n { font-size: 24px; font-weight: 700; line-height: 1.2; }
.stat .l { font-size: 12px; color: var(--muted); }

.dialog-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.55); display: none; align-items: center; justify-content: center; padding: 20px; z-index: 100; }
.dialog-backdrop.show { display: flex; }
.dialog { background: #fff; border-radius: 12px; max-width: 900px; width: 100%; max-height: 88vh; overflow: auto; padding: 14px; }
.dialog img { width: 100%; height: auto; }

/* ---- 公式渲染 ---- */
.math { font-family: "Cambria Math", "Latin Modern Math", "Times New Roman", serif; }
.frac {
  display: inline-flex; flex-direction: column; vertical-align: middle;
  text-align: center; margin: 0 2px; line-height: 1.15; font-size: .92em;
}
.frac .num { border-bottom: 1px solid currentColor; padding: 0 3px; }
.frac .den { padding: 0 3px; }
.sqrt .radicand { border-top: 1px solid currentColor; padding: 0 2px; }
.q-text sup, .q-text sub { font-size: .72em; }

/* ---- 题目裁图 ---- */
.q-crop { margin-bottom: 10px; }
.q-crop img {
  max-width: 100%; max-height: 220px; display: block;
  border: 1px solid var(--line); border-radius: 8px; cursor: zoom-in; background: #fff;
}
.q-crop .small { margin-top: 4px; }

/* ---- 手动裁切 ---- */
.crop-wrap {
  position: relative; display: inline-block; max-width: 100%;
  user-select: none; touch-action: none; cursor: crosshair; line-height: 0;
}
.crop-wrap img { max-width: 100%; max-height: 68vh; display: block; border-radius: 8px; }
.crop-box {
  position: absolute; display: none; pointer-events: none;
  border: 2px solid var(--primary); background: rgba(37, 99, 235, .18);
  box-shadow: 0 0 0 9999px rgba(15, 23, 42, .28);
}

/* ---------------------------------------------------------------- 手机端 */
/* 目标：不出现横向滚动，按钮够大能点，表格不撑破卡片 */
@media (max-width: 720px) {
  body {
    font-size: 14px;
    overflow-x: hidden;      /* 兜底：宁可不显示，也不要整页横向滚 */
  }

  /* 顶栏改成两行：第一行品牌 + 账号，第二行导航横向滑动 */
  .topbar-inner {
    height: auto;
    flex-wrap: wrap;
    gap: 4px;
    padding: 8px 10px 0;
    overflow: visible;
  }
  .brand { font-size: 15px; }
  .userbox { margin-left: auto; font-size: 12px; }
  .userbox button { margin-left: 6px; }
  .nav {
    order: 3;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 2px 0 8px;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { padding: 7px 11px; font-size: 13px; }

  .container { padding: 12px 10px 72px; }
  .card { padding: 12px; overflow-x: auto; }   /* 宽表格在卡片里滚，不撑破页面 */
  h1 { font-size: 18px; }
  h2 { font-size: 14px; }

  .page-head { margin-bottom: 10px; }
  .row { gap: 8px; }
  .field { margin-bottom: 10px; }

  /* iOS 上小于 16px 的输入框会自动放大页面 */
  input[type="text"], input[type="password"], input[type="date"],
  input[type="number"], input[type="search"], select, textarea {
    font-size: 16px;
    padding: 9px 10px;
  }

  .btn { padding: 9px 14px; }
  .btn-sm { padding: 7px 10px; font-size: 12px; }
  .btn-block { width: 100%; justify-content: center; }

  table { font-size: 12px; }
  th, td { padding: 7px 5px; }

  .thumb { max-height: 150px; }
  .previews { grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); }
  .previews img { height: 64px; }
  .previews .rm { width: 22px; height: 22px; right: 2px; }

  .dialog { max-height: 92vh; padding: 10px; border-radius: 10px; }
  .q-card { padding: 10px; }
  .stat { padding: 12px; }
  .stat .n { font-size: 20px; }

  .kv { flex-wrap: wrap; }
  .kv .k { min-width: 56px; }
}

/* 很窄的屏幕（iPhone SE 这类）再收紧一点 */
@media (max-width: 380px) {
  .container { padding: 10px 8px 72px; }
  .card { padding: 10px; }
  .nav a { padding: 6px 8px; font-size: 12px; }
  .btn { padding: 8px 11px; font-size: 13px; }
}
