/* --- EARTH TONE PALETTE & FONTS --- */
:root {
    --color-background: #2a2a2a; /* Dark wood/charcoal */
    --color-table: #0a3d1e; /* Deep, desaturated felt green */
    --color-border: #4a3c2a; /* Dark wood brown */
    --color-text: #e0d8c7; /* Cream/beige */
    --color-gold: #bca46c; /* Muted gold */
    --color-button: #6d2121; /* Deep maroon */
    --color-button-hover: #8e2b2b;
    --font-title: 'Playfair Display', serif;
    --font-body: 'Lora', serif;
}

body {
    font-family: var(--font-body);
    background-color: var(--color-background);
    color: var(--color-text);
    margin: 0;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    box-sizing: border-box;
    background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAAAXNSR0IArs4c6QAAARlJREFUaAXt0KENwjAQRFFbUTsR3cEK1IIN2IIl2IItWIEVmIEV2IAd2IEdOIJzkxkkJe+8p907/A8gQ/I8SRL5kABg2M459z8AIiACKpB/AQgA9vPnRhgAAIA9zCgACIAIVAAbfyoACIAIVAAbeAYAgSMgAipwT0wACEAECtCTWgAIUIACdCcjASEACEAAHMmJAAIQgADmSSkAAUCAAnQmIwEhAAhAABzJiQAClD/g/frr3g5Afs95zzOSgAAA+Jy/P/o7gH/ZjwCMgAiowC8/B+AZEAAAAAIgAlVABt4BACAERECF7okJAAIQgQJ0pzUBIECBCtCdjASEACEAAHCkJwIQgAAEUC+lAAQIUICeTEZgLwBCgR/cN8oK1X7tAAAAAElFTkSuQmCC');
    position: relative; 
    overflow-x: hidden;
    overflow-y: auto;
}

.game-container {
    width: 100%;
    max-width: 900px;
    margin: auto;
    z-index: 10; 
    position: relative;
}

/* --- BACKGROUND CARDS (NEW) --- */
.background-cards {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 1;
    pointer-events: none;
}
.card-bg {
    position: absolute;
    width: 160px;
    height: 230px;
    background-color: rgba(224, 216, 199, 0.05); /* Faint beige */
    border: 1px solid rgba(188, 164, 108, 0.1);
    border-radius: 10px;
    padding: 10px;
    box-sizing: border-box;
    opacity: 0.5; /* Opacity on the parent */
}
.card-bg-content {
    font-family: var(--font-body);
    color: rgba(188, 164, 108, 0.2);
    text-align: left;
}
.card-bg-content h3 {
    font-family: var(--font-title);
    font-size: 1em;
    margin: 0 0 10px 0;
    border-bottom: 1px solid rgba(188, 164, 108, 0.2);
}
.card-bg-content p {
    font-size: 0.8em;
    margin: 4px 0;
}
.card-bg-1 { top: 10%; left: 15%; transform: rotate(-15deg); }
.card-bg-2 { bottom: 12%; left: 25%; transform: rotate(8deg); }
.card-bg-3 { top: 20%; right: 20%; transform: rotate(20deg); }
.card-bg-4 { bottom: 5%; right: 10%; transform: rotate(-10deg); }


/* --- POKER TABLE & LOBBY --- */
.poker-table {
    background-color: var(--color-table);
    border: 15px solid var(--color-border);
    border-radius: 50px;
    padding: 40px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), inset 0 0 15px rgba(0,0,0,0.5);
    text-align: center;
}
.poker-table h1 {
    font-family: var(--font-title);
    color: var(--color-gold);
    font-size: 2.5em;
    margin-bottom: 30px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.6);
}
/* Leaderboard specific tweaks */
.leaderboard-table tbody tr.faded {
    opacity: 0.5;
}
#lobby-view .lobby-menu {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

#main-menu {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px; /* This creates the uniform vertical spacing */
    width: 100%;
}

