/* Reset */
* { box-sizing: border-box; user-select: none; }
body {
    font-family: 'Segoe UI', Tahoma, sans-serif;
    background-color: #2c3e50;
    color: white;
    margin: 0; 
    height: 100vh; 
    height: 100dvh; 
    overflow: hidden;
    transition: background-color 0.5s;
}
.hidden { display: none !important; }

/* --- LOBBY SCREEN --- */
#lobby {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    height: 100%; padding: 20px;
}
#lobby input, #lobby button {
    padding: 15px; font-size: 1.1rem; margin: 10px 0;
    border-radius: 8px; border: none; width: 100%; max-width: 300px;
}
.btn-player { background: #27ae60; color: white; cursor: pointer; }
.btn-table { background: #d35400; color: white; cursor: pointer; }

/* --- TABLE VIEW LAYOUT (HUD Style) --- */
#game-main-view { 
    position: relative;
    width: 100%;
    /* Use flex-grow instead of height: 100% to prevent pushing footer off screen */
    flex-grow: 1; 
    overflow: hidden;
    display: flex;          
    flex-direction: column;
}

#table-view { 
    width: 100%;
    height: 100%;
    position: relative;
}

/* 1. TRICK AREA */
#trick-area {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0) 70%);
    z-index: 1; 
}
#trick-container { width: 100%; height: 100%; position: relative; }

/* 2. OVERLAY UI */
#table-sidebar {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none; 
    z-index: 50;
    padding: 10px; /* Reduced padding to push HUD elements to edges */
}

/* Player Info (Bottom Left) */
.sidebar-section {
    position: absolute;
    bottom: 10px;
    left: 10px;
    width: 260px; /* Slightly more compact */
    pointer-events: auto; 
}

#player-list { 
    list-style: none; padding: 0; display: flex; flex-direction: column; gap: 5px;
}
#player-list li {
    background: rgba(44, 62, 80, 0.9); 
    padding: 6px 10px; /* Compact padding */
    border-radius: 6px;
    border: 1px solid rgba(255,255,255,0.15); 
    display: flex; 
    justify-content: space-between; 
    align-items: center;
    font-size: 0.85rem; /* Slightly smaller text */
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
    min-height: 35px;
}
#player-list li.turn-active { 
    border-color: #2ecc71; 
    background: rgba(39, 174, 96, 0.3); 
    box-shadow: 0 0 10px rgba(46, 204, 113, 0.3);
}

/* POKER SPECIFIC LIST STYLES */
#player-list li.poker-in-hand {
    border-color: #2ecc71; 
    background: rgba(39, 174, 96, 0.3); 
    box-shadow: 0 0 10px rgba(46, 204, 113, 0.3);
}

#player-list li.poker-folded {
    border-color: #c0392b;
    background: rgba(192, 57, 43, 0.3);
    color: #bdc3c7; /* Dim text color */
}

/* LOBBY / SEATING CONTROLS */
.btn-move {
    background: rgba(255, 255, 255, 0.15) !important;
    color: white !important; 
    border: 1px solid rgba(255,255,255,0.2) !important;
    border-radius: 4px !important;
    width: 25px !important; 
    height: 25px !important; 
    padding: 0 !important; 
    margin: 0 5px !important; 
    font-size: 0.7rem !important;
    cursor: pointer; 
    display: inline-flex; align-items: center; justify-content: center;
    flex-shrink: 0; 
}
.btn-kick {
    background: #c0392b !important;
    color: white !important;
    border: none !important;
    border-radius: 4px !important;
    width: 25px !important;
    height: 25px !important;
    padding: 0 !important;
    margin-left: 8px !important;
    font-size: 0.7rem !important;
    cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}

/* --- BUTTON SYSTEM --- */
/* Base styles for all in-game functional buttons */
#table-controls button, 
#scoreboard-view button { 
    margin: 0; 
    font-size: 1rem; 
    padding: 12px; 
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
    border-radius: 8px; 
    border: none; 
    color: white; 
    cursor: pointer;
    transition: transform 0.1s, background 0.2s;
    position: relative;
    overflow: hidden;
}

