/* 爱学习 阅卷端 - 全局样式
   规范：纯色、无渐变、无 emoji、无 fa 图标字体、SVG矢量图标 */
:root {
  --primary: #2B6CF6;
  --primary-pressed: #1E54C8;
  --primary-disabled: #A9C1FA;
  --success: #22C55E;
  --success-pressed: #16A34A;
  --warning: #F59E0B;
  --warning-pressed: #D97706;
  --danger: #EF4444;
  --danger-pressed: #DC2626;
  --bg: #F5F7FA;
  --card: #FFFFFF;
  --text-main: #1F2937;
  --text-sub: #6B7280;
  --text-aux: #9CA3AF;
  --divider: #E5E7EB;
  --mask: rgba(0,0,0,0.45);
  --annot-red: #E11D48;
  --annot-blue: #2563EB;
  --annot-black: #111827;
  --tap-bg: #F3F4F6;
  --skeleton: #E5E7EB;
  --skeleton-light: #F3F4F6;
  --radius-card: 12px;
  --radius-btn: 8px;
  --radius-input: 8px;
  --radius-tag: 4px;
  --radius-modal: 16px;
  --shadow-card: 0 1px 4px rgba(0,0,0,0.05);
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 22px;
  color: var(--text-main);
  background: var(--bg);
  overscroll-behavior-y: contain;
}
img { max-width: 100%; display: block; }
a { color: var(--primary); text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font-family: inherit; font-size: 15px; color: var(--text-main); }
input:focus, select:focus, textarea:focus { outline: none; }
/* 数字等宽 */
.num { font-family: "SF Mono", Menlo, Consolas, monospace; font-weight: 500; }

