/* game.css - Big Two */
:root {
    --bg-color: #0d1117;
    --panel-bg: rgba(22, 27, 34, 0.6);
    --panel-border: rgba(255, 255, 255, 0.1);
    --text-primary: #e6edf3;
    --text-secondary: #848d97;
    --primary-color: #2f81f7;
    --secondary-color: #238636;
    --warning-color: #d29922;
    --danger-color: #f85149;
    --info-color: #a371f7;
    --glow-primary: rgba(47, 129, 247, 0.4);
    --glow-secondary: rgba(35, 134, 54, 0.4);
    --glow-warning: rgba(210, 153, 34, 0.4);
    font-family: 'Noto Sans TC', sans-serif;
}

body.dark-theme {
    background-color: var(--bg-color);
    color: var(--text-primary);
    margin: 0;
    min-height: 100vh;
    overflow-x: hidden;
    background: radial-gradient(circle at 50% 10%, #1f2937, #0d1117 80%);
}

#particles-bg {
    position: fixed; top: 0; left: 0;
    width: 100vw; height: 100vh; z-index: -1;
    background: url('https://www.transparenttextures.com/patterns/stardust.png');
    opacity: 0.3;
}

h1, h2, h3, h4 { font-family: 'Orbitron', 'Play', sans-serif; }

.app-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 15px;
    box-sizing: border-box;
}

