/* 3-20 人斗地主 · 样式 */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --felt: #0b5d3b;
  --felt-dark: #07472d;
  --panel: rgba(0, 0, 0, 0.55);
  --panel-border: rgba(255, 255, 255, 0.18);
  --gold: #ffd75e;
  --gold-dark: #c9a227;
  --text: #f2f2f2;
  --text-dim: #b8c4bd;
  --red: #e23b3b;
  --blue: #5aa9ff;
  /* 牌尺寸：由 JS renderMyHand 按视口动态计算并写回 --cw/--ch（含内联宽高），
     默认固定值仅作回退；不用 CSS clamp()（JS parseFloat 解析 clamp 字符串得 NaN，导致计算与渲染漂移）*/
  --cw: 52px;
  --ch: 74px;
}

html, body { height: 100%; }
body {
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(ellipse at 50% 30%, #17805a 0%, var(--felt) 55%, var(--felt-dark) 100%);
  overflow: hidden;
}

.hidden { display: none !important; }

.view { position: fixed; inset: 0; display: flex; flex-direction: column; padding: 14px; gap: 12px; }
.view > header { display: flex; align-items: center; justify-content: space-between; }
.view > header h1 { font-size: 22px; letter-spacing: 1px; text-shadow: 0 2px 4px rgba(0,0,0,.4); }

#conn-status { font-size: 13px; padding: 4px 12px; border-radius: 999px; background: var(--panel); border: 1px solid var(--panel-border); }
#conn-status.ok { color: #7ef0a2; }
#conn-status.bad { color: #ff9a9a; }

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 14px 16px;
  backdrop-filter: blur(4px);
}
.panel h2 { font-size: 16px; margin-bottom: 10px; color: var(--gold); }

/* ---------- 大厅 ---------- */
#view-lobby .lobby-grid { display: grid; grid-template-columns: minmax(280px, 30vw) 1fr; gap: 14px; flex: 1; min-height: 0; }
#view-lobby .rooms-panel { display: flex; flex-direction: column; min-height: 0; }

label { display: block; font-size: 13px; margin-bottom: 8px; color: var(--text-dim); }
label input, label select {
  display: block; width: 100%; margin-top: 3px; padding: 6px 8px;
  border-radius: 8px; border: 1px solid var(--panel-border);
  background: rgba(0,0,0,.4); color: var(--text); font-size: 14px;
}
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

