/* 掼蛋游戏样式 */

.guandan-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10000;
  animation: fadeIn 0.3s;
}

.guandan-modal-content {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 30px;
  border-radius: 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  text-align: center;
  max-width: 400px;
  color: white;
}

.guandan-modal-content h2 {
  margin: 0 0 15px 0;
  font-size: 28px;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.guandan-modal-content p {
  margin: 10px 0;
  font-size: 16px;
}

.guandan-hint {
  font-size: 14px;
  opacity: 0.9;
  line-height: 1.6;
  margin-top: 15px !important;
}

.guandan-buttons {
  margin-top: 25px;
  display: flex;
  gap: 15px;
  justify-content: center;
}

.guandan-btn {
  padding: 12px 30px;
  font-size: 16px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-weight: bold;
  transition: all 0.3s;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
}

.guandan-btn-confirm {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  color: white;
}

.guandan-btn-confirm:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
}

.guandan-btn-cancel {
  background: #6c757d;
  color: white;
}

.guandan-btn-cancel:hover {
  background: #5a6268;
  transform: translateY(-2px);
}

/* 掼蛋游戏主界面：仿主流掼蛋 H5 的"墨绿赌桌"风格 */
.guandan-game-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(ellipse at center, #1e6b3a 0%, #0e3d20 60%, #062012 100%);
  z-index: 9999;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', sans-serif;
}

/* （顶部标题栏的样式合并到下方原 .guandan-header 规则中） */

/* ===== 横屏 / 全屏模式（掼蛋专用） =====
   核心需求：进入掼蛋后画面始终以"横屏视觉"呈现，按 16:9 比例铺满屏幕。
   关键策略：旋转是"按需"的——目的是让视觉上始终是横屏：
     A) 手机已是物理横屏（viewport 宽>高）→ 不需要旋转，直接铺满 ✓
        否则会把已经横屏的内容再 rotate(90deg) 转成竖屏视觉（用户看到的
        牌全部缩在屏幕一侧，文字侧躺），就是这次截图反馈的 Bug。
     B) 手机是物理竖屏（viewport 高>宽）→ 用 CSS rotate(90deg) 把容器
        转 90° 让视觉变成横屏；前提是已经清掉 body.rotate-cw90，
        避免两层 rotate 叠加。
   用户体验：用户进入掼蛋后只需要把手机倒成横屏即可（或者本来就横屏），
            画面始终是"正向"的 16:9 横屏，不会出现错向。
*/

body.guandan-landscape {
  overflow: hidden;
  position: fixed;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  margin: 0;
  padding: 0;
  background:
    radial-gradient(ellipse at center, #1e6b3a 0%, #0e3d20 60%, #062012 100%);
}

body.guandan-landscape #game-wrap,
body.guandan-landscape #game,
body.guandan-landscape #overlay,
body.guandan-landscape #hud,
body.guandan-landscape #controls,
body.guandan-landscape .auto-toggle,
body.guandan-landscape .orientation-toggle {
  display: none !important;
}

/* 通用：容器始终是 16:9 居中铺满；旋转角度由下面的 @media 按方向决定。
   旋转前容器宽高的语义：
     - 不旋转时：width 即视觉宽，height 即视觉高 → 16:9 横向；
     - 旋转 90° 时：width 对应视觉的"高"，height 对应视觉的"宽" → 仍然是 16:9。
   因此宽高公式对两种情况都成立：
     width  = min(100vw, 100vh*16/9)  在横屏下 → 视觉的横向 16
     height = min(100vh, 100vw*9/16)  在横屏下 → 视觉的纵向 9 */
body.guandan-landscape .guandan-game-container,
body.guandan-landscape #gd-wild-picker {
  position: fixed;
  top: 50%;
  left: 50%;
  /* 显式清掉基类可能写过的 right/bottom（例如 .gd-wild-picker 的 inset:0），
     避免与下面的 width/height + transform 冲突。 */
  right: auto;
  bottom: auto;
}

