:root {
  --bg: #f3f5f8;
  --panel: #ffffff;
  --border: #dfe4ea;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-weak: #dbeafe;
  --danger: #dc2626;
  --line: #ef4444;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── 顶栏 ─────────────────────────────── */
#topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  flex-shrink: 0;
}
.brand { font-weight: 700; font-size: 16px; white-space: nowrap; }
.tb-group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tb-spacer { flex: 1; }
.vsep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }

.btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: #f1f5f9; border-color: #c7d0da; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn.active { background: var(--accent-weak); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.status { font-size: 12px; color: var(--muted); max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sens { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; }
.sens input { width: 90px; accent-color: var(--accent); }
#sensVal { min-width: 24px; }
.qcount { font-size: 12px; color: var(--muted); }
.sel {
  border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 8px; font-size: 13px; background: #fff; color: var(--text);
}
.btn.dir { padding: 6px 9px; }
.btn.dir.active { background: #fef2f2; border-color: #ef4444; color: #ef4444; font-weight: 600; }
#dirV.active { background: #fff7ed; border-color: #f97316; color: #f97316; }

/* ── 主区域 ───────────────────────────── */
#main { flex: 1; display: flex; min-height: 0; }
#canvasWrap { flex: 1; position: relative; overflow: hidden; }
#scroller { position: absolute; top: 0; left: 0; right: 0; bottom: 0; overflow: auto; }
#cv { display: block; margin: 16px auto; box-shadow: 0 2px 12px rgba(0,0,0,.14); background: #fff; cursor: crosshair; touch-action: none; }

#empty {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 10px; text-align: center; color: var(--muted);
}
.empty-icon { font-size: 56px; }
#empty h2 { color: var(--text); font-size: 18px; }
#empty p { font-size: 13px; line-height: 1.9; }

#hint {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  background: rgba(30,41,59,.88); color: #fff;
  font-size: 12px; padding: 6px 14px; border-radius: 20px;
  pointer-events: none; white-space: nowrap;
}

/* ── 右侧题目列表 ─────────────────────── */
#side {
  width: 290px; flex-shrink: 0;
  background: var(--panel);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.side-head {
  padding: 10px 14px; font-weight: 600; font-size: 14px;
  border-bottom: 1px solid var(--border);
}
#qList { flex: 1; overflow-y: auto; padding: 8px; }
.q-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 40px 10px; line-height: 1.8; }
.q-card {
  display: flex; gap: 8px; align-items: center;
  border: 1px solid var(--border); border-radius: 8px;
  padding: 6px; margin-bottom: 8px; background: #fff;
  cursor: pointer; transition: border-color .12s, box-shadow .12s;
}
.q-card:hover { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-weak); }
.q-card.flash { box-shadow: 0 0 0 3px var(--accent); }
.q-thumb { width: 84px; height: 64px; object-fit: contain; border: 1px solid var(--border); border-radius: 4px; background: #fafafa; flex-shrink: 0; }
.q-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.q-label {
  border: 1px solid transparent; border-radius: 4px;
  font-size: 13px; padding: 3px 5px; width: 100%;
  background: transparent; color: var(--text);
}
.q-label:hover, .q-label:focus { border-color: var(--border); background: #fff; outline: none; }
.q-sub { font-size: 11px; color: var(--muted); display: flex; justify-content: space-between; align-items: center; }
.q-del {
  border: none; background: none; color: var(--muted);
  cursor: pointer; font-size: 15px; padding: 2px 4px; border-radius: 4px;
}
.q-del:hover { color: var(--danger); background: #fee2e2; }

@media (max-width: 768px) {
  #side { width: 210px; }
  .q-thumb { width: 56px; height: 48px; }
}

/* ── 选中态与画布内操作条 ───────────────────────── */
#cv { touch-action: none; }
#hint { display: flex; align-items: center; gap: 8px; pointer-events: none; }
#hintOps .hint-btn {
  pointer-events: auto;                /* 容器穿透，按钮可点 */
  border: 1px solid rgba(255,255,255,.35); background: rgba(255,255,255,.12);
  color: #fff; border-radius: 14px; padding: 4px 12px; font-size: 12px; cursor: pointer;
}
#hintOps .hint-btn.danger { background: #dc2626; border-color: #dc2626; }
#hintOps .hint-btn:active { transform: translateY(1px); }

#fab {
  display: none; position: fixed; left: 14px; bottom: 14px; z-index: 200;
  width: 52px; height: 52px; border-radius: 50%; border: none;
  background: var(--accent); color: #fff; font-size: 20px;
  box-shadow: 0 4px 16px rgba(37,99,235,.4); cursor: pointer;
}
#fabBadge {
  position: absolute; top: -4px; right: -4px; min-width: 20px; height: 20px;
  border-radius: 10px; background: #dc2626; color: #fff;
  font-size: 11px; line-height: 20px; padding: 0 5px;
}
.side-grip { display: none; }

