:root {
  --bg: #0f1419;
  --bg-2: #1a2027;
  --bg-3: #232b36;
  --fg: #d6dee6;
  --fg-dim: #8a96a3;
  --accent: #4dabf7;
  --ok: #51cf66;
  --warn: #ffd43b;
  --err: #ff6b6b;
  --gray: #495057;
  --border: #2a3340;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--fg); }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

/* ---- 顶部状态栏 ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px 24px;
  flex-wrap: wrap;
  padding: 10px 20px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand {
  font-weight: 600;
  font-size: 16px;
  color: var(--accent);
}
.status-group {
  display: flex;
  gap: 14px 18px;
  flex: 1;
  flex-wrap: wrap;
  min-width: 0;
}
.status-item { display: flex; align-items: center; gap: 6px; }
.status-item .label { color: var(--fg-dim); font-size: 12px; }
.status-item .value { font-weight: 500; }
.status-item .money { color: var(--ok); }
.actions { display: flex; gap: 8px; }

/* 桌面：折叠控件隐藏，顶栏主体「展开」进 flex 行 */
.topbar-rest {
  display: contents;
}
.topbar-mobile-cb {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
.topbar-mobile-toggle {
  display: none;
}
.topbar-mobile-hint-open {
  display: none;
}
.topbar-mobile-cb:checked + .topbar-mobile-toggle .topbar-mobile-hint-closed {
  display: none;
}
.topbar-mobile-cb:checked + .topbar-mobile-toggle .topbar-mobile-hint-open {
  display: inline;
}
.topbar-mobile-chev::before {
  content: "\25BE";
  font-size: 12px;
  color: var(--fg-dim);
  display: inline-block;
  line-height: 1;
  transition: transform 0.15s ease;
}
.topbar-mobile-cb:checked + .topbar-mobile-toggle .topbar-mobile-chev::before {
  transform: rotate(-180deg);
}

/* ---- badge ---- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 500;
}
.badge.green { background: rgba(81, 207, 102, 0.15); color: var(--ok); }
.badge.red   { background: rgba(255, 107, 107, 0.15); color: var(--err); }
.badge.yellow{ background: rgba(255, 212, 59, 0.15); color: var(--warn); }
.badge.blue  { background: rgba(77, 171, 247, 0.15); color: var(--accent); }
.badge.gray  { background: rgba(73, 80, 87, 0.3); color: var(--fg-dim); }

/* ---- 主区布局：顶栏三卡 + 跟注 + 玩家全宽表 + 底表 ---- */
.main.layout-main {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin: 0 auto;
  padding: 20px clamp(12px, 2vw, 28px);
  min-width: 0;
}
.dash-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  align-items: stretch;
}
.dash-row > .card {
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.mid-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.mid-row > .card {
  min-width: 0;
}

@media (max-width: 1100px) {
  .dash-row {
    grid-template-columns: 1fr;
  }
  .mid-row {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 1101px) and (max-width: 1280px) {
  .dash-row {
    grid-template-columns: 1fr 1fr;
  }
  .dash-row .card.meta {
    grid-column: 1 / -1;
  }
}

.card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}
.row-engine-flow .engine-flow {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  flex: 1;
  min-width: 0;
}
.flow-detail {
  font-size: 12px;
  color: var(--fg-dim);
  word-break: break-all;
}

.card h2 {
  margin: 0 0 12px 0;
  font-size: 14px;
  color: var(--fg-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}
.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid rgba(42, 51, 64, 0.5);
}
.row:last-child { border-bottom: none; }
.row .label { color: var(--fg-dim); font-size: 13px; }
.row .value { font-weight: 500; }
.row-check { justify-content: flex-start; align-items: flex-start; }
.check-label { color: var(--fg-dim); font-size: 13px; cursor: pointer; display: flex; gap: 8px; align-items: center; }
.check-label input { flex-shrink: 0; }
.actions-inline { justify-content: flex-start; padding-top: 10px; }
.input {
  width: 120px;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  font-size: 13px;
}
.input:focus { outline: none; border-color: var(--accent); }
.input-wide { width: min(200px, 42vw); }
.input-stretch {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}
.mono-sm {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  word-break: break-all;
  line-height: 1.35;
  text-align: right;
  max-width: 100%;
}
.error-multiline {
  word-break: break-word;
  white-space: pre-wrap;
  text-align: left;
  font-size: 12px;
  line-height: 1.4;
  max-width: 100%;
}
.row-error {
  align-items: flex-start;
}
.row-error .label {
  padding-top: 2px;
}

/* 表单行：标签 + 控件栅格对齐 */
.card.engine-opts .row-field,
.player-form-block .row-field,
.player-dialog-form .row-field {
  display: grid;
  grid-template-columns: minmax(100px, 32%) 1fr;
  gap: 8px 14px;
  align-items: center;
}
.card.engine-opts .row-field .label,
.player-form-block .row-field .label,
.player-dialog-form .row-field .label {
  justify-self: start;
}
.row-field-top {
  align-items: start;
}
.row-field-top .label {
  padding-top: 8px;
}
.player-dialog-form .row-field-body,
.player-form-block .row-field-body {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.player-dialog-form .row-field-body .hint-inline,
.player-form-block .row-field-body .hint-inline {
  margin-left: 0;
}
.player-dialog-form .row-field-body-stack,
.player-form-block .row-field-body-stack {
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}
.player-dialog-form .follow-cond-line,
.player-form-block .follow-cond-line {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  max-width: 100%;
}
.player-dialog-form .row-field-body .input-stretch,
.player-form-block .row-field-body .input-stretch {
  flex: 1 1 120px;
  min-width: 0;
}

.player-pick-cell {
  line-height: 1.35;
}
.pick-follow-status {
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted, #8a9199);
}
.pick-follow-status--following {
  color: var(--accent, #6eb5ff);
}
.pick-follow-status--no_match {
  color: var(--warn, #e6a23c);
}
.pick-follow-live--ok b {
  color: var(--accent, #6eb5ff);
}
.pick-follow-live--warn {
  color: var(--warn, #e6a23c);
}

.hint-tight {
  margin-top: 6px !important;
  margin-bottom: 8px !important;
}
.hint-disclosure {
  margin: 0 0 12px 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  padding: 0 12px;
}
.hint-disclosure summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--accent);
  padding: 10px 0;
  user-select: none;
  list-style-position: outside;
}
.hint-disclosure summary::-webkit-details-marker { color: var(--fg-dim); }
.hint-disclosure[open] summary {
  border-bottom: 1px solid rgba(42, 51, 64, 0.6);
  margin-bottom: 8px;
}
.hint-disclosure .hint {
  margin-bottom: 12px !important;
}

.table-wrap-tight {
  margin-bottom: 8px;
}
.player-ladder-ta {
  min-height: 100px !important;
  width: 100% !important;
  max-width: none !important;
}

.card .hint { color: var(--fg-dim); font-size: 12px; margin: 0 0 12px 0; line-height: 1.45; }
.card .hint code { background: var(--bg-3); padding: 1px 5px; border-radius: 3px; font-size: 11px; }
.value.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.value.big { font-size: 18px; }
.value.error { color: var(--err); }

/* ---- 开奖球 ---- */
.balls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.ball {
  display: inline-flex;
  width: 28px;
  height: 28px;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--bg-3);
  border: 1px solid var(--border);
  font-weight: 600;
  font-size: 13px;
}

/* ---- 按钮 ---- */
.btn {
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-3);
  color: var(--fg);
  font-weight: 500;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--bg-2); border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.1); }
.btn.primary:disabled,
.btn.primary[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
  filter: none;
}
.btn.danger { background: transparent; color: var(--err); border-color: var(--err); }
.btn.danger:hover { background: rgba(255,107,107,0.1); }
.btn.ghost { background: transparent; }
.btn.btn-sm { padding: 4px 10px; font-size: 12px; margin-left: 8px; vertical-align: middle; }
.btn-icon {
  padding: 8px 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}
.btn-icon svg { flex-shrink: 0; }
.hint-inline { color: var(--fg-dim); font-size: 12px; margin-left: 4px; }
.row-next-stake { align-items: center; flex-wrap: wrap; gap: 6px; }
.ladder-err { margin: 4px 0 8px 0; }
.cfg-ladder-store { display: none !important; }
.ladder-ta { min-height: 200px; }
.dialog-new-player {
  width: min(560px, 94vw);
  max-height: 90dvh;
  overflow-y: auto;
  box-sizing: border-box;
}
.limit-rules-panel {
  margin: 4px 0 12px;
  padding: 10px 12px 4px;
  border: 1px solid var(--border, #2a3344);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.12);
}
.limit-rule-block {
  margin-bottom: 10px;
}
.limit-rule-block:last-child {
  margin-bottom: 4px;
}
.limit-rule-head {
  margin-bottom: 4px;
  font-weight: 500;
}
.limit-rule-fields {
  margin-left: 1.4rem;
  padding-bottom: 4px;
}
.limit-rule-fields-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
}
.limit-rule-fields-stack {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.limit-rule-inline {
  flex-wrap: wrap;
  gap: 6px 10px;
}
.limit-rule-inline .input-narrow {
  width: 3.2em;
}
.row-compact {
  margin-bottom: 6px;
}
.row-compact .label {
  min-width: 4.5em;
}
.row-compact-check {
  margin: 4px 0 6px;
}
.input-narrow {
  width: 5.5rem;
  max-width: 100%;
}
.dialog-ext-replace {
  max-height: 90dvh;
  overflow-y: auto;
  box-sizing: border-box;
}
/* 更新策略弹窗：复选框长说明独占一行，勿用双列 grid 压成竖条 */
.dialog-ext-replace .ext-replace-form .row-field.row-check {
  display: block;
  padding: 6px 0 10px;
}
.dialog-ext-replace .ext-replace-form .row-field.row-check .check-label {
  width: 100%;
  align-items: flex-start;
  white-space: normal;
}
.dialog-ext-replace .ext-replace-form .row-field.row-check .check-label input {
  margin-top: 4px;
}
.dialog-follow {
  width: min(520px, 94vw);
}
.dialog-equity {
  width: 80vw;
  max-width: 80vw;
  max-height: 90vh;
  overflow-y: auto;
  box-sizing: border-box;
}
.equity-range-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.equity-range-bar .btn-sm {
  margin-left: 0;
}
.equity-range-bar .label-inline {
  font-size: 12px;
  color: var(--fg-dim);
  margin-right: 4px;
  align-self: center;
}
.equity-indicator-toggles {
  align-items: center;
  gap: 10px 14px;
}
.equity-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  color: var(--fg);
  cursor: pointer;
  user-select: none;
}
.equity-toggle input {
  width: 15px;
  height: 15px;
  margin: 0;
  cursor: pointer;
}
.player-today-profit {
  white-space: nowrap;
  font-size: 12px;
}
.badge-warn {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  font-size: 11px;
  border-radius: 4px;
  background: rgba(255, 152, 0, 0.2);
  color: #ffb74d;
  vertical-align: middle;
}
.badge-limit-ok {
  display: inline-block;
  padding: 1px 6px;
  font-size: 11px;
  border-radius: 4px;
  background: rgba(129, 199, 132, 0.15);
  color: #81c784;
}
.player-col-limit {
  min-width: 6.5rem;
  max-width: 10rem;
  vertical-align: top;
}
.player-col-limit .badge-warn {
  margin-left: 0;
}
.limit-stop-reason {
  margin-top: 4px;
  color: #ffb74d;
  font-size: 11px;
  line-height: 1.35;
  word-break: break-word;
}
.player-row-limit-stop td {
  background: rgba(255, 152, 0, 0.05);
}
.player-row-limit-stop .player-col-limit {
  background: rgba(255, 152, 0, 0.1);
}
.row-check {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--fg-dim);
}
.row-check input {
  width: 16px;
  height: 16px;
}
.equity-chart-wrap {
  min-height: 120px;
}
.equity-scroll-hint {
  margin: 0 0 8px;
  color: var(--fg-dim);
}
.equity-chart-dom {
  width: 100%;
  height: calc(88vh - 260px);
  min-height: 400px;
  max-height: 76vh;
  touch-action: none;
}
.bets-table td.clickable-principal {
  cursor: pointer;
  color: var(--accent);
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}
.bets-table td.clickable-principal:hover {
  filter: brightness(1.12);
}
.turn-clickable {
  cursor: pointer;
  color: var(--accent);
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}
.turn-clickable:hover {
  filter: brightness(1.12);
}
.dialog-turn-bets {
  width: 80vw;
  max-width: 80vw;
  max-height: 90vh;
  overflow-y: auto;
  box-sizing: border-box;
}
.dialog-hit-analysis {
  width: min(92vw, 1100px);
  max-height: 90vh;
  overflow-y: auto;
  box-sizing: border-box;
}
.hit-analysis-panels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin: 10px 0 14px;
}
.hit-analysis-panel h3 {
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 600;
}
.hit-analysis-dist-table {
  font-size: 12px;
  width: 100%;
}
.hit-analysis-row-active td {
  color: var(--accent, #7dd3fc);
}
.hit-analysis-detail-wrap {
  max-height: min(42vh, 360px);
  overflow: auto;
}
.hit-analysis-detail-table {
  font-size: 12px;
  width: 100%;
}
.turn-bets-table-wrap {
  max-height: min(62vh, 520px);
  overflow: auto;
  margin: 8px 0 0 0;
}
.turn-bets-table {
  font-size: 12px;
}
/* 投注记录 10 列：不用 fixed 均分，避免「投注号码」与「金额」挤叠 */
.bets-table.turn-bets-table.bet-hist-table {
  table-layout: auto;
  width: max-content;
  min-width: 1180px;
}
.bets-table.turn-bets-table.bet-hist-table th,
.bets-table.turn-bets-table.bet-hist-table td {
  vertical-align: middle;
}
.bet-hist-table th:nth-child(1),
.bet-hist-table td:nth-child(1) {
  min-width: 108px;
}
.bet-hist-table th:nth-child(2),
.bet-hist-table td:nth-child(2) {
  min-width: 148px;
}
.bet-hist-table th:nth-child(3),
.bet-hist-table td:nth-child(3) {
  width: 2.8em;
  text-align: center;
}
.bet-hist-table th:nth-child(4),
.bet-hist-table td:nth-child(4) {
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bet-hist-table th:nth-child(5),
.bet-hist-table td:nth-child(5) {
  min-width: 200px;
  max-width: 280px;
  width: 240px;
  white-space: normal;
  word-break: break-all;
  overflow-wrap: anywhere;
  line-height: 1.4;
  vertical-align: top;
}
.bet-hist-table th:nth-child(6),
.bet-hist-table td:nth-child(6) {
  min-width: 3.2em;
  padding-left: 12px;
  padding-right: 12px;
  text-align: center;
}
.bet-hist-table th:nth-child(7),
.bet-hist-table td:nth-child(7) {
  min-width: 168px;
  max-width: 240px;
  width: 200px;
  white-space: normal;
  word-break: break-all;
  overflow-wrap: anywhere;
  line-height: 1.4;
  vertical-align: top;
}
.bet-hist-table th:nth-child(1),
.bet-hist-table td:nth-child(1),
.bet-hist-table th:nth-child(2),
.bet-hist-table td:nth-child(2),
.bet-hist-table th:nth-child(3),
.bet-hist-table td:nth-child(3),
.bet-hist-table th:nth-child(4),
.bet-hist-table td:nth-child(4),
.bet-hist-table th:nth-child(6),
.bet-hist-table td:nth-child(6),
.bet-hist-table th:nth-child(8),
.bet-hist-table td:nth-child(8),
.bet-hist-table th:nth-child(9),
.bet-hist-table td:nth-child(9),
.bet-hist-table th:nth-child(10),
.bet-hist-table td:nth-child(10) {
  white-space: nowrap;
}
.bet-hist-table th:nth-child(8),
.bet-hist-table td:nth-child(8) {
  min-width: 5.5em;
}
.bet-hist-table th:nth-child(9),
.bet-hist-table td:nth-child(9) {
  min-width: 4.5em;
  text-align: right;
}
.bet-hist-table th:nth-child(10),
.bet-hist-table td:nth-child(10) {
  min-width: 5.5em;
  text-align: right;
}
.bet-hist-limit-yes {
  color: #ffb74d;
  font-weight: 600;
}

.bet-hist-profit-neg {
  color: var(--err);
  font-weight: 600;
}
.bet-hist-range-bar {
  margin-top: 4px;
}

/* ---- dialog ---- */
dialog {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-2);
  color: var(--fg);
  padding: 24px;
  width: min(560px, 92vw);
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
dialog.dialog-ext-replace {
  width: 80vw;
  max-width: 80vw;
  min-width: min(720px, calc(100vw - 24px));
}
dialog.dialog-ext-test {
  width: min(920px, 88vw);
  max-width: 88vw;
  max-height: 90dvh;
  overflow-y: auto;
  box-sizing: border-box;
}
dialog.dialog-draw-history {
  width: min(920px, 92vw);
  max-width: 92vw;
  max-height: 88dvh;
  overflow-y: auto;
  box-sizing: border-box;
}
.draw-history-inner {
  min-width: 0;
}
.draw-history-range {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  margin-top: 10px;
}
.draw-history-range .label {
  margin-right: 4px;
  color: var(--muted, #8a96a3);
  font-size: 0.9rem;
}
.draw-history-range-opt {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  user-select: none;
}
.draw-history-tabs {
  margin-top: 8px;
}
.dialog-draw-history .dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}
.draw-history-table-wrap {
  max-height: min(56vh, 520px);
  margin-top: 8px;
}
.draw-history-table.bets-table {
  min-width: 480px;
}
.draw-history-table th:nth-child(1),
.draw-history-table td:nth-child(1) {
  width: 28%;
}
.draw-history-table th:nth-child(2),
.draw-history-table td:nth-child(2) {
  width: 32%;
}
.ext-test-dialog-inner {
  min-width: 0;
}
.ext-test-block {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid rgba(42, 51, 64, 0.75);
}
.ext-test-block:first-of-type {
  margin-top: 8px;
  border-top: none;
  padding-top: 0;
}
.ext-test-h3 {
  margin: 0 0 10px 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--fg-dim);
  letter-spacing: 0.04em;
}
.ext-test-pre {
  margin: 10px 0 0;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.45;
  max-height: 38vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.ext-test-result {
  min-width: 0;
}
.ext-test-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
  align-items: center;
}
.ext-test-tab {
  margin: 0;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--fg-dim);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
}
.ext-test-tab:hover {
  color: var(--fg);
  background: rgba(255, 255, 255, 0.04);
}
.ext-test-tab-active {
  color: var(--fg);
  background: var(--bg-3);
  border-color: var(--border);
}
.ext-test-pre-tab {
  margin-top: 8px;
}
dialog::backdrop {
  background: rgba(0,0,0,0.55);
}
dialog h2 { margin: 0 0 12px 0; font-size: 18px; }
dialog .hint { color: var(--fg-dim); font-size: 13px; margin: 0 0 12px 0; }
dialog code {
  background: var(--bg-3);
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 12px;
}
dialog textarea {
  width: 100%;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  resize: vertical;
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}
.cookie-result {
  margin-top: 12px;
  font-size: 13px;
  min-height: 1.2em;
  white-space: pre-wrap;
}
.cookie-result.ok  { color: var(--ok); }
.cookie-result.err { color: var(--err); }

