* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

#game-container {
    width: 100vw;
    height: 100vh;
    position: relative;
    background: linear-gradient(180deg, #0f3460 0%, #1a1a2e 100%);
    overflow: hidden;
}

.screen {
    display: none;
    width: 100%;
    height: 100%;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.screen.active {
    display: flex;
}

/* Character Selection Screen */
.character-selection {
    display: flex;
    gap: 30px;
    margin: 30px 0;
    flex-wrap: wrap;
    justify-content: center;
}

.btn-character {
    background: linear-gradient(180deg, #5a5a8a 0%, #3a3a6a 100%);
    border: 4px solid rgba(255, 255, 255, 0.3);
    padding: 25px;
    border-radius: 25px;
    cursor: pointer;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.4);
    transition: all 0.3s ease;
    min-width: 200px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.btn-character:hover {
    transform: translateY(-5px) scale(1.05);
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.5);
    border-color: rgba(255, 255, 255, 0.5);
}

.btn-character:active {
    transform: translateY(-2px);
}

.character-icon {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    padding: 15px;
    transition: transform 0.3s ease;
}

.btn-character:hover .character-icon {
    transform: scale(1.1);
}

.character-icon svg {
    display: block;
}

.character-name {
    font-size: 1.3rem;
    font-weight: bold;
    color: #FFD700;
    text-align: center;
}

.character-desc {
    font-size: 0.9rem;
    color: #ccc;
    text-align: center;
}

.btn-character[data-character="perry"] {
    background: linear-gradient(180deg, #4A90D9 0%, #2E5C8A 100%);
}

.btn-character[data-character="frog"] {
    background: linear-gradient(180deg, #2E8B2E 0%, #1a5c1a 100%);
}

.btn-character[data-character="beaver"] {
    background: linear-gradient(180deg, #8B4513 0%, #6B3510 100%);
}

/* Menu Screen */
.game-title {
    font-size: 2.5rem;
    color: #4A90D9;
    text-shadow: 3px 3px 0 #2E5C8A, -1px -1px 0 #2E5C8A, 1px -1px 0 #2E5C8A, -1px 1px 0 #2E5C8A;
    margin-bottom: 10px;
    text-align: center;
}

.game-subtitle {
    font-size: 1.5rem;
    color: #7B68EE;
    margin-bottom: 30px;
    text-align: center;
}

.menu-perry {
    margin: 20px 0;
    animation: bounce 2s ease-in-out infinite;
}

.menu-perry img {
    display: block;
    margin: 0 auto;
}

/* Difficulty Selection */
.difficulty-selection {
    margin: 20px 0;
    text-align: center;
}

.difficulty-selection h3 {
    color: #FFD700;
    font-size: 1.3rem;
    margin-bottom: 20px;
}

.difficulty-buttons {
    display: flex;
    flex-direction: row;
    gap: 15px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
}

.btn-difficulty {
    background: linear-gradient(180deg, #4A90D9 0%, #2E5C8A 100%);
    border: 3px solid rgba(255, 255, 255, 0.2);
    padding: 15px 30px;
    font-size: 1.1rem;
    border-radius: 20px;
    cursor: pointer;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
    min-width: 200px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.btn-difficulty:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.4);
}

.btn-difficulty:active {
    transform: translateY(0);
}

.btn-difficulty .diff-icon {
    font-size: 2rem;
}

.btn-difficulty .diff-title {
    font-weight: bold;
    font-size: 1.2rem;
}

.btn-difficulty .diff-rows {
    font-size: 0.9rem;
    opacity: 0.9;
}

.btn-easy {
    background: linear-gradient(180deg, #C8F7C8 0%, #A8E6A8 100%);
    border-color: #98D898;
    color: #2D5A2D;
}

.btn-medium {
    background: linear-gradient(180deg, #FFF4C8 0%, #FFE5A8 100%);
    border-color: #FFD898;
    color: #5A4A2D;
}

.btn-hard {
    background: linear-gradient(180deg, #FFC8C8 0%, #FFA8A8 100%);
    border-color: #FF9898;
    color: #5A2D2D;
}

.btn-zen {
    background: linear-gradient(180deg, #E8F5E9 0%, #C8E6C9 100%);
    border-color: #A5D6A7;
    color: #2E5C3E;
}

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

.btn-primary {
    background: linear-gradient(180deg, #4A90D9 0%, #2E5C8A 100%);
    color: white;
    border: none;
    padding: 15px 40px;
    font-size: 1.2rem;
    border-radius: 30px;
    cursor: pointer;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s, box-shadow 0.2s;
    margin-top: 20px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.btn-primary:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
}

.high-score {
    color: #FFD700;
    font-size: 1.2rem;
    margin-top: 20px;
}

/* Game Screen */
#game-screen {
    justify-content: flex-start;
    position: relative;
    overflow: hidden;
}

.game-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    padding: 15px 20px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 10px;
    margin-bottom: 10px;
    z-index: 100;
    position: relative;
}

.score, .high-score-small {
    color: white;
    font-size: 1.1rem;
    font-weight: bold;
}

.score span, .high-score-small span {
    color: #4A90D9;
}

#game-canvas {
    flex: 1;
    width: 100%;
    height: 100%;
    display: block;
}

#click-instruction {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    color: white;
    font-size: 1rem;
    background: rgba(0, 0, 0, 0.6);
    padding: 10px 20px;
    border-radius: 20px;
    pointer-events: none;
    z-index: 50;
}

/* Mobile Controls */
.mobile-controls {
    position: absolute;
    bottom: 20px;
    left: 0;
    right: 0;
    display: none; /* Hidden by default on desktop */
    justify-content: space-between;
    padding: 0 20px;
    gap: 20px;
    z-index: 100;
    pointer-events: none;
}

.jump-btn {
    pointer-events: auto;
    background: linear-gradient(180deg, #5a5a8a 0%, #3a3a6a 100%);
    border: 3px solid rgba(255, 255, 255, 0.4);
    border-radius: 20px;
    padding: 15px 25px;
    min-width: 120px;
    min-height: 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
    transition: all 0.2s ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.jump-btn:active {
    transform: scale(0.95);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.4);
    background: linear-gradient(180deg, #4a4a7a 0%, #2a2a5a 100%);
}

.jump-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

.jump-left {
    background: linear-gradient(180deg, #4A90D9 0%, #2E5C8A 100%);
}

.jump-right {
    background: linear-gradient(180deg, #7B68EE 0%, #5a4acd 100%);
}

.jump-btn .btn-arrow {
    font-size: 2rem;
    font-weight: bold;
    color: white;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.jump-btn .btn-label {
    font-size: 0.9rem;
    color: white;
    font-weight: bold;
    text-transform: uppercase;
}

.row {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-bottom: 10px;
    position: relative;
}

.row.start-row .barrel {
    background: linear-gradient(180deg, #90EE90 0%, #228B22 100%);
    cursor: default;
}

.barrel {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(180deg, #8B4513 0%, #654321 50%, #8B4513 100%);
    border: 4px solid #5D3A1A;
    cursor: pointer;
    position: relative;
    transition: transform 0.3s, opacity 0.3s;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
}

.barrel::before {
    content: '';
    position: absolute;
    top: 10%;
    left: 10%;
    right: 10%;
    height: 20%;
    background: repeating-linear-gradient(
        90deg,
        #5D3A1A,
        #5D3A1A 10px,
        #8B4513 10px,
        #8B4513 20px
    );
    border-radius: 50%;
}

.barrel::after {
    content: '';
    position: absolute;
    bottom: 10%;
    left: 10%;
    right: 10%;
    height: 20%;
    background: repeating-linear-gradient(
        90deg,
        #5D3A1A,
        #5D3A1A 10px,
        #8B4513 10px,
        #8B4513 20px
    );
    border-radius: 50%;
}

.barrel:hover:not(.clicked):not(.safe):not(.water) {
    transform: scale(1.1);
    box-shadow: 0 8px 20px rgba(74, 144, 217, 0.6);
}

.barrel.safe {
    background: linear-gradient(180deg, #90EE90 0%, #228B22 100%);
    border-color: #006400;
    pointer-events: none;
}

.barrel.water {
    background: linear-gradient(180deg, #4169E1 0%, #0000CD 100%);
    border-color: #000080;
    pointer-events: none;
    animation: water-splash 0.5s ease-out;
}

@keyframes water-splash {
    0% { transform: scale(1); }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

.barrel.clicked {
    pointer-events: none;
}

.perry {
    position: absolute;
    width: 60px;
    height: 60px;
    z-index: 10;
    transition: all 0.3s ease;
}

.perry img {
    width: 100%;
    height: 100%;
    display: block;
}

/* Helicopter */
.helicopter {
    position: absolute;
    top: 80px;
    left: 0;
    z-index: 5;
    animation: helicopter-move 8s linear infinite;
}

@keyframes helicopter-move {
    0% { left: -100px; }
    100% { left: 100%; }
}

.bomb {
    position: absolute;
    width: 30px;
    height: 30px;
    z-index: 8;
    animation: bomb-fall 2s linear forwards;
}

@keyframes bomb-fall {
    0% { top: 120px; opacity: 1; }
    100% { top: 100%; opacity: 1; }
}

.bomb img {
    width: 100%;
    height: 100%;
    display: block;
}

/* Game Over Screen */
.game-over-title {
    font-size: 2.5rem;
    color: #e74c3c;
    margin-bottom: 20px;
}

/* Victory Screen */
.victory-title {
    font-size: 3rem;
    color: #FFD700;
    text-shadow: 3px 3px 0 #FFA500, -1px -1px 0 #FFA500, 1px -1px 0 #FFA500, -1px 1px 0 #FFA500;
    margin-bottom: 20px;
    animation: victory-bounce 0.5s ease-in-out infinite alternate;
}

@keyframes victory-bounce {
    0% { transform: scale(1); }
    100% { transform: scale(1.05); }
}

.victory-message {
    font-size: 1.5rem;
    color: #90EE90;
    margin-bottom: 30px;
}

.victory-score {
    color: #FFD700;
}

.gameover-character {
    margin: 20px 0;
}

.gameover-character img {
    display: block;
    margin: 0 auto;
}

.final-score {
    font-size: 1.8rem;
    color: white;
    margin: 20px 0;
}

.new-record {
    color: #FFD700;
    font-size: 1.5rem;
    margin: 10px 0;
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* Perry falling animation */
@keyframes perry-fall {
    0% { transform: translateY(0) rotate(0deg); }
    100% { transform: translateY(200px) rotate(720deg); opacity: 0; }
}

.perry.falling {
    animation: perry-fall 1s ease-in forwards;
}

/* Responsive */
@media (max-width: 768px) {
    /* Character selection horizontal scroll */
    .character-selection {
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
        padding: 10px 20px;
        max-width: 100vw;
        gap: 15px;
    }

    .character-selection::-webkit-scrollbar {
        height: 6px;
    }

    .character-selection::-webkit-scrollbar-track {
        background: rgba(255, 255, 255, 0.1);
        border-radius: 3px;
    }

    .character-selection::-webkit-scrollbar-thumb {
        background: rgba(255, 255, 255, 0.3);
        border-radius: 3px;
    }

    .btn-character {
        scroll-snap-align: center;
        flex-shrink: 0;
        min-width: 160px;
        padding: 20px;
    }

    /* Difficulty buttons horizontal scroll */
    .difficulty-buttons {
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
        padding: 10px 5px;
        max-width: 100vw;
        gap: 12px;
    }

    .difficulty-buttons::-webkit-scrollbar {
        height: 5px;
    }

    .difficulty-buttons::-webkit-scrollbar-track {
        background: rgba(255, 255, 255, 0.1);
        border-radius: 3px;
    }

    .difficulty-buttons::-webkit-scrollbar-thumb {
        background: rgba(255, 255, 255, 0.3);
        border-radius: 3px;
    }

    .btn-difficulty {
        scroll-snap-align: center;
        flex-shrink: 0;
        min-width: 140px;
        padding: 12px 20px;
    }

    /* Show mobile controls on mobile devices */
    .mobile-controls {
        display: flex;
    }

    /* Hide click instruction on mobile */
    #click-instruction {
        display: none;
    }

    .jump-btn {
        min-width: 100px;
        min-height: 70px;
        padding: 12px 20px;
        border-radius: 15px;
    }

    .jump-btn .btn-arrow {
        font-size: 1.8rem;
    }

    .jump-btn .btn-label {
        font-size: 0.8rem;
    }
}

/* Mobile-specific adjustments */
@media (max-width: 400px) {
    .barrel {
        width: 60px;
        height: 60px;
    }

    .row {
        gap: 15px;
    }

    .game-title {
        font-size: 2rem;
    }

    .perry {
        width: 45px;
        height: 45px;
    }

    .mobile-controls {
        bottom: 15px;
        padding: 0 15px;
        gap: 15px;
    }

    .jump-btn {
        min-width: 90px;
        min-height: 65px;
        padding: 10px 15px;
    }

    .jump-btn .btn-arrow {
        font-size: 1.5rem;
    }

    .jump-btn .btn-label {
        font-size: 0.75rem;
    }
}

/* Landscape mode adjustments for mobile */
@media (max-width: 768px) and (max-height: 500px) and (orientation: landscape) {
    .mobile-controls {
        bottom: 10px;
        padding: 0 30px;
        gap: 30px;
    }

    .jump-btn {
        min-width: 110px;
        min-height: 50px;
        padding: 8px 20px;
        flex-direction: row;
    }

    .jump-btn .btn-arrow {
        font-size: 1.5rem;
    }

    .jump-btn .btn-label {
        font-size: 0.8rem;
    }

    .game-header {
        padding: 8px 15px;
    }

    .score, .high-score-small {
        font-size: 0.9rem;
    }
}
