/* ========================================= */
/* === 1. VARIABLES & RESET              === */
/* ========================================= */
:root {

    html,
    body {
        margin: 0;
        padding: 0;
        width: 100%;
        height: 100%;
        overflow: hidden;
        /* Prevents scroll bounce */
        overscroll-behavior: none;
        /* Disables Pull-to-Refresh */
        touch-action: none;
        /* Disables browser zooming/panning gestures */
        user-select: none;
        /* Disables text highlighting on tap */
        -webkit-user-select: none;
        font-family: var(--font-body);
        background-color: var(--bg-color);
    }

    /* Re-enable scrolling for specific panels if needed */
    .scrollable-content {
        overflow-y: auto;
        touch-action: pan-y;
        /* Allow vertical scroll only here */
    }

    /* Ensure Animations work */
    .flying-card {
        position: fixed;
        z-index: 9999;
        pointer-events: none;
        transition: transform 0.6s ease-in-out, opacity 0.3s ease;
        box-shadow: 0 10px 20px rgba(0, 0, 0, 0.5);
    }

    --card-w: 50px;
    --card-h: 70px;

    /* COLORS SAMPLED FROM LOGO & CARDS */
    --bg-color: #1a252f;
    /* Deep Navy (Spade Background) */
    --accent-color: #f1c40f;
    /* Master Club Gold */
    --accent-dark: #d4ac0d;
    --rose-red: #c0392b;
    /* Rose Red */
    --stone-grey: #7f8c8d;
    /* Spade Stone Grey */
    --surface-dark: rgba(0, 0, 0, 0.6);

    /* TYPOGRAPHY */
    --font-title: 'Cinzel',
    serif;
    /* Formal Branding */
    --font-body: 'Roboto',
    sans-serif;
    /* High Readability */
    --text-primary: #f4f7f6;
    /* Soft, non-flashy white */
    --text-secondary: #bdc3c7;
    /* Muted silver for labels */
    --card-brightness: 0.92;
    /* Global brightness control for cards */
}

.card-img {
    /* ... existing properties ... */
    filter: brightness(var(--card-brightness));
    /* Mutes the white face of the cards */
    background: var(--text-primary);
    /* Soft white background for card containers */
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    /* Handle iPhone Notch/Dynamic Island */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);

    font-family: var(--font-body);
    background: var(--bg-color);
    color: white;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    /* Mobile Fallback */
    overflow: hidden;

    /* Prevent user selecting text (looks like a website if they do) */
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    /* Remove blue tap box on Android */
}

/* ========================================= */
/* === 2. SCREENS & MENUS                === */
/* ========================================= */
.feature-pills {
    display: flex;
    flex-wrap: wrap;
    /* Allow wrapping if screen is very narrow */
    justify-content: center;
    gap: 10px;
    margin-top: 10px;
}

.feature-pills span {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(241, 196, 15, 0.3);
    /* Subtle Gold Border */
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: bold;
    letter-spacing: 1px;
    padding: 6px 12px;
    border-radius: 20px;
    /* Pill shape */
    white-space: nowrap;
    /* PREVENTS "2/4 \n PLAYER" WRAPPING */
    text-transform: uppercase;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.landing-action-grid {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
}

.app-screen {
    display: none !important;
    height: 100%;
    width: 100%;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 0;
    left: 0;
    background: var(--bg-color);
    transition: opacity 0.3s;
    z-index: 10;
}

.logo-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    width: 100%;
    margin-bottom: 20px;

    /* 1. Control the spacing between ALL items (logo, h1, h2) */
    gap: 5px;
}

/* 2. Remove default browser margins that push headings apart */
.logo-area h1,
.logo-area h2 {
    margin: 0;
    padding: 0;
    line-height: 1.1;
    /* Optional: tightens the vertical space of the letters themselves */
}

/* 3. If you want the logo image to have more space than the text: */
.logo-area img {
    margin-bottom: 10px;
}

.active-screen {
    display: flex !important;
    z-index: 20;
}

.game-bg {
    background: var(--bg-color);
}

.logo {
    font-family: var(--font-title);
    font-size: 48px;
    /* Slightly bigger */
    font-weight: 900;
    color: var(--accent-color);
    text-shadow: 2px 2px 0px #000, 0 0 15px rgba(241, 196, 15, 0.3);
    /* Gold Glow */
    letter-spacing: 2px;
    margin-bottom: 5px;
}

h2 {
    font-family: var(--font-title);
    color: var(--accent-color);
    letter-spacing: 1px;
    border-bottom: 2px solid rgba(241, 196, 15, 0.2);
    padding-bottom: 10px;
    margin-bottom: 20px;
}

.logo-sub {
    font-size: 14px;
    color: #bdc3c7;
    margin-bottom: 40px;
}

/* style.css - BUTTONS SECTION */

.menu-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    /* Create 2 columns */
    gap: 12px;
    width: 100%;
    max-width: 340px;
    /* Constrain width on tablets */
    margin: 30px auto 0 auto;
    padding: 0 15px;
    /* Ensure buttons don't touch screen edges */
}

.menu-list>button:nth-child(1),
.menu-list>button:nth-child(2) {
    grid-column: span 2;
}

.menu-btn {
    width: 100%;
    /* Fluid width to fit the grid cell */
    height: 50px;
    padding: 0 5px;
    /* Tighter padding for side-by-side buttons */
    margin: 0;

    font-family: var(--font-title);
    font-size: 14px;
    /* Slightly smaller text for mobile grid */
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;

    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;

    white-space: nowrap;
    /* Prevent text wrapping */
    overflow: hidden;
    text-overflow: ellipsis;
}