/* ---- 表格（.bets-table：玩家列表等） ---- */
/* 任意卡片内宽表：限制在视口内，横向滚动留在本容器，避免整页被撑开 */
.table-wrap {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.bets-table {
  width: 100%;
  min-width: 1040px;
  border-collapse: collapse;
  font-size: 13px;
  table-layout: fixed;
}
.bets-table th, .bets-table td {
  border: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}
.bets-table th {
  background: var(--bg-3);
  color: var(--fg-dim);
  font-weight: 600;
  white-space: nowrap;
}
.bets-table td.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.bets-table td.open-draw {
  word-break: break-all;
  line-height: 1.4;
}

/* 外部策略 Worker 观测 */
.ext-worker-panel {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border, #2a3142);
}
.ext-worker-title {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  font-weight: 600;
}
.ext-worker-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: center;
  margin-bottom: 0.5rem;
}
.ext-worker-summary .badge.ok {
  color: #6ee7a0;
  border-color: #3d6b52;
}
.bets-table.ext-worker-table th,
.bets-table.ext-worker-table td {
  text-align: left;
  vertical-align: middle;
}
.ext-worker-progress-cell {
  min-width: 7.5rem;
}
.ext-worker-bar {
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 0.25rem;
}
.ext-worker-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #3b82f6, #22c55e);
  border-radius: 3px;
  transition: width 0.25s ease;
}
.bets-table.ext-worker-table .th-sub {
  font-size: 10px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  opacity: 0.85;
}
.ext-worker-timing-cell {
  white-space: nowrap;
}
.ext-worker-dur-warn {
  color: #d4a017;
}
.ext-worker-dur-slow {
  color: #e05c5c;
  font-weight: 600;
}
.ext-worker-digest {
  max-width: 10rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 外部 Python 策略表：6 列显式分配，避免 fixed 下列宽漂移导致表头与「测试/操作」错位 */
.bets-table.ext-strat-table th,
.bets-table.ext-strat-table td {
  text-align: left;
}
.bets-table.ext-strat-table .mono-sm {
  text-align: left;
}
.bets-table.ext-strat-table th:nth-child(1),
.bets-table.ext-strat-table td:nth-child(1) {
  width: 18%;
  min-width: 0;
}
.bets-table.ext-strat-table th:nth-child(2),
.bets-table.ext-strat-table td:nth-child(2) {
  width: 3.75rem;
  max-width: 4.25rem;
  white-space: nowrap;
  vertical-align: middle;
}
.bets-table.ext-strat-table th:nth-child(3),
.bets-table.ext-strat-table td:nth-child(3) {
  width: 4.5rem;
  max-width: 5.5rem;
  white-space: nowrap;
  vertical-align: middle;
}
.bets-table.ext-strat-table th:nth-child(4),
.bets-table.ext-strat-table td:nth-child(4) {
  width: 26%;
  min-width: 0;
  white-space: normal;
  word-break: break-word;
  vertical-align: top;
}
.bets-table.ext-strat-table th:nth-child(5),
.bets-table.ext-strat-table td:nth-child(5) {
  width: 11.5rem;
  max-width: 13rem;
  min-width: 9rem;
  white-space: normal;
  word-break: break-all;
  vertical-align: top;
}
.bets-table.ext-strat-table th:nth-child(6),
.bets-table.ext-strat-table td:nth-child(6) {
  width: 17rem;
  min-width: 15rem;
  max-width: 22rem;
  white-space: nowrap;
  vertical-align: middle;
}
.bets-table.ext-strat-table td:nth-child(6) .btn-sm {
  margin-left: 0;
  margin-right: 6px;
}
.bets-table.ext-strat-table td:nth-child(6) .btn-sm:last-child {
  margin-right: 0;
}

/* ---- 移动端 / 窄屏自适应 ---- */
@media (max-width: 900px) {
  .topbar {
    display: block;
    padding: 8px 12px;
    padding-left: max(12px, env(safe-area-inset-left, 0px));
    padding-right: max(12px, env(safe-area-inset-right, 0px));
    padding-top: max(8px, env(safe-area-inset-top, 0px));
  }
  .topbar-mobile-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    width: 100%;
    min-height: 44px;
    padding: 8px 12px;
    margin: 0;
    border-radius: 8px;
    background: var(--bg-3);
    border: 1px solid var(--border);
    cursor: pointer;
    box-sizing: border-box;
    font: inherit;
    color: inherit;
    -webkit-tap-highlight-color: transparent;
  }
  .topbar-mobile-toggle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }
  .topbar-mobile-toggle-title {
    font-weight: 600;
    color: var(--accent);
    font-size: 15px;
    flex-shrink: 0;
  }
  .topbar-mobile-hint {
    font-size: 12px;
    color: var(--fg-dim);
    margin-left: auto;
    margin-right: 4px;
    white-space: nowrap;
  }
  .topbar-rest {
    display: none;
    margin-top: 10px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    gap: 12px;
    flex-direction: column;
    align-items: stretch;
  }
  .topbar-mobile-cb:checked ~ .topbar-rest {
    display: flex;
  }
  .topbar-rest .brand {
    display: none;
  }
  .status-group {
    flex: 1 1 100%;
    min-width: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 14px;
  }
  .status-item {
    min-width: 0;
    flex-wrap: wrap;
    row-gap: 2px;
  }
  .status-item .value {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
  }
  .actions {
    flex: 1 1 100%;
    width: 100%;
    justify-content: stretch;
    gap: 8px;
  }
  .actions .btn {
    flex: 1 1 auto;
    min-height: 44px;
    padding: 10px 12px;
  }
  /* 外部 Python 策略：列少，窄屏下按视口换行排布，避免依赖 1040px 最小宽 */
  .bets-table.ext-strat-table {
    min-width: 0;
    width: 100%;
    max-width: 100%;
    table-layout: fixed;
  }
  .bets-table.ext-strat-table th,
  .bets-table.ext-strat-table td {
    white-space: normal;
    word-break: break-word;
    overflow-wrap: anywhere;
    vertical-align: top;
  }
  .bets-table.ext-strat-table th {
    white-space: normal;
  }
  .bets-table.ext-strat-table th:nth-child(2),
  .bets-table.ext-strat-table td:nth-child(2),
  .bets-table.ext-strat-table th:nth-child(3),
  .bets-table.ext-strat-table td:nth-child(3) {
    white-space: nowrap;
    word-break: normal;
    overflow-wrap: normal;
  }
  .bets-table.ext-strat-table th:nth-child(2),
  .bets-table.ext-strat-table td:nth-child(2) {
    width: 3.75rem;
    max-width: 4.25rem;
  }
  .bets-table.ext-strat-table th:nth-child(1),
  .bets-table.ext-strat-table td:nth-child(1),
  .bets-table.ext-strat-table th:nth-child(4),
  .bets-table.ext-strat-table td:nth-child(4),
  .bets-table.ext-strat-table th:nth-child(5),
  .bets-table.ext-strat-table td:nth-child(5),
  .bets-table.ext-strat-table th:nth-child(6),
  .bets-table.ext-strat-table td:nth-child(6) {
    width: auto;
    max-width: none;
    min-width: 0;
  }
  .bets-table.ext-strat-table th:nth-child(6),
  .bets-table.ext-strat-table td:nth-child(6) {
    white-space: normal;
  }
  .bets-table.ext-strat-table td:nth-child(6) .btn-sm {
    margin-bottom: 4px;
  }
  .ext-strat-table td:nth-child(1),
  .ext-strat-table td:nth-child(5) {
    text-align: left;
  }
  .main.layout-main {
    padding: 12px;
    padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
    gap: 12px;
  }
}