#table-controls button:active,
#scoreboard-view button:active {
    transform: translateY(2px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

/* LONG PRESS BUTTON ANIMATION */
button.hold-btn::after {
    content: '';
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 0%;
    background: rgba(255,255,255,0.3);
    transition: width 0s; /* Reset immediately */
}

button.hold-btn.holding::after {
    width: 100%;
    transition: width 0.8s linear; /* Match hold duration */
}


/* Controls Container (Sidebar) */
#table-controls { 
    position: absolute;
    bottom: 10px;
    right: 10px;
    width: 160px;
    pointer-events: auto;
    display: flex; flex-direction: column; gap: 8px; 
}

/* Color Palette */
.btn-deal { background: #2980b9; } 
.btn-deal:hover { background: #3498db; }
.btn-history { background: #8e44ad; }
.btn-history:hover { background: #9b59b6; }
.btn-score { background: #16a085; }
.btn-score:hover { background: #1abc9c; }
.btn-restart { background: #e74c3c; } 
.btn-restart:hover { background: #c0392b; }
.btn-undo { background: #e67e22; }
.btn-undo:hover { background: #d35400; }

/* SPADES BID TRACKER (Top Right HUD) */
.sidebar-top-right {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 250px;
    pointer-events: auto;
    display: flex;
    flex-direction: column;
    gap: 15px; /* Spacing between team boxes */
    z-index: 55;
}

/* Updated Scoreboard Look */
.bid-tracker-box {
    background: rgba(30, 40, 50, 0.95);
    border-radius: 8px;
    padding: 0;
    box-shadow: 0 8px 20px rgba(0,0,0,0.5);
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.1);
    display: flex;
    flex-direction: column;
}

/* Color Coding Bars */
.bid-tracker-box.team-1 { border-left: 8px solid #3498db; } /* Blue Team */
.bid-tracker-box.team-2 { border-left: 8px solid #e67e22; } /* Orange Team */

.tracker-team-name { 
    font-size: 0.75rem; 
    text-transform: uppercase; 
    color: #ecf0f1; 
    background: rgba(255,255,255,0.1);
    padding: 5px 10px;
    font-weight: bold;
    letter-spacing: 1px;
}

.tracker-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
}

/* Split layout for numbers */
.stat-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 1;
}

.stat-label {
    font-size: 0.7rem;
    color: #bdc3c7;
    text-transform: uppercase;
    margin-bottom: 3px;
}

.stat-value {
    font-weight: bold;
    color: white;
}

/* Hierarchy: Tricks Taken is huge, Bid is medium */
.stat-value.taken { font-size: 2.2rem; }
.stat-value.bid { font-size: 1.4rem; color: #95a5a6; }

.divider {
    font-size: 1.5rem;
    color: rgba(255,255,255,0.2);
    margin: 0 10px;
}

.tracker-nil { 
    background: #c0392b;
    color: white;
    font-size: 0.75rem; 
    text-align: center;
    padding: 3px;
    font-weight: bold;
    text-transform: uppercase;
}

/* SETTINGS (Centered Lobby Box) */
#settings-area {
    position: absolute; 
    top: 50%; left: 50%; 
    transform: translate(-50%, -50%);
    width: 400px; 
    padding: 25px; 
    background: rgba(44, 62, 80, 0.98);
    border-radius: 12px; 
    text-align: center; 
    pointer-events: auto;
    box-shadow: 0 20px 50px rgba(0,0,0,0.6); 
    border: 1px solid rgba(255,255,255,0.1);
    z-index: 100;
}
.toggle-container {
    display: flex; align-items: center; gap: 15px; font-size: 1.1rem;
    cursor: pointer; justify-content: center; margin-top: 20px;
    background: rgba(0,0,0,0.2); padding: 10px; border-radius: 8px;
}
#game-selector { display: flex; gap: 15px; justify-content: center; margin-bottom: 20px; }
.game-option { 
    background: #34495e; color: #bdc3c7; 
    cursor: pointer; flex: 1; padding: 15px; 
    border-radius: 8px; border: 2px solid transparent;
    font-size: 1.1rem; font-weight: bold;
}
.game-option.active { 
    background: #2ecc71; color: white; 
    border-color: #27ae60;
}

/* Header & Misc */
#game-area { padding: 0; height: 100%; display: flex; flex-direction: column; }
#header-info { 
    padding: 10px 20px; display: flex; justify-content: space-between; align-items: center; 
    border-bottom: 1px solid rgba(255,255,255,0.2); flex-shrink: 0; background: #2c3e50;
    z-index: 10; /* Ensure header sits above scrolled content if needed */
}
.header-left { display: flex; align-items: center; gap: 15px; }
.btn-hide {
    background: rgba(255, 255, 255, 0.1); border: 1px solid rgba(255, 255, 255, 0.3);
    color: #ecf0f1; padding: 5px 12px; font-size: 0.9rem; cursor: pointer;
    border-radius: 20px; width: auto; margin: 0;
}

/* --- SCOREBOARD --- */
#scoreboard-view {
    text-align: center; display: flex; flex-direction: column;
    align-items: center; justify-content: center; flex-grow: 1; padding: 20px;
}
#scoreboard-view button {
    width: 200px; /* Make results buttons a consistent size */
    margin: 10px;
}
#score-table {
    width: 100%; max-width: 600px; border-collapse: collapse; margin: 20px 0;
    background: rgba(0,0,0,0.2); border-radius: 10px; overflow: hidden;
}
#score-table th, #score-table td {
    padding: 15px; border-bottom: 1px solid rgba(255,255,255,0.1);
    text-align: center; font-size: 1.2rem;
}
#score-table th { background: rgba(0,0,0,0.3); }
.winner-row { background-color: #f1c40f; color: #2c3e50; font-weight: bold; }

/* Overlays */
#last-trick-overlay, #live-score-overlay {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(44, 62, 80, 0.95); border-radius: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 60; 
}
.btn-close-overlay { background: #95a5a6; color: white; width: auto; cursor: pointer; margin-top: 20px; padding: 10px 20px; border: none; border-radius: 5px; font-size: 1rem;}

/* Player Hand (Mobile View) */
#hand-wrapper { 
    position: relative; 
    flex-grow: 1; 
    display: flex; 
    flex-direction: column; 
    overflow: hidden; 
    width: 100%; 
}

#hand-curtain {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: #34495e; z-index: 100; display: flex;
    align-items: center; justify-content: center; cursor: pointer;
}
.curtain-msg { text-align: center; color: white; font-size: 1.5rem; pointer-events: none; animation: pulse 2s infinite; }
@keyframes pulse { 0% { opacity: 1; } 50% { opacity: 0.7; } 100% { opacity: 1; } }

.hand-container {
    display: flex; 
    flex-wrap: wrap; 
    justify-content: center; 
    gap: 10px;
    align-content: flex-start;
    padding: 20px; 
    overflow-y: auto; 
    flex-grow: 1; 
    border-top: 2px solid transparent;
}
.hand-container.active-turn { background: rgba(46, 204, 113, 0.1); border-top: 2px solid #2ecc71; }
.hand-container.bidding-mode .card { width: 18vmin; height: 25vmin; }

/* --- POKER SPECIFIC STYLES --- */

/* The Table View for Poker */
#trick-container.poker-board {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    height: 100%;
    width: 100%;
}

.board-card {
    position: relative !important; /* Override absolute from trick-taking */
    transform: none !important;
    top: auto !important; left: auto !important;
    margin: 0 !important;
    width: 16vmin !important;
    height: 22vmin !important;
    box-shadow: 0 5px 15px rgba(0,0,0,0.5);
}

.fade-in { animation: fadeIn 0.5s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

/* The Hand View for Poker */
.poker-header {
    width: 100%;
    padding: 20px;
    text-align: center;
    font-size: 1.5rem;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
}

.poker-header.in-hand { background: #27ae60; color: white; }
.poker-header.folded { background: #c0392b; color: white; }

#poker-bottom-area {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 40vh; /* Occupy bottom part of screen */
    display: flex;
    align-items: center; /* Vertically center cards in this area */
    justify-content: center; /* Horizontally center cards */
    pointer-events: none; /* Let clicks pass through empty space */
    padding-bottom: 20px;
}

#poker-card-area {
    display: flex;
    justify-content: center;
    gap: 20px;
    pointer-events: auto;
}

.card.hole-card {
    width: 25vmin;
    height: 35vmin;
    border: 2px solid rgba(255,255,255,0.1);
    box-shadow: 0 10px 20px rgba(0,0,0,0.4);
}

.card.face-down {
    background-color: #34495e; /* Fallback if image fails */
    border: 5px solid white;
}

#peek-btn {
    position: absolute;
    right: 30px;
    bottom: 30px;
    width: 150px;
    height: 150px;
    border-radius: 50%;
    font-size: 1.2rem;
    font-weight: bold;
    background: #f1c40f;
    color: #2c3e50;
    border: none;
    box-shadow: 0 5px 0 #d35400, 0 10px 10px rgba(0,0,0,0.3);
    touch-action: none;
    pointer-events: auto;
}
#peek-btn:active {
    transform: translateY(5px);
    box-shadow: none;
    background: #f39c12;
}
#peek-btn:disabled {
    background: #95a5a6;
    box-shadow: none;
}

#poker-fold-btn {
    background: transparent;
    border: 2px solid white;
    color: white;
    padding: 5px 15px;
    border-radius: 5px;
    font-size: 1rem;
    cursor: pointer;
}


