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

body {
    background: #F5F0E6;
    overflow: hidden;
    font-family: 'Caveat', cursive;
    touch-action: none;
    user-select: none;
}

#canvas {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

#title-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
    background: linear-gradient(135deg, #F5F0E6 0%, #E8E0D0 100%);
    pointer-events: auto;
}

#title {
    font-family: 'Caveat', cursive;
    font-size: clamp(2.5rem, 8vw, 5rem);
    font-weight: 700;
    color: #1A1A1A;
    text-align: center;
    padding: 0 20px;
    text-shadow: 3px 3px 0 #E85454, 6px 6px 0 rgba(0,0,0,0.1);
    animation: wobbleTitle 2s ease-in-out infinite;
    transform: rotate(-2deg);
}

@keyframes wobbleTitle {
    0%, 100% { transform: rotate(-2deg) scale(1); }
    50% { transform: rotate(2deg) scale(1.02); }
}

#highscore-display {
    font-size: 1.5rem;
    color: #555;
    margin-top: 20px;
}

#start-prompt {
    font-size: 1.8rem;
    color: #1A1A1A;
    margin-top: 40px;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

#controls-hint {
    margin-top: 30px;
    font-family: 'Patrick Hand', cursive;
    font-size: 1.2rem;
    color: #666;
    text-align: center;
    line-height: 1.8;
    padding: 20px;
    border: 2px dashed #999;
    border-radius: 10px;
    background: rgba(255,255,255,0.5);
}

#hud {
    display: none;
    position: fixed;
    top: 15px;
    left: 15px;
    z-index: 50;
    pointer-events: none;
}

#speedometer {
    background: #F5F0E6;
    border: 3px solid #1A1A1A;
    border-radius: 50%;
    width: 80px;
    height: 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-family: 'Caveat', cursive;
    box-shadow: 3px 3px 0 rgba(0,0,0,0.2);
}

#speed-value {
    font-size: 2rem;
    font-weight: 700;
    color: #1A1A1A;
    line-height: 1;
}

#speed-label {
    font-size: 0.8rem;
    color: #666;
}

#score-display {
    margin-top: 10px;
    background: #F5F0E6;
    border: 2px solid #1A1A1A;
    padding: 5px 15px;
    border-radius: 8px;
    font-size: 1.2rem;
    box-shadow: 2px 2px 0 rgba(0,0,0,0.2);
}

#chaos-meter {
    margin-top: 10px;
    background: #F5F0E6;
    border: 2px solid #1A1A1A;
    padding: 5px 10px;
    border-radius: 8px;
    box-shadow: 2px 2px 0 rgba(0,0,0,0.2);
}

#chaos-label {
    font-size: 0.9rem;
    color: #666;
}

#chaos-bar {
    width: 100px;
    height: 12px;
    background: #DDD;
    border: 2px solid #1A1A1A;
    border-radius: 6px;
    overflow: hidden;
    margin-top: 3px;
}

#chaos-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #E85454, #FF6B6B);
    transition: width 0.3s;
}

#minimap {
    display: none;
    position: fixed;
    top: 15px;
    right: 15px;
    width: 100px;
    height: 100px;
    background: #F5F0E6;
    border: 3px solid #1A1A1A;
    border-radius: 8px;
    z-index: 50;
    box-shadow: 3px 3px 0 rgba(0,0,0,0.2);
    overflow: hidden;
}

#minimap canvas {
    width: 100%;
    height: 100%;
}

#controls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 50;
}

#mobile-controls {
    display: none;
    justify-content: space-between;
    align-items: flex-end;
    padding: 20px;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
}

#dpad {
    display: grid;
    grid-template-areas: 
        ". up ."
        "left . right"
        ". down .";
    gap: 5px;
}

.dpad-btn {
    width: 55px;
    height: 55px;
    background: rgba(245, 240, 230, 0.9);
    border: 3px solid #1A1A1A;
    border-radius: 12px;
    font-size: 1.5rem;
    font-weight: bold;
    color: #1A1A1A;
    cursor: pointer;
    box-shadow: 2px 2px 0 rgba(0,0,0,0.3);
    transition: transform 0.1s, box-shadow 0.1s;
}

.dpad-btn:active {
    transform: translate(2px, 2px);
    box-shadow: none;
}

#btn-up { grid-area: up; }
#btn-down { grid-area: down; }
#btn-left { grid-area: left; }
#btn-right { grid-area: right; }

#action-btns {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.action-btn {
    width: 70px;
    height: 55px;
    background: rgba(245, 240, 230, 0.9);
    border: 3px solid #1A1A1A;
    border-radius: 12px;
    font-family: 'Patrick Hand', cursive;
    font-size: 0.9rem;
    font-weight: bold;
    color: #1A1A1A;
    cursor: pointer;
    box-shadow: 2px 2px 0 rgba(0,0,0,0.3);
    transition: transform 0.1s, box-shadow 0.1s;
}

#btn-brake {
    background: rgba(232, 84, 84, 0.9);
    color: white;
}

#btn-honk {
    background: rgba(255, 213, 79, 0.9);
}

.action-btn:active {
    transform: translate(2px, 2px);
    box-shadow: none;
}

#footer {
    position: fixed;
    bottom: 5px;
    right: 10px;
    z-index: 40;
    font-family: 'Patrick Hand', cursive;
    font-size: 0.9rem;
    color: #888;
    display: flex;
    gap: 10px;
}

#footer a {
    color: #666;
    text-decoration: none;
    border-bottom: 1px dashed #999;
}

#footer a:hover {
    color: #E85454;
}

@media (max-width: 768px) {
    #hud {
        top: 10px;
        left: 10px;
        transform: scale(0.85);
        transform-origin: top left;
    }
    
    #minimap {
        width: 70px;
        height: 70px;
        top: 10px;
        right: 10px;
    }
    
    #controls-hint {
        font-size: 1rem;
        padding: 15px;
    }
    
    #footer {
        display: none;
    }
}

@media (hover: none) and (pointer: coarse) {
    #mobile-controls {
        display: flex !important;
    }
}