.menu-btn.primary {
    background: linear-gradient(135deg, #f1c40f 0%, #d4ac0d 100%) !important;
    box-shadow: 0 0 20px rgba(241, 196, 15, 0.4);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.menu-btn.primary:hover {
    box-shadow: 0 0 35px rgba(241, 196, 15, 0.6);
    transform: scale(1.05) translateY(-3px);
}

.menu-btn.secondary {
    background: transparent;
    color: var(--accent-color);
    border: 1px solid var(--accent-color);
    /* Outlined Gold */
}

.menu-btn.secondary:hover {
    background: rgba(241, 196, 15, 0.15);
}

/* Pause Menu - Leave Game Button */
.menu-btn.danger {
    background: var(--rose-red);
    color: var(--text-primary);
    border: 1px solid #962d22;
}

.menu-btn.text-only {
    background: transparent;
    color: var(--stone-grey);
    /* Updated from #bdc3c7 to match your logo grey */
    box-shadow: none;
    border: none;
    /* Ensures no ghost borders appear */
}

/* Keep this exactly as is for the "click" effect */
.menu-btn:active {
    transform: scale(0.95);
}

/* ========================================= */
/* === 3. GAME GRID (MOBILE DEFAULT)     === */
/* ========================================= */
#game-ui {
    width: 100%;
    height: 100%;
}

#game-grid {
    display: grid;
    height: 100%;
    width: 100%;
    /* Mobile: 5 Rows */
    grid-template-columns: 5px 1fr 5px;
    grid-template-rows: 25px 30px 1fr 30px 110px;
    grid-template-areas:
        "top-info   top-info   top-info"
        "timer-top  timer-top  timer-top"
        "side-left  table      side-right"
        "timer-bot  timer-bot  timer-bot"
        "player     player     player";
}

/* Timer Backgrounds (Hidden by default based on latest preference) */
.timer-row {
    background: transparent !important;
    border: none !important;
    z-index: 1;
}

#timers-top {
    grid-area: timer-top;
}

#timers-bottom {
    grid-area: timer-bot;
}

/* ========================================= */
/* === 4. ZONES & CONTAINERS             === */
/* ========================================= */
.side-zone {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: visible !important;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: transparent !important;
    z-index: 2;
    border: none !important;
}

#hand-left-zone {
    grid-area: side-left;
    align-items: flex-start !important;
}

#hand-right-zone {
    grid-area: side-right;
    align-items: flex-end !important;
}

#partner-zone {
    grid-area: top-info;
    background: transparent !important;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    position: relative;
    overflow: visible;
    padding-bottom: 20px;
}

#table-zone {
    grid-area: table;
    position: relative;
    padding: 1px 0;
    overflow: hidden !important;
    display: grid;
    flex-direction: column;
    justify-content: center;
    gap: 10px;
    min-width: 0;
    /* Prevents grid blowout */
    width: 100%;
    /* Ensures it stays within the 1fr track */
    grid-template-rows: 1fr auto 1fr;
}

#my-zone {
    grid-area: player;
    background: transparent !important;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 10px;
    position: relative;
    z-index: 5;
}

/* ========================================= */
/* === 5. HUD ELEMENTS                   === */
/* ========================================= */
#hud-left,
#hud-right,
#hud-partner,
#hud-me {
    display: flex;
    align-items: center;
    gap: 6px;
    position: relative;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
}

/* Mobile HUD Positioning */
#hud-left {
    grid-area: timer-top;
    justify-self: start;
    z-index: 10;
    margin-left: 5px;
}

#hud-partner {
    grid-area: timer-top;
    justify-self: center;
    z-index: 10;
}

#hud-right {
    grid-area: timer-top;
    justify-self: end;
    z-index: 10;
    margin-right: 5px;
    flex-direction: row-reverse;
}

#hud-me {
    grid-area: timer-bot;
    justify-self: center;
    z-index: 10;
}

.player-hud {
    background: rgba(26, 37, 47, 0.9);
    /* Matching Navy background */
    border: 1px solid var(--stone-grey);
    /* Stone Grey border */
    border-radius: 4px;
    padding: 5px 10px;
}

.hud-name {
    color: var(--accent-color) !important;
    /* Gold Names */
    font-family: var(--font-title);
    font-weight: 900;
}

.timer-text {
    font-family: var(--font-body);
    font-weight: bold;
    color: var(--text-primary);
    /* Clean white timers */
}

.status-light {
    width: 15px;
    /* Give it size! */
    height: 15px;
    /* Give it size! */
    border-radius: 50%;
    /* Make it a circle */
    background-color: #e74c3c;
    /* RED (Not your turn) */
    border: 2px solid rgba(0, 0, 0, 0.3);
    /* Subtle border for depth */
    box-shadow: inset 0 0 3px rgba(0, 0, 0, 0.5);
    /* Inner shadow for "bulb" look */
    transition: all 0.3s ease;
    flex-shrink: 0;
    /* Prevent it from getting squished in flexbox */
    display: inline-block;
    /* Ensure it sits correctly */
}

.status-light.active {
    background-color: #2ecc71 !important;
    /* GREEN (Your turn) */
    box-shadow: 0 0 10px #2ecc71, inset 0 0 2px rgba(255, 255, 255, 0.5);
    /* Glow effect */
    border-color: #27ae60;
    transform: scale(1.1);
    /* Slight pop when active */
}

