@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

body {
    background-color: #1a1a2e;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    min-height: 100dvh;
    font-family: 'Press Start 2P', 'Courier New', monospace;
    touch-action: manipulation;
}

#game-container {
    position: relative;
    border: 4px solid #4a4a6a;
    border-radius: 8px;
    box-shadow: 0 0 20px rgba(100, 100, 200, 0.3);
}

#gameCanvas {
    display: block;
    background: linear-gradient(180deg, #87CEEB 0%, #B0E0E6 50%, #98FB98 95%, #228B22 100%);
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

#ui-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    pointer-events: none;
}

#score-display {
    position: absolute;
    top: 10px;
    right: 15px;
    color: #fff;
    font-size: 16px;
    text-shadow: 2px 2px 0 #000, -1px -1px 0 #000;
    letter-spacing: 1px;
}

/* Touch Controls - Hidden by default on desktop */
#touch-controls {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    justify-content: space-between;
    padding: 15px 25px;
    padding-bottom: max(15px, env(safe-area-inset-bottom));
    pointer-events: none;
    z-index: 100;
}

#touch-controls button {
    pointer-events: auto;
    width: 70px;
    height: 70px;
    font-size: 28px;
    border: 3px solid rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    background: rgba(100, 100, 200, 0.6);
    color: white;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    cursor: pointer;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
}

#touch-controls button:active {
    background: rgba(150, 150, 255, 0.8);
    transform: scale(0.92);
    border-color: white;
}

/* Mobile Portrait Mode */
@media (max-width: 850px), (pointer: coarse) {
    body {
        flex-direction: column;
        justify-content: flex-start;
        padding-top: 5px;
    }

    #game-container {
        border-width: 2px;
        border-radius: 4px;
        max-width: calc(100vw - 10px);
    }

    #gameCanvas {
        width: calc(100vw - 10px);
        max-width: 800px;
        height: auto;
    }

    #touch-controls {
        display: flex;
    }

    #score-display {
        font-size: 10px;
        top: 3px;
        right: 8px;
    }
}

/* Mobile Landscape Mode */
@media (max-height: 500px) and (orientation: landscape) {
    body {
        flex-direction: row;
        justify-content: center;
        align-items: center;
        padding: 5px;
    }

    #game-container {
        max-height: calc(100vh - 10px);
        max-height: calc(100dvh - 10px);
    }

    #gameCanvas {
        width: auto;
        height: calc(100vh - 20px);
        height: calc(100dvh - 20px);
        max-height: 600px;
        max-width: calc(100vw - 140px); /* Leave room for side buttons */
    }

    #touch-controls {
        position: fixed;
        bottom: auto;
        top: 50%;
        transform: translateY(-50%);
        left: 0;
        right: 0;
        padding: 0 10px;
        justify-content: space-between;
        align-items: center;
        pointer-events: none;
    }

    #touch-controls button {
        width: 55px;
        height: 55px;
        font-size: 22px;
        pointer-events: auto;
    }

    #score-display {
        font-size: 8px;
        top: 2px;
        right: 5px;
    }
}

/* Very small landscape (e.g. iPhone SE landscape) */
@media (max-height: 400px) and (orientation: landscape) {
    #touch-controls button {
        width: 45px;
        height: 45px;
        font-size: 18px;
    }

    #touch-controls {
        padding: 0 5px;
    }
}

/* Large phones portrait */
@media (min-width: 400px) and (max-width: 850px) and (orientation: portrait) {
    #touch-controls button {
        width: 80px;
        height: 80px;
        font-size: 32px;
    }

    #touch-controls {
        padding: 20px 30px;
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }
}

/* Prevent text selection and callouts on touch */
canvas, button {
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

/* Hide touch controls on devices with fine pointer (mouse) */
@media (pointer: fine) and (hover: hover) {
    #touch-controls {
        display: none !important;
    }
}

/* Speed Controls (mobile) */
#speed-controls {
    display: none;
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    align-items: center;
    gap: 8px;
    z-index: 50;
}

#speed-controls button {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.7);
    background: rgba(65, 105, 225, 0.8);
    color: white;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    touch-action: manipulation;
}

#speed-controls button:active {
    background: rgba(100, 149, 237, 0.9);
    transform: scale(0.95);
}

#speed-label {
    color: white;
    font-family: 'Press Start 2P', monospace;
    font-size: 10px;
    text-shadow: 1px 1px 2px #000;
    min-width: 40px;
    text-align: center;
}

/* Show speed controls on mobile/touch devices */
@media (max-width: 850px), (pointer: coarse) {
    #speed-controls {
        display: flex;
    }
}

/* Hide on desktop with mouse */
@media (pointer: fine) and (hover: hover) {
    #speed-controls {
        display: none !important;
    }
}

/* Help Button */
#help-btn {
    position: absolute;
    top: 45px;
    left: 10px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.7);
    background: rgba(65, 105, 225, 0.8);
    color: white;
    font-size: 20px;
    font-weight: bold;
    font-family: 'Press Start 2P', monospace;
    cursor: pointer;
    z-index: 50;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s, background 0.2s;
}

#help-btn:hover {
    transform: scale(1.1);
    background: rgba(100, 149, 237, 0.9);
}

#help-btn:active {
    transform: scale(0.95);
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 20px;
    box-sizing: border-box;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: linear-gradient(135deg, #1a1a2e 0%, #2d2d5a 100%);
    border: 3px solid #4a4a6a;
    border-radius: 12px;
    padding: 24px;
    max-width: 400px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 0 30px rgba(100, 100, 200, 0.4);
    font-family: 'Press Start 2P', monospace;
}

.modal-content h2 {
    color: #FFD700;
    font-size: 18px;
    text-align: center;
    margin-bottom: 20px;
    text-shadow: 2px 2px 0 #000;
}

.modal-content h3 {
    color: #87CEEB;
    font-size: 12px;
    margin: 16px 0 8px 0;
    text-shadow: 1px 1px 0 #000;
}

.modal-content p {
    color: #fff;
    font-size: 9px;
    line-height: 1.8;
    margin: 4px 0;
}

.modal-content p.green { color: #90EE90; }
.modal-content p.pink { color: #FFB6C1; }
.modal-content p.gold { color: #FFD700; }
.modal-content p.magenta { color: #FF69B4; }
.modal-content p.red { color: #FF6347; }

.close-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 30px;
    height: 30px;
    border: none;
    background: rgba(255, 0, 0, 0.6);
    color: white;
    font-size: 20px;
    border-radius: 50%;
    cursor: pointer;
    line-height: 1;
}

.close-btn:hover {
    background: rgba(255, 0, 0, 0.8);
}

.got-it-btn {
    display: block;
    width: 100%;
    margin-top: 20px;
    padding: 12px;
    background: linear-gradient(180deg, #4CAF50 0%, #388E3C 100%);
    border: 2px solid #2E7D32;
    border-radius: 8px;
    color: white;
    font-family: 'Press Start 2P', monospace;
    font-size: 12px;
    cursor: pointer;
    text-shadow: 1px 1px 0 #000;
}

.got-it-btn:hover {
    background: linear-gradient(180deg, #66BB6A 0%, #43A047 100%);
}

.got-it-btn:active {
    transform: scale(0.98);
}

/* Mobile modal adjustments */
@media (max-width: 850px) {
    .modal-content {
        padding: 16px;
        max-height: 70vh;
    }

    .modal-content h2 {
        font-size: 14px;
    }

    .modal-content h3 {
        font-size: 10px;
    }

    .modal-content p {
        font-size: 8px;
    }

    #help-btn {
        width: 32px;
        height: 32px;
        font-size: 16px;
    }
}
