/* --- BASE STYLES & RESET (BINGO COLORS) --- */
:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --ai-color: #ec4899;
    --ai-hover: #db2777;
    --bg-dark: #0f172a;
    --bg-panel: #1e293b;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --cell-bg: #334155;
    --cell-hover: #475569;
    --cell-marked: #10b981;
    --board-bg: #cbd5e1;
}

* { 
    box-sizing: border-box; 
    margin: 0; 
    padding: 0; 
}

body {
    /* Merged Tic Tac Toe dark gradient with Bingo Dark Color */
    background: linear-gradient(135deg, #090914, var(--bg-dark));
    color: var(--text-main);
    font-family: system-ui, -apple-system, sans-serif;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    overflow: hidden; 
}

.screen {
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2vmin; 
}

.screen.hidden { display: none !important; }
.screen.active { display: flex; }

.main-title, .game-title {
    font-size: 8vmin;
    letter-spacing: 2vmin;
    margin-bottom: 3vmin;
    text-align: center;
    color: var(--primary);
    text-shadow: 0 0.5vmin 1vmin rgba(0,0,0,0.5);
    padding-left: 2vmin; 
}

#lobby-status {
    color: var(--text-muted);
    margin-bottom: 5vmin;
    font-size: 2.5vmin;
}

.lobby-buttons {
    display: flex;
    gap: 3vmin;
    width: 80vmin; 
    max-width: 600px;
}

.primary-btn {
    flex: 1; 
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.5vmin;
    background-color: var(--primary);
    color: white;
    border: none;
    padding: 3vmin 2vmin;
    font-size: 2.5vmin;
    font-weight: bold;
    border-radius: 2vmin;
    cursor: pointer;
    transition: transform 0.2s ease, background 0.2s;
    /* Glass shadow */
    box-shadow: 0 1vmin 2vmin rgba(0,0,0,0.6);
}

.primary-btn svg { width: 6vmin; height: 6vmin; }
.primary-btn:active { transform: scale(0.95); }
.primary-btn:hover { background-color: var(--primary-hover); transform: scale(1.03); }
.primary-btn.ai-btn { background-color: var(--ai-color); }
.primary-btn.ai-btn:hover { background-color: var(--ai-hover); transform: scale(1.03); }

#loading-spinner {
    margin-top: 4vmin;
    font-size: 3vmin;
    color: var(--cell-marked);
    font-weight: bold;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* --- ORIGINAL DESKTOP GRID LAYOUT --- */
#game-screen.active {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    grid-template-rows: auto auto auto auto;
    align-items: center;
    justify-items: center;
    gap: 3vmin;
    width: 100vw;
    height: 100vh;
    padding: 2vmin;
}

/* TOP CONTROLS & WAVE ANIMATION */
.top-controls {
    position: absolute;
    top: 3vmin;
    right: 3vmin;
    display: flex;
    gap: 2vmin;
    z-index: 150;
}
.icon-btn {
    /* Glass Icon Button */
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.15);
    backdrop-filter: blur(8px);
    border-radius: 50%;
    width: 7vmin;
    height: 7vmin;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0.5vmin 1.5vmin rgba(0,0,0,0.5);
    transition: transform 0.2s ease, background 0.2s;
}
.icon-btn:active { transform: scale(0.9); }
.icon-btn:hover { background: rgba(255,255,255,0.25); transform: scale(1.08); }

@keyframes waveAppearText {
    0% { opacity: 0; transform: translateY(2vmin) scale(0.5); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}
.wave-text {
    display: inline-block;
    opacity: 0;
    animation: waveAppearText 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.game-title {
    grid-column: 1 / -1;
    grid-row: 1;
    margin-bottom: 0;
}

.game-header {
    display: contents !important; 
}

/* Updated Player Info Box to be 1:1 Square */
.player-info {
    display: flex !important;
    flex-direction: column;
    /* GLASS TEXTURE */
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    box-shadow: 0 1vmin 3vmin rgba(0,0,0,0.7);
    /* ORIGINAL SIZING */
    padding: 2.5vmin;
    border-radius: 2vmin;
    width: 32vmin; 
    height: 32vmin; 
    max-width: 200px;
    max-height: 200px;
    text-align: center;
    align-items: center !important;
    justify-content: space-between;
    transition: all 0.3s ease;
    position: relative;
}
.player-info.active-turn {
    /* Glass Glow using Bingo Green */
    border: 1px solid rgba(255,255,255,0.7);
    box-shadow: 0 0 3vmin rgba(16, 185, 129, 0.4);
    transform: scale(1.05);
}
.turn-label {
    font-size: 2.5vmin;
    color: var(--cell-marked);
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.2vmin;
    opacity: 0;
    transition: opacity 0.3s;
    position: absolute;
    top: -4vmin;
}
.player-info.active-turn .turn-label {
    opacity: 1;
}

@keyframes popNumber {
    0% { transform: scale(0.5); opacity: 0; }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); opacity: 1; }
}
.pop-anim {
    animation: popNumber 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.player-name {
    font-size: 4vmin;
    font-weight: bold;
    color: var(--primary);
    width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis; 
}

.last-pick-box {
    /* Glass inner box */
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.15);
    color: white;
    /* ORIGINAL SIZING */
    width: 16vmin;
    height: 16vmin;
    max-width: 110px;
    max-height: 110px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 7.5vmin;
    font-weight: bold;
    border-radius: 2vmin;
    box-shadow: inset 0 0.5vmin 1vmin rgba(0,0,0,0.3);
    margin-bottom: 1vmin;
}

