/* ==========================================================================
   VARIABILI E RESET GLOBAL
   ========================================================================== */
:root {
    --primary-gradient: linear-gradient(135deg, #2575fc 0%, #1a4cb0 100%);
    --play-gradient: linear-gradient(135deg, #ff9800 0%, #fe5115 100%);
    --bg-dark: #0f172a;
    --bg-card: #ffffff;
    --text-main: #1e293b;
    --text-light: #64748b;
    --accent: #2ecc71;
    --danger: #ef4444;
    --radius-lg: 16px;
    --radius-md: 12px;
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 10px 25px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.2);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

body,
html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--bg-dark);
    color: var(--text-main);
}

/* ==========================================================================
   SCHERMATE PRINCIPALI E LOBBY
   ========================================================================== */
#mainMenu,
#multiplayerLobby,
#roomWaitingScreen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--primary-gradient);
    color: white;
    z-index: 20;
    padding: 20px;
}

#roomWaitingScreen {
    gap: 10px;
}

#playersList {
    list-style: none;
    background: rgba(0, 0, 0, 0.2);
    padding: 20px;
    border-radius: 10px;
    width: 90%;
    max-width: 300px;
    margin: 20px 0;
}

#playersList li {
    padding: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 18px;
}

#mainMenu {
    background: radial-gradient(circle at center, #1e40af 0%, #0f172a 100%);
}

#menuTitle {
    font-size: 54px;
    font-weight: 800;
    margin-bottom: 40px;
    letter-spacing: -1px;
    text-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
    animation: floating 3s ease-in-out infinite;
}

/* Pulsanti stile Gaming-Moderno */
button {
    padding: 14px 32px;
    font-size: 18px;
    font-weight: 700;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: var(--shadow-md);
    width: 100%;
    max-width: 300px;
}

#buttonGame2 {
    background: var(--play-gradient);
    color: white;
    font-size: 22px;
    padding: 18px 40px;
}

#buttonGame2:hover {
    transform: scale(1.06) translateY(-2px);
    box-shadow: 0 15px 30px rgba(254, 81, 21, 0.4);
}

#mainMenu button:not(#buttonGame2) {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(8px);
    margin-top: 12px;
}

#mainMenu button:not(#buttonGame2):hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

#mainMenu button {
    width: 90%;
    /* Adattabile su mobile */
    max-width: 300px;
}

/* ==========================================================================
   CARDS E LOBBY MULTIPLAYER
   ========================================================================== */
.lobby-card {
    background: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 24px;
    border-radius: var(--radius-lg);
    margin: 14px 0;
    text-align: center;
    width: 100%;
    max-width: 340px;
    box-shadow: var(--shadow-lg);
}

.lobby-card h3 {
    margin-bottom: 16px;
    font-size: 20px;
    font-weight: 600;
}

.lobby-card input,
.popup-content input {
    width: 100%;
    padding: 14px;
    border-radius: var(--radius-md);
    border: 1px solid rgba(0, 0, 0, 0.1);
    background: #f8fafc;
    margin-bottom: 14px;
    font-size: 16px;
    color: var(--text-main);
    outline: none;
    transition: all 0.2s;
}

.lobby-card input:focus,
.popup-content input:focus {
    border-color: #2575fc;
    box-shadow: 0 0 0 3px rgba(37, 117, 252, 0.15);
    background: white;
}

.lobby-card input {
    text-align: center;
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 2px;
}

/* ==========================================================================
   OVERLAY & MODALI (Sicurezza, Classifiche, Autenticazione)
   ========================================================================== */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.75);
    color: white;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    z-index: 10;
    text-align: center;
    padding: 20px;
}

.overlay h1 {
    font-size: 36px;
}

.overlay p {
    font-size: 18px;
    max-width: 500px;
    line-height: 1.5;
}

.popup-content {
    background: var(--bg-card);
    padding: 40px;
    border-radius: var(--radius-lg);
    text-align: center;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
    color: var(--text-main);
    position: relative;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.popup-content h1,
.popup-content h2 {
    font-size: 28px;
    font-weight: 800;
    margin-bottom: 12px;
    color: #0f172a;
}

.popup-content p {
    color: var(--text-light);
    font-size: 15px;
    margin-bottom: 24px;
    line-height: 1.5;
}

/* Pulsanti di login specifici */
#magicLinkBtn {
    background: var(--primary-gradient);
    color: white;
    margin-top: 10px;
}

