* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Nunito', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

:root {
    --primary-color: #4285f4;
    --secondary-color: #ffd166;
    --accent-color: #34a853;
    --accent-dark: #2a7b3f;
    --background-color: #fff;
    --text-color: #333;
    --white: #fff;
    --grass-color: #4caf50;
    --road-color: #37474f;
    --sky-color: #87ceeb;
}

html, body {
    width: 100%;
    height: 100%;
    overscroll-behavior: none;
    overflow: hidden;
    touch-action: none;
    height: 100dvh; /* Dynamic viewport height for mobile */
}

body {
    background-color: #ffffff;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    margin: 0;
    position: relative;
}

/* Confetti animation for start screen */
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: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    background-color: transparent;
    overflow: hidden;
    transition: all 0.3s ease;
}

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

/* Start screen transparent to show confetti */
#start-screen {
    background-color: transparent;
}

.hidden {
    display: none !important;
}

/* Game screen needs sky background for 3D canvas */
#game-screen {
    background: #06101c;
    /* The renderer is sized to the visual viewport.  The generic screen
       padding would make that canvas overflow by a few pixels on mobile. */
    width: 100dvw;
    height: 100dvh;
    padding: 0;
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: none;
}

#game-screen canvas {
    display: block;
    width: 100dvw !important;
    height: 100dvh !important;
    max-width: none;
    max-height: none;
}

#game-ui { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
#game-ui button, #joystick-container { pointer-events: auto; }