.hud-name,
.timer-text {
    font-family: 'Segoe UI', sans-serif !important;
    font-size: 14px !important;
    font-weight: bold !important;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.9) !important;
    color: var(--text-primary);
    line-height: 1.2 !important;
}

.hud-name {
    color: #f1c40f !important;
    text-transform: uppercase;
    max-width: none !important;
}

/* ========================================= */
/* === 6. CARDS & PILES                  === */
/* ========================================= */
.card-img {
    width: var(--card-w);
    height: var(--card-h);
    border-radius: 4px;
    box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.3);
    background: white;
}

/* Containers */
.vert-hand-container {
    display: flex;
    flex-direction: column;
    justify-content: center;
    height: 100%;
    width: 100%;
    overflow: visible !important;
    position: relative;
}

.horiz-hand-container {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
}

/* Mobile Side Hands Push */
#hand-left {
    align-items: flex-start;
    transform: translateX(-30px);
    padding: 0;
    width: 100%;
}

#hand-right {
    align-items: flex-end;
    transform: translateX(30px);
    padding: 0;
    width: 100%;
}

.side-card {
    width: var(--card-w);
    height: var(--card-h);
    background-image: url('cards/BackRed.png');
    background-size: cover;
    border-radius: 4px;
    border: 1px solid #111;
    transform: rotate(90deg);
    box-shadow: -2px 2px 5px rgba(0, 0, 0, 0.4);
    flex-shrink: 0;
}

.partner-card {
    width: var(--card-w);
    height: var(--card-h);
    background-image: url('cards/BackRed.png');
    background-size: cover;
    border-radius: 4px;
    border: 1px solid #111;
}

/* My Hand */
#my-hand {
    display: flex;
    width: 100%;
    height: 100%;
    align-items: flex-start !important;
    justify-content: center;
    padding: 15px 5px 0 5px;
    overflow: visible !important;
    z-index: 50;
}

.hand-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    min-width: var(--card-w);
    transition: margin 0.3s ease;
}

.hand-card-wrap {
    width: var(--card-w);
    height: var(--card-h);
    position: relative;
    transition: margin 0.2s, transform 0.1s;
}

.hand-card-wrap.selected::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 253, 208, 0.4);
    border: 2px solid #f1c40f;
    border-radius: 4px;
    pointer-events: none;
}

.hand-card-wrap img {
    width: 100%;
    height: 100%;
    border-radius: 4px;
}

/* Melds */
.meld-row {
    display: flex;
    flex-direction: row;
    overflow: visible !important;
    padding: 0 5px;
    width: 100vw;
    flex-wrap: nowrap !important;
    justify-content: flex-start !important;
    padding-left: 5px;
    align-items: flex-start !important;
    height: 160px !important;
    min-height: 160px !important;
    max-height: 160px !important;
    margin: 0 !important;
    position: relative;
}

.meld-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: var(--card-w);
    margin-right: 8px;
    flex-shrink: 0;
    transition: margin 0.2s ease;
    /* Smooth squeeze animation */
    max-height: 150px;
    overflow: visible;
    position: relative;
}

.meld-label {
    font-size: 9px;
    font-weight: bold;
    text-shadow: 1px 1px 1px black;
    margin-bottom: 2px;
    color: #bdc3c7;
}

/* Center Strip */
.pile-area {
    display: flex;
    width: 100%;
    height: 75px;
    margin: 5px 0;
    padding: 0 5px;
    overflow: visible;
}

.score-group,
.piles-group {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
}

.score-group {
    flex: 0.7;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding-left: 10px;
    padding-top: max(10px, env(safe-area-inset-top));
    margin-right: 5px;
    color: #f1c40f;
    font-weight: bold;
    font-size: 12px;
}

.piles-group {
    flex: 1.3;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 5px;
    padding-left: 0;
}

/* Discard & Draw */
#discard-area,
#draw-area {
    position: relative;
    width: var(--card-w);
    height: var(--card-h);
    cursor: pointer;
}

#discard-display {
    width: 100%;
    height: 100%;
    position: relative;
}

.discard-stack-card {
    position: absolute;
    top: 0;
    left: 0;
    width: var(--card-w);
    height: var(--card-h);
    border-radius: 4px;
    box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s ease-out;
    z-index: 5;
}

.discard-base-card {
    z-index: 1;
}

.frozen-rotated-top {
    transform: translateX(20px) rotate(-90deg);
    z-index: 20;
    /* Shadow shifted to positive 2px to fall on the right side */
    box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.4);
}

.discard-empty-slot {
    width: var(--card-w);
    height: var(--card-h);

    /* 2px Dashed Line, semi-transparent white */
    border: 2px dashed rgba(255, 255, 255, 0.3);
    border-radius: 4px;

    /* Ensures the border stays inside the width/height calculations */
    box-sizing: border-box;

    /* Optional: Center it perfectly if needed */
    position: absolute;
    top: 0;
    left: 0;
}

/* CHANGED: Buried Freezer -> Shift RIGHT (20px) & rotate. */
.frozen-rotated-under {
    transform: translateX(20px) rotate(-90deg);
    z-index: 0;
    filter: brightness(0.9);
}

