:root {
  --felt-1: #12463a;
  --felt-2: #0b3028;
  --gold: #d8b45a;
  --gold-dim: #8a7233;
  --ink: #eef2ee;
  --ink-dim: #9db0a8;
  --card-face: #fbfaf6;
  --card-edge: #d9d4c6;
  --red: #c0392b;
  --black: #1d2320;
  --danger: #e05b4b;
  --ok: #4fb47a;
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  background: #08130f;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.screen { position: absolute; inset: 0; }

/* ---------- 大厅 ---------- */
#lobby {
  display: grid;
  place-items: center;
  background:
    radial-gradient(120% 90% at 50% 0%, #1a5748 0%, #0b3028 55%, #06100d 100%);
  padding: 24px;
}

.lobby-card {
  width: min(420px, 100%);
  background: rgba(10, 30, 25, .72);
  border: 1px solid rgba(216, 180, 90, .28);
  border-radius: 20px;
  padding: 30px 28px 24px;
  backdrop-filter: blur(12px);
  box-shadow: 0 24px 70px rgba(0, 0, 0, .5);
}

.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 26px; }
.brand-mark {
  width: 52px; height: 52px;
  display: grid; place-items: center;
  font-size: 28px;
  color: var(--gold);
  background: linear-gradient(160deg, rgba(216,180,90,.18), rgba(216,180,90,.04));
  border: 1px solid rgba(216, 180, 90, .4);
  border-radius: 14px;
}
.brand h1 { font-size: 26px; letter-spacing: 3px; font-weight: 600; }
.brand-sub { font-size: 12px; color: var(--ink-dim); margin-top: 4px; letter-spacing: .5px; }

.field { display: block; margin-bottom: 16px; }
.field span {
  display: block;
  font-size: 12px;
  color: var(--ink-dim);
  margin-bottom: 7px;
  letter-spacing: 1px;
}
input {
  width: 100%;
  padding: 12px 14px;
  font-size: 15px;
  color: var(--ink);
  background: rgba(0, 0, 0, .3);
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 10px;
  outline: none;
  transition: border-color .15s;
}
input:focus { border-color: var(--gold-dim); }
input::placeholder { color: #5d7268; }

.lobby-actions { display: grid; gap: 12px; margin-top: 4px; }
.join-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; }

.btn {
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: .5px;
  color: var(--ink);
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 10px;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: rgba(255, 255, 255, .14); }
.btn:disabled { opacity: .38; cursor: not-allowed; }