/* Glassmorphism */
.glass-panel {
    background: var(--panel-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--panel-border);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

/* Buttons */
.btn {
    padding: 10px 20px; border: none; border-radius: 8px;
    font-weight: 700; cursor: pointer; transition: all 0.3s ease;
    text-transform: uppercase; color: #fff; outline: none;
    font-family: inherit; font-size: 0.95rem;
}
.btn-sm { padding: 6px 14px; font-size: 0.85rem; }
.btn-lg { padding: 14px 28px; font-size: 1.1rem; }
.btn-primary { background: var(--primary-color); }
.btn-primary:hover { background: #388bfd; box-shadow: 0 0 15px var(--glow-primary); }
.btn-secondary { background: #484f58; }
.btn-secondary:hover { background: #6e7681; }
.btn-success { background: var(--secondary-color); }
.btn-success:hover { background: #2ea043; box-shadow: 0 0 15px var(--glow-secondary); }
.btn-warning { background: var(--warning-color); color: #000; }
.btn-warning:hover { background: #e3b341; box-shadow: 0 0 15px var(--glow-warning); }
.btn-danger { background: var(--danger-color); }
.btn-danger:hover { background: #ff6e6a; }
.btn-info { background: var(--info-color); }
.btn-info:hover { background: #b48ef7; }
.btn-outline {
    background: transparent; border: 1px solid var(--panel-border);
    color: var(--text-secondary);
}
.btn-outline:hover { background: rgba(255,255,255,0.1); color: var(--text-primary); }
.btn-pass {
    background: transparent; border: 2px solid var(--secondary-color);
    color: var(--secondary-color); padding: 12px 24px; font-size: 1rem;
}
.btn-pass:hover { background: var(--secondary-color); color: #fff; }

.hidden { display: none !important; }

/* Login */
.login-wrapper {
    display: flex; justify-content: center; align-items: center; min-height: 80vh;
}
.login-panel {
    padding: 40px; text-align: center; width: 100%; max-width: 420px;
}
.logo-title {
    font-size: 3.5rem; margin-bottom: 0;
    background: linear-gradient(45deg, #f85149, #a371f7);
    -webkit-background-clip: text; background-clip: text;
    -webkit-text-fill-color: transparent;
}
.subtitle { color: var(--text-secondary); margin-bottom: 30px; font-size: 1.1rem; }

.input-group input {
    width: 100%; padding: 12px; margin-bottom: 20px; border-radius: 8px;
    border: 1px solid var(--panel-border); background: rgba(0, 0, 0, 0.3);
    color: #fff; box-sizing: border-box; font-size: 1rem;
}

.invite-info { margin: 20px 0; text-align: left; }
.invite-info p { margin: 8px 0; color: var(--text-secondary); }
.invite-info strong { color: var(--text-primary); }

/* Lobby */
.lobby-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 20px; margin-bottom: 30px;
}
.room-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}
.room-card {
    padding: 20px; display: flex; justify-content: space-between;
    align-items: center; transition: transform 0.2s; cursor: pointer;
}
.room-card:hover { transform: translateY(-4px); }
.room-info h4 { margin: 0 0 8px 0; }
.room-info p { margin: 4px 0; color: var(--text-secondary); font-size: 0.9rem; }
.empty-lobby { padding: 40px; text-align: center; color: var(--text-secondary); }
.info-text { color: var(--text-secondary); font-size: 0.9rem; margin: 15px 0; }

/* Modals */
.modal-overlay {
    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: 1000;
}
.modal-content { padding: 30px; width: 90%; max-width: 500px; }
.form-row { display: flex; gap: 15px; margin-bottom: 15px; }
.form-group {
    flex: 1; display: flex; flex-direction: column; text-align: left;
}
.form-group label { margin-bottom: 8px; color: var(--text-secondary); font-size: 0.9rem; }
.form-group input, .form-group select {
    padding: 10px; border-radius: 6px; background: rgba(0, 0, 0, 0.4);
    color: #fff; border: 1px solid var(--panel-border); font-size: 1rem;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 25px; }

/* ======= GAME ROOM ======= */

.game-wrapper {
    display: flex; flex-direction: column; gap: 10px; min-height: 95vh;
}

.room-header {
    padding: 10px 20px; display: flex; justify-content: space-between;
    align-items: center; flex-wrap: wrap; gap: 10px;
}
.room-header h2 { font-size: 1.1rem; margin: 0; white-space: nowrap; }
.top-status { color: var(--text-secondary); font-size: 0.85rem; }
.header-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.game-board {
    display: flex; flex-direction: column; flex: 1; overflow: visible;
}

/* ======= TABLE LAYOUT (opponents around table) ======= */
.table-layout {
    display: flex; flex: 1; min-height: 0;
}

/* Seat slots */
.seat {
    display: flex; align-items: center; justify-content: center;
    flex-direction: column;
}
.seat-left, .seat-right {
    width: 120px; flex-shrink: 0;
    padding: 10px 5px;
    overflow: hidden;
}
.seat-left:empty, .seat-right:empty {
    width: 0; padding: 0; overflow: visible;
}
.seat-center-col {
    flex: 1; display: flex; flex-direction: column; min-width: 0;
}
.seat-top {
    display: flex; justify-content: center; gap: 40px;
    padding: 12px 10px; flex-wrap: wrap;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

/* Opponent slot (used in all seats) */
.opponent-slot {
    text-align: center; transition: all 0.3s;
}
.opponent-slot.active-turn .opponent-name {
    color: var(--warning-color);
    text-shadow: 0 0 10px var(--glow-warning);
}
.opponent-name {
    font-weight: 700; font-size: 0.85rem; margin-bottom: 6px;
    white-space: nowrap;
}
.opponent-cards {
    display: flex; justify-content: center; gap: 1px; flex-wrap: wrap;
}

/* Side seats: cards stacked vertically */
.seat-left .opponent-cards,
.seat-right .opponent-cards {
    flex-direction: column; align-items: center; gap: 0;
}
.seat-left .mini-card-back,
.seat-right .mini-card-back {
    margin-top: -14px;
}
.seat-left .mini-card-back:first-child,
.seat-right .mini-card-back:first-child {
    margin-top: 0;
}

.mini-card-back {
    width: 24px; height: 34px; border-radius: 3px;
    background: linear-gradient(135deg, #8b1a1a, #c0392b);
    border: 1px solid rgba(255,255,255,0.15);
    box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}
.opponent-card-count {
    display: inline-block; margin-top: 6px;
    background: rgba(0,0,0,0.6); border-radius: 10px;
    padding: 2px 8px; font-size: 0.75rem; font-weight: 700;
    color: var(--warning-color);
}

/* ======= TABLE AREA (green felt center) ======= */
.table-area {
    flex: 1; min-height: 180px;
    background: radial-gradient(ellipse at center, #1b6b3a 0%, #0d3018 70%, #0a200f 100%);
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; position: relative;
    box-shadow: inset 0 0 80px rgba(0, 0, 0, 0.6),
                inset 0 0 20px rgba(0, 0, 0, 0.3);
    border: 3px solid #1a3d1a;
    border-radius: 12px;
    margin: 0 5px;
}
.table-center { text-align: center; z-index: 1; }
.last-played-info { text-align: center; }
.last-played-label {
    font-size: 0.9rem; color: rgba(255,255,255,0.6);
    margin-bottom: 10px; display: block;
}
.played-cards-display {
    display: flex; justify-content: center; flex-wrap: wrap;
    min-height: 80px; align-items: center;
}
.played-cards-display .played-card {
    margin-left: -25px;
}
.played-cards-display .played-card:first-child {
    margin-left: 0;
}
.game-state-text {
    margin-top: 10px;
    font-size: 0.8rem; color: rgba(255,255,255,0.4);
    z-index: 1;
}

/* Turn Timer */
.turn-timer {
    position: absolute; top: 12px; right: 12px;
    width: 52px; height: 52px;
}
.timer-ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.timer-ring-bg {
    fill: none; stroke: rgba(255,255,255,0.1); stroke-width: 4;
}
.timer-ring-progress {
    fill: none; stroke: var(--secondary-color); stroke-width: 4;
    stroke-linecap: round;
    stroke-dasharray: 163.36;
    stroke-dashoffset: 0;
    transition: stroke-dashoffset 1s linear, stroke 0.3s;
}
.timer-ring-progress.urgent { stroke: var(--danger-color); }
.timer-number {
    position: absolute; top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1rem; font-weight: 700; color: #fff;
}

/* Table Controls (overlaid on green felt) */
.table-controls {
    margin-top: 15px; z-index: 2; text-align: center;
}
.play-actions {
    display: flex; justify-content: center; gap: 10px;
    align-items: center; flex-wrap: wrap;
}
.turn-hint {
    margin-bottom: 10px; font-size: 0.9rem; color: var(--warning-color);
    min-height: 24px; text-shadow: 0 1px 4px rgba(0,0,0,0.5);
}

/* ======= CARD STYLING ======= */
.playing-card {
    width: 80px; border-radius: 8px;
    position: relative;
    box-shadow: 0 2px 6px rgba(0,0,0,0.35);
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, z-index 0s;
    display: inline-block;
    user-select: none;
    flex-shrink: 0;
    overflow: hidden;
}
.playing-card img {
    display: block; width: calc(100% + 4px); height: auto;
    margin: -2px;
    pointer-events: none;
}

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

.playing-card.selected {
    transform: translateY(-22px);
    border-color: #ffd700;
    box-shadow: 0 0 12px rgba(255, 215, 0, 0.5), 0 6px 20px rgba(0,0,0,0.4);
}
.playing-card.selected:hover {
    transform: translateY(-26px);
}

/* Card in play area */
.played-card {
    width: 70px; border-radius: 8px;
    position: relative;
    box-shadow: 0 3px 10px rgba(0,0,0,0.5);
    display: inline-block;
    flex-shrink: 0;
    overflow: hidden;
}
.played-card img {
    display: block; width: calc(100% + 4px); height: auto;
    margin: -2px;
    pointer-events: none;
}

/* My Hand Area */
.my-hand-area {
    padding: 12px 10px 8px;
    overflow-x: auto; overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    min-height: 0;
}
.hand-cards {
    display: flex; justify-content: center;
    flex-wrap: nowrap;
    min-height: 130px; align-items: flex-end;
    padding: 25px 15px 5px 15px;
    width: max-content;
    min-width: 100%;
    box-sizing: border-box;
}
.hand-cards .playing-card {
    margin-left: -45px;
}
.hand-cards .playing-card:first-child {
    margin-left: 0;
}
.hand-cards .playing-card:hover {
    z-index: 20;
}

/* Hint Bar (below hand) */
.hint-bar {
    padding: 8px 15px 10px;
    text-align: center;
    border-top: 1px solid rgba(255,255,255,0.05);
    background: rgba(0,0,0,0.15);
}
.hint-panel {
    display: flex; gap: 8px; justify-content: center;
    flex-wrap: wrap;
}
.hint-type-btn {
    padding: 8px 20px; border: 2px solid rgba(255,255,255,0.15);
    border-radius: 24px; background: rgba(255,255,255,0.06);
    color: var(--text-primary); cursor: pointer;
    font-size: 0.9rem; font-weight: 700;
    transition: all 0.2s; font-family: inherit;
    min-width: 70px;
}
.hint-type-btn:hover {
    background: rgba(163, 113, 247, 0.15); border-color: var(--info-color);
}
.hint-type-btn.active {
    background: var(--info-color); color: #fff;
    border-color: var(--info-color);
    box-shadow: 0 0 12px rgba(163, 113, 247, 0.5);
}
.hint-type-btn .hint-count {
    font-size: 0.7rem; opacity: 0.6; margin-left: 3px;
}
.hint-cycle-info {
    font-size: 0.8rem; color: var(--text-secondary);
    margin-top: 6px; min-height: 18px;
}

/* Dealing Animation */
@keyframes dealToHand {
    0% {
        transform: translate(var(--deal-from-x, 0px), var(--deal-from-y, -300px)) rotate(-180deg) scale(0.3);
        opacity: 0;
    }
    60% { opacity: 1; }
    100% {
        transform: translate(0, 0) rotate(0deg) scale(1);
        opacity: 1;
    }
}
.deal-animation {
    animation: dealToHand 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    opacity: 0;
}

@keyframes flyToTable {
    0% { transform: translateY(0) scale(1); opacity: 1; }
    100% { transform: translateY(-150px) scale(0.85); opacity: 0.8; }
}
.fly-to-table {
    animation: flyToTable 0.4s ease-out forwards;
}

@keyframes newRoundFlash {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}
.new-round-flash {
    animation: newRoundFlash 0.5s ease 3;
}

/* Players Area (bottom bar) */
.players-area {
    display: flex; padding: 10px 15px; gap: 10px;
    overflow-x: auto; justify-content: center;
    flex-wrap: wrap;
}
.player-card {
    position: relative; min-width: 100px; padding: 10px 12px;
    text-align: center; background: rgba(0, 0, 0, 0.3);
    border-radius: 10px; border: 2px solid transparent;
    transition: all 0.3s;
}
.player-card.active-turn {
    border-color: var(--warning-color);
    box-shadow: 0 0 15px rgba(210, 153, 34, 0.3);
}
.player-card.is-me {
    border-color: var(--primary-color);
    box-shadow: 0 0 10px var(--glow-primary);
}
.player-card.disconnected { opacity: 0.5; filter: grayscale(1); }
.player-card .nickname { font-weight: bold; font-size: 0.85rem; }
.player-card .card-count {
    color: var(--warning-color); font-weight: bold; margin-top: 3px; font-size: 0.8rem;
}
.player-card .status {
    font-size: 0.7rem; margin-top: 3px; color: var(--text-secondary); min-height: 14px;
}
.kick-btn {
    position: absolute; top: -6px; right: -6px;
    width: 22px; height: 22px; padding: 0;
    font-size: 0.7rem; line-height: 22px; border-radius: 50%;
    text-align: center; border: 1px solid var(--panel-border);
    background: var(--danger-color); cursor: pointer;
    opacity: 0.6; transition: opacity 0.2s; color: #fff;
}
.kick-btn:hover { opacity: 1; }

/* Game Log */
.game-log {
    padding: 10px 15px; max-height: 110px;
    overflow-y: auto; font-size: 0.82rem;
}
.game-log ul { list-style: none; padding: 0; margin: 0; }
.game-log li {
    margin-bottom: 3px; border-bottom: 1px solid rgba(255,255,255,0.05);
    padding-bottom: 3px; color: var(--text-secondary);
}

/* Game Over Modal */
.game-over-modal {
    padding: 40px; width: 95%; max-width: 550px;
    max-height: 85vh; overflow-y: auto; text-align: center;
}
.game-over-title {
    color: var(--warning-color); font-size: 2rem; margin-bottom: 20px;
}
.winner-banner {
    background: linear-gradient(135deg, rgba(210,153,34,0.3), rgba(47,129,247,0.2));
    border: 1px solid var(--warning-color); border-radius: 12px;
    padding: 15px 20px; font-size: 1.2rem; margin-bottom: 25px;
    animation: pulseGlow 1.5s infinite alternate;
}
@keyframes pulseGlow {
    from { box-shadow: 0 0 10px rgba(47,129,247,0.2); }
    to { box-shadow: 0 0 25px rgba(210,153,34,0.6); }
}
.leaderboard-table {
    width: 100%; border-collapse: collapse; margin-bottom: 20px; font-size: 0.95rem;
}
.leaderboard-table th {
    background: rgba(255,255,255,0.08); padding: 10px;
    text-align: center; border-bottom: 1px solid var(--panel-border);
    color: var(--text-secondary); text-transform: uppercase; font-size: 0.8rem;
}
.leaderboard-table td {
    padding: 12px 10px; text-align: center;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}
.leaderboard-table tr.winner-row td {
    color: var(--warning-color); font-weight: bold;
    background: rgba(210,153,34,0.1);
}

/* ======= RWD ======= */

@media (max-width: 1024px) {
    .app-container { padding: 10px; }
    .seat-left, .seat-right { width: 100px; }
    .seat-top { gap: 20px; }
}

@media (max-width: 768px) {
    .room-header {
        flex-direction: column; padding: 8px 10px; text-align: center;
    }
    .room-header h2 { font-size: 0.95rem; }

    /* On mobile: stack all opponents at top, hide side seats */
    .table-layout { flex-direction: column; }
    .seat-left, .seat-right { display: none; }
    .seat-top {
        gap: 12px; padding: 10px;
    }
    .mini-card-back { width: 18px; height: 26px; }
    .opponent-name { font-size: 0.8rem; }

    .table-area { min-height: 150px; }

    .playing-card { width: 60px; }
    .playing-card.selected { transform: translateY(-16px); }
    .playing-card.selected:hover { transform: translateY(-18px); }

    .played-card { width: 52px; }

    .hand-cards {
        justify-content: flex-start;
        min-height: 90px; padding: 16px 10px 5px 10px;
    }
    .hand-cards .playing-card { margin-left: -35px; }
    .my-hand-area { padding: 8px 5px; }

    .play-actions { gap: 8px; }
    .btn-lg { padding: 10px 20px; font-size: 1rem; }

    .players-area { gap: 8px; padding: 8px; }
    .player-card { min-width: 85px; padding: 8px; }

    .game-log { max-height: 80px; font-size: 0.78rem; }

    .game-over-modal { padding: 20px; }
    .game-over-title { font-size: 1.5rem; }

    .hint-type-btn { padding: 6px 14px; font-size: 0.82rem; min-width: 55px; }

    .turn-timer { width: 42px; height: 42px; top: 8px; right: 8px; }
    .timer-number { font-size: 0.85rem; }
}

@media (max-width: 480px) {
    .logo-title { font-size: 2.5rem; }
    .login-panel { padding: 25px; }

    .playing-card { width: 48px; }
    .playing-card.selected { transform: translateY(-12px); }

    .played-card { width: 42px; }

    .mini-card-back { width: 14px; height: 20px; }
    .hand-cards { min-height: 75px; }
    .hand-cards .playing-card { margin-left: -28px; }

    .hint-type-btn { padding: 5px 10px; font-size: 0.78rem; min-width: 48px; }
}

/* Bot badge */
.bot-badge {
    display: inline-block; font-size: 0.6rem; padding: 1px 5px;
    background: var(--info-color); color: #fff; border-radius: 4px;
    vertical-align: middle; font-weight: 700; letter-spacing: 0.05em;
}
.bot-tag {
    display: inline-block; font-size: 0.7rem; padding: 2px 6px;
    background: var(--info-color); color: #fff; border-radius: 4px;
    font-weight: 700;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.3); }