.player-info.left { grid-column: 1; grid-row: 2 / span 2; align-self: center; }
.player-info.right { grid-column: 3; grid-row: 2 / span 2; align-self: center; }

.bingo-tracker {
    grid-column: 2;
    grid-row: 2;
    display: flex;
    justify-content: space-between;
    width: 70vmin;
    margin-bottom: 2vmin;
}

.bingo-letter {
    /* Glass Letter Box */
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255,255,255,0.1);
    backdrop-filter: blur(8px);
    color: var(--text-muted);
    /* ORIGINAL SIZING */
    width: 12vmin;
    height: 12vmin;
    font-size: 6vmin;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 1.5vmin;
    box-shadow: inset 0 0.5vmin 1vmin rgba(0,0,0,0.3);
    transition: all 0.3s ease;
}

.bingo-letter.struck {
    background: var(--primary);
    color: white;
    box-shadow: 0 0.5vmin 1vmin rgba(0,0,0,0.4), 0 0 1.5vmin rgba(99, 102, 241, 0.5);
    border-color: transparent;
    transform: scale(1.05);
}

.badge {
    display: block !important; 
    font-size: 1.5vmin;
    color: var(--text-muted);
    margin-bottom: 1vmin;
    text-transform: uppercase;
    letter-spacing: 0.2vmin;
}

#turn-indicator { display: none !important; }

/* Middle Board */
.bingo-board {
    grid-column: 2;
    grid-row: 3;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    grid-template-rows: repeat(5, 1fr);
    gap: 1.2vmin; 
    /* Glass Board Background */
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255,255,255,0.08);
    backdrop-filter: blur(10px);
    box-shadow: 0 1vmin 3vmin rgba(0,0,0,0.8);
    /* ORIGINAL SIZING */
    padding: 1.5vmin;
    border-radius: 2vmin;
    width: 70vmin; 
    height: 70vmin;
    aspect-ratio: 1 / 1;
}

.cell {
    /* Glass Cell Background */
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255,255,255,0.15);
    color: white;
    /* ORIGINAL SIZING */
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 6.5vmin; 
    font-weight: bold;
    border-radius: 1vmin;
    cursor: pointer;
    user-select: none;
    transition: all 0.2s ease;
    box-shadow: inset 0 0 1vmin rgba(0,0,0,0.2);
}

@media (hover: hover) {
    .cell:hover:not(.marked) { 
        background: rgba(255, 255, 255, 0.25); 
        transform: translateY(-0.3vmin); 
    }
}

.cell.marked {
    background: var(--cell-marked);
    color: #022c22;
    cursor: default;
    transform: scale(0.95);
    box-shadow: inset 0 0.5vmin 1vmin rgba(0,0,0,0.3), 0 0 1.5vmin rgba(16, 185, 129, 0.4);
    border-color: transparent;
}

.not-my-turn { pointer-events: none; opacity: 0.6; filter: grayscale(0.5); }
.hidden { display: none !important; }

/* --- CUSTOM MODAL --- */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0,0,0,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(8px);
}
.modal-box {
    /* Glass Modal Box */
    background: rgba(255, 255, 255, 0.1); 
    border: 1px solid rgba(255, 255, 255, 0.2);
    /* ORIGINAL SIZING */
    padding: 5vmin;
    border-radius: 2vmin;
    width: 80vmin;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 2vmin 4vmin rgba(0,0,0,0.5);
}
#modal-title { font-size: 5vmin; color: var(--primary); margin-bottom: 2vmin; }
#modal-message { font-size: 3.5vmin; margin-bottom: 4vmin; }
.modal-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2vmin;
}
.secondary-btn {
    background: rgba(255, 255, 255, 0.15); 
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    padding: 2vmin;
    font-size: 2.5vmin;
    font-weight: bold;
    border-radius: 1vmin;
    cursor: pointer;
}

