/* ==================== 全局样式 ==================== */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg-dark: #1a1a2e;
  --bg-card: #16213e;
  --bg-felt: #0d5e2e;
  --felt-dark: #0a4923;
  --felt-border: #1a7a3a;
  --gold: #d4a843;
  --gold-light: #f0d68a;
  --text: #e0e0e0;
  --text-dim: #888;
  --red: #e74c3c;
  --red-dark: #c0392b;
  --green: #2ecc71;
  --blue: #3498db;
  --orange: #f39c12;
  --white: #fff;
  --radius: 8px;
  --shadow: 0 4px 15px rgba(0,0,0,0.3);
  --font: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg-dark);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

.hidden { display: none !important; }

.screen {
  width: 100%;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ==================== 按钮 ==================== */
.btn {
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.2s;
  font-family: var(--font);
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--blue); color: var(--white); }
.btn-success { background: var(--green); color: var(--white); }
.btn-danger { background: var(--red); color: var(--white); }
.btn-danger-dark { background: #8b0000; color: var(--white); }
.btn-secondary { background: #555; color: var(--white); }
.btn-warning { background: var(--orange); color: var(--white); }
.btn-info { background: #17a2b8; color: var(--white); }
.btn-outline { background: transparent; border: 1px solid #555; color: #aaa; }
.btn-outline:hover { border-color: #888; color: #fff; }
.btn-sm { padding: 5px 12px; font-size: 12px; }

/* ==================== 登录界面 ==================== */
.login-container {
  text-align: center;
  max-width: 420px;
  width: 90%;
}

.logo { margin-bottom: 30px; }
.logo-icon { font-size: 48px; letter-spacing: 8px; color: var(--gold); margin-bottom: 10px; }
.logo h1 { font-size: 36px; color: var(--white); margin-bottom: 5px; }
.subtitle { color: var(--text-dim); font-size: 14px; }

.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-form input {
  padding: 14px 16px;
  border: 2px solid #333;
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--white);
  font-size: 16px;
  text-align: center;
  outline: none;
  transition: border-color 0.2s;
}
.login-form input:focus { border-color: var(--blue); }
.login-form .btn { padding: 14px; font-size: 16px; }

.token-status {
  margin-top: 16px;
  font-size: 12px;
  color: var(--text-dim);
}

/* ==================== 大厅 ==================== */
.lobby-container {
  max-width: 700px;
  width: 90%;
}

.lobby-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 30px;
  padding-bottom: 16px;
  border-bottom: 1px solid #333;
  gap: 20px;
  width: 100%;
}
.lobby-header .logo { display: flex; align-items: center; gap: 16px; }
.lobby-header .logo-icon { font-size: 48px; letter-spacing: 8px; color: var(--gold); }
.lobby-header .logo h1 { font-size: 36px; color: var(--white); margin: 0; }

.nickname-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 400px;
}
.nickname-row label {
  font-size: 15px;
  color: var(--text-dim);
  white-space: nowrap;
}
.nickname-row input {
  padding: 10px 14px;
  border: 2px solid #444;
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--white);
  font-size: 15px;
  flex: 1;
  outline: none;
  transition: border-color 0.2s;
}
.nickname-row input:focus { border-color: var(--blue); }
.btn-sm { padding: 6px 14px; font-size: 13px; }

.lobby-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.action-card {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 24px;
  border: 1px solid #333;
}
.action-card h3 {
  font-size: 18px;
  color: var(--white);
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--blue);
}
.action-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.action-form label {
  font-size: 13px;
  color: var(--text-dim);
}
.action-form select,
.action-form input {
  padding: 10px 12px;
  border: 1px solid #444;
  border-radius: var(--radius);
  background: var(--bg-dark);
  color: var(--white);
  font-size: 14px;
  outline: none;
  font-family: var(--font);
}
.action-form select:focus,
.action-form input:focus { border-color: var(--blue); }

/* ==================== 游戏界面 ==================== */
.game-container {
  width: 100%;
  max-width: 1100px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 10px;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-card);
  border-radius: var(--radius);
  margin-bottom: 8px;
  flex-shrink: 0;
}