@media (min-width: 901px) {
  .topbar-rest {
    display: contents !important;
  }
  .topbar-mobile-toggle {
    display: none !important;
  }
}

@media (max-width: 520px) {
  body {
    font-size: 13px;
  }
  .actions {
    flex-direction: column;
  }
  .actions .btn {
    width: 100%;
  }
  .card {
    padding: 12px;
  }
  .card .row:not(.row-check):not(.actions-inline) {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px 0;
  }
  .card .row:not(.row-check):not(.actions-inline) .value {
    width: 100%;
    text-align: left;
    white-space: normal;
    word-break: break-word;
  }
  .row-check .check-label {
    align-items: flex-start;
  }
  .row-next-stake {
    flex-direction: column;
    align-items: flex-start;
  }
  .row-next-stake .btn-sm {
    margin-left: 0;
    margin-top: 6px;
  }
  .input,
  .input-wide {
    width: 100%;
    max-width: 100%;
  }
  .value.big {
    font-size: 16px;
  }
  .ball {
    width: 26px;
    height: 26px;
    font-size: 12px;
  }
  .bets-table {
    font-size: 12px;
    min-width: 920px;
  }
  .bets-table th,
  .bets-table td {
    padding: 6px 8px;
  }
  dialog {
    width: min(560px, 100vw - 16px);
    max-height: min(90vh, 100dvh - 16px);
    margin: auto;
    padding: 16px;
    overflow-y: auto;
  }
  .dialog-actions {
    flex-wrap: wrap;
    justify-content: stretch;
  }
  .dialog-actions .btn {
    flex: 1 1 calc(50% - 4px);
    min-height: 44px;
  }
}

