/* ==============================================
   Fruit Ninja - Stili principali
   ============================================== */

/* Reset e setup base */
html,
body {
    padding: 0;
    margin: 0;
    overflow: hidden;
    overscroll-behavior: none;
    font-family: Arial, sans-serif;
}

/* Touch/selection lock solo sul canvas di gioco, non sugli overlay HTML */
#game {
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* Container del gioco */
#game {
    width: 100vw;
    height: 100vh;
    background-color: #005832;
    background-image: url('../images/background.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

/* Overlay interattivi: ripristina touch e selezione */
#splash-screen,
.game-over-popup,
.leaderboard-popup {
    touch-action: auto;
    -webkit-user-select: auto;
    user-select: auto;
}

.game-over-input {
    -webkit-user-select: text;
    user-select: text;
    touch-action: auto;
}

.game-stripes {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: auto;
    z-index: 50;
    pointer-events: none;
}

/* ==============================================
   Score Container
   ============================================== */

#score-container {
    position: fixed;
    top: 3.5%;
    left: 3.5%;
    width: clamp(120px, 8.5vw, 329px);
    height: clamp(66px, 4.7vw, 182px);
    background-color: #FFFFFF;
    border-radius: 100px;
    padding: 2px 16px 6px 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 60;
    pointer-events: none;
    box-sizing: border-box;
}

#score-container.hidden {
    display: none;
}

#score-value {
    font-family: 'Barlow', sans-serif;
    font-weight: 700;
    font-style: normal;
    font-size: clamp(32px, 3.3vw, 128px);
    line-height: 100%;
    letter-spacing: 0;
    text-align: center;
    color: #BD1923;
}

/* ==============================================
   Timer Container
   ============================================== */

#timer-container {
    position: fixed;
    top: 3.5%;
    right: 3.5%;
    width: clamp(120px, 8.5vw, 329px);
    height: clamp(66px, 4.7vw, 182px);
    background-color: #FFFFFF;
    border-radius: 100px;
    padding: 2px 16px 6px 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 60;
    pointer-events: none;
    box-sizing: border-box;
}

#timer-container.hidden {
    display: none;
}

#timer-value {
    font-family: 'Barlow', sans-serif;
    font-weight: 700;
    font-style: normal;
    font-size: clamp(32px, 3.3vw, 128px);
    line-height: 100%;
    letter-spacing: 0;
    text-align: center;
    color: #005832;
}

#timer-container.timer-warning #timer-value {
    color: #BD1923;
}

/* ==============================================
   Lives Container
   ============================================== */

#lives-container {
    position: fixed;
    top: calc(3.5% + clamp(66px, 4.7vw, 182px) + 10px);
    right: 3.5%;
    display: flex;
    gap: clamp(4px, 0.5vw, 8px);
    z-index: 60;
    pointer-events: none;
}

#lives-container.hidden {
    display: none;
}

.life-heart {
    width: clamp(30px, 2.8vw, 56px);
    height: auto;
    transition: opacity 0.3s, transform 0.3s;
}

.life-heart.lost {
    opacity: 0.2;
    transform: scale(0.8);
}

/* ==============================================
   Combo Popup
   ============================================== */

.combo-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 70;
    pointer-events: none;
    font-family: 'Barlow', sans-serif;
    font-weight: 800;
    font-style: italic;
    font-size: clamp(36px, 5vw, 80px);
    color: #FFFFFF;
    text-shadow: 0 3px 12px rgba(0, 0, 0, 0.5), 0 0 40px rgba(64, 167, 45, 0.6);
    opacity: 0;
    transition: none;
}

.combo-popup.hidden {
    display: none;
}

@keyframes comboAppear {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.5);
    }
    20% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.2);
    }
    40% {
        transform: translate(-50%, -50%) scale(1);
    }
    80% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1) translateY(0);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.8) translateY(-30px);
    }
}

/* ==============================================
   Splash Screen
   ============================================== */

#splash-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: linear-gradient(180deg, #135B3C 0%, #022D1A 100%);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    z-index: 100;
    font-family: 'Barlow', sans-serif;
}

#splash-screen.hidden {
    display: none;
}

.splash-rainbow {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    width: auto;
    z-index: 101;
    pointer-events: none;
    object-fit: cover;
    object-position: right center;
    transition: opacity 0.5s ease;
}

.splash-content {
    position: relative;
    z-index: 102;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: clamp(1rem, 3vw, 2rem);
    text-align: center;
    width: 100%;
    box-sizing: border-box;
}