/* --- ORIGINAL END GAME BOARDS LAYOUT --- */
#end-game-view {
    position: absolute;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    background: var(--bg-dark);
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    gap: 4vw;
    z-index: 100;
    padding: 2vw;
    box-sizing: border-box;
}
.end-board { width: 42vw; max-width: 400px; height: auto; aspect-ratio: 1 / 1; min-height: max-content; flex-shrink: 0; gap: 0.8vmin; padding: 1.5vmin; box-sizing: border-box; }
.end-tracker { width: 42vw; max-width: 400px; margin-bottom: 2vmin; }
.end-letter { width: 7vw; height: 7vw; max-width: 70px; max-height: 70px; font-size: 4vw; }
.end-board-title { font-size: 4vw; margin-bottom: 2vmin; color: var(--primary); }
.end-board .cell { font-size: 4vw; border-radius: 0.5vmin; }

.end-board-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
}
.end-board-title {
    color: var(--primary);
    font-size: 4vmin;
    margin-bottom: 2vmin;
}

/* --- ORIGINAL MOBILE VIEW OVERRIDE --- */
@media (max-width: 800px) and (orientation: portrait) {
    #game-screen.active {
        display: flex;
        flex-direction: column;
        justify-content: center;
        padding: 0;
        margin: 0;
    }
    .game-title { order: 1; font-size: 10vw; margin-bottom: 2vw; }
    
    .bingo-tracker {
        order: 2;
        width: 98vw;
        margin-bottom: 3vw;
    }
    .bingo-letter {
        width: 17vw;
        height: 17vw;
        font-size: 8vw;
    }
    
    .bingo-board {
        order: 3;
        width: 98vw; height: 98vw; gap: 1vw; padding: 1.5vw; margin-bottom: 5vw; 
    }
    .cell { font-size: 10vw; }
    
    .game-header {
        order: 4; 
        display: flex !important;
        width: 98vw;
        justify-content: space-between;
        background: transparent; 
        padding: 0;
        margin-bottom: 2vmin;
    }
    
    .player-info {
        width: 38vw; 
        height: 38vw;
        background: rgba(255, 255, 255, 0.06);
        padding: 2.5vw;
        box-shadow: 0 1vmin 2vmin rgba(0,0,0,0.3);
        border-radius: 2vmin;
        align-items: center !important;
        justify-content: space-between;
        text-align: center;
        border: 0.5vw solid transparent;
        position: relative;
    }
    .turn-label { font-size: 3vw; top: -5vw; }
    .player-name {
        font-size: 3.2vw;
        width: 100%;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .last-pick-box {
        width: 15vw;
        height: 15vw;
        font-size: 6.5vw;
        margin-bottom: 1vw;
    }
    .player-info.left { align-items: center !important; text-align: center; }
    .player-info.right { align-items: center !important; text-align: center; }
    .main-title { font-size: 10vw; margin-bottom: 2vw; }
    
    #end-game-view { flex-direction: row; gap: 3vw; padding: 2vw; }
    .end-board { width: 46vw; height: auto; aspect-ratio: 1 / 1; min-height: max-content; flex-shrink: 0; gap: 0.5vw; padding: 1.5vw; box-sizing: border-box; }
    .end-tracker { width: 46vw; margin-bottom: 1vw; }
    .end-letter { width: 8vw; height: 8vw; font-size: 4vw; }
    .end-board-title { font-size: 4.5vw; }
    .end-board .cell { font-size: 4.5vw; }
    
    .top-controls { position: fixed; top: 4vw; right: 4vw; gap: 3vw; z-index: 200; }
    .icon-btn { width: 10vw; height: 10vw; }

    .modal-box { padding: 5vw; width: 90vw; }
    #modal-title { font-size: 8vw; }
    #modal-message { font-size: 5vw; }
    .modal-actions button { font-size: 4vw; padding: 3vw; }
}

/* --- LANDSCAPE FIX FOR SMALL SCREENS (PHONES TILTED SIDEWAYS) --- */
@media (max-height: 600px) and (orientation: landscape) {
    #game-screen.active { gap: 1vmin; padding: 1vmin; }
    .game-title { font-size: 6vmin; margin-bottom: 1vmin; }
    
    .bingo-board { width: 65vmin; height: 65vmin; padding: 1.5vmin; }
    .cell { font-size: 5.5vmin; }
    
    .bingo-tracker { width: 65vmin; margin-bottom: 1vmin; }
    .bingo-letter { width: 10vmin; height: 10vmin; font-size: 5vmin; }
    
    .player-info { width: 28vmin; height: 28vmin; padding: 1.5vmin; }
    .last-pick-box { width: 12vmin; height: 12vmin; font-size: 5.5vmin; margin-bottom: 0.5vmin; }
    .player-name { font-size: 3.5vmin; }
    .turn-label { top: -3vmin; font-size: 2vmin; }
    
    .top-controls { top: 2vmin; right: 2vmin; transform: scale(0.7); transform-origin: top right; }
}