#deck-count {
    position: absolute;
    top: auto;
    bottom: 4px;
    left: 4px;
    transform: none;
    background: rgba(0, 0, 0, 0.7);
    color: var(--text-primary);
    font-size: 12px;
    font-weight: bold;
    min-width: 24px;
    padding: 2px 5px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    z-index: 10;
    pointer-events: none;
    display: flex;
    justify-content: center;
}

/* ========================================= */
/* === 7. MOBILE OVERRIDES (< 800px)     === */
/* ========================================= */
@media (max-width: 800px) {
    .pile-area {
        position: relative !important;
        width: 100% !important;
        height: 80px !important;
        display: flex !important;
        align-items: center !important;
        margin: 0 !important;
        /* Ensure no extra padding pushes the center point */
        padding: 0 !important;
    }

    .piles-group {
        /* 1. Anchor the left edge to the middle of the screen */
        position: absolute !important;
        left: 50% !important;

        /* 2. REMOVE the shift. This makes it "start" from the middle and grow right. */
        transform: none !important;

        /* 3. Standard Layout Settings */
        flex: 0 0 auto !important;
        width: auto !important;
        margin: 0 !important;
        padding: 0 !important;

        /* Ensure items inside (Discard -> Draw) flow left-to-right */
        justify-content: flex-start !important;
        gap: 5px !important;
        z-index: 10;
    }


    /* Adjust the inner groups to fit the tighter space */
    .score-group {
        flex: 1 !important;
        padding-left: 36px !important;
        text-align: flex-start !important;
        align-items: flex-start !important;
    }

    .landing-content {
        padding: 20px 15px !important;
        min-height: 100vh;
        /* Use full screen height */
        display: flex;
        flex-direction: column;
        justify-content: center;
        /* Center content vertically */
    }

    /* 2. SHRINK LOGO & TITLE */
    .landing-hero-logo {
        width: 130px !important;
        /* Reduced from default (~220px) */
        margin-bottom: 10px;
    }

    .logo {
        font-size: 34px !important;
        /* Reduced from 48px */
        margin-bottom: 5px !important;
    }

    /* 3. TIGHTEN PILLS */
    .feature-pills {
        gap: 6px !important;
        margin-bottom: 20px;
        /* Space before buttons */
    }

    .feature-pills span {
        font-size: 10px !important;
        padding: 4px 10px !important;
    }

    /* 4. ADJUST BUTTON GRID */
    .landing-action-grid {
        margin-top: 10px !important;
        gap: 20px !important;
        /* Less gap between Buttons and Leaderboard */
    }

    .landing-cta {
        gap: 10px !important;
        /* Tighter buttons */
        margin-bottom: 0 !important;
    }

    /* 5. LEADERBOARD PREVIEW */
    .landing-stats-preview {
        padding: 15px !important;
        background: rgba(0, 0, 0, 0.4) !important;
        /* Darker for better contrast */
    }

    .landing-stats-preview h3 {
        font-size: 14px !important;
        margin-bottom: 10px;
    }

    #hud-left {
        grid-area: side-left !important;
        align-self: center;
        justify-self: center;
        transform: rotate(90deg);
        background: rgba(0, 0, 0, 0.2) !important;
        z-index: 50;
        width: max-content;
        white-space: nowrap;
        padding: 4px 10px;
        margin: 0 0 0 30px !important;
        pointer-events: none;
        border-radius: 0 0 4px 4px;
    }

    #hud-right {
        grid-area: side-right !important;
        align-self: center;
        justify-self: center;
        transform: rotate(-90deg);
        background: rgba(0, 0, 0, 0.2) !important;
        z-index: 50;
        width: max-content;
        white-space: nowrap;
        padding: 4px 10px;
        margin: 0 30px 0 0 !important;
        pointer-events: none;
        border-radius: 0 0 4px 4px;
    }

    #hud-partner {
        grid-area: top-info !important;
        background: transparent !important;
        border: none !important;
        transform: none;
        z-index: 20;
    }

    #timers-top {
        display: none;
    }

    /* Reclaim space from timer row */
    #game-grid {
        grid-template-rows: 35px 0px 1fr 30px 110px !important;
        grid-template-columns: 5px 1fr 5px !important;
    }

    #partner-zone {
        overflow: visible !important;
        padding-bottom: 0;
    }

    #enemy-melds {
        height: 140px !important;
        min-height: 140px !important;
        max-height: 140px !important;
    }

    #enemy-melds .meld-group {
        max-height: 130px !important;
    }


    /* ========================================= */
    /* === MOBILE SCOREBOARD FIXES           === */
    /* ========================================= */

    @media (max-width: 800px) {

        /* 1. HIDE THE HEADER ROW ("Category", "My Team", "Opponents") */
        .score-table th {
            display: none !important;
        }

        /* 2. COLOR CODING (Since headers are gone) */

        /* Column 2: My Team (Green) */
        .score-table td:nth-child(2) {
            color: #2ecc71 !important;
            /* Bright Green */
            font-weight: bold;
        }

        /* Column 3: Opponents (Red) */
        .score-table td:nth-child(3) {
            color: #e74c3c !important;
            /* Bright Red */
            font-weight: bold;
        }

        /* 3. FIT BLOCKS ON SCREEN */

        /* maximize the container width */
        .score-box {
            width: 98% !important;
            padding: 10px 5px !important;
            /* Minimal padding */
        }

        /* Reduce general table font size */
        .score-table {
            font-size: 13px !important;
        }

        /* Tighter cell padding so columns don't overflow */
        .score-table td {
            padding: 6px 2px !important;
        }

        /* Reduce the massive font size of the Final Score row */
        .score-table .total-row {
            font-size: 16px !important;
            letter-spacing: 0px !important;
            /* Remove wide spacing */
        }

        /* Optional: Make the Category labels (Left Column) subtle/smaller */
        .score-table td:first-child {
            font-size: 11px !important;
            color: #95a5a6 !important;
            /* Muted Grey */
            width: 35%;
            /* Prevent labels from getting crushed */
        }
    }
}

