/* ═══════════════════════════════════════════════════════
   tien-len.css — UI Tiến Lên v5.0
   - Bàn chiếm toàn bộ không gian
   - hand + actions overlay ở đáy bàn
   - Slot hệ thống: người chơi quay bài vào trung tâm
   - Avatar ở các góc theo vị trí
   ═══════════════════════════════════════════════════════ */

/* ── Layout chính ── */

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

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

/* ── Bàn chơi — chiếm toàn bộ ── */

.tl-board {
    flex: 1;
    position: relative;
    min-height: 0;
    border-radius: 18px;
    overflow: hidden;
    background:
        radial-gradient(ellipse at 50% 40%,
            #0e6422 0%,
            #0a5018 40%,
            #063b12 100%);
    border: 3px solid #1a5c28;
    box-shadow:
        inset 0 0 60px rgba(0,0,0,0.4),
        0 0 0 4px #0a200d,
        0 0 0 6px rgba(255,215,0,0.07),
        0 6px 24px rgba(0,0,0,0.6);
    margin: 6px;
}

.tl-board::after {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 2px,
            rgba(0,0,0,0.04) 2px,
            rgba(0,0,0,0.04) 4px
        );
    pointer-events: none;
    border-radius: 15px;
    z-index: 0;
}

/* ═══════════════════════════════════════════════════════
   SLOT SYSTEM
   Mỗi slot được đặt tuyệt đối trên bàn.
   Bài trong slot LUÔN xoay đầu vào trung tâm bàn.
   Avatar + tên + số bài ở phần kề cạnh ngoài slot.
   ═══════════════════════════════════════════════════════ */

.tl-slot {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    visibility: hidden;
    pointer-events: none;
}

.tl-slot:not(:empty) {
    visibility: visible;
    pointer-events: auto;
}

/* ── Cấu trúc nội dung slot ──
   Mỗi slot gồm: .tl-fan (bài) + .tl-player-info (avatar+tên+badge)
   Sắp xếp theo hướng bài → trung tâm
*/

.tl-player-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
}

/* ══════════════════════════════════════════════════════
   PORTRAIT — 1 đối thủ
   slot-a: trên giữa → bài xoay xuống (rotate 180deg)
   Avatar ở phía trên bài (ra ngoài cạnh trên)
   ══════════════════════════════════════════════════════ */

#tl-board[data-opponents="1"] #tl-slot-a {
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    flex-direction: column;
}

#tl-board[data-opponents="1"] #tl-slot-a .tl-player-info {
    order: -1; /* avatar trên, bài dưới quay vào trung tâm */
}

#tl-board[data-opponents="1"] #tl-slot-a .tl-fan {
    transform: rotate(180deg);
}

/* ══════════════════════════════════════════════════════
   PORTRAIT — 2 đối thủ
   slot-a: trái giữa → bài quay sang phải (rotate 90deg)
   slot-b: phải giữa → bài quay sang trái (rotate -90deg)
   ══════════════════════════════════════════════════════ */

#tl-board[data-opponents="2"] #tl-slot-a {
    left: 0;
    top: 38%;
    transform: translateY(-50%);
    flex-direction: row;
}

#tl-board[data-opponents="2"] #tl-slot-a .tl-player-info {
    order: -1;
}

#tl-board[data-opponents="2"] #tl-slot-a .tl-fan {
    transform: rotate(90deg);
}

#tl-board[data-opponents="2"] #tl-slot-b {
    right: 0;
    top: 38%;
    transform: translateY(-50%);
    flex-direction: row;
}

#tl-board[data-opponents="2"] #tl-slot-b .tl-fan {
    transform: rotate(-90deg);
}

/* ══════════════════════════════════════════════════════
   PORTRAIT — 3 đối thủ
   slot-a: trái giữa
   slot-b: trên giữa
   slot-c: phải giữa
   ══════════════════════════════════════════════════════ */

#tl-board[data-opponents="3"] #tl-slot-a {
    left: 0;
    top: 38%;
    transform: translateY(-50%);
    flex-direction: row;
}

#tl-board[data-opponents="3"] #tl-slot-a .tl-player-info {
    order: -1;
}

#tl-board[data-opponents="3"] #tl-slot-a .tl-fan {
    transform: rotate(90deg);
}

#tl-board[data-opponents="3"] #tl-slot-b {
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    flex-direction: column;
}