/* ---------- 布局 ---------- */
.page { max-width: 560px; margin: 0 auto; min-height: 100vh; background: var(--bg); position: relative; padding-bottom: 84px; }
.page-no-tab { padding-bottom: 24px; }
.navbar {
  position: sticky; top: 0; z-index: 40;
  background: var(--card); border-bottom: 1px solid var(--divider);
  height: 52px; display: flex; align-items: center; padding: 0 16px; gap: 10px;
}
.navbar .title { font-size: 17px; font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.navbar .back, .navbar .side { width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; color: var(--text-main); }
.navbar .side.right { margin-left: auto; }
.padding { padding: 16px; }
.mt-8 { margin-top: 8px; } .mt-12 { margin-top: 12px; } .mt-16 { margin-top: 16px; }
.row { display: flex; align-items: center; }
.gap-8 { gap: 8px; } .gap-12 { gap: 12px; }
.flex-1 { flex: 1; min-width: 0; }
.center { text-align: center; }
.sub { color: var(--text-sub); font-size: 13px; line-height: 20px; }
.aux { color: var(--text-aux); font-size: 11px; line-height: 16px; }
.hide { display: none !important; }

/* ---------- 卡片 ---------- */
.card { background: var(--card); border-radius: var(--radius-card); box-shadow: var(--shadow-card); margin-bottom: 12px; overflow: hidden; }
.card .card-body { padding: 16px; }
.card-title { font-size: 17px; font-weight: 600; line-height: 24px; }
.card-sub { font-size: 13px; color: var(--text-sub); margin-top: 4px; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 44px; padding: 0 20px; border-radius: var(--radius-btn);
  font-size: 15px; font-weight: 500; color: #fff; background: var(--primary);
  transition: transform 0.12s ease, background-color 0.2s ease, opacity 0.15s ease;
  user-select: none;
}
.btn:active { transform: scale(0.97); background: var(--primary-pressed); }
.btn.block { width: 100%; }
.btn:disabled { background: var(--primary-disabled); cursor: not-allowed; }
.btn.ghost { background: var(--card); color: var(--primary); border: 1px solid var(--primary); }
.btn.ghost:active { background: #EEF3FF; }
.btn.secondary { background: var(--card); color: var(--text-main); border: 1px solid var(--divider); }
.btn.secondary:active { background: var(--tap-bg); }
.btn.danger { background: var(--danger); }
.btn.danger:active { background: var(--danger-pressed); }
.btn.warning { background: var(--warning); }
.btn.warning:active { background: var(--warning-pressed); }
.btn.small { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 6px; }
.btn .spin { width: 18px; height: 18px; }

/* ---------- 输入框 ---------- */
.input, .select, .textarea {
  width: 100%; height: 44px; border: 1px solid var(--divider); border-radius: var(--radius-input);
  padding: 0 12px; background: var(--card); transition: border-color 0.2s;
}
.textarea { height: auto; min-height: 88px; padding: 10px 12px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); }
.input-wrap { position: relative; }
.input-wrap .clear { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; color: var(--text-aux); }
.label { font-size: 13px; color: var(--text-sub); display: block; margin-bottom: 6px; }
.field { margin-bottom: 16px; }
.field .error-msg { color: var(--danger); font-size: 13px; margin-top: 4px; }

/* ---------- 标签 ---------- */
.tag { display: inline-flex; align-items: center; height: 20px; padding: 0 8px; border-radius: var(--radius-tag); font-size: 11px; line-height: 16px; }
.tag.default { background: #EEF0F4; color: var(--text-sub); }
.tag.primary { background: #E8F0FE; color: var(--primary); }
.tag.success { background: #E7F8ED; color: #16A34A; }
.tag.warning { background: #FEF3E2; color: #D97706; }
.tag.danger { background: #FDEAEA; color: #DC2626; }

/* ---------- 骨架屏 ---------- */
.skeleton { position: relative; overflow: hidden; background: var(--skeleton); border-radius: 6px; }
.skeleton::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, var(--skeleton-light), transparent);
  animation: sk-sweep 1.2s linear infinite;
}
@keyframes sk-sweep { 0% { transform: translateX(-100%); } 100% { transform: translateX(100%); } }

/* ---------- 环形加载 ---------- */
.spin { display: inline-block; width: 24px; height: 24px; border: 2px solid var(--divider); border-top-color: var(--primary); border-radius: 50%; animation: spin-turn 0.8s linear infinite; }
.spin.sm { width: 20px; height: 20px; border-width: 2px; }
.spin.md { width: 36px; height: 36px; border-width: 3px; }
.spin.lg { width: 48px; height: 48px; border-width: 4px; }
.spin.in-btn { border-top-color: #fff; border-color: rgba(255,255,255,0.5); border-top-color: #fff; }
@keyframes spin-turn { to { transform: rotate(360deg); } }

/* ---------- 三点跳动 ---------- */
.dots { display: inline-flex; gap: 6px; align-items: center; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); animation: dot-bounce 0.4s ease-in-out infinite alternate; }
.dots i:nth-child(2) { animation-delay: 0.13s; }
.dots i:nth-child(3) { animation-delay: 0.26s; }
@keyframes dot-bounce { from { transform: translateY(0); opacity: 0.5; } to { transform: translateY(-6px); opacity: 1; } }

/* ---------- 进度条 ---------- */
.progress { height: 4px; border-radius: 2px; background: var(--divider); overflow: hidden; }
.progress .bar { height: 100%; background: var(--primary); border-radius: 2px; transition: width 0.3s ease; }
.progress.lg { height: 8px; border-radius: 4px; }
.progress .bar.success { background: var(--success); }

/* ---------- 顶部横条 ---------- */
.topbar { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 60; background: var(--divider); }
.topbar .slide { position: absolute; top: 0; left: 0; width: 40%; height: 100%; background: var(--primary); animation: top-slide 1s linear infinite; }
@keyframes top-slide { from { left: -40%; } to { left: 100%; } }

/* ---------- 空/错误状态 ---------- */
.state-box { padding: 48px 24px; text-align: center; }
.state-box .icon { width: 64px; height: 64px; margin: 0 auto 16px; color: var(--text-aux); opacity: 0.6; }
.state-box .title { font-size: 15px; color: var(--text-sub); margin-bottom: 16px; }

/* ---------- 列表 ---------- */
.list-item { display: flex; align-items: center; min-height: 56px; padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--divider); transition: background 0.08s; }
.list-item:active { background: var(--tap-bg); }
.list-item:last-child { border-bottom: none; }

/* ---------- 弹窗 ---------- */
.modal-mask { position: fixed; inset: 0; background: var(--mask); z-index: 100; display: flex; align-items: flex-end; justify-content: center; opacity: 0; pointer-events: none; transition: opacity 0.2s ease; }
.modal-mask.show { opacity: 1; pointer-events: auto; }
.modal {
  width: 100%; max-width: 560px; background: var(--card); border-radius: var(--radius-modal) var(--radius-modal) 0 0;
  padding: 20px 16px 24px; transform: translateY(16px) scale(0.96); opacity: 0; transition: transform 0.2s ease, opacity 0.2s ease;
}
.modal-mask.show .modal { transform: translateY(0) scale(1); opacity: 1; }
.modal .m-title { font-size: 17px; font-weight: 600; text-align: center; margin-bottom: 16px; }
.modal .m-actions { display: flex; gap: 12px; margin-top: 20px; }
.modal .m-actions .btn { flex: 1; }

/* ---------- 提示 toast ---------- */
.toast {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%) scale(0.92);
  background: var(--text-main); color: #fff; border-radius: 10px; padding: 12px 18px;
  font-size: 14px; z-index: 200; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
  max-width: 80%; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }

/* ---------- 图标默认样式 ---------- */
.ic { width: 24px; height: 24px; color: inherit; stroke: currentColor; fill: none; stroke-width: 2; }
.ic.filled { fill: currentColor; stroke: none; }

/* ---------- 底部导航 ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  max-width: 560px; margin: 0 auto; height: 60px; background: var(--card);
  border-top: 1px solid var(--divider); display: flex;
}
.tabbar .tab { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--text-aux); font-size: 11px; }
.tabbar .tab .ic { width: 22px; height: 22px; }
.tabbar .tab.active { color: var(--primary); }
.tabbar .tab:active { opacity: 0.7; }

/* ---------- 阅卷页专用 ---------- */
.grade-stage { position: relative; background: #1F2937; overflow: hidden; }
.grade-stage canvas { width: 100%; display: block; touch-action: none; }
.grade-bottombar { position: sticky; bottom: 0; background: var(--card); border-top: 1px solid var(--divider); padding: 10px 16px; box-shadow: 0 -2px 8px rgba(0,0,0,0.04); }
.score-input-big { height: 52px; font-size: 24px; font-weight: 600; text-align: center; font-family: "SF Mono", Menlo, Consolas, monospace; }
.quick-score { display: flex; gap: 8px; margin-top: 10px; overflow-x: auto; }
.quick-score .qs { flex-shrink: 0; min-width: 56px; height: 40px; border: 1px solid var(--divider); border-radius: 8px; font-size: 15px; color: var(--text-main); background: var(--card); }
.quick-score .qs:active { background: var(--tap-bg); }

/* 阅卷页重写版：图片原生显示 + overlay 批注层（缩放/旋转作用于外层 wrapper） */
.mark-wrap { position: relative; display: inline-block; line-height: 0; transform-origin: center center; }
.mark-wrap img { max-width: 100%; max-height: 60vh; -webkit-user-drag: none; user-select: none; }
.mark-wrap .anno-layer { position: absolute; left: 0; top: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; background: transparent; }

/* 批注工具条 */
.toolbar { display: flex; gap: 4px; padding: 8px 12px; background: var(--card); border-radius: 10px; box-shadow: 0 2px 10px rgba(0,0,0,0.12); }
.toolbar .tool { width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; border-radius: 8px; color: var(--text-main); font-size: 13px; }
.toolbar .tool.active { background: #E8F0FE; color: var(--primary); }
.color-dot { width: 22px; height: 22px; border-radius: 50%; border: 2px solid transparent; }
.color-dot.active { border-color: var(--text-main); }

/* 分割校正 */
.crop-stage { position: relative; background: #fff; border: 1px solid var(--divider); border-radius: 8px; overflow: hidden; }
.crop-stage canvas { width: 100%; display: block; touch-action: none; }
.split-handle { position: absolute; width: 20px; height: 20px; background: rgba(255,255,255,0.9); border: 2px solid var(--primary); border-radius: 50%; transform: translate(-50%, -50%); }

/* 分段标题 */
.sec-title { display: flex; align-items: center; justify-content: space-between; padding: 4px 16px 8px; font-size: 15px; font-weight: 600; }

/* 折叠 */
.acc-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; min-height: 56px; }
.acc-head:active { background: var(--tap-bg); }
.acc-body { padding: 0 16px 16px; }

/* 加载页 */
.loadpage { position: fixed; inset: 0; z-index: 300; background: var(--card); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px; }
.loadpage .logo { width: 80px; height: 80px; border-radius: 20px; background: var(--primary); display: flex; align-items: center; justify-content: center; color: #fff; animation: fade-in 0.4s ease; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ============================================================
   电脑端（桌面）适配：>=900px 时启用
   后台管理页(ax-admin)：容器加宽 + 左侧导航 + 内容自适应
   答题卡上传/模板列表/学情：卡片横向多列利用
   ============================================================ */
@media (min-width: 900px) {
  body { background: var(--bg); }
  .page { max-width: 1200px; padding-bottom: 24px; }
  .page-no-tab { max-width: 1200px; }

  /* 顶层导航更高、光标 */
  .navbar { height: 60px; padding: 0 24px; }
  .navbar .title { font-size: 18px; }
  .navbar .back, .navbar .side { width: 48px; height: 48px; }

  /* 底栏：后台(admin容器)改左侧垂直导航；教师/学生端保持底部导航（收拢到 #page-admin，
     避免 body.ax-admin 全局类泄漏导致师生端在桌面被转成侧边栏遮挡内容） */
  #page-admin .tabbar {
    position: fixed; left: 16px; top: 50%; transform: translateY(-50%);
    width: 200px; height: auto; max-width: 200px; margin: 0;
    flex-direction: column; gap: 4px; padding: 12px 8px;
    border: 1px solid var(--divider); border-radius: 12px;
    box-shadow: var(--shadow-card);
  }
  #page-admin .tabbar .tab {
    flex-direction: row; justify-content: flex-start; gap: 10px;
    height: 44px; padding: 0 12px; border-radius: 8px; font-size: 14px;
  }
  #page-admin .tabbar .tab.active { background: #E8F0FE; }
  #page-admin .tabbar .tab .ic { width: 20px; height: 20px; }
  #page-admin .page { max-width: none; padding-bottom: 32px; }

  /* 教师/学生端桌面仍为底部导航，内容需预留底部空间防止被遮挡 */
  #page-teacher .page, #page-student .page { padding-bottom: 84px; }

  /* 内容卡片自适应列 */
  .padding { padding: 24px; }
  .sec-title { padding: 4px 24px 12px; font-size: 16px; }

  /* 列表行高加大 */
  .list-item { min-height: 64px; padding: 16px 24px; }
  .card .card-body { padding: 20px 24px; }

  /* 答题卡上传：学生卡片两列；模板/任务列表自适应 */
  body.ax-admin .card { margin-bottom: 16px; }
  body.ax-admin #sh-wrap { display: flex; flex-wrap: wrap; gap: 12px; align-items: stretch; }
  body.ax-admin #sh-wrap .card { flex: 1 1 calc(50% - 12px); min-width: 320px; margin-bottom: 0; }
  body.ax-admin #tp-wrap, body.ax-admin #tk-wrap { display: flex; flex-wrap: wrap; gap: 12px; align-items: stretch; }
  body.ax-admin #tp-wrap .card, body.ax-admin #tk-wrap .card { flex: 0 1 calc(50% - 12px); min-width: 340px; margin-bottom: 0; }

  /* 按钮更大 */
  .btn { height: 48px; padding: 0 24px; font-size: 16px; }
  .btn.small { height: 36px; font-size: 14px; padding: 0 16px; }

  /* 阅卷页桌面：图像区居中给足高度，读操作不受影响
     （#page-mark 为路由壳容器；body:not(.ax-admin) 兼容独立入口 ax_mark.php） */
  #page-mark .grade-stage, body:not(.ax-admin) .grade-stage { min-height: 60vh; }
  #page-mark .score-input-big, body:not(.ax-admin) .score-input-big { max-width: 320px; margin: 0 auto; }
  #page-mark .grade-bottombar, body:not(.ax-admin) .grade-bottombar { max-width: 1200px; margin: 0 auto; }
  #page-mark .quick-score, body:not(.ax-admin) .quick-score { justify-content: flex-start; }
}