/* --- UPDATED BIDDING UI: THE WHEEL --- */

#bidding-area {
    width: 100%; 
    background: #2c3e50; 
    padding: 10px 10px; /* Reduced vertical padding */
    z-index: 50; 
    border-top: 2px solid rgba(255,255,255,0.2);
    flex-shrink: 0; 
    box-shadow: 0 -5px 15px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.wheel-interface {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    width: 100%;
    max-width: 500px;
}

/* The Wheel Container (Window) */
.wheel-wrapper {
    position: relative;
    width: 120px;
    height: 150px; /* Shows ~3 items at 50px each */
    background: #34495e;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: inset 0 0 20px rgba(0,0,0,0.5);
    border: 1px solid rgba(255,255,255,0.1);
}

/* The Selection Overlay (Green Lines) */
.wheel-selection-overlay {
    position: absolute;
    top: 50%;
    left: 0;
    width: 100%;
    height: 50px; /* Matches wheel-item height */
    transform: translateY(-50%);
    border-top: 2px solid #2ecc71;
    border-bottom: 2px solid #2ecc71;
    background: rgba(46, 204, 113, 0.1);
    pointer-events: none; /* Let clicks pass through */
    z-index: 10;
}

/* The Scrolling List */
.bid-wheel {
    height: 100%;
    overflow-y: scroll;
    scroll-snap-type: y mandatory;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none;  /* IE */
    display: flex;
    flex-direction: column;
    padding-top: 50px;    /* Half height padding to center first item */
    padding-bottom: 50px; /* Half height padding to center last item */
}

