/* --- ALAP BEÁLLÍTÁSOK ÉS KONTEXTUS --- */
#game-area { 
    display: none; 
    opacity: 0; 
    z-index: 10;
    transition: opacity 0.5s;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 1px; 
    min-height: 100vh;
    box-sizing: border-box;
}
#game-area.visible { display: flex; opacity: 1; }

.main-frame { 
    background: linear-gradient(135deg, #1a2a6c, #b21f1f, #fdbb2d); 
    padding: 8px; 
    border-radius: 12px; 
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

.inner-board { 
    background: #fff; 
    border-radius: 5px; 
    position: relative;
    overflow: visible !important; 
}

/* --- TÁBLÁZAT (KOMPAKT TABLET OPTIMALIZÁLT) --- */
table { border-collapse: collapse; margin: 0 auto; table-layout: fixed; width: auto; max-width: 100%; }

th { 
    padding: 6px 2px; 
    color: white; 
    border: 1px solid rgba(0,0,0,0.2); 
    font-size: 16px; 
    background-color: #333;
    position: relative;
    font-family: 'Kalam', cursive;
}

td { 
    border: 1px solid #ccc; 
    position: relative; 
    width: 50px; 
    height: 34px; /* Kompakt magasság a 11,5" kijelzőhöz */
    text-align: center;
}

.label { 
    background: rgba(0,0,0,0.05); 
    width: 105px; 
    font-weight: bold; 
    font-size: 14px; 
}

.cell-val { 
    width: 100%; 
    height: 100%; 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    font-size: 18px; 
    cursor: pointer;
    pointer-events: none; /* Átengedi a kattintást a TD-nek */
}

.cell-interactive { cursor: pointer; }
.cell-interactive.filled .cell-val { font-weight: 800; color: #333; }

/* --- VAGÁNY FÉLKÖRÍVES BUBORÉK PICKER --- */
.bubble-picker-radial {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    z-index: 10000;
    pointer-events: none;
}

.bubble-picker-radial.active { pointer-events: auto; }

.comic-bubble {
    position: absolute;
    border-radius: 50%;
    width: 72px; /* Nagyobb méret tablethez */
    height: 72px; 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    font-weight: 800;
    font-size: 26px; 
    cursor: pointer; 
    background: #ffffff;
    border: 3px solid #333;
    box-shadow: 
        0 8px 15px rgba(0,0,0,0.3), 
        inset 0 -5px 5px rgba(0,0,0,0.1),
        inset 0 5px 5px rgba(255,255,255,0.8);
    transform: translate(-50%, -50%) scale(0);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 10001;
    pointer-events: auto;
}

.bubble-picker-radial.active .comic-bubble { transform: translate(-50%, -50%) scale(1); }

.val-btn { color: #1b5e20; background: linear-gradient(135deg, #ffffff 0%, #e8f5e9 100%); border-color: #2e7d32; }
.strike-btn { color: #b71c1c; background: linear-gradient(135deg, #ffffff 0%, #ffebee 100%); border-color: #d32f2f; }
.num-trigger { color: #0d47a1; background: linear-gradient(135deg, #ffffff 0%, #e3f2fd 100%); border-color: #1a2a6c; }

/* Meccstörténet táblázat - optimalizált oszlopszélességek a panelhez */
#match-history-table {
    width: 100%;
    max-width: 100%;
    border-collapse: collapse;
    table-layout: fixed; /* Fixált layout a jobb kontrollhoz */
    box-sizing: border-box;
}

#match-history-table thead {
    background: #000;
    color: #fff;
}

#match-history-table th {
    padding: 2px 3px; /* Csökkentett padding */
    font-family: Arial, sans-serif;
    font-size: 9px; /* Kisebb betűméret */
    text-align: left;
    border-bottom: 1px solid #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Optimális oszlopszélességek - összesen ~260px (nyertes oszlop nélkül) */
#match-history-table th:nth-child(1) {
    width: 65px; /* Dátum - igazítva a tartalomhoz */
}

#match-history-table th:nth-child(2) {
    width: 85px; /* Játékosok - több hely a nyertes kiemeléshez */
}

#match-history-table th:nth-child(3) {
    width: 55px; /* Pontszámok - extra kompakt */
    text-align: center;
}

#match-history-table th:nth-child(4) {
    width: 35px; /* Játékmód - extra kompakt */
    text-align: center;
}

