:root {
  --bg: #0b0f17;
  --bg-soft: #121826;
  --panel: #161d2c;
  --panel-2: #1b2436;
  --line: #263149;
  --text: #e7ecf5;
  --muted: #8b98b0;
  --gold: #e8c473;
  --green: #3ddc97;
  --red: #ff6b6b;
  --blue: #63a4ff;
  --shadow: 0 18px 40px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(1200px 700px at 15% -10%, #17233a 0%, var(--bg) 55%) fixed;
  color: var(--text);
  font: 14px/1.5 -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  min-height: 100%;
}

button {
  font: inherit;
  cursor: pointer;
  border-radius: 9px;
  border: 1px solid transparent;
  padding: 8px 14px;
  transition: filter .15s ease, transform .05s ease, background .15s ease;
}
button:active { transform: translateY(1px); }
button.primary {
  background: linear-gradient(180deg, #2f6fed, #2457c9);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 6px 18px rgba(47, 111, 237, .35);
}
button.primary:hover { filter: brightness(1.08); }
button.ghost {
  background: rgba(255, 255, 255, .04);
  border-color: var(--line);
  color: var(--text);
}
button.ghost:hover { background: rgba(255, 255, 255, .09); }
button.danger { background: rgba(255, 107, 107, .14); border-color: rgba(255, 107, 107, .45); color: #ffb3b3; }
button.icon { padding: 2px 10px; font-size: 18px; line-height: 1.2; }
button:disabled { opacity: .5; cursor: not-allowed; }

input, select {
  font: inherit;
  color: var(--text);
  background: #0e1420;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 12px;
  outline: none;
}
input:focus, select:focus { border-color: #3b6fd4; box-shadow: 0 0 0 3px rgba(59, 111, 212, .18); }

.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
code { background: rgba(255, 255, 255, .07); padding: 1px 5px; border-radius: 5px; font-size: 12px; }

/* ---------------- login ---------------- */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(400px, 94vw);
  background: linear-gradient(180deg, rgba(30, 40, 60, .96), rgba(18, 24, 38, .98));
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px 26px 22px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-brand { font-size: 21px; font-weight: 700; letter-spacing: .5px; }
.login-brand .suit { color: var(--gold); }
.login-card .field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.login-card button { margin-top: 6px; padding: 11px; }
.error { color: #ff9d9d; min-height: 18px; font-size: 13px; }

/* ---------------- layout ---------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 15, 23, .82);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { font-weight: 700; letter-spacing: .5px; }
.brand .suit { color: var(--gold); }
.spacer { flex: 1; }
.conn { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12.5px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #5a6579; }
.dot.on { background: var(--green); box-shadow: 0 0 10px rgba(61, 220, 151, .8); }
.dot.off { background: #5a6579; }
.dot.err { background: var(--red); box-shadow: 0 0 10px rgba(255, 107, 107, .7); }
.who { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.who-name { color: var(--gold); font-weight: 600; }
.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}
.badge.role { border-color: rgba(232, 196, 115, .45); color: var(--gold); }

.controls {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 14px 18px 6px;
  flex-wrap: wrap;
}
.table-input { flex: 1 1 360px; max-width: 520px; }
#source-info { font-size: 12px; }

.table-list {
  display: flex;
  gap: 8px;
  padding: 8px 18px 0;
  flex-wrap: wrap;
}
.table-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12.5px;
  cursor: pointer;
}
.table-chip:hover { border-color: #3b6fd4; }
.table-chip .no { color: var(--gold); font-weight: 600; }
.table-chip .live { color: var(--green); font-size: 11px; }

.boards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(430px, 1fr));
  gap: 16px;
  padding: 14px 18px 60px;
}
.empty-hint { grid-column: 1 / -1; display: grid; place-items: center; padding: 30px 10px; }
.empty-card {
  border: 1px dashed var(--line);
  border-radius: 16px;
  padding: 26px 30px;
  max-width: 640px;
  background: rgba(20, 27, 42, .55);
}
.empty-card h2 { margin: 0 0 6px; font-size: 17px; }
.hint-list { margin: 12px 0 0; padding-left: 18px; color: var(--muted); font-size: 13px; }
.hint-list li { margin: 4px 0; }

/* ---------------- board ---------------- */
.board {
  background: linear-gradient(180deg, var(--panel), #131a29);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px 14px 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}
.board-head { display: flex; align-items: flex-start; gap: 10px; }
.board-title { display: flex; flex-direction: column; min-width: 0; }
.board-title strong { font-size: 15px; }
.board-title .sub { font-size: 11.5px; color: var(--muted); }
.board-stats { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; align-items: center; }
.tag {
  font-size: 11.5px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}
.tag.stage { color: #0b0f17; background: var(--gold); border-color: transparent; font-weight: 700; }
.tag.stage.finished { background: #6b7385; color: #fff; }
.tag.stage.waiting { background: #3d4a63; color: #dfe7f5; }
.tag.turn { color: var(--green); border-color: rgba(61, 220, 151, .45); }
.stat { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.stat b { color: var(--text); font-weight: 600; }

.board-cards {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 8px 10px;
  background: rgba(6, 10, 18, .55);
  border: 1px solid rgba(38, 49, 73, .8);
  border-radius: 12px;
  min-height: 66px;
}
.slot {
  width: 42px;
  height: 58px;
  border-radius: 7px;
  border: 1px dashed rgba(139, 152, 176, .35);
  display: grid;
  place-items: center;
  color: rgba(139, 152, 176, .45);
  font-size: 12px;
}
.card {
  width: 42px;
  height: 58px;
  border-radius: 7px;
  background: linear-gradient(180deg, #fdfefe, #e9edf5);
  color: #1b2230;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  font-weight: 700;
  box-shadow: 0 3px 8px rgba(0, 0, 0, .35);
  position: relative;
  flex: 0 0 auto;
}
.card .rank { font-size: 19px; line-height: 1; }
.card .suit { font-size: 13px; line-height: 1.1; }
.card.red { color: #cf2f42; }
.card.small { width: 30px; height: 42px; border-radius: 5px; }
.card.small .rank { font-size: 14px; }
.card.small .suit { font-size: 10px; }
.card.back {
  background: repeating-linear-gradient(45deg, #23304a, #23304a 4px, #1a2438 4px, #1a2438 8px);
  border: 1px solid #32415f;
  color: transparent;
  box-shadow: none;
}

.seats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
}
.seat {
  background: rgba(10, 15, 25, .55);
  border: 1px solid rgba(38, 49, 73, .9);
  border-radius: 11px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  transition: border-color .15s ease, background .15s ease;
}
.seat.turn { border-color: rgba(61, 220, 151, .75); background: rgba(26, 60, 47, .35); box-shadow: 0 0 0 1px rgba(61, 220, 151, .25) inset; }
.seat.folded { opacity: .45; }
.seat.winner { border-color: var(--gold); box-shadow: 0 0 18px rgba(232, 196, 115, .25); }
.seat-top { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.seat-no {
  background: rgba(255, 255, 255, .08);
  border-radius: 6px;
  padding: 1px 5px;
  font-size: 11px;
  color: var(--muted);
}
.seat-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat-uid { margin-left: auto; color: var(--muted); font-size: 10.5px; font-family: ui-monospace, Menlo, monospace; }
.seat-holes { display: flex; gap: 4px; align-items: center; min-height: 42px; }
.seat-meta { display: flex; gap: 8px; align-items: center; font-size: 11px; color: var(--muted); }
.seat-meta .stack { color: var(--text); font-weight: 600; }
.seat-meta .bet { color: var(--gold); }
.seat-tags { display: flex; gap: 4px; flex-wrap: wrap; }
.seat-actions { display: flex; gap: 6px; margin-top: 2px; }
.swap-btn {
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 7px;
  border: 1px solid rgba(255, 107, 107, .45);
  background: rgba(255, 107, 107, .12);
  color: #ffb3b3;
  cursor: pointer;
}
.swap-btn:hover { background: rgba(255, 107, 107, .22); color: #fff; }
.swap-flag { color: #ffb3b3; border-color: rgba(255, 107, 107, .45); background: rgba(255, 107, 107, .12); }
.mini {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}
.mini.d { background: rgba(232, 196, 115, .16); color: var(--gold); border-color: rgba(232, 196, 115, .4); }
.mini.fold { background: rgba(255, 107, 107, .12); color: #ff9d9d; border-color: rgba(255, 107, 107, .3); }
.mini.allin { background: rgba(99, 164, 255, .14); color: var(--blue); border-color: rgba(99, 164, 255, .35); }
.mini.bot { background: rgba(139, 152, 176, .12); }
.hand-label { font-size: 11px; color: #9fd7ff; margin-top: 2px; }

.result {
  border-top: 1px dashed var(--line);
  padding-top: 8px;
  font-size: 12px;
  color: var(--gold);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.board-error {
  color: #ff9d9d;
  font-size: 12.5px;
  border-top: 1px dashed rgba(255, 107, 107, .35);
  padding-top: 8px;
}
.board-close {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  padding: 0 4px;
}
.board-close:hover { color: #fff; }

/* ---------------- footer / modal / toast ---------------- */
.logbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 8px 18px;
  background: rgba(9, 13, 20, .92);
  border-top: 1px solid var(--line);
  font-size: 12px;
  backdrop-filter: blur(8px);
}
.status-line { color: var(--green); }

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(4, 7, 12, .72);
  display: grid;
  place-items: center;
  padding: 20px;
}
.modal[hidden] { display: none; }
.modal-card {
  width: min(860px, 96vw);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.modal-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.modal-head h2 { font-size: 16px; margin: 0; flex: 1; }
.modal-body { padding: 16px; overflow: auto; display: flex; flex-direction: column; gap: 14px; }

.account-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.account-form input, .account-form select { flex: 1 1 160px; min-width: 130px; }
.account-form > .primary { margin-left: auto; }
.perm-form { flex: 1 1 100%; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.perm-check { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; font-size: 12.5px; color: var(--text); background: rgba(255, 255, 255, .04); border: 1px solid var(--line); border-radius: 9px; padding: 7px 10px; cursor: pointer; }
.perm-check input { width: auto; accent-color: var(--green); }
.perm-check input:disabled + span { color: var(--muted); }
.perm-badges { display: flex; gap: 4px; flex-wrap: wrap; }
.account-actions { display: flex; gap: 4px; flex-wrap: wrap; white-space: nowrap; }
.account-actions button { padding: 4px 8px; }
.view-denied { display: grid; place-items: center; padding: 60px 20px; }
.denied-card {
  max-width: 560px;
  text-align: center;
  background: linear-gradient(180deg, rgba(30, 40, 60, .9), rgba(18, 24, 38, .95));
  border: 1px solid rgba(245, 166, 35, .45);
  border-radius: 16px;
  padding: 28px 32px;
  box-shadow: var(--shadow);
}
.denied-card h2 { margin: 0 0 8px; font-size: 19px; color: var(--warn); }
.denied-card p { margin: 0; line-height: 1.7; }

.swap-info { display: flex; flex-direction: column; gap: 4px; padding: 10px 12px; background: rgba(255, 255, 255, .03); border: 1px solid var(--line); border-radius: 10px; }
.swap-line { font-size: 12.5px; color: var(--muted); }
.swap-line b { color: var(--text); }
.swap-field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
.swap-field select, .swap-field input { width: 100%; }
.swap-card-row { display: flex; gap: 8px; }
.swap-card-row input { flex: 1; text-transform: none; font-family: ui-monospace, Menlo, monospace; }
.swap-hint { margin: 0; font-size: 11.5px; color: #ffb3b3; line-height: 1.6; border-left: 2px solid rgba(255, 107, 107, .5); padding-left: 8px; }
.swap-error { font-size: 12.5px; color: #ff9d9d; background: rgba(255, 107, 107, .1); border: 1px solid rgba(255, 107, 107, .35); border-radius: 8px; padding: 8px 10px; }
.swap-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 2px; }
.swap-actions .danger { background: linear-gradient(180deg, #e05555, #b93c3c); border-color: transparent; }

.form-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.form-row input { min-width: 150px; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 12px; }
table.grid { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.grid th, table.grid td { padding: 8px 10px; text-align: left; border-bottom: 1px solid rgba(38, 49, 73, .7); white-space: nowrap; }
table.grid th { color: var(--muted); font-weight: 600; background: rgba(255, 255, 255, .03); }
table.grid tr:last-child td { border-bottom: none; }
.pill { font-size: 11px; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.pill.on { color: var(--green); border-color: rgba(61, 220, 151, .4); }
.pill.off { color: #ff9d9d; border-color: rgba(255, 107, 107, .35); }

.toast {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(24, 33, 50, .96);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 10px;
  font-size: 13px;
  z-index: 80;
  box-shadow: var(--shadow);
}
.toast.err { border-color: rgba(255, 107, 107, .5); color: #ffb3b3; }
.toast[hidden] { display: none; }

@media (max-width: 560px) {
  .boards { grid-template-columns: 1fr; padding: 12px 10px 70px; }
  .topbar { flex-wrap: wrap; gap: 8px; }
  .who { order: 3; }
}