/* Hide Scrollbar Webkit */
.bid-wheel::-webkit-scrollbar { 
    display: none; 
}

/* Individual Wheel Items */
.wheel-item {
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    font-weight: bold;
    color: #bdc3c7;
    scroll-snap-align: center;
    transition: color 0.2s, transform 0.2s;
    cursor: pointer;
    flex-shrink: 0;
}

/* Highlighted state controlled by JS intersection or just visual proximity */
.wheel-item.active {
    color: white;
    transform: scale(1.2);
}

/* Confirm Button Area */
#bid-confirm-area {
    flex-grow: 1;
    display: flex;
    justify-content: center;
}

.btn-confirm-bid {
    width: 100%;
    padding: 20px;
    font-size: 1.2rem;
    font-weight: bold;
    border-radius: 8px;
    border: none;
    background: #27ae60;
    color: white;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    text-transform: uppercase;
    letter-spacing: 1px;
}
.btn-confirm-bid:disabled {
    background: #95a5a6;
    cursor: not-allowed;
    opacity: 0.6;
}
.btn-confirm-bid:not(:disabled):active {
    transform: scale(0.98);
}

#hand-actions {
    width: 100%; padding: 10px; text-align: center; flex-shrink: 0;
    background: rgba(0,0,0,0.2); border-top: 1px solid rgba(255,255,255,0.1);
    z-index: 50; /* Ensure it stays above content if needed */
}
.btn-pass { padding: 15px; width: 100%; max-width: 300px; border-radius: 8px; border: none; font-size: 1.1rem; }
.btn-pass:disabled { background: #7f8c8d; color: white; cursor: not-allowed; }
.btn-pass.active { background: #e67e22; cursor: pointer; }


/* --- CARD STYLES (SVG Implementation) --- */
.card {
    background-color: transparent; 
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain; 
    width: 14vmin; 
    height: 20vmin; 
    border-radius: 1vmin;
    box-shadow: 0.5vmin 0.5vmin 1vmin rgba(0,0,0,0.5);
    position: relative; 
    transition: transform 0.3s;
}

/* CHANGED: Increased card size to better fill the screen */
.hand-container .card { 
    width: 22vmin; 
    height: 30vmin; 
    margin: 0; 
}

.hand-container .card:hover { transform: translateY(-10px); }
.hand-container .card.selected { transform: translateY(-15px); border: 0.6vmin solid #f1c40f; border-radius: 1.2vmin; }

/* --- DISABLED CARD STYLE --- */
.card.disabled { 
    opacity: 0.5; /* Keeps shading without losing color */
    cursor: default;
    filter: brightness(0.7); /* Optional: makes it slightly darker instead of grey */
}

/* --- TABLE CARD OVERRIDES --- */
#trick-container .card, #last-trick-container .card {
    position: absolute;
    top: 50%; /* Center vertically exactly */
    left: 50%; /* Center horizontally exactly */
    margin: 0; 
    transform-origin: center center;
    
    /* MAXIMIZED CARDS FOR COMMUNITY TABLET */
    width: 24vmin; 
    height: 32vmin;
    
    box-shadow: 0 10px 20px rgba(0,0,0,0.5);
}
.card-owner { 
    font-size: 0.8rem; font-weight: bold;
    color: white; text-shadow: 0 0 3px black, 0 0 3px black;
    margin-top: 0; text-transform: uppercase; 
    position: absolute; bottom: -1.5rem; width: 100%; text-align: center; white-space: nowrap; overflow: hidden;
}

/* Card Positions */
#trick-container .card.pos-0, #last-trick-container .card.pos-0 { 
    /* Bottom Player */
    transform: translate(-50%, -50%) translateY(29vmin); z-index: 10; 
}
#trick-container .card.pos-1, #last-trick-container .card.pos-1 { 
    /* Left Player */
    transform: translate(-50%, -50%) translateX(-29vmin) rotate(90deg); z-index: 9; 
}    
#trick-container .card.pos-2, #last-trick-container .card.pos-2 { 
    /* Top Player */
    transform: translate(-50%, -50%) translateY(-29vmin) rotate(180deg); z-index: 8; 
}    
#trick-container .card.pos-3, #last-trick-container .card.pos-3 { 
    /* Right Player */
    transform: translate(-50%, -50%) translateX(29vmin) rotate(-90deg); z-index: 9; 
}   

