/* CSS Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: url('Immagini/Island_Mode/background.webp') center center / cover no-repeat fixed;
    color: #fff;
    overflow: hidden;
    position: relative;
    min-height: 100vh;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    touch-action: manipulation;
    transition: background-image 0.5s ease-in-out;
}

/* Dark overlay for better readability */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(0, 20, 10, 0.85), rgba(10, 40, 20, 0.75));
    z-index: -1;
    animation: pulseOverlay 8s ease-in-out infinite;
}

@keyframes pulseOverlay {

    0%,
    100% {
        opacity: 0.85;
    }

    50% {
        opacity: 0.75;
    }
}

/* Screen Management */
.screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.screen.active {
    display: flex;
}

/* Menu Screen */
.menu-container {
    text-align: center;
    max-width: 600px;
    padding: 40px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(15px);
    border-radius: 30px;
    border: 2px solid rgba(139, 69, 19, 0.5);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7),
        0 0 40px rgba(255, 140, 0, 0.2);
}

.game-title {
    font-size: 4.5rem;
    font-weight: 900;
    letter-spacing: 8px;
    background: linear-gradient(135deg, #ff6b00, #ff3300, #cc0000);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 0 30px rgba(255, 60, 0, 0.5);
    margin-bottom: 10px;
    animation: titleGlow 2s ease-in-out infinite;
}

@keyframes titleGlow {

    0%,
    100% {
        filter: drop-shadow(0 0 10px rgba(255, 100, 0, 0.6));
    }

    50% {
        filter: drop-shadow(0 0 25px rgba(255, 100, 0, 0.9));
    }
}

.game-subtitle {
    font-size: 1.3rem;
    color: #ffaa66;
    margin-bottom: 40px;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.8);
    letter-spacing: 3px;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-bottom: 40px;
}

.menu-btn {
    background: linear-gradient(135deg, rgba(139, 69, 19, 0.8), rgba(101, 67, 33, 0.9));
    border: 2px solid rgba(255, 140, 0, 0.6);
    border-radius: 15px;
    padding: 20px 30px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.5);
    position: relative;
    overflow: hidden;
}

.menu-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 140, 0, 0.3), transparent);
    transition: left 0.5s;
}

.menu-btn:hover::before {
    left: 100%;
}

.menu-btn:hover {
    transform: translateY(-5px) scale(1.05);
    border-color: #ff8800;
    box-shadow: 0 10px 30px rgba(255, 100, 0, 0.6),
        0 0 20px rgba(255, 140, 0, 0.4);
}

.menu-btn:active {
    transform: translateY(-2px) scale(1.02);
}

.mode-name {
    font-size: 1.8rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: 2px;
}

.mode-desc {
    font-size: 1rem;
    color: #ffcc99;
    font-style: italic;
}

.menu-btn.secondary {
    background: linear-gradient(135deg, rgba(60, 60, 60, 0.8), rgba(40, 40, 40, 0.9));
    border-color: rgba(100, 100, 100, 0.6);
}

.menu-btn.secondary:hover {
    border-color: #888;
    box-shadow: 0 10px 30px rgba(100, 100, 100, 0.4);
}

.game-instructions {
    background: rgba(0, 0, 0, 0.5);
    padding: 20px;
    border-radius: 15px;
    border: 1px solid rgba(255, 140, 0, 0.3);
}

.game-instructions h3 {
    color: #ff8800;
    margin-bottom: 15px;
    font-size: 1.4rem;
    letter-spacing: 2px;
}

.game-instructions p {
    margin: 10px 0;
    font-size: 1rem;
    color: #ffddaa;
    line-height: 1.6;
}

.game-instructions strong {
    color: #ffaa66;
    font-weight: 700;
}

/* Game Screen */
#gameScreen {
    flex-direction: column;
    padding: 0;
}

.game-ui {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 40px;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.8), transparent);
    position: relative;
    z-index: 20;
}

.ui-left,
.ui-center,
.ui-right {
    flex: 1;
}

.ui-center {
    text-align: center;
}

.ui-right {
    text-align: right;
}

.score-display,
.lives-display {
    font-size: 1.5rem;
    font-weight: 700;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.8);
}

.label {
    color: #ffaa66;
    margin-right: 10px;
}

.value {
    color: #fff;
    font-size: 2rem;
    text-shadow: 0 0 10px rgba(255, 200, 0, 0.6);
}

.hearts {
    font-size: 1.8rem;
    letter-spacing: 5px;
}

/* Oxygen Bar (Hard Mode) */
.oxygen-display {
    margin-top: 15px;
}

.oxygen-display.hidden {
    display: none;
}

.oxygen-bar {
    width: 200px;
    height: 20px;
    background: rgba(0, 0, 0, 0.6);
    border: 2px solid rgba(0, 221, 255, 0.6);
    border-radius: 10px;
    overflow: hidden;
    display: inline-block;
    vertical-align: middle;
    margin: 0 10px;
}

