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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    color: #fff;
    overflow-x: hidden;
    min-height: 100vh;
    touch-action: manipulation;
}

select {
    background: #333;
    color: #4ade80;
    border: 2px solid #4ade80;
    padding: 10px 20px;
    font-family: 'Courier New', monospace;
    font-size: 1rem;
    cursor: pointer;
    border-radius: 5px;
}

/* Game Container - Vertical Stack Layout */
#game-container {
    width: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 10px;
    gap: 5px;
    max-width: 1200px;
    margin: 0 auto;
}

/* Mobile: Remove space between HUD and canvas */
@media (max-width: 768px) {
    #game-container {
        gap: 0;
        padding: 5px;
    }

    #hud {
        margin-bottom: 0;
    }

    #canvas-container {
        padding: 5px 0;
    }

    #gameCanvas {
        border-radius: 8px;
    }
}

/* HUD */
#hud {
    background: rgba(0, 0, 0, 0.6);
    border-radius: 12px;
    padding: 12px 20px;
    border: 2px solid rgba(255, 215, 0, 0.4);
    flex-shrink: 0;
    width: 100%;
}

.hud-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
    width: 100%;
}

/* Desktop: Show all HUD elements in single line */
@media (min-width: 769px) {
    .hud-row {
        display: flex;
        justify-content: space-around;
        align-items: center;
        gap: 20px;
        width: 100%;
    }

    #hud {
        display: flex;
    }
}

#score-display, #high-score-display, #level-display {
    background: rgba(0, 0, 0, 0.6);
    padding: 8px 16px;
    border-radius: 20px;
    border: 1px solid rgba(0, 255, 136, 0.5);
    font-size: 1rem;
}

#pause-btn {
    pointer-events: auto;
    background: rgba(0, 0, 0, 0.8);
    border: 2px solid #ffd700;
    border-radius: 8px;
    padding: 10px 20px;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.3s;
    color: #ffd700;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 5px;
}

#pause-btn:hover {
    background: rgba(0, 255, 136, 0.3);
    border-color: #00ff88;
}

/* Canvas Container */
#canvas-container {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    touch-action: none;
    min-height: 0;
}

#gameCanvas {
    background: rgba(0, 0, 0, 0.5);
    border-radius: 12px;
    box-shadow: 0 0 30px rgba(0, 255, 100, 0.3);
    touch-action: none;
    display: block;
    margin: auto;
    max-width: 100%;
    max-height: 100%;
}

/* Power-up Notifications */
.powerup-notifications {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
    width: 100%;
    padding: 10px;
    flex-shrink: 0;
}

.powerup-notification {
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 12px 20px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.6);
    animation: slideDown 0.3s ease, fadeOut 0.6s ease 2.5s forwards;
    pointer-events: auto;
    max-width: 90%;
    border: 1px solid;
}

.powerup-notification.speed {
    border-color: rgba(0, 212, 255, 0.5);
    box-shadow: 0 4px 15px rgba(0, 212, 255, 0.2);
}

.powerup-notification.invincible {
    border-color: rgba(255, 0, 255, 0.5);
    box-shadow: 0 4px 15px rgba(255, 0, 255, 0.2);
}

.powerup-icon {
    font-size: 1.5rem;
}

.powerup-content {
    text-align: left;
    flex: 1;
}

.powerup-content h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: bold;
    margin-bottom: 2px;
    color: #fff;
}

.powerup-content p {
    margin: 0;
    font-size: 0.8rem;
    opacity: 0.9;
    color: #ccc;
}

.speed .powerup-content h3 {
    color: #00d4ff;
}

.invincible .powerup-content h3 {
    color: #ff00ff;
}

/* Mobile Controls */
#mobile-controls {
    display: grid;
    grid-template-columns: repeat(3, 60px);
    grid-template-rows: repeat(2, 60px);
    gap: 10px;
    padding: 5px 0;
    flex-shrink: 0;
    justify-content: center;
}

/* Hide mobile controls on bigger screens */
@media (min-width: 769px) {
    #mobile-controls {
        display: none;
    }
}

#mobile-controls .control-btn {
    background: rgba(0, 255, 136, 0.2);
    border: 2px solid rgba(0, 255, 136, 0.5);
    border-radius: 12px;
    color: #00ff88;
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.2s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    display: flex;
    justify-content: center;
    align-items: center;
}

#mobile-controls .control-btn:hover {
    background: rgba(0, 255, 136, 0.4);
    transform: scale(1.1);
}

#mobile-controls .control-btn:active {
    transform: scale(0.95);
}

#mobile-controls .up {
    grid-column: 2;
    grid-row: 1;
}

#mobile-controls .left {
    grid-column: 1;
    grid-row: 2;
}

#mobile-controls .down {
    grid-column: 2;
    grid-row: 2;
}

#mobile-controls .right {
    grid-column: 3;
    grid-row: 2;
}

/* UI Overlays */
.menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 100;
    animation: fadeIn 0.3s ease;
    padding: 20px;
}

.hidden {
    display: none !important;
}

.menu-content {
    text-align: center;
    width: 100%;
    max-width: 600px;
    padding: 2rem;
    animation: slideUp 0.3s ease;
}

/* Game Title */
.game-title {
    font-size: 3rem;
    font-weight: bold;
    margin-bottom: 0.5rem;
    background: linear-gradient(45deg, #00ff88, #00d4ff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 0 30px rgba(0, 255, 136, 0.5);
}

.game-subtitle {
    font-size: 1.2rem;
    color: #888;
    margin-bottom: 2rem;
}

/* Game Over Screen */
#game-over {
    z-index: 150;
}

