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

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

#game-container {
    position: relative;
    width: 800px;
    height: 600px;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 100px rgba(78, 204, 163, 0.1);
}

#gameCanvas {
    display: block;
    background: linear-gradient(180deg, #1a2a4a 0%, #16213e 100%);
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* Screens */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, rgba(22, 33, 62, 0.97) 0%, rgba(15, 52, 96, 0.97) 100%);
    backdrop-filter: blur(10px);
}

.screen.hidden {
    display: none;
}

.screen-content, .title-content {
    text-align: center;
    color: #e8f4f8;
}

/* Title Screen */
.game-title {
    font-size: 72px;
    font-weight: 800;
    background: linear-gradient(135deg, #4ecca3 0%, #45b7aa 50%, #38ada9 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: none;
    margin-bottom: 20px;
    letter-spacing: 6px;
    animation: titlePulse 2s ease-in-out infinite;
}

@keyframes titlePulse {
    0%, 100% { transform: scale(1); filter: brightness(1); }
    50% { transform: scale(1.02); filter: brightness(1.1); }
}

.title-hippo {
    width: 140px;
    height: 100px;
    background: linear-gradient(180deg, #8e9aeb 0%, #7b8cde 50%, #6a7bd4 100%);
    margin: 0 auto 30px;
    border-radius: 50% 50% 45% 45%;
    position: relative;
    box-shadow: 0 12px 0 #5c6bc0, 0 20px 40px rgba(0,0,0,0.3);
    animation: hippoFloat 3s ease-in-out infinite;
}

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

.title-hippo::before {
    content: '';
    position: absolute;
    top: 20%;
    left: 18%;
    width: 17%;
    height: 24%;
    background: radial-gradient(circle at 30% 30%, #fff 0%, #e8e8e8 100%);
    border-radius: 50%;
    box-shadow: calc(140px * 0.47) 0 0 0 #fff;
    animation: blink 4s ease-in-out infinite;
}

@keyframes blink {
    0%, 45%, 55%, 100% { transform: scaleY(1); }
    50% { transform: scaleY(0.1); }
}

.title-hippo::after {
    content: '';
    position: absolute;
    top: 26%;
    left: 23%;
    width: 7%;
    height: 10%;
    background: #232931;
    border-radius: 50%;
    box-shadow: calc(140px * 0.47) 0 0 #232931;
}

/* Buttons */
.game-btn {
    background: linear-gradient(135deg, #4ecca3 0%, #38ada9 100%);
    color: #1a1a2e;
    border: none;
    padding: 16px 48px;
    font-size: 18px;
    font-family: 'Segoe UI', 'Roboto', sans-serif;
    font-weight: 700;
    cursor: pointer;
    margin: 8px;
    border-radius: 8px;
    transition: all 0.2s ease;
    box-shadow: 0 4px 15px rgba(78, 204, 163, 0.3);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.game-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(78, 204, 163, 0.4);
    filter: brightness(1.1);
}

.game-btn:active {
    transform: translateY(1px);
    box-shadow: 0 2px 10px rgba(78, 204, 163, 0.3);
}

.game-btn.secondary {
    background: linear-gradient(135deg, #7b8cde 0%, #5c6bc0 100%);
    box-shadow: 0 4px 15px rgba(123, 140, 222, 0.3);
}

.game-btn.secondary:hover {
    box-shadow: 0 8px 25px rgba(123, 140, 222, 0.4);
}

.game-btn.pulse {
    animation: btnPulse 1.5s ease-in-out infinite;
}

@keyframes btnPulse {
    0%, 100% { box-shadow: 0 4px 15px rgba(78, 204, 163, 0.3); }
    50% { box-shadow: 0 4px 30px rgba(78, 204, 163, 0.6); }
}

/* Controls Box on Title Screen */
.controls-box {
    background: rgba(0, 0, 0, 0.4);
    border-radius: 12px;
    padding: 20px 30px;
    margin: 25px auto;
    max-width: 320px;
    border: 1px solid rgba(78, 204, 163, 0.3);
}

.control-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.control-item:last-child {
    border-bottom: none;
}

.control-key {
    background: linear-gradient(135deg, #4ecca3 0%, #38ada9 100%);
    color: #1a1a2e;
    padding: 8px 16px;
    border-radius: 6px;
    font-weight: 700;
    font-size: 16px;
    min-width: 70px;
    text-align: center;
}

.control-desc {
    color: #ddd;
    font-size: 15px;
    margin-left: 15px;
    text-align: right;
    flex: 1;
}

.controls-hint {
    margin-top: 30px;
    color: rgba(255,255,255,0.5);
    font-size: 14px;
    letter-spacing: 1px;
}

/* Rules Screen */
.rules-content {
    max-width: 480px;
    max-height: 580px;
    overflow-y: auto;
}

.rules-content h2 {
    font-size: 32px;
    margin-bottom: 12px;
    background: linear-gradient(135deg, #4ecca3 0%, #45b7aa 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.rules-box {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    padding: 15px 20px;
    margin: 12px 0;
    text-align: left;
    border: 1px solid rgba(78, 204, 163, 0.2);
}

.rule-section {
    margin-bottom: 12px;
}

.rule-section:last-child {
    margin-bottom: 0;
}

.rule-section h3 {
    color: #4ecca3;
    font-size: 15px;
    margin-bottom: 6px;
    font-weight: 600;
}

.rule-section p {
    color: #ccc;
    line-height: 1.4;
    margin-bottom: 4px;
    font-size: 13px;
}

.rule-section ul {
    color: #ccc;
    line-height: 1.6;
    padding-left: 18px;
    font-size: 13px;
}

.key {
    background: linear-gradient(135deg, #3d3d5c 0%, #2d2d4a 100%);
    padding: 2px 8px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    color: #fff;
    border: 1px solid #555;
    font-size: 12px;
}

/* Rules screen button */
#rules-back-btn {
    padding: 12px 36px;
    font-size: 15px;
    margin-top: 8px;
}

.highlight {
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 600;
}

.highlight.water {
    background: rgba(52, 152, 219, 0.3);
    color: #5dade2;
}

.highlight.eat {
    background: rgba(231, 76, 60, 0.3);
    color: #e74c3c;
}

.highlight.banana {
    background: rgba(241, 196, 15, 0.3);
    color: #f1c40f;
}

/* Level Intro Screen */
.level-intro-content h2 {
    font-size: 24px;
    color: rgba(255,255,255,0.6);
    text-transform: uppercase;
    letter-spacing: 4px;
    margin-bottom: 5px;
}

.level-intro-content h3 {
    font-size: 48px;
    background: linear-gradient(135deg, #4ecca3 0%, #45b7aa 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 25px;
}

.objectives-box {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    padding: 20px 40px;
    margin: 20px 0;
    text-align: left;
    border: 1px solid rgba(78, 204, 163, 0.2);
}

.objective-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    color: #ddd;
    font-size: 18px;
}

.objective-icon {
    font-size: 24px;
}

.intro-timer {
    font-size: 28px;
    color: #f39c12;
    margin: 20px 0;
    font-weight: 600;
}

.timer-icon {
    margin-right: 8px;
}

/* HUD */
#hud {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    pointer-events: none;
}

#hud.hidden {
    display: none;
}

.hud-left, .hud-right {
    background: linear-gradient(135deg, rgba(0, 0, 0, 0.6) 0%, rgba(0, 0, 0, 0.4) 100%);
    padding: 12px 18px;
    border-radius: 10px;
    color: #e8f4f8;
    font-size: 15px;
    backdrop-filter: blur(5px);
    border: 1px solid rgba(255,255,255,0.1);
}

.hud-center {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, rgba(243, 156, 18, 0.9) 0%, rgba(211, 84, 0, 0.9) 100%);
    padding: 8px 24px;
    border-radius: 8px;
    font-size: 24px;
    font-weight: 700;
    color: #fff;
    box-shadow: 0 4px 20px rgba(243, 156, 18, 0.4);
}

#timer-display.warning {
    animation: timerWarning 0.5s ease-in-out infinite;
}

@keyframes timerWarning {
    0%, 100% { background: linear-gradient(135deg, rgba(231, 76, 60, 0.9) 0%, rgba(192, 57, 43, 0.9) 100%); }
    50% { background: linear-gradient(135deg, rgba(243, 156, 18, 0.9) 0%, rgba(211, 84, 0, 0.9) 100%); }
}

#health-display {
    display: flex;
    gap: 6px;
    margin-bottom: 8px;
}

.heart {
    width: 22px;
    height: 22px;
    background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
    clip-path: polygon(50% 0%, 100% 35%, 100% 70%, 50% 100%, 0% 70%, 0% 35%);
    transition: all 0.3s ease;
}

.heart.empty {
    background: linear-gradient(135deg, #444 0%, #333 100%);
    transform: scale(0.9);
}

.heart.pulse {
    animation: heartPulse 0.5s ease-in-out infinite;
}

@keyframes heartPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); filter: brightness(1.3); }
}

