:root {
  --bg: #0e1116;
  --panel: #171c24;
  --panel2: #1f2632;
  --line: #2a3240;
  --tx: #e8ecf2;
  --mut: #8b95a6;
  --win: #34d399;
  --lose: #f87171;
  --gold: #fbbf24;
  --blue: #4f8ef7;
}

* { box-sizing: border-box; margin: 0; -webkit-tap-highlight-color: transparent; }
[v-cloak] { display: none; }

html, body { height: 100%; overscroll-behavior: none; -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--tx);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
#app {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

button {
  font: inherit;
  border: none;
  border-radius: 9px;
  cursor: pointer;
  background: var(--panel2);
  color: var(--tx);
  touch-action: manipulation;
}
button:disabled { opacity: .35; cursor: default; }
input, select {
  font: inherit;
  background: #12161d;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--tx);
  padding: 10px 12px;
}
input:focus, select:focus { outline: none; border-color: var(--blue); }

.up { color: var(--win); }
.down { color: var(--lose); }
.gold { color: var(--gold); }
.nowrap { white-space: nowrap; }

/* ---------- header ---------- */
header {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 2px 2px 4px;
}
.title { font-size: clamp(15px, 1.4vmin + 5px, 21px); font-weight: 700; }
.info { margin-top: 3px; display: flex; align-items: center; flex-wrap: wrap; gap: clamp(5px, 0.6vmin + 1px, 10px); }
.badge {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: clamp(3px, 0.5vmin + 1px, 7px) clamp(10px, 1.1vmin + 2px, 18px);
  font-size: clamp(12px, 1.2vmin + 4px, 17px);
  color: var(--mut);
  white-space: nowrap;
}
.badge b { color: var(--tx); font-weight: 700; font-size: 1.12em; font-variant-numeric: tabular-nums; }
.badge.warn {
  border-color: var(--lose);
  background: color-mix(in srgb, var(--lose) 16%, var(--panel2));
}
.badge.warn b { color: var(--lose); }
.badge.gold-badge {
  border-color: color-mix(in srgb, var(--gold) 50%, var(--line));
  background: color-mix(in srgb, var(--gold) 10%, var(--panel2));
}
.hbtns { display: flex; gap: 6px; }
.primary { background: var(--blue); color: #fff; padding: 6px 10px; font-weight: 600; font-size: 13.5px; }
.ghost { background: transparent; border: 1px solid var(--line); padding: 6px 10px; font-size: 13.5px; }
.mini { padding: 4px 9px; font-size: 12.5px; border-radius: 8px; }
.danger-solid { background: #b91c1c; color: #fff; padding: 10px 16px; }

/* ---------- 悬浮置顶（头部+庄家区） ---------- */
.top-sticky {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  padding-bottom: 6px;
}

/* ---------- main frame ---------- */
main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ---------- dealer ---------- */
.dealer-zone { position: relative; flex: none; }
.dealer-drop { min-height: 46px; }
.dealer-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: linear-gradient(135deg, #2a2312, #1a1f28);
  border: 1px solid #7a661f;
  border-radius: 12px;
  padding: 8px 16px;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.dealer-card .tag {
  flex: none;
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--gold);
  color: #201a05;
  font-size: 17px;
  font-weight: 800;
}
.dname { font-size: clamp(16px, 2vmin + 5px, 26px); font-weight: 700; }
.dstats { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 1px; font-size: clamp(11px, 1.1vmin + 3px, 15px); color: var(--mut); }
.dstats b { font-size: clamp(14px, 1.6vmin + 4px, 20px); color: var(--tx); font-variant-numeric: tabular-nums; margin-left: 4px; }
.dz-hint {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  border: 1.5px dashed var(--line);
  border-radius: 12px;
  color: var(--mut);
  font-size: 13px;
  pointer-events: none;
}

/* ---------- decks ---------- */
.decks {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
  grid-auto-rows: 1fr;
  gap: 6px;
}
@media (max-width: 620px) {
  .decks { grid-template-columns: 1fr; grid-template-rows: repeat(4, 1fr); grid-auto-rows: 1fr; }
}
.deck {
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 5px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow: hidden;
}
.deck-head { display: flex; align-items: baseline; gap: 8px; flex: none; }
.dno { font-size: 14px; font-weight: 700; }
.cnt { font-size: 11.5px; color: var(--mut); }
.deck-edit {
  margin-left: auto;
  align-self: center;
  flex: none;
  width: 24px;
  height: 24px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--mut);
  font-size: 12px;
  line-height: 1;
}
.deck-edit:active { color: var(--tx); border-color: var(--blue); }

.add-deck {
  min-height: 56px;
  border: 1.5px dashed var(--line);
  border-radius: 12px;
  background: transparent;
  color: var(--mut);
  font-size: 14px;
}
.add-deck:active { color: var(--tx); border-color: var(--blue); }

.ctl { display: flex; align-items: center; gap: 4px; flex: none; flex-wrap: nowrap; }
.dirbtn {
  flex: none;
  width: clamp(36px, 4vmin + 5px, 48px);
  height: clamp(36px, 4vmin + 5px, 48px);
  padding: 0;
  border: 1.5px solid var(--line);
  border-radius: 50%;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
}
.dirbtn svg { width: 45%; height: 45%; }
/* 加减按钮和倍数之间拉开距离 */
.dirbtn.win { margin-left: 12px; }
.dirbtn:active { transform: scale(.96); }
.dirbtn.win { color: var(--win); border-color: color-mix(in srgb, var(--win) 45%, var(--line)); }
.dirbtn.lose { color: var(--lose); border-color: color-mix(in srgb, var(--lose) 45%, var(--line)); }
.mult {
  display: flex; gap: 2px;
  padding: 2px;
  background: var(--panel2);
  border-radius: 9px;
}
.mbtn {
  width: clamp(30px, 3.6vmin + 4px, 42px);
  height: clamp(26px, 3vmin + 4px, 38px);
  padding: 0;
  font-size: clamp(12.5px, 1.2vmin + 3px, 16px);
  font-weight: 600;
  background: transparent;
  border-radius: 6px;
  color: var(--mut);
  font-variant-numeric: tabular-nums;
}
.mbtn.on { background: var(--blue); color: #fff; }

.players {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  /* 内边距给选中/拖拽的发光留出空间，负 margin 抵消以免布局位移 */
  padding: 5px;
  margin: -5px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: flex-start;
  align-content: flex-start;
}
.pchip {
  display: inline-flex;
  align-items: baseline;
  gap: clamp(6px, 0.8vmin + 1px, 10px);
  max-width: 100%;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: clamp(4px, 0.6vmin + 1px, 8px) clamp(12px, 1.2vmin + 2px, 18px);
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overflow: hidden;
}
.pname {
  font-size: clamp(12px, 1.3vmin + 3px, 18px);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pbal { font-size: clamp(12px, 1.4vmin + 3px, 19px); font-weight: 700; font-variant-numeric: tabular-nums; }
.pbal.neg { color: var(--lose); }
.pdelta {
  font-style: normal;
  font-size: clamp(10px, 1vmin + 2px, 14px);
  font-weight: 700;
  margin-left: 2px;
  font-variant-numeric: tabular-nums;
}
.pbet { font-size: clamp(10.5px, 1vmin + 2px, 14px); color: var(--mut); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- waiting ---------- */
.wait-zone {
  flex: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 4px 10px 6px;
}
.w-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 5px; font-size: 13px; font-weight: 700; }
.w-head .w-hint { font-size: 11px; font-weight: 400; color: var(--mut); }
.wlist {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 28px;
  align-items: flex-start;
}
.wchip {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 13px;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.wchip b { font-size: clamp(12px, 1.3vmin + 3px, 17px); }
.wchip .wbal { font-size: clamp(11px, 1.2vmin + 3px, 15px); color: var(--mut); font-variant-numeric: tabular-nums; }
.wchip .wbal.neg { color: var(--lose); }
.wchip .wbet { flex: none; align-self: center; display: flex; align-items: center; color: var(--win); }
.wchip .wbet svg { width: clamp(11px, 1.2vmin + 2px, 15px); height: clamp(11px, 1.2vmin + 2px, 15px); display: block; }

/* ---------- 历史客人（名字输入下拉） ---------- */
.name-sug {
  position: absolute;
  z-index: 5;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: -4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #12161d;
  overflow: hidden;
  box-shadow: 0 10px 24px rgba(0, 0, 0, .5);
}
.name-sug-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 12px;
  cursor: pointer;
}
.name-sug-item + .name-sug-item { border-top: 1px solid #202835; }
.name-sug-item:active { background: var(--panel2); }
.name-sug-item span { font-size: 13px; }
.gsug-del { font-style: normal; font-size: 11px; color: var(--mut); padding: 2px 4px; }
.gsug-del:active { color: var(--lose); }
.guests { border-top: 1px solid var(--line); padding-top: 10px; }

/* ---------- 风险提醒（实时） ---------- */
/* 玩家：黄 = 余额不足下注5倍；红 = 下注超过余额 */
.pchip.risk-low {
  border-color: var(--gold);
  background: color-mix(in srgb, var(--gold) 14%, var(--panel2));
}
.pchip.risk-over {
  border-color: var(--lose);
  background: color-mix(in srgb, var(--lose) 18%, var(--panel2));
}
.pchip.risk-over .pbal { color: var(--lose); }
/* 庄家：黄 = 余额不足总注5倍；红 = 不足总注1倍 */
.dealer-card.risk-low { border-color: var(--gold); }
.dealer-card.risk-over {
  border-color: var(--lose);
  box-shadow: 0 0 12px color-mix(in srgb, var(--lose) 45%, transparent);
}
.w-empty { color: var(--mut); font-size: 12px; padding: 4px 2px; }

/* ---------- sortable states ---------- */
.sortable-ghost { opacity: .35; }
.sortable-chosen { box-shadow: 0 0 0 2px var(--blue); }
.sortable-drag {
  opacity: .95;
  transform: rotate(1.5deg);
  box-shadow: 0 10px 26px rgba(0, 0, 0, .5);
}

/* ---------- modal ---------- */
.overlay {
  position: fixed; inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, .58);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  width: 640px;
  max-width: 94vw;
  max-height: 86vh;
  max-height: 86dvh;
  overflow: auto;
}
.modal.small { width: 420px; }
.m-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; font-size: 17px; }
.m-head-btns { display: flex; gap: 6px; }
.mini.danger { color: var(--lose); }
.m-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.m-grid label, .m-col label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--mut); }
.m-col { position: relative; margin-bottom: 12px; display: flex; flex-direction: column; gap: 10px; }
.m-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 12px;
  background: var(--panel2);
  border-radius: 10px;
  margin-bottom: 12px;
  font-size: 14px; color: var(--mut);
}
.m-row b.big { font-size: 24px; color: var(--tx); font-variant-numeric: tabular-nums; }
.adj { width: 110px; }
.m-btns { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.m-btns .primary { padding: 10px 16px; font-size: 14px; }
.m-btns .ghost { padding: 10px 16px; font-size: 14px; }
.cmsg { margin-bottom: 16px; line-height: 1.6; }
.deck-hint { font-size: 12.5px; color: var(--mut); line-height: 1.6; }

.menu-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.menu-grid button { padding: 12px 8px; }
.help { border-top: 1px solid var(--line); padding-top: 10px; font-size: 12.5px; color: var(--mut); line-height: 1.9; }

/* ---------- 后台参数 ---------- */
.params { border-top: 1px solid var(--line); padding-top: 10px; margin-bottom: 12px; }
.p-title { font-size: 13px; font-weight: 700; margin-bottom: 8px; }
.p-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.p-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--mut); }
.p-grid input { padding: 7px 9px; font-variant-numeric: tabular-nums; }
.lock-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--tx);
  margin-top: 8px;
  cursor: pointer;
}
.lock-toggle input { width: 16px; height: 16px; }
.params .deck-hint { margin: 8px 0 0; }
.rake-box { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 8px; }
.rake-row {
  display: flex;
  gap: 10px;
  justify-content: space-between;
  font-size: 12px;
  color: var(--mut);
  font-variant-numeric: tabular-nums;
  padding: 3px 0;
  border-bottom: 1px solid #202835;
}
.rake-row .up { font-weight: 700; }