#score-container {
    position: absolute;
    top: max(20px, env(safe-area-inset-top));
    left: max(20px, env(safe-area-inset-left));
    min-width: 172px;
    padding: 14px 16px 12px;
    color: #f5f3e9;
    background: linear-gradient(135deg, rgba(5, 14, 25, .88), rgba(10, 29, 45, .58));
    border: 1px solid rgba(181, 230, 255, .3);
    border-left: 3px solid #f6bd4c;
    border-radius: 5px;
    box-shadow: 0 12px 40px rgba(0,0,0,.24), inset 0 1px 0 rgba(255,255,255,.12);
    backdrop-filter: blur(12px);
}
.hud-label { color: #9fc7df; font: 700 12px/1 'Barlow Condensed', sans-serif; letter-spacing: .16em; }
.hud-score { font: 800 clamp(32px, 5vw, 46px)/.94 'Barlow Condensed', sans-serif; letter-spacing: .02em; margin: 5px 0; }
.hud-unit { font-size: .32em; color: #f6bd4c; margin-left: 5px; letter-spacing: .12em; }
.hud-speed { color: #bdd3e1; font: 700 13px/1 'Barlow Condensed', sans-serif; letter-spacing: .12em; }
#back-button { position:absolute; left: 0; top: calc(100% + 10px); background:rgba(5,14,25,.72); border:1px solid rgba(181,230,255,.25); color:#e8f3f7; padding:8px 12px; font-size:13px; }
#mission-container { position:absolute; top:max(24px, env(safe-area-inset-top)); left:50%; transform:translateX(-50%); padding:10px 16px; color:#eaf8ff; background:rgba(5,14,25,.54); border:1px solid rgba(181,230,255,.2); border-radius:999px; font:700 15px/1 'Nunito',sans-serif; box-shadow:0 10px 30px rgba(0,0,0,.2); backdrop-filter:blur(10px); }
.mission-dot { display:inline-block; width:8px; height:8px; margin-right:8px; border-radius:50%; background:#f6bd4c; box-shadow:0 0 12px #f6bd4c; }

/* Loading screen */
#loading-screen {
    background-color: rgba(0, 0, 0, 0.8);
    color: var(--white);
    z-index: 100;
}

.loader {
    border: 5px solid var(--white);
    border-top: 5px solid var(--primary-color);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

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

.car-preview-container {
    width: 200px;
    height: 150px;
    margin: 20px auto;
    background-color: var(--secondary-color);
    border-radius: 10px;
    overflow: hidden;
    position: relative;
}

/* Controls info */
.controls-info {
    background-color: #f9f9f9;
    padding: 15px;
    border-radius: 10px;
    margin: 15px auto;
    border: 2px dashed var(--secondary-color);
    width: 100%;
    max-width: 400px;
}

.controls-info p {
    margin: 5px 0;
    font-size: clamp(14px, 3vw, 18px);
    text-align: center;
}

/* Mode selection styling */
.mode-selection {
    margin: 15px auto;
    width: 100%;
    max-width: 400px;
}

.mode-selection h3 {
    color: var(--primary-color);
    font-size: clamp(18px, 4vw, 22px);
    margin-bottom: 10px;
}

.mode-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.mode-button {
    flex: 1;
    max-width: 150px;
    padding: 12px 16px;
    border: 3px solid #9bb9df;
    border-radius: 12px;
    background: #f7fbff;
    color: #1d466f;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    margin-top: 0;
    box-shadow: 0 4px 0 #8eacc8;
    text-shadow: none;
}

.mode-button:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: 0 6px 0 #76a1ca;
}

.mode-button.active {
    border-color: var(--primary-color);
    background: var(--primary-color);
    color: white;
    box-shadow: 0 5px 0 #2473d5;
}

.mode-icon {
    font-size: 28px;
    font-weight: bold;
}

.mode-label {
    font-size: 14px;
    font-weight: 600;
}

/* Tafels selection styling */
.tafels-selection {
    background-color: #f9f9f9;
    padding: 15px;
    border-radius: 10px;
    margin: 15px auto;
    border: 2px dashed var(--primary-color);
    width: 100%;
    max-width: 400px;
}

.tafels-selection h3 {
    color: var(--primary-color);
    font-size: clamp(18px, 4vw, 22px);
    margin-bottom: 10px;
}

.slider-container {
    position: relative;
    width: 100%;
    margin: 15px 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.slider {
    -webkit-appearance: none;
    width: 80%;
    height: 10px;
    border-radius: 5px;
    background: #d3d3d3;
    outline: none;
    opacity: 0.7;
    -webkit-transition: .2s;
    transition: opacity .2s;
}

.slider:hover {
    opacity: 1;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 25px;
    height: 25px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
}

.slider::-moz-range-thumb {
    width: 25px;
    height: 25px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
}

.slider-value {
    margin-left: 15px;
    width: 30px;
    height: 30px;
    background-color: var(--primary-color);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

.tafels-display {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-top: 15px;
}

.tafel-number {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: #e0e0e0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    opacity: 0.6;
    transition: all 0.2s ease;
}

.tafel-number.active {
    background-color: var(--accent-color);
    color: white;
    opacity: 1;
    transform: scale(1.05);
}

/* The multiplication table is a 1–10 overview. Keep its full sequence
   visible at once instead of splitting it into rows at narrower widths. */
#multiplication-settings .tafels-display {
    flex-wrap: nowrap;
    justify-content: space-between;
    gap: 3px;
}

#multiplication-settings .tafel-number {
    width: calc((100% - 27px) / 10);
    height: clamp(29px, 7.5vw, 36px);
    min-width: 0;
    min-height: 0;
    aspect-ratio: 1;
    font-size: clamp(12px, 3.4vw, 15px);
    flex: 0 1 auto;
}

/* Typography */
h1 {
    color: var(--primary-color);
    font-size: clamp(32px, 7vw, 48px);
    margin-bottom: 20px;
    text-shadow: 2px 2px 0 var(--secondary-color);
    text-align: center;
}

p {
    margin: 10px 0;
    font-size: clamp(16px, 3vw, 20px);
    color: var(--text-color);
    text-align: center;
}

/* Buttons */
button {
    background-color: var(--accent-color);
    color: var(--white);
    border: none;
    padding: 10px 20px;
    font-size: clamp(18px, 4vw, 24px);
    border-radius: 10px;
    cursor: pointer;
    margin-top: 15px;
    box-shadow: 0 5px 0 var(--accent-dark);
    transition: all 0.1s;
    -webkit-appearance: none;
}

button:hover {
    transform: translateY(2px);
    box-shadow: 0 3px 0 var(--accent-dark);
}

button:active {
    transform: translateY(5px);
    box-shadow: 0 0 0 var(--accent-dark);
}

/* Desktop/mobile display */
.desktop-only {
    display: block;
}

.mobile-only {
    display: none;
}

/* Game UI */
#game-ui {
    z-index: 5;
}

#game-ui > * {
    pointer-events: auto;
}

#score-container {
    display: block;
}

