:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --line: #e6e9f0;
  --text: #1f2937;
  --muted: #6b7280;
  --brand: #3b82f6;
  --brand-dark: #2563eb;
  --up: #10b981;
  --up-dark: #059669;
  --down: #f43f5e;
  --down-dark: #e11d48;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(17, 24, 39, .08), 0 4px 14px rgba(17, 24, 39, .05);
}

* { box-sizing: border-box; }
/* 禁用移动端手势缩放：pan-x pan-y 保留单指滚动、屏蔽双指捏合缩放 */
html, body { margin: 0; padding: 0; touch-action: pan-x pan-y; }
body {
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  /* 触摸优化：去掉点按时的灰色高亮，并关闭双击缩放（双指缩放仍可用） */
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.err { color: var(--down); min-height: 1.2em; margin: 8px 0 0; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: 10px;
  touch-action: pan-x pan-y;
  transition: transform .05s ease, background .15s ease, box-shadow .15s ease;
}
button:active { transform: translateY(1px); }
button.primary {
  background: var(--brand);
  color: #fff;
  padding: 10px 18px;
  font-weight: 600;
}
button.primary:hover { background: var(--brand-dark); }
button.ghost {
  background: #eef1f7;
  color: var(--text);
  padding: 8px 14px;
  font-weight: 500;
}
button.ghost:hover { background: #e2e7f0; }
button.voice-on { background: #e3edff; color: var(--brand-dark); }
button.voice-on:hover { background: #d3e2ff; }
.who-btn { font-size: 13px; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-box.wide { max-width: 560px; width: 100%; }
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-sub { margin: 16px 0 8px; font-size: 14px; color: var(--muted); font-weight: 600; }
.pw-row { display: flex; gap: 8px; }
.pw-row input { flex: 1; min-width: 0; }
.pw-row button { flex: none; }
.hint { min-height: 1.2em; margin: 10px 0 0; color: var(--muted); font-size: 13px; }
.login-box .small { font-size: 12px; margin: 10px 0 0; }
.login-box a { color: var(--brand); text-decoration: none; }
.login-box a:hover { text-decoration: underline; }
button.danger-ghost { color: var(--down); background: #fdeef0; }
button.danger-ghost:hover { background: #fbd9dd; }
.icon-btn { background: transparent; color: var(--muted); font-size: 14px; width: 26px; height: 26px; border-radius: 6px; }
.icon-btn:hover { background: #eef1f7; color: var(--text); }
.icon-btn.danger:hover { background: #fdeef0; color: var(--down); }

input {
  font-family: inherit;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  background: #fff;
  color: var(--text);
  touch-action: pan-x pan-y;
}
input:focus { outline: none; border-color: var(--brand); }

/* 登录 */
#login {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #dbeafe, #f4f6fb);
  z-index: 100;
}
.login-box {
  background: var(--card);
  padding: 40px 36px;
  border-radius: 20px;
  box-shadow: var(--shadow);
  width: min(340px, 92vw);
  text-align: center;
}
.login-box h1 { margin: 0 0 6px; font-size: 24px; }
.login-box input { width: 100%; margin: 16px 0 12px; }
.login-box button { width: 100%; }

/* 伪装成账号框，只用来告诉浏览器密码管理器「用户名在这里」，
   避免它把密码本身当成用户名显示在保存提示里。离屏 + 透明，用户看不到也点不到。 */
.autofill-decoy {
  position: absolute;
  left: -9999px;
  top: 0;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  opacity: 0;
  pointer-events: none;
}
input.masked { -webkit-text-security: disc; }

/* 顶栏 */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.brand { font-size: 18px; font-weight: 700; min-width: 0; }
.sync-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  vertical-align: middle;
  margin-left: 8px;
  background: #e7f8f1;
  color: var(--up-dark);
  transition: background .2s ease, color .2s ease;
}
.sync-status::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}
.sync-status.syncing { background: #fef3c7; color: #b45309; }
.sync-status.offline { background: #f1f5f9; color: #64748b; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.backup-wrap { position: relative; flex: none; }
.backup-wrap > .ghost { display: inline-flex; align-items: center; gap: 6px; }
.backup-wrap > .ghost span { font-size: 11px; }
.backup-wrap > .ghost[aria-expanded="true"] { background: #e3edff; color: var(--brand-dark); }
.backup-menu { position: absolute; top: calc(100% + 6px); left: 0; z-index: 40; min-width: 142px; padding: 4px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); box-shadow: 0 10px 24px rgba(17, 24, 39, .14); }
.backup-menu button { display: block; width: 100%; min-height: 40px; padding: 9px 11px; background: transparent; color: var(--text); text-align: left; white-space: nowrap; font-size: 13px; }
.backup-menu button:hover, .backup-menu button:focus-visible { background: #eef4ff; color: var(--brand-dark); }

/* 布局 */
.layout {
  display: grid;
  grid-template-columns: 260px 1fr 320px;
  gap: 16px;
  padding: 16px 20px;
  align-items: start;
  max-width: 1600px;
  margin: 0 auto;
}
@media (max-width: 1100px) {
  .layout { grid-template-columns: 220px 1fr; }
  .right { grid-column: 1 / -1; }
}
/* 移动端班级切换下拉（桌面端隐藏）；在 720px 媒体查询中显示 */
.mobile-class-select { display: none; }
/* 移动端：班级弹窗相关（桌面端隐藏） */
#btn-classes { display: none; }
.class-close { display: none; margin-left: auto; }
.class-backdrop { display: none; }
/* 触屏/粗指针设备（无 hover）：始终显示班级条目的编辑/删除按钮 */
@media (hover: none), (pointer: coarse) {
  .class-list .class-item .tools { opacity: 1; visibility: visible; pointer-events: auto; }
}

.right {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}
@media (min-width: 721px) and (max-width: 1100px) {
  .right { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .right .panel { min-width: 0; }
  .right .history-panel { display: flex; flex-direction: column; min-height: 0; }
  .right .history-panel > .panel-head { flex: none; }
  .right .history-panel > .history { flex: 1 1 0; height: 0; min-height: 0; max-height: none; }
  .right .history-panel .hist-item { flex-shrink: 0; }
}

.sidebar, .right .panel, .main {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.sidebar { padding: 14px; overscroll-behavior: contain; }
.panel { padding: 14px; }
.panel-head {
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 12px;
  display: flex; align-items: center; gap: 8px;
}
.new-class { display: flex; gap: 8px; }
.new-class input { flex: 1 1 0; min-width: 0; width: 100%; }
.new-class #btn-add-class { flex: 0 0 40px; padding: 0; min-height: 40px; font-size: 20px; }

/* 班级列表 */
.class-list { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.class-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px;
  min-height: 46px; /* 固定高度，防止 hover 显示操作按钮时改变行高导致整页抖动/闪烁 */
  border-radius: 10px;
  cursor: pointer;
  background: #f6f8fc;
}
.class-item:hover { background: #eef1f7; }
.class-item.active { background: #e3edff; color: var(--brand-dark); font-weight: 600; }
.class-item .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.class-item .tools {
  display: flex; gap: 2px; flex: none;
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity .12s ease;
}
.class-item:hover .tools { opacity: 1; visibility: visible; pointer-events: auto; }
.empty { color: var(--muted); text-align: center; padding: 20px 0; font-size: 14px; }

/* 记分板 */
.main { padding: 20px; min-height: 70vh; }
.board-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 10px; }
.board-title { margin: 0; font-size: 20px; }
.board-actions { display: flex; gap: 10px; }
.board { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }

/* 全班加减分操作栏 */
.class-score {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 12px;
  margin-bottom: 14px;
  background: #f6f8fc;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.class-score.disabled { opacity: .5; pointer-events: none; }
.class-score .cs-label { flex: none; font-size: 14px; font-weight: 700; color: var(--brand-dark); }
.class-score .cs-quick { display: flex; gap: 6px; flex: 1 1 auto; }
.class-score .cs-quick .qbtn { flex: 0 1 62px; min-width: 46px; }
.class-score .cs-custom { display: flex; gap: 6px; margin-left: auto; }
.class-score .cs-custom input { width: 88px; padding: 8px 10px; font-size: 13px; }
.class-score .cs-custom button { padding: 8px 14px; background: var(--brand); color: #fff; font-weight: 600; border-radius: 8px; }
.class-score .cs-custom button:hover { background: var(--brand-dark); }

.group-card {
  position: relative;
  border: 1px solid var(--line);
  border-left: 3px solid var(--c, #5B9BD5);
  border-radius: 14px;
  padding: 12px;
  min-width: 0;
  background: #fff;
  box-shadow: 0 2px 8px rgba(17, 24, 39, .04);
  display: flex; flex-direction: column; gap: 8px;
}
.group-head { display: flex; align-items: center; gap: 7px; min-height: 24px; }
.group-head .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c, #5B9BD5); flex: none; }
.group-head .gname { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-meta { position: relative; display: flex; justify-content: flex-end; align-items: center; flex: none; min-width: 76px; height: 24px; }
.group-tools { position: absolute; inset: 0; display: flex; justify-content: flex-end; align-items: center; background: #fff; opacity: 0; pointer-events: none; }
.group-tools .icon-btn { width: 24px; height: 24px; padding: 0; font-size: 14px; }
.group-card:hover .group-tools, .group-card:focus-within .group-tools { opacity: 1; pointer-events: auto; }
.group-card:hover .school-rank, .group-card:focus-within .school-rank { opacity: 0; }
@media (hover: none) and (min-width: 721px) {
  .group-meta { min-width: 150px; padding-right: 76px; }
  .group-tools { left: auto; width: 72px; opacity: 1; pointer-events: auto; }
  .group-card:hover .school-rank, .group-card:focus-within .school-rank { opacity: 1; }
}
.group-score-row { display: flex; align-items: center; gap: 8px; }
.group-score-row .gscore { flex: 1; min-width: 0; }
.gscore { font-size: 36px; line-height: 1.2; font-weight: 800; text-align: center; letter-spacing: .5px; }
.school-rank {
  position: static;
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0;
  font-size: 11px;
  font-weight: 500;
  line-height: 1;
  color: var(--muted);
  white-space: nowrap;
}
.school-rank .rk-medal { font-size: 13px; line-height: 1; }
.school-rank.rk1 { color: #a16207; }
.school-rank.rk2 { color: #475569; }
.school-rank.rk3 { color: #9a3412; }
.group-card .quick { gap: 5px; }
.group-card .qbtn { min-height: 32px; padding: 5px 0; font-size: 13px; border-radius: 7px; }
.quick { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.qbtn { padding: 8px 0; font-weight: 600; font-size: 14px; border-radius: 8px; }
.qbtn.up { background: #e7f8f1; color: var(--up-dark); }
.qbtn.up:hover { background: #d0f0e2; }
.qbtn.down { background: #fdeef0; color: var(--down-dark); }
.qbtn.down:hover { background: #fbdcdf; }

/* 排行榜 */
.leaderboard { display: flex; flex-direction: column; gap: 8px; }
.lb-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; background: #f6f8fc; }
.lb-item .rank { width: 32px; flex: none; text-align: center; font-weight: 700; color: var(--muted); }
.lb-item.rank1 { background: #fdf1cf; border: 1px solid #f2d281; }
.lb-item.rank2 { background: #eef1f6; border: 1px solid #d3d9e3; }
.lb-item.rank1 .rank { color: #b45309; }
.lb-item.rank2 .rank { color: #64748b; }
.lb-item.rank3 .rank { color: #92400e; }
.lb-item .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c); flex: none; }
.lb-item .lb-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-item .lb-score { font-weight: 700; }
.lb-toggle {
  margin-left: auto;
  display: flex;
  background: #eef1f7;
  border-radius: 8px;
  padding: 2px;
}
.lb-toggle button {
  background: transparent;
  border: none;
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 6px;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}
.lb-toggle button.on {
  background: #fff;
  color: var(--text);
  box-shadow: var(--shadow);
}

/* 记录 */
.history { display: flex; flex-direction: column; gap: 6px; max-height: 420px; overflow-y: auto; }
.hist-item { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 8px; background: #f8fafc; font-size: 13px; }
.hist-delta { font-weight: 700; width: 30px; text-align: center; }
.hist-delta.pos { color: var(--up-dark); }
.hist-delta.neg { color: var(--down-dark); }
.hist-group { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.hist-group.batch { color: var(--brand-dark); font-weight: 600; }
.hist-reason { flex: 1; min-width: 0; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-time { color: var(--muted); font-size: 11px; flex: none; }

/* 投屏 */
#projector {
  position: fixed; inset: 0;
  background: linear-gradient(160deg, #0f172a, #1e293b);
  color: #fff;
  display: flex; flex-direction: column;
  padding: 30px 40px;
  z-index: 50;
}
.close-btn {
  position: absolute; top: 20px; right: 24px;
  background: rgba(255,255,255,.12); color: #fff;
  padding: 10px 16px; font-size: 15px;
}
.close-btn:hover { background: rgba(255,255,255,.2); }
.proj-tools { position: absolute; top: 20px; right: 24px; display: flex; gap: 10px; z-index: 2; }
.proj-tools .close-btn { position: static; }
.proj-tools { align-items: center; flex-wrap: wrap; }
.proj-tools .sync-status { margin-left: 0; white-space: nowrap; }
.close-btn.voice-on { background: rgba(59,130,246,.5); }
.close-btn.voice-on:hover { background: rgba(59,130,246,.65); }
.projector-title { font-size: 30px; font-weight: 800; text-align: center; margin-bottom: 24px; }
.projector-board {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;   /* 滚到底后不要把滚动传给背后的页面 */
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 20px;
  align-content: start;
  padding-bottom: 8px;
}
.proj-card {
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.14);
  border-top: 6px solid var(--c);
  border-radius: 18px;
  padding: 20px;
  text-align: center;
  user-select: none;              /* 长按计分时不会选中文字 */
  -webkit-user-select: none;
}
.proj-card .p-name { font-size: 22px; font-weight: 600; }
.proj-card .p-score { font-size: 64px; font-weight: 800; margin-top: 8px; }
.proj-card .p-actions { display: flex; gap: 10px; justify-content: center; margin-top: 14px; }
.proj-card .pbtn {
  font-size: 20px;
  font-weight: 800;
  padding: 10px 20px;
  border-radius: 10px;
  border: 1px solid transparent;
  min-width: 74px;
}
.proj-card .pbtn.plus { background: rgba(16,185,129,.18); color: #6ee7b7; border-color: rgba(16,185,129,.38); }
.proj-card .pbtn.plus:hover { background: rgba(16,185,129,.3); }
.proj-card .pbtn.minus { background: rgba(244,63,94,.18); color: #fda4af; border-color: rgba(244,63,94,.38); }
.proj-card .pbtn.minus:hover { background: rgba(244,63,94,.3); }

/* 拖拽调序 */
.group-card { user-select: none; }
.group-card input { user-select: text; }
.drag-handle {
  cursor: grab;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  color: var(--muted);
  font-size: 15px;
}
.drag-handle:hover { background: #eef1f7; color: var(--text); }
.drag-handle:active { cursor: grabbing; }
.group-card.dragging {
  opacity: .72;
  position: relative;
  z-index: 10;
  box-shadow: 0 12px 26px rgba(17, 24, 39, .18);
}
#board.reordering { touch-action: none; }

/* 弹窗 */
.modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(0, 0, 0, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
/* 弹窗打开期间锁住背后的页面：窗口里的滚动区滚到头时，滚轮/触摸不会再带着整页一起滚 */
body.modal-open { overflow: hidden; }
.modal, .modal-box { overscroll-behavior: contain; }
.roster-body, .roster-nav, .ri-body, .ri-preview { overscroll-behavior: contain; }
.modal-box {
  background: var(--card);
  border-radius: 16px;
  box-shadow: 0 18px 40px rgba(17, 24, 39, .25);
  padding: 24px;
  width: min(380px, 100%);
}
.modal-box h3 { margin: 0 0 10px; font-size: 18px; }
.site-settings-box { width: min(360px, 100%); padding: 20px; }
.site-settings-box .modal-head h3 { margin: 0; font-size: 18px; }
.site-settings-box .modal-head .icon-btn { width: 28px; height: 28px; }
.site-settings-section { margin-top: 18px; padding: 14px; border: 1px solid #edf0f6; border-radius: 12px; background: #f7f9fc; }
.site-settings-section h4 { margin: 0 0 12px; font-size: 14px; font-weight: 600; }
.site-settings-range { display: flex; gap: 3px; padding: 3px; border-radius: 9px; background: #e9edf5; margin-bottom: 12px; }
.site-settings-range button { flex: 1; padding: 7px 4px; background: transparent; color: var(--muted); border-radius: 7px; font-size: 13px; }
.site-settings-range button[aria-pressed="true"] { background: #fff; color: var(--text); font-weight: 600; box-shadow: 0 1px 3px #1f293715; }
.site-settings-date input { display: block; min-width: 0; width: 100%; height: 40px; padding: 8px 10px; border-radius: 8px; background: #fff; font-size: 16px; }
.site-settings-date input:disabled { background: #f0f3f8; color: #9aa3b2; cursor: default; }
.site-settings-box .site-settings-hint { margin: 10px 0 0; font-size: 12px; line-height: 1.5; color: var(--muted); }
.site-settings-box .err:empty { display: none; }
.site-settings-box .modal-actions { margin-top: 16px; gap: 8px; }
.site-settings-box .modal-actions button { flex: none; min-width: 76px; min-height: 36px; padding: 8px 18px; font-size: 13px; border-radius: 8px; }
.site-settings-box .modal-actions .primary { min-width: 96px; }
.modal-box p { margin: 0 0 12px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.modal-box input[type="password"] { width: 100%; margin: 6px 0 10px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }
.modal-actions button { flex: 1; padding: 10px 0; }
/* 退出登录放在账号弹窗底部，单独一段 + 分隔线，和上面的保存操作区分开 */
.modal-foot { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.modal-logout {
  display: flex; align-items: center; justify-content: center;
  width: 100%; min-height: 44px; padding: 11px 0;
  font-size: 14px; font-weight: 600; border-radius: 10px;
}
button.primary.danger { background: var(--down); }
button.primary.danger:hover { background: var(--down-dark); }

/* 防止移动端输入框聚焦时 iOS 自动放大整个页面：移动端所有输入元素字号 >= 16px */
html { -webkit-text-size-adjust: 100%; }

/* ---------------- 班级名单弹窗 ---------------- */
.modal-box.roster-box {
  width: min(760px, 100%);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  padding: 18px 20px 14px;
}
.roster-box h3 { margin: 0; font-size: 19px; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; flex: 1 1 auto; min-width: 0; }
.roster-box .modal-head { gap: 10px; align-items: flex-start; }
.roster-box .modal-head .icon-btn { flex: none; }
.roster-sub { font-size: 12.5px; color: var(--muted); font-weight: 400; }
.roster-tools { display: flex; gap: 8px; margin: 12px 0 0; flex-wrap: wrap; align-items: center; }
.roster-tools button { white-space: nowrap; }
.roster-search { flex: 1 1 200px; display: flex; align-items: center; gap: 8px; background: #f5f7fb; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; min-width: 0; }
.roster-search span { color: #9aa3b2; font-size: 13px; }
.roster-search input { flex: 1; min-width: 0; border: 0; background: none; padding: 0; font-size: 13.5px; outline: none; color: var(--text); }
/* 常驻快速添加条：选一次组，然后一直敲名字回车 */
.roster-quick { margin: 10px 0 0; background: linear-gradient(180deg, #f2f7ff, #eef4ff); border: 1px solid #cfe0fb; border-radius: 13px; padding: 10px 11px 9px; }
.rq-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.rq-chip { display: inline-flex; align-items: center; gap: 6px; background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 5px 11px; font-size: 12.5px; color: #4b5563; }
.rq-chip i { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.rq-chip.on { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; box-shadow: 0 2px 6px rgba(59, 130, 246, .35); }
.rq-chip.on i { background: #fff !important; }
.rq-n { font-size: 11px; opacity: .8; font-weight: 700; }
.rq-row { display: flex; gap: 8px; }
.rq-row input { flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; font-size: 14px; background: #fff; outline: none; color: var(--text); }
.rq-row input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(59, 130, 246, .14); }
.rq-row button { flex: none; padding: 9px 18px; }
.rq-hint { display: flex; align-items: center; gap: 8px; margin-top: 7px; font-size: 11.5px; color: #5b6472; }
.rq-undo { margin-left: auto; color: var(--brand-dark); font-weight: 600; background: #fff; border: 1px solid #cfe0fb; border-radius: 8px; padding: 4px 10px; font-size: 11.5px; flex: none; }
/* 主体：左边组导航 + 右边名单 */
.roster-main { flex: 1; min-height: 0; display: grid; grid-template-columns: 148px minmax(0, 1fr); gap: 12px; margin-top: 10px; }
.roster-nav { display: flex; flex-direction: column; gap: 2px; background: #f8fafd; border: 1px solid var(--line); border-radius: 12px; padding: 6px; overflow-y: auto; }
.rn-title { font-size: 11.5px; color: var(--muted); padding: 4px 8px 6px; }
.rn-item { display: flex; align-items: center; gap: 8px; padding: 7px 9px; border-radius: 9px; font-size: 13px; color: #374151; text-align: left; }
.rn-item i { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.rn-item span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rn-item b { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.rn-item:hover { background: #eef2f9; }
.rn-item.on { background: #fff; box-shadow: var(--shadow); color: var(--brand-dark); font-weight: 600; }
.rn-item.on b { color: var(--brand-dark); }
.roster-body { min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding-right: 2px; }
.roster-empty { color: var(--muted); font-size: 14px; line-height: 1.8; padding: 16px 2px; }
.roster-group { border: 1px solid var(--line); border-left: 5px solid var(--c, #cbd5e1); border-radius: 13px; background: #fff; }
.roster-group.search-dim { opacity: .45; }
.rg-head { display: flex; align-items: center; gap: 8px; padding: 9px 12px; background: #fbfcfe; border-radius: 12px 8px 0 0; border-bottom: 1px solid #f1f4f9; position: sticky; top: 0; z-index: 3; flex-wrap: wrap; }
.rg-dot { width: 11px; height: 11px; border-radius: 50%; flex: none; background: var(--c, #cbd5e1); }
.rg-name { font-weight: 700; font-size: 15px; }
.rg-count { font-size: 11.5px; font-weight: 600; color: #4b5563; background: #eef1f7; border-radius: 999px; padding: 2px 9px; flex: none; }
.rg-score { font-size: 11.5px; font-weight: 600; color: var(--brand-dark); background: #eef4ff; border-radius: 999px; padding: 2px 9px; flex: none; }
.rg-btns { margin-left: auto; display: flex; gap: 6px; flex: none; }
.rg-add { font-size: 12.5px; font-weight: 600; color: var(--brand-dark); background: #fff; border: 1px solid #cfe0fb; border-radius: 9px; padding: 6px 12px; flex: none; white-space: nowrap; }
.rg-add:hover { background: #eef4ff; }
.rg-import { font-size: 12.5px; font-weight: 600; color: #4b5563; background: #fff; border: 1px solid var(--line); border-radius: 9px; padding: 6px 12px; flex: none; white-space: nowrap; }
.rg-import:hover { background: #eef4ff; border-color: #cfe0fb; color: var(--brand-dark); }
.rg-rows { display: flex; flex-direction: column; }
.rg-none { color: var(--muted); font-size: 12.5px; padding: 10px 12px; }
.stu-row { display: flex; align-items: center; gap: 10px; padding: 8px 12px; position: relative; border-top: 1px solid #f1f4f9; }
.stu-row:first-child { border-top: 0; }
.stu-row:hover { background: #f8fbff; }
.stu-row.menu-open { background: #f4f8ff; }
.stu-row.search-hidden, .rg-none.search-hidden { display: none; }
.stu-row.dragging { background: #eef4ff; box-shadow: 0 10px 22px rgba(17, 24, 39, .16); z-index: 4; }
.stu-grip { color: #cdd4de; font-size: 13px; line-height: 1; padding: 6px 2px; cursor: grab; touch-action: none; flex: none; }
.stu-grip, .stu-more { background: transparent; }
.stu-grip:hover { color: var(--muted); }
.stu-av { width: 32px; height: 32px; border-radius: 50%; background: var(--c, #94a3b8); color: #fff; font-size: 13.5px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.stu-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.stu-more { width: 34px; height: 32px; border-radius: 9px; color: #7b8697; font-size: 17px; line-height: 1; flex: none; }
.stu-more:hover, .stu-more.on { background: #eef1f7; color: var(--text); }
/* 行内小浮层：贴着这一行，不再把下面的学生整体顶下去 */
.stu-menu { position: absolute; right: 10px; top: calc(100% - 4px); z-index: 9; width: 268px; max-width: calc(100vw - 64px); background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 14px 32px rgba(17, 24, 39, .18); padding: 10px; }
.stu-menu.up { top: auto; bottom: calc(100% - 4px); }
.sm-grp { font-size: 11.5px; color: var(--muted); margin: 0 0 6px; }
.sm-row { display: flex; gap: 7px; }
.sm-row + .sm-grp { margin-top: 9px; }
.sm-row input, .sm-row select { flex: 1; min-width: 0; padding: 8px 10px; font-size: 13.5px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--text); outline: none; }
.sm-row input:focus, .sm-row select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(59, 130, 246, .14); }
.sm-row button { flex: none; padding: 8px 13px; font-size: 13px; }
/* ---------------- 批量导入到小组 ---------------- */
/* 打开导入面板时把「快速添加条」收起来，让注意力集中在这一件事上 */
.roster-box.importing #roster-quick { display: none; }
/* flex:none 很关键：不要被名单区挤扁；高度按内容长，长名单只滚面板中间，名单区留出约两百像素看上下文 */
.roster-import-panel { margin: 10px 0 0; background: #fff; border: 1px solid #cfe0fb; border-radius: 13px; box-shadow: 0 6px 20px rgba(17, 24, 39, .10); overflow: hidden; display: flex; flex-direction: column; max-height: 52vh; flex: none; }
.ri-head { display: flex; align-items: center; gap: 9px; padding: 10px 12px; background: linear-gradient(180deg, #f2f7ff, #eef4ff); border-bottom: 1px solid #dce8fb; flex-wrap: wrap; }
.ri-bar { width: 4px; height: 18px; border-radius: 2px; background: var(--c, var(--brand)); flex: none; }
.ri-title { font-size: 14.5px; font-weight: 700; }
.ri-lock { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; background: #fff; border: 1px solid #cfe0fb; border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: 600; color: #374151; }
.ri-lock i { width: 9px; height: 9px; border-radius: 50%; background: var(--c, var(--brand)); flex: none; }
.ri-lock button { color: var(--brand-dark); font-weight: 600; text-decoration: underline; font-size: 12px; }
.ri-close { width: 30px; height: 30px; border-radius: 9px; color: #8b95a5; font-size: 15px; line-height: 1; flex: none; }
.ri-close:hover { background: #eef1f7; color: var(--text); }
.ri-steps { display: flex; gap: 6px; padding: 9px 12px 0; flex-wrap: wrap; }
.ri-steps button { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); background: #f4f6fb; border-radius: 999px; padding: 5px 11px; }
.ri-steps button i { font-style: normal; width: 16px; height: 16px; border-radius: 50%; background: #dbe2ec; color: #5b6472; font-size: 10.5px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.ri-steps button.on { background: var(--brand); color: #fff; font-weight: 600; }
.ri-steps button.on i { background: rgba(255, 255, 255, .28); color: #fff; }
.ri-steps button.done i { background: #e9f7f1; color: var(--up-dark); }
/* 名单太长时只滚面板中间，步骤条和按钮始终看得到 */
.ri-body { padding: 11px 12px 3px; flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.ri-foot { display: flex; align-items: center; gap: 8px; padding: 11px 12px 12px; flex-wrap: wrap; flex: none; border-top: 1px solid #f1f4f9; position: relative; }
/* 内容被截断时给一条渐隐，看起来是「下面还有」而不是排版坏了 */
.ri-foot::before { content: ''; position: absolute; left: 0; right: 0; top: -18px; height: 18px; background: linear-gradient(rgba(255, 255, 255, 0), #fff); pointer-events: none; }
.ri-foot .ri-gap { margin-left: auto; }
.ri-foot button { padding: 9px 14px; font-size: 13px; font-weight: 600; border-radius: 9px; }
.ri-foot button:disabled { opacity: .55; cursor: not-allowed; }
.ri-tip { margin: 9px 0 0; font-size: 11.5px; color: var(--muted); line-height: 1.6; }
/* 第一步：选目标组 */
.ri-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.ri-chip { display: inline-flex; align-items: center; gap: 6px; background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: 12.5px; color: #4b5563; }
.ri-chip i { width: 8px; height: 8px; border-radius: 50%; background: var(--c, #94a3b8); flex: none; }
.ri-chip small { font-size: 11px; color: #9aa3b2; }
.ri-chip.on { background: var(--c, var(--brand)); border-color: var(--c, var(--brand)); color: #fff; font-weight: 600; }
.ri-chip.on small, .ri-chip.on b { color: rgba(255, 255, 255, .9); }
/* 第二步：粘贴 + 实时解析 */
.ri-paste { background: #f7f9fc; border: 1px solid var(--line); border-radius: 11px; padding: 10px; }
.ri-ph { display: flex; align-items: baseline; gap: 8px; margin-bottom: 7px; flex-wrap: wrap; }
.ri-ph span { font-size: 11.5px; color: var(--muted); }
.ri-paste textarea { width: 100%; min-height: 132px; font-family: inherit; font-size: 14px; line-height: 1.75; border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; resize: vertical; background: #fff; color: var(--text); outline: none; }
.ri-paste textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(59, 130, 246, .14); }
.ri-tools { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.ri-tools button { padding: 7px 12px; font-size: 12.5px; border-radius: 8px; }
.ri-parse { margin-top: 10px; background: #fff; border: 1px solid var(--line); border-radius: 11px; padding: 10px; }
.ri-psum { font-size: 13px; font-weight: 600; }
.ri-psum b { font-variant-numeric: tabular-nums; }
.ri-psum b.ok { color: var(--up-dark); }
.ri-psum b.warn { color: #b45309; }
.ri-names { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.ri-nm { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; border-radius: 999px; padding: 4px 10px; border: 1px solid transparent; }
.ri-nm small { font-size: 10.5px; font-weight: 600; }
.ri-nm.new { background: #eef4ff; border-color: #cfe0fb; color: var(--brand-dark); font-weight: 600; }
.ri-nm.other, .ri-nm.same { background: #fff6e7; border-color: #f7dcae; color: #b45309; }
.ri-nm.dup { background: #f4f6fb; border-color: var(--line); color: #9aa3b2; text-decoration: line-through; }
.ri-nm.empty { background: #f4f6fb; border-color: var(--line); color: #9aa3b2; }
.ri-rule { display: flex; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.ri-rule > span { font-size: 12.5px; color: var(--muted); }
.ri-seg { display: flex; gap: 4px; background: #eef1f7; border-radius: 10px; padding: 3px; flex: 1 1 200px; }
.ri-seg button { flex: 1 1 90px; padding: 7px 10px; border-radius: 8px; font-size: 12.5px; color: #4b5563; }
.ri-seg button.on { background: #fff; color: var(--brand-dark); font-weight: 600; box-shadow: 0 1px 3px rgba(17, 24, 39, .12); }
/* 第三步：确认 */
.ri-confirm { display: flex; align-items: center; gap: 8px; font-size: 13.5px; flex-wrap: wrap; }
.ri-confirm b { color: var(--brand-dark); }
.ri-gtag { display: inline-flex; align-items: center; gap: 6px; background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; font-size: 12.5px; font-weight: 600; }
.ri-gtag i { width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--brand)); flex: none; }
.ri-delta { margin-left: auto; font-size: 12px; color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
/* 确认页名单太长时只滚这份名单，上面的结论和下面的按钮/提示始终看得到 */
.ri-preview { margin-top: 10px; border: 1px solid var(--line); border-radius: 11px; max-height: 208px; overflow-y: auto; overflow-x: hidden; }
/* 滚动条做得明显一点：看到条就知道下面还有内容 */
.ri-body::-webkit-scrollbar, .ri-preview::-webkit-scrollbar { width: 9px; }
.ri-body::-webkit-scrollbar-track, .ri-preview::-webkit-scrollbar-track { background: #f4f6fb; }
.ri-body::-webkit-scrollbar-thumb, .ri-preview::-webkit-scrollbar-thumb { background: #c3d0e2; border-radius: 9px; border: 2px solid #f4f6fb; }
.ri-body::-webkit-scrollbar-thumb:hover, .ri-preview::-webkit-scrollbar-thumb:hover { background: #9fb3cd; }
.ri-body, .ri-preview { scrollbar-width: thin; scrollbar-color: #c3d0e2 #f4f6fb; }
.ri-plabel { background: #f7f9fc; padding: 7px 11px; font-size: 11.5px; font-weight: 700; color: #4b5563; border-top: 1px solid var(--line); }
.ri-plabel:first-child { border-top: 0; }
.ri-prow { display: flex; align-items: center; gap: 9px; padding: 7px 11px; border-top: 1px solid #f1f4f9; font-size: 13.5px; }
.ri-pav { width: 26px; height: 26px; border-radius: 50%; background: var(--c, var(--brand)); color: #fff; font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.ri-pname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ri-prow.skip { color: #9aa3b2; }
.ri-prow.skip .ri-pname { text-decoration: line-through; }
.ri-pnote { margin-left: auto; font-size: 11.5px; color: #b45309; text-align: right; }
.ri-prow.skip .ri-pnote { color: #9aa3b2; }
.ri-more { padding: 7px 11px; border-top: 1px solid #f1f4f9; font-size: 11.5px; color: var(--muted); background: #fcfdff; }
/* 第四步：导入完成 */
.ri-done { display: flex; align-items: center; gap: 9px; background: #e9f7f1; border: 1px solid #c3e9d8; border-radius: 11px; padding: 10px 12px; font-size: 13.5px; font-weight: 600; color: #0f5132; flex-wrap: wrap; }
.ri-done button { margin-left: auto; background: #fff; border: 1px solid #c3e9d8; color: var(--up-dark); border-radius: 8px; padding: 6px 11px; font-size: 12.5px; font-weight: 600; }
/* 刚导入进来的学生在名单里闪一下，方便当场对照 */
@keyframes stuFlash { from { background: #dbeafe; } to { background: transparent; } }
.stu-row.flash { animation: stuFlash 3s ease-out 1; }
@media (max-width: 720px) {
  input, select, textarea { font-size: 16px; }
  .class-score .cs-custom input { font-size: 16px; }
  /* 班级名单在手机上：收起左侧导航，改成单列 + 更大的点击区 */
  #roster-modal { padding: 8px; }
  .modal-box.roster-box { width: 100%; max-height: 94vh; padding: 12px 12px 10px; }
  .roster-main { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .roster-nav { display: none; }
  .roster-search { flex: 1 1 100%; }
  .roster-tools button { flex: 1 1 0; padding: 10px 8px; }
  .rq-row input, .roster-search input, .sm-row input, .sm-row select { font-size: 16px; }
  .stu-row { padding: 10px 10px; }
  .stu-grip { font-size: 16px; padding: 9px 4px; }
  .stu-more { width: 40px; height: 38px; font-size: 17px; }
  .stu-menu { left: 8px; right: 8px; width: auto; }
  .rg-head { padding: 10px 10px; }
  .rg-add { padding: 7px 10px; }
  /* 小组卡片上的两个按钮在手机上整行摊开，别挤成一团 */
  .rg-btns { flex: 1 1 100%; margin-left: 0; }
  .rg-btns button { flex: 1 1 0; padding: 8px 10px; }
  /* 导入面板：手机上按钮摊平，点着更稳 */
  .ri-head { padding: 9px 10px; }
  /* 第一行「标题 + ✕」，第二行整行是组名胶囊：不管屏幕多窄，✕ 都在右边，不会被挤到左边单独一行 */
  .ri-title { order: 1; flex: 1 1 auto; min-width: 0; }
  .ri-close { order: 2; }
  .ri-lock { order: 3; flex: 1 1 100%; margin-left: 0; }
  .ri-body { padding: 10px 10px 3px; }
  .ri-foot { padding: 10px 10px 11px; }
  .ri-foot button { flex: 1 1 0; padding: 11px 10px; }
  .ri-foot .ri-gap { display: none; }
  .ri-close { width: 34px; height: 34px; }
  /* 手机上导入面板独占弹窗剩下的高度：下面的名单先让位，不然两边都只挤出一条 */
  .roster-box.importing .roster-main { display: none; }
  .roster-import-panel { flex: 1 1 auto; max-height: none; }
  .ri-preview { max-height: 150px; }
  .ri-tools button { flex: 1 1 0; padding: 9px 10px; }
  .ri-chip { padding: 8px 12px; }
  /* 手机上把粘贴框收矮一点、提示行收紧，让「同名规则」那一行也能落在首屏里 */
  .ri-paste textarea { font-size: 16px; min-height: 104px; }
  .ri-ph { margin-bottom: 5px; }
  .ri-ph span { font-size: 11px; line-height: 1.5; }
  .ri-steps { padding: 7px 10px 0; }
}

/* ---------------------------------------------------------------------------
   移动端布局（≤720px）
   注意：这一整块必须放在所有基础样式之后。之前它位于文件中段，被后面的
   .main / .gscore / .history / #projector / .proj-card 等基础规则按「同权重
   后者优先」覆盖掉了，等于从未生效——例如投屏卡片分数一直是 64px 而不是 44px、
   卡片一直是一列而不是两列。
--------------------------------------------------------------------------- */
@media (max-width: 720px) {
  .layout { grid-template-columns: 1fr; gap: 12px; padding: 12px; }
  .sidebar { order: 2; }
  .main { order: 1; }
  .right { order: 3; flex-direction: column; }
  .right .panel { flex: none; }
  .topbar { padding: 10px 14px; gap: 8px; }
  .brand { font-size: 16px; }
  .actions { width: 100%; justify-content: flex-start; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
  .actions .ghost { padding: 8px 12px; font-size: 13px; white-space: nowrap; flex: none; }
  .main, .sidebar, .right .panel { padding: 12px; }
  .main { min-height: 0; }
  .board-head { flex-direction: column; align-items: stretch; gap: 8px; }
  .board-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .board-actions #btn-reset { display: none; }
  .board-actions button { white-space: nowrap; }
  .board { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .group-card { gap: 10px; padding: 12px 10px; }
  .group-card .group-head { gap: 6px; }
  .group-card .group-head .dot { width: 10px; height: 10px; }
  .group-card .group-head .gname { font-size: 14px; }
  .group-card .group-head .icon-btn,
  .group-card .group-meta,
  .group-card .school-rank,
  .group-card .quick .qbtn:not([data-delta="1"]):not([data-delta="-1"]) { display: none; }
  .group-card .gscore { padding: 0; font-size: 34px; line-height: 1.1; }
  .group-card .quick { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  .group-card .quick .qbtn { min-height: 44px; border-radius: 9px; font-size: 17px; }
  .class-score { gap: 6px; padding: 10px; }
  .class-score .cs-quick { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); flex: 1 1 0; min-width: 0; }
  .class-score .cs-quick .qbtn { min-width: 0; min-height: 44px; font-size: 15px; }
  .class-score .cs-custom { display: none; }
  .gscore { font-size: 34px; }
  input { font-size: 16px; }
  .icon-btn { width: 32px; height: 32px; font-size: 16px; }
  .drag-handle { font-size: 18px; }
  .qbtn { padding: 10px 0; font-size: 15px; }
  .class-list .class-item .tools { opacity: 1; visibility: visible; pointer-events: auto; }
  .mobile-class-select { display: block; width: 100%; margin-bottom: 12px; font-size: 16px; padding: 12px; }
  .history { max-height: 320px; }
  #projector { padding: 14px 12px; }
  .projector-title { font-size: 22px; margin-bottom: 14px; padding: 0 40px; }
  .projector-board { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
  .proj-card { padding: 14px; border-radius: 14px; }
  .proj-card .p-name { font-size: 18px; }
  .proj-card .p-score { font-size: 44px; margin-top: 4px; }
  .close-btn { top: 12px; right: 14px; padding: 8px 12px; font-size: 14px; }
  .proj-tools { top: 12px; right: 14px; }
  .proj-tools .close-btn { padding: 8px 12px; font-size: 14px; }
  /* 顶部操作：隐藏导出/导入；显示“班级”按钮 */
  #btn-classes { display: inline-flex; }
  .backup-wrap { display: none; }
  .class-close { display: inline-flex; }
  /* 班级板块改为点击按钮后弹出的窗口 */
  .sidebar {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0;
    margin: 0;
    max-height: 82vh;
    overflow-y: auto;
    z-index: 60;
    border-radius: 0 0 var(--radius) var(--radius);
    box-shadow: 0 12px 30px rgba(0,0,0,.22);
  }
  .sidebar.open { display: block; }
  .class-backdrop.open { display: block; position: fixed; inset: 0; z-index: 55; background: rgba(0,0,0,.45); }
}

@media (max-width: 360px) {
  .class-score .cs-label { flex: 1 1 100%; }
  .class-score .cs-quick { flex: 1 1 100%; grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ---------------------------------------------------------------------------
   手机安全区（状态栏 / 刘海 / 底部指示条）
   index.html 的 viewport 已加 viewport-fit=cover，这里用 env(safe-area-inset-*)
   把贴边的元素顶开。投屏模式的两个按钮原来固定在 top:12px，会被状态栏压住。
   不支持 env() 的浏览器会忽略这些声明，自动沿用上面的默认值，不会更糟。
--------------------------------------------------------------------------- */
.topbar {
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  padding-left: calc(20px + env(safe-area-inset-left, 0px));
  padding-right: calc(20px + env(safe-area-inset-right, 0px));
}
.layout {
  padding-left: calc(20px + env(safe-area-inset-left, 0px));
  padding-right: calc(20px + env(safe-area-inset-right, 0px));
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}
/* 投屏工具条：用 max() 保证不会比原来的间距更小 */
.proj-tools {
  top: max(20px, env(safe-area-inset-top, 0px));
  right: max(24px, env(safe-area-inset-right, 0px));
}
/* 投屏整屏：四周都让开安全区，横屏时左右刘海也算进去 */
#projector {
  padding-top: max(30px, env(safe-area-inset-top, 0px));
  padding-right: max(40px, env(safe-area-inset-right, 0px));
  padding-bottom: max(30px, env(safe-area-inset-bottom, 0px));
  padding-left: max(40px, env(safe-area-inset-left, 0px));
}

@media (max-width: 720px) {
  .topbar {
    padding-top: calc(6px + env(safe-area-inset-top, 0px));
    padding-left: calc(14px + env(safe-area-inset-left, 0px));
    padding-right: calc(14px + env(safe-area-inset-right, 0px));
  }
  .layout {
    padding-left: calc(12px + env(safe-area-inset-left, 0px));
    padding-right: calc(12px + env(safe-area-inset-right, 0px));
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }
  /* 移动端「班级」弹窗贴在屏幕顶部，同样要让开状态栏 */
  .sidebar {
    padding-top: calc(14px + env(safe-area-inset-top, 0px));
  }
  .proj-tools {
    top: max(12px, env(safe-area-inset-top, 0px));
    right: max(14px, env(safe-area-inset-right, 0px));
  }
  #projector {
    padding-top: max(14px, env(safe-area-inset-top, 0px));
    padding-right: max(12px, env(safe-area-inset-right, 0px));
    padding-bottom: max(14px, env(safe-area-inset-bottom, 0px));
    padding-left: max(12px, env(safe-area-inset-left, 0px));
  }
}

/* ---------------------------------------------------------------------------
   移动端体验优化
   1. 顶栏按钮加大触控目标、隐藏横向滚动条
   2. 记分卡快捷按钮加高到便于手指点按
   3. 投屏工具条改为跟随布局，不再压住班级标题
   4. 投屏卡片两个加减分按钮各占一半宽度，不会再挤出卡片
   5. 登录框与弹窗可滚动，软键盘弹出时不会被顶出屏幕
--------------------------------------------------------------------------- */
@media (max-width: 720px) {
  .topbar { gap: 4px; padding-bottom: 6px; }
  html.jiafen-app-shell .topbar { padding-top: 6px; }
  .actions { gap: 6px; scrollbar-width: none; }
  .actions::-webkit-scrollbar { display: none; }
  /* 顶栏按钮保持单行横向滚动，避免窄屏时挤压页面 */
  .actions .ghost { padding: 8px 10px; font-size: 14px; }
  .who-btn { max-width: 96px; }

  .qbtn { padding: 12px 0; font-size: 15px; }
  .icon-btn { width: 36px; height: 36px; font-size: 17px; }
  .lb-toggle button { padding: 8px 12px; font-size: 13px; }

  #login, .modal {
    align-items: flex-start;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: max(16px, env(safe-area-inset-top, 0px)) 16px max(16px, env(safe-area-inset-bottom, 0px));
  }
  /* margin:auto 让内容有空间时居中、空间不够时贴顶并可滚动 */
  .login-box, .modal-box { margin: auto; }
  .modal-box { padding: 18px; }
  /* 一行多个输入框在手机上挤不下，改为竖排 */
  .pw-row { flex-wrap: wrap; }
  .pw-row input, .pw-row button { flex: 1 1 100%; }

  .proj-tools {
    position: static;
    justify-content: flex-end;
    flex-wrap: nowrap;
    gap: 6px;
    margin-bottom: 8px;
  }
  .proj-tools .sync-status { margin-right: auto; font-size: 11px; padding: 3px 7px; flex: none; }
  .proj-tools .close-btn { padding: 8px; font-size: 12px; min-height: 36px; white-space: nowrap; }
  .projector-title { padding: 0; margin-bottom: 12px; }

  .proj-card { padding: 14px; }
  .proj-card .p-actions { gap: 8px; margin-top: 12px; }
  .proj-card .pbtn { flex: 1 1 0; min-width: 0; padding: 12px 0; font-size: 22px; }
}

/* 奖励 */
#btn-rewards { background: #dc2626; color: #fff; font-weight: 700; box-shadow: 0 2px 8px rgba(220, 38, 38, .24); }
#btn-rewards:hover { background: #b91c1c; }
#btn-rewards:focus-visible { outline: 2px solid #dc2626; outline-offset: 2px; }
#app.reward-mode .actions button:not(#btn-rewards) { display: none; }
#app.reward-mode .backup-wrap { display: none; }
#app.reward-mode .topbar { position: sticky; top: 0; z-index: 20; }
#app.reward-mode #btn-rewards::before { content: '←'; margin-right: 6px; font-size: 16px; }
.rewards-page { max-width: 1160px; margin: 0 auto; padding: 24px 20px 64px; }
.reward-controlbar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin: 0 0 13px; }
.reward-tabs { display: inline-flex; gap: 3px; padding: 4px; border-radius: 10px; background: #eef1f7; }
.reward-tabs button { min-width: 88px; padding: 9px 16px; border-radius: 8px; background: transparent; color: var(--muted); font-size: 13px; font-weight: 600; }
.reward-tabs button.on { background: #e3edff; color: var(--brand-dark); }
.reward-tabs button:focus-visible, .reward-class-chip:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.reward-settings-trigger { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.reward-settings-trigger span { font-size: 17px; line-height: 1; }
.reward-controls { display: flex; flex-wrap: wrap; gap: 8px; }
.reward-monthly-switch { display: flex; align-items: center; gap: 8px; margin-bottom: 18px; font-size: 14px; cursor: pointer; }
.reward-monthly-switch input { width: 17px; height: 17px; margin: 0; accent-color: var(--brand); }
.reward-month-label { display: block; margin: 18px 0 8px; font-size: 13px; font-weight: 600; }
.reward-month-picker { display: flex; gap: 8px; }
.reward-month-picker input { min-width: 0; flex: 1; width: 100%; font-size: 14px; }
.reward-month-picker button { flex: none; }
.reward-months { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; max-height: 130px; overflow-y: auto; }
.reward-month-chip { display: inline-flex; align-items: center; gap: 8px; padding: 6px 9px; background: #edf3ff; color: var(--brand-dark); font-size: 12px; }
.reward-month-chip span { font-size: 15px; }
.reward-month-chip:disabled { color: var(--muted); background: #f1f3f7; cursor: default; }
.archives-box { width: min(960px, 100%); height: min(760px, 86vh); display: flex; flex-direction: column; overflow: hidden; padding: 0; }
.archives-box > .modal-head { flex: none; padding: 20px 24px; border-bottom: 1px solid var(--border, #e5e7eb); }
.archives-box > .modal-head h3 { margin: 0; }
.archives-layout { display: grid; grid-template-columns: 240px minmax(0, 1fr); flex: 1; min-height: 0; }
.archives-sidebar { display: flex; flex-direction: column; gap: 16px; padding: 20px 16px; min-height: 0; background: #f6f8fc; border-right: 1px solid var(--border, #e5e7eb); }
.archives-sidebar > button { width: 100%; flex: none; }
.archives-list { display: flex; flex-direction: column; gap: 8px; overflow-y: auto; min-height: 0; padding: 3px; }
.archive-tile { display: flex; align-items: center; gap: 12px; width: 100%; padding: 14px 12px; text-align: left; color: var(--muted); background: transparent; border: 1px solid transparent; border-radius: 12px; }
.archive-tile:hover { background: #edf2fa; }
.archive-tile.on { background: #e3edff; color: var(--brand-dark); border-color: #c7dafe; }
.archive-tile:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.archive-tile-icon { flex: none; width: 34px; height: 34px; }
.archive-tile-icon svg { display: block; width: 100%; height: 100%; }
.archive-tile-info { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.archive-tile-name { color: var(--text); font-size: 13px; font-weight: 600; overflow-wrap: anywhere; }
.archive-tile.on .archive-tile-name { color: var(--brand-dark); }
.archive-tile-time { font-size: 11px; line-height: 1.5; }
.archives-content { min-width: 0; overflow-y: auto; padding: 24px; }
.archive-detail-title { margin: 0 0 6px; font-size: 18px; overflow-wrap: anywhere; }
@media (max-width: 600px) {
  .archives-box { height: 88vh; max-height: 88vh; }
  .archives-box > .modal-head { padding: 14px 16px; }
  .archives-layout { grid-template-columns: 104px minmax(0, 1fr); }
  .archives-sidebar { padding: 12px 6px; gap: 12px; }
  .archives-sidebar > button { padding: 10px 4px; font-size: 12px; }
  .archive-tile { flex-direction: column; gap: 8px; padding: 12px 6px; text-align: center; }
  .archive-tile-name { font-size: 11px; }
  .archive-tile-time { font-size: 10px; }
  .archives-content { padding: 14px 10px; }
  .archive-detail-title { font-size: 15px; }
  .archives-box .archive-rank-tabs button { padding: 8px 3px; font-size: 12px; }
  .archive-rank-list .lb-item { padding: 8px 6px; gap: 6px; font-size: 12px; }
  .archive-rank-list .lb-item .rank { width: 24px; }
  .archive-rank-list .lb-item .dot { width: 8px; height: 8px; }
}
.archives-box .err:empty, .archive-create-box .err:empty { display: none; }
.archive-create-box { width: min(390px, 100%); }
.archive-create-box label { display: block; margin: 16px 0 7px; font-size: 13px; font-weight: 600; }
.archive-create-box input { display: block; width: 100%; min-width: 0; }
.archive-create-box #archive-available { margin: 10px 0; font-size: 12px; }
.archives-box .archive-rank-tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin-bottom: 14px; }
.archive-class-nav { margin-top: 4px; }
.archive-rank-list .lb-name { white-space: normal; overflow-wrap: anywhere; }
.archives-box .archive-cutoff-label { margin: 0 0 14px; font-size: 12px; }
.archive-rank-tabs button { min-width: 0; flex: 1; }
.reward-lock-box { width: min(380px, 100%); }
.reward-lock-tiers { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px 8px; max-height: 50vh; overflow-y: auto; padding: 4px; margin: 16px -4px; }
.reward-lock-tiers .reward-token { width: 100%; min-width: 0; }
.reward-lock-tiers .reward-token-threshold { max-width: 100%; overflow-wrap: anywhere; white-space: normal; }
.reward-lock-tiers button:disabled { opacity: .6; cursor: wait; }
.reward-lock-box .err:empty { display: none; }
.reward-settings-box { width: min(340px, 100%); }
.reward-settings-box .modal-head h3 { margin: 0; }
.reward-settings-form { margin-top: 20px; }
.reward-step-row { display: flex; align-items: center; gap: 10px; color: var(--text); font-size: 15px; font-weight: 600; }
.reward-step-row input { width: 84px; padding: 10px; font-size: 18px; font-weight: 700; text-align: center; -moz-appearance: textfield; }
.reward-step-row input::-webkit-inner-spin-button, .reward-step-row input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.reward-settings-box .reward-settings-note { margin: 12px 0 0; font-size: 12px; }
.reward-settings-box .err { margin: 8px 0 0; font-size: 12px; }
.reward-settings-box .err:empty { display: none; }
.reward-settings-form .modal-actions { margin-top: 20px; }
.reward-settings-form .primary:disabled { background: #eef1f7; color: #a0aaba; cursor: default; transition: none; }
.reward-confirm-box .reward-confirm-detail { margin: 8px 0 0; color: var(--text); font-size: 15px; font-weight: 600; }
.reward-confirm-box .err { margin: 8px 0 0; font-size: 12px; }
.reward-confirm-box .err:empty { display: none; }
.reward-confirm-box .modal-actions { margin-top: 20px; }
.reward-confirm-box .primary:disabled { opacity: .6; cursor: default; }
.reward-add-box { width: min(340px, 100%); }
.reward-add-detail { margin: 12px 0 17px; color: var(--text); font-size: 15px; font-weight: 650; }
.reward-add-label { display: block; margin-bottom: 7px; color: var(--muted); font-size: 12px; font-weight: 600; }
.reward-add-box input { width: 100%; }
.reward-add-box .err { margin: 8px 0 0; font-size: 12px; }
.reward-add-box .err:empty { display: none; }
.reward-add-box .modal-actions { margin-top: 20px; }
.reward-add-box .primary:disabled { opacity: .6; cursor: default; }
.reward-class-nav { display: flex; flex-wrap: wrap; gap: 8px; padding: 2px 1px 13px; }
.reward-class-chip { display: inline-flex; align-items: center; gap: 8px; max-width: 100%; padding: 8px 13px; border: 1px solid var(--line); border-radius: 10px; background: #f6f8fc; color: var(--text); font-size: 12px; font-weight: 600; overflow-wrap: anywhere; text-align: left; }
.reward-class-chip:hover { background: #eef1f7; }
.reward-class-chip.on { border-color: #d3e2ff; background: #e3edff; color: var(--brand-dark); }
.reward-class-chip span { display: grid; min-width: 19px; height: 19px; flex: none; place-items: center; padding: 0 5px; border-radius: 99px; background: #eef1f7; color: var(--muted); font-size: 11px; }
.reward-class-chip.on span { background: #d3e2ff; color: var(--brand-dark); }
.reward-section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 7px 1px 14px; }
.reward-section-head h2 { margin: 0; color: var(--text); font-size: 17px; font-weight: 700; }
.reward-section-head span { color: var(--muted); font-size: 12px; white-space: nowrap; }
.reward-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.reward-card {
  position: relative;
  min-width: 0;
  min-height: 145px;
  overflow: hidden;
  padding: 20px 20px 17px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--group-color, #5B9BD5);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}
.reward-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; min-height: 40px; }
.reward-card-identity { display: flex; flex: 1; align-items: flex-start; gap: 9px; min-width: 0; padding-top: 5px; }
.reward-card-dot { width: 14px; height: 14px; flex: none; margin-top: 2px; border-radius: 50%; background: var(--group-color, #5B9BD5); }
.reward-card-names { flex: 1; min-width: 0; }
.reward-card-names h3 { display: flex; align-items: baseline; gap: 8px; overflow: hidden; margin: 0; color: var(--text); font-size: 16px; font-weight: 600; white-space: nowrap; }
.reward-card-class { min-width: 0; overflow: hidden; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.reward-card-group { flex: none; }
.reward-card-score { display: flex; align-items: baseline; gap: 3px; flex: none; color: var(--text); font-variant-numeric: tabular-nums; }
.reward-card-score strong { font-size: 28px; font-weight: 800; line-height: 1.1; }
.reward-card-score span { color: var(--muted); font-size: 11px; }
.reward-card-tokens { display: flex; align-items: flex-start; flex-wrap: wrap; gap: 8px; min-height: 61px; margin-top: 13px; }
.reward-token { display: inline-flex; width: 51px; min-height: 61px; flex: none; flex-direction: column; align-items: center; gap: 6px; padding: 0; background: transparent; color: var(--brand-dark); }
.reward-token:hover { background: transparent; }
.reward-token:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.reward-token-disc { display: grid; width: 42px; height: 42px; place-items: center; border-radius: 10px; background: var(--brand); color: #fff; font-size: 21px; transition: background .15s ease; }
.reward-token:hover .reward-token-disc { background: var(--brand-dark); }
.reward-token.completed { color: var(--muted); }
.reward-token.completed .reward-token-disc { background: #cbd5e1; color: #fff; }
.reward-token.completed:hover .reward-token-disc { background: #b9c6d6; }
.reward-token-threshold { font-size: 11px; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.reward-token.manual { width: 60px; color: #b76a00; }
.reward-token.manual .reward-token-disc { background: #f59e0b; }
.reward-token.manual:hover .reward-token-disc { background: #d97706; }
.reward-token.manual.completed { color: var(--muted); }
.reward-token.manual.completed .reward-token-disc { background: #cbd5e1; }
.reward-token.manual.completed:hover .reward-token-disc { background: #b9c6d6; }
.reward-token.manual .reward-token-threshold { max-width: 60px; overflow: hidden; text-overflow: ellipsis; }
.reward-add { display: inline-flex; width: 51px; height: 42px; flex: none; align-items: center; justify-content: center; padding: 0; background: transparent; color: var(--muted); }
.reward-add:hover { background: transparent; color: var(--brand-dark); }
.reward-add:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.reward-add > span { display: grid; width: 42px; height: 42px; place-items: center; border: 1px dashed #cbd5e1; border-radius: 10px; color: #94a3b8; font-size: 22px; line-height: 1; }
.reward-add:hover > span { border-color: var(--brand); color: var(--brand); }
.reward-empty { display: flex; min-height: 170px; align-items: center; justify-content: center; padding: 30px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--muted); text-align: center; font-size: 14px; }
.reward-empty-clear { flex-direction: column; gap: 7px; }
.reward-empty-clear span { color: var(--brand); font-size: 28px; }
.reward-empty-clear strong { color: var(--text); font-size: 14px; font-weight: 600; }
@media (max-width: 720px) {
  #app.reward-mode .topbar { flex-wrap: nowrap; }
  #app.reward-mode .actions { width: auto; flex: none; margin-left: auto; overflow: visible; padding-bottom: 0; }
  .rewards-page { padding: 14px 12px 38px; }
  .reward-controlbar { gap: 10px; margin: 0 0 12px; }
  .reward-tabs { display: grid; flex: 1; grid-template-columns: 1fr 1fr; }
  .reward-tabs button { min-width: 0; min-height: 38px; }
  .reward-settings-trigger { flex: none; }
  .reward-class-nav { padding-bottom: 13px; }
  .reward-section-head { margin: 5px 1px 12px; }
  .reward-grid { grid-template-columns: minmax(0, 1fr); gap: 11px; }
  .reward-card { min-height: 150px; padding: 18px 17px 15px; }
  .reward-card.has-class .reward-card-names h3 { gap: 6px; font-size: 14px; }
  .reward-card-tokens { gap: 6px; }
}

/* Ranking periods share the existing ranking presentation. */
.lb-period-controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: center; gap: 8px; margin: 0 0 8px; }
.lb-period-controls .lb-toggle { margin-left: 0; min-width: 0; }
.lb-period-controls .lb-toggle button { flex: 1; min-width: 0; padding: 6px 8px; }
.lb-scope-controls { margin: 0 0 10px; width: 100%; }
.lb-scope-controls button { flex: 1; min-width: 0; padding: 6px 8px; }
.lb-period-label { margin-bottom: 10px; color: var(--muted); font-size: 12px; }
.lb-score small { margin-left: 3px; color: var(--muted); font-size: 11px; font-weight: 400; }

/* Classroom records: compact circles by default, a full-day track while editing. */
.lessons-box { width: min(1100px, 100%); max-height: 88vh; overflow-y: auto; }
.lessons-toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin: 16px 0; }
.lessons-toolbar select { min-width: 110px; flex: 1; }
.lessons-toolbar input { width: 160px; min-width: 0; }
.lessons-box .err:empty { display: none; }
.lesson-day h4 { margin: 18px 0 10px; color: var(--muted); font-size: 12px; font-weight: 500; }
.lesson-circle-row { display: flex; flex-wrap: wrap; gap: 12px; }
.lesson-circle-item { display: flex; flex-direction: column; align-items: center; gap: 5px; background: transparent; padding: 5px; color: var(--text); }
.lesson-circle { display: grid; place-items: center; width: 66px; height: 66px; border-radius: 50%; background: #eef3ff; color: var(--brand-dark); font-size: 24px; font-weight: 700; border: 2px solid transparent; }
.lesson-circle-item.on .lesson-circle { border-color: var(--brand); background: #e3edff; }
.lesson-circle-item small { color: var(--muted); font-size: 10px; }
.lesson-circle-item strong { font-size: 12px; }
.lesson-circle-item.review .lesson-circle { background: #fff6e5; color: #b45309; }
.lesson-circle-item.unknown .lesson-circle { background: #eef1f6; color: #64748b; }
.lesson-detail-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 24px; border-top: 1px solid var(--line); padding-top: 18px; }
.lesson-detail-head h4 { margin: 0 0 5px; }
.lessons-box .lesson-detail-head p,.lessons-box .lesson-note { font-size: 12px; margin: 6px 0; }
.lesson-stats { display: flex; gap: 24px; flex-wrap: wrap; margin: 16px 0; }
.lesson-stats span { color: var(--muted); font-size: 12px; }
.lesson-stats b { display: inline-block; margin-left: 6px; font-size: 22px; color: var(--text); }
.lesson-stats b.lesson-positive { color: var(--up-dark); }
.lesson-stats b.lesson-negative { color: var(--down-dark); }
.lesson-table-wrap { overflow-x: auto; }
.lesson-table { width: 100%; border-collapse: collapse; text-align: left; font-size: 13px; }
.lesson-table td,.lesson-table th { padding: 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.lesson-table th { color: var(--muted); font-weight: 500; background: #f8faff; }
.lesson-edit-controls { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; margin: 14px 0; }
.lesson-edit-controls label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.lesson-edit-controls input { width: 220px; max-width: 100%; font-size: 13px; }
.lesson-timeline-scroll { overflow: auto; max-height: 340px; border: 1px solid var(--line); border-radius: 12px; background: #fbfcff; overscroll-behavior: contain; }
#lesson-timeline { position: relative; min-height: 135px; margin-right: 180px; }
.lesson-tick { position: absolute; top: 0; height: 100%; border-left: 1px solid #e9edf5; padding: 8px 5px; color: var(--muted); font-size: 10px; pointer-events: none; }
.lesson-window-shade { position: absolute; top: 30px; bottom: 0; background: rgba(59,130,246,.07); pointer-events: none; }
.lesson-timeline-entry { position: absolute; z-index: 1; font-size: 11px; white-space: nowrap; color: var(--text); pointer-events: none; }
.lesson-timeline-entry span { color: var(--brand); }
.voided { color: #94a3b8; text-decoration: line-through; }
.lesson-boundary { position: absolute; top: 28px; bottom: 0; width: 20px; margin-left: -10px; z-index: 3; border-radius: 0; background: transparent; border-left: 3px solid var(--brand); touch-action: none; cursor: ew-resize; }
.lesson-boundary span { position: absolute; left: -14px; top: -27px; padding: 3px 7px; background: var(--brand); color: white; font-size: 11px; border-radius: 5px; white-space: nowrap; }
.lesson-boundary:active { transform: none; }
.lesson-preview-net { display: flex; gap: 14px; align-items: center; margin: 18px 0 8px; color: var(--muted); font-size: 13px; }
.lesson-preview-net b { color: var(--text); font-size: 20px; }
.lesson-editor-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin: 16px 0; }
.lesson-form-box label { display: block; margin: 14px 0 6px; font-size: 13px; color: var(--muted); }
.lesson-form-box input { width: 100%; min-width: 0; }
.lesson-notice { color: #b45309 !important; font-size: 12px !important; }
@media (max-width: 600px) {
  .lessons-box { padding: 16px; }
  .lessons-toolbar { gap: 6px; }
  .lessons-toolbar select,.lessons-toolbar input { width: calc(50% - 3px); flex: 1 1 calc(50% - 3px); }
  .lessons-toolbar button { flex: 1; }
  .lesson-circle { width: 58px; height: 58px; font-size: 21px; }
  .lesson-edit-controls label { width: 100%; }
  .lesson-edit-controls input { width: 100%; }
  .lesson-stats { gap: 16px; }
}

.observed { color: #7c8798; }

.history-undo { flex: none; padding: 5px 7px; border-radius: 6px; background: transparent; color: var(--down-dark); font-size: 12px; white-space: nowrap; min-height: 30px; }
.history-undo:hover { background: #fdeef0; }
.history-undo:disabled { color: #94a3b8; cursor: default; }

.group-create-box { width: min(360px, 100%); }
.group-create-box label { display: block; margin: 16px 0 7px; font-size: 13px; color: var(--muted); }
.group-create-box input { width: 100%; min-width: 0; }
.group-create-box .err:empty { display: none; }
.group-create-box .modal-actions { margin-top: 18px; }

@media (hover: hover) and (pointer: fine) {
  .hist-item { position: relative; min-height: 36px; }
  .hist-item .history-undo {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0;
    pointer-events: none;
    background: #f8fafc;
    transition: opacity .12s ease;
  }
  .hist-item:hover .history-undo,
  .hist-item:focus-within .history-undo { opacity: 1; pointer-events: auto; }
  .hist-item:hover .hist-time,
  .hist-item:focus-within .hist-time { opacity: 0; }
  .hist-item .history-undo:hover { background: #fdeef0; }
  .hist-item .history-undo:active { transform: translateY(calc(-50% + 1px)); }
}

/* JF-003 continuous event axis: all records in the selected month share one scale. */
.timeline-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 16px 0 8px; color: var(--muted); font-size: 12px; }
.timeline-toolbar > span { margin-right: auto; }
.timeline-toolbar label { display: flex; align-items: center; gap: 6px; }
.timeline-toolbar select { font-size: 12px; padding: 7px; }
.timeline-toolbar button { font-size: 12px; }
.lesson-timeline-scroll { cursor: grab; background: #fbfdfc; }
.lesson-timeline-scroll.panning { cursor: grabbing; user-select: none; }
#lesson-timeline { margin-right: 100px; }
.lesson-axis-line { position: absolute; left: 0; right: 0; height: 2px; background: #cbd5e1; pointer-events: none; }
.lesson-tick { font-variant-numeric: tabular-nums; white-space: nowrap; }
.lesson-window-shade { top: 35px; background: rgba(16,185,129,.11); }
.lesson-boundary { top: 32px; border-left-color: #059669; }
.lesson-boundary span { background: #059669; }
.lesson-other-window { position: absolute; top: 35px; bottom: 0; background: rgba(148,163,184,.06); border-left: 1px solid #cbd5e1; border-right: 1px solid #cbd5e1; pointer-events: none; }
.lesson-other-window button { position: absolute; top: 2px; left: 3px; padding: 3px 6px; font-size: 10px; color: #64748b; white-space: nowrap; background: #edf1f7; pointer-events: auto; }
.lesson-event { position: absolute; width: 20px; height: 20px; padding: 0; transform: translate(-50%,-50%); color: #059669; background: transparent; border-radius: 50%; z-index: 2; cursor: pointer; }
.lesson-event.negative { color: #e45536; }
.lesson-event.voided,.lesson-event.observed { color: #94a3b8; }
.lesson-event:active { transform: translate(-50%,-50%); }
.lesson-event-stem { position: absolute; left: 9px; bottom: 50%; width: 1px; height: var(--stem); background: currentColor; opacity: .3; pointer-events: none; }
.lesson-event-dot { position: absolute; width: 9px; height: 9px; left: 5px; top: 5px; background: currentColor; border-radius: 50%; border: 1px solid white; }
.lesson-event-value { position: absolute; bottom: calc(var(--stem) + 7px); left: 50%; transform: translateX(-50%); background: white; padding: 3px 7px; border: 1px solid currentColor; border-radius: 7px; font-size: 12px; font-weight: 650; min-width: 30px; }
.lesson-event.in-window .lesson-event-dot { box-shadow: 0 0 0 4px rgba(16,185,129,.13); }
.lesson-event:hover,.lesson-event:focus-visible { z-index: 4; outline: 2px solid currentColor; outline-offset: 2px; }
.lesson-event-card { background: #f5f8fc; border: 1px solid var(--line); padding: 12px 16px; border-radius: 10px; margin-top: 12px; font-size: 13px; }
.lesson-event-card p { margin: 5px 0; font-size: 12px; }
.lesson-affected { border-left: 3px solid #f59e0b; padding: 8px 14px; margin: 14px 0; background: #fffbef; font-size: 12px; }
.lesson-affected h4 { margin: 0 0 6px; }
#lesson-window-select { max-width: 100%; }
@media (max-width: 600px) {
  .timeline-toolbar > span { flex: 1 1 100%; }
  #lesson-window-select { flex: 1 1 100%; min-width: 0; }
}
.lesson-axis-time { position: absolute; padding: 2px 5px; white-space: nowrap; font-size: 10px; color: var(--muted); pointer-events: none; }

/* The month stays next to the heading, including when history ignores it. */
.leaderboard-heading { justify-content: space-between; }
.leaderboard-heading > span { flex-shrink: 0; }
.lb-month-control { min-width: 0; flex: 0 1 160px; max-width: calc(100% - 60px); }
.lb-month-control input { display: block; min-width: 0; width: 100%; padding: 6px 8px; font-size: 12px; font-weight: 400; }
.lb-month-control input:disabled { background: #f8faff; color: #9ca3af; cursor: default; opacity: 1; }
.lb-period-caption { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 4px 10px; margin-bottom: 10px; }
.lb-period-caption .lb-period-label { margin: 0; }
#lb-basis-hint { color: var(--muted); font-size: 11px; }
.lb-average-entry { min-width: 0; }
.leaderboard.lb-loading .rank, .leaderboard.lb-loading .lb-score { visibility: hidden; }

/* Classroom viewing and editing share a stable header and a separate save bar. */
.lessons-box { display: flex; flex-direction: column; padding: 0; max-height: 90vh; max-height: 90dvh; overflow: hidden; }
.lessons-header { flex: none; padding: 18px 24px 0; border-bottom: 1px solid var(--line); }
.lessons-header h3 { margin: 0; }
.lessons-header .icon-btn { width: 32px; height: 32px; }
.lessons-toolbar { align-items: center; gap: 8px; margin: 16px 0 12px; }
.lesson-class-picker { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 12px; color: var(--muted); }
.lessons-toolbar .lesson-class-picker select { width: 180px; min-width: 0; flex: none; }
.lessons-box select { font-family: inherit; color: var(--text); background: white; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.lesson-month-picker { display: flex; align-items: center; gap: 2px; border: 1px solid var(--line); border-radius: 10px; background: white; }
.lessons-toolbar .lesson-month-picker input { width: 137px; flex: none; border: none; padding: 8px 2px; font-size: 13px; }
.lesson-month-picker button { width: 30px; min-height: 36px; background: transparent; color: var(--muted); font-size: 22px; }
.lesson-month-picker button:hover { background: var(--bg); }
.lessons-toolbar-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.lessons-toolbar button { white-space: nowrap; font-size: 12px; }
.lessons-toolbar .lesson-mode-button { background: #e3edff; color: var(--brand-dark); }
.lessons-overview { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 18px; min-height: 40px; padding-bottom: 10px; color: var(--muted); font-size: 12px; }
.lessons-overview b { color: var(--text); font-variant-numeric: tabular-nums; }
.lessons-overview button { background: transparent; padding: 4px 0; font-size: 12px; }
.lessons-overview .lesson-quality-review { color: #b45309; }
.lessons-overview .lesson-refresh { margin-left: auto; color: var(--brand-dark); }
.lessons-body { min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 20px 24px 24px; }
.lessons-body > .err { margin: 0 0 12px; font-size: 13px; }
.lesson-circle-row { gap: 12px; }
.lesson-circle-item { padding: 8px; border-radius: 12px; }
.lesson-circle-item:hover { background: #f8faff; }
.lesson-circle-item.on { background: #f0f5ff; }
.lesson-circle-item.negative .lesson-circle { color: var(--down-dark); }
.lesson-circle-item.zero .lesson-circle { color: var(--muted); }
.lesson-empty { padding: 24px 12px; text-align: center; }
.lesson-empty p { color: var(--muted); font-size: 13px; margin: 8px 0 16px; }
.lesson-detail-head { margin-top: 20px; }
.is-editing .lesson-detail-head { margin-top: 0; padding-top: 0; border-top: none; }
.lesson-detail-head h4 { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; font-size: 16px; }
.lesson-detail-head p { color: var(--muted); }
.lesson-status-badge { padding: 3px 7px; border-radius: 5px; background: #e6f8f1; color: var(--up-dark); font-size: 11px; font-weight: 500; }
.lesson-status-badge.review { background: #fff4df; color: #b45309; }
.lesson-status-badge.unknown { background: #eef1f7; color: var(--muted); }
.lesson-detail-nav { display: flex; align-items: center; gap: 5px; }
.lesson-detail-nav > button { min-width: 32px; min-height: 32px; background: #eef1f7; color: var(--text); font-size: 20px; }
.lesson-detail-nav > .ghost { font-size: 12px; }
.lessons-box button:disabled { cursor: default; opacity: .4; }
.lesson-stats { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 10px; margin: 16px 0; }
.lesson-stats > span { padding: 12px 16px; border-radius: 10px; background: #f8faff; }
.lesson-stats > .lesson-stat-net { background: #eef4ff; color: var(--brand-dark); }
.lesson-stats b { display: block; margin: 4px 0 0; font-variant-numeric: tabular-nums; font-size: 25px; }
.lesson-stat-net b { color: var(--brand-dark); }
.lesson-table th:not(:first-child),.lesson-table .lesson-numeric { text-align: right; }
.lesson-table .lesson-net-cell { font-weight: 650; }
.lesson-net-cell.positive { color: var(--up-dark); }
.lesson-net-cell.negative { color: var(--down-dark); }
.lesson-source-details,.lesson-precision,.lesson-preview-groups,.lesson-records-details { border: 1px solid var(--line); border-radius: 10px; margin-top: 12px; font-size: 12px; overflow: hidden; }
.lessons-box summary { cursor: pointer; padding: 11px 12px; color: var(--muted); user-select: none; }
.lessons-box summary:hover { background: #f8faff; color: var(--text); }
.lesson-source-details p { margin: 0; padding: 0 12px 12px; color: var(--muted); line-height: 1.7; }
.lesson-edit-controls { margin: 0; padding: 4px 12px 14px; }
.lesson-precision .lesson-edit-controls label { flex: 1; min-width: 0; }
.lesson-edit-controls input { width: 100%; min-width: 0; }
.lesson-axis-legend { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 14px; color: var(--muted); font-size: 11px; margin: 12px 0; }
.lesson-axis-legend .positive { color: var(--up-dark); }
.lesson-axis-legend .negative { color: var(--down-dark); }
.lesson-axis-legend label { display: flex; align-items: center; gap: 5px; cursor: pointer; }
.lesson-axis-legend input { width: 14px; height: 14px; padding: 0; margin: 0; accent-color: var(--brand); }
.lesson-axis-hint { margin: 8px 0 0; color: var(--muted); font-size: 11px; }
.lesson-timeline-scroll { max-height: 280px; }
.lesson-boundary { display: flex; align-items: flex-start; justify-content: flex-start; padding: 0; }
.lesson-boundary span { position: sticky; display: inline-block; top: 4px; left: auto; margin-left: -4px; }
#lesson-boundary-start span { transform: translateX(-100%); }
#lesson-visible-range { margin-left: auto; font-variant-numeric: tabular-nums; }
.lesson-records-details summary span { margin-left: 6px; font-size: 11px; }
.lesson-records-tools { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px 12px; color: var(--muted); }
.lesson-records-tools select { font-size: 12px; margin-left: 5px; }
.lesson-records-details .lesson-table th,.lesson-records-details .lesson-table td { text-align: left; }
.lesson-event-card { position: relative; padding-right: 44px; }
.lesson-event-close { position: absolute; top: 8px; right: 8px; }
.lesson-preview-net { margin: 14px 0; }
.lesson-preview-breakdown { color: var(--muted); font-size: 12px; margin-top: -6px; }
.lesson-workflow-bar { display: flex; align-items: center; gap: 8px; flex: none; border-top: 1px solid var(--line); background: white; padding: 14px 24px; }
.lesson-workflow-bar[hidden] { display: none; }
#lesson-workflow-state { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; margin-right: auto; color: var(--muted); font-size: 12px; }
#lesson-workflow-state > span:first-child { margin-right: 8px; }
#lesson-workflow-state .unsaved { color: #b45309; }
#lesson-workflow-state b { color: var(--text); font-variant-numeric: tabular-nums; }
#lesson-workflow-state small { margin-left: 3px; }
.lesson-workflow-bar > button { font-size: 13px; white-space: nowrap; }
.lesson-more-actions { position: relative; }
.lesson-more-actions summary { list-style: none; white-space: nowrap; font-size: 12px; border-radius: 8px; }
.lesson-more-actions summary::-webkit-details-marker { display: none; }
.lesson-more-actions > div { position: absolute; bottom: calc(100% + 12px); right: 0; min-width: 150px; padding: 5px; border: 1px solid var(--line); border-radius: 10px; background: white; box-shadow: var(--shadow); }
.lesson-more-actions button { display: block; padding: 10px 12px; width: 100%; background: white; color: var(--text); font-size: 13px; text-align: left; white-space: nowrap; }
.lesson-more-actions button:hover { background: var(--bg); }
.lessons-box :focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
@media (max-width: 700px) {
  .lessons-header { padding: 14px 16px 0; }
  .lessons-body { padding: 16px; }
  .lessons-toolbar { gap: 8px; }
  .lesson-class-picker { flex: 1 1 146px; }
  .lesson-class-picker > span { display: none; }
  .lessons-toolbar .lesson-class-picker select { width: 100%; }
  .lesson-month-picker { flex: none; }
  .lesson-month-picker button { width: 24px; }
  .lessons-toolbar .lesson-month-picker input { width: 108px; flex: none; }
  .lessons-toolbar button { flex: none; }
  .lessons-toolbar-actions { flex: 1; min-width: 238px; margin-left: 0; }
  .lessons-toolbar-actions button:first-child { margin-right: auto; }
  .lessons-overview { gap: 6px 12px; }
  .lesson-detail-head { align-items: flex-start; }
  .lesson-detail-head h4 { gap: 5px; font-size: 14px; }
  .lesson-detail-nav { flex: none; flex-wrap: wrap; max-width: 100px; justify-content: flex-end; }
  .lesson-detail-nav > .ghost { width: 100%; }
  .lesson-timeline-scroll { max-height: 220px; }
  .lesson-stats { gap: 6px; }
  .lesson-stats > span { padding: 10px 12px; }
  .lesson-stats b { font-size: 23px; }
  .lesson-workflow-bar { padding: 10px 16px; flex-wrap: wrap; }
  #lesson-workflow-state { flex-basis: 100%; min-height: 20px; }
  .lesson-more-actions { margin-right: auto; }
  .lesson-more-actions > div { left: 0; right: auto; }
  .lesson-precision .lesson-edit-controls label { flex-basis: 100%; }
  #lesson-visible-range { margin-left: 0; flex-basis: 100%; }
}