#game-over .menu-content {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border: 2px solid #ffd700;
    box-shadow: 0 0 30px rgba(255, 215, 0, 0.3);
    border-radius: 16px;
}

#game-over .primary-btn {
    margin-top: 1rem;
    font-size: 1.1rem;
    background: linear-gradient(45deg, #ffd700, #ff8c00);
    box-shadow: 0 5px 15px rgba(255, 215, 0, 0.4);
}

#game-over .primary-btn:hover {
    box-shadow: 0 8px 25px rgba(255, 215, 0, 0.6);
}

#game-over .secondary-btn {
    margin: 5px;
    font-size: 1rem;
    padding: 12px 30px;
}

/* Pause Menu */
#pause-menu {
    z-index: 150;
}

#pause-menu .menu-content {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border: 2px solid #ffd700;
    box-shadow: 0 0 30px rgba(255, 215, 0, 0.3);
    border-radius: 16px;
}

#pause-menu h2 {
    font-size: 3rem;
    margin-bottom: 0.5rem;
    background: linear-gradient(45deg, #ffd700, #ff8c00);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

#pause-menu .game-subtitle {
    margin-bottom: 2rem;
    color: #fff;
}

#pause-menu .primary-btn {
    margin-top: 1rem;
    font-size: 1.1rem;
    background: linear-gradient(45deg, #ffd700, #ff8c00);
    box-shadow: 0 5px 15px rgba(255, 215, 0, 0.4);
}

#pause-menu .primary-btn:hover {
    box-shadow: 0 8px 25px rgba(255, 215, 0, 0.6);
}

#pause-menu .secondary-btn {
    margin: 5px;
    font-size: 1rem;
    padding: 12px 30px;
}

/* Menu Footer */
.menu-footer {
    margin-top: 1.5rem;
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

.primary-btn, .secondary-btn {
    background: linear-gradient(45deg, #00ff88, #00d4ff);
    color: #1a1a2e;
    border: none;
    padding: 15px 40px;
    font-size: 1.3rem;
    font-weight: bold;
    border-radius: 30px;
    cursor: pointer;
    transition: all 0.3s;
    margin: 10px;
    text-transform: uppercase;
    letter-spacing: 2px;
    box-shadow: 0 5px 20px rgba(0, 255, 136, 0.4);
}

.primary-btn:hover, .secondary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(0, 255, 136, 0.6);
}

.secondary-btn {
    background: transparent;
    border: 2px solid #00ff88;
    color: #00ff88;
}

.secondary-btn:hover {
    background: rgba(0, 255, 136, 0.1);
}

/* Speed Selection */
.speed-selection {
    margin: 2rem 0;
}

.speed-selection h3 {
    margin-bottom: 1rem;
    color: #00ff88;
}

/* Final Score */
.final-score {
    margin: 2rem 0;
}

.final-score p {
    font-size: 1.3rem;
    margin: 10px 0;
}

.final-score span {
    color: #00ff88;
    font-weight: bold;
    font-size: 1.5rem;
}

/* High Score Announcement */
.high-score-announcement {
    background: linear-gradient(45deg, #ffd700, #ff8c00);
    color: #1a1a2e;
    padding: 15px;
    border-radius: 10px;
    margin: 1rem 0;
    font-weight: bold;
    font-size: 1.3rem;
    animation: pulse 1s infinite;
}

/* Sound Toggle */
.sound-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 1rem;
    cursor: pointer;
    font-size: 1rem;
}

.sound-toggle input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
}

.sound-toggle input[type="checkbox"]:checked + span {
    color: #00ff88;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        transform: translateY(50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

@keyframes slideDown {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    .game-title {
        font-size: 3rem;
    }

    .game-subtitle {
        font-size: 1rem;
    }

    .primary-btn, .secondary-btn {
        padding: 12px 30px;
        font-size: 1.1rem;
    }

    .hud-left, .hud-right {
        font-size: 1rem;
    }

    /* Game Container Flex Layout for Mobile */
    #game-container {
        flex-direction: column;
        align-items: center;
        padding-bottom: 0;
        height: 100%;
    }

    #hud {
        padding: 6px 12px;
        font-size: 0.8rem;
    }

    /* Canvas scales to fit */
    #gameCanvas {
        max-width: 95%;
        max-height: calc(100% - 250px);
        width: auto;
        height: auto;
    }

    /* Mobile Controls */
    #mobile-controls {
        display: grid;
    }

    #pause-btn {
        display: flex;
    }
}

@media (max-width: 480px) {
    .game-title {
        font-size: 2.5rem;
    }

    .menu-content {
        padding: 1.5rem;
    }

    #mobile-controls {
        grid-template-columns: repeat(3, 50px);
        grid-template-rows: repeat(2, 50px);
    }
}

/* Mobile - Compact HUD with 2 lines, left/right alignment */
@media (max-width: 768px) {
    #hud {
        padding: 8px 12px;
        border-radius: 8px;
        flex-direction: column;
        gap: 8px;
        width: 100%;
    }

    .hud-row {
        width: 100%;
        justify-content: space-between;
        flex-direction: row;
    }

    .hud-row:first-child {
        margin-bottom: 4px;
    }

    #score-display, #high-score-display, #level-display {
        font-size: 0.75rem;
        padding: 3px 8px;
    }

    #pause-btn {
        font-size: 0.75rem;
        padding: 4px 10px;
        display: inline-flex;
    }
}