.room-info { display: flex; gap: 10px; align-items: center; }
.room-badge {
  background: #333;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 13px;
  color: var(--white);
}
.room-badge strong { color: var(--gold); }
.phase-badge {
  background: var(--blue);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.hand-badge {
  background: #555;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
}

.pot-display {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 20px;
  font-weight: 700;
  color: var(--gold);
}
.pot-icon { font-size: 24px; }

/* ==================== 扑克桌 ==================== */
.poker-table {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.table-felt {
  width: 100%;
  max-width: 800px;
  aspect-ratio: 2 / 1;
  background: radial-gradient(ellipse at center, var(--bg-felt) 0%, var(--felt-dark) 100%);
  border-radius: 200px;
  border: 8px solid #5a3a1a;
  box-shadow: 0 0 40px rgba(0,0,0,0.5), inset 0 0 80px rgba(0,0,0,0.3);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 公共牌 */
.community-cards {
  display: flex;
  gap: 8px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

/* 玩家座位 */
.player-seats {
  position: absolute;
  inset: 0;
}

.player-seat {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transform: translate(-50%, -50%);
}

.player-seat .seat-info {
  font-size: 11px;
  color: #ccc;
  text-align: center;
  white-space: nowrap;
}
.player-seat .seat-nickname {
  font-weight: 600;
  color: var(--white);
  font-size: 12px;
}
.player-seat .seat-chips {
  color: var(--gold);
  font-size: 11px;
}
.player-seat .seat-bet {
  color: var(--orange);
  font-size: 11px;
  font-weight: 600;
}
.player-seat .seat-badge {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: 700;
}
.player-seat .seat-badge.dealer { background: var(--white); color: #000; }
.player-seat .seat-badge.sb { background: var(--blue); color: var(--white); }
.player-seat .seat-badge.bb { background: var(--red); color: var(--white); }
.player-seat .seat-badge.folded { background: #555; color: #999; text-decoration: line-through; }
.player-seat .seat-badge.allin { background: #8b0000; color: #ff6b6b; }
.player-seat .seat-badge.active { background: var(--green); color: var(--white); animation: pulse 1s infinite; }
.player-seat .seat-badge.disconnected { background: #666; color: #999; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.player-seat .seat-cards {
  display: flex;
  gap: 3px;
}
.player-seat .mini-card {
  width: 22px;
  height: 30px;
  background: var(--white);
  border-radius: 3px;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  border: 1px solid #ccc;
  line-height: 1;
}
.mini-card.red { color: var(--red); }
.mini-card.black { color: #000; }
.mini-card.back { background: #1a3a6e; color: #3a6ae0; font-size: 14px; }

/* ==================== 牌面 ==================== */
.card-placeholder {
  width: 80px;
  height: 112px;
  border-radius: 8px;
  border: 2px dashed #3a7a3a;
  background: rgba(0,0,0,0.2);
}

.card {
  width: 80px;
  height: 112px;
  background: var(--white);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  box-shadow: 2px 2px 8px rgba(0,0,0,0.4);
  position: relative;
  border: 1px solid #ddd;
}
.card.red { color: var(--red); }
.card.black { color: #000; }
.card .card-corner-top {
  position: absolute;
  top: 5px;
  left: 7px;
  font-size: 16px;
  line-height: 1.1;
  font-weight: 700;
}
.card .card-corner-bottom {
  position: absolute;
  bottom: 5px;
  right: 7px;
  font-size: 16px;
  line-height: 1.1;
  font-weight: 700;
  transform: rotate(180deg);
}

.card.back {
  background: linear-gradient(135deg, #1a3a6e, #2a5aae);
  color: #4a7ae0;
  font-size: 28px;
}

/* ==================== 底部玩家区 ==================== */
.player-area {
  flex-shrink: 0;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.your-cards {
  display: flex;
  gap: 8px;
}

.your-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.your-name { font-size: 16px; font-weight: 700; color: var(--white); }
.your-chips { font-size: 14px; color: var(--gold); font-weight: 600; }

.action-buttons {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.action-buttons.hidden { display: none; }

.action-buttons .btn { padding: 8px 16px; font-size: 13px; }

.raise-group {
  display: flex;
  align-items: center;
  gap: 6px;
}
.raise-group input[type="range"] {
  width: 80px;
  accent-color: var(--orange);
}

.turn-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-dim);
  font-size: 13px;
}
.turn-indicator.hidden { display: none; }
.turn-indicator.your-turn { color: var(--green); }
.turn-indicator.your-turn .turn-timer {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid var(--green);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  animation: timer-pulse 1s infinite;
}

@keyframes timer-pulse {
  0%, 100% { border-color: var(--green); color: var(--green); }
  50% { border-color: var(--red); color: var(--red); }
}

/* ==================== 弹窗 ==================== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-content {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 24px;
  max-width: 650px;
  width: 95%;
  max-height: 85vh;
  overflow-y: auto;
  border: 1px solid #444;
}
.modal-content h2 {
  text-align: center;
  color: var(--gold);
  margin-bottom: 20px;
  font-size: 22px;
}

/* 摊牌 - 公共牌 */
.sd-community {
  margin-bottom: 16px;
  text-align: center;
}
.sd-section-title {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.sd-community-cards {
  display: flex;
  gap: 8px;
  justify-content: center;
}

/* 摊牌 - 卡牌 */
.showdown-card {
  width: 64px !important;
  height: 90px !important;
  flex-shrink: 0;
}
.showdown-card .card-corner-top {
  font-size: 13px !important;
  top: 4px !important;
  left: 5px !important;
}
.showdown-card .card-corner-bottom {
  font-size: 13px !important;
  bottom: 4px !important;
  right: 5px !important;
}
/* 牌背 */
.showdown-card.card-back {
  background: linear-gradient(135deg, #2c3e50 0%, #1a1a2e 50%, #2c3e50 100%) !important;
  border: 2px solid var(--gold) !important;
  display: flex;
  align-items: center;
  justify-content: center;
}
.card-back-pattern {
  font-size: 14px;
  color: var(--gold);
  opacity: 0.6;
  letter-spacing: 2px;
}

/* 摊牌 - 玩家行 */
.showdown-player {
  padding: 12px 14px;
  margin-bottom: 8px;
  background: var(--bg-dark);
  border-radius: var(--radius);
  border-left: 4px solid #555;
}
.showdown-player.winner {
  border-left-color: var(--green);
  background: linear-gradient(90deg, rgba(46,204,113,0.15) 0%, rgba(46,204,113,0.03) 50%, transparent 100%);
  box-shadow: 0 0 12px rgba(46,204,113,0.2);
}
.showdown-player .sp-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.showdown-player .sp-name { font-weight: 700; color: var(--white); font-size: 16px; }
.showdown-player.winner .sp-name { color: var(--green); }
.showdown-player .sp-hand { color: var(--orange); font-size: 14px; font-weight: 600; }
.showdown-player .sp-win { color: var(--gold); font-weight: 700; font-size: 16px; margin-left: auto; }
.showdown-player .sp-cards { display: flex; gap: 6px; }

/* ==================== 游戏日志 ==================== */
.game-log {
  position: fixed;
  right: 10px;
  bottom: 10px;
  width: 250px;
  background: rgba(0,0,0,0.85);
  border-radius: var(--radius);
  border: 1px solid #333;
  font-size: 12px;
  z-index: 500;
  max-height: 300px;
  overflow: hidden;
}
.log-header {
  padding: 6px 12px;
  background: #333;
  font-weight: 600;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.log-header::after {
  content: '▼';
  font-size: 10px;
  transition: transform 0.2s;
}
.game-log.collapsed .log-header::after {
  transform: rotate(-90deg);
}
.log-content {
  padding: 6px 12px;
  max-height: 260px;
  overflow-y: auto;
  color: #aaa;
  line-height: 1.6;
}
.game-log.collapsed .log-content {
  display: none;
}

/* ==================== 断线重连遮罩 ==================== */
.reconnect-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.75);
  z-index: 10000;
  display: flex; align-items: center; justify-content: center;
}
.reconnect-overlay.hidden { display: none; }
.reconnect-content {
  text-align: center;
  color: var(--white);
}
.reconnect-spinner {
  width: 48px; height: 48px;
  border: 4px solid rgba(255,255,255,0.2);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.reconnect-msg {
  font-size: 16px;
  color: var(--text-dim);
}

/* ==================== Toast ==================== */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  color: var(--white);
  padding: 10px 24px;
  border-radius: 20px;
  font-size: 14px;
  z-index: 2000;
  border: 1px solid #444;
  animation: toast-in 0.3s ease;
}
.toast.error { border-color: var(--red); color: var(--red); }
.toast.success { border-color: var(--green); color: var(--green); }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(-20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ==================== 牌型大小弹窗 ==================== */
.hand-rankings-content {
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
}
.hand-rankings-content h2 {
  text-align: center;
  color: var(--gold);
  margin-bottom: 20px;
  font-size: 20px;
}
.hand-rankings-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.hand-rank-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 14px;
  background: var(--bg-dark);
  border-radius: var(--radius);
  border: 1px solid #333;
  transition: border-color 0.2s;
}
.hand-rank-item:hover {
  border-color: var(--gold);
}
.hand-rank-cards {
  display: flex;
  gap: 3px;
  flex-shrink: 0;
}
.mini-card {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 50px;
  border-radius: 3px;
  background: #fff;
  color: #222;
  font-size: 18px;
  font-weight: 700;
  border: 1px solid #ccc;
}
.mini-card.red { color: #c0392b; }
.hand-rank-info {
  flex: 1;
  min-width: 0;
}
.hand-rank-info strong {
  color: var(--white);
  font-size: 15px;
  display: block;
}
.hand-rank-desc {
  color: var(--text-dim);
  font-size: 12px;
  display: block;
  margin-top: 2px;
}

/* ==================== 响应式 ==================== */
@media (max-width: 768px) {
  .lobby-actions { grid-template-columns: 1fr; }
  .table-felt { border-radius: 100px; border-width: 4px; }
  .card { width: 56px; height: 78px; }
  .card .card-corner-top { font-size: 12px; top: 3px; left: 5px; }
  .card .card-corner-bottom { font-size: 12px; bottom: 3px; right: 5px; }
  .card-placeholder { width: 56px; height: 78px; }
  .community-cards { gap: 4px; }
  .player-area { gap: 10px; padding: 8px; }
  .action-buttons { gap: 4px; }
  .action-buttons .btn { padding: 6px 10px; font-size: 11px; }
  .game-log { right: 4px; bottom: 4px; width: 200px; font-size: 10px; }
}

/* ==================== 手机端适配 ==================== */
@media (max-width: 480px) {
  body { overflow-x: hidden; }

  /* 大厅 */
  .lobby-header .logo h1 { font-size: 26px; }
  .lobby-header .logo-icon { font-size: 36px; letter-spacing: 6px; }
  .lobby-header { margin-bottom: 20px; gap: 16px; }
  .nickname-row { max-width: 100%; }
  .nickname-row input { font-size: 14px; }
  .lobby-actions { gap: 14px; }
  .action-card { padding: 18px; }
  .action-card h3 { font-size: 16px; }

  /* 游戏容器 */
  .game-container { padding: 6px; height: 100vh; height: 100dvh; }

  /* 顶部栏可换行 */
  .game-header { flex-wrap: wrap; gap: 6px; padding: 8px 10px; }
  .room-info { flex-wrap: wrap; gap: 5px; }
  .room-badge { font-size: 11px; padding: 3px 8px; }
  .phase-badge, .hand-badge { font-size: 10px; padding: 3px 8px; }
  .game-actions-header { display: flex; gap: 4px; flex-wrap: wrap; margin-left: auto; }
  .game-actions-header .btn { padding: 4px 8px; font-size: 11px; }
  .pot-display { font-size: 16px; gap: 4px; }
  .pot-icon { font-size: 18px; }
  #copy-room-btn { padding: 3px 6px; font-size: 10px; }

  /* 扑克桌 */
  .table-felt { border-radius: 50%; border-width: 4px; }

  /* 公共牌缩小 */
  .community-cards { gap: 3px; }
  .card { width: 46px; height: 64px; }
  .card .card-corner-top { font-size: 10px; top: 3px; left: 4px; }
  .card .card-corner-bottom { font-size: 10px; bottom: 3px; right: 4px; }
  .card-placeholder { width: 46px; height: 64px; }

  /* 座位元素缩小 */
  .player-seat { gap: 2px; }
  .player-seat .seat-info { font-size: 9px; }
  .player-seat .seat-nickname { font-size: 10px; }
  .player-seat .seat-chips { font-size: 9px; }
  .player-seat .seat-bet { font-size: 9px; }
  .player-seat .seat-badge { font-size: 8px; padding: 0 4px; }
  .player-seat .mini-card { width: 15px; height: 21px; font-size: 8px; }
  .player-seat .seat-cards { gap: 2px; }

  /* 底部操作区纵向布局 */
  .player-area { flex-direction: column; align-items: stretch; gap: 8px; padding: 8px 10px; flex-wrap: nowrap; }
  .your-cards { justify-content: center; }
  .your-info { text-align: center; }
  .your-name { font-size: 14px; }
  .your-chips { font-size: 12px; }
  .action-buttons { justify-content: center; gap: 5px; flex-wrap: wrap; }
  .action-buttons .btn { padding: 8px 10px; font-size: 12px; }
  .raise-group { justify-content: center; flex-wrap: wrap; gap: 5px; }
  .raise-group input[type="range"] { width: 90px; }
  .turn-indicator { justify-content: center; font-size: 12px; }

  /* 摊牌弹窗卡牌缩小 */
  .modal-content { padding: 16px; }
  .modal-content h2 { font-size: 18px; }
  .showdown-card { width: 42px !important; height: 59px !important; }
  .showdown-card .card-corner-top, .showdown-card .card-corner-bottom { font-size: 9px !important; }
  .showdown-player { padding: 10px; }
  .showdown-player .sp-name { font-size: 14px; }
  .showdown-player .sp-hand { font-size: 12px; }
  .showdown-player .sp-win { font-size: 13px; }

  /* 牌型大小弹窗 */
  .hand-rankings-content h2 { font-size: 17px; }
  .hand-rank-item { gap: 10px; padding: 8px 10px; }
  .hand-rank-cards .mini-card { width: 26px; height: 36px; font-size: 13px; }
  .hand-rank-info strong { font-size: 13px; }
  .hand-rank-desc { font-size: 11px; }

  /* 游戏日志更小 */
  .game-log { width: 150px; max-height: 200px; font-size: 10px; }
  .log-content { max-height: 170px; }
}

/* 竖屏手机：椭圆桌面加高，避免座位挤在水平中线上 */
@media (max-width: 480px) and (orientation: portrait) {
  .table-felt { aspect-ratio: 6 / 5; }
}

/* 横屏手机 / 小平板 */
@media (max-width: 850px) and (orientation: landscape) {
  .game-container { height: 100vh; height: 100dvh; }
  .poker-table { min-height: 0; overflow: hidden; }
  /* 桌面按“高度”撑满，宽度由比例推导，避免横屏桌面过高挤掉上下信息 */
  .table-felt {
    width: auto;
    max-width: none;
    align-self: stretch;
    aspect-ratio: 2 / 1;
  }
  .player-area { padding: 4px 10px; gap: 6px; }
  .card { width: 40px; height: 56px; }
  .card .card-corner-top { font-size: 9px; top: 2px; left: 3px; }
  .card .card-corner-bottom { font-size: 9px; bottom: 2px; right: 3px; }
  .card-placeholder { width: 40px; height: 56px; }
  .action-buttons .btn { padding: 5px 9px; font-size: 11px; }
  .game-header { padding: 6px 10px; }
  .your-name { font-size: 13px; }
  .your-chips { font-size: 12px; }
}