#match-history-table th:nth-child(5) {
    width: 30px; /* Részletek - extra kompakt */
    text-align: center;
}

/* Pontszámok oszlop speciális kezelése */
#match-history-table td:nth-child(1) {
    padding: 1px 2px;
    font-family: Arial, sans-serif;
    font-size: 10px;
    border-bottom: 1px solid #eee;
    height: 20px;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 65px;
    width: 65px;
}

#match-history-table td:nth-child(3) {
    padding: 1px 2px;
    font-family: Arial, sans-serif;
    font-size: 10px;
    border-bottom: 1px solid #eee;
    height: 20px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 55px;
}

#match-history-table td {
    padding: 1px 2px;
    font-family: Arial, sans-serif;
    font-size: 10px;
    border-bottom: 1px solid #eee;
    height: 20px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#match-history-table tr:hover {
    background-color: #f9f9f9;
}

/* --- 7"-OS ÉS KISEBB MOBILOK OPTIMALIZÁLÁSA --- */
@media screen and (max-width: 768px) and (max-height: 1024px) {
    #game-area {
        padding: 3px;
        max-width: 100vw;
        overflow-x: hidden;
        display: flex;
        justify-content: center;
        align-items: center;
    }
    
    .main-frame {
        padding: 4px;
        border-radius: 8px;
        max-width: 98vw;
        margin: 0 auto;
        width: fit-content;
    }
    
    .inner-board {
        max-width: 96vw;
        overflow-x: auto;
        margin: 0 auto;
        width: fit-content;
    }
    
    table {
        max-width: 94vw;
        font-size: 14px;
        margin: 0 auto;
        width: 94vw !important;
        table-layout: fixed;
    }
    
    th {
        padding: 4px 3px;
        font-size: 12px;
        width: auto !important;
        white-space: nowrap;
    }
    
    td {
        width: auto !important;
        height: 32px;
        min-width: 48px;
    }
    
    .label {
        width: 95px !important;
        font-size: 11px;
        min-width: 95px;
    }
    
    .cell-val {
        font-size: 14px;
    }
    
    /* BUBORÉKOK - FINOM EGYMÁSRA CSÚSZÁS ÉS KÉPERNYŐN BELÜLI TARTÁS */
    .comic-bubble {
        width: 55px;
        height: 55px;
        font-size: 20px;
        border-width: 2px;
    }
    
    /* BUBORÉKOK - NEM MÓDOSÍTJUK A POZÍCIÓT, HAGYJUK A JS DYNAMIKUS POZÍCIÓT */
    /* Csak a jobb oldali celláknál korlátozzuk a kilógást overflow-val */
    td:last-child .bubble-picker-radial {
        overflow: visible;
        max-width: 120px;
        margin-left: -10px;
    }
    
    /* MOBIL SPECIFIKUS KORLÁTOZÁS - JOBB OLDALI KILÓGÁS MEGELŐZÉSE */
    @media screen and (max-width: 768px) {
        td:last-child .bubble-picker-radial {
            overflow: visible;
            max-width: 100px;
            margin-left: -15px;
        }
        
        /* BUBORÉKOK KÖZELEBB EGYMÁSHOZ MOBILON - RADIUS CSÖKKENTÉSE */
        .bubble-picker-radial.active .comic-bubble {
            transform: scale(0.9) !important;
        }
        
        /* MECCSTÖRTÉNET TÁBLÁZAT MOBIL OPTIMALIZÁLÁS */
        #match-history-table th {
            padding: 1px 2px !important;
            font-size: 8px !important;
        }
        
        #match-history-table td {
            padding: 1px 2px !important;
            font-size: 9px !important;
            height: 18px !important;
        }
        
        #match-history-table th:nth-child(1) { width: 55px !important; }
        #match-history-table th:nth-child(2) { width: 70px !important; }
        #match-history-table th:nth-child(3) { width: 45px !important; }
        #match-history-table th:nth-child(4) { width: 30px !important; }
        #match-history-table th:nth-child(5) { width: 25px !important; }
    }
    
    #footer-container {
        margin-top: 3px;
        padding: 0 5px;
        width: 100%;
        max-width: 98vw;
        margin-left: auto;
        margin-right: auto;
    }
    
    #game-exit-btn {
        padding: 8px 15px;
        font-size: 14px;
        bottom: 10px;
        right: 10px;
    }
    
    #waiting-msg {
        font-size: 14px;
        padding: 4px 12px;
    }
}