/* ── 移动端（≤768px）：顶栏两行+横滚 / 列表底部抽屉 / FAB ── */
@media (max-width: 768px) {
  #topbar {
    flex-direction: column; align-items: stretch; flex-wrap: nowrap;
    padding: 6px 10px; gap: 5px;
  }
  .brand { font-size: 14px; text-align: center; }
  .tb-group {
    flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden;
    -webkit-overflow-scrolling: touch; min-width: 0; max-width: 100%;
    padding-bottom: 2px; gap: 5px;
  }
  .tb-group > * { flex: none; }
  .status { display: none; }               /* 状态文案改走 hint 条 */
  .sens { flex: none; }

  .btn { padding: 8px 11px; min-height: 40px; font-size: 13px; }
  .sel { min-height: 40px; }

  #main { flex-direction: column; }
  #side {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0; width: 100%;
    z-index: 150; transform: translateY(100%); transition: transform .28s ease;
    border-left: none; border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0; box-shadow: 0 -4px 24px rgba(0,0,0,.18);
  }
  #side.open { transform: translateY(0); }
  .side-grip {
    display: flex; justify-content: center; padding: 9px 0 5px; cursor: pointer;
    border-bottom: 1px solid var(--border); touch-action: none;
  }
  .side-grip-bar { width: 42px; height: 4px; border-radius: 2px; background: #c7d0da; }
  #fab { display: block; }

  #hint { bottom: 78px; max-width: 94vw; white-space: normal; }
  #scroller { top: 0; left: 0; right: 0; bottom: 0; }
  #cv { margin: 8px auto; }
  .q-card { padding: 8px; }
  .q-label { font-size: 15px; }
}

/* ── 触屏（coarse 指针）：命中区与控件放大 ── */
@media (pointer: coarse) {
  .btn { min-height: 42px; }
  .q-card { min-height: 64px; }
}

/* ── 微信内置浏览器下载提示条 ── */
#wxTip {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: 14px; z-index: 400; max-width: 92vw;
  display: flex; align-items: center; gap: 10px;
  background: rgba(17,24,39,.94); color: #fff;
  padding: 10px 14px; border-radius: 12px;
  font-size: 13px; line-height: 1.5;
  box-shadow: 0 6px 24px rgba(0,0,0,.3);
}
#wxTip b { color: #fbbf24; }
#wxTipClose {
  flex: none; border: none; border-radius: 8px; padding: 5px 10px;
  background: rgba(255,255,255,.15); color: #fff; font-size: 12px; cursor: pointer;
}

/* ── 导出预览弹窗 ── */
#pvMask {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 300;
  background: rgba(15,23,42,.55);
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
}
#pvPanel {
  background: var(--bg, #fff); border-radius: 14px;
  width: min(920px, 94vw); max-height: 88vh;
  display: flex; flex-direction: column;
  box-shadow: 0 18px 60px rgba(0,0,0,.35); overflow: hidden;
}
.pv-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border, #e5e7eb);
  font-weight: 600; font-size: 15px;
}
.pv-head b { color: var(--accent, #2563eb); }
#pvClose {
  border: none; background: transparent; font-size: 16px;
  cursor: pointer; color: var(--muted, #6b7280); padding: 4px 8px; border-radius: 8px;
}
#pvClose:hover { background: var(--border, #e5e7eb); }
#pvGrid {
  flex: 1; overflow-y: auto; padding: 14px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px; align-content: start;
}
.pv-cell {
  position: relative; border: 1px solid var(--border, #e5e7eb); border-radius: 10px;
  overflow: hidden; background: #fff;
}
.pv-cell canvas { display: block; width: 100%; height: auto; }
.pv-num {
  position: absolute; top: 6px; left: 6px; min-width: 22px; height: 22px;
  border-radius: 11px; background: var(--accent, #2563eb); color: #fff;
  font-size: 12px; line-height: 22px; text-align: center; padding: 0 6px;
  box-shadow: 0 1px 4px rgba(0,0,0,.25);
}
.pv-foot {
  display: flex; align-items: center; justify-content: flex-end; gap: 10px;
  padding: 12px 16px; border-top: 1px solid var(--border, #e5e7eb);
}
.pv-hint { font-size: 12px; color: var(--muted, #6b7280); margin-right: auto; }

@media (max-width: 768px) {
  #pvMask { padding: 0; align-items: flex-end; }
  #pvPanel { width: 100vw; max-height: 92vh; border-radius: 16px 16px 0 0; }
  #pvGrid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; padding: 10px; }
  .pv-foot { padding: 10px 12px; }
  .pv-hint { display: none; }
}

/* ── 预览题号编辑 ── */
.pv-edit-btn {
  border: 1px solid var(--border, #e5e7eb); background: var(--bg, #fff);
  color: var(--muted, #6b7280); border-radius: 14px; padding: 4px 12px;
  font-size: 12px; cursor: pointer; margin-left: auto;
}
.pv-edit-btn.editing { border-color: var(--accent, #2563eb); color: var(--accent, #2563eb); background: rgba(37,99,235,.06); }
.pv-head span { margin-right: 0; }
.pv-cell { display: flex; flex-direction: column; }
.pv-label {
  border: none; border-top: 1px solid var(--border, #e5e7eb);
  padding: 6px 8px; font-size: 13px; text-align: center;
  color: var(--text, #1f2937); background: transparent; outline: none;
  min-width: 0;
}
.pv-label:disabled { color: var(--muted, #6b7280); background: transparent; cursor: default; }
.pv-label:not(:disabled) { background: rgba(37,99,235,.04); border-bottom: 2px solid var(--accent, #2563eb); }
.pv-head { justify-content: flex-start; gap: 10px; }

/* ── 列表题号编辑开关 ── */
.side-head { display: flex; align-items: center; gap: 8px; }
.side-head span { margin-right: 0; }
.side-edit-btn { margin-left: auto; padding: 3px 10px; font-size: 11px; }
.q-label:disabled { color: var(--muted, #6b7280); background: transparent; }
.q-label:not(:disabled) { border-bottom: 2px solid var(--accent, #2563eb); background: rgba(37,99,235,.04); }
