:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --panel-2: #fafbfe;
  --border: #e3e8f0;
  --border-strong: #cdd5e3;
  --text: #1f2733;
  --text-soft: #5b6577;
  --muted: #8b95a7;
  --brand: #2f6bff;
  --brand-soft: #eaf1ff;
  --ok: #12a150;
  --ok-soft: #e7f7ee;
  --warn: #d9822b;
  --err: #d92d20;
  --err-soft: #fdeceb;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 6px 20px rgba(16, 24, 40, 0.06);
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.5;
}

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 24px 80px;
}

header.masthead h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.2px;
}
header.masthead { position: relative; }
.mast-actions { position: absolute; top: 0; right: 0; display: flex; gap: 10px; }
.mast-btn {
  border: 1px solid var(--border-strong); border-radius: 999px;
  padding: 9px 15px; background: #fff; color: var(--text); font-weight: 600;
  cursor: pointer;
}
.mast-btn:hover { background: #f5f7fb; }
.mast-btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); box-shadow: 0 5px 14px rgba(47,107,255,.28); }
.mast-btn.primary:hover { background: #205ae0; }
.tutorial-pulse { display: inline-grid; place-items: center; width: 18px; height: 18px; margin-left: 4px; border-radius: 50%; background: var(--brand); color: #fff; font-size: 12px; }
#tutorial-trigger:not(.seen) { animation: tutorial-bounce 1.5s ease-in-out infinite; }
@keyframes tutorial-bounce { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
.tutorial-modal { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 20px; background: rgba(15,23,42,.42); }
.tutorial-card { position: relative; width: min(640px, 100%); max-height: 88vh; overflow-y: auto; padding: 28px 30px 30px; border-radius: 16px; background: #fff; box-shadow: 0 18px 50px rgba(15,23,42,.25); }
.tutorial-card h2 { margin: 0 0 6px; font-size: 20px; }
.tutorial-close { position: absolute; top: 10px; right: 14px; border: 0; background: transparent; font-size: 26px; color: var(--muted); cursor: pointer; z-index: 1; }

/* 教程内容 */
.tut-lead { margin: 0 0 18px; color: var(--text-soft); font-size: 13.5px; line-height: 1.7; }
.tut-lead strong { color: var(--text); }
.tut-block { margin-top: 20px; }
.tut-block h3 { margin: 0 0 10px; font-size: 15px; color: var(--text); display: flex; align-items: center; gap: 8px; }
.tut-block h3::before { content: ""; width: 4px; height: 15px; border-radius: 2px; background: var(--brand); }
.tut-list { margin: 0; padding-left: 18px; }
.tut-list li { margin: 7px 0; color: var(--text-soft); line-height: 1.6; }
.tut-list b, .tut-list strong { color: var(--text); }

/* 模式说明卡 */
.tut-mode { display: flex; gap: 12px; align-items: flex-start; background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-top: 10px; }
.tut-mode p { margin: 4px 0; color: var(--text-soft); font-size: 13px; line-height: 1.6; }
.tut-mode b { color: var(--text); }
.tut-badge { flex: none; padding: 4px 12px; border-radius: 20px; font-size: 12.5px; font-weight: 700; background: var(--brand-soft); color: var(--brand); white-space: nowrap; }
.tut-badge.alt { background: var(--ok-soft); color: var(--ok); }
.tut-formula { font-weight: 600; color: var(--text) !important; background: #fff; border: 1px dashed var(--border-strong); border-radius: 7px; padding: 6px 10px; display: inline-block; }
.tut-eg { color: var(--muted) !important; font-size: 12.5px !important; }

/* 步骤 */
.tut-steps { list-style: none; margin: 0; padding: 0; }
.tut-steps > li { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px dashed var(--border); }
.tut-steps > li:last-child { border-bottom: 0; }
.tut-step-n { flex: none; width: 24px; height: 24px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: 13px; font-weight: 700; }
.tut-steps > li > div { flex: 1; }
.tut-steps b { color: var(--text); }
.tut-steps p { margin: 6px 0; color: var(--text-soft); font-size: 13px; line-height: 1.6; }
.tut-steps ul { margin: 6px 0 0; padding-left: 18px; }
.tut-steps li ul li { margin: 5px 0; color: var(--text-soft); font-size: 13px; line-height: 1.6; }
.tut-tip { color: var(--warn) !important; font-size: 12.5px !important; }

.tut-faq { border-top: 1px solid var(--border); padding-top: 16px; }

/* 规则设置页 */
.rules-modal { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 20px; background: rgba(15,23,42,.5); }
.rules-page { position: relative; width: min(1040px, 100%); max-height: 92vh; display: flex; flex-direction: column; background: var(--bg); border-radius: 16px; overflow: hidden; box-shadow: 0 24px 60px rgba(15,23,42,.35); }
.rules-head { display: flex; align-items: center; gap: 12px; padding: 16px 22px; background: #fff; border-bottom: 1px solid var(--border); }
.rules-head h2 { margin: 0; font-size: 18px; }
.rules-head .rules-sub { color: var(--muted); font-size: 12.5px; }
.rules-head .spacer { flex: 1; }
.rules-close { border: 0; background: transparent; font-size: 26px; color: var(--muted); cursor: pointer; line-height: 1; }
.rules-body { padding: 16px 22px 22px; overflow-y: auto; }

.brand-card { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; margin-top: 14px; }
.brand-card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.brand-card-head b { font-size: 15px; }
.brand-card-head .spacer { flex: 1; }
.brand-card .grid-wrap { max-height: none; }
.brand-card table.result { min-width: 480px; }
header.masthead p {
  margin: 6px 0 0;
  color: var(--text-soft);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-top: 22px;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
}
.panel-head .idx {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 600;
  flex: none;
}
.panel-head h2 {
  margin: 0;
  font-size: 16px;
}
.panel-head .hint {
  margin-left: auto;
  color: var(--muted);
  font-size: 12.5px;
}
.panel-body { padding: 18px 20px; }

/* Tabs */
.tabs {
  display: inline-flex;
  background: #eef1f7;
  border-radius: 9px;
  padding: 3px;
  gap: 2px;
}
.tabs button {
  border: 0;
  background: transparent;
  color: var(--text-soft);
  padding: 7px 16px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
}
.tabs button.active {
  background: #fff;
  color: var(--brand);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.08);
}
.tab-pane { display: none; margin-top: 16px; }
.tab-pane.active { display: block; }

/* Buttons */
.btn {
  border: 1px solid var(--border-strong);
  background: #fff;
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: #f5f7fb; }
.btn.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.btn.primary:hover { background: #205ae0; }
.btn.ghost { border-style: dashed; color: var(--brand); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn.danger { color: var(--err); border-color: #f0c2be; }
.btn.danger:hover { background: var(--err-soft); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.row-count { color: var(--muted); font-size: 12.5px; }

/* Editable grid */
.grid-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; }
table.grid { border-collapse: collapse; width: 100%; min-width: 640px; }
table.grid th {
  background: var(--panel-2);
  text-align: left;
  padding: 9px 10px;
  font-size: 12.5px;
  color: var(--text-soft);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.grid td {
  padding: 0;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
}
table.grid td:last-child { border-right: 0; }
table.grid tr:last-child td { border-bottom: 0; }
table.grid input,
table.grid select {
  width: 100%;
  border: 0;
  background: transparent;
  padding: 8px 10px;
  font-size: 13.5px;
  color: var(--text);
  outline: none;
  font-family: inherit;
}
table.grid input:focus,
table.grid select:focus { background: var(--brand-soft); }
table.grid td.disabled { background: repeating-linear-gradient(45deg, #f7f8fb, #f7f8fb 6px, #f1f3f8 6px, #f1f3f8 12px); }
table.grid td.disabled input { color: var(--muted); }
table.grid td.op { text-align: center; width: 46px; }
.icon-del {
  border: 0; background: transparent; cursor: pointer;
  color: var(--muted); font-size: 16px; line-height: 1; padding: 6px;
}
.icon-del:hover { color: var(--err); }

/* Paste box */
textarea.paste {
  width: 100%;
  min-height: 120px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 12px;
  font-family: "Consolas", "Menlo", monospace;
  font-size: 13px;
  resize: vertical;
  color: var(--text);
}
textarea.paste:focus { outline: none; border-color: var(--brand); }

/* Upload */
.drop {
  border: 1.5px dashed var(--border-strong);
  border-radius: 10px;
  padding: 26px;
  text-align: center;
  color: var(--text-soft);
  background: var(--panel-2);
}
.drop.hover { border-color: var(--brand); background: var(--brand-soft); }
.drop strong { color: var(--brand); cursor: pointer; }
.help {
  margin-top: 14px;
  background: var(--brand-soft);
  border: 1px solid #d6e2ff;
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 12.5px;
  color: #3355a8;
}
.help code { background: #fff; padding: 1px 6px; border-radius: 5px; border: 1px solid #d6e2ff; }
.help ul { margin: 8px 0 0; padding-left: 18px; }

/* Run bar */
.runbar {
  position: sticky;
  bottom: 0;
  margin-top: 24px;
  display: flex;
  gap: 14px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 20px;
  box-shadow: var(--shadow);
}
.runbar .big { padding: 11px 26px; font-size: 15px; }
.runbar .status { color: var(--text-soft); }

/* Result */
.summary { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
.stat {
  flex: 1;
  min-width: 130px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  background: var(--panel-2);
}
.stat .n { font-size: 24px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.stat.ok .n { color: var(--ok); }
.stat.bad .n { color: var(--err); }

table.result { border-collapse: collapse; width: 100%; min-width: 820px; }
table.result th, table.result td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 13px;
  white-space: nowrap;
}
table.result th { background: var(--panel-2); color: var(--text-soft); font-weight: 600; position: sticky; top: 0; }
table.result td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.result tr.miss td { background: #fef7f6; }
table.result td.reason { white-space: normal; color: var(--err); min-width: 260px; }
.tag {
  display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600;
}
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.no { background: var(--err-soft); color: var(--err); }
.tag.mode { background: var(--brand-soft); color: var(--brand); }

.empty { text-align: center; color: var(--muted); padding: 40px 0; }
.hidden { display: none !important; }

/* 提成点计算过程按钮 + 弹窗 */
.pt-cell { white-space: nowrap; }
.calc-btn {
  border: 1px solid var(--brand); background: var(--brand-soft); color: var(--brand);
  border-radius: 20px; padding: 2px 9px; font-size: 11.5px; font-weight: 600;
  cursor: pointer; margin-left: 6px; vertical-align: middle;
}
.calc-btn:hover { background: var(--brand); color: #fff; }
.calc-modal { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 20px; background: rgba(15,23,42,.5); }
.calc-card { position: relative; width: min(680px, 100%); max-height: 90vh; overflow-y: auto; padding: 24px 26px 26px; border-radius: 16px; background: #fff; box-shadow: 0 22px 60px rgba(15,23,42,.32); }
.calc-card h2 { margin: 0 0 14px; font-size: 18px; }
.calc-close { position: absolute; top: 10px; right: 14px; border: 0; background: transparent; font-size: 26px; color: var(--muted); cursor: pointer; line-height: 1; }
.calc-meta { display: flex; flex-wrap: wrap; gap: 8px 18px; padding: 12px 14px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; font-size: 13px; }
.calc-meta b { color: var(--muted); font-weight: 600; margin-right: 5px; }
.calc-steps { list-style: none; counter-reset: step; margin: 16px 0 6px; padding: 0; }
.calc-steps li { counter-increment: step; display: flex; gap: 12px; align-items: baseline; padding: 9px 0; border-bottom: 1px dashed var(--border); }
.calc-steps li:last-child { border-bottom: 0; }
.calc-steps li::before { content: counter(step); flex: none; width: 20px; height: 20px; border-radius: 50%; background: var(--brand); color: #fff; font-size: 12px; display: grid; place-items: center; align-self: center; }
.calc-k { flex: none; width: 84px; color: var(--text-soft); font-weight: 600; font-size: 12.5px; }
.calc-v { flex: 1; font-size: 13px; }
.calc-sub { margin: 16px 0 8px; font-size: 13px; color: var(--text-soft); }
.calc-sub b { color: var(--brand); }
table.calc-ladder { min-width: 0; }
table.calc-ladder tr.hit td { background: var(--brand-soft); font-weight: 700; }
.calc-ladder .hit-tag { color: var(--brand); font-weight: 600; font-size: 12px; }
.calc-final { margin-top: 16px; padding: 14px 16px; border-radius: 10px; font-size: 13.5px; line-height: 1.9; }
.calc-final.ok { background: var(--ok-soft); border: 1px solid #bfe6cf; }
.calc-final.ok b { color: var(--ok); font-size: 15px; }
.calc-final.bad { background: var(--err-soft); border: 1px solid #f0c2be; color: var(--err); font-weight: 600; }

/* 访问密码闸门 */
body.locked { overflow: hidden; }
.gate {
  position: fixed; inset: 0; z-index: 9999;
  display: grid; place-items: center; padding: 20px;
  background: linear-gradient(135deg, #eef2fb 0%, #dfe7fb 100%);
}
.gate-card {
  width: min(360px, 100%); padding: 34px 30px; text-align: center;
  background: #fff; border-radius: 16px;
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.18);
}
.gate-icon { font-size: 34px; line-height: 1; }
.gate-card h2 { margin: 12px 0 4px; font-size: 19px; }
.gate-card p { margin: 0 0 18px; color: var(--text-soft); font-size: 13px; }
.gate-card input {
  width: 100%; padding: 11px 14px; font-size: 15px;
  border: 1px solid var(--border-strong); border-radius: 9px;
  outline: none; color: var(--text);
}
.gate-card input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.gate-card button {
  width: 100%; margin-top: 14px; padding: 11px; font-size: 15px; font-weight: 600;
  border: 0; border-radius: 9px; background: var(--brand); color: #fff; cursor: pointer;
  box-shadow: 0 6px 16px rgba(47, 107, 255, 0.28);
}
.gate-card button:hover { background: #205ae0; }
.gate-err { margin: 12px 0 0 !important; color: var(--err) !important; font-weight: 600; }
.pill { font-size: 12px; color: var(--muted); }
