:root {
  --bg: #f5f6f8;
  --card: #fff;
  --line: #e6e8ec;
  --text: #1c1f23;
  --muted: #6b7280;
  --brand: #2563eb;
  --green: #15803d;
  --slight: #86efac;
  --yellow: #fbbf24;
  --brown: #a16207;
  --red: #dc2626;
  --none: #d7dbe0;
  --radius: 12px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  padding-bottom: 40px;
}
a { color: var(--brand); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.wrap { max-width: 960px; margin: 0 auto; padding: 0 14px; }
.wrap.wide { max-width: 1440px; }

header.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255,255,255,.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 960px; margin: 0 auto; padding: 10px 14px;
  display: flex; align-items: center; gap: 10px;
}
.topbar-inner.wide { max-width: 1440px; }
.brand { font-weight: 700; font-size: 16px; }
.brand small { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 6px; }
.spacer { flex: 1; }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin-top: 12px;
}
.card h3 { margin: 0 0 8px; font-size: 15px; }

.btn {
  border: 1px solid var(--line); background: #fff; color: var(--text);
  border-radius: 9px; padding: 7px 12px; font-size: 14px;
}
.btn:hover { border-color: #c9ced6; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #1d4ed8; }
.btn.ghost { border-color: transparent; color: var(--muted); }
.btn.danger { color: var(--red); border-color: #f3c7c7; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.input, select.input, textarea.input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 9px; background: #fff; outline: none;
}
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }

