* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    min-height: 100dvh;
    background: linear-gradient(180deg, #2d3a2d 0%, #1a221a 100%);
    font-family: 'Press Start 2P', cursive;
    touch-action: manipulation;
    overflow-x: hidden;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.game-container {
    position: relative;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 12px;
    padding: 16px;
    box-shadow:
        0 0 0 2px #445d46,
        0 8px 32px rgba(0, 0, 0, 0.5),
        inset 0 0 60px rgba(61, 80, 64, 0.2);
    max-width: 100%;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    gap: 16px;
}

.game-title {
    font-size: 18px;
    color: #9fcb9f;
    text-shadow: 0 0 10px rgba(159, 203, 159, 0.5);
    letter-spacing: 2px;
}

.game-library-btn {
    font-family: 'Press Start 2P', cursive;
    font-size: 10px;
    padding: 8px 12px;
    background: #3d5040;
    color: #9fcb9f;
    text-decoration: none;
    border: 2px solid #4d6250;
    border-radius: 4px;
    transition: all 0.2s;
}

.game-library-btn:hover {
    background: #4d6250;
    color: #c5e0c5;
    box-shadow: 0 0 12px rgba(159, 203, 159, 0.35);
}

.mute-btn {
    font-size: 18px;
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid #445d46;
    border-radius: 4px;
    padding: 6px 10px;
    cursor: pointer;
    transition: all 0.2s;
}
.mute-btn:hover {
    border-color: #4d6250;
    background: rgba(68, 93, 70, 0.35);
}

.score-bar {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 12px;
    color: #9fcb9f;
}

.score, .high-score, .combo {
    background: rgba(0, 0, 0, 0.35);
    padding: 6px 12px;
    border-radius: 4px;
    border: 1px solid #445d46;
}

.throttle-indicator {
    min-width: 24px;
    text-align: center;
    font-size: 12px;
}
.throttle-indicator.throttle-boost {
    color: #7fbf7f;
}
.throttle-indicator.throttle-brake {
    color: #bc8f8f;
}

.combo {
    color: #78a078;
    min-width: 40px;
    text-align: center;
}

.combo.combo-active {
    color: #ffd700;
    border-color: #b8860b;
    animation: combo-pulse 0.3s ease-out;
}

/* Hide empty indicators to avoid empty boxes */
.throttle-indicator:empty,
.combo:empty {
    min-width: 0;
    padding: 0;
    margin: 0 -4px;
    border: none;
    background: transparent !important;
}

@keyframes combo-pulse {
    0% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

#gameCanvas {
    display: block;
    background: #1a221a;
    border: 2px solid #445d46;
    border-radius: 6px;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    touch-action: none;
}

/* Start screen */
.start-screen {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    background: rgba(45, 58, 45, 0.95);
    padding: 32px;
    border-radius: 8px;
    border: 2px solid #4d6250;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
    z-index: 10;
    animation: fade-in 0.5s ease-out;
}

@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.start-screen h2 {
    font-size: 20px;
    color: #9fcb9f;
    margin-bottom: 16px;
    text-shadow: 0 0 8px rgba(159, 203, 159, 0.5);
}

.start-screen p {
    font-size: 10px;
    color: #78a078;
    line-height: 1.8;
    margin-bottom: 12px;
}

.start-screen .controls {
    font-size: 8px;
    color: #628a62;
    margin-bottom: 24px;
}

#startButton {
    font-family: 'Press Start 2P', cursive;
    font-size: 14px;
    padding: 16px 32px;
    background: #3d5040;
    color: #9fcb9f;
    border: 2px solid #4d6250;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

#startButton:hover {
    background: #4d6250;
    color: #c5e0c5;
    box-shadow: 0 0 20px rgba(159, 203, 159, 0.4);
}

/* Game over */
.game-over {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    background: rgba(45, 58, 45, 0.98);
    padding: 32px;
    border-radius: 8px;
    border: 2px solid #5a3d3d;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.6);
    z-index: 10;
    animation: game-over-in 0.4s ease-out;
}