/* Mute Button */
.mute-btn {
    position: absolute;
    bottom: 12px;
    right: 20px;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255,255,255,0.2);
    color: #fff;
    font-size: 20px;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    cursor: pointer;
    pointer-events: auto;
    transition: all 0.2s ease;
}

.mute-btn:hover {
    background: rgba(0, 0, 0, 0.7);
    transform: scale(1.1);
}

#level-name {
    font-weight: 700;
    color: #4ecca3;
    margin-bottom: 6px;
    font-size: 16px;
}

#banana-count {
    color: #f1c40f;
    font-weight: 600;
}

/* Screen content */
.screen-content h2 {
    font-size: 52px;
    background: linear-gradient(135deg, #4ecca3 0%, #45b7aa 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 20px;
}

.screen-content p {
    font-size: 18px;
    margin-bottom: 20px;
    color: rgba(255,255,255,0.7);
}

#level-stats, #final-stats {
    background: rgba(0,0,0,0.3);
    padding: 25px 40px;
    border-radius: 12px;
    margin: 25px 0;
    font-size: 18px;
    line-height: 2;
    border: 1px solid rgba(78, 204, 163, 0.2);
}

/* Victory screen special styling */
#victory .screen-content h2 {
    font-size: 64px;
    animation: victoryPulse 1s ease-in-out infinite;
}

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

