/* ========== 旺來麻將 遊戲牌桌樣式 ========== */

/* ===== 強制橫向提示 ===== */
.portrait-warn {
  display: none;
  position: absolute;
  inset: 0;
  background: #0a0014;
  color: #fff;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  font-size: 28px;
  font-weight: 700;
  z-index: 9999;
  text-align: center;
}

.landscape-only {
  display: flex;
  flex-direction: column;
  height: 100%;
}

@media (orientation: portrait) {
  .portrait-warn { display: flex; }
  .landscape-only { display: none; }
}

/* ===== 牌桌容器 ===== */
.game-table {
  position: absolute;
  inset: 0;
  overflow: hidden;
  user-select: none;
  font-family: inherit;
  background: #0a0014;
}

/* ===== 頂部資訊欄 ===== */
.gt-header {
  display: flex;
  align-items: center;
  height: 44px;
  background: linear-gradient(90deg, rgba(20,0,40,0.95), rgba(10,0,20,0.95));
  border-bottom: 1px solid rgba(139,92,246,0.3);
  padding: 0 10px;
  flex-shrink: 0;
  z-index: 20;
}

.gt-header-left {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.gt-gameid {
  font-size: 10px;
  color: rgba(255,255,255,0.45);
  letter-spacing: 0.5px;
}
.gt-stakes {
  font-size: 12px;
  font-weight: 700;
  color: #fbbf24;
}

.gt-header-center {
  flex: 1;
  display: flex;
  justify-content: center;
}
.gt-avatar-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.gt-avatar {
  border-radius: 50%;
  background: linear-gradient(135deg, #7c3aed, #2563eb);
  border: 2px solid rgba(255,215,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  flex-shrink: 0;
}
.top-avatar { width: 36px; height: 36px; font-size: 13px; }
.sm-avatar  { width: 32px; height: 32px; font-size: 12px; }
.gt-score-badge {
  font-size: 11px;
  font-weight: 700;
  color: #fbbf24;
  background: rgba(0,0,0,0.4);
  border-radius: 8px;
  padding: 1px 6px;
}

.gt-header-right {
  display: flex;
  gap: 3px;
}

/* ===== 主桌面（填充剩餘高度） ===== */
.gt-table {
  flex: 1;
  display: flex;
  flex-direction: row;
  overflow: hidden;
  /* 綠色桌面 + 賽博朋克底圖 */
  background:
    radial-gradient(ellipse at center, rgba(20,80,30,0.92) 0%, rgba(10,50,15,0.96) 70%, rgba(5,25,8,1) 100%),
    url('../assets/bg/cyberpunk_1920x1080.png') center/cover no-repeat;
  position: relative;
  perspective: 600px;
}

.gt-table-inner {
  display: flex;
  flex-direction: row;
  flex: 1;
  transform: perspective(700px) rotateX(5deg);
  transform-origin: center 85%;
}

/* 木質外框 */
.gt-table::before {
  content: '';
  position: absolute;
  inset: 0;
  border: 8px solid transparent;
  border-image: linear-gradient(135deg, #a0622a, #d4935a, #8b4513, #c87941, #6b3010) 1;
  pointer-events: none;
  z-index: 1;
  box-shadow: inset 0 0 30px rgba(0,0,0,0.4), 0 0 20px rgba(0,0,0,0.5);
}

/* ===== 左右側玩家欄 ===== */
.gt-side {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  padding: 4px 2px;
  gap: 4px;
  z-index: 5;
}

.gt-side-left  { flex-direction: row; width: 100px; gap: 2px; }
.gt-side-right { flex-direction: row; width: 100px; gap: 2px; }


.gt-side-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 4px;
}

.gt-side-name {
  font-size: 10px;
  color: rgba(255,255,255,0.7);
  font-weight: 600;
  white-space: nowrap;
}

.gt-side-score {
  font-size: 11px;
  font-weight: 700;
}
.gt-side-score.positive { color: #22c55e; }
.gt-side-score.negative { color: #ef4444; }

/* ===== 輪次高亮 ===== */
@keyframes turnPulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 2px rgba(255, 213, 0, 0.5); }
  50%       { opacity: 1; box-shadow: 0 0 0 4px rgba(255, 213, 0, 1), 0 0 18px rgba(255, 213, 0, 0.55); }
}
@keyframes selfTurnPulse {
  0%, 100% { box-shadow: 0 -3px 0 2px rgba(34, 197, 94, 0.5); }
  50%       { box-shadow: 0 -3px 0 4px rgba(34, 197, 94, 1), 0 0 18px rgba(34, 197, 94, 0.4); }
}

/* 對手頭像發光框 */
.turn-active-avatar {
  animation: turnPulse 1.2s ease-in-out infinite;
  border-radius: 50%;
  outline: 2px solid rgba(255, 213, 0, 0.9);
  outline-offset: 2px;
}
/* 自己回合：底部發光邊 */
.gt-bottom.self-turn-active {
  animation: selfTurnPulse 1.2s ease-in-out infinite;
  border-radius: 8px 8px 0 0;
}
/* 中央輪次提示條 */
.turn-indicator-bar {
  position: absolute;
  bottom: -14px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.78);
  color: #fbbf24;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 10px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 20;
  letter-spacing: 0.5px;
}

.badge-zhuang {
  background: #dc2626;
  color: #fff;
  font-size: 10px;
  font-weight: 900;
  padding: 1px 5px;
  border-radius: 4px;
}

/* ===== 牌背 ===== */
.tile-back {
  background: linear-gradient(180deg, #7bcae0 0%, #5ba8c8 30%, #3d8aaa 68%, #2d6a8a 72%, #1a4a6a 100%);
  border: 1.5px solid rgba(255,255,255,0.3);
  position: relative;
  overflow: visible;
  border-radius: 2px;
  flex-shrink: 0;
  box-shadow: 0 -3px 0 #a8e0f0, 0 6px 0 #f0ebe0, 0 8px 5px rgba(0,0,0,0.4);
}
.tile-back::after {
  content: '';
  position: absolute;
  inset: 2px;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 1px;
  background: repeating-linear-gradient(
    45deg, transparent, transparent 3px,
    rgba(255,255,255,0.07) 3px, rgba(255,255,255,0.07) 4px
  );
}

/* ===== 牌牆 tile（小型雙層） ===== */
.wall-tile {
  flex-shrink: 0;
  box-shadow: 0 1px 0 #a8e0f0, 0 2px 0 #f0ebe0, 0 3px 2px rgba(0,0,0,0.3);
  border-width: 1px;
}
/* 牌牆：站立的牌（高>寬，約3:2比例） */
.wt-top  { width: 14px; height: 20px; }
.wt-side { width: 20px; height: 14px; }

.wall-tile::after { display: none; }

.wall-top { display: flex; flex-direction: column; gap: 1px; align-items: center; }
.wall-row { display: flex; gap: 0; }

.wall-left, .wall-right { display: flex; flex-direction: row; gap: 1px; align-self: center; }
.wall-col { display: flex; flex-direction: column; gap: 0; }

/* ===== 門前牌 tile（較大站立） ===== */
.hand-tile { flex-shrink: 0; }
/* 上家門前牌：上白下藍 */
.ht-top  {
  width: 20px; height: 12px;
  background: linear-gradient(180deg, #f0ebe0 45%, #5ba8c8 45%) !important;
  border: 1px solid rgba(0,0,0,0.15) !important;
  box-shadow: none !important;
}
.ht-top::after { display: none !important; }
/* 左家門前牌：左白右藍 */
.hand-left .ht-side {
  width: 12px; height: 20px;
  background: linear-gradient(90deg, #f0ebe0 45%, #5ba8c8 45%) !important;
  border: 1px solid rgba(0,0,0,0.15) !important;
  box-shadow: none !important;
}
/* 右家門前牌：左藍右白 */
.hand-right .ht-side {
  width: 12px; height: 20px;
  background: linear-gradient(90deg, #5ba8c8 55%, #f0ebe0 55%) !important;
  border: 1px solid rgba(0,0,0,0.15) !important;
  box-shadow: none !important;
}
.ht-side::after { display: none !important; }

.hand-top   { display: flex; gap: 1px; justify-content: center; padding: 2px 0; }
.hand-left  { display: flex; flex-direction: column; gap: 0; align-self: center; }
.hand-right { display: flex; flex-direction: column; gap: 0; align-self: center; }

/* 上家容器 */
.gt-opponent-top {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  padding: 4px 0 2px 0;
}

/* ===== 中央區域 ===== */
.gt-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: visible;
}


/* 河牌 + 風向盤區 */
.gt-river {
  flex: 1;
  overflow: visible;
  position: relative;
  display: grid;
  grid-template-areas:
    ". top    ."
    "left wind right"
    ". self   .";
  grid-template-columns: 1fr auto 1fr;
  grid-template-rows: 1fr auto 1fr;
  gap: 4px;
  padding: 4px;
  width: 100%;
}

.river-top  { grid-area: top;  display: flex; flex-wrap: wrap; justify-content: center; align-content: flex-start; gap: 1px; padding-bottom: 14px; overflow: visible; }
.river-left { grid-area: left; overflow: visible; display: flex; flex-direction: row; flex-wrap: wrap; align-content: flex-start; justify-content: flex-start; justify-self: start; align-items: flex-start; max-width: 140px; gap: 2px; }
.river-right{ grid-area: right; overflow: visible; display: flex; flex-direction: row; flex-wrap: wrap; align-content: flex-start; justify-content: flex-end; justify-self: end; align-items: flex-start; max-width: 140px; gap: 2px; }

/* 左右河牌、牌背：統一用 box-shadow（角度降低後歪斜不明顯） */
.river-self { grid-area: self; display: flex; flex-wrap: wrap; justify-content: center; align-content: flex-end; gap: 1px; }

/* ===== 風向盤 ===== */
.wind-indicator {
  grid-area: wind;
  position: relative;
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.wind-diamond {
  width: 56px;
  height: 56px;
  transform: rotate(45deg);
  background: linear-gradient(135deg, #2d0a5a, #1a0632);
  border: 2px solid rgba(255,215,0,0.7);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 15px rgba(255,215,0,0.15);
}
.wind-remaining {
  transform: rotate(-45deg);
  font-size: 20px;
  font-weight: 900;
  color: #fbbf24;
  text-shadow: 0 0 8px rgba(251,191,36,0.5);
}

.wind-label {
  position: absolute;
  font-size: 11px;
  font-weight: 700;
  color: rgba(255,255,255,0.4);
}
.wind-label.active { color: #fbbf24; text-shadow: 0 0 6px rgba(251,191,36,0.5); }
.wl-top    { top: -2px;  left: 50%; transform: translateX(-50%); }
.wl-bottom { bottom: -2px; left: 50%; transform: translateX(-50%); }
.wl-left   { left: -4px;  top: 50%; transform: translateY(-50%); }
.wl-right  { right: -4px; top: 50%; transform: translateY(-50%); }

/* ===== 河牌小牌 ===== */
.tile-small {
  width: 22px;
  height: 30px;
  border-radius: 2px;
  background: linear-gradient(180deg, #fff 0%, #e8e0d0 100%);
  border: 1px solid #c0b090;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 0 #f0ebe0, 0 10px 0 #2d6a8a, 0 13px 6px rgba(0,0,0,0.4);
  flex-shrink: 0;
  position: relative;
  overflow: visible;
}
.tile-small .tile-face {
  width: 100%;
  height: 100%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tile-small .tile-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.tile-small .tile-fallback {
  font-size: 9px;
  font-weight: 800;
  color: #333;
}

/* ===== 底部：副露 + 手牌 ===== */
.gt-bottom {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  padding: 0 6px 4px 6px;
  gap: 3px;
  flex-shrink: 0;
  position: relative;
}

.gt-meld-left, .gt-meld-right {
  display: flex;
  flex-direction: column;
  gap: 3px;
  align-items: center;
  min-width: 40px;
  padding-bottom: 4px;
}

/* 動作按鈕（手牌正上方） */
.action-bar {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 3px;
  z-index: 30;
  animation: actionFadeIn 0.25s ease;
}

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

.action-btn {
  padding: 6px 16px;
  border-radius: 8px;
  border: none;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 2px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  transition: transform 0.1s;
}
.action-btn:active { transform: scale(0.92); }
.action-btn.chi  { background: linear-gradient(135deg, #2563eb, #60a5fa); color: #fff; }
.action-btn.pong { background: linear-gradient(135deg, #16a34a, #4ade80); color: #fff; }
.action-btn.kong { background: linear-gradient(135deg, #7c3aed, #a78bfa); color: #fff; }
.action-btn.hu   { background: linear-gradient(135deg, #dc2626, #f87171); color: #fff; box-shadow: 0 0 16px rgba(220,38,38,0.5); }
.action-btn.pass { background: rgba(255,255,255,0.12); color: rgba(255,255,255,0.6); }

/* ===== 手牌 ===== */
.hand-tiles {
  display: flex;
  flex-direction: row;
  gap: 2px;
  align-items: flex-end;
  flex: 1;
  justify-content: center;
}

/* ===== 大牌（手牌） ===== */
.tile {
  width: 42px;
  height: 58px;
  border-radius: 4px;
  background: linear-gradient(180deg, #ffffff 0%, #f0ebe0 60%, #e0d8c8 100%);
  border: 1px solid #c0b090;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  position: relative;
  overflow: visible;
  box-shadow: 0 2px 0 #f0ebe0, 0 10px 0 #2d6a8a, 0 13px 8px rgba(0,0,0,0.5);
  flex-shrink: 0;
}
.tile .tile-face {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 3px;
}
.tile-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.tile-fallback {
  font-size: 14px;
  font-weight: 800;
  color: #333;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 懸停 */
.hand-tiles .tile:hover {
  transform: translateY(-10px);
  box-shadow: 0 2px 0 #b0a080, 0 3px 0 #a09070, 0 12px 20px rgba(0,0,0,0.5);
}
/* 選中 */
.hand-tiles .tile.selected {
  transform: translateY(-16px);
  border-color: #00d4ff;
  box-shadow: 0 2px 0 #b0a080, 0 3px 0 #a09070, 0 12px 20px rgba(0,212,255,0.4);
}
/* 剛摸的牌 */
.hand-tiles .tile.new-draw {
  margin-left: 10px;
}

/* ===== 底部狀態列 ===== */
.game-status-bar {
  height: 26px;
  background: linear-gradient(90deg, #2d1065, #1e1065, #2d1065);
  border-top: 1px solid rgba(139,92,246,0.3);
  display: flex;
  align-items: center;
  padding: 0 10px;
  gap: 3px;
  font-size: 11px;
  flex-shrink: 0;
  z-index: 20;
}
.status-wind  { color: #fbbf24; font-weight: 700; }
.status-name  { color: #e2e8f0; }
.status-score { font-weight: 700; }
.status-score.positive { color: #22c55e; }
.status-score.negative { color: #ef4444; }
.status-timer { margin-left: auto; color: rgba(255,255,255,0.5); font-variant-numeric: tabular-nums; }

/* ===== 小按鈕 ===== */
.game-icon-btn {
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.4);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.game-icon-btn:active { transform: scale(0.88); }
.game-icon-btn.sm { width: 30px; height: 30px; font-size: 14px; }

/* ===== 勝利特效 ===== */
.win-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  background: rgba(0,0,0,0.5);
  animation: winFadeIn 0.3s ease;
}
@keyframes winFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.win-effect-img {
  width: min(70vw, 360px);
  height: auto;
  animation: winPop 0.4s cubic-bezier(0.2, 0.8, 0.3, 1.2) both;
  filter: drop-shadow(0 0 30px rgba(255,215,0,0.9));
}
@keyframes winPop {
  0%   { transform: scale(0.3) rotate(-10deg); opacity: 0; }
  70%  { transform: scale(1.1) rotate(3deg); opacity: 1; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

/* ===== 結算畫面 ===== */
.result-screen {
  position: absolute;
  inset: 0;
  background: var(--bg-gradient);
  overflow-y: auto;
  padding: 20px 16px;
}
.result-title {
  text-align: center;
  font-size: 28px;
  font-weight: 900;
  margin-bottom: 20px;
}
.result-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 3px;
  max-width: 600px;
  margin: 0 auto 20px;
}
.result-card {
  border-radius: 12px;
  padding: 16px;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.result-card .rc-avatar {
  width: 48px; height: 48px; border-radius: 50%;
  background: linear-gradient(135deg,#6b21a8,#2563eb);
  margin: 0 auto 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; border: 2px solid rgba(255,215,0,0.6);
}
.result-card .rc-name  { font-size: 14px; font-weight: 700; margin-bottom: 4px; }
.result-card .rc-id    { font-size: 10px; color: rgba(255,255,255,0.4); margin-bottom: 10px; }
.result-card .rc-score { font-size: 24px; font-weight: 900; }
.result-card .rc-score.positive { color: #22c55e; }
.result-card .rc-score.negative { color: #ef4444; }
.result-card.winner { border: 2px solid #fbbf24; box-shadow: 0 0 20px rgba(251,191,36,0.3); }
.result-card .winner-badge { position: absolute; top: 8px; right: 8px; font-size: 22px; }
.result-info { text-align: center; font-size: 11px; color: rgba(255,255,255,0.4); margin-bottom: 16px; line-height: 1.8; }
.result-actions { display: flex; gap: 3px; justify-content: center; max-width: 400px; margin: 0 auto; }

/* ===== 響應式微調 ===== */
@media (max-height: 420px) and (orientation: landscape) {
  .gt-header { height: 36px; }
  .tile { width: 36px; height: 50px; }
  .wt-top { width: 11px; height: 16px; }
  .wt-side { width: 16px; height: 11px; }
  .ht-top { width: 16px; height: 10px; }
  .ht-side { width: 6px; height: 14px; }
  .tile-small { width: 18px; height: 24px; }
  .wind-indicator { width: 64px; height: 64px; }
  .wind-diamond { width: 44px; height: 44px; }
  .wind-remaining { font-size: 15px; }
  .gt-side-left, .gt-side-right { width: 80px; }
}
