/* ============ 牌桌布局 v3：CSS Grid 精确分区，无绝对定位叠加 ============ */

#view-table {
  background: radial-gradient(circle at 50% 38%, #22654a, #0e1f18 72%);
  overflow: hidden;
}

/* 顶栏固定可点 */
#view-table .topbar {
  position: relative;
  z-index: 100;
  flex-shrink: 0;
}

/* 牌桌主体：三行 = 对手区 / 中央区 / 自己区 */
.table-wrap {
  flex: 1;
  min-height: 0;
  display: grid;
  /* 四方牌桌：上＝对家，左＝上家，右＝下家，下＝我 */
  grid-template-areas:
    ".    top    ."
    "left center right"
    ".    self   .";
  grid-template-columns: minmax(0, 0.9fr) minmax(120px, 2fr) minmax(0, 0.9fr);
  grid-template-rows: auto 1fr auto;
  align-items: center;
  justify-items: center;
  padding: 8px 10px;
  gap: 4px;
  position: relative;
  z-index: 1;
}

/* 容器本身不占格子，三个对手直接落进牌桌四边 */
.seats { display: contents; }

.seat.pos-top    { grid-area: top;    justify-self: center; align-self: start; }
.seat.pos-left   { grid-area: left;   justify-self: start;  align-self: center; }
.seat.pos-right  { grid-area: right;  justify-self: end;    align-self: center; }
#self-seat       { grid-area: self;   justify-self: center; align-self: end; }
.table-wrap .center { grid-area: center; align-self: center; justify-self: center; }

