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

body {
    font-family: 'Nunito', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background-color: #ffffff;
    color: #333;
    overflow: hidden;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    width: 100vw;
    touch-action: none;
    position: relative;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* Confetti animation */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: -1;
    background-image: 
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='90'%3E%3Crect x='38' y='42' width='3' height='7' fill='%23ea4335' transform='rotate(25 40 45)'/%3E%3C/svg%3E"),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='110'%3E%3Crect x='48' y='52' width='3' height='7' fill='%234285f4' transform='rotate(-20 50 55)'/%3E%3C/svg%3E"),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='100'%3E%3Crect x='58' y='47' width='3' height='7' fill='%23fbbc04' transform='rotate(50 60 50)'/%3E%3C/svg%3E"),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='90' height='120'%3E%3Crect x='43' y='57' width='3' height='7' fill='%2334a853' transform='rotate(-40 45 60)'/%3E%3C/svg%3E"),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='110' height='80'%3E%3Crect x='53' y='37' width='3' height='7' fill='%23ea4335' transform='rotate(70 55 40)'/%3E%3C/svg%3E"),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='95' height='105'%3E%3Crect x='45' y='50' width='3' height='7' fill='%234285f4' transform='rotate(-55 47 52)'/%3E%3C/svg%3E"),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='85' height='95'%3E%3Crect x='40' y='44' width='3' height='7' fill='%23fbbc04' transform='rotate(15 42 47)'/%3E%3C/svg%3E"),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='105' height='85'%3E%3Crect x='50' y='40' width='3' height='7' fill='%2334a853' transform='rotate(-65 52 43)'/%3E%3C/svg%3E"),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='115' height='115'%3E%3Crect x='55' y='55' width='3' height='7' fill='%23ff6d00' transform='rotate(35 57 58)'/%3E%3C/svg%3E"),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='75' height='100'%3E%3Crect x='35' y='47' width='3' height='7' fill='%234285f4' transform='rotate(-30 37 50)'/%3E%3C/svg%3E");
    background-size: 
        80px 90px, 100px 110px, 120px 100px, 90px 120px,
        110px 80px, 95px 105px, 85px 95px, 105px 85px,
        115px 115px, 75px 100px;
    background-position: 
        0 0, 31px 47px, 67px 23px, 13px 71px,
        53px 89px, 97px 11px, 41px 103px, 79px 59px,
        17px 37px, 61px 67px;
    animation: confettiFall 20s linear infinite;
    opacity: 1;
}

@keyframes confettiFall {
    0% {
        background-position: 
            0 0, 31px 47px, 67px 23px, 13px 71px,
            53px 89px, 97px 11px, 41px 103px, 79px 59px,
            17px 37px, 61px 67px;
    }
    100% {
        background-position: 
            0 100vh, 31px calc(47px + 100vh), 67px calc(23px + 100vh), 13px calc(71px + 100vh),
            53px calc(89px + 100vh), 97px calc(11px + 100vh), 41px calc(103px + 100vh), 79px calc(59px + 100vh),
            17px calc(37px + 100vh), 61px calc(67px + 100vh);
    }
}

.game-container {
    position: relative;
    width: 100%;
    height: 100%;
    height: 100dvh; /* Dynamic viewport height for mobile */
    overflow: hidden;
    background-color: transparent;
}

/* Common Screen Styles */
.screen {
    position: absolute;
    width: 100%;
    height: 100%;
    height: 100dvh; /* Dynamic viewport height for mobile */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
    background-color: transparent;
    padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    overflow-y: auto;
}

.hidden {
    display: none !important;
}

/* Start Screen */
.start-content {
    text-align: center;
    max-width: 90%;
    padding: clamp(16px, 4vw, 24px);
    background-color: rgba(255, 255, 255, 0.85);
    border-radius: 15px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 40px);
    overflow-y: auto;
}

.start-content h1 {
    color: #ff6b6b;
    font-size: clamp(24px, 6vw, 36px);
    margin-bottom: clamp(16px, 4vw, 24px);
    line-height: 1.2;
}

.benja-image-container {
    margin: 0 auto clamp(16px, 4vw, 24px);
    max-width: clamp(120px, 35vw, 180px);
}

.benja-image {
    width: 100%;
    height: auto;
    display: block;
}

.controls-info {
    margin: clamp(16px, 4vw, 24px) 0;
    padding: clamp(10px, 2.5vw, 14px);
    background-color: #f9f9f9;
    border-radius: 10px;
    font-size: clamp(14px, 3.5vw, 18px);
    line-height: 1.4;
}

.settings {
    margin: clamp(16px, 4vw, 24px) 0;
}

.setting {
    margin: clamp(10px, 2.5vw, 14px) 0;
}