/* ---------- 题单列表 ---------- */
.sheet-item {
  display: flex; align-items: center; gap: 12px;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-top: 10px;
}
.sheet-item:hover { border-color: #c9ced6; }
.sheet-item .grow { flex: 1; min-width: 0; }
.sheet-item .title { font-weight: 600; }
.sheet-item .meta { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.ring {
  --p: 0;
  width: 44px; height: 44px; border-radius: 50%; flex: none;
  background: conic-gradient(var(--brand) calc(var(--p) * 1%), #e9edf2 0);
  display: grid; place-items: center;
}
.ring > span {
  width: 34px; height: 34px; border-radius: 50%; background: #fff;
  display: grid; place-items: center; font-size: 11.5px; color: var(--muted);
}

/* ---------- 题目卡片 ---------- */
.problem {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 13px 14px; margin-top: 10px;
}
.problem.need-redo { border-color: #f0d9a8; background: #fffdf7; }
.p-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.pid {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px; font-weight: 700; padding: 2px 6px; border-radius: 6px;
  background: #eef2ff; color: #3730a3;
}
.pid.src-cf { background: #e0f2fe; color: #075985; }
.pid.src-atcoder { background: #f3f0ff; color: #5b21b6; }
.pid.src-oj { background: #ecfdf5; color: #065f46; }
.p-title { font-weight: 600; }
.p-diff { font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 0 7px; }
.p-tags { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.p-mid { margin-top: 9px; display: flex; flex-wrap: wrap; gap: 6px; }

.dot {
  width: 30px; height: 30px; border-radius: 50%; border: 2px solid transparent;
  display: inline-grid; place-items: center; padding: 0; font-size: 11px; color: #334155;
  background: var(--none); position: relative;
}
.dot[data-s="green"]  { background: var(--green);  color: #fff; }
.dot[data-s="slight"] { background: var(--slight); }
.dot[data-s="yellow"] { background: var(--yellow); }
.dot[data-s="brown"]  { background: var(--brown);  color: #fff; }
.dot[data-s="red"]    { background: var(--red);    color: #fff; }
.dot[data-s="none"]   { background: var(--none); color: #64748b; }
.dot.active { outline: 2px solid #1e293b; outline-offset: 2px; }
.dot:hover { transform: translateY(-1px); }

.p-note { margin-top: 9px; display: flex; gap: 8px; align-items: center; }
.p-note input { flex: 1; }
.attempts { display: flex; align-items: center; gap: 4px; font-size: 12.5px; color: var(--muted); }
.attempts input { width: 46px; padding: 5px 6px; text-align: center; }

.saved-hint { font-size: 12px; color: var(--green); opacity: 0; transition: opacity .2s; }
.saved-hint.show { opacity: 1; }

.progress { height: 6px; border-radius: 999px; background: #e9edf2; overflow: hidden; margin-top: 8px; }
.progress > i { display: block; height: 100%; background: var(--brand); border-radius: 999px; transition: width .25s; }

.empty { text-align: center; color: var(--muted); padding: 36px 12px; }

/* ---------- 教练端 ---------- */
.admin-grid { display: grid; grid-template-columns: 320px 1fr; gap: 14px; align-items: start; }
@media (max-width: 900px) { .admin-grid { grid-template-columns: 1fr; } }

.sheet-row { padding: 10px 12px; border-radius: 10px; border: 1px solid transparent; cursor: pointer; }
.sheet-row:hover { background: #f8fafc; }
.sheet-row.active { background: #eff6ff; border-color: #bfdbfe; }
.sheet-row .t { font-weight: 600; font-size: 14px; }
.sheet-row .m { font-size: 12px; color: var(--muted); }

.table-scroll { overflow: auto; max-height: 68vh; border: 1px solid var(--line); border-radius: 10px; }
table.matrix { border-collapse: separate; border-spacing: 0; font-size: 13px; }
table.matrix th, table.matrix td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 0; }
table.matrix thead th {
  position: sticky; top: 0; background: #f8fafc; z-index: 2;
  font-weight: 600; padding: 6px 8px; white-space: nowrap; font-size: 12px;
}
table.matrix td.name, table.matrix th.name {
  position: sticky; left: 0; background: #fff; z-index: 3;
  padding: 6px 10px; white-space: nowrap; font-weight: 500;
}
table.matrix thead th.name { background: #f8fafc; z-index: 4; }
table.matrix td.cell {
  width: 46px; height: 34px; text-align: center; cursor: pointer;
  font-size: 11px; color: #334155;
}
table.matrix td.cell[data-s="green"]  { background: var(--green);  color: #fff; }
table.matrix td.cell[data-s="slight"] { background: var(--slight); }
table.matrix td.cell[data-s="yellow"] { background: var(--yellow); }
table.matrix td.cell[data-s="brown"]  { background: var(--brown);  color: #fff; }
table.matrix td.cell[data-s="red"]    { background: var(--red);    color: #fff; }
table.matrix td.cell[data-s="none"]   { background: #fff; color: #cbd5e1; }
table.matrix td.cell:hover { outline: 2px solid #334155; outline-offset: -2px; }

.legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; margin-right: 4px; vertical-align: -1px; }

.stat-row { display: flex; gap: 18px; flex-wrap: wrap; }
.stat { min-width: 84px; }
.stat b { display: block; font-size: 21px; line-height: 1.2; }
.stat span { font-size: 12px; color: var(--muted); }

.modal-mask {
  position: fixed; inset: 0; background: rgba(15,23,42,.42);
  display: grid; place-items: center; z-index: 50; padding: 14px;
}
.modal {
  background: #fff; border-radius: 14px; width: min(760px, 100%);
  max-height: 88vh; overflow: auto; padding: 18px;
}
.modal h2 { margin: 0 0 14px; font-size: 17px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.pick-list { max-height: 240px; overflow: auto; border: 1px solid var(--line); border-radius: 9px; margin-top: 8px; }
.pick-row { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-bottom: 1px solid #f1f3f6; font-size: 13px; }
.pick-row:last-child { border-bottom: 0; }
.pick-row .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.chip { font-size: 12px; padding: 3px 8px; border-radius: 999px; background: #f1f5f9; color: #475569; }
.chip .x { margin-left: 5px; cursor: pointer; color: #94a3b8; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: #111827; color: #fff; font-size: 13px; padding: 9px 16px; border-radius: 999px;
  opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; z-index: 99;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

/* ---------- v2：账号体系新增 ---------- */
.who { font-size: 13px; color: var(--muted); margin-right: 8px; }
a.sheet-item { color: inherit; text-decoration: none; }
.p-title { color: inherit; }
.auth-card { max-width: 420px; margin: 32px auto; }
.auth-tabs { display: flex; gap: 6px; background: #f1f5f9; padding: 4px; border-radius: 10px; margin-bottom: 16px; }
.auth-tab { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 8px; font-size: 14px; color: #64748b; }
.auth-tab.active { background: #fff; color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.alert { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; border-radius: 9px; padding: 8px 10px; font-size: 13px; margin-bottom: 12px; }
.hint { color: var(--muted); font-size: 13px; margin: 0 0 14px; line-height: 1.55; }
.btn.wide { width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-top: 16px; font-size: 13px; color: var(--muted); }
.chev { color: #94a3b8; font-size: 18px; }
.section-title { margin: 18px 0 2px; font-weight: 700; font-size: 14px; }
.sheet-head { display: flex; align-items: center; gap: 10px; }
.sheet-title { margin: 8px 0 2px; }
.memo { font-size: 13px; color: #475569; margin-top: 6px; white-space: pre-wrap; }
.muted-sm { font-size: 12.5px; color: var(--muted); }
.sep { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }
code { background: #f1f5f9; padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }

/* 教练端 tab */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tab { border: 0; background: transparent; padding: 9px 14px; font-size: 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

table.plain { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.plain th, table.plain td { text-align: left; padding: 8px 10px; border-bottom: 1px solid #f1f3f6; }
table.plain th { font-weight: 600; color: #475569; font-size: 12.5px; background: #fafbfc; }
table.plain tr:hover td { background: #fafbfc; }
.badge { display: inline-block; font-size: 11.5px; padding: 1px 7px; border-radius: 999px; background: #eef2ff; color: #3730a3; }
.badge.off { background: #f1f5f9; color: #94a3b8; }
.badge.coach { background: #fef3c7; color: #92400e; }
.code-box { font-family: ui-monospace, Menlo, monospace; background: #f8fafc; border: 1px dashed #cbd5e1; border-radius: 8px; padding: 8px 12px; font-size: 15px; letter-spacing: .5px; }

/* ---------- v3：题单卡片交互 ---------- */
.diff { font-size: 11.5px; font-weight: 600; color: #fff; padding: 1.5px 7px; border-radius: 4px; line-height: 1.5; white-space: nowrap; }
.p-actions { display: flex; gap: 8px; margin-top: 11px; flex-wrap: wrap; }
.btn.sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.done-row { margin-top: 10px; display: flex; align-items: center; gap: 7px; flex-wrap: wrap; font-size: 13px; color: #334155; background: #f8fafc; border: 1px solid #eef2f7; border-radius: 9px; padding: 8px 11px; }
.done-row b { font-weight: 600; }
.done-note { color: #64748b; border-left: 2px solid #e2e8f0; padding-left: 8px; }
.dot-sm { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.opt-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.opt-card { display: flex; align-items: center; gap: 8px; padding: 10px 11px; border: 1.5px solid var(--line); border-radius: 10px; background: #fff; text-align: left; font-size: 13px; line-height: 1.35; }
.opt-card:hover { border-color: #c9ced6; }
.opt-card.active { border-color: var(--brand); background: #eff6ff; box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.opt-card:last-child { grid-column: 1 / -1; }
.opt-dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
.field-label { font-size: 13px; color: var(--muted); margin: 0 0 8px; }
.dlg-title { margin: 0 0 4px; font-size: 16px; }
@media (max-width: 380px) { .opt-grid { grid-template-columns: 1fr; } .opt-card:last-child { grid-column: auto; } }

/* ---------- v4：卡片状态色 + 完成反馈 ---------- */
.problem { border-left-width: 4px; }
/* 旧的 need-redo 只保留语义，颜色交给 data-st 统一管 */
.problem.need-redo { border-color: var(--line); }
.problem[data-st="green"]  { border-left-color: #15803d; background: #f6fbf7; }
.problem[data-st="slight"] { border-left-color: #86efac; background: #f8fdf9; }
.problem[data-st="yellow"] { border-left-color: #fbbf24; background: #fffdf5; }
.problem[data-st="brown"]  { border-left-color: #a16207; background: #fdf8f4; }
.problem[data-st="red"]    { border-left-color: #dc2626; background: #fef6f6; }
.problem[data-st="none"]   { border-left-color: #e5e7eb; }

.celebrate {
  position: fixed; inset: 0; z-index: 200; display: grid; place-items: center;
  background: rgba(15,23,42,.42);
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
  transition: opacity .5s;
}
.celebrate.out { opacity: 0; }
.celebration-box { text-align: center; animation: cel-pop .6s cubic-bezier(.18,1.5,.4,1); position: relative; z-index: 2; }
.celebration-mark {
  width: 104px; height: 104px; margin: 0 auto 16px; border-radius: 50%;
  color: #fff; display: grid; place-items: center; font-size: 56px; font-weight: 300;
  box-shadow: 0 12px 44px rgba(0,0,0,.28); animation: cel-ring 1.1s ease-out;
}
.celebration-text { color: #fff; font-size: 23px; font-weight: 800; letter-spacing: 3px; text-shadow: 0 2px 14px rgba(0,0,0,.35); }
.celebration-sub { color: rgba(255,255,255,.82); font-size: 13px; margin-top: 7px; }
.celebration-pid { color: rgba(255,255,255,.55); font-size: 12px; margin-top: 14px; font-family: ui-monospace, Menlo, monospace; }
.confetti { position: absolute; left: 50%; top: 50%; width: 9px; height: 9px; border-radius: 2px; opacity: 0; animation: cel-fly var(--d) cubic-bezier(.2,.7,.3,1) forwards; }
@keyframes cel-pop { 0% { transform: scale(.35); opacity: 0 } 62% { transform: scale(1.06); opacity: 1 } 100% { transform: scale(1) } }
@keyframes cel-ring { 0% { box-shadow: 0 0 0 0 rgba(255,255,255,.55) } 100% { box-shadow: 0 0 0 44px rgba(255,255,255,0) } }
@keyframes cel-fly { 0% { opacity: 1; transform: translate(0,0) rotate(0) scale(1) } 100% { opacity: 0; transform: translate(var(--x), var(--y)) rotate(var(--r)) scale(.35) } }