.btn-primary {
  color: #17251f;
  background: linear-gradient(180deg, #e6c877, #c9a44b);
  border-color: #e6c877;
  font-weight: 600;
}
.btn-primary:hover:not(:disabled) { background: linear-gradient(180deg, #f0d489, #d6b157); }

.btn-ghost { background: transparent; }
.btn-sm { padding: 7px 14px; font-size: 13px; }

.lobby-msg { min-height: 18px; font-size: 12.5px; color: var(--danger); margin-top: 12px; }

.rules-hint {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, .08);
  font-size: 12px;
  color: var(--ink-dim);
  line-height: 1.7;
}
.rules-hint strong { color: var(--gold); display: block; margin-bottom: 3px; font-weight: 500; }

/* ---------- 顶栏 ---------- */
#table { display: flex; flex-direction: column; }

.topbar {
  height: 52px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  background: rgba(0, 0, 0, .35);
  border-bottom: 1px solid rgba(216, 180, 90, .18);
  font-size: 13px;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 14px; }
.topbar-center { display: flex; align-items: center; gap: 18px; }

.room-tag { color: var(--ink-dim); }
.room-tag b { color: var(--gold); font-family: ui-monospace, monospace; letter-spacing: 2px; }

.phase-tag {
  padding: 4px 10px;
  border-radius: 20px;
  background: rgba(216, 180, 90, .14);
  border: 1px solid rgba(216, 180, 90, .3);
  color: var(--gold);
  font-size: 11.5px;
}

.trump-box, .level-box { display: flex; align-items: baseline; gap: 6px; }
.lbl { font-size: 11px; color: var(--ink-dim); }
.trump-val { font-size: 17px; color: var(--gold); font-weight: 600; }
.trump-val.red { color: #e8695a; }
.level-val { font-size: 17px; color: var(--gold); font-weight: 600; }

/* 两队级牌进度 */
.progress { display: flex; gap: 12px; align-items: center; }
.team-prog { display: flex; align-items: center; gap: 5px; font-size: 10.5px; color: var(--ink-dim); }
.team-prog .tp-name { letter-spacing: .5px; }
.team-prog .tp-dots { display: flex; gap: 2px; }
.team-prog .dot2 {
  width: 5px; height: 5px; border-radius: 50%;
  background: rgba(255, 255, 255, .13);
}
.team-prog .dot2.done { background: var(--gold-dim); }
.team-prog .dot2.cur { background: var(--gold); box-shadow: 0 0 4px rgba(216, 180, 90, .7); }
.team-prog.hasDealer .tp-name { color: var(--gold); }
.score-tag {
  font-variant-numeric: tabular-nums;
  color: var(--ink-dim);
  padding: 4px 10px;
  border-radius: 6px;
  background: rgba(255, 255, 255, .05);
}
.score-tag .s-compact { display: none; }

/* ---------- 桌面 ---------- */
.felt {
  flex: 1 1 auto;
  position: relative;
  min-height: 0;
  background:
    radial-gradient(75% 65% at 50% 45%, var(--felt-1) 0%, var(--felt-2) 62%, #05100c 100%);
  box-shadow: inset 0 0 120px rgba(0, 0, 0, .55);
}
.felt::after {
  content: "";
  position: absolute;
  inset: 26px 40px;
  border: 1px solid rgba(216, 180, 90, .12);
  border-radius: 160px / 120px;
  pointer-events: none;
}

/* 座位 */
.seat {
  position: absolute;
  width: 128px;
  padding: 9px 11px;
  border-radius: 11px;
  background: rgba(0, 0, 0, .3);
  border: 1px solid rgba(255, 255, 255, .08);
  transition: all .2s;
  font-size: 12px;
}
.seat-n { top: 18px; left: 50%; transform: translateX(-50%); }
.seat-s { bottom: 14px; left: 50%; transform: translateX(-50%); width: 0; height: 0; padding: 0; border: 0; background: none; }
.seat-w { left: 18px; top: 50%; transform: translateY(-50%); }
.seat-e { right: 18px; top: 50%; transform: translateY(-50%); }

.seat.active {
  border-color: var(--gold);
  background: rgba(216, 180, 90, .13);
  box-shadow: 0 0 0 3px rgba(216, 180, 90, .12), 0 0 22px rgba(216, 180, 90, .2);
}
.seat.offline { opacity: .45; }

.seat-name {
  font-weight: 600;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.seat-name .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ok); flex: 0 0 auto; }
.seat-name .dot.off { background: #6a7a73; }
.seat-team { font-size: 10.5px; color: var(--ink-dim); margin-top: 2px; }
.seat-badges { display: flex; gap: 5px; margin-top: 6px; flex-wrap: wrap; }
.badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, .1);
  color: var(--ink-dim);
}
.badge.banker { background: rgba(216, 180, 90, .2); color: var(--gold); }
.badge.owner { background: rgba(230, 100, 90, .18); color: #e88a7d; }
.badge.ready { background: rgba(79, 180, 122, .18); color: var(--ok); }
.badge.you { background: rgba(120, 170, 255, .16); color: #8fb6ff; }
.seat-count { font-size: 11px; color: var(--ink-dim); margin-top: 5px; font-variant-numeric: tabular-nums; }
.seat-count b { color: var(--ink); }

/* 踢人按钮：房主专属，平时隐藏 hover 显现 */
.btn-kick {
  width: 100%;
  margin-top: 7px;
  padding: 4px 0;
  font-size: 11px;
  letter-spacing: 1px;
  color: #e88a7d;
  background: rgba(190, 60, 45, .12);
  border: 1px solid rgba(224, 91, 75, .35);
  border-radius: 6px;
  cursor: pointer;
  transition: all .15s;
}
.btn-kick:hover { background: rgba(190, 60, 45, .3); color: #fff; border-color: var(--danger); }

/* 中央 */
.center {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 14px;
  pointer-events: none;
}

.trick-area {
  display: grid;
  grid-template-columns: repeat(2, auto);
  gap: 10px 26px;
  justify-items: center;
  align-items: center;
  min-height: 110px;
}
.trick-slot { display: flex; gap: 4px; }
.trick-slot.empty { opacity: 0; }

.center-status {
  text-align: center;
  font-size: 12.5px;
  color: var(--ink-dim);
  min-height: 18px;
  letter-spacing: .5px;
}
.center-status b { color: var(--gold); font-weight: 500; }

/* ---------- 手牌 ---------- */
.handzone {
  flex: 0 0 auto;
  padding: 10px 18px 16px;
  background: linear-gradient(180deg, rgba(0,0,0,.1), rgba(0,0,0,.45));
}
.hand-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--ink-dim);
}
.hand-actions { display: flex; gap: 8px; }

.hand {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  width: 100%;
  min-height: 108px;
  padding-top: 16px;
  container-type: inline-size;
}

/* 牌：宽度由容器等分算出，保证 N 张一定排得进，不依赖 JS 测量。
   --denom = 0.55*N + 0.45（叠压 45%），由 JS 写在 .hand 上。
   总宽 = N*w - (N-1)*0.45w = w*(0.55N+0.45) = 容器宽  →  w = 容器宽/denom */
.card {
  position: relative;
  /* 等分宽度 + 上限：容器再宽，单张也不超过 76px */
  width: min(calc(100cqw / var(--denom, 7.05)), 92px);
  aspect-ratio: 5 / 7;
  /* 叠压量 = 牌宽的 45%，但不超过 43px（对应牌宽上限 76px 时的叠压）。
     用 max() 取「较不负」的那个，否则容器变宽时叠压会超过牌宽、整叠塌成一张。 */
  margin-left: max(calc(-45cqw / var(--denom, 7.05)), -41px);
  border-radius: 7px;
  background: linear-gradient(170deg, #ffffff, var(--card-face) 55%, #f2efe4);
  border: 1px solid var(--card-edge);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
  cursor: pointer;
  transition: transform .13s ease, box-shadow .13s ease;
  user-select: none;
  flex: 0 0 auto;
}
.card:first-child { margin-left: 0; }
.card:hover { transform: translateY(-9px); z-index: 30; box-shadow: 0 8px 18px rgba(0, 0, 0, .45); }
.card.selected {
  transform: translateY(-22px);
  box-shadow: 0 0 0 2px var(--gold), 0 10px 22px rgba(0, 0, 0, .5);
  z-index: 40;
}
.card.dim { filter: brightness(.72) saturate(.8); }

.card .corner {
  position: absolute;
  top: 4%;
  left: 7%;
  line-height: 1;
  text-align: center;
  font-weight: 700;
  font-size: min(calc(26cqw / var(--denom, 7.05)), 20px);
  letter-spacing: -.5px;
}
.card .corner .suit {
  display: block;
  margin-top: 4%;
  font-size: min(calc(19cqw / var(--denom, 7.05)), 15px);
}
.card .pip {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: min(calc(48cqw / var(--denom, 7.05)), 38px);
  opacity: .92;
}
.card.red { color: var(--red); }
.card.black { color: var(--black); }
.card.trump {
  background: linear-gradient(170deg, #fffdf3, #fbf4dd 55%, #f3e8c6);
  border-color: #d9c68a;
}
.card.trump::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 7px;
  border: 1.5px solid rgba(200, 165, 70, .55);
  pointer-events: none;
}
/* 中央出牌区的小牌：固定尺寸，不参与手牌等分 */
.card.small {
  width: 40px;
  height: 58px;
  aspect-ratio: auto;
  margin-left: -10px;
  border-radius: 5px;
}
.card.small .corner { font-size: 11px; top: 3px; left: 3px; }
.card.small .corner .suit { font-size: 9px; }
.card.small .pip { font-size: 18px; }
.card.small:first-child { margin-left: 0; }
.card.small:first-child { margin-left: 0; }

.card.back {
  background:
    repeating-linear-gradient(45deg, #1e4f42 0 5px, #17423a 5px 10px);
  border-color: #2f6a58;
}
.card.back::before {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(216, 180, 90, .3);
  border-radius: 3px;
}

/* ---------- 浮层 ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(3, 10, 8, .72);
  backdrop-filter: blur(4px);
  z-index: 100;
}
.overlay-card {
  width: min(400px, calc(100% - 40px));
  background: rgba(12, 34, 28, .96);
  border: 1px solid rgba(216, 180, 90, .3);
  border-radius: 18px;
  padding: 26px 26px 22px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .6);
}
.overlay-card h2 { font-size: 19px; margin-bottom: 6px; font-weight: 600; }
.overlay-card p { font-size: 13px; color: var(--ink-dim); line-height: 1.8; }
.overlay-card .suit-picker {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 18px 0;
}
.suit-btn {
  padding: 16px 0;
  font-size: 26px;
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 12px;
  cursor: pointer;
  color: var(--ink);
  transition: all .15s;
}
.suit-btn:hover:not(:disabled) { border-color: var(--gold); background: rgba(216, 180, 90, .14); }
.suit-btn:disabled { opacity: .25; cursor: not-allowed; }
.suit-btn.red { color: #e8695a; }
.suit-btn small { display: block; font-size: 10px; color: var(--ink-dim); margin-top: 3px; }

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 18px 0;
}
.result-cell {
  padding: 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, .05);
}
.result-cell .k { font-size: 11px; color: var(--ink-dim); margin-bottom: 5px; }
.result-cell .v { font-size: 20px; font-weight: 600; color: var(--gold); font-variant-numeric: tabular-nums; }
.result-cell .v.bad { color: #e8695a; }

/* ---------- 事件流 ---------- */
.eventlog {
  position: absolute;
  right: 16px;
  bottom: 132px;
  width: 190px;
  display: flex;
  flex-direction: column-reverse;
  gap: 5px;
  pointer-events: none;
  z-index: 20;
}
.eventlog .ev {
  font-size: 11.5px;
  padding: 6px 10px;
  border-radius: 7px;
  background: rgba(0, 0, 0, .5);
  border-left: 2px solid var(--gold-dim);
  color: var(--ink-dim);
  animation: evIn .25s ease;
}
@keyframes evIn { from { opacity: 0; transform: translateX(8px); } }

/* ---------- Toast ---------- */
.toast {
  position: absolute;
  top: 68px;
  left: 50%;
  transform: translateX(-50%);
  padding: 9px 18px;
  border-radius: 9px;
  background: rgba(190, 60, 45, .94);
  color: #fff;
  font-size: 13px;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
  animation: evIn .2s ease;
}
.toast.ok { background: rgba(46, 130, 85, .95); }

/* ---------- 移动端 ---------- */
@media (max-width: 720px) {
  /* 顶栏用网格：第一行 左/右，第二行 通栏居中的主牌信息 */
  .topbar {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "left right"
      "center center";
    align-items: center;
    gap: 4px 8px;
    height: auto;
    padding: 6px 8px;
    font-size: 11.5px;
    max-width: 100vw;
  }
  .topbar-left { grid-area: left; min-width: 0; gap: 7px; }
  .topbar-right { grid-area: right; gap: 7px; justify-self: end; min-width: 0; }
  .topbar-center { grid-area: center; width: auto; justify-content: center; gap: 10px; min-width: 0; }

  .room-tag, .phase-tag { font-size: 10.5px; }
  .phase-tag { padding: 3px 7px; }
  .score-tag { padding: 3px 6px; font-size: 10.5px; }
  .score-tag .s-full { display: none; }
  .score-tag .s-compact { display: inline; }
  .topbar-right .btn-sm { padding: 4px 9px; font-size: 11.5px; }
  .lbl { font-size: 10px; }
  .trump-val, .level-val { font-size: 15px; }

  /* 进度点压缩，确保两队在窄屏内不撑破 */
  .progress { gap: 7px; min-width: 0; }
  .team-prog { gap: 3px; font-size: 9px; }
  .team-prog .tp-dots { gap: 1px; }
  .team-prog .dot2 { width: 3px; height: 3px; }

  .seat { width: 88px; padding: 6px 8px; font-size: 10px; }
  .seat-name { font-size: 10.5px; }
  .seat-team, .seat-count { font-size: 9.5px; }
  .seat-w { left: 5px; }
  .seat-e { right: 5px; }
  .seat-n { top: 6px; }

  .handzone { padding: 8px 8px 12px; }
  .hand-meta { font-size: 11px; margin-bottom: 6px; }
  .hand { padding-top: 14px; min-height: 80px; }

  .eventlog { display: none; }
  .felt::after { inset: 14px 12px; }
}