.setting label {
    display: block;
    margin-bottom: 8px;
    font-size: clamp(14px, 3.5vw, 18px);
    line-height: 1.4;
}

.setting input {
    width: clamp(60px, 15vw, 80px);
    padding: clamp(10px, 2.5vw, 14px);
    font-size: clamp(16px, 4vw, 20px);
    border: 2px solid #ddd;
    border-radius: 5px;
    min-height: 44px; /* Minimum touch target */
    text-align: center;
}

button {
    background-color: #4CAF50;
    color: white;
    border: none;
    padding: clamp(12px, 3vw, 16px) clamp(20px, 5vw, 28px);
    font-size: clamp(16px, 4vw, 20px);
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s;
    min-height: 44px; /* Minimum touch target for iPhone */
    min-width: 44px;
    touch-action: manipulation;
}

button:hover {
    background-color: #45a049;
}

#start-button {
    background-color: #ff6b6b;
    font-size: clamp(18px, 4.5vw, 24px);
    padding: clamp(14px, 3.5vw, 18px) clamp(24px, 6vw, 32px);
    margin-top: clamp(16px, 4vw, 24px);
    min-height: 48px;
}

#start-button:hover {
    background-color: #ff5252;
}

/* Game Screen */
#game-screen {
    position: relative;
    background-color: #8bc34a; /* Grass green background */
}

#score-container {
    position: absolute;
    top: max(0px, env(safe-area-inset-top));
    left: 0;
    width: 100%;
    display: flex;
    justify-content: space-between;
    padding: clamp(10px, 2.5vw, 14px);
    background-color: rgba(0, 0, 0, 0.6);
    color: white;
    z-index: 5;
    min-height: 44px; /* Minimum touch target */
    font-size: clamp(14px, 3.5vw, 18px);
}

#game-area {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* Car Styling */
#car {
    position: absolute;
    width: 60px;
    height: 100px;
    background-image: url('img/car.png');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    z-index: 2;
    transform-origin: center center;
    transition: transform 0.1s;
}

/* Car directions */
.direction-up {
    transform: rotate(0deg);
}

.direction-right {
    transform: rotate(90deg);
}

.direction-down {
    transform: rotate(180deg);
}

.direction-left {
    transform: rotate(-90deg);
}

/* Road Styling */
.road {
    position: absolute;
    background-color: #757575;
    z-index: 1;
}

.road.horizontal {
    height: 60px;
}

.road.vertical {
    width: 60px;
}

.road-intersection {
    position: absolute;
    background-color: #757575;
    z-index: 1;
}

/* Question Mark Styling */
.question-mark {
    position: absolute;
    width: 40px;
    height: 40px;
    background-color: #ffeb3b;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    font-weight: bold;
    color: #333;
    z-index: 3;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    user-select: none;
}

/* Joystick Styling */
#joystick-container {
    position: absolute;
    bottom: max(20px, calc(20px + env(safe-area-inset-bottom)));
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    touch-action: none;
}

#joystick-base {
    position: relative;
    width: clamp(110px, 28vw, 130px);
    height: clamp(110px, 28vw, 130px);
    min-width: 110px;
    min-height: 110px;
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
}

#joystick-knob {
    position: absolute;
    width: clamp(50px, 12.5vw, 60px);
    height: clamp(50px, 12.5vw, 60px);
    min-width: 50px;
    min-height: 50px;
    background-color: rgba(0, 0, 0, 0.6);
    border-radius: 50%;
    transform: translate(-50%, -50%);
}

/* Question Screen */
#question-screen {
    background-color: rgba(0, 0, 0, 0.7);
}

#question-box {
    background-color: white;
    padding: clamp(16px, 4vw, 24px);
    border-radius: 10px;
    text-align: center;
    max-width: clamp(280px, 85vw, 350px);
    width: 90%;
    max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 40px);
    overflow-y: auto;
}

#question-box h2 {
    color: #ff6b6b;
    margin-bottom: clamp(12px, 3vw, 18px);
    font-size: clamp(20px, 5vw, 28px);
    line-height: 1.2;
}

#question {
    font-size: clamp(24px, 6vw, 36px);
    margin: clamp(12px, 3vw, 18px) 0;
    font-weight: bold;
    line-height: 1.3;
}

#answer-input {
    width: 100%;
    padding: clamp(12px, 3vw, 16px);
    font-size: clamp(20px, 5vw, 24px);
    border: 2px solid #ddd;
    border-radius: 5px;
    margin-bottom: clamp(12px, 3vw, 18px);
    min-height: 48px; /* Minimum touch target */
    text-align: center;
    touch-action: manipulation;
}

#feedback {
    margin-top: 10px;
    padding: 8px;
    border-radius: 5px;
}