/* Game Over styling */
#game-over .screen-content h2,
#times-up .screen-content h2 {
    background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Touch Controls - Overlay on game */
#touch-controls {
    display: none; /* Hidden by default, shown via JS on touch devices */
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 100;
}

/* Joystick zone - left side of screen */
#joystick-zone {
    position: absolute;
    left: 15px;
    bottom: 15px;
    width: 150px;
    height: 150px;
    pointer-events: auto;
    touch-action: none;
}

#joystick-base {
    position: absolute;
    width: 130px;
    height: 130px;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    background: rgba(78, 204, 163, 0.25);
    border: 3px solid rgba(78, 204, 163, 0.5);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
}

#joystick-thumb {
    width: 60px;
    height: 60px;
    background: rgba(78, 204, 163, 0.6);
    border: 3px solid rgba(78, 204, 163, 0.9);
    border-radius: 50%;
    transition: transform 0.05s ease-out;
}

#joystick-thumb.active {
    background: rgba(78, 204, 163, 0.85);
}

.action-btn {
    position: absolute;
    right: 10px;
    bottom: 10px;
    width: 140px;
    height: 140px;
    background: rgba(241, 196, 15, 0.5);
    border: 5px solid rgba(241, 196, 15, 0.8);
    border-radius: 50%;
    color: rgba(255, 255, 255, 0.9);
    font-size: 48px;
    font-weight: bold;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    pointer-events: auto;
    transition: background 0.1s, transform 0.1s;
}

.action-btn.active {
    background: rgba(241, 196, 15, 0.85);
    transform: scale(0.92);
}