/* --- KÜLÖN ÁLLÓ NEZET OPTIMALIZÁLÁSA --- */
@media screen and (max-width: 768px) and (max-height: 500px) {
    table {
        width: 95vw !important;
        max-width: 95vw !important;
    }
    
    th {
        min-width: 50px !important;
        padding: 4px 4px !important;
    }
    
    td {
        min-width: 52px !important;
        height: 35px !important;
    }
    
    .label {
        width: 100px !important;
        min-width: 100px !important;
    }
}

/* --- CUSTOM NUMPAD --- */
#custom-numpad {
    display: none;
    position: fixed !important;
    top: 35% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) scale(0.8);
    background: #fff !important;
    border: 5px solid #1a2a6c !important; 
    border-radius: 15px;
    padding: 15px;
    z-index: 2000000;
    width: 260px; 
    box-shadow: 0 15px 40px rgba(0,0,0,0.5);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    opacity: 0;
}

#custom-numpad.show { display: block !important; opacity: 1; transform: translate(-50%, -50%) scale(1); }

.numpad-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

.num-btn {
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f8f9fa;
    border: 2px solid #ddd;
    border-radius: 10px;
    font-family: 'Kalam', cursive;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.1s;
}
.num-btn:active { background: #e2e6ea; transform: scale(0.95); }

.num-btn.strike { 
    background-color: #f44336 !important; /* Piros */
    color: white !important;               /* Fehér — jel */
    border-color: #d32f2f !important;
}

.num-btn.confirm { 
    background-color: #4CAF50 !important; 
    color: white !important;               
    border-color: #388E3C !important;
    
    /* ELTÁVOLÍTJUK a fix magasságot és kényszerítést */
    grid-column: span 1 !important;
    height: auto !important; 
    aspect-ratio: auto !important;
    
    /* Átveszi a sima .num-btn alapértelmezett paddingját */
    padding: 15px !important; 
}


/* --- JÁTÉKOS VÁLTÓ OVERLAY --- */
#player-turn-overlay {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.5) rotate(-10deg);
    z-index: 1000000;
    width: 320px;
    padding: 30px;
    border: 8px solid rgba(255, 255, 255, 0.4);
    border-radius: 25px;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
    opacity: 0;
    transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    pointer-events: none;
}
#player-turn-overlay.visible { display: flex !important; opacity: 1; transform: translate(-50%, -50%) scale(1.1) rotate(-3deg); }

#player-turn-overlay h2 { font-family: 'Kalam', cursive; font-size: 2.8rem; margin: 0; text-shadow: 3px 3px 0px rgba(0,0,0,0.2); }

/* --- EREDMÉNYJELZŐ SCREEN (GAME OVER) --- */
#end-screen {
    position: fixed !important;
    top: 0 !important; 
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    background: rgba(0, 0, 0, 0.88) !important;
    z-index: 10000002;
    display: none;
    flex-direction: column;
    align-items: center !important;
    justify-content: center !important;
    backdrop-filter: blur(10px);
    opacity: 0;
    transition: opacity 0.5s ease;
    margin: 0 !important;
    padding: 20px !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    transform: none !important;
    text-align: center !important;
    left: 0px !important;
    margin-left: 0px !important;
    float: none !important;
}

#end-screen.visible { 
    opacity: 1 !important; 
    display: flex !important; 
    align-items: center !important;
    justify-content: center !important;
    text-align: center !important;
    left: 0px !important;
    margin-left: 0px !important;
    transform: none !important;
    float: none !important;
}

/* Erőltetett középre igazítás minden tartalomra */
#end-screen > * {
    margin-left: auto !important;
    margin-right: auto !important;
    text-align: center !important;
    left: 0 !important;
    right: 0 !important;
}

/* Body centering teljes letiltása, amikor az end-screen látható */
body:has(#end-screen.visible) {
    align-items: flex-start !important;
    padding-left: 0 !important;
    margin: 0 !important;
    text-align: left !important;
    justify-content: flex-start !important;
    display: block !important;
}

/* Extra fix minden esetre */
html:has(#end-screen.visible) {
    text-align: left !important;
}

/* Erőltetett középre igazítás az end-screen tartalmára */
#end-screen.visible > * {
    margin-left: auto !important;
    margin-right: auto !important;
    text-align: center !important;
}