/* ========================================= */
/* === 8. DESKTOP OVERRIDES (> 800px)    === */
/* ========================================= */
@media (min-width: 800px) {
    :root {
        --card-w: 75px;
        --card-h: 105px;
        --bg-color: #162029;
        /* Slightly deeper navy for desktop */
    }

    /* --- LAYOUT --- */
    /* --- Global Screen Header Styles --- */

    .menu-btn {
        max-width: 300px;
        /* Matches your input fields width */
        margin-left: auto;
        /* Centers the button horizontally */
        margin-right: auto;
        width: 100%;
        /* Ensures it fills space up to 300px */
    }

    /* specific fix for the landing page if you want them right-aligned */
    .landing-cta .menu-btn {
        margin-right: 0;
        /* or keep margin-right: auto if you want them centered there too */
    }

    .menu-list {
        display: grid !important;
        /* Desktop: 2 columns, fixed width buttons */
        grid-template-columns: repeat(2, 280px);
        gap: 20px 30px;
        justify-content: center;
        max-width: none;
        /* Remove mobile constraint */
        padding: 0;
    }

    /* DESKTOP RESET: Make Play & Train buttons take 1 column each (side-by-side) */
    .menu-list>button:nth-child(1),
    .menu-list>button:nth-child(2) {
        grid-column: span 1 !important;
    }

    .menu-btn {
        font-size: 16px;
        /* Restore larger text for desktop */
        letter-spacing: 1.5px;
    }

    .screen-header {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        /* Centers the title */
        padding: 20px;
        position: relative;
        border-bottom: 1px solid rgba(241, 196, 15, 0.1);
        /* Subtle gold line */
        background: linear-gradient(to bottom, rgba(0, 0, 0, 0.2), transparent);
        margin-bottom: 30px;
    }

    .home-icon {
        filter: drop-shadow(0 0 5px var(--accent-color));
        /* Makes the icon pop */
    }

    .back-nav {
        position: absolute;
        left: 20px;
        display: flex;
        align-items: center;
        gap: 8px;
        cursor: pointer;
        opacity: 0.7;
        transition: all 0.2s ease;
        filter: drop-shadow(0 0 5px var(--accent-color));
    }

    .back-nav:hover {
        opacity: 1;
        color: var(--accent-color);
        transform: translateX(-5px);
        /* Subtle "pull" effect */
    }

    .back-text {
        font-family: var(--font-title);
        font-size: 14px;
        letter-spacing: 1px;
    }

    .landing-content {
        max-width: 1000px;
        /* Increased to accommodate side-by-side layout */
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    .landing-action-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        /* Split into CTA and Stats columns */
        gap: 50px;
        width: 100%;
        align-items: center;
        margin-top: 40px;
    }

    .landing-cta {
        align-items: flex-end;
        /* Buttons sit toward the center-left */
        margin-bottom: 0;
        /* Remove mobile spacing */
    }

    .landing-stats-preview {
        text-align: left;
        align-self: stretch;
        /* Match height of CTA column for symmetry */
        background: rgba(255, 255, 255, 0.03);
        backdrop-filter: blur(10px);
        border: 1px solid rgba(241, 196, 15, 0.15);
    }

    #game-grid {
        grid-template-columns: 140px 1fr 140px;
        grid-template-rows: 40px 0px 1fr 0px 120px !important;
        grid-template-areas:
            ".          partner    ."
            ".          timer-top  ."
            "side-left  center     side-right"
            ".          timer-bot  ."
            ".          player     .";
    }

    /* --- ZONES --- */
    #partner-zone {
        grid-area: partner;
        align-items: flex-end;
        overflow: visible;
        padding-bottom: 0;
    }

    #my-zone {
        grid-area: player;
        align-items: flex-start;
        padding-top: 10px;
    }

    #table-zone {
        grid-area: center;
        display: grid;
        grid-template-rows: 1fr auto 1fr !important;
        padding: 0 40px;
        height: 100%;
        gap: 0 !important;
        align-content: center;
        overflow: hidden !important;
    }

    .side-zone {
        justify-content: center;
        padding-top: 0 !important;
        border: none;
        background: transparent;
    }

    /* --- HUD POSITIONS --- */
    #hud-left,
    #hud-right {
        grid-area: center !important;
        position: static !important;
        width: auto !important;
        height: auto !important;
        z-index: 100 !important;
    }

    #hud-left {
        justify-self: start !important
    }

    #hud-right {
        justify-self: end !important
    }

    #hud-partner {
        grid-area: timer-top;
        align-self: center;
        justify-self: center;
        transform: translateY(10px) !important;
        pointer-events: none;
        z-index: 100 !important;
    }

    #hud-me {
        grid-area: timer-bot;
        align-self: center;
        justify-self: center;
        transform: translateY(15px) !important;
        pointer-events: none;
        z-index: 100 !important;
    }

    /* --- TABLE ELEMENTS --- */
    .pile-area {
        grid-row: 2;
        width: 550px !important;
        max-width: 90% !important;
        margin: 0 auto !important;
        transform: translateX(-40px) !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        gap: 20px !important;
        height: 100px;
        padding: 0 !important;
        position: static !important;
    }

    .score-group {
        flex: 0 0 220px !important;
        width: 220px !important;
        height: 90px !important;
        margin: 0 !important;
        position: static !important;
    }

    .piles-group {
        flex: 0 0 auto !important;
        width: auto !important;
        min-width: 180px !important;
        height: 90px !important;
        margin: 0 !important;
        justify-content: center;
        gap: 15px;
        position: static !important;
    }

    #enemy-melds {
        margin-top: 18px !important;
        /* Clears the "BOT 1" timer text */
        padding-top: 20px !important;
        height: 195px !important;
        /* Fixed height for the "Green Box" */
        max-height: 195px !important;
        min-height: 195px !important;
        justify-content: center !important;
        display: flex !important;
        align-items: flex-start !important;
        overflow: visible !important;
        padding-left: 0 !important;
    }

    #my-melds {
        /* Symmetric height for user, keeping spacing we liked before */
        padding-top: 20px !important;
        height: 195px !important;
        max-height: 195px !important;
        min-height: 195px !important;
        margin-bottom: 0px !important;
        justify-content: center !important;
        padding-left: 0 !important;
    }

    .meld-container {
        display: flex;
        flex-direction: column;
        align-items: center;
        width: 100%;
    }

    .meld-card {
        /* Optional: Slightly thinner border to match your screenshot's clean look */
        border: 0.5px solid rgba(0, 0, 0, 0.5);
    }


    /* --- CARDS --- */
    #hand-left,
    #hand-right {
        transform: none !important;
        padding: 20px 0;
        margin: 0 5px !important;
    }

    #hand-left {
        align-items: flex-start !important;
    }

    #hand-right {
        align-items: flex-end !important;
    }

    .side-card {
        margin-top: -50px;
    }

    /* --- MISC --- */
    #btn-game-menu {
        top: 20px !important;
        right: 20px !important;
        bottom: auto !important;
        width: 45px;
        height: 45px;
        font-size: 24px;
    }
}