/* Overlay Markers (Swap, etc) */
.card.received-pass { border: 0.4vmin solid #3498db; border-radius: 1.2vmin; }
.swap-marker { 
    position: absolute; 
    top: -5px; right: -5px; 
    font-size: 1.2rem; 
    color: #3498db; 
    background: white;
    border-radius: 50%;
    width: 20px; height: 20px;
    display: flex; align-items: center; justify-content: center;
    font-weight: bold; 
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.card.playable { cursor: pointer; } 
/* The disabled class style is handled above now */

/* BIDDING DASHBOARD Overlay */
.bidding-status {
    position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%);
    text-align: center; background: rgba(44, 62, 80, 0.95); padding: 20px 40px;
    border-radius: 15px; border: 2px solid rgba(255,255,255,0.1);
    box-shadow: 0 10px 30px rgba(0,0,0,0.5); color: white; min-width: 250px; z-index: 20;
}
.bid-title { font-size: 1rem; text-transform: uppercase; letter-spacing: 2px; opacity: 0.7; margin-bottom: 5px; }
.bid-total { font-size: 3.5rem; font-weight: bold; color: #e67e22; line-height: 1; margin-bottom: 5px; }
.bid-remaining { font-size: 1.2rem; color: #bdc3c7; }

.lobby-tabs {
    display: flex; gap: 10px; margin-bottom: 20px; width: 100%; max-width: 300px;
}
.lobby-tabs button {
    flex: 1; padding: 10px; cursor: pointer; background: #34495e; color: #bdc3c7; border: none; border-bottom: 2px solid transparent;
}
.lobby-tabs button.active {
    background: transparent; color: white; border-bottom: 2px solid #2ecc71; font-weight: bold;
}
#big-room-code {
    font-family: monospace; font-size: 2rem; letter-spacing: 5px; background: rgba(0,0,0,0.3); padding: 5px 15px; border-radius: 5px;
}
#join-section, #host-section { width: 100%; display: flex; flex-direction: column; align-items: center; }