:root {
    --bg-color: #0f172a;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --text-color: #f8fafc;
    --card-bg: #1e293b;
    --card-back: #334155;
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --matched-color: #10b981;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
    background-image: radial-gradient(circle at 50% -20%, #1e1b4b, var(--bg-color));
    /* padding-bottom: 60px; Spazio per evitare sovrapposizioni con l'ad banner */
}

.game-container {
    width: 100%;
    max-width: 600px;
    padding: 1rem 2rem 2rem 2rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    width: 100%;
}

.header-top {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    width: 100%;
}

.header-top h1 {
    grid-column: 2;
    text-align: center;
}

.music-btn {
    grid-column: 3;
    justify-self: end;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    border-radius: 50%;
    width: 45px;
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
    transition: transform 0.2s, background 0.2s;
}

.music-btn:hover {
    transform: scale(1.1);
    background: rgba(255, 255, 255, 0.1);
}

header h1 {
    font-size: 2.5rem;
    font-weight: 800;
    background: linear-gradient(to right, #3b82f6, #8b5cf6);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.stats {
    display: flex;
    justify-content: space-between;
    width: 100%;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 1rem;
    padding: 1rem 2rem;
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.level-box, .timer-box, .lives-box, .score-box {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.level-box > span:first-child, .timer-box > span:first-child, .lives-box > span:first-child, .score-box > span:first-child {
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #94a3b8;
}

.level-box > span:last-child, .timer-box > span:last-child, .lives-box > span:last-child, .score-box > span:last-child {
    font-size: 1.5rem;
    font-weight: 800;
}

#score-wrapper {
    display: flex;
    align-items: center;
}

#score {
    font-size: 2.2rem !important;
    font-weight: 800;
    color: #fbbf24 !important;
    text-shadow: 0 0 15px rgba(251, 191, 36, 0.8);
    line-height: 1;
}

.timer-box.warning span:last-child {
    color: #ef4444;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    perspective: 1000px;
}

.card {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    cursor: pointer;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.card.flipped {
    transform: rotateY(180deg);
}

.card.matched .card-front {
    background-color: var(--matched-color);
    box-shadow: 0 0 15px rgba(16, 185, 129, 0.5);
}

.card.jolly-matched .card-front {
    background-color: #f59e0b;
    box-shadow: 0 0 20px rgba(245, 158, 11, 0.8);
    animation: pulse-jolly 1s infinite;
}

@keyframes pulse-jolly {
    0%, 100% { box-shadow: 0 0 15px rgba(245, 158, 11, 0.5); }
    50% { box-shadow: 0 0 25px rgba(245, 158, 11, 1); }
}

.card.jolly-revealed .card-front {
    background-color: #8b5cf6;
    box-shadow: 0 0 15px rgba(139, 92, 246, 0.5);
}

.card.bomb-exploded .card-front {
    background-color: #ef4444;
    box-shadow: 0 0 20px rgba(239, 68, 68, 0.8);
}

.card.time-bonus-activated .card-front {
    background-color: #10b981;
    box-shadow: 0 0 20px rgba(16, 185, 129, 0.8);
    animation: pulse-bonus 1s infinite;
}

@keyframes pulse-bonus {
    0%, 100% { box-shadow: 0 0 15px rgba(16, 185, 129, 0.5); }
    50% { box-shadow: 0 0 25px rgba(16, 185, 129, 1); }
}

.bonus-time-anim span:last-child {
    color: #10b981 !important;
    transform: scale(1.3);
    transition: transform 0.3s, color 0.3s;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-10px); }
    40% { transform: translateX(10px); }
    60% { transform: translateX(-10px); }
    80% { transform: translateX(10px); }
}

.shake {
    animation: shake 0.5s cubic-bezier(.36,.07,.19,.97) both;
}

.card-front, .card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 1rem;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 3rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    user-select: none;
}