.splash-logo {
    width: clamp(100px, 12vw, 200px);
    height: auto;
    margin-bottom: clamp(20px, 4vh, 50px);
}

.splash-title-img {
    width: clamp(220px, 30vw, 460px);
    height: auto;
    margin-bottom: clamp(16px, 3vh, 36px);
}

.splash-subtitle {
    color: #FFFFFF;
    font-family: 'Barlow', sans-serif;
    font-style: normal;
    font-weight: 700;
    font-size: clamp(24px, 4vw, 64px);
    line-height: 100%;
    text-align: center;
    margin: 0 0 clamp(10px, 2vh, 24px) 0;
    max-width: 90%;
}

.splash-description {
    color: #FFFFFF;
    font-family: 'Barlow', sans-serif;
    font-style: normal;
    font-weight: 500;
    font-size: clamp(12px, 1.5vw, 22px);
    line-height: 140%;
    text-align: center;
    margin: 0 0 clamp(1rem, 2vw, 2rem) 0;
    max-width: 600px;
    opacity: 0.85;
}

.splash-info-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.splash-description .text-pink {
    color: #F48399;
}

.splash-description .text-green {
    color: #40A72D;
}

.splash-description .text-yellow {
    color: #FFC511;
}

.splash-buttons {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(0.6rem, 1.2vw, 1rem);
}

#start-button {
    font-family: 'Barlow', sans-serif;
    font-weight: 700;
    font-size: clamp(16px, 2vw, 32px);
    background-color: #ffffff;
    color: #005832;
    border: none;
    border-radius: 100px;
    padding: clamp(10px, 1.5vh, 20px) clamp(32px, 5vw, 80px);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s, background-color 0.3s ease;
}

#start-button:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 20px rgba(255, 255, 255, 0.3);
}

#start-button:active {
    transform: scale(0.98);
}

.splash-leaderboard-btn {
    color: #FFFFFF;
    font-family: 'Barlow', sans-serif;
    font-weight: 600;
    font-size: clamp(0.85rem, 1.8vw, 1.1rem);
    text-decoration: underline;
    cursor: pointer;
    transition: opacity 0.2s;
}

.splash-leaderboard-btn:hover {
    opacity: 0.8;
}

.splash-stripes {
    width: 100%;
    height: auto;
    display: block;
}

/* ==============================================
   Game Over Popup
   ============================================== */

.game-over-popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 90;
    font-family: 'Barlow', sans-serif;
    padding: 1rem;
    box-sizing: border-box;
    opacity: 0;
    animation: fadeInOverlay 0.3s ease forwards;
}

.game-over-popup.hidden {
    display: none;
}

