:root {
  --bg: #f4f6fb;
  --card: #fff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #2563eb;
  --primary-soft: #dbeafe;
  --done: #16a34a;
  --done-soft: #dcfce7;
  --late: #d97706;
  --late-soft: #fef3c7;
  --redo: #9333ea;
  --redo-soft: #f3e8ff;
  --none: #dc2626;
  --none-soft: #fee2e2;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  min-height: 100vh;
  overscroll-behavior-y: contain;
}
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }

#app { max-width: 640px; margin: 0 auto; padding-bottom: calc(76px + var(--safe-b)); }
#app.no-tab { padding-bottom: 0; }

/* 顶栏 */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px; min-height: 56px;
  background: rgba(244, 246, 251, .92);
  backdrop-filter: blur(10px);
}
.topbar h1 { font-size: 20px; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .sub { font-size: 13px; color: var(--muted); font-weight: normal; }
.icon-btn {
  border: 0; background: var(--card); border-radius: 12px;
  min-width: 44px; height: 44px; padding: 0 12px;
  font-size: 15px; box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
.icon-btn:active { transform: scale(.96); }

.page { padding: 0 16px 16px; }
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.muted { color: var(--muted); font-size: 14px; }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; line-height: 1.8; }

/* 按钮 / 表单 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 12px; height: 48px; padding: 0 18px;
  background: var(--primary); color: #fff; font-size: 16px; font-weight: 600;
}
.btn:active { opacity: .85; }
.btn.block { width: 100%; }
.btn.ghost { background: var(--primary-soft); color: var(--primary); }
.btn.danger { background: var(--none-soft); color: var(--none); }
.btn.plain { background: #eef0f4; color: var(--text); }
.btn.sm { height: 38px; font-size: 14px; padding: 0 12px; border-radius: 10px; }
.btn[disabled] { opacity: .5; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.input {
  width: 100%; height: 48px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 12px; background: #fff;
  font-size: 16px; outline: none;
}
textarea.input { height: auto; min-height: 96px; padding: 12px 14px; resize: vertical; }
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: #fff; border-radius: 999px;
  height: 36px; padding: 0 14px; font-size: 14px; white-space: nowrap;
}
.chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }

/* 登录 */
.login { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 24px; max-width: 420px; margin: 0 auto; }
.login .logo { width: 72px; height: 72px; margin: 0 auto 12px; display: block; }
.login h2 { text-align: center; margin: 0 0 4px; font-size: 24px; }
.login p.muted { text-align: center; margin: 0 0 28px; }

.seg { display: grid; grid-template-columns: 1fr 1fr; background: #e8ebf2; border-radius: 12px; padding: 4px; margin-bottom: 18px; }
.seg button { border: 0; background: none; height: 40px; border-radius: 9px; font-size: 15px; color: var(--muted); }
.seg button.on { background: #fff; color: var(--primary); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.08); }

/* 作业照片 */
.thumbs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 4px 0 10px; }
.thumb { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: #eef0f4; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-del { position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 50%; border: 0; background: rgba(0,0,0,.55); color: #fff; font-size: 18px; line-height: 24px; padding: 0; }
.stu .pics { position: absolute; bottom: 3px; left: 5px; font-size: 10px; }
.lightbox { position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,.92); display: flex; align-items: center; justify-content: center; animation: fade .15s; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }
.lightbox .lb-tip { position: absolute; bottom: calc(16px + var(--safe-b)); left: 0; right: 0; text-align: center; color: rgba(255,255,255,.6); font-size: 13px; }
.btn-row-left { display: flex; gap: 10px; flex-wrap: wrap; }
.thumb-tag { position: absolute; left: 4px; bottom: 4px; font-size: 11px; font-weight: 600; color: #fff; background: #e11d48; border-radius: 6px; padding: 1px 6px; }
.thumb-tag.todo { background: var(--primary); }
.chip.chip-mark { border-color: #e11d48; color: #e11d48; font-weight: 600; }
.chip.chip-mark.on { background: #e11d48; color: #fff; }
.pic-banner { display: block; width: 100%; text-align: left; border: 0; border-radius: 12px; background: #fff1f2; color: #be123c; padding: 12px 14px; margin-bottom: 12px; font-size: 14px; }
.pic-card { margin-bottom: 0; }
.pic-head { display: flex; align-items: baseline; gap: 6px; margin-bottom: 8px; }
.marked-tip { font-size: 14px; color: #e11d48; font-weight: 600; margin: 6px 0 2px; }
.lightbox .lb-switch { position: absolute; top: calc(16px + env(safe-area-inset-top, 0px)); right: 16px; border: 0; border-radius: 999px; padding: 8px 16px; background: rgba(255,255,255,.9); color: #111; font-size: 14px; font-weight: 600; }

/* 批改编辑器（层级低于弹层 50，确认框才能盖在上面） */
.editor { position: fixed; inset: 0; z-index: 45; background: #111; display: flex; flex-direction: column; color: #fff; }
.ed-top { display: flex; align-items: center; gap: 8px; padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top)); }
.ed-title { flex: 1; text-align: center; font-weight: 600; }
.ed-btn { border: 0; border-radius: 10px; height: 38px; padding: 0 14px; background: rgba(255,255,255,.12); color: #fff; font-size: 15px; }
.ed-btn.primary { background: var(--primary); font-weight: 600; }
.ed-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; position: relative; padding: 4px; }
.ed-stage canvas { max-width: 100%; max-height: 100%; touch-action: none; background: #fff; }
.ed-loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.5); font-size: 15px; }
.ed-tools { padding: 10px 12px calc(12px + var(--safe-b)); display: flex; flex-direction: column; gap: 10px; background: #1c1c1e; }
.ed-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ed-color { width: 32px; height: 32px; border-radius: 50%; border: 3px solid transparent; padding: 0; }
.ed-color.on { border-color: #fff; }
.ed-chip { border: 0; border-radius: 999px; height: 34px; padding: 0 12px; background: rgba(255,255,255,.14); color: #fff; font-size: 14px; }
.ed-chip.danger { color: #fda4af; }

/* 作业附件 */
.atts { margin: 4px 0 10px; }
.atts .thumbs { margin-bottom: 6px; }
.att-pdf { display: flex; align-items: center; gap: 8px; background: #f3f4f6; border-radius: 10px; padding: 10px 12px; margin-bottom: 6px; font-size: 14px; }
.att-pdf a, .att-pdf > span:first-child { flex: 1; min-width: 0; color: var(--primary); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-del { border: 0; background: none; color: var(--none); font-size: 13px; padding: 4px; }

/* 小红花 */
.stu .flower { position: absolute; top: 2px; left: 4px; font-size: 13px; }
.stu .dot { left: auto; right: 6px; top: auto; bottom: 18px; }
.flower-btn { border: 1px solid #fecdd3; background: #fff1f2; color: #e11d48; border-radius: 999px; height: 32px; padding: 0 12px; font-size: 13px; font-weight: 600; flex: none; }
.flower-btn.on { background: #e11d48; border-color: #e11d48; color: #fff; }
.flower-tip { background: #fff1f2; color: #e11d48; font-weight: 600; font-size: 14px; border-radius: 10px; padding: 8px 12px; margin-bottom: 8px; }
.flower-total { flex: none; background: #fff1f2; color: #e11d48; font-weight: 700; border-radius: 999px; padding: 6px 12px; font-size: 15px; }

/* 排行榜 */
.rank-line { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); }
.rank-list { box-shadow: none; }
.rank-list .row { cursor: default; }
.rank-no { width: 32px; text-align: center; font-size: 20px; font-weight: 700; color: var(--muted); flex: none; }
.rank-me { background: #eff6ff; }

/* 学生端 */
.s-action { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.s-state { font-weight: 600; font-size: 15px; }
.s-action .btn.sm { align-self: flex-start; }

/* 作业列表 */
.a-item { display: block; color: inherit; text-decoration: none; }
.a-item:active { background: #f9fafb; }
.a-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 6px; background: var(--primary-soft); color: var(--primary); flex: none; }
.a-title { font-weight: 600; font-size: 16px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.a-date { font-size: 13px; color: var(--muted); flex: none; }
.progress { height: 8px; border-radius: 99px; background: #eef0f4; overflow: hidden; display: flex; margin: 10px 0 8px; }
.progress span { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; color: var(--muted); }
.legend b { font-weight: 600; }
.c-done { color: var(--done); } .c-late { color: var(--late); } .c-redo { color: var(--redo); } .c-none { color: var(--none); }
.bg-done { background: var(--done); } .bg-late { background: var(--late); } .bg-redo { background: var(--redo); }

.date-group { font-size: 13px; color: var(--muted); margin: 16px 4px 8px; }

.fab {
  position: fixed; right: max(20px, calc(50% - 300px)); bottom: calc(88px + var(--safe-b));
  width: 58px; height: 58px; border-radius: 50%; border: 0;
  background: var(--primary); color: #fff; font-size: 30px; line-height: 1;
  box-shadow: 0 6px 16px rgba(37,99,235,.4); z-index: 20;
}
.fab:active { transform: scale(.94); }

/* 作业详情：学生格子 */
.summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; }
.summary div { border-radius: 10px; padding: 8px 0; }
.summary b { display: block; font-size: 20px; }
.summary small { font-size: 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.stu {
  position: relative; border: 2px solid transparent; border-radius: 12px;
  background: #fff; padding: 10px 4px 8px; text-align: center; min-height: 64px;
  box-shadow: 0 1px 2px rgba(0,0,0,.06); user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  transition: transform .08s;
}
.stu:active { transform: scale(.95); }
.stu .no { font-size: 12px; color: var(--muted); }
.stu .nm { font-size: 16px; font-weight: 600; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stu .badge { position: absolute; top: 4px; right: 6px; font-size: 11px; font-weight: 700; }
.stu .dot { position: absolute; top: 6px; left: 6px; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.stu .self { position: absolute; bottom: 3px; right: 4px; font-size: 10px; color: var(--done); opacity: .8; }
.stu.s-done { background: var(--done-soft); border-color: var(--done); }
.stu.s-done .no { color: var(--done); }
.stu.s-late { background: var(--late-soft); border-color: var(--late); }
.stu.s-late .no { color: var(--late); }
.stu.s-redo { background: var(--redo-soft); border-color: var(--redo); }
.stu.s-redo .no { color: var(--redo); }

/* 底部"画笔"工具条 */
.brushbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: #fff; border-top: 1px solid var(--line);
  padding: 10px 12px calc(10px + var(--safe-b));
}
.brushbar .inner { max-width: 640px; margin: 0 auto; }
.brushbar .tip { font-size: 12px; color: var(--muted); text-align: center; margin-bottom: 8px; }
.brushes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.brush { height: 46px; border-radius: 12px; border: 2px solid var(--line); background: #fff; font-weight: 600; font-size: 15px; }
.brush.b-done.on { background: var(--done); border-color: var(--done); color: #fff; }
.brush.b-late.on { background: var(--late); border-color: var(--late); color: #fff; }
.brush.b-redo.on { background: var(--redo); border-color: var(--redo); color: #fff; }
.brush.b-none.on { background: var(--none); border-color: var(--none); color: #fff; }
#app.with-brush { padding-bottom: calc(130px + var(--safe-b)); }

/* 列表行 */
.list { background: #fff; border-radius: var(--radius); overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,.05); }
.row { display: flex; align-items: center; gap: 12px; padding: 0 16px; min-height: 56px; border-bottom: 1px solid #f1f2f5; width: 100%; background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left; color: inherit; text-decoration: none; }
.row:last-child { border-bottom: 0; }
.row:active { background: #f9fafb; }
.row .grow { flex: 1; min-width: 0; }
.row .arrow { color: #c0c4cc; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: flex; align-items: center; justify-content: center; font-weight: 700; flex: none; }
.pill { font-size: 13px; padding: 3px 10px; border-radius: 999px; font-weight: 600; flex: none; }
.pill.none { background: var(--none-soft); color: var(--none); }
.pill.ok { background: var(--done-soft); color: var(--done); }

.searchbox { position: relative; margin-bottom: 12px; }
.searchbox .input { padding-left: 40px; }
.searchbox::before { content: "🔍"; position: absolute; left: 14px; top: 13px; font-size: 16px; opacity: .6; }

.stat-top { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.stat-top b { display: block; font-size: 24px; color: var(--primary); }
.stat-top small { color: var(--muted); font-size: 12px; }

/* 底部导航 */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  display: flex; background: #fff; border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; height: 60px; font-size: 12px; color: var(--muted); text-decoration: none; }
.tabbar a .ti { font-size: 22px; filter: grayscale(1); opacity: .7; }
.tabbar a.on { color: var(--primary); font-weight: 600; }
.tabbar a.on .ti { filter: none; opacity: 1; }

/* 底部弹层 */
.sheet-mask { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 50; animation: fade .15s; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51;
  max-width: 640px; margin: 0 auto; max-height: 88vh; overflow-y: auto;
  background: #fff; border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(16px + var(--safe-b));
  animation: up .2s ease-out;
}
.sheet .handle { width: 40px; height: 5px; border-radius: 3px; background: #d1d5db; margin: 4px auto 12px; }
.sheet h3 { margin: 0 0 14px; font-size: 18px; }
.opt-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.opt { height: 44px; border-radius: 10px; border: 2px solid var(--line); background: #fff; font-size: 15px; }
.opt.on { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.menu .row { padding: 0 4px; }

@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.toast {
  position: fixed; left: 50%; top: 40%; transform: translateX(-50%); z-index: 100;
  background: rgba(17,24,39,.88); color: #fff; padding: 12px 20px; border-radius: 12px;
  font-size: 15px; width: max-content; max-width: 80vw; text-align: center;
}