/* ========================================= */
/* === 9. UI COMPONENTS                  === */
/* ========================================= */
.form-group {
    margin-bottom: 15px;
    width: 100%;
    max-width: 300px;
}

.form-input {
    width: 100%;
    padding: 12px;
    border-radius: 4px;
    /* Sharper corners */
    border: 1px solid #444;
    background: rgba(0, 0, 0, 0.5);
    /* Darker background */
    color: var(--accent-color);
    /* Gold text when typing */
    font-family: var(--font-body);
    font-size: 16px;
    text-align: center;
    transition: border 0.3s;
}

.form-input::placeholder {
    color: var(--text-secondary);
    ;
    font-family: var(--font-title);
    /* Placeholder uses fancy font */
    text-transform: uppercase;
    font-size: 12px;
    letter-spacing: 1px;
}

.form-input:focus {
    outline: none;
    border-color: var(--accent-color);
    /* Gold border on focus */
    background: rgba(0, 0, 0, 0.7);
    box-shadow: 0 0 10px rgba(241, 196, 15, 0.1);
}

.error-msg {
    color: #e74c3c;
    margin-bottom: 10px;
    font-size: 14px;
    display: none;
}

.link-text {
    color: #bdc3c7;
    margin-top: 15px;
    cursor: pointer;
    font-size: 14px;
    text-decoration: underline;
}

/* Modals */
.menu-box {
    background: #1a252f;
    /* Deep Navy */
    border: 2px solid var(--accent-color);
    /* Gold Border */
    padding: 30px;
    border-radius: 8px;
    text-align: center;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.8);
}

.menu-box h3 {
    color: var(--text-primary);
    font-family: var(--font-title);
    letter-spacing: 2px;
    margin-bottom: 25px;
    text-transform: uppercase;
}

#ready-modal,
#score-modal,
#game-menu-overlay {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 2000;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.ready-box {
    background: #2c3e50;
    border: 2px solid var(--accent-color);
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.8);
}

/* Dark Theme Score Box to match the app */
.score-box {
    background: #2c3e50;
    /* Dark Navy instead of White */
    color: var(--text-primary);
    /* White Text */
    width: 85%;
    max-width: 600px;
    padding: 25px;
    border-radius: 12px;
    text-align: center;
    border: 2px solid var(--accent-color);
    /* Gold Border */
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.8);
}

.score-box h2 {
    color: var(--text-primary);
    font-family: var(--font-title);
    letter-spacing: 2px;
    margin-bottom: 20px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.score-table {
    width: 100%;
    border-collapse: collapse;
    margin: 15px 0;
    font-size: 15px;
    color: var(--text-primary);
    /* Text is now visible on dark bg */
    background: transparent;
}

.score-table th {
    background: var(--accent-color) !important;
    /* Gold Header */
    color: #1a252f !important;
    /* Dark Text on Gold */
    padding: 12px 8px;
    font-family: var(--font-title);
    text-transform: uppercase;
    font-weight: 900;
    letter-spacing: 1px;
    border-bottom: 2px solid #fff;
}

.score-table td {
    padding: 7px 5px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    /* Subtle divider */
    text-align: center;
}

/* Highlights the category labels in the first column */
.score-table td:first-child {
    text-align: left;
    color: #bdc3c7;
    /* Silver for labels */
    font-weight: bold;
}

/* Total Row Styling */
.score-table .total-row {
    font-weight: 900;
    color: #2c3e50 !important;
    background: rgba(0, 0, 0, 0.4);
    /* Darker stripe */
    border-top: 2px solid var(--accent-color);
    font-size: 18px;
}

/* In-Game Menu */
#btn-game-menu {
    position: absolute;
    bottom: 115px;
    right: 10px;
    width: 35px;
    height: 35px;
    background: rgba(0, 0, 0, 0.6);
    color: var(--text-primary);
    font-size: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border: 2px solid rgba(255, 255, 255, 0.3);
    z-index: 2000;
}

