:root {
  color-scheme: dark;
  --bg: #0b1015;
  --panel: #151c25;
  --felt: radial-gradient(ellipse at center, #1a6b4a 0%, #0e4a33 70%, #072414 100%);
  --line: rgba(255,255,255,0.08);
  --text: #e8ecf3;
  --muted: #8b93a7;
  --gold: #f4c36d;
  --red: #ef4444;
  --blue: #60a5fa;
  --green: #34d399;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
button { font-family: inherit; }
input { font-family: inherit; }

.screen { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
#table.screen { height: 100vh; height: 100dvh; min-height: 0; overflow: hidden; }
.hidden { display: none !important; }

/* ============ 大厅 ============ */
#lobby { align-items: center; justify-content: center; padding: 20px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 28px; width: 100%; max-width: 460px;
  box-shadow: 0 20px 60px -20px rgba(0,0,0,0.6);
}
.card h1 { margin: 0 0 4px; font-size: 28px; }
.card .sub { color: var(--muted); font-size: 13px; margin: 0 0 20px; }
.card label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 6px; }
.card input {
  width: 100%; padding: 10px 12px; font-size: 14px;
  background: #0e141c; color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  outline: none;
}
.card input:focus { border-color: var(--blue); }
.card .row { display: flex; gap: 8px; margin-top: 16px; }
.card .row input { flex: 1; }
.card button, .primary {
  appearance: none; border: 0; cursor: pointer;
  padding: 10px 18px; border-radius: 10px; font-weight: 600; font-size: 14px;
  background: linear-gradient(135deg, #60a5fa, #a78bfa); color: #0b0f1a;
}
.card button.ghost {
  background: rgba(255,255,255,0.06); color: var(--text);
}
.card .hint { color: var(--muted); font-size: 11px; text-align: center; margin-top: 16px; }

.rooms { margin-top: 20px; display: flex; flex-direction: column; gap: 8px; max-height: 280px; overflow-y: auto; }
.room-row {
  display: flex; justify-content: space-between; align-items: center;
  background: #0e141c; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 14px; font-size: 13px; cursor: pointer; transition: background 0.15s;
}
.room-row:hover { background: #121a24; }
.room-row .rname { font-weight: 600; }
.room-row .rmeta { color: var(--muted); font-size: 12px; }

/* ============ 牌桌 ============ */
#table { background: #0a0e13; }

.topbar {
  padding: 10px 16px; display: flex; align-items: center; justify-content: space-between;
  background: rgba(0,0,0,0.4); border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.room-info { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.stage-badge {
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: rgba(96,165,250,0.15); color: var(--blue); font-weight: 500;
}
.pot-info { color: var(--gold); font-variant-numeric: tabular-nums; }
.pot-info b { font-size: 16px; margin-left: 4px; }
.topbar button.ghost {
  appearance: none; border: 0; padding: 6px 12px; border-radius: 8px;
  background: rgba(255,255,255,0.06); color: var(--text); cursor: pointer; font-size: 12px;
}

.felt {
  --rx: 42;
  --ry: 36;
  --seat-w: 120px;
  flex: 1;
  background: var(--felt);
  position: relative;
  min-height: 320px;
  padding: 20px;
  overflow: hidden;
}

.community {
  position: absolute; top: 42%; left: 50%; transform: translate(-50%, -50%);
  display: flex; gap: 6px; z-index: 1;
}

.card-face {
  width: 44px; height: 60px; border-radius: 6px;
  background: #fff; color: #111; display: flex; flex-direction: column; align-items: center;
  justify-content: center; font-weight: 700;
  box-shadow: 0 4px 10px rgba(0,0,0,0.4);
  font-size: 20px;
  font-family: Georgia, "Times New Roman", serif;
}
.card-face.red { color: #dc2626; }
.card-face.back {
  background: repeating-linear-gradient(45deg, #1e3a8a, #1e3a8a 4px, #1e40af 4px, #1e40af 8px);
  color: transparent; border: 2px solid rgba(255,255,255,0.2);
}
.card-face .suit { font-size: 18px; line-height: 1; margin-top: 2px; }

.seats { position: absolute; inset: 0; z-index: 2; }
.seat {
  position: absolute;
  width: var(--seat-w, 120px);
  padding: 8px 10px;
  background: rgba(0,0,0,0.55); border: 1px solid var(--line); border-radius: 12px;
  text-align: center; font-size: 12px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.seat.empty { opacity: 0.25; }
.seat.folded { opacity: 0.5; }
.seat.to-act { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(244,195,109,0.35); }
.seat.dealer::after {
  content: "D"; position: absolute; top: -8px; right: -8px;
  width: 22px; height: 22px; border-radius: 50%;
  background: #fff; color: #111; font-weight: 700; font-size: 12px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 4px rgba(0,0,0,0.4);
}
.seat.me { border-color: var(--blue); }
.seat .pname { font-weight: 700; }
.seat .pchips { color: var(--gold); font-variant-numeric: tabular-nums; }
.seat .pbet {
  margin-top: 4px; font-size: 11px; color: var(--text);
  background: rgba(244,195,109,0.15); padding: 2px 6px; border-radius: 999px;
  display: inline-block;
}
.seat .phole { display: flex; gap: 3px; justify-content: center; margin-top: 4px; }
.seat .phole .card-face { width: 28px; height: 38px; font-size: 14px; }
.seat .phole .card-face .suit { font-size: 12px; }
.seat .tag {
  display: inline-block; font-size: 10px; padding: 1px 6px; border-radius: 999px;
  background: rgba(239,68,68,0.18); color: #fca5a5; margin-top: 2px;
}
.seat .tag.allin { background: rgba(244,195,109,0.2); color: var(--gold); }
.seat .tag.off { background: rgba(255,255,255,0.06); color: var(--muted); }

/* 历史记录 */
.history {
  background: rgba(0,0,0,0.4); border-top: 1px solid var(--line);
  max-height: 100px; overflow-y: auto;
  padding: 6px 16px; font-size: 12px; color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.history .line { padding: 1px 0; }

/* 动作按钮 */
.actions {
  display: flex; gap: 8px; padding: 12px 16px;
  background: var(--panel); border-top: 1px solid var(--line);
  flex-wrap: wrap; align-items: center;
}
.act {
  appearance: none; border: 0; cursor: pointer;
  padding: 10px 14px; border-radius: 10px; font-weight: 600; font-size: 14px;
  min-width: 72px;
  transition: transform 0.08s, opacity 0.15s;
}
.act:active { transform: scale(0.96); }
.act:disabled { opacity: 0.3; cursor: not-allowed; }
.act-fold { background: #4b5563; color: #fff; }
.act-check, .act-call { background: #2563eb; color: #fff; }
.act-raise { background: var(--gold); color: #111; }
.act-allin { background: #ef4444; color: #fff; }
.raise-group { display: flex; gap: 6px; align-items: center; flex: 1; min-width: 160px; }
.raise-group input {
  flex: 1; padding: 9px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: #0e141c; color: var(--text); outline: none; font-size: 14px;
  min-width: 80px;
}
.raise-group input:focus { border-color: var(--gold); }

.start-row {
  display: flex; justify-content: center; align-items: center; gap: 12px;
  padding: 8px 16px; background: var(--panel);
  border-top: 1px solid var(--line);
  min-height: 36px;
}
.start-row .primary {
  padding: 8px 22px; border-radius: 999px; cursor: pointer;
}
.msg { color: var(--muted); font-size: 12px; }

/* 胜者面板 */
.winners {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 24px 28px; max-width: 90vw; min-width: 300px; z-index: 10;
  box-shadow: 0 20px 60px -10px rgba(0,0,0,0.8);
  animation: pop 0.2s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translate(-50%, -45%) scale(0.95); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }
.winners h3 { margin: 0 0 12px; text-align: center; color: var(--gold); }
.winners .wrow {
  display: flex; justify-content: space-between; gap: 16px; align-items: center;
  padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px;
}
.winners .wrow:last-child { border-bottom: 0; }
.winners .wname { font-weight: 600; }
.winners .whand { color: var(--muted); font-size: 12px; }
.winners .wwin { color: var(--gold); font-variant-numeric: tabular-nums; font-weight: 700; }
.winners .wwin.zero { color: var(--muted); font-weight: 400; }
.winners .wcards { display: flex; gap: 4px; margin-top: 4px; align-items: center; font-size: 11px; color: var(--muted); }
.winners .wcards .card-face { width: 26px; height: 36px; font-size: 13px; }
.winners .wcards .card-face .suit { font-size: 11px; }

/* ============ 移动端 ============ */
@media (max-width: 640px) {
  #lobby { padding: 12px; }
  .card { padding: 20px 18px; border-radius: 14px; }
  .card h1 { font-size: 22px; }
  .rooms { max-height: 220px; }

  .topbar { padding: 8px 12px; font-size: 12px; gap: 6px; }
  .topbar .room-info { gap: 6px; min-width: 0; flex-wrap: wrap; }
  .topbar .room-info > span:first-child { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .stage-badge { font-size: 10px; padding: 1px 6px; }
  .pot-info { font-size: 12px; }
  .pot-info b { font-size: 14px; }
  .topbar button.ghost { padding: 5px 10px; font-size: 11px; }

  .felt {
    --rx: 37; --ry: 30; --seat-w: 90px;
    padding: 8px;
    min-height: 0;
  }
  .seat { font-size: 10px; padding: 5px 6px; border-radius: 9px; }
  .seat .pname { font-size: 11px; }
  .seat .pchips { font-size: 11px; }
  .seat .pbet { font-size: 10px; padding: 1px 5px; }
  .seat .phole { gap: 2px; margin-top: 3px; }
  .seat .phole .card-face { width: 24px; height: 32px; font-size: 12px; border-radius: 4px; }
  .seat .phole .card-face .suit { font-size: 10px; }
  .seat .tag { font-size: 9px; padding: 1px 5px; }
  .seat.dealer::after { width: 18px; height: 18px; font-size: 10px; top: -6px; right: -6px; }

  .community { gap: 4px; }
  .card-face { width: 32px; height: 46px; font-size: 15px; border-radius: 5px; }
  .card-face .suit { font-size: 12px; }

  /* 自己的手牌稍微大一点，方便看清 */
  .seat.me .phole .card-face { width: 30px; height: 42px; font-size: 15px; }
  .seat.me .phole .card-face .suit { font-size: 13px; }

  .history { max-height: 52px; padding: 4px 10px; font-size: 11px; }

  .actions {
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    gap: 6px;
  }
  .act {
    min-width: 0;
    flex: 1 1 0;
    padding: 10px 4px;
    font-size: 13px;
    border-radius: 8px;
  }
  .raise-group {
    flex: 1 1 100%;
    order: 10;
    min-width: 0;
  }
  .raise-group input { padding: 9px 8px; font-size: 14px; }
  .raise-group .act { flex: 0 0 auto; min-width: 72px; }

  .start-row { padding: 6px 12px; }
  .start-row .primary { padding: 7px 16px; font-size: 13px; }

  .winners { padding: 18px 20px; min-width: 260px; max-height: 80vh; overflow-y: auto; }
  .winners h3 { font-size: 15px; }
  .winners .wrow { font-size: 12px; gap: 10px; }
  .winners .wcards .card-face { width: 22px; height: 30px; font-size: 11px; }
  .winners .wcards .card-face .suit { font-size: 9px; }
}

/* 很窄的屏（iPhone SE / 小屏 Android） */
@media (max-width: 380px) {
  .felt { --rx: 36; --ry: 28; --seat-w: 78px; }
  .seat { padding: 4px 5px; }
  .card-face { width: 28px; height: 40px; font-size: 13px; }
  .card-face .suit { font-size: 11px; }
  .act { font-size: 12px; padding: 9px 2px; }
}

/* 横屏手机：桌面更扁，收窄椭圆 */
@media (max-height: 480px) and (orientation: landscape) {
  .felt { --rx: 38; --ry: 28; --seat-w: 100px; padding: 6px; }
  .history { max-height: 36px; }
  .topbar { padding: 6px 12px; }
  .actions { padding: 6px 10px; }
}