/* ---- 模拟玩家（与主界面同风格） ---- */
.card.ext-strat,
.card.players {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}
.ext-strat-head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin: 0 0 12px 0;
  padding: 0;
  border: none;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  text-align: left;
}
.ext-strat-collapsed .ext-strat-head {
  margin-bottom: 0;
}
.ext-strat-head h2 {
  margin: 0;
  flex: 1;
  font-size: 14px;
  color: var(--fg-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}
.ext-strat-head-hint {
  font-size: 12px;
  color: var(--fg-dim);
}
.ext-strat-chev::before {
  content: "\25BE";
  font-size: 12px;
  color: var(--fg-dim);
  display: inline-block;
  line-height: 1;
  transition: transform 0.15s ease;
}
.ext-strat-collapsed .ext-strat-chev::before {
  transform: rotate(-90deg);
}
.ext-strat-head:hover h2,
.ext-strat-head:hover .ext-strat-head-hint,
.ext-strat-head:focus-visible h2,
.ext-strat-head:focus-visible .ext-strat-head-hint {
  color: var(--fg);
}
.ext-strat-head:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
.player-detail-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px 20px;
  margin-top: 4px;
  padding-top: 12px;
  border-top: 1px solid rgba(42, 51, 64, 0.6);
}
.player-form-block,
.player-side-block {
  min-width: 0;
}
@media (max-width: 900px) {
  .player-detail-layout {
    grid-template-columns: 1fr;
  }
}
.player-table {
  min-width: 960px;
}
.player-col-streak {
  min-width: 5.5rem;
  max-width: 7rem;
  vertical-align: top;
  font-size: 11px;
  line-height: 1.45;
  white-space: pre-line;
}
.bets-table.player-table th.player-col-streak {
  white-space: normal;
  line-height: 1.35;
}
.player-col-hitrates {
  min-width: 6.5rem;
  max-width: 8.5rem;
  vertical-align: top;
  font-size: 11px;
  line-height: 1.45;
  white-space: pre-line;
}
.bets-table.player-table th.player-col-hitrates {
  white-space: normal;
  line-height: 1.35;
}
.player-stats-stack {
  white-space: pre-line;
  line-height: 1.45;
  font-size: 11px;
}
/* 玩家列表：避免 fixed+1% 列被压成一字宽；允许按内容撑开横向滚动 */
.bets-table.player-table {
  table-layout: auto;
  width: max-content;
  max-width: none;
}
.player-col-bet {
  min-width: 11rem;
  max-width: 18rem;
  vertical-align: top;
  font-size: 12px;
}
.bets-table.player-table th.player-col-bet {
  white-space: normal;
  line-height: 1.3;
  min-width: 11rem;
}
.pbc-stack {
  display: flex;
  flex-direction: column;
  gap: 3px;
  line-height: 1.35;
}
.pbc-line {
  word-break: normal;
  overflow-wrap: break-word;
  white-space: normal;
}
.pbc-sub {
  font-size: 11px;
  color: var(--fg-dim);
  opacity: 0.92;
}
.pbc-amt {
  color: var(--fg-dim);
  font-weight: 500;
}
.player-outcome-cell .pbc-amt {
  color: inherit;
  opacity: 0.95;
}
.pbc-empty {
  color: var(--fg-dim);
}
.player-outcome-cell.player-last-bet-win {
  color: var(--ok);
  font-weight: 600;
}
.player-outcome-cell.player-last-bet-lose {
  color: var(--err);
  font-weight: 600;
}
.player-outcome-cell.player-last-bet-pending {
  color: var(--fg-dim);
  font-weight: 500;
}
.player-col-actions {
  width: 1%;
  white-space: nowrap;
  text-align: right;
  vertical-align: middle;
}
.player-table .player-col-actions .btn-sm + .btn-sm {
  margin-left: 6px;
}
.player-table-sm {
  min-width: 360px;
}
.player-row:hover {
  background: rgba(77, 171, 247, 0.06);
}
.player-row-pinned td {
  background: rgba(77, 171, 247, 0.05);
}
.player-row-pinned:hover td {
  background: rgba(77, 171, 247, 0.1);
}
.player-pin-mark {
  display: inline-block;
  margin-right: 4px;
  color: var(--accent, #6eb5ff);
  font-size: 12px;
  line-height: 1;
}
.player-table .player-col-actions .btn-pin-active {
  color: var(--accent, #6eb5ff);
  border-color: rgba(110, 181, 255, 0.45);
}
.player-detail-title {
  margin: 16px 0 8px;
  font-size: 13px;
  color: var(--fg-dim);
  font-weight: 600;
  letter-spacing: 0.04em;
}
.player-subh {
  margin: 10px 0 6px;
  font-size: 12px;
  color: var(--fg-dim);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
select.input {
  width: 100%;
  min-width: 0;
  max-width: 100%;
}

.ext-strat-actions {
  position: relative;
  width: 100%;
  min-width: 0;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.ext-file-input {
  position: absolute;
  left: 0;
  top: 0;
  width: 0.1px;
  height: 0.1px;
  opacity: 0;
  overflow: hidden;
  z-index: -1;
}

.ext-file-name {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ext-kind-select {
  width: auto;
  min-width: 120px;
  max-width: 200px;
}
@media (max-width: 520px) {
  .ext-strat-actions .ext-kind-select {
    flex: 1 1 100%;
    max-width: none;
    width: 100%;
  }
}

.label-inline {
  font-size: 12px;
  color: var(--fg-dim);
}

.card .hint.ok {
  color: var(--ok);
}

.card .hint.error {
  color: var(--err);
}

.hint.warn {
  color: var(--warn);
}

.follow-player-checks {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
  padding: 8px 10px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 6px;
  flex: 1;
  min-width: 0;
}

.row-follow-picks {
  align-items: flex-start;
}

.follow-player-check {
  font-size: 13px;
}

.follow-player-select-all {
  padding-bottom: 6px;
  margin-bottom: 2px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

/* 跟注状态：独立全宽卡片（位于顶栏三卡下方） */
.card.follow-status-panel {
  width: 100%;
  min-width: 0;
}

.follow-status-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 16px;
  margin-bottom: 12px;
}

.follow-status-head h2 {
  margin: 0;
}

.follow-status-scroll {
  overflow-x: auto;
  max-height: min(320px, 40vh);
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-3);
}

.follow-status-table {
  width: 100%;
  min-width: 820px;
  border-collapse: collapse;
  font-size: 13px;
}

.follow-status-table th,
.follow-status-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

.follow-status-table tbody tr:last-child td {
  border-bottom: none;
}

.follow-status-table th {
  color: var(--fg-dim);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  position: sticky;
  top: 0;
  background: var(--bg-3);
  white-space: nowrap;
}

.follow-status-table .col-player {
  min-width: 10em;
  max-width: 14em;
}

.follow-status-table .col-turn {
  white-space: nowrap;
}

.follow-status-table .col-phase {
  white-space: nowrap;
}

.follow-status-table .col-streak {
  white-space: pre-line;
  line-height: 1.35;
  min-width: 5.5em;
}

.follow-status-table .col-nums {
  min-width: 12em;
  white-space: nowrap;
}

.follow-status-table .col-amount {
  white-space: nowrap;
}

.follow-status-table .col-order {
  min-width: 16em;
  word-break: break-all;
  line-height: 1.4;
}

.follow-status-nums {
  line-height: 1.35;
}

.follow-dry-tag {
  display: inline-block;
  margin-left: 4px;
  padding: 0 4px;
  font-size: 10px;
  border-radius: 3px;
  background: var(--warn);
  color: #1a1a1a;
  font-weight: 600;
}