button {
  padding: 8px 16px; border-radius: 10px; border: none; cursor: pointer;
  font-size: 14px; background: linear-gradient(180deg, #ffd75e, #e0a92e); color: #3a2a00; font-weight: 700;
  transition: transform .06s, filter .15s;
}
button:hover { filter: brightness(1.08); }
button:active { transform: translateY(1px); }
button:disabled { filter: grayscale(.7) brightness(.7); cursor: not-allowed; }
button.ghost { background: rgba(255,255,255,.12); color: var(--text); font-weight: 400; }
button.danger { background: linear-gradient(180deg, #ff7a6b, #d8483a); color: #fff; }
button.small { padding: 4px 10px; font-size: 12px; border-radius: 8px; }

#create-form .submit { width: 100%; margin-top: 4px; padding: 10px; font-size: 15px; }
#room-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
#room-table th, #room-table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid rgba(255,255,255,.08); }
#room-table th { color: var(--gold); font-weight: 600; }
#room-table tbody tr:hover { background: rgba(255,255,255,.05); }
#room-table .status-tag, .tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; }
#room-table .status-waiting { background: #1d8a4e; color: #dfffe9; }
#room-table .status-playing { background: #b3591d; color: #ffe9d9; }
.tag.landlord { background: #b3591d; color: #fff; }
.tag.owner { background: var(--gold-dark); color: #3a2a00; }
.tag.off { background: #555; color: #ddd; }
.rooms-scroll { flex: 1; overflow: auto; min-height: 0; }

/* ---------- 房间视图 ---------- */
#view-room .room-grid { display: grid; grid-template-columns: 1fr minmax(260px, 26vw); gap: 14px; flex: 1; min-height: 0; }
#view-room .players-list { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.player-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: rgba(255,255,255,.06); border-radius: 10px; }
.player-row .nick { flex: 1; font-size: 15px; }
.player-row.me { outline: 1px solid var(--gold); }
.start-area { text-align: center; padding: 12px 0; }
.start-area .big { width: 100%; padding: 12px; font-size: 17px; }
.settings-note { font-size: 12px; color: var(--text-dim); margin-top: 8px; line-height: 1.7; }

/* ---------- 对局视图 ---------- */
#view-game { padding: 0; }
#game-topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 30;
  display: flex; align-items: center; gap: clamp(8px, 1.2vmin, 14px); padding: 0.8vmin 1.4vw;
  background: linear-gradient(180deg, rgba(0,0,0,.55), transparent);
  font-size: clamp(11px, 1.6vmin, 15px);
}
#game-topbar .room-name { font-weight: 700; }
#game-topbar .bombs { color: var(--gold); }
#game-table { position: absolute; inset: 0; }
/* 座位：宽度由 JS 按人数与视口动态设置（--seat-w），保证互不重叠 */
.seat { position: absolute; transform: translate(-50%, -50%); width: var(--seat-w, 150px); text-align: center; z-index: 10; }
.seat .chip {
  background: rgba(0,0,0,.55); border: 2px solid transparent; border-radius: 10px;
  padding: 0.6vmin 0.8vw; display: flex; flex-direction: column; gap: 0.4vmin; align-items: center;
  font-size: clamp(10px, 1.5vmin, 14px); transition: border-color .15s;
}
.seat.active .chip { border-color: var(--gold); box-shadow: 0 0 12px rgba(255,215,94,.5); }
.seat .nick { font-weight: 700; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; font-size: 1.15em; }
.seat .count { color: var(--text-dim); font-size: 0.92em; }
.seat .lastplay { min-height: 3.4vmin; display: flex; justify-content: center; align-items: center; gap: 1px; }
.seat .pass-text { color: var(--text-dim); font-size: 0.92em; }
.seat.me-seat .chip { border-color: var(--blue); }

/* 中央区域：永远水平+垂直居中，覆盖在所有图层之上 */
#center-area {
  position: absolute; left: 50%; top: 46%; transform: translate(-50%, -50%);
  text-align: center; z-index: 40; pointer-events: none;
  display: flex; flex-direction: column; align-items: center;
  width: min(72vw, 60vmin); max-width: 620px;
}
#center-area > * { pointer-events: auto; }
#banner { font-size: clamp(14px, 2.4vmin, 23px); font-weight: 800; text-shadow: 0 2px 6px rgba(0,0,0,.6); margin-bottom: 0.8vmin; }
#bottom-cards { display: flex; justify-content: center; gap: 0.5vw; margin-bottom: 1vmin; min-height: 5.5vmin; }
#last-play-center { display: flex; justify-content: center; gap: 0.4vw; min-height: 6vmin; align-items: center; }
#last-play-center .who { color: var(--text-dim); font-size: clamp(10px, 1.4vmin, 13px); margin-right: 0.6vw; }
/* 叫分面板：居中卡片，永不偏离 */
#bid-panel {
  margin-top: 1.4vmin; display: flex; flex-direction: column; gap: 0.8vmin; align-items: center;
  pointer-events: auto;
  background: rgba(0,0,0,.6); border: 1px solid var(--panel-border); border-radius: 14px;
  padding: 1.4vmin 2.4vmin; box-shadow: 0 4px 18px rgba(0,0,0,.45);
}
#bid-hint { font-size: clamp(11px, 1.6vmin, 14px); color: var(--gold); }
#bid-btns { display: flex; gap: clamp(6px, 1.2vmin, 12px); justify-content: center; }
#bid-panel button { font-size: clamp(13px, 1.9vmin, 17px); padding: clamp(7px, 1.2vmin, 12px) clamp(14px, 2.2vmin, 22px); }
#turn-info { margin-top: 1vmin; font-size: clamp(11px, 1.5vmin, 14px); color: var(--text-dim); }

/* 牌 */
.card {
  width: var(--cw); height: var(--ch); border-radius: 6px;
  background: #fff; color: #222; position: relative;
  box-shadow: 0 2px 4px rgba(0,0,0,.4); user-select: none;
  display: inline-flex; flex-direction: column; justify-content: space-between;
  padding: 3px 4px; font-weight: 800; line-height: 1;
}
.card .rank { font-size: calc(var(--cw) * .42); }
.card .suit { font-size: calc(var(--cw) * .34); }
.card .corner { text-align: left; }
.card .center { text-align: center; }
.card.red { color: var(--red); }
.card.black { color: #222; }
.card.joker-red { color: var(--red); background: linear-gradient(160deg,#fff,#ffe3e3); }
.card.joker-black { color: #222; background: linear-gradient(160deg,#fff,#e6e6e6); }
.card.small { --cw: clamp(17px, 2.6vmin, 30px); --ch: clamp(25px, 3.8vmin, 44px); border-radius: 4px; box-shadow: 0 1px 2px rgba(0,0,0,.4); }
.card.tiny { --cw: clamp(13px, 1.9vmin, 22px); --ch: clamp(19px, 2.8vmin, 32px); border-radius: 3px; }

/* 手牌区 */
#my-area {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 25;
  display: flex; flex-direction: column; align-items: center; gap: 0.6vmin;
  padding: 0.8vmin 1vw 1.2vmin;
  background: linear-gradient(0deg, rgba(0,0,0,.6), transparent);
}
#my-hand {
  display: flex; flex-direction: column; align-items: center; gap: 0.6vmin;
  max-width: 100%; width: 100%; padding: 0.8vmin 0.4vw 0; overflow: visible;
}
.hand-row { display: flex; justify-content: center; align-items: flex-end; width: 100%; }
.hand-row .card { cursor: pointer; transition: transform .08s; flex-shrink: 0; touch-action: none; -webkit-user-select: none; user-select: none; }
.hand-row .card:hover { transform: translateY(-0.8vmin); }
.hand-row .card.selected { transform: translateY(-2.2vmin); }
#my-actions { display: flex; gap: clamp(6px, 1.2vmin, 12px); align-items: center; margin-bottom: 0.2vmin; }
#my-actions .action-btn { min-width: clamp(60px, 9vw, 92px); padding: clamp(7px, 1.2vmin, 11px) clamp(10px, 1.6vmin, 18px); font-size: clamp(12px, 1.8vmin, 16px); }
#my-actions .action-btn.primary { background: linear-gradient(180deg, #7ef0a2, #3fbf6d); color: #06301a; }
#my-actions .action-btn.pass-btn { background: linear-gradient(180deg, #ff9a9a, #d8483a); color: #fff; }
#my-actions .action-btn:disabled { filter: grayscale(.8) brightness(.7); }
#hand-count { font-size: clamp(11px, 1.6vmin, 14px); color: var(--text-dim); }

/* 聊天：右上角，宽度按视口百分比，不压手牌 */
#chat {
  position: absolute; right: 1vw; top: 6vmin; z-index: 26; width: min(26vw, 250px);
  background: rgba(0,0,0,.55); border: 1px solid var(--panel-border); border-radius: 10px;
  display: flex; flex-direction: column; max-height: min(36vh, 300px);
}
#chat-head { padding: 0.6vmin 1vw; font-size: clamp(11px, 1.5vmin, 13px); color: var(--gold); border-bottom: 1px solid rgba(255,255,255,.1); cursor: pointer; }
#chat-body { flex: 1; overflow: auto; padding: 0.6vmin 1vw; font-size: clamp(11px, 1.5vmin, 13px); max-height: 60%; }
#chat-body .msg { margin-bottom: 0.4vmin; line-height: 1.4; word-break: break-all; }
#chat-body .who { color: var(--gold); margin-right: 0.4vw; }
#chat-input-row { display: flex; border-top: 1px solid rgba(255,255,255,.1); }
#chat-input { flex: 1; background: transparent; border: none; outline: none; color: var(--text); padding: 0.6vmin 1vw; font-size: clamp(11px, 1.5vmin, 13px); }

/* 结算遮罩 */
#overlay {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.72); backdrop-filter: blur(3px);
}
#overlay .box { background: var(--panel); border: 1px solid var(--panel-border); border-radius: 16px; padding: 2.6vmin 3.4vmin; min-width: min(90vw, 420px); max-width: 94vw; text-align: center; }
#overlay h2 { font-size: clamp(18px, 3vmin, 25px); margin-bottom: 0.4vmin; }
#overlay .sub { color: var(--text-dim); font-size: clamp(11px, 1.6vmin, 14px); margin-bottom: 1.4vmin; }
#overlay table { width: 100%; border-collapse: collapse; margin-bottom: 1.6vmin; font-size: clamp(12px, 1.8vmin, 15px); }
#overlay td, #overlay th { padding: 0.6vmin 0.8vw; border-bottom: 1px solid rgba(255,255,255,.1); }
#overlay .win { color: #7ef0a2; }
#overlay .lose { color: #ff9a9a; }
#overlay .btn-row { display: flex; gap: 1vmin; justify-content: center; }

/* Toast */
#toast {
  position: fixed; top: 18px; left: 50%; transform: translateX(-50%); z-index: 200;
  background: rgba(20,20,20,.92); color: #fff; padding: 10px 20px; border-radius: 10px;
  font-size: 14px; box-shadow: 0 4px 16px rgba(0,0,0,.5); display: none; max-width: 80%;
}
#toast.show { display: block; animation: toast-in .2s; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* 观战 */
.spec-count { color: var(--text-dim); font-size: 11px; margin-left: 4px; }
#btn-leave-spectate { font-size: 12px; padding: 3px 10px; margin-left: 8px; }

/* 响应式：超窄屏微调 */
@media (max-width: 700px) {
  #view-lobby .lobby-grid { grid-template-columns: 1fr; overflow: auto; }
  #view-room .room-grid { grid-template-columns: 1fr; overflow: auto; }
  #chat { display: none; }
  #game-topbar { font-size: 11px; }
}