@keyframes fadeInOverlay {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes scaleInPopup {
    from {
        opacity: 0;
        transform: scale(0.85);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.game-over-popup-box {
    width: clamp(280px, 32vw, 889px);
    max-width: calc(100vw - 2rem);
    max-height: 90vh;
    background-color: #FFFFFF;
    border: 3px solid #005832;
    border-radius: 36px;
    padding: clamp(28px, 3.2vw, 60px) clamp(28px, 3.4vw, 64px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: clamp(20px, 3.7vw, 70px);
    box-sizing: border-box;
    overflow-y: auto;
    overflow-x: hidden;
    animation: scaleInPopup 0.3s ease forwards;
}

.game-over-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(4px, 0.5vw, 10px);
    width: 100%;
}

.game-over-title {
    font-family: 'Barlow', sans-serif;
    font-weight: 700;
    font-size: clamp(18px, 2.2vw, 40px);
    color: #005832;
    margin: 0;
    text-align: center;
}

.game-over-score {
    font-family: 'Barlow', sans-serif;
    font-weight: 700;
    font-size: clamp(36px, 5vw, 80px);
    color: #BD1923;
    margin: 0;
    line-height: 1;
    text-align: center;
}

.game-over-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(16px, 2vw, 28px);
    width: 100%;
}

.game-over-step.hidden {
    display: none;
}

.game-over-saved-msg {
    font-family: 'Barlow', sans-serif;
    font-weight: 600;
    font-size: clamp(13px, 1.3vw, 20px);
    color: #005832;
    margin: 0;
    text-align: center;
}

.game-over-form {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: clamp(6px, 0.8vw, 14px);
    width: 100%;
}

.game-over-label {
    font-family: 'Barlow', sans-serif;
    font-weight: 700;
    font-size: clamp(13px, 1.3vw, 22px);
    color: #005832;
    display: block;
    width: 100%;
    text-align: left;
    margin: 0;
}

.game-over-input {
    width: 100%;
    box-sizing: border-box;
    padding: clamp(10px, 1vw, 16px) clamp(12px, 1.2vw, 20px);
    font-family: 'Barlow', sans-serif;
    font-size: clamp(13px, 1.2vw, 20px);
    border: 1.5px solid #ccc;
    border-radius: 12px;
    outline: none;
    transition: border-color 0.2s;
}

.game-over-input:focus {
    border-color: #005832;
}

.game-over-input::placeholder {
    color: #aaa;
}

.game-over-buttons {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    gap: clamp(8px, 0.8vw, 14px);
}

.game-over-btn {
    width: 100%;
    padding: clamp(10px, 1.1vw, 18px) clamp(16px, 2vw, 24px);
    font-family: 'Barlow', sans-serif;
    font-weight: 700;
    font-size: clamp(13px, 1.3vw, 22px);
    border-radius: 50px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s, background-color 0.15s;
    border: 2px solid #005832;
    box-sizing: border-box;
}

.game-over-btn-outline {
    background-color: #FFFFFF;
    color: #005832;
}

.game-over-btn-outline:hover {
    background-color: #f5f5f5;
}

.game-over-btn-primary {
    background-color: #005832;
    color: #FFFFFF;
    border: 2px solid #005832;
}

.game-over-btn-primary:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 16px rgba(0, 88, 50, 0.4);
}

.game-over-btn:active {
    transform: scale(0.97);
}

/* ==============================================
   Leaderboard Popup
   ============================================== */

.leaderboard-popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 95;
    font-family: 'Barlow', sans-serif;
    padding: 1rem;
    box-sizing: border-box;
    opacity: 0;
    animation: fadeInOverlay 0.3s ease forwards;
}

.leaderboard-popup.hidden {
    display: none;
}

.leaderboard-popup-box {
    width: clamp(280px, 32vw, 889px);
    max-width: calc(100vw - 2rem);
    max-height: 90vh;
    background-color: #FFFFFF;
    border: 3px solid #005832;
    border-radius: 36px;
    padding: clamp(28px, 3.2vw, 60px) clamp(28px, 3.4vw, 64px);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(16px, 2.5vw, 40px);
    box-sizing: border-box;
    overflow-y: auto;
    animation: scaleInPopup 0.3s ease forwards;
}

.leaderboard-title {
    font-family: 'Barlow', sans-serif;
    font-weight: 700;
    font-size: clamp(20px, 2.5vw, 44px);
    color: #005832;
    margin: 0;
    text-align: center;
}

.leaderboard-list {
    width: 100%;
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: clamp(4px, 0.5vw, 8px);
    counter-reset: lb;
    max-height: 50vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.leaderboard-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: clamp(8px, 1vw, 14px) clamp(12px, 1.5vw, 20px);
    background-color: #f7f7f7;
    border-radius: 12px;
    font-family: 'Barlow', sans-serif;
    font-size: clamp(13px, 1.3vw, 22px);
    color: #333;
    counter-increment: lb;
}

.leaderboard-list li::before {
    content: counter(lb) ".";
    font-weight: 700;
    color: #005832;
    margin-right: clamp(8px, 1vw, 16px);
    min-width: 1.8em;
}

.leaderboard-list li:first-child {
    background-color: #e8f5e9;
    font-weight: 700;
    color: #005832;
}