#magicLinkBtn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(37, 117, 252, 0.3);
}

.guest-btn {
    background: #f1f5f9 !important;
    color: #475569 !important;
    box-shadow: none !important;
    margin-top: 10px;
}

.guest-btn:hover {
    background: #e2e8f0 !important;
}

/* ==========================================================================
   UI DI GIOCO INTERNA (In-Game HUD)
   ========================================================================== */
#gameContainer {
    position: relative;
    width: 100vw;
    height: 100vh;
}

#ui-layer {
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    display: flex;
    gap: 10px;
    pointer-events: none;
    z-index: 5;
}

.icon-btn {
    pointer-events: auto;
    font-size: 18px;
    width: 46px;
    height: 46px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: var(--radius-md);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: all 0.2s;
}

.icon-btn:hover {
    background: white;
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* Schermate di stato del gioco (HUD overlays) */
#tutorialPanel,
#gameOverPanel {
    background: rgba(15, 23, 42, 0.85);
}

/* Tabella Punteggi Live / Multiplayer */
#liveScoreboard {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
    color: var(--text-main);
    padding: 12px 16px;
    /* Ridotto padding interno (prima era 20px) */
    border-radius: var(--radius-md);
    z-index: 10;
    pointer-events: none;
    min-width: 180px;
    /* Ridotta larghezza minima (prima era 240px) */
    max-width: 220px;
    /* Imposta un limite massimo */
    box-shadow: var(--shadow-md);
    border: 1px solid rgba(0, 0, 0, 0.05);
    transition: all 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#liveScoreboard h3 {
    margin-bottom: 12px;
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #0f172a;
}

#scoreTable {
    width: 100%;
    border-collapse: collapse;
}

#scoreTable th {
    font-size: 10px;
    color: var(--text-light);
    text-transform: uppercase;
    padding-bottom: 8px;
    border-bottom: 2px solid #f1f5f9;
}

#scoreTable td {
    padding: 6px 0;
    font-size: 15px;
    font-weight: 500;
    border-bottom: 1px solid #f1f5f9;
}

#liveScoreboard.center-zoomed {
    top: 50%;
    right: 50%;
    transform: translate(50%, -50%) scale(1.15);
    background: white;
    pointer-events: auto;
    box-shadow: var(--shadow-lg);
    padding: 30px;
}

/* Impostazioni */
#settingsPanel {
    position: fixed;
    top: 80px;
    right: 20px;
    background: white;
    padding: 18px;
    padding-bottom: 15px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 2000;
    width: 280px;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.setting-row {
    margin: 16px 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.setting-row label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-main);
}

.setting-row input[type="range"] {
    width: 100%;
    accent-color: #2575fc;
}

/* ==========================================================================
   ANIMAZIONI ED UTILITY
   ========================================================================== */
.blink {
    animation: blinker 1.5s linear infinite;
    margin-top: 20px;
    color: #f1c40f;
    font-weight: bold;
    pointer-events: auto;
    cursor: pointer;
}

@keyframes blinker {
    50% {
        opacity: 0.3;
    }
}

@keyframes floating {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

.hidden {
    display: none !important;
}

.hide-ui {
    display: none !important;
}

/* Assicura che i widget Iubenda non interferiscano con la UI di gioco */
#iubenda-cs-banner,
.iubenda-cs-container,
.iubenda-embed {
    z-index: 9999 !important;
}

/* Sostituisci il vecchio #cookiePrivacyLinks con questo */
#cookiePrivacyLinks {
    position: absolute;
    bottom: 10px;
    left: 0;
    width: 100%;
    z-index: 9999;
    font-size: 12px;
    /* Leggermente più piccolo su mobile */
    display: flex;
    justify-content: center;
    gap: 10px;
    padding: 5px;
}

/* 2. Il popup di autenticazione (overlay) quando è ATTIVO */
#authPopup {
    position: fixed;            /* Copre l'intero schermo sopra il Main Menu */
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85); /* Sfondo scuro semitrasparente */
    display: flex !important;   /* Forza il flex per centrare il box di login */
    justify-content: center;
    align-items: center;
    z-index: 99999;             /* Sta sopra a qualsiasi cosa nel Main Menu */
}

/* 3. Forza la sparizione del popup quando ha la classe .hidden */
#authPopup.hidden {
    display: none !important;   /* Vince su 'display: flex !important' */
}