/* —— A) 手机本来就是横屏：直接铺满，禁止再旋转 —— */
@media screen and (orientation: landscape) {
  body.guandan-landscape .guandan-game-container,
  body.guandan-landscape #gd-wild-picker {
    width: 100vw;
    height: 100vh;
    transform: translate(-50%, -50%);
    transform-origin: center center;
  }
}

/* —— B) 手机是竖屏：用 CSS 旋转 90° 让视觉横屏 —— */
@media screen and (orientation: portrait) {
  body.guandan-landscape .guandan-game-container,
  body.guandan-landscape #gd-wild-picker {
    width: 100vh;
    height: 100vw;
    transform: translate(-50%, -50%) rotate(90deg);
    transform-origin: center center;
  }
}

/* ===== 横屏（掼蛋）16:9 紧凑布局 =====
   背景：原始 .guandan-table { min-height: 200px } + .player-hand { min-height: 110px }
   是按"竖屏/平板高度"设计的。16:9 横屏下容器高度被限制为 ~min(100vh, 100vw*9/16)，
   往往只有 360~500px。原始尺寸会让 header+对家+桌面 三块就把空间撑满，
   bottom 的玩家手牌/出牌按钮被 overflow:hidden 裁掉 → 看不到手牌也无法出牌。
   这里专门为 body.guandan-landscape 收缩各区高度和间距，确保 27 张手牌、
   出牌/不要按钮都能在 16:9 容器内可见可点。 */

body.guandan-landscape .guandan-game-board {
  padding: 6px 10px;
  position: relative;
}

body.guandan-landscape .guandan-header {
  position: absolute;
  top: 6px;
  left: 10px;
  right: 10px;
  z-index: 20;
  padding: 0;
  margin: 0;
  background: none;
  border: 0;
  pointer-events: none;
}
body.guandan-landscape .guandan-header h2 {
  position: absolute;
  top: 0;
  left: 4px;
  font-size: 15px;
  letter-spacing: 0.3px;
  padding: 3px 8px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.28);
}
body.guandan-landscape .team-score {
  position: absolute;
  top: 24px;
  left: 4px;
  font-size: 10px;
  padding: 3px 8px;
  background: rgba(0, 0, 0, 0.28);
}
body.guandan-landscape .guandan-quit {
  position: absolute;
  top: 0;
  right: 4px;
  padding: 5px 14px;
  font-size: 12px;
  pointer-events: auto;
}

body.guandan-landscape .guandan-players {
  /* 用三段定额：上对家自动 / 中区拉伸 / 下玩家固定下限 = 留出底部出牌区 */
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 0;
}
body.guandan-landscape .guandan-player { gap: 3px; }
body.guandan-landscape .player-name { font-size: 12px; padding: 2px 10px; }
body.guandan-landscape .card-count { font-size: 11px; padding: 3px 10px; }
body.guandan-landscape .player-cards-back { gap: 3px; }

body.guandan-landscape .guandan-middle-row {
  flex: 1 1 auto;
  min-height: 0;
  padding: 2px 0;
  /* 让桌面拉伸到 row 高度，避免桌面只占自己 min-height 而留白 */
  align-items: stretch;
}
body.guandan-landscape .guandan-player-left,
body.guandan-landscape .guandan-player-right {
  width: 110px;
  /* 左右对手保持竖向居中即可，不需要拉伸 */
  align-self: center;
}
body.guandan-landscape .guandan-table {
  min-height: 52px;
  max-height: 124px;
  padding: 6px 14px;
  margin: 0 8px;
  border-radius: 18px;
  overflow: hidden;
}
body.guandan-landscape .last-play {
  min-height: 32px;
  max-height: 78px;
  margin-bottom: 2px;
  overflow: hidden;
}
body.guandan-landscape .last-play-cards { gap: 4px; }
body.guandan-landscape .last-play-meta { font-size: 12px; }
body.guandan-landscape .empty-table { font-size: 12px; }
body.guandan-landscape .game-info { font-size: 12px; margin-top: 2px; }