.oxygen-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #00ddff, #00aaff);
    transition: width 0.3s ease, background-color 0.3s ease;
    box-shadow: 0 0 10px rgba(0, 221, 255, 0.5);
}

.oxygen-percent {
    font-size: 1.2rem;
    font-weight: 700;
    color: #00ddff;
    text-shadow: 0 0 10px rgba(0, 221, 255, 0.6);
}

.difficulty-display {
    background: rgba(139, 69, 19, 0.8);
    padding: 10px 30px;
    border-radius: 20px;
    border: 2px solid rgba(255, 140, 0, 0.6);
    display: inline-block;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
}

.difficulty-display span {
    font-size: 1.3rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: 2px;
    text-transform: uppercase;
}

#gameCanvas {
    display: block;
    margin: 0 auto;
    background: transparent;
    cursor: none;
    touch-action: none;
}

/* Pause Menu */
.pause-menu {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    transition: opacity 0.3s ease;
}

.pause-menu.hidden {
    display: none;
}

.pause-container {
    text-align: center;
    max-width: 500px;
    padding: 40px;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(15px);
    border-radius: 30px;
    border: 2px solid rgba(255, 140, 0, 0.6);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8),
        0 0 40px rgba(255, 140, 0, 0.3);
}

.pause-title {
    font-size: 3.5rem;
    font-weight: 900;
    letter-spacing: 6px;
    color: #ff8800;
    text-shadow: 0 0 20px rgba(255, 140, 0, 0.8),
        0 5px 10px rgba(0, 0, 0, 0.8);
    margin-bottom: 40px;
}

.pause-buttons {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.pause-btn {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid rgba(255, 140, 0, 0.6);
    padding: 12px 30px;
    border-radius: 25px;
    color: #fff;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 30;
}

.pause-btn:hover {
    background: rgba(139, 69, 19, 0.9);
    transform: translateX(-50%) scale(1.1);
    box-shadow: 0 5px 20px rgba(255, 140, 0, 0.5);
}

/* Game Over Screen */
.gameover-container {
    text-align: center;
    max-width: 600px;
    padding: 50px 40px;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(15px);
    border-radius: 30px;
    border: 2px solid rgba(204, 0, 0, 0.6);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8),
        0 0 40px rgba(204, 0, 0, 0.3);
}

.gameover-title {
    font-size: 4rem;
    font-weight: 900;
    letter-spacing: 6px;
    color: #ff3300;
    text-shadow: 0 0 20px rgba(255, 0, 0, 0.8),
        0 5px 10px rgba(0, 0, 0, 0.8);
    margin-bottom: 20px;
    animation: gameOverPulse 1.5s ease-in-out infinite;
}

@keyframes gameOverPulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }
}

.gameover-reason {
    margin-bottom: 30px;
    font-size: 1.3rem;
    color: #ffaa99;
}

.final-score {
    background: rgba(139, 69, 19, 0.6);
    padding: 20px;
    border-radius: 15px;
    margin-bottom: 40px;
    border: 2px solid rgba(255, 140, 0, 0.4);
}

.final-score .label {
    display: block;
    font-size: 1.2rem;
    color: #ffaa66;
    margin-bottom: 10px;
}

.final-score .value {
    font-size: 3.5rem;
    font-weight: 900;
    color: #ffdd00;
    text-shadow: 0 0 15px rgba(255, 200, 0, 0.8);
}

.gameover-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Responsive Design */
@media (max-width: 768px) {
    .game-title {
        font-size: 3rem;
        letter-spacing: 4px;
    }

    .menu-container {
        padding: 30px 20px;
        max-width: 90%;
    }

    .menu-btn {
        padding: 25px 20px;
        min-height: 80px;
    }

    .mode-name {
        font-size: 1.6rem;
    }

    .mode-desc {
        font-size: 0.95rem;
    }

    .game-ui {
        padding: 15px 20px;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 10px;
    }

    .ui-left,
    .ui-center,
    .ui-right {
        flex: 1;
        min-width: 100px;
    }

    .ui-center {
        flex-basis: 100%;
        order: -1;
        margin-bottom: 10px;
    }

    .score-display,
    .lives-display {
        font-size: 1rem;
    }

    .value {
        font-size: 1.3rem;
    }

    .hearts {
        font-size: 1.3rem;
    }

    .difficulty-display span {
        font-size: 1.1rem;
    }

    .pause-btn {
        font-size: 1rem;
        padding: 10px 25px;
        bottom: 20px;
    }

    .pause-title {
        font-size: 2.5rem;
    }

    .pause-container {
        max-width: 90%;
        padding: 30px 20px;
    }

    .gameover-title {
        font-size: 3rem;
    }

    .final-score .value {
        font-size: 2.8rem;
    }
}

/* Loading Animation */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.screen.active {
    animation: fadeIn 0.5s ease-out;
}