.pass-toggle {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    opacity: 0.7;
    z-index: 5;
}

/* Victory & Animation */
.victory-content {
    text-align: center;
    animation: popIn 0.5s ease;
}

@keyframes popIn {
    0% {
        transform: scale(0.8);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.final-score-box {
    background: rgba(255, 255, 255, 0.1);
    padding: 20px;
    border-radius: 12px;
    width: 280px;
    margin: 0 auto 30px auto;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.fs-row {
    display: flex;
    justify-content: space-between;
    font-size: 20px;
    font-weight: bold;
    padding: 5px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.flying-card {
    position: fixed;
    z-index: 9999;
    pointer-events: none;
    transition: all 0.5s cubic-bezier(0.25, 1, 0.5, 1);
    box-shadow: 5px 5px 15px rgba(0, 0, 0, 0.5);
    border-radius: 4px;
    transform-origin: top left;
}

/* Bot UI */
.diff-grid {
    display: flex;
    gap: 10px;
    margin: 20px 0;
    justify-content: center;
}

.diff-btn {
    padding: 10px 20px;
    border: 2px solid #46719b;
    border-radius: 8px;
    color: #bdc3c7;
    cursor: pointer;
    font-weight: bold;
    background: rgba(0, 0, 0, 0.2);
}

.diff-btn.selected {
    background: var(--accent-color);
    color: #2c3e50;
    border-color: var(--accent-color);
}

.p-indicator {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #444;
    color: #aaa;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    border: 2px solid #555;
}

.p-indicator.ready {
    background: #2ecc71;
    color: var(--text-primary);
    border-color: var(--text-primary);
    box-shadow: 0 0 10px #2ecc71;
}

#staging-panel {
    display: none;
    position: absolute;
    bottom: 35%;
    left: 10%;
    width: 80%;
    background: #2d3436;
    color: var(--text-primary);
    padding: 10px;
    border-radius: 8px;
    border: 2px solid #f1c40f;
    z-index: 999;
}

/* --- LEADERBOARD STYLES --- */
.leaderboard-container {
    width: 95%;
    max-width: 600px;
    height: 60vh;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 10px;
    margin-bottom: 20px;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.5);
}

.lb-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 15px;
}

/* Row Hover Effect */
.lb-row:not(.lb-header):hover {
    background: rgba(255, 255, 255, 0.05);
}

.lb-header {
    font-weight: bold;
    color: #7f8c8d;
    border-bottom: 2px solid #555;
    font-size: 12px;
    letter-spacing: 1px;
    position: sticky;
    top: 0;
    background: #2c3e50;
    /* Matches body bg to cover scrolling items */
    z-index: 10;
}

.lb-name {
    flex: 1;
    text-align: left;
    padding-left: 10px;
    font-weight: bold;
    color: var(--text-primary);
}

.lb-rating {
    width: 60px;
    text-align: right;
    color: #f1c40f;
    font-weight: bold;
}

.lb-stats {
    width: 60px;
    text-align: right;
    color: #95a5a6;
    font-size: 12px;
}

/* Rank Styling */
.rank-num {
    width: 50px;
    text-align: left;
    font-weight: bold;
    color: #777;
}

.rank-1 {
    color: #f1c40f;
    text-shadow: 0 0 10px rgba(241, 196, 15, 0.3);
    font-size: 1.1em;
}

/* Gold */
.rank-2 {
    color: #bdc3c7;
    text-shadow: 0 0 10px rgba(189, 195, 199, 0.3);
}

/* Silver */
.rank-3 {
    color: #e67e22;
    text-shadow: 0 0 10px rgba(230, 126, 34, 0.3);
}

/* Bronze */

.side-card,
.partner-card {
    width: var(--card-w);
    /* Ensure width is locked */
    height: var(--card-h);
    /* Ensure height is locked */
    background-size: cover;
    border-radius: 4px;
    border: 1px solid #111;
    flex-shrink: 0;
    /* CRITICAL: Prevents cards from being squashed */
}

/* Add specific classes */
.card-back-Red {
    background-image: url('cards/BackRed.png');
}

.card-back-Blue {
    background-image: url('cards/BackBlue.png');
}

#hand-left .side-card {
    transform: rotate(270deg);
}

/* Remove white background from Draw Pile so transparent corners look correct */
#draw-area .card-img {
    background: transparent;
}

.table-logo {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 200px;
    /* Adjust size */
    opacity: 0.15;
    /* Make it faint/watermark style */
    pointer-events: none;
    /* Click through it */
    z-index: 0;
    /* Behind cards */
}

/* 1. Ensure the meld container can anchor the logo */
#my-melds {
    position: relative;
    z-index: 1;
    /* Establishes a stacking context */
}