/* —— 关键：玩家底部区域保证可见 —— */
body.guandan-landscape .guandan-player-bottom {
  /* 用 flex-shrink:0 + min-height 防止被 middle-row 挤掉 */
  flex-shrink: 0;
  gap: 2px;
}
body.guandan-landscape .player-hand {
  min-height: 138px;
  padding: 4px 10px 6px;
  margin: 0 auto 4px;
  /* 横屏下手牌只占容器中段宽度，给左右留白避免 27 张牌被 max-width 卡死 */
  max-width: 92%;
}
body.guandan-landscape .card { width: 38px; height: 58px; }
body.guandan-landscape .player-hand .hand-card-group { width: 38px; }
body.guandan-landscape .player-hand .hand-card-group .card + .card { margin-top: -34px; }
body.guandan-landscape .player-hand .card .card-content { padding: 4px 0 0 4px; }
body.guandan-landscape .card-rank { font-size: 14px; }
body.guandan-landscape .card-suit { font-size: 11px; margin-top: 0; }
body.guandan-landscape .card.selected { transform: translateY(-14px); }
body.guandan-landscape .player-hand .card:hover { transform: translateY(-7px); }

body.guandan-landscape .player-actions { padding: 0 2px 2px; gap: 10px; }
body.guandan-landscape .action-btn { padding: 6px 18px; font-size: 13px; }
body.guandan-landscape .player-msg { font-size: 11px; margin-left: 8px; }

.guandan-game-board {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 10px;
  box-sizing: border-box;
}

.guandan-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  background: linear-gradient(180deg, rgba(0,0,0,.45) 0%, rgba(0,0,0,.15) 100%);
  border-bottom: 1px solid rgba(255, 215, 0, 0.3);
  border-radius: 10px;
  margin-bottom: 10px;
}

.guandan-header h2 {
  color: #ffd700;
  margin: 0;
  font-size: 22px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  letter-spacing: 0.5px;
}

.guandan-quit {
  background: #dc3545;
  color: white;
  border: none;
  padding: 8px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: bold;
}

.guandan-quit:hover {
  background: #c82333;
}

.guandan-players {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.guandan-player {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.player-name {
  color: white;
  font-weight: bold;
  font-size: 16px;
  background: rgba(0, 0, 0, 0.4);
  padding: 5px 15px;
  border-radius: 20px;
}

.player-cards-back {
  display: flex;
  gap: 5px;
}

.card-count {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  padding: 8px 15px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: bold;
}

.guandan-middle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex: 1;
  padding: 20px 0;
}

.guandan-player-left,
.guandan-player-right {
  width: 150px;
}

.guandan-table {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at center, #1a7a40 0%, #0a3a1c 100%);
  border: 3px solid rgba(255, 215, 0, 0.55);
  box-shadow:
    0 0 0 2px rgba(0,0,0,0.3) inset,
    0 0 30px rgba(255, 215, 0, 0.18),
    0 8px 24px rgba(0,0,0,0.55);
  border-radius: 28px;
  padding: 20px;
  margin: 0 20px;
  min-height: 200px;
  position: relative;
}

.table-cards {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 15px;
}

.game-info {
  color: white;
  font-size: 18px;
  font-weight: bold;
  text-align: center;
  margin-top: 10px;
}

.player-hand {
  display: flex;
  gap: 10px;
  flex-wrap: nowrap;
  justify-content: flex-start;
  align-items: flex-end;
  padding: 12px 15px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 15px;
  max-width: 96%;
  margin: 0 auto 12px;
  min-height: 190px;
  overflow-x: auto;
  overflow-y: visible;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,215,0,.6) rgba(0,0,0,.2);
}