.lb-nickname {
    flex: 1;
    text-align: left;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.lb-score {
    font-weight: 700;
    color: #BD1923;
    margin-left: clamp(8px, 1vw, 16px);
    white-space: nowrap;
}

.leaderboard-empty {
    font-family: 'Barlow', sans-serif;
    font-size: clamp(13px, 1.3vw, 20px);
    color: #999;
    margin: 0;
    text-align: center;
}

.leaderboard-empty.hidden {
    display: none;
}

/* ==============================================
   Leaderboard Page (/leaderboard.html)
   ============================================== */

.lb-page {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: linear-gradient(180deg, #135B3C 0%, #022D1A 100%);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    font-family: 'Barlow', sans-serif;
    overflow: hidden;
}

.lb-page-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    width: 100%;
    max-width: 700px;
    padding: clamp(1.5rem, 3vw, 3rem) clamp(1rem, 3vw, 2rem);
    box-sizing: border-box;
    overflow: hidden;
}

.lb-page-logo {
    width: clamp(80px, 15vw, 180px);
    height: auto;
    margin-bottom: clamp(0.8rem, 1.5vw, 1.5rem);
}

.lb-page-title {
    font-family: 'Barlow', sans-serif;
    font-weight: 700;
    font-size: clamp(1.5rem, 3vw, 2.5rem);
    color: #FFFFFF;
    margin: 0 0 clamp(1rem, 2vw, 2rem) 0;
    text-align: center;
}

.lb-page-card {
    width: 100%;
    flex: 1;
    min-height: 0;
    background-color: #FFFFFF;
    border-radius: 24px;
    padding: clamp(16px, 2vw, 32px);
    box-sizing: border-box;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: clamp(1rem, 2vw, 2rem);
}

.lb-page-card .leaderboard-list {
    max-height: none;
}

.lb-page-back-btn {
    display: inline-block;
    background-color: #FFFFFF;
    color: #005832;
    text-decoration: none;
    font-family: 'Barlow', sans-serif;
    font-weight: 700;
    font-size: clamp(0.9rem, 1.8vw, 1.2rem);
    padding: clamp(0.7rem, 1.2vw, 1rem) clamp(2rem, 4vw, 3rem);
    border-radius: 50px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    margin-bottom: clamp(0.5rem, 1vw, 1rem);
    flex-shrink: 0;
}

.lb-page-back-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 20px rgba(255, 255, 255, 0.3);
}

.lb-page-back-btn:active {
    transform: scale(0.98);
}

@media (max-width: 1024px) {
    .splash-logo {
        width: clamp(160px, 25vw, 280px);
    }

    .splash-title-img {
        width: clamp(240px, 50vw, 420px);
    }

    .splash-subtitle {
        font-size: clamp(28px, 5vw, 52px);
    }

    .splash-description {
        font-size: clamp(14px, 2.5vw, 20px);
        max-width: 80vw;
    }

    #start-button {
        font-size: clamp(18px, 3vw, 28px);
    }

    .game-over-popup-box,
    .leaderboard-popup-box {
        width: clamp(320px, 60vw, 889px);
    }
}

@media (max-width: 768px) {
    .game-over-popup-box,
    .leaderboard-popup-box {
        width: min(92vw, 889px);
        border-radius: 28px;
        padding: 36px 32px;
        gap: 24px;
    }

    .game-over-header {
        gap: 6px;
    }

    .game-over-title {
        font-size: 20px;
    }

    .game-over-score {
        font-size: 44px;
    }

    .game-over-form {
        gap: 10px;
    }

    .game-over-label {
        font-size: 15px;
    }

    .game-over-input {
        font-size: 16px;
        padding: 12px 16px;
    }

    .game-over-buttons {
        gap: 10px;
    }

    .game-over-btn {
        font-size: 15px;
        padding: 12px 20px;
    }

    .leaderboard-title {
        font-size: 22px;
    }

    .leaderboard-list li {
        font-size: 14px;
        padding: 10px 14px;
    }
}

@media (max-width: 600px) {
    .splash-logo {
        width: clamp(160px, 45vw, 240px);
    }

    .splash-title-img {
        width: clamp(220px, 70vw, 360px);
    }

    .splash-info-box {
        background-color: rgba(0, 0, 0, 0.5);
        border-radius: 16px;
        padding: clamp(16px, 3vh, 28px) clamp(16px, 4vw, 28px);
        margin-bottom: clamp(10px, 2vh, 20px);
        max-width: 90vw;
    }

    .splash-subtitle {
        font-size: clamp(24px, 7vw, 40px);
        margin-bottom: clamp(8px, 1.5vh, 16px);
    }

    .splash-description {
        font-size: clamp(12px, 3.5vw, 18px);
        max-width: 85vw;
    }

    #start-button {
        font-size: clamp(14px, 4vw, 22px);
    }
}

@media (max-width: 480px) {
    .game-over-popup-box,
    .leaderboard-popup-box {
        width: calc(100vw - 2rem);
        border-radius: 20px;
        padding: 28px 20px;
        gap: 20px;
    }

    .game-over-title {
        font-size: 18px;
    }

    .game-over-score {
        font-size: 36px;
    }

    .game-over-label {
        font-size: 14px;
    }

    .game-over-input {
        font-size: 16px;
        padding: 10px 14px;
        border-radius: 8px;
    }

    .game-over-btn {
        font-size: 14px;
        padding: 10px 16px;
    }

    .leaderboard-title {
        font-size: 20px;
    }
}