.card-back {
    background: linear-gradient(135deg, var(--card-back), #1e293b);
    border: 1px solid rgba(255, 255, 255, 0.05);
    background-image: radial-gradient(#475569 1px, transparent 1px);
    background-size: 10px 10px;
}

.card-front {
    background-color: var(--card-bg);
    transform: rotateY(180deg);
    border: 1px solid var(--glass-border);
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    padding: 3rem;
    border-radius: 1.5rem;
    text-align: center;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    transform: scale(1);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    max-height: 85vh;
    overflow-y: auto;
}

.modal.hidden .modal-content {
    transform: scale(0.8);
}

.modal h2 {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    background: linear-gradient(to right, #10b981, #3b82f6);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

#game-over-modal h2 {
    background: linear-gradient(to right, #ef4444, #f59e0b);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.modal p {
    font-size: 1.2rem;
    color: #cbd5e1;
    margin-bottom: 2rem;
}

.modal button {
    background-color: var(--primary);
    color: white;
    border: none;
    padding: 1rem 2rem;
    font-size: 1.2rem;
    font-weight: 600;
    border-radius: 0.75rem;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
    outline: none;
}

.modal button:hover {
    background-color: var(--primary-hover);
    transform: translateY(-2px);
}

.modal button:active {
    transform: translateY(0);
}

/* Power Box e Pulsante Super Potere */
.power-box {
    display: flex;
    flex-direction: column;
    align-items: center;
}
.power-box span:first-child {
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #94a3b8;
}
.power-btn {
    background: linear-gradient(to right, #8b5cf6, #ec4899);
    border: none;
    border-radius: 50%;
    width: 35px;
    height: 35px;
    font-size: 1.2rem;
    cursor: pointer;
    box-shadow: 0 0 15px rgba(236, 72, 153, 0.6);
    transition: transform 0.2s, box-shadow 0.2s;
    animation: pulse-magic 2s infinite;
}
.power-btn:disabled {
    background: #334155;
    box-shadow: none;
    animation: none;
    cursor: not-allowed;
    opacity: 0.5;
}
.power-btn:not(:disabled):hover {
    transform: scale(1.1);
    box-shadow: 0 0 25px rgba(236, 72, 153, 0.9);
}
@keyframes pulse-magic {
    0%, 100% { box-shadow: 0 0 10px rgba(236, 72, 153, 0.5); }
    50% { box-shadow: 0 0 20px rgba(236, 72, 153, 0.8); }
}

/* Slot Machine */
.slot-content {
    padding: 2rem;
}
.slot-machine {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin: 2rem 0;
}
.reel {
    width: 70px;
    height: 90px;
    background: #1e293b;
    border: 2px solid var(--glass-border);
    border-radius: 1rem;
    font-size: 2.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: inset 0 10px 20px rgba(0,0,0,0.5);
    overflow: hidden;
    position: relative;
    user-select: none;
}
.reel.spinning {
    animation: slot-spin 0.1s linear infinite;
}
@keyframes slot-spin {
    0% { transform: translateY(-5px); }
    50% { transform: translateY(5px); }
    100% { transform: translateY(-5px); }
}
.slot-result {
    font-size: 1.2rem;
    height: 1.5rem;
    margin-bottom: 1.5rem;
    font-weight: bold;
}
.win-text {
    color: #10b981;
    animation: pulse-bonus 1s infinite;
}
.lose-text {
    color: #94a3b8;
}

/* X-Ray Animation */
.card.xray-active .card-front {
    background-color: #8b5cf6;
    box-shadow: 0 0 20px rgba(139, 92, 246, 0.8);
}


@media (max-width: 480px) {
    .stats {
        padding: 0.8rem 0.5rem;
        gap: 0.5rem;
    }
    .level-box > span:first-child, .timer-box > span:first-child, .lives-box > span:first-child, .score-box > span:first-child {
        font-size: 0.7rem;
    }
    #score {
        font-size: 1.8rem !important;
    }
    #lives {
        white-space: nowrap;
        letter-spacing: -2px;
    }
    header h1 {
        font-size: 1.75rem;
    }
    .music-btn {
        width: 36px;
        height: 36px;
        font-size: 1.2rem;
    }
    .grid {
        gap: 0.5rem;
    }
    .card-front, .card-back {
        font-size: 2rem;
        border-radius: 0.5rem;
    }
    header {
        gap: 0.5rem;
    }
    .game-container {
        padding: 0.5rem;
        gap: 0.8rem;
    }
    .start-screen {
        padding: 1rem;
    }
    .modal-content {
        padding: 1.5rem;
    }
    .start-title {
        font-size: 2.2rem;
        margin-bottom: 1rem;
    }
    .rules-text {
        font-size: 0.95rem;
        padding: 1rem;
        margin-bottom: 1.5rem;
    }
    .play-btn {
        padding: 1rem 2rem;
        font-size: 1.2rem;
    }
    .modal h2 {
        font-size: 1.8rem;
    }
}

/* Banner Pubblicitario */
.ad-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 60px;
    background-color: rgba(15, 23, 42, 0.95);
    border-top: 1px solid var(--glass-border);
    display: none; /* Nascondi momentaneamente */
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(10px);
}

.ad-banner span {
    color: #94a3b8;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

@media (max-width: 480px) {
    .ad-banner span {
        font-size: 0.7rem;
        text-align: center;
        padding: 0 1rem;
    }
}

/* Utilities & Start Screen */
.d-none {
    display: none !important;
}

.start-screen {
    width: 100%;
    max-width: 600px;
    padding: 2rem;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 50;
}

.start-title {
    font-size: 3rem;
    font-weight: 800;
    background: linear-gradient(to right, #3b82f6, #8b5cf6);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 2rem;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.game-lang-switch {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 0.5rem;
    border-radius: 0.5rem;
    outline: none;
    cursor: pointer;
    font-weight: 600;
    font-size: 1rem;
    backdrop-filter: blur(5px);
    transition: background 0.2s;
}
.game-lang-switch:hover {
    background: rgba(255, 255, 255, 0.2);
}
.game-lang-switch option {
    background: #1e293b;
    color: white;
}

.rules-text {
    font-size: 1.1rem;
    color: #cbd5e1;
    margin-bottom: 2.5rem;
    line-height: 1.6;
    text-align: left;
    background: rgba(0,0,0,0.2);
    padding: 1.5rem;
    border-radius: 1rem;
}

.play-btn {
    background: linear-gradient(to right, #10b981, #3b82f6);
    color: white;
    border: none;
    padding: 1.2rem 3rem;
    font-size: 1.5rem;
    font-weight: 800;
    border-radius: 1rem;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.4);
}

.play-btn:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 8px 25px rgba(16, 185, 129, 0.6);
}

.arcade-input {
    background: rgba(0, 0, 0, 0.4);
    border: 2px solid #3b82f6;
    color: #fbbf24;
    font-size: 1.5rem;
    font-weight: 800;
    text-align: center;
    padding: 0.8rem;
    border-radius: 0.5rem;
    width: 100%;
    outline: none;
    text-transform: uppercase;
    letter-spacing: 3px;
    box-shadow: inset 0 2px 10px rgba(0,0,0,0.5);
    transition: all 0.3s;
}

.arcade-input:focus {
    border-color: #f59e0b;
    box-shadow: inset 0 2px 10px rgba(0,0,0,0.5), 0 0 15px rgba(245, 158, 11, 0.5);
}

/* Leaderboard Nuova */
.arcade-leaderboard {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 50vh;
    overflow-y: auto;
    padding-right: 5px;
}
.arcade-leaderboard::-webkit-scrollbar {
    width: 6px;
}
.arcade-leaderboard::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.2);
    border-radius: 10px;
}
.arcade-leaderboard::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 10px;
}