#back-button {
    box-shadow: none;
}

#back-button:hover {
    box-shadow: none;
}

#back-button:active {
    box-shadow: none;
}

/* Mobile joystick */
#joystick-container {
    position: absolute;
    bottom: max(30px, calc(30px + env(safe-area-inset-bottom)));
    left: 50%;
    transform: translateX(-50%);
    width: 120px;
    height: 120px;
    z-index: 10;
    display: none;
    touch-action: none;
}

#joystick-base {
    position: absolute;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.3);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    min-width: 120px;
    min-height: 120px;
}

#joystick-knob {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 50%;
    height: 50%;
    background-color: rgba(255, 255, 255, 0.7);
    border-radius: 50%;
    pointer-events: none;
    min-width: 60px;
    min-height: 60px;
    transform: translate(-50%, -50%);
    transition: transform 140ms cubic-bezier(.2, .8, .2, 1);
}

#joystick-container.is-active #joystick-knob { transition: none; }

/* Game over screen */
.game-over-content {
    background-color: rgba(255, 255, 255, 0.9);
    border-radius: 20px;
    width: 90%;
    max-width: 500px;
    padding: 30px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    text-align: center;
    margin: 0 auto;
}

/* Math problem popup */
.math-problem-container {
    perspective: 1000px;
    width: 90%;
    max-width: 500px;
    margin: 0 auto;
}

.math-problem-content {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.8s;
    transform-style: preserve-3d;
    background-color: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    text-align: center;
    border: 4px solid var(--primary-color);
}

.math-problem-content.flipped {
    transform: rotateY(180deg);
}

.math-problem-front, .math-problem-back {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden; /* Safari */
    backface-visibility: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    left: 0;
    top: 0;
    padding: 30px;
}

.math-problem-back {
    transform: rotateY(180deg);
}

.correct-answer {
    color: #444;
    font-size: clamp(1.5rem, 4vw, 2rem);
    font-weight: bold;
    margin: 15px 0;
}

.score-penalty {
    color: #ff5252;
    font-weight: bold;
    font-size: clamp(1rem, 3vw, 1.25rem);
    margin: 10px 0;
}

.score-bonus {
    color: #4CAF50;
    font-weight: bold;
    font-size: clamp(1rem, 3vw, 1.25rem);
    margin: 10px 0;
}

h2 {
    color: var(--primary-color);
    font-size: clamp(26px, 6vw, 36px);
    margin-bottom: 20px;
    text-align: center;
}

#math-problem, #math-answer {
    padding: 20px;
    background-color: #f9f9f9;
    border-radius: 10px;
    margin: 15px auto;
    border: 2px dashed var(--secondary-color);
    width: 100%;
}

#problem-text {
    font-size: clamp(24px, 5vw, 42px);
    font-weight: bold;
    margin-bottom: 20px;
}

#answer-input {
    width: 100%;
    max-width: 200px;
    padding: 12px;
    font-size: clamp(18px, 4vw, 24px);
    text-align: center;
    border: 3px solid var(--accent-color);
    border-radius: 10px;
    margin-bottom: 15px;
}

/* Shake animation for wrong answers */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-8px); }
    20%, 40%, 60%, 80% { transform: translateX(8px); }
}

.shake {
    animation: shake 0.5s cubic-bezier(.36,.07,.19,.97) both;
    border-color: #ff3c3c !important;
}