#lobby-view input, #lobby-view button {
    width: 100%;
    max-width: 300px;
    box-sizing: border-box;
    padding: 12px;
    border-radius: 8px;
    border: 2px solid var(--color-gold);
    font-size: 1em;
    font-family: var(--font-body);
}
#lobby-view select {
    width: 100%;
    max-width: 300px;
    box-sizing: border-box;
    padding: 12px;
    border-radius: 8px;
    border: 2px solid var(--color-gold);
    font-size: 1em;
    font-family: var(--font-body);
    background-color: rgba(0, 0, 0, 0.3);
    color: var(--color-text);
    /* avoid iOS/Android oversized native styles */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="20" height="20" fill="%23bca46c"><path d="M7 10l5 5 5-5z"/></svg>');
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 36px;
}
#lobby-view input {
    background-color: rgba(0, 0, 0, 0.3);
    color: var(--color-text);
    text-align: center;
}
#lobby-view button {
    background-color: var(--color-button);
    color: var(--color-text);
    cursor: pointer;
    font-weight: 600;
    transition: background-color 0.3s, transform 0.2s;
}
#lobby-view button:hover {
    background-color: var(--color-button-hover);
    transform: translateY(-2px);
}
#lobby-view button:disabled {
    background-color: #555;
    cursor: not-allowed;
    transform: none;
}
#lobby-view .join-group {
    display: flex;
    gap: 10px;
    width: 100%;
    max-width: 300px;
    justify-content: center;
}
#lobby-view .create-options { width: 100%; max-width: 300px; }
.create-title { color: var(--color-gold); font-weight: 700; margin-bottom: 6px; }
.create-row { display: flex; gap: 10px; justify-content: center; }
.create-row > button, .create-row > .ai-group, .create-row > .friend-group { flex: 1; }
.create-row > button { width: 100%; }
.ai-group { position: relative; display: inline-block; }
.ai-group > button { width: 100%; }
.friend-group { position: relative; display: inline-block; }
.friend-group > button { width: 100%; }
.ai-submenu { position: absolute; top: 110%; left: 0; background: rgba(0,0,0,0.7); border: 2px solid var(--color-gold); padding: 8px; border-radius: 8px; display: flex; flex-direction: column; gap: 6px; width: max-content; }
.ai-submenu button { width: 160px; }
#lobby-view .join-group #game-code-input { width: 60%; }
#lobby-view .join-group #join-game-btn { width: 40%; }
#game-code-display { margin-top: 15px; }
#game-code-text {
    background-color: rgba(0,0,0,0.3);
    padding: 10px;
    border-radius: 5px;
    font-size: 1.5em;
    font-weight: bold;
    letter-spacing: 3px;
    color: #a3b9a3;
    margin-top: 10px;
}
.error-text { color: #ff8a8a; margin-top: 10px; height: 1em; }

/* --- GAME VIEW STYLING --- */
#game-view { display: none; max-width: 500px; margin: auto; }
.game-header { display: flex; justify-content: space-between; margin-bottom: 15px; font-weight: 600; }
.my-card-area, .opponent-card-area { display: flex; justify-content: center; align-items: center; min-height: 280px; }
.opponent-card-area { gap: 10px; flex-wrap: wrap; }
.opponent-card-area .card.back { width: 120px; height: 160px; }
.card {
    background: var(--color-text);
    color: #333;
    border-radius: 10px;
    padding: 15px;
    width: 250px;
    height: auto;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    border: 5px solid var(--color-gold);
    transition: transform 0.3s, box-shadow 0.3s;
}
.card.back { background-color: var(--color-button); border-color: var(--color-border); }
.card-header { text-align: center; border-bottom: 2px solid #ddd; margin-bottom: 10px; padding-bottom: 5px; }
.card-header h3 { margin: 0; font-family: var(--font-title); font-size: 1.2em; }
.card-header p { margin: 5px 0 0; font-size: 0.8em; color: #666; }
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { display: flex; justify-content: space-between; padding: 5px; border-radius: 4px; }
.stat-label { font-weight: 600; font-size: 0.9em;}
.stat-value { font-weight: bold; }
.stat.clickable { cursor: pointer; background-color: #e3f2fd; transition: background-color 0.2s; }
.stat.clickable:hover { background-color: #bbdefb; }
#turn-indicator { text-align: center; font-size: 1.2em; font-weight: bold; margin: 15px 0; min-height: 1.5em; }
.game-controls { text-align: center; margin-top: 15px; }
.game-controls .end-button { margin-left: 8px; }
.game-controls .end-button:hover { background-color: inherit; }

/* Comparison Area */
.comparison-area { padding: 10px; margin: 15px 0; text-align: center; min-height: 60px; }
.comparison-result strong { font-family: var(--font-title); font-size: 1.3em; color: var(--color-gold);}
.player-value h3 { font-size: 1.8em; margin: 5px 0; }
.player-value p { margin: 0; font-size: 0.9em; opacity: 0.8; }
.winner { color: #a3b9a3; }
.loser { color: #ff8a8a; }
.draw { color: var(--color-text); }

/* --- 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 {
    background: var(--color-border); padding: 30px; border-radius: 15px;
    text-align: center; border: 5px solid var(--color-gold);
    box-shadow: 0 5px 25px rgba(0,0,0,0.5);
}
.modal-content h2 { margin-top: 0; font-family: var(--font-title); }
.hidden { display: none !important; }

/* --- RESPONSIVE DESIGN --- */
/* Floating community link */
.community-link {
    position: fixed;
    left: 50%;
    bottom: 14px;
    transform: translateX(-50%);
    z-index: 1100;
    background: var(--color-button);
    color: var(--color-text);
    border: 2px solid var(--color-gold);
    border-radius: 20px;
    padding: 8px 12px;
    font-family: var(--font-body);
    text-decoration: none;
    font-weight: 600;
    box-shadow: 0 4px 10px rgba(0,0,0,0.4);
}
.community-link:hover { background: var(--color-button-hover); }

/* Top variant for pages where we want it at the top */
.community-link-top {
    top: 14px;
    bottom: auto;
}

/* Hide opponent face-down placeholder cards */
.opponent-card-area .card.back {
    display: none;
}

@media (max-width: 600px) {
    .community-link { bottom: max(12px, calc(env(safe-area-inset-bottom) + 8px)); }
    body { 
        padding: 10px; 
        /* Allow vertical scroll on mobile to avoid clipped bottom */
        overflow-y: auto; 
        overflow-x: hidden;
        min-height: 100dvh;
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
    .card-bg { display: none; } /* Hide background cards on small screens */
    .poker-table { padding: 16px; border-width: 10px; }
    .poker-table h1 { font-size: 1.6em; margin-bottom: 16px; }
    #lobby-view .join-group { flex-direction: column; }
    #lobby-view .join-group #game-code-input, #lobby-view .join-group #join-game-btn { width: 100%; }
    
    #game-view {
        display: none;
        /* Use dynamic viewport height on mobile browsers */
        min-height: calc(100dvh - 40px);
        display: flex;
        flex-direction: column;
    }
    .game-container { padding-bottom: max(20px, env(safe-area-inset-bottom)); }
    /* Shrink the opponent card area to reclaim space */
    .opponent-card-area { min-height: 120px; }
    .opponent-card-area .card.back { width: 90px; height: 120px; border-width: 3px; }
    .my-card-area { flex: 1; min-height: 0; margin-bottom: 8px; }
    .card { width: 92%; max-width: 300px; padding: 10px; }
    .stats-grid { gap: 5px; }
    .stat { padding: 3px; }
    /* Make header easier to read and bring it away from the very top */
    .game-header { font-size: 1.05em; margin-bottom: 10px; }
    .pot-info { font-weight: 600; }
    #turn-indicator { margin: 10px 0; }
    .comparison-area { margin: 10px 0; }
}