/* ---------- history table ---------- */
.hist { border-top: 1px solid var(--line); padding-top: 10px; }
.h-title { font-size: 14px; font-weight: 700; margin-bottom: 8px; }
.htab { width: 100%; border-collapse: collapse; font-size: 13px; }
.htab th { text-align: left; color: var(--mut); font-weight: 400; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.htab td { padding: 6px; border-bottom: 1px solid #202835; font-variant-numeric: tabular-nums; }
.htab .tar { text-align: right; font-weight: 700; }
.empty { color: var(--mut); font-size: 13px; padding: 10px 4px; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 90;
  background: #2b3340;
  border: 1px solid var(--line);
  color: var(--tx);
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
}

/* ---------- 自适应 ---------- */
/* 手机竖屏：整页可滚动，桌子再多人也看得见 */
@media (max-width: 620px) {
  body { overflow: visible; height: auto; min-height: 100dvh; }
  #app { height: auto; min-height: 100dvh; }
  main { overflow: visible; flex: none; }
  .decks { grid-template-columns: 1fr; grid-template-rows: none; grid-auto-rows: auto; }
  .deck { min-height: 108px; }
  .players { flex: none; min-height: 40px; max-height: 180px; }
}
/* 矮屏（手机横屏等）：压缩纵向留白 */
@media (max-height: 520px) {
  body { padding: 4px 10px calc(4px + env(safe-area-inset-bottom)); }
  header { padding: 0 2px 2px; }
  .dealer-card { padding: 4px 12px; }
  .dealer-card .tag { width: 30px; height: 30px; font-size: 14px; }
  .dealer-drop { min-height: 38px; }
  .wait-zone { padding: 2px 10px 4px; }
  .wlist { min-height: 24px; }
}