#tl-board[data-opponents="3"] #tl-slot-b .tl-player-info {
    order: -1;
}

#tl-board[data-opponents="3"] #tl-slot-b .tl-fan {
    transform: rotate(180deg);
}

#tl-board[data-opponents="3"] #tl-slot-c {
    right: 0;
    top: 38%;
    transform: translateY(-50%);
    flex-direction: row;
}

#tl-board[data-opponents="3"] #tl-slot-c .tl-fan {
    transform: rotate(-90deg);
}

/* ── Fan bài trong slot đối thủ ── */

.tl-slot .tl-fan {
    width: 100px;
    height: 55px;
    position: relative;
    overflow: visible;
    flex-shrink: 0;
}

/* ── Avatar hình tròn ── */

.tl-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, #8b1a1a, #c0392b);
    border: 2px solid rgba(255, 215, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 700;
    color: #fff;
    text-transform: uppercase;
    box-shadow: 0 2px 8px rgba(0,0,0,0.5);
    flex-shrink: 0;
}

.tl-my-turn .tl-avatar {
    background: linear-gradient(135deg, #b8860b, #ffd700);
    color: #1a0a00;
    border-color: #ffd700;
    box-shadow: 0 0 12px rgba(255,215,0,0.6), 0 2px 8px rgba(0,0,0,0.5);
    animation: tl-pulse 1.2s ease-in-out infinite;
}

@keyframes tl-pulse {
    0%, 100% { box-shadow: 0 0 12px rgba(255,215,0,0.6), 0 2px 8px rgba(0,0,0,0.5); }
    50%       { box-shadow: 0 0 22px rgba(255,215,0,0.9), 0 2px 8px rgba(0,0,0,0.5); }
}

/* ── Tên người chơi ── */

.tl-player-name {
    font-size: 0.65rem;
    color: #ddd;
    white-space: nowrap;
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    background: rgba(0,0,0,0.65);
    padding: 2px 6px;
    border-radius: 6px;
    border: 1px solid rgba(255,255,255,0.1);
}

.tl-my-turn .tl-player-name {
    color: var(--gold);
    font-weight: 700;
    border-color: rgba(255,215,0,0.5);
    background: rgba(255,215,0,0.1);
}

/* ── Số bài còn lại ── */

.tl-card-count-badge {
    background: rgba(255,215,0,0.12);
    color: var(--gold);
    border: 1px solid rgba(255,215,0,0.3);
    border-radius: 20px;
    font-size: 0.6rem;
    font-weight: 700;
    padding: 1px 6px;
}

/* ── Khu vực đánh bài giữa bàn ── */

.tl-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 5;
    text-align: center;
    pointer-events: none;
}

.tl-center-label {
    color: rgba(255,255,255,0.28);
    font-style: italic;
    font-size: 0.78rem;
}

/* ── Fan chung (tay bài + center) ── */

.tl-fan {
    position: relative;
    height: 90px;
    display: flex;
    justify-content: center;
}

.tl-fan .card { margin: 0 !important; }

.tl-fan-card {
    position: absolute;
    transition: transform 0.18s ease, box-shadow 0.15s ease;
}

/* ════════════════════════════════════════════════════════
   TAY BÀI + NÚT HÀNH ĐỘNG — overlay ở đáy bàn
   Nút đánh/bỏ ở TRÊN bài, bài ở DƯỚI
   ════════════════════════════════════════════════════════ */

.tl-hand-area {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 20;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    padding-bottom: 4px;
    /* Gradient mờ để bài nổi lên trên bàn */
    background: linear-gradient(to top,
        rgba(6,59,18,0.92) 0%,
        rgba(6,59,18,0.6) 60%,
        transparent 100%);
    border-radius: 0 0 15px 15px;
}

.tl-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    z-index: 22;
    padding: 6px 0 4px;
}

.tl-hand {
    width: 100%;
    display: flex;
    justify-content: center;
    min-height: 100px;
    z-index: 21;
    position: relative;
}

.tl-btn-play,
.tl-btn-pass {
    margin: 0;
    width: 120px;
    padding: 8px 14px;
    font-size: 0.88rem;
}

/* Bài được chọn trong fan — chỉ thêm glow xanh, KHÔNG override transform */
.tl-fan-card.tl-selected {
    box-shadow:
        0 0 0 2.5px #22c55e,
        0 -8px 20px rgba(34,197,94,0.35),
        0 6px 18px rgba(0,0,0,0.5) !important;
}