.player-hand::-webkit-scrollbar {
  height: 6px;
}
.player-hand::-webkit-scrollbar-thumb {
  background: rgba(255, 215, 0, .55);
  border-radius: 3px;
}

.player-hand.disabled {
  filter: grayscale(80%) brightness(0.65);
  pointer-events: none;
  cursor: not-allowed;
}

/* 自动理牌：外层横向排点数组，组内牌上下叠放，参考移动端掼蛋手牌布局。 */
.player-hand .hand-card-group {
  width: 60px;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  position: relative;
}

.player-hand .hand-card-group .card {
  flex: 0 0 auto;
  z-index: 1;
}

.player-hand .hand-card-group .card + .card {
  margin-top: -62px;
}

/* 竖向叠牌时只露牌头，因此玩家手牌的点数/花色必须放在左上角。 */
.player-hand .card .card-content {
  align-items: flex-start;
  justify-content: flex-start;
  box-sizing: border-box;
  padding: 6px 0 0 6px;
}

.player-hand .card-rank {
  font-size: 18px;
  line-height: 1;
}

.player-hand .card-suit {
  font-size: 14px;
  line-height: 1;
  margin-top: 1px;
}

.player-hand .hand-card-group[data-group-size="2"] .card {
  box-shadow: 0 4px 8px rgba(0,0,0,0.2), inset 0 -3px 0 rgba(255,193,7,0.55);
}
.player-hand .hand-card-group[data-group-size="3"] .card {
  box-shadow: 0 4px 8px rgba(0,0,0,0.2), inset 0 -3px 0 rgba(255,140,0,0.75);
}
.player-hand .hand-card-group[data-group-size="4"] .card,
.player-hand .hand-card-group[data-group-size="5"] .card,
.player-hand .hand-card-group[data-group-size="6"] .card,
.player-hand .hand-card-group[data-group-size="7"] .card,
.player-hand .hand-card-group[data-group-size="8"] .card {
  box-shadow: 0 4px 8px rgba(0,0,0,0.2), inset 0 -3px 0 rgba(220,53,69,0.85);
}
.player-hand .card:hover {
  transform: translateY(-10px);
  z-index: 10;
}
.player-hand .card.selected {
  z-index: 20;
}

.card {
  width: 60px;
  height: 90px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.card:hover {
  transform: translateY(-10px);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
}

.card.selected {
  transform: translateY(-20px);
  box-shadow: 0 12px 24px rgba(255, 215, 0, 0.5);
  border: 3px solid #FFD700;
}

.card-small {
  width: 50px;
  height: 75px;
  cursor: default;
}

.card-small:hover {
  transform: none;
}

.card-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: bold;
}

.card-rank {
  font-size: 24px;
  line-height: 1;
}

.card-suit {
  font-size: 20px;
  line-height: 1;
  margin-top: 5px;
}

.card-small .card-rank {
  font-size: 18px;
}

.card-small .card-suit {
  font-size: 16px;
}

.player-actions {
  display: flex;
  gap: 15px;
  justify-content: center;
  padding: 10px;
}

.action-btn {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  padding: 12px 30px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 16px;
  font-weight: bold;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  transition: all 0.3s;
}

.action-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
}

.action-btn:active {
  transform: translateY(0);
}

/* 结算界面 */
.guandan-result {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: white;
  text-align: center;
}

.guandan-result h1 {
  font-size: 48px;
  margin: 0 0 30px 0;
  text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.5);
}