/* Mobile Responsive - Full screen game */
@media (max-width: 850px), (max-height: 500px) {
    body {
        padding: 0;
        margin: 0;
        overflow: hidden;
    }

    #game-container {
        width: 100vw;
        height: 100vh;
        border-radius: 0;
        box-shadow: none;
    }

    /* Screens need to fit within container */
    .screen {
        overflow-y: auto;
    }

    .screen-content, .title-content {
        padding: 15px;
        max-height: 100%;
        overflow-y: auto;
    }

    .game-title {
        font-size: 32px;
        letter-spacing: 2px;
        margin-bottom: 10px;
    }

    .title-hippo {
        width: 70px;
        height: 50px;
        margin-bottom: 15px;
    }

    .title-hippo::before {
        top: 20%;
        left: 18%;
        width: 17%;
        height: 24%;
        box-shadow: 33px 0 0 0 #fff;
    }

    .title-hippo::after {
        top: 26%;
        left: 23%;
        width: 7%;
        height: 10%;
        box-shadow: 33px 0 0 #232931;
    }

    .game-btn {
        padding: 12px 24px;
        font-size: 14px;
        margin: 5px;
    }

    /* Level intro screen fixes */
    .level-intro-content h2 {
        font-size: 16px;
        margin-bottom: 2px;
    }

    .level-intro-content h3 {
        font-size: 24px;
        margin-bottom: 8px;
    }

    .objectives-box {
        padding: 10px 15px;
        margin: 8px 0;
    }

    .objective-item {
        font-size: 13px;
        padding: 4px 0;
    }

    .intro-timer {
        font-size: 18px;
        margin: 8px 0;
    }

    .hud-left, .hud-right {
        padding: 4px 8px;
        font-size: 10px;
    }

    .hud-center {
        padding: 3px 10px;
        font-size: 14px;
    }

    #level-name {
        font-size: 11px;
    }

    .heart {
        width: 14px;
        height: 14px;
    }

    /* Joystick adjustments for mobile - keep them big! */
    #joystick-zone {
        width: 140px;
        height: 140px;
    }

    #joystick-base {
        width: 120px;
        height: 120px;
    }

    #joystick-thumb {
        width: 55px;
        height: 55px;
    }

    .action-btn {
        width: 130px;
        height: 130px;
        font-size: 44px;
    }
}

/* Very small screens (iPhone SE, etc) */
@media (max-width: 400px) {
    .game-title {
        font-size: 26px;
    }

    .title-hippo {
        width: 50px;
        height: 35px;
    }

    .title-hippo::before {
        top: 20%;
        left: 18%;
        width: 17%;
        height: 24%;
        box-shadow: 23px 0 0 0 #fff;
    }

    .title-hippo::after {
        top: 26%;
        left: 23%;
        width: 7%;
        height: 10%;
        box-shadow: 23px 0 0 #232931;
    }

    .game-btn {
        padding: 10px 20px;
        font-size: 13px;
    }

    .level-intro-content h3 {
        font-size: 20px;
    }

    .objectives-box {
        padding: 8px 12px;
    }

    .objective-item {
        font-size: 12px;
    }

    .rules-content {
        max-width: 95vw;
        padding: 8px;
    }

    .rules-box {
        padding: 8px 12px;
    }

    .rule-section h3 {
        font-size: 12px;
    }

    .rule-section p,
    .rule-section ul {
        font-size: 10px;
    }

    #joystick-zone {
        width: 120px;
        height: 120px;
    }

    #joystick-base {
        width: 100px;
        height: 100px;
    }

    #joystick-thumb {
        width: 45px;
        height: 45px;
    }

    .action-btn {
        width: 110px;
        height: 110px;
        font-size: 36px;
    }
}

/* Landscape mode adjustments */
@media (orientation: landscape) and (max-height: 500px) {
    .screen-content, .title-content {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        gap: 10px;
    }

    .game-title {
        width: 100%;
        font-size: 28px;
        margin-bottom: 5px;
    }

    .title-hippo {
        display: none;
    }

    .objectives-box {
        max-width: 250px;
    }
}