.cup-img { width: 160px; height: auto; filter: drop-shadow(0 0 25px rgba(253, 187, 45, 0.6)); animation: cupFloat 3s infinite ease-in-out; }

.ribbon {
    position: relative;
    background: #b21f1f;
    color: white;
    padding: 12px 50px;
    font-family: 'Kalam', cursive;
    font-size: 2.2rem;
    font-weight: bold;
    box-shadow: 0 6px 20px rgba(0,0,0,0.4);
    margin: 20px 0;
    border-radius: 4px;
}
.ribbon::before, .ribbon::after { content: ''; position: absolute; bottom: -12px; border: 18px solid #8b1818; z-index: -1; }
.ribbon::before { left: -25px; border-left-color: transparent; }
.ribbon::after { right: -25px; border-right-color: transparent; }

.winner-info { color: white; font-family: 'Kalam', cursive; text-align: center; }
#final-scores-list { font-size: 2.5rem; font-weight: bold; color: #fdbb2d; letter-spacing: 5px; display: block; margin-top: 10px; }

.end-btn {
    background: linear-gradient(to bottom, #fdbb2d, #f9a825);
    color: #1a2a6c;
    border: 3px solid #1a2a6c;
    padding: 15px 40px;
    font-family: 'Kalam', cursive;
    font-size: 1.4rem;
    font-weight: 800;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 6px 0 #b8962d;
    margin-top: 30px;
}
.end-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #b8962d; }

/* Pontszám doboz a szalag alatt */
.score-pills-container {
    background: rgba(255, 255, 255, 0.8) !important; /* Áttetsző fehér */
    padding: 2px 40px !important; /* Minimális függőleges hely */
    border-radius: 50px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    margin-top: -30px !important; /* Rácsúsztatás a szalagra */
    z-index: 10000001 !important; /* A szalag fölé kényszerítve */
    backdrop-filter: blur(5px);
    border: 1px solid rgba(255,255,255,0.4);
    height: auto;
    min-height: 40px; /* Hogy épp csak beleférjenek a számok */
    display: flex;
    align-items: center;
    justify-content: center;
}

/* A számok színe - kényszerített fekete */
#final-scores-list {
    font-size: 2rem !important;
    font-weight: 900 !important;
    color: #000000 !important; /* Brutál fekete */
    letter-spacing: 5px;
    font-family: 'Kalam', cursive;
    margin: 0 !important;
    line-height: 1 !important; /* Megszünteti a felesleges alsó/felső térközt a betű körül */
}


/* Gombok elrendezése */
.end-button-group {
    display: flex;
    gap: 20px;
    margin-top: 40px;
}

.primary-btn {
    background: linear-gradient(to bottom, #fdbb2d, #f9a825) !important;
    color: #1a2a6c !important;
}

.secondary-btn {
    background: white !important;
    color: #333 !important;
    box-shadow: 0 6px 0 #999 !important;
}

/* Pontnéző Popup Stílusa */
.review-modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.7);
    z-index: 10000002;
    display: none;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
}

.review-content {
    background: #f4f7f6;
    padding: 20px;
    border-radius: 15px;
    width: 90%;
    max-width: 500px;
    text-align: center;
}

/* Tűzijáték rakéta stílus (a konfetti helyett) */
.firework {
    position: absolute;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 10000002;
}

/* --- PONTBEVITELI EFFEKTEK --- */
.score-pop-effect {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 24px;
    font-weight: bold;
    color: #1a2a6c;
    z-index: 10002;
    pointer-events: none;
    animation: scorePop 0.8s ease-out forwards;
}

@keyframes scorePop {
    0% {
        transform: translate(-50%, -50%) scale(0) rotate(0deg);
        opacity: 0;
    }
    50% {
        transform: translate(-50%, -50%) scale(1.5) rotate(180deg);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(1) rotate(360deg);
        opacity: 0;
    }
}

.score-sparkle {
    position: absolute;
    width: 4px;
    height: 4px;
    background: #fdbb2d;
    border-radius: 50%;
    pointer-events: none;
    z-index: 10001;
    animation: sparkle 1s ease-out forwards;
}

@keyframes sparkle {
    0% {
        transform: translate(0, 0) scale(0);
        opacity: 1;
    }
    100% {
        transform: translate(var(--tx), var(--ty)) scale(1);
        opacity: 0;
    }
}

/* --- EGYEBEK --- */
#status-exit-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 8px 20px;
    gap: 15px;
}