.result-score {
  font-size: 36px;
  font-weight: bold;
  margin: 20px 0;
  color: #FFD700;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.result-detail {
  font-size: 24px;
  margin: 15px 0 30px 0;
  opacity: 0.9;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* ===== v2 新增 ===== */

/* 表格分 */
.team-score {
  color: #ffd700;
  font-weight: bold;
  font-size: 14px;
  background: rgba(0, 0, 0, 0.4);
  padding: 6px 14px;
  border-radius: 16px;
}

/* 桌面：上一手 */
.last-play {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  min-height: 100px;
  justify-content: center;
}

.empty-table {
  color: rgba(255, 255, 255, 0.6);
  font-size: 14px;
  font-style: italic;
}

.last-play-meta {
  color: #ffd700;
  font-size: 13px;
  font-weight: bold;
}

.last-play-cards {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}

/* 当前轮次高亮 */
.card-count.active {
  background: linear-gradient(135deg, #ffb347 0%, #ffcc33 100%);
  color: #222;
  box-shadow: 0 0 12px rgba(255, 215, 0, 0.7);
}

/* 红心级牌（潜在癞子）轻微高亮 */
.card.wild {
  background: linear-gradient(180deg, #fff 0%, #ffe9e9 100%);
  border: 2px solid #ff6b6b;
}

/* 级牌右上角小星 */
.lv-mark {
  font-size: 9px;
  color: #ffb700;
  vertical-align: super;
}

/* 玩家提示信息 */
.player-msg {
  color: #ffea7a;
  font-size: 13px;
  margin-left: 12px;
  align-self: center;
}

/* 按钮禁用态 */
.action-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: grayscale(40%);
}
.action-btn:disabled:hover {
  transform: none;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

/* ===== 红心癞子 ===== */

.wild-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  background: linear-gradient(135deg, #ff6b6b 0%, #d4001a 100%);
  color: #fff;
  font-size: 10px;
  font-weight: bold;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  z-index: 5;
}

.wild-arrow {
  position: absolute;
  bottom: 2px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 10px;
  color: #d4001a;
  font-weight: bold;
  background: rgba(255, 255, 255, 0.85);
  padding: 1px 0;
  border-radius: 3px;
}

.card .card-content {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: bold;
}

/* ===== Wild Picker ===== */

.gd-wild-picker {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10001;
  animation: fadeIn 0.2s;
}

.gd-wild-card {
  background: linear-gradient(135deg, #2a5298 0%, #1e3c72 100%);
  padding: 22px 24px;
  border-radius: 16px;
  min-width: 320px;
  max-width: 92vw;
  color: #fff;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
  border: 2px solid rgba(255, 215, 0, 0.4);
}

.gd-wild-title {
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 14px;
  text-align: center;
}

.gd-wild-hint {
  font-size: 12px;
  font-weight: normal;
  opacity: 0.75;
  margin-left: 6px;
}

.gd-wild-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}

.gd-wild-grid button,
.gd-wild-row button {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: bold;
  transition: all 0.15s;
}

.gd-wild-grid button:hover,
.gd-wild-row button:hover {
  background: rgba(255, 215, 0, 0.3);
  border-color: rgba(255, 215, 0, 0.7);
  transform: translateY(-1px);
}

.gd-wild-grid button.wp-sel,
.gd-wild-row button.wp-sel {
  background: linear-gradient(135deg, #ffb347 0%, #ffcc33 100%);
  color: #1e3c72;
  border-color: #ffd700;
}

.gd-wild-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.gd-wild-actions {
  margin-top: 10px;
  margin-bottom: 0;
}

.gd-wild-close {
  background: #6c757d !important;
  border-color: #6c757d !important;
}

/* 手机横屏适配（仅对未进入掼蛋横屏模式的兜底；进入掼蛋后由
   上面的 body.guandan-landscape 规则统一接管，避免与紧凑布局冲突） */
@media screen and (max-width: 900px) and (orientation: landscape) {
  body:not(.guandan-landscape) .guandan-header h2 { font-size: 18px; }
  body:not(.guandan-landscape) .card { width: 50px; height: 75px; }
  body:not(.guandan-landscape) .card-rank { font-size: 18px; }
  body:not(.guandan-landscape) .card-suit { font-size: 16px; }
  body:not(.guandan-landscape) .player-hand { padding: 10px; max-height: 100px; }
  body:not(.guandan-landscape) .action-btn { padding: 10px 20px; font-size: 14px; }
}
