/* ═══════════════════════════════════════════════════════
   texas-holdem.css — Texas Hold'em v1.0
   Task 2A: Bàn oval + seat positions
   ═══════════════════════════════════════════════════════

   Seat positions (% từ top-left của .th-table):
     Mình (seat mình) luôn ở dưới cùng giữa — không có slot,
     được render trong .th-self-area bên ngoài bàn.

   Seat slots đánh số theo chiều kim đồng hồ:
     data-seat="0" → trên cùng giữa
     data-seat="1" → trên phải
     data-seat="2" → phải giữa
     data-seat="3" → dưới phải
     data-seat="4" → dưới trái  (ít dùng — self thường ở đây)
     data-seat="5" → trái giữa
     data-seat="6" → trên trái

   Vị trí % được tính theo ellipse 90%×80% center tại (50%, 46%)
   ═══════════════════════════════════════════════════════ */

/* ── Screen wrapper ─────────────────────────────────── */

.th-screen {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    flex: 1;
    box-sizing: border-box;
    overflow: hidden;
    gap: 0;
}

body.is-texasholdem #dynamic-game-area {
    overflow: hidden !important;
    padding: 0 !important;
}

/* ── Khu vực bàn + self ─────────────────────────────── */

.th-arena {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 6px 6px 0;
    gap: 6px;
    position: relative;
}

/* ── Bàn chơi oval ──────────────────────────────────── */

.th-table {
    flex: 1;
    min-height: 0;
    position: relative;
    border-radius: 50% / 42%;
    background:
        radial-gradient(ellipse at 50% 38%,
            var(--felt-light) 0%,
            var(--felt-mid)   45%,
            var(--felt-dark)  100%);
    border: 4px solid var(--felt-border);
    box-shadow:
        inset 0 0 60px rgba(0, 0, 0, 0.45),
        0 0 0 5px var(--felt-outer),
        0 0 0 8px rgba(255, 215, 0, 0.08),
        0 8px 30px rgba(0, 0, 0, 0.7);
    overflow: visible; /* seat slots nhô ra ngoài */
}

/* Vân nỉ tinh tế */
.th-table::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background-image:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 3px,
            rgba(0, 0, 0, 0.03) 3px,
            rgba(0, 0, 0, 0.03) 6px
        );
    pointer-events: none;
    z-index: 0;
}

/* Viền ánh vàng bên trong */
.th-table::after {
    content: '';
    position: absolute;
    inset: 6px;
    border-radius: 50% / 42%;
    border: 1px solid rgba(255, 215, 0, 0.1);
    pointer-events: none;
    z-index: 0;
}

/* ── Vùng giữa bàn: community + pot ─────────────────── */

.th-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    z-index: 5;
    pointer-events: none;
}

/* Phase label (PREFLOP / FLOP / TURN / RIVER) */
.th-phase-label {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: rgba(255, 215, 0, 0.55);
}

/* 5 ô community cards */
.th-community {
    display: flex;
    gap: 5px;
    align-items: center;
    justify-content: center;
}