#final-score {
    background-color: #f9f9f9;
    padding: 15px;
    border-radius: 10px;
    margin: 15px auto;
    border: 2px dashed var(--secondary-color);
}

#final-score p {
    font-size: clamp(18px, 4vw, 24px);
    font-weight: bold;
}

/* Success answer style */
.success-answer {
    color: #4CAF50;
    font-size: clamp(1.5rem, 4vw, 2rem);
    font-weight: bold;
    margin: 15px 0;
}

/* Responsive styles */
@media (max-width: 768px) {
    .desktop-only {
        display: none;
    }
    
    .mobile-only {
        display: block;
    }
    
    #joystick-container {
        display: block;
    }
    
    #score-container {
        padding: clamp(10px, 2vw, 15px);
    }
    
    button {
        padding: clamp(12px, 3vw, 16px) clamp(16px, 4vw, 24px);
        font-size: clamp(16px, 4vw, 20px);
        min-height: 44px; /* Minimum touch target for iPhone */
        min-width: 44px;
    }
    
    .start-content, .game-over-content, .math-problem-content {
        width: 95%;
        padding: clamp(16px, 3vw, 24px);
    }

    .math-problem-front, .math-problem-back {
        padding: clamp(12px, 2vw, 20px);
    }
    
    .tafel-number {
        width: clamp(35px, 8vw, 40px);
        height: clamp(35px, 8vw, 40px);
        font-size: clamp(14px, 3vw, 16px);
        min-width: 44px; /* Minimum touch target */
        min-height: 44px;
    }

    /* Keep the 1–10 table overview together: it is a read-only progress
       indicator, so compact circles are clearer than wrapping onto a new row. */
    #multiplication-settings .tafels-display {
        flex-wrap: nowrap;
        justify-content: space-between;
        gap: 3px;
    }

    #multiplication-settings .tafel-number {
        width: calc((100% - 27px) / 10);
        height: clamp(29px, 7.5vw, 36px);
        min-width: 0;
        min-height: 0;
        aspect-ratio: 1;
        font-size: clamp(12px, 3.4vw, 15px);
        flex: 0 1 auto;
    }
    
    .slider {
        width: 70%;
        height: 12px; /* Larger touch target */
    }
    
    .slider::-webkit-slider-thumb {
        width: 28px;
        height: 28px;
    }
    
    .slider::-moz-range-thumb {
        width: 28px;
        height: 28px;
    }

    .correct-answer {
        font-size: clamp(24px, 5vw, 40px);
        margin: 15px 0;
    }

    .score-penalty {
        font-size: clamp(18px, 4vw, 24px);
    }
    
    .car-preview-container {
        width: clamp(150px, 40vw, 200px);
        height: clamp(100px, 30vw, 150px);
    }
}