#feedback.correct {
    background-color: #d4edda;
    color: #155724;
}

#feedback.incorrect {
    background-color: #f8d7da;
    color: #721c24;
}

.question-countdown {
    margin: 10px 0;
    font-weight: bold;
}

.countdown-warning {
    color: #ff0000;
}

/* Game Over Screen */
.game-over-content {
    text-align: center;
    background-color: white;
    padding: clamp(16px, 4vw, 24px);
    border-radius: 10px;
    max-width: 90%;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 40px);
    overflow-y: auto;
}

.game-over-content h1 {
    color: #ff6b6b;
    margin-bottom: clamp(16px, 4vw, 24px);
    font-size: clamp(24px, 6vw, 32px);
    line-height: 1.2;
}

#final-score {
    margin: clamp(16px, 4vw, 24px) 0;
    font-size: clamp(16px, 4vw, 20px);
    line-height: 1.4;
}

#play-again-button {
    background-color: #ff6b6b;
    margin-top: clamp(16px, 4vw, 24px);
    min-height: 48px;
}

/* Score Animation */
.score-animation {
    position: absolute;
    color: #4CAF50;
    font-weight: bold;
    font-size: 1.5rem;
    opacity: 0;
    transition: transform 1s, opacity 1s;
}

.score-highlight {
    animation: highlight 0.6s ease-in-out;
}

@keyframes highlight {
    0%, 100% {
        color: inherit;
    }
    50% {
        color: #4CAF50;
        transform: scale(1.2);
    }
}

/* Mobile Specific Styles */
@media (max-width: 768px) {
    .start-content h1 {
        font-size: clamp(22px, 5.5vw, 32px);
    }
    
    #car {
        width: clamp(40px, 10vw, 60px);
        height: clamp(80px, 20vw, 100px);
        background-size: contain;
    }
    
    .question-mark {
        width: clamp(32px, 8vw, 40px);
        height: clamp(32px, 8vw, 40px);
        font-size: clamp(18px, 4.5vw, 24px);
        min-width: 44px; /* Minimum touch target */
        min-height: 44px;
    }
    
    .mobile-only {
        display: block;
    }
    
    .desktop-only {
        display: none;
    }
    
    #joystick-container {
        display: block;
    }
    
    .stop-sign {
        width: clamp(32px, 8vw, 40px);
        height: clamp(32px, 8vw, 40px);
        font-size: clamp(10px, 2.5vw, 12px);
        min-width: 44px;
        min-height: 44px;
    }
    
    .game-over-content {
        max-width: 90%;
        padding: clamp(16px, 4vw, 24px);
        max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 40px);
        overflow-y: auto;
    }
    
    .game-over-content h1 {
        font-size: clamp(24px, 6vw, 32px);
        margin-bottom: clamp(16px, 4vw, 24px);
    }
}

/* iPhone 15 specific optimizations (390x844) */
@media screen and (max-width: 430px) {
    .start-content {
        width: 100%;
        border-radius: 0;
        max-height: 100dvh;
        padding: clamp(16px, 4vw, 24px);
    }
    
    #joystick-container {
        width: 110px;
        height: 110px;
        bottom: max(20px, calc(20px + env(safe-area-inset-bottom)));
    }
    
    #joystick-base {
        width: 110px;
        height: 110px;
        min-width: 110px;
        min-height: 110px;
    }
    
    #joystick-knob {
        width: 55px;
        height: 55px;
        min-width: 55px;
        min-height: 55px;
    }
    
    #question-box {
        max-width: 95%;
        padding: clamp(14px, 3.5vw, 20px);
    }
    
    .game-over-content {
        width: 100%;
        border-radius: 0;
        max-height: 100dvh;
    }
}

/* Desktop Specific Styles */
@media (min-width: 769px) {
    .mobile-only {
        display: none;
    }
    
    .desktop-only {
        display: block;
    }
}

/* Stopbord styling */
.stop-sign {
    position: absolute;
    width: 40px;
    height: 40px;
    background-color: #ff3333;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 12px;
    box-shadow: 0 3px 5px rgba(0, 0, 0, 0.3);
    z-index: 5;
    border: 2px solid white;
    transform: rotate(0deg);
    transition: transform 0.5s ease;
}

/* Animatie voor feedback popup bij stopbord botsing */
@keyframes fadeUpAndOut {
    0% {
        opacity: 0;
        transform: translateY(0);
    }
    20% {
        opacity: 1;
    }
    100% {
        opacity: 0;
        transform: translateY(-30px);
    }
}

.feedback-popup {
    pointer-events: none;
    font-size: 16px;
    text-shadow: 0 0 4px rgba(0, 0, 0, 0.7);
} 