.th-community-slot {
    width: 40px;
    height: 58px;
    border-radius: 6px;
    border: 1.5px dashed rgba(255, 215, 0, 0.2);
    background: rgba(0, 0, 0, 0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.3s ease;
    box-sizing: border-box;
}

.th-community-slot.has-card {
    border-color: transparent;
    background: transparent;
}

/* Pot display */
.th-pot {
    display: flex;
    align-items: center;
    gap: 5px;
    background: rgba(0, 0, 0, 0.45);
    border: 1px solid rgba(255, 215, 0, 0.2);
    border-radius: 20px;
    padding: 4px 12px;
    color: var(--gold);
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    pointer-events: auto;
}

.th-pot::before {
    content: '🪙';
    font-size: 0.85rem;
}

/* ══════════════════════════════════════════════════════
   SEAT SLOTS
   Mỗi .th-seat được đặt absolute trên .th-table,
   căn chỉnh bằng transform để center ra đúng điểm.

   CSS custom props --sx, --sy = tọa độ % (left, top)
   dùng để JS tính góc bottle spin (Task 3).
   ══════════════════════════════════════════════════════ */

.th-seat {
    position: absolute;
    left: var(--sx);
    top:  var(--sy);
    transform: translate(-50%, -50%);
    width: 72px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    z-index: 10;
    transition: opacity 0.2s ease;
}

.th-seat[data-empty="true"] {
    opacity: 0.25;
    pointer-events: none;
}

/* Highlight lượt đi */
.th-seat--active .th-seat-avatar {
    box-shadow:
        0 0 0 3px var(--gold),
        0 0 16px rgba(255, 215, 0, 0.6);
    animation: th-pulse-active 1s ease-in-out infinite;
}

@keyframes th-pulse-active {
    0%, 100% { box-shadow: 0 0 0 3px var(--gold), 0 0 16px rgba(255, 215, 0, 0.6); }
    50%       { box-shadow: 0 0 0 3px var(--gold), 0 0 28px rgba(255, 215, 0, 0.9); }
}

/* Avatar */
.th-seat-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 2px solid rgba(255, 215, 0, 0.25);
    background: var(--surface-2);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
    transition: box-shadow 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

.th-seat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Tên player */
.th-seat-name {
    font-size: 0.62rem;
    font-weight: 600;
    color: var(--text-main);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 72px;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

/* Chip count */
.th-seat-chips {
    font-size: 0.6rem;
    color: var(--gold);
    font-weight: 700;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 10px;
    padding: 1px 7px;
    letter-spacing: 0.3px;
}

/* 2 hole cards úp — hiển thị cho opponent */
.th-seat-cards {
    display: flex;
    gap: -4px;
}

.th-hole-back {
    width: 22px;
    height: 32px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background:
        linear-gradient(135deg, #1a237e 0%, #283593 50%, #1a237e 100%);
    box-shadow: 1px 2px 5px rgba(0, 0, 0, 0.6);
    position: relative;
    flex-shrink: 0;
}

.th-hole-back:nth-child(2) {
    margin-left: -8px;
}

/* Badge bet / action nhỏ trên avatar */
.th-seat-badge {
    position: absolute;
    bottom: -2px;
    right: -2px;
    background: var(--primary);
    color: #fff;
    font-size: 0.52rem;
    font-weight: 700;
    border-radius: 8px;
    padding: 1px 5px;
    white-space: nowrap;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
    text-transform: uppercase;
}

.th-seat-badge.fold  { background: #555; }
.th-seat-badge.call  { background: #1b5e20; }
.th-seat-badge.raise { background: #b71c1c; }
.th-seat-badge.bet   { background: rgba(0,0,0,0.65); color: var(--gold); border: 1px solid rgba(255,215,0,0.3); }

/* ══════════════════════════════════════════════════════
   SEAT COORDINATE MAP
   Trục tọa độ % tính trên .th-table (width=100%, height=100%).
   Ellipse seats: rx=44%, ry=38%, center (50%, 46%).

   Công thức:
     sx = 50% + rx * cos(θ)
     sy = 46% + ry * sin(θ)
   θ = 0° = phải, 90° = dưới (chiều kim đồng hồ).
   Mình luôn ở θ=90° (dưới giữa) → không render slot ở đây.

   Các slot opponent xếp từ θ=-90° (trên) đi chiều kim đồng hồ.

   Ánh xạ data-seat-pos="0..7":
     0 = trên giữa        (θ = -90°)
     1 = trên phải        (θ = -45°)
     2 = phải giữa        (θ =   0°)
     3 = dưới phải        (θ =  45°)
     4 = dưới trái        (θ = 135°)
     5 = trái giữa        (θ = 180°)
     6 = trên trái        (θ = -135°)
     7 = trên phải-giữa   (θ = -20°)

   Các preset theo số người dùng [data-players="N"] để xác định
   --sx/--sy qua attribute selector bên dưới.
   ══════════════════════════════════════════════════════ */

/* Toạ độ cố định cho từng vị trí pos (rx=44%, ry=38%, cy=46%) */

/* pos=0: top-center  θ=-90°  → sx=50%,  sy=8%  */
.th-seat[data-seat-pos="0"] { --sx: 50%;  --sy: 8%;  }

/* pos=1: top-right   θ=-45°  → sx=81%,  sy=19% */
.th-seat[data-seat-pos="1"] { --sx: 81%;  --sy: 19%; }

/* pos=2: mid-right   θ=0°    → sx=94%,  sy=46% */
.th-seat[data-seat-pos="2"] { --sx: 94%;  --sy: 46%; }

/* pos=3: bot-right   θ=45°   → sx=81%,  sy=73% */
.th-seat[data-seat-pos="3"] { --sx: 81%;  --sy: 73%; }

/* pos=4: bot-left    θ=135°  → sx=19%,  sy=73% */
.th-seat[data-seat-pos="4"] { --sx: 19%;  --sy: 73%; }

/* pos=5: mid-left    θ=180°  → sx=6%,   sy=46% */
.th-seat[data-seat-pos="5"] { --sx: 6%;   --sy: 46%; }

/* pos=6: top-left    θ=-135° → sx=19%,  sy=19% */
.th-seat[data-seat-pos="6"] { --sx: 19%;  --sy: 19%; }

/* pos=7: top-right-near θ=-20° → sx=91%, sy=33% */
.th-seat[data-seat-pos="7"] { --sx: 91%;  --sy: 33%; }

/* pos=8: top-left-near θ=-160° → sx=9%,  sy=33% */
.th-seat[data-seat-pos="8"] { --sx: 9%;   --sy: 33%; }

/*
  ── PRESET THEO SỐ NGƯỜI ──────────────────────────────
  JS sẽ set data-seat-pos="X" dựa trên số người và index.
  Bảng ánh xạ được JS dùng (comment để tham khảo):

  2 players (1 opponent):
    opp[0] → pos 0   (top)

  3 players (2 opponents):
    opp[0] → pos 6   (top-left)
    opp[1] → pos 1   (top-right)

  4 players (3 opponents):
    opp[0] → pos 5   (mid-left)
    opp[1] → pos 0   (top)
    opp[2] → pos 2   (mid-right)

  5 players (4 opponents):
    opp[0] → pos 5   (mid-left)
    opp[1] → pos 6   (top-left)
    opp[2] → pos 1   (top-right)
    opp[3] → pos 2   (mid-right)

  6 players (5 opponents):
    opp[0] → pos 4   (bot-left)
    opp[1] → pos 5   (mid-left)
    opp[2] → pos 0   (top)
    opp[3] → pos 2   (mid-right)
    opp[4] → pos 3   (bot-right)

  7 players (6 opponents):
    opp[0] → pos 4   (bot-left)
    opp[1] → pos 5   (mid-left)
    opp[2] → pos 6   (top-left)
    opp[3] → pos 1   (top-right)
    opp[4] → pos 2   (mid-right)
    opp[5] → pos 3   (bot-right)

  8 players (7 opponents):
    opp[0] → pos 4   (bot-left)
    opp[1] → pos 8   (top-left-near)
    opp[2] → pos 5   (mid-left)
    opp[3] → pos 6   (top-left)   ← or use 0 top
    opp[4] → pos 0   (top)
    opp[5] → pos 1   (top-right)
    opp[6] → pos 2   (mid-right)

  9 players (8 opponents):
    opp[0] → pos 4   (bot-left)
    opp[1] → pos 8   (top-left-near)
    opp[2] → pos 5   (mid-left)
    opp[3] → pos 6   (top-left)
    opp[4] → pos 0   (top)
    opp[5] → pos 1   (top-right)
    opp[6] → pos 7   (top-right-near)
    opp[7] → pos 2   (mid-right)
*/

/* ── Khu vực mình (self) — bên dưới bàn ─────────────── */

.th-self-area {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 6px 6px 4px;
    background:
        linear-gradient(to bottom,
            transparent 0%,
            rgba(0, 0, 0, 0.35) 30%,
            rgba(0, 0, 0, 0.55) 100%);
    position: relative;
}

/* Tên + chips của mình */
.th-self-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.th-self-name {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-main);
}

.th-self-chips {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--gold);
    background: rgba(0, 0, 0, 0.45);
    border-radius: 12px;
    padding: 2px 10px;
}

/* 2 hole cards của mình (lật ngửa) — see Task 5 CSS block below */

/* ══════════════════════════════════════════════════════
   ACTION BUTTONS
   .th-actions — container 3 nút: Bỏ / Theo / Gấp đôi
   ══════════════════════════════════════════════════════ */

.th-actions {
    display: flex;
    gap: 8px;
    justify-content: center;
    align-items: center;
    flex-wrap: nowrap;
}

.th-actions.hidden {
    visibility: hidden;
    pointer-events: none;
}

.th-btn {
    flex: 1;
    max-width: 110px;
    min-width: 72px;
    padding: 10px 6px;
    border: none;
    border-radius: 22px;
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
    letter-spacing: 0.3px;
    transition: transform 0.1s, box-shadow 0.15s, opacity 0.15s;
    white-space: nowrap;
}

.th-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    transform: none !important;
}

.th-btn:not(:disabled):active {
    transform: scale(0.94);
}

/* Bỏ (fold) */
.th-btn--fold {
    background: linear-gradient(135deg, #616161, #424242);
    color: #ddd;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.4);
}
.th-btn--fold:not(:disabled):hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

/* Theo (call) */
.th-btn--call {
    background: linear-gradient(135deg, #2e7d32, #1b5e20);
    color: #fff;
    box-shadow: 0 3px 12px rgba(27, 94, 32, 0.5);
}
.th-btn--call:not(:disabled):hover {
    box-shadow: 0 4px 20px rgba(46, 125, 50, 0.7);
}

/* Gấp đôi (raise) */
.th-btn--raise {
    background: linear-gradient(135deg, #c62828, #b71c1c);
    color: #fff;
    box-shadow: 0 3px 12px rgba(198, 40, 40, 0.45);
}
.th-btn--raise:not(:disabled):hover {
    box-shadow: 0 4px 20px rgba(198, 40, 40, 0.7);
}

/* Countdown timer cho lượt action */
.th-timer {
    position: absolute;
    top: -4px;
    left: 50%;
    transform: translateX(-50%);
    width: 34px;
    height: 34px;
    z-index: 20;
}

.th-timer-svg {
    transform: rotate(-90deg);
}

.th-timer-track {
    fill: none;
    stroke: rgba(255, 255, 255, 0.1);
    stroke-width: 3;
}

.th-timer-fill {
    fill: none;
    stroke: var(--gold);
    stroke-width: 3;
    stroke-linecap: round;
    stroke-dasharray: 88;
    stroke-dashoffset: 0;
    transition: stroke 0.5s ease;
}

.th-timer-fill.warning {
    stroke: #ff7043;
}

.th-timer-fill.urgent {
    stroke: #e53935;
    animation: th-timer-blink 0.5s ease-in-out infinite;
}

@keyframes th-timer-blink {
    50% { opacity: 0.3; }
}

/* ══════════════════════════════════════════════════════
   BOTTLE SPIN OVERLAY (Task 3 — placeholder layout)
   ══════════════════════════════════════════════════════ */

.th-spin-overlay {
    position: absolute;
    inset: 0;
    z-index: 50;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: rgba(0, 0, 0, 0.35);
    border-radius: inherit;
    pointer-events: none;
}

.th-spin-overlay.hidden {
    display: none;
}

.th-bottle {
    width: 48px;
    height: 120px;
    transform-origin: center center;
    /* transform: rotate(Xdeg) sẽ được set bởi JS */
    transition: transform 3s cubic-bezier(0.17, 0.67, 0.12, 0.99);
    filter: drop-shadow(0 4px 16px rgba(0, 0, 0, 0.6));
}

.th-spin-label {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--gold);
    text-shadow: 0 0 12px rgba(255, 215, 0, 0.6);
    text-align: center;
    letter-spacing: 0.5px;
}

/* ══════════════════════════════════════════════════════
   SHOWDOWN / RESULT OVERLAY
   ══════════════════════════════════════════════════════ */

.th-result-overlay {
    position: absolute;
    inset: 0;
    z-index: 60;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: inherit;
    animation: th-fade-in 0.4s ease;
}

.th-result-overlay.hidden {
    display: none;
}

@keyframes th-fade-in {
    from { opacity: 0; transform: scale(0.95); }
    to   { opacity: 1; transform: scale(1); }
}

.th-result-winner {
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--gold);
    text-shadow: 0 0 24px rgba(255, 215, 0, 0.8);
    letter-spacing: 1px;
}

.th-result-hand {
    font-size: 0.82rem;
    color: var(--text-sub);
    font-weight: 600;
    letter-spacing: 0.5px;
}

.th-result-amount {
    font-size: 1rem;
    font-weight: 700;
    color: #69f0ae;
}

/* ══════════════════════════════════════════════════════
   DEAL DECK OVERLAY (Task 5)
   Stack bài ảo ở giữa bàn khi chia bài
   ══════════════════════════════════════════════════════ */

.th-deal-deck {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 28px;
    height: 40px;
    z-index: 45;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.th-deck-card {
    position: absolute;
    inset: 0;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background:
        linear-gradient(135deg, #1a237e 0%, #283593 50%, #1a237e 100%);
    box-shadow: 1px 2px 6px rgba(0, 0, 0, 0.7);
}

/* ── Face-up card (lá bài ngửa) ─────────────────────── */

.th-card-face {
    width: 40px;
    height: 58px;
    border-radius: 6px;
    border: 1.5px solid rgba(255, 255, 255, 0.15);
    background: #fafafa;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.6);
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}

.th-card-face::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        135deg,
        rgba(255, 255, 255, 0.25) 0%,
        transparent 60%
    );
    pointer-events: none;
}

.th-card-face .th-card-rank {
    font-size: 1.05rem;
    font-weight: 800;
    line-height: 1;
    letter-spacing: -0.5px;
}

.th-card-face .th-card-suit {
    font-size: 0.85rem;
    line-height: 1;
}

.th-card--red .th-card-rank,
.th-card--red .th-card-suit {
    color: #c62828;
}

.th-card--black .th-card-rank,
.th-card--black .th-card-suit {
    color: #111;
}

/* Self cards area: 2 lá cạnh nhau với gap */
.th-self-cards {
    display: flex;
    gap: 8px;
    justify-content: center;
    min-height: 58px; /* giữ layout khi chưa có bài */
}

/* ══════════════════════════════════════════════════════
   CARD ANIMATIONS (bay lá bài khi chia — Task 5)
   ══════════════════════════════════════════════════════ */

@keyframes th-deal-fly {
    from {
        opacity: 0;
        transform: translate(var(--deal-from-x), var(--deal-from-y)) scale(0.6) rotate(-15deg);
    }
    to {
        opacity: 1;
        transform: translate(0, 0) scale(1) rotate(0deg);
    }
}

.th-dealing {
    animation: th-deal-fly 0.32s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}

/* ── Community card flip ── */
@keyframes th-flip-card {
    0%   { transform: rotateY(0deg); }
    50%  { transform: rotateY(90deg); }
    100% { transform: rotateY(0deg); }
}

.th-community-slot.flipping {
    animation: th-flip-card 0.4s ease;
}

/* ══════════════════════════════════════════════════════
   RESPONSIVE: landscape (wide screen)
   ══════════════════════════════════════════════════════ */

@media (orientation: landscape) and (min-width: 600px) {
    .th-self-area {
        flex-direction: row;
        justify-content: center;
        gap: 16px;
        padding: 8px 16px;
    }

    .th-actions {
        gap: 12px;
    }

    .th-btn {
        max-width: 130px;
        padding: 11px 10px;
        font-size: 0.82rem;
    }

    .th-seat-avatar {
        width: 48px;
        height: 48px;
    }
}