.tl-btn-play:disabled {
    background: linear-gradient(135deg, #444, #333) !important;
    color: #888 !important;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

.tl-btn-pass:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    border-color: #555;
    color: #555;
}

/* ═══════════════════════════════════════════════════════
   LANDSCAPE (orientation media query) + FULLSCREEN
   Board mở rộng toàn màn, hand-area overlay đáy bàn
   Sidebar vẫn ở phải
   ═══════════════════════════════════════════════════════ */

@media (orientation: landscape) {
    .tl-screen {
        flex-direction: row;
        height: 100%;
        padding: 0;
        gap: 0;
    }

    .tl-board {
        flex: 1;
        height: 100%;
        min-height: 0;
        min-width: 0;
        margin: 6px;
    }

    /* Slot landscape — bài vẫn quay vào trung tâm */

    #tl-board[data-opponents="1"] #tl-slot-a {
        top: 0;
        left: 50%;
        transform: translateX(-50%);
        flex-direction: column;
        right: auto;
    }

    #tl-board[data-opponents="2"] #tl-slot-a {
        left: 0;
        top: 38%;
        transform: translateY(-50%);
        flex-direction: row;
        right: auto;
    }

    #tl-board[data-opponents="2"] #tl-slot-b {
        right: 0;
        top: 38%;
        transform: translateY(-50%);
        flex-direction: row;
        left: auto;
    }

    #tl-board[data-opponents="3"] #tl-slot-a {
        left: 0;
        top: 38%;
        transform: translateY(-50%);
        flex-direction: row;
        right: auto;
    }

    #tl-board[data-opponents="3"] #tl-slot-b {
        top: 0;
        left: 50%;
        transform: translateX(-50%);
        flex-direction: column;
        right: auto;
    }

    #tl-board[data-opponents="3"] #tl-slot-c {
        right: 0;
        top: 38%;
        transform: translateY(-50%);
        flex-direction: row;
        left: auto;
    }

    #dynamic-game-area { padding: 0 !important; overflow: hidden !important; }
}

/* ── Fullscreen JS class ── */

body.is-fullscreen.is-tienlen .tl-screen {
    flex-direction: row !important;
    height: 100% !important;
    width: 100% !important;
    overflow: hidden !important;
    padding: 0 !important;
    gap: 0 !important;
}

body.is-fullscreen.is-tienlen .tl-board {
    flex: 1 !important;
    height: 100% !important;
    min-height: 0 !important;
    min-width: 0 !important;
    margin: 6px !important;
}

/* Slot positions fullscreen — same as landscape */
body.is-fullscreen.is-tienlen #tl-board[data-opponents="1"] #tl-slot-a {
    top: 0; left: 50%; transform: translateX(-50%); right: auto;
    flex-direction: column;
}

body.is-fullscreen.is-tienlen #tl-board[data-opponents="2"] #tl-slot-a {
    left: 0; top: 38%; transform: translateY(-50%); right: auto;
    flex-direction: row;
}

body.is-fullscreen.is-tienlen #tl-board[data-opponents="2"] #tl-slot-b {
    right: 0; top: 38%; transform: translateY(-50%); left: auto;
    flex-direction: row;
}

body.is-fullscreen.is-tienlen #tl-board[data-opponents="3"] #tl-slot-a {
    left: 0; top: 38%; transform: translateY(-50%); right: auto;
    flex-direction: row;
}

body.is-fullscreen.is-tienlen #tl-board[data-opponents="3"] #tl-slot-b {
    top: 0; left: 50%; transform: translateX(-50%); right: auto;
    flex-direction: column;
}

body.is-fullscreen.is-tienlen #tl-board[data-opponents="3"] #tl-slot-c {
    right: 0; top: 38%; transform: translateY(-50%); left: auto;
    flex-direction: row;
}

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

body.is-fullscreen.is-tienlen #game-sys-msg {
    transform: translateX(-50%) !important;
    writing-mode: horizontal-tb !important;
}

body.is-fullscreen.is-tienlen #toast-msg {
    transform: translateX(-50%) !important;
    top: 12px !important;
    left: 50% !important;
    writing-mode: horizontal-tb !important;
}

body.is-fullscreen.is-tienlen .modal-box {
    transform: none !important;
    width: min(72vw, 400px) !important;
    max-width: 90vw !important;
    writing-mode: horizontal-tb !important;
}