#waiting-msg {
    font-family: 'Kalam', cursive;
    font-size: 1.2rem;
    color: #333;
    background: rgba(255, 255, 255, 0.9);
    padding: 6px 20px;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    width: fit-content;
    text-align: left;
    margin: 0;
    flex: 1;
}

#game-exit-btn {
    background: linear-gradient(135deg, #e74c3c, #c0392b);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-family: 'Kalam', cursive;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    margin: 0;
    flex-shrink: 0;
}

#game-exit-btn:hover {
    background: linear-gradient(135deg, #c0392b, #a93226);
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.4);
}

#game-exit-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.active-player-header { animation: playerBlink 1.5s infinite ease-in-out; }

@keyframes playerBlink { 0%, 100% { filter: brightness(1); } 50% { filter: brightness(1.3); } }
@keyframes cupFloat { 0%, 100% { transform: translateY(0) rotate(0deg); } 50% { transform: translateY(-20px) rotate(3deg); } }


/* Numpad rács és gombok stílusa */
.numpad-grid { 
    display: grid; 
    grid-template-columns: repeat(3, 1fr); 
    gap: 10px; 
    margin-top: 10px; 
}
.num-btn { 
    padding: 15px; 
    background: #eee; 
    border: 2px solid #ccc; 
    border-radius: 8px; 
    font-size: 20px; 
    font-weight: bold; 
    cursor: pointer; 
    text-align: center; 
}
.num-btn.confirm { 
    grid-column: span 2; 
    background: #ffcc00 !important; 
    color: #333 !important; 
    border-color: #e6b800 !important;
}
.num-btn.strike { 
    background: #ff4d4d !important; 
    color: white !important; 
    border-color: #cc0000 !important;
}

/* End Screen (Kupa és Ribbon) - DUPLICATE REMOVED - using the definition above */
.cup-img { width: 150px; margin-bottom: 20px; }
.ribbon { background: #b21f1f; color: white; padding: 10px 40px; font-size: 2.5rem; font-family: 'Kalam', cursive; border-radius: 4px; box-shadow: 0 5px 15px rgba(0,0,0,0.3); margin-bottom: 15px; }
.winner-info { color: white; text-align: center; font-family: 'Kalam', cursive; }
#final-scores-list { font-size: 2rem; display: block; margin: 10px 0; color: #fdbb2d; }

/* --- YEAH KÉPREGÉNY FELIRAT --- */
.royal-yeah-overlay {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.5) rotate(-15deg);
    z-index: 2000000;
    padding: 40px 80px;
    background: linear-gradient(135deg, #ff6b6b, #ee5a24);
    border: 12px solid #ffffff;
    border-radius: 20px;
    color: white;
    font-family: 'Kalam', cursive;
    font-size: 6rem;
    font-weight: 900;
    text-shadow: 
        8px 8px 0px #000000,
        -2px -2px 0px #000000,
        2px -2px 0px #000000,
        -2px 2px 0px #000000;
    box-shadow: 
        0 0 0 8px #000000,
        0 20px 40px rgba(0,0,0,0.8),
        inset 0 -10px 20px rgba(0,0,0,0.3);
    opacity: 0;
    pointer-events: none;
    animation: yeahPop 2s ease-out forwards;
}

.royal-yeah-overlay::before {
    content: '';
    position: absolute;
    top: -20px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 30px solid transparent;
    border-right: 30px solid transparent;
    border-bottom: 40px solid #ffffff;
    z-index: -1;
}

.royal-yeah-overlay::after {
    content: '';
    position: absolute;
    bottom: -15px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 25px solid transparent;
    border-right: 25px solid transparent;
    border-top: 35px solid #ffffff;
    z-index: -1;
}

@keyframes yeahPop {
    0% {
        transform: translate(-50%, -50%) scale(0.3) rotate(-15deg);
        opacity: 0;
    }
    20% {
        transform: translate(-50%, -50%) scale(1.4) rotate(5deg);
        opacity: 1;
    }
    40% {
        transform: translate(-50%, -50%) scale(1.2) rotate(-3deg);
        opacity: 1;
    }
    60% {
        transform: translate(-50%, -50%) scale(1.3) rotate(2deg);
        opacity: 1;
    }
    80% {
        transform: translate(-50%, -50%) scale(1.1) rotate(-1deg);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(1) rotate(0deg);
        opacity: 0;
    }
}