@keyframes game-over-in {
    from { opacity: 0; transform: translate(-50%, -50%) scale(0.9); }
    to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.game-over h2 {
    font-size: 16px;
    color: #c9a0a0;
    margin-bottom: 20px;
    text-shadow: 0 0 8px rgba(201, 160, 160, 0.5);
}

.game-over p {
    font-size: 12px;
    color: #9fcb9f;
    margin-bottom: 12px;
}

.game-over .new-best {
    color: #ffd700;
    font-size: 14px;
    animation: new-best-pulse 0.6s ease-out;
}

@keyframes new-best-pulse {
    0% { transform: scale(1.3); opacity: 0; }
    50% { transform: scale(1.1); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

#restartButton {
    font-family: 'Press Start 2P', cursive;
    font-size: 12px;
    margin-top: 20px;
    padding: 14px 28px;
    background: #3d5040;
    color: #9fcb9f;
    border: 2px solid #4d6250;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

#restartButton:hover {
    background: #4d6250;
    color: #c5e0c5;
    box-shadow: 0 0 20px rgba(159, 203, 159, 0.4);
}

.hidden {
    display: none !important;
}

/* Show mobile controls on touch devices, desktop otherwise */
.controls-mobile {
    display: none;
}
@media (pointer: coarse), (max-width: 600px) {
    .controls-desktop {
        display: none !important;
    }
    .controls-mobile {
        display: block !important;
    }
}

/* Tablet */
@media (max-width: 860px) {
    .game-container {
        padding: 12px;
        width: 100%;
        max-width: min(100vw, 860px);
    }

    .game-header {
        gap: 10px;
        flex-wrap: wrap;
    }

    .game-title {
        font-size: 14px;
        flex: 1;
        min-width: 0;
    }

    .game-library-btn {
        font-size: 8px;
        padding: 8px 12px;
        min-height: 36px;
    }

    .mute-btn {
        font-size: 16px;
        padding: 8px 12px;
        min-width: 44px;
        min-height: 44px;
    }

    .score-bar {
        font-size: 10px;
        gap: 6px;
        flex-wrap: wrap;
    }

    .score, .high-score, .combo {
        padding: 6px 10px;
    }

    .throttle-indicator {
        min-width: 20px;
    }

    .combo {
        min-width: 36px;
    }

    .start-screen {
        padding: 24px 20px;
        max-width: calc(100vw - 40px);
    }

    .start-screen h2 {
        font-size: 16px;
    }

    .start-screen p {
        font-size: 8px;
    }

    .game-over {
        padding: 24px 20px;
        max-width: calc(100vw - 40px);
    }

    .game-over h2 {
        font-size: 14px;
    }

    .game-over p {
        font-size: 10px;
    }

    #restartButton, #startButton {
        font-size: 10px;
        padding: 14px 28px;
        min-height: 48px;
    }
}

/* Phone */
@media (max-width: 480px) {
    body {
        align-items: stretch;
        padding: 0;
    }

    .game-container {
        padding: 0;
        width: 100vw;
        height: 100dvh;
        min-height: 100dvh;
        min-height: 100vh;
        border-radius: 0;
        box-shadow: none;
        background: #1a221a;
        overflow: hidden;
    }

    .game-header {
        position: absolute;
        top: calc(env(safe-area-inset-top) + 6px);
        left: 6px;
        right: 6px;
        z-index: 20;
        flex-direction: row;
        margin-bottom: 0;
        gap: 8px;
        background: rgba(0, 0, 0, 0.25);
        border-radius: 6px;
        padding: 6px;
    }

    .game-title {
        font-size: 10px;
        line-height: 1.4;
    }

    .game-library-btn {
        font-size: 6px;
        padding: 10px 12px;
        min-height: 44px;
    }

    .mute-btn {
        font-size: 20px;
        padding: 10px;
        min-width: 44px;
        min-height: 44px;
    }

    .score-bar {
        position: absolute;
        top: calc(env(safe-area-inset-top) + 52px);
        left: 6px;
        right: 6px;
        z-index: 20;
        background: rgba(0, 0, 0, 0.2);
        border-radius: 6px;
        padding: 4px;
        font-size: 8px;
        margin-bottom: 0;
        gap: 4px;
    }

    .score, .high-score {
        padding: 6px 8px;
    }

    .score span, .high-score span {
        font-size: 8px;
    }

    .throttle-indicator {
        min-width: 18px;
        font-size: 10px;
    }
    .combo {
        min-width: 32px;
        font-size: 8px;
    }

    #gameCanvas {
        width: 100vw;
        height: 100dvh;
        max-width: 100vw;
        max-height: 100dvh;
        border-radius: 0;
        border: none;
    }

    .start-screen {
        padding: 20px 16px;
        width: calc(100% - 32px);
        max-width: 360px;
    }

    .start-screen h2 {
        font-size: 14px;
        margin-bottom: 12px;
    }

    .start-screen p {
        font-size: 6px;
        line-height: 1.6;
    }

    .controls-mobile {
        font-size: 6px !important;
    }

    #startButton {
        font-size: 8px;
        padding: 16px 24px;
        min-height: 48px;
    }

    .game-over {
        padding: 20px 16px;
        width: calc(100% - 32px);
        max-width: 360px;
    }

    .game-over h2 {
        font-size: 12px;
        margin-bottom: 16px;
    }

    .game-over p {
        font-size: 8px;
    }

    .game-over .new-best {
        font-size: 10px;
    }

    #restartButton {
        font-size: 8px;
        padding: 16px 24px;
        min-height: 48px;
    }
}

/* Very small phones */
@media (max-width: 360px) {
    .game-title {
        font-size: 8px;
    }

    .score-bar {
        font-size: 6px;
    }

    .score, .high-score {
        padding: 4px 6px;
    }
}

/* Landscape on small screens - canvas scales to fit */
@media (max-height: 450px) and (max-width: 900px) {
    .game-container {
        padding: 6px;
    }
    .game-header, .score-bar {
        margin-bottom: 4px;
    }
}

@media (max-height: 450px) and (max-width: 480px) {
    .game-container {
        padding: 0;
    }
    .game-header, .score-bar {
        margin-bottom: 0;
    }
}