/* 2. Create the Logo using a pseudo-element */
/* 1. Target the Opponent's meld area */
#enemy-melds {
    position: relative;
    z-index: 1;
    padding-top: env(safe-area-inset-top);
    /* Ensures cards stay on top */
}

#enemy-melds::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 220px;
    height: 100%;
    background-image: url('Canasta logo.png');
    background-repeat: no-repeat;
    background-size: contain;
    background-position: center;
    opacity: 0.12;
    /* Fainter for gameplay clarity */
    pointer-events: none;
    z-index: -1;
}

/* 2. Target Your meld area */
#my-melds {
    position: relative;
    z-index: 1;
}

#my-melds::before {
    content: "CANASTA\a MASTER CLUB";
    white-space: pre;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: var(--font-title);
    font-weight: 900;
    font-size: 32px;
    /* Scaled down for table usage */
    text-align: center;
    color: var(--accent-color);
    letter-spacing: 3px;
    opacity: 0.12;
    text-shadow: 2px 2px 0px #000;
    pointer-events: none;
    z-index: -1;
}

#inactivity-warning {
    position: fixed;
    top: 20%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(231, 76, 60, 0.95);
    color: var(--text-primary);
    padding: 20px 40px;
    border-radius: 8px;
    z-index: 10000;
    font-weight: bold;
    font-size: 18px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    border: 2px solid white;
    text-align: center;
    pointer-events: none;
    /* CRITICAL: Allows clicks to pass through */
    display: none;
    /* Hidden by default */
}

#inactivity-warning .warning-icon {
    font-size: 30px;
    margin-bottom: 10px;
}

#inactivity-warning .warning-countdown {
    font-size: 22px;
    color: var(--accent-color);
    /* Uses your existing Gold variable */
    margin-top: 10px;
    font-weight: 900;
}

#inactivity-warning .warning-hint {
    font-size: 12px;
    margin-top: 5px;
}

.setting-item {
    margin: 15px 0;
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: sans-serif;
}

#botSpeedRange {
    cursor: pointer;
    width: 150px;
}

#speedValue {
    font-weight: bold;
    color: #2c3e50;
    min-width: 60px;
}

.rules-container {
    width: 90%;
    max-width: 600px;
    height: 70vh;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.4);
    padding: 20px;
    border-radius: 12px;
    border: 1px solid rgba(241, 196, 15, 0.2);
    margin-bottom: 20px;
    text-align: left;
}

.rules-section {
    margin-bottom: 25px;
}

.rules-section h3 {
    color: var(--accent-color);
    font-family: var(--font-title);
    font-size: 18px;
    margin-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.rules-section ul {
    padding-left: 20px;
    color: var(--text-secondary);
}

.rules-section li {
    margin-bottom: 8px;
    line-height: 1.4;
}

.rules-table {
    width: 100%;
    border-collapse: collapse;
    color: var(--text-primary);
    font-size: 14px;
}

.rules-table th {
    text-align: left;
    color: var(--accent-color);
    padding: 8px 0;
}

.rules-table td {
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.landing-content {
    max-width: 800px;
    padding: 40px 20px;
    text-align: center;
    animation: fadeIn 0.8s ease-out;
}

.hero-text {
    font-size: 18px;
    color: var(--text-secondary);
    line-height: 1.6;
    margin: 20px auto 40px;
    max-width: 500px;
}

.landing-hero-logo {
    width: 220px;
    /* Slightly larger */
    filter: drop-shadow(0 0 30px rgba(241, 196, 15, 0.25));
    animation: float 6s ease-in-out infinite;
    /* Adds "life" */
}

.landing-cta {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    margin-bottom: 50px;
}

.landing-stats-preview {
    background: rgba(255, 255, 255, 0.03);
    backdrop-filter: blur(10px);
    /* Frosted glass effect */
    border: 1px solid rgba(241, 196, 15, 0.2);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.8);
    border-radius: 15px;
    padding: 25px;
    width: 100%;
    max-width: 450px;
    /* Better density */
}

#screen-landing,
#screen-home {
    /* Fallback solid color for Firefox */
    background-color: var(--bg-color);
    /* Rich radial gradient centered on the branding */
    background: radial-gradient(circle at center, #2c3e50 0%, var(--bg-color) 100%) !important;
    position: relative;
    overflow: hidden;
    min-height: 100vh;
    /* Ensure full viewport coverage on Firefox */
}

#screen-landing::before,
#screen-home::before {
    content: "♠ ♥ ♣ ♦";
    position: absolute;
    font-size: 20rem;
    color: rgba(255, 255, 255, 0.02);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-15deg);
    pointer-events: none;
    z-index: 0;
}

/* Dynamic Floating Cards Background */
.bg-cards {
    position: absolute;
    width: 100%;
    height: 100%;
    overflow: hidden;
    z-index: 1;
    pointer-events: none;
}

.floating-card-bg {
    position: absolute;
    opacity: 0.05;
    /* Very faint */
    animation: float-around 20s linear infinite;
}

@keyframes float-around {
    0% {
        transform: translateY(110vh) rotate(0deg);
    }

    100% {
        transform: translateY(-10vh) rotate(360deg);
    }
}

.meld-target-highlight {
    filter: brightness(1.3) contrast(1.1);
    box-shadow: 0 0 15px var(--accent-color) !important;
    transform: scale(1.05);
    z-index: 100 !important;
    border: 2px solid var(--accent-color) !important;
    background: rgba(241, 196, 15, 0.1);
    border-radius: 8px;
    cursor: pointer;
}