/* 等待/选座模式：隐藏座位，选座面板占满 */
.table-wrap.waiting-mode {
  display: flex;
  align-items: center;
  justify-content: center;
}
.table-wrap.waiting-mode .seats { display: none; }
.table-wrap.waiting-mode .self-seat { display: none; }
.table-wrap.waiting-mode .center { width: 100%; }
.seat {
  text-align: center;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.seat .avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #2a4034;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  color: var(--gold);
  border: 2px solid transparent;
  flex-shrink: 0;
}
.seat.active .avatar {
  border-color: var(--gold);
  box-shadow: 0 0 12px rgba(232,184,75,.65);
}
.seat .pname {
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  margin-top: 4px;
}
.seat .pcount {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
  white-space: nowrap;
}
.seat.partner .pname { color: #7fd4a8; }

/* 每位玩家打出的牌，显示在其座位下方 */
.seat-play {
  margin-top: 5px;
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  justify-content: center;
  min-height: 22px;
}
.seat-play .mini {
  width: 20px;
  height: 28px;
  background: #fdfcf8;
  border-radius: 3px;
  color: #1a1a1a;
  font-size: 9px;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.05;
  box-shadow: 0 1px 2px rgba(0,0,0,.4);
}
.seat-play .mini.red { color: #c0392b; }
.seat-play .tag {
  font-size: 10px;
  color: var(--muted);
  padding: 2px 0;
}

/* ── 中央区：最近一手大牌展示 ── */
.center {
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.last-play {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
  align-items: center;
  max-width: 100%;
}
.last-play .label {
  width: 100%;
  text-align: center;
  font-size: 12px;
  color: var(--gold);
  margin-bottom: 4px;
}

/* ── 自己区域：手牌 + 按钮 ── */
.self-area {
  flex-shrink: 0;
  position: relative;
  z-index: 50;
  padding-bottom: 4px;
}
.actions-row {
  display: flex;
  gap: 9px;
  padding: 8px 4px 14px;
  flex-shrink: 0;
}
.actions-row button {
  flex: 1;
  padding: 13px;
  cursor: pointer;
}
.actions-row .primary {
  flex: 2.4;
  padding: 15px 13px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 2px;
}
/* 结束/开始类按钮独占一行 */
.actions-row .primary#btn-start,
.actions-row .primary#btn-next { flex: 1; letter-spacing: 0; }
.actions-row button:disabled { opacity: .4; cursor: default; }

/* ── 等待页选座：按牌桌方位摆放 ── */
.pick-table {
  display: grid;
  grid-template-columns: 1fr 1.15fr 1fr;
  grid-template-rows: auto auto auto;
  gap: 7px;
  width: 100%;
  max-width: 330px;
  margin: 0 auto;
  align-items: center;
}
.pick-table .pos-top    { grid-column: 2; grid-row: 1; }
.pick-table .pos-left   { grid-column: 1; grid-row: 2; }
.pick-table .pos-mid    { grid-column: 2; grid-row: 2; }
.pick-table .pos-right  { grid-column: 3; grid-row: 2; }
.pick-table .pos-bottom { grid-column: 2; grid-row: 3; }

.pick-mid {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: #4e6b5c;
  border: 1px dashed #29402f;
  border-radius: 8px;
  padding: 10px 0;
  user-select: none;
}

.seat-pick {
  background: #17251f;
  border: 1px solid #2a4034;
  border-radius: 10px;
  padding: 9px 6px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.seat-pick .sp-nm {
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.seat-pick .sp-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}
.seat-pick.empty { border-style: dashed; }
.seat-pick.empty .sp-nm { color: var(--muted); }
.seat-pick.mine {
  border-color: var(--gold);
  background: #23331f;
  box-shadow: 0 0 10px rgba(232,184,75,.25);
}
.seat-pick.mine .sp-nm { color: var(--gold); font-weight: 600; }
.seat-pick.partner { border-color: #3d7a5c; }
.seat-pick.partner .sp-nm { color: #7fd4a8; }
.seat-pick.taken { opacity: .72; cursor: default; }

.pick-hint {
  color: #8ba99b;
  font-size: 12.5px;
  margin-top: 10px;
  text-align: center;
  line-height: 1.6;
}

/* 终局结算面板 */
.result-mask {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 24px;
}
.result-card {
  background: #16302a;
  border: 1px solid #2f5548;
  border-radius: 16px;
  padding: 22px 20px;
  width: 100%;
  max-width: 340px;
  text-align: center;
}
.result-card h2 {
  font-size: 20px;
  color: var(--gold);
  margin-bottom: 4px;
}
.result-card .rsub {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 16px;
}
.result-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: #1c3a32;
  border-radius: 9px;
  margin-bottom: 7px;
  font-size: 14px;
}
.result-row.win { background: #1f4630; border: 1px solid #3d7a5c; }
.result-row .rk {
  width: 22px;
  font-weight: 700;
  color: var(--muted);
}
.result-row.win .rk { color: var(--gold); }
.result-row .rn { flex: 1; text-align: left; }
.result-row .rt { font-size: 12px; color: var(--muted); }
.result-close {
  margin-top: 14px;
  width: 100%;
  padding: 12px;
  background: var(--green);
  color: #fff;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
}

@media (max-height: 700px) {
  .seat .avatar { width: 34px; height: 34px; font-size: 13px; }
  .seat-play .mini { width: 17px; height: 24px; font-size: 8px; }
}

/* 手牌：牌面按屏宽自适应，保证 27 张在 3 行内放完，绝不裁切 */
.myhand {
  --cw: clamp(26px, calc((100vw - 44px) / 9.4), 38px);
  max-height: none;
  overflow: visible;
}
.myhand .card {
  width: var(--cw);
  height: calc(var(--cw) * 1.42);
  font-size: calc(var(--cw) * 0.34);
}
.myhand .card .suit { font-size: calc(var(--cw) * 0.39); }
.myhand .card.joker { font-size: calc(var(--cw) * 0.27); }

/* 结算面板：队伍级数与下一局 */
.result-teams {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin: 12px 0 4px;
  font-size: 12.5px;
  color: var(--muted);
  flex-wrap: wrap;
}
.result-teams span {
  background: #1c3a32;
  border-radius: 6px;
  padding: 4px 9px;
}
.result-teams .tw {
  background: #1f4630;
  color: var(--gold);
  border: 1px solid #3d7a5c;
}
.result-teams .rmy { background: transparent; color: #7fd4a8; }
.result-next {
  margin-top: 14px;
  width: 100%;
  padding: 13px;
  background: var(--green);
  color: #fff;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.result-next:disabled { opacity: .55; }
.ghost-link {
  margin-top: 9px;
  width: 100%;
  padding: 10px;
  background: transparent;
  color: var(--muted);
  border: 1px solid #2f5548;
  border-radius: 10px;
  font-size: 13.5px;
  cursor: pointer;
}

/* 已出完牌：名次标识 */
.seat.done .avatar {
  background: #23331f;
  border-color: #4a6b55;
  color: var(--gold);
  position: relative;
}
.seat.done .pname { color: #9fb5a8; }

/* 头像右上角的名次序号 */
.rank-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--gold);
  color: #14301f;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(0,0,0,.5);
}

/* 名次文字标签 */
.rank-tag {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .5px;
}
.rank-tag.r1 { background: var(--gold); color: #14301f; }
.rank-tag.r2 { background: #7fd4a8; color: #14301f; }
.rank-tag.r3 { background: #5b8a76; color: #eef7f1; }
.rank-tag.r4 { background: #3a4f45; color: #9fb5a8; }

/* 自己的座位条：底部手牌上方 */
.self-seat {
  padding: 0;
  flex-shrink: 0;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
/* 我这一手打出的牌 */
.self-play {
  display: flex;
  gap: 3px;
  justify-content: center;
  align-items: center;
}
.self-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0,0,0,.22);
  border: 1px solid #2a4034;
  border-radius: 9px;
  padding: 5px 10px;
  font-size: 12.5px;
}
.self-chip.active {
  border-color: var(--gold);
  box-shadow: 0 0 10px rgba(232,184,75,.3);
}
.self-chip.done { background: rgba(35,51,31,.9); border-color: #4a6b55; }
.self-avatar {
  width: 24px; height: 24px; border-radius: 50%;
  background: #2a4034; color: var(--gold);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; flex-shrink: 0;
}
.self-chip.done .self-avatar { background: #23331f; }
.self-name { color: var(--gold); font-weight: 600; white-space: nowrap; }
.self-status { color: var(--muted); margin-left: auto; white-space: nowrap; }
.turn-tag { color: var(--gold); font-weight: 600; }

/* 终局摊牌：各家剩余手牌，列在自己面前 */
.seat-play.reveal {
  flex-wrap: wrap;
  gap: 2px;
  max-width: 96px;
  justify-content: center;
}
.seat-play.reveal .mini {
  width: 15px;
  height: 21px;
  font-size: 7px;
  border-radius: 2px;
}
/* 左右两家列窄，进一步收小 */
.seat.pos-left .seat-play.reveal,
.seat.pos-right .seat-play.reveal { max-width: 62px; }

/* ── 封盘遮罩 ── */
.paused-mask {
  position: absolute; inset: 0; z-index: 40;
  display: flex; align-items: center; justify-content: center;
  background: rgba(10, 22, 17, .82);
  backdrop-filter: blur(2px);
}
.paused-box {
  text-align: center; padding: 22px 26px;
  background: #16241d; border: 1px solid var(--gold);
  border-radius: 14px; max-width: 78%;
}
.paused-title {
  font-size: 20px; font-weight: 700; color: var(--gold);
  letter-spacing: 2px; margin-bottom: 8px;
}
.paused-sub {
  font-size: 12.5px; color: #9fb5a8; line-height: 1.7;
  margin-bottom: 16px;
}
.paused-box .primary {
  width: 100%; padding: 11px 22px; font-size: 15px;
}