.leaderboard-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.05);
    padding: 0.8rem 1rem;
    border-radius: 0.8rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: transform 0.2s, background 0.2s;
}

.leaderboard-row:hover {
    transform: scale(1.02);
    background: rgba(255, 255, 255, 0.1);
}

.leaderboard-row.top-1 {
    background: linear-gradient(to right, rgba(251, 191, 36, 0.2), rgba(251, 191, 36, 0.05));
    border-color: rgba(251, 191, 36, 0.5);
    box-shadow: 0 0 15px rgba(251, 191, 36, 0.2);
}

.leaderboard-row.top-2 {
    background: linear-gradient(to right, rgba(148, 163, 184, 0.2), rgba(148, 163, 184, 0.05));
    border-color: rgba(148, 163, 184, 0.5);
}

.leaderboard-row.top-3 {
    background: linear-gradient(to right, rgba(180, 83, 9, 0.2), rgba(180, 83, 9, 0.05));
    border-color: rgba(180, 83, 9, 0.5);
}

.leaderboard-row.current-player {
    border-color: #10b981;
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.3);
}

.lb-rank {
    font-size: 1.5rem;
    font-weight: 800;
    width: 40px;
    text-align: center;
}

.top-1 .lb-rank { color: #fbbf24; text-shadow: 0 0 10px rgba(251,191,36,0.5); }
.top-2 .lb-rank { color: #94a3b8; }
.top-3 .lb-rank { color: #b45309; }

.lb-name {
    flex-grow: 1;
    font-size: 1.2rem;
    font-weight: 600;
    text-align: left;
    margin-left: 1rem;
    font-family: 'Outfit', sans-serif;
    color: #f8fafc;
}
.current-player .lb-name {
    color: #10b981;
}

.lb-score {
    font-family: monospace;
    font-size: 1.4rem;
    font-weight: bold;
    color: #e2e8f0;
}
.top-1 .lb-score { color: #fbbf24; }

/* Splash Screen */
.splash-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #ffffff;
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 1;
    transition: opacity 0.5s ease-out;
}

.splash-screen.fade-out {
    opacity: 0;
    pointer-events: none;
}

.splash-content {
    text-align: center;
    animation: zoom-in-out 3.5s forwards;
}

.splash-text {
    color: #1e293b;
    font-size: 1.2rem;
    margin-bottom: 0.5rem;
    font-weight: 400;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.splash-logo-img {
    max-width: 80%;
    max-height: 120px;
    height: auto;
    margin: 1rem auto;
    display: block;
}

.splash-subtext {
    color: #1e293b;
    font-size: 1.1rem;
    margin-top: 0.5rem;
    font-weight: 400;
    letter-spacing: 1px;
    text-transform: uppercase;
}

@keyframes zoom-in-out {
    0% { transform: scale(0.8); opacity: 0; }
    20% { transform: scale(1); opacity: 1; }
    80% { transform: scale(1); opacity: 1; }
    100% { transform: scale(1.1); opacity: 0; }
}