/* 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);
    }
    
    h1 {
        font-size: clamp(28px, 7vw, 36px);
        margin-bottom: 16px;
        line-height: 1.2;
    }
    
    p {
        font-size: clamp(14px, 3.5vw, 18px);
        line-height: 1.4;
    }
    
    .tafels-selection, .controls-info {
        padding: 12px;
        margin: 12px auto;
    }
    
    .tafels-selection h3 {
        font-size: clamp(16px, 4vw, 20px);
    }
    
    .tafels-display {
        gap: 6px;
        margin-top: 12px;
    }
    
    .slider-container {
        margin: 12px 0;
    }
    
    #joystick-container {
        width: 110px;
        height: 110px;
        bottom: max(25px, calc(25px + env(safe-area-inset-bottom)));
    }
    
    #joystick-base {
        min-width: 110px;
        min-height: 110px;
    }
    
    #joystick-knob {
        min-width: 55px;
        min-height: 55px;
    }
    
    .math-problem-container {
        width: 95%;
        max-width: 100%;
    }
    
    .math-problem-content {
        padding: clamp(16px, 3vw, 24px);
    }
    
    #answer-input {
        padding: 14px;
        font-size: clamp(20px, 5vw, 24px);
        min-height: 48px;
    }
    
    #back-button {
        padding: 10px 16px;
        font-size: 15px;
        min-height: 44px;
    }
}

/* Compact, no-scroll phone layout (including iPhone 12: 390 x 844). */
@media screen and (max-width: 430px) and (min-height: 700px) {
    #start-screen {
        overflow: hidden;
        padding: max(8px, env(safe-area-inset-top)) 10px max(8px, env(safe-area-inset-bottom));
    }

    .start-content {
        width: 100%;
        max-height: none;
        overflow: hidden;
        padding: 11px 14px 13px;
        border-radius: 16px;
    }

    .start-content h1 {
        font-size: 29px;
        line-height: 1;
        margin: 0 0 6px;
    }

    .car-preview-container {
        width: 126px;
        height: 80px;
        margin: 5px auto 7px;
        border-radius: 9px;
    }

    .mode-selection,
    .tafels-selection,
    .controls-info {
        margin: 7px auto;
    }

    .mode-selection h3,
    .tafels-selection h3 {
        font-size: 16px;
        margin-bottom: 4px;
    }

    .mode-button {
        padding: 6px 9px;
        min-height: 52px;
        border-width: 2px;
        gap: 1px;
    }

    .mode-icon { font-size: 21px; }
    .mode-label { font-size: 12px; }

    .tafels-selection,
    .controls-info {
        padding: 8px 10px;
    }

    .tafels-selection p,
    .controls-info p {
        font-size: 12px;
        line-height: 1.2;
        margin: 2px 0;
    }

    .slider-container { margin: 7px 0; }
    .slider { height: 8px; }
    .slider::-webkit-slider-thumb { width: 22px; height: 22px; }
    .slider::-moz-range-thumb { width: 22px; height: 22px; }

    .tafel-number {
        width: 28px;
        height: 28px;
        min-width: 28px;
        min-height: 28px;
        font-size: 12px;
    }

    .tafels-display { gap: 4px; margin-top: 6px; }
    .controls-info .desktop-only { display: none; }
    #start-button { padding: 10px 18px; min-height: 42px; font-size: 16px; }
}

/* For very small screens */
@media (max-width: 350px) {
    #joystick-container {
        width: 100px;
        height: 100px;
        bottom: max(20px, calc(20px + env(safe-area-inset-bottom)));
    }
    
    #joystick-base {
        min-width: 100px;
        min-height: 100px;
    }
    
    #joystick-knob {
        min-width: 50px;
        min-height: 50px;
    }
    
    #score-container {
        padding: 8px 12px;
    }
    
    button {
        padding: 10px 14px;
        font-size: 15px;
        min-height: 44px;
    }
    
    .tafel-number {
        width: clamp(32px, 8vw, 36px);
        height: clamp(32px, 8vw, 36px);
        font-size: 13px;
        min-width: 44px;
        min-height: 44px;
    }
    
    .tafels-display {
        gap: 5px;
    }

    .math-problem-front, .math-problem-back {
        padding: 12px;
    }

    #math-problem, #math-answer {
        padding: 12px 8px;
    }
}

/* Landscape orientation for mobile */
@media screen and (max-height: 500px) and (orientation: landscape) {
    .start-content, .game-over-content {
        padding: 12px;
        max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 20px);
    }
    
    h1 {
        font-size: clamp(20px, 4vw, 24px);
        margin-bottom: 8px;
    }
    
    .car-preview-container {
        height: clamp(80px, 20vh, 100px);
        margin: 8px auto;
    }
    
    .controls-info {
        padding: 8px;
        margin: 8px auto;
    }
    
    #joystick-container {
        width: 90px;
        height: 90px;
        bottom: max(15px, calc(15px + env(safe-area-inset-bottom)));
    }
    
    #joystick-base {
        min-width: 90px;
        min-height: 90px;
    }
    
    #joystick-knob {
        min-width: 45px;
        min-height: 45px;
    }
}
