/**
 * Boulder Dash - Klas Persson Edition CSS
 */

#boulder-dash-game-container {
    position: relative;
    background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
    border: 3px solid #444;
    box-shadow: 
        0 0 20px rgba(0, 255, 0, 0.3),
        inset 0 0 20px rgba(0, 0, 0, 0.5);
}

#boulder-dash-canvas {
    border: 2px solid #666;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.8);
}

/* Pratbubbla för Ubbe */
.speech-bubble {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.9);
    color: #fff;
    padding: 15px 20px;
    border-radius: 20px;
    border: 3px solid #fff;
    font-family: 'Arial', sans-serif;
    font-size: 18px;
    font-weight: bold;
    text-align: center;
    z-index: 1000;
    animation: speechPop 0.3s ease-out;
    max-width: 300px;
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
}

.speech-bubble::after {
    content: '';
    position: absolute;
    bottom: -15px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 15px solid transparent;
    border-right: 15px solid transparent;
    border-top: 15px solid #fff;
}

.speech-bubble::before {
    content: '';
    position: absolute;
    bottom: -12px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 12px solid transparent;
    border-right: 12px solid transparent;
    border-top: 12px solid rgba(0, 0, 0, 0.9);
}

.speech-bubble.hidden {
    display: none;
}

@keyframes speechPop {
    0% {
        transform: translate(-50%, -50%) scale(0.5);
        opacity: 0;
    }
    50% {
        transform: translate(-50%, -50%) scale(1.1);
    }
    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
}

/* Game UI förbättringar */
#game-ui {
    background: linear-gradient(90deg, #333 0%, #444 50%, #333 100%);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 10px;
}

#game-ui .lives,
#game-ui .score,
#game-ui .level,
#game-ui .diamonds {
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
}

/* Knappar */
button {
    transition: all 0.2s ease;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

button:active {
    transform: translateY(0);
}

/* Modaler */
#rules-modal,
#highscore-modal {
    backdrop-filter: blur(5px);
}

#rules-modal .bg-black,
#highscore-modal .bg-black {
    background: linear-gradient(135deg, #000 0%, #1a1a1a 100%);
    box-shadow: 
        0 0 50px rgba(255, 255, 255, 0.2),
        inset 0 0 20px rgba(255, 255, 255, 0.1);
}

/* Highscore tabell */
.boulder-dash-highscore table {
    background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
    border-radius: 8px;
    overflow: hidden;
}

.boulder-dash-highscore th {
    background: linear-gradient(90deg, #333 0%, #444 50%, #333 100%);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
}

.boulder-dash-highscore tr:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Responsiv design */
@media (max-width: 768px) {
    #boulder-dash-game-container {
        padding: 10px;
        margin: 10px;
    }
    
    #boulder-dash-canvas {
        max-width: 100%;
        height: auto;
    }
    
    .speech-bubble {
        font-size: 16px;
        padding: 12px 16px;
        max-width: 250px;
    }
    
    #game-ui {
        flex-direction: column;
        gap: 5px;
        text-align: center;
    }
    
    #game-ui .flex {
        flex-wrap: wrap;
        justify-content: center;
        gap: 15px;
    }
}

/* Animationer för spelelement */
@keyframes diamondSparkle {
    0%, 100% { transform: scale(1) rotate(0deg); }
    50% { transform: scale(1.1) rotate(180deg); }
}

@keyframes boulderShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-2px); }
    75% { transform: translateX(2px); }
}

@keyframes explosionFlash {
    0% { background: rgba(255, 0, 0, 0); }
    50% { background: rgba(255, 0, 0, 0.8); }
    100% { background: rgba(255, 0, 0, 0); }
}

/* Retro CRT-effekt (optional) */
.retro-crt {
    position: relative;
}

.retro-crt::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        transparent 50%,
        rgba(0, 255, 0, 0.03) 50%
    );
    background-size: 100% 4px;
    pointer-events: none;
    z-index: 1;
}

/* Glöd-effekter */
.glow-green {
    box-shadow: 0 0 10px rgba(0, 255, 0, 0.5);
}

.glow-red {
    box-shadow: 0 0 10px rgba(255, 0, 0, 0.5);
}

.glow-blue {
    box-shadow: 0 0 10px rgba(0, 0, 255, 0.5);
}

.glow-yellow {
    box-shadow: 0 0 10px rgba(255, 255, 0, 0.5);
}

/* Text-effekter */
.text-shadow-lg {
    text-shadow: 
        2px 2px 4px rgba(0, 0, 0, 0.8),
        0 0 10px rgba(255, 255, 255, 0.3);
}

/* Loading animation */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.loading {
    animation: pulse 1.5s ease-in-out infinite;
}

/* Game over och level complete skärmar */
#game-over-screen,
#level-complete-screen {
    backdrop-filter: blur(10px);
}

/* Säkerställ att hidden-klassen fungerar */
#game-over-screen.hidden,
#level-complete-screen.hidden {
    display: none !important;
}

#game-over-screen h1,
#level-complete-screen h1 {
    animation: textGlow 2s ease-in-out infinite alternate;
}

@keyframes textGlow {
    from {
        text-shadow: 
            0 0 5px currentColor,
            0 0 10px currentColor,
            0 0 15px currentColor;
    }
    to {
        text-shadow: 
            0 0 10px currentColor,
            0 0 20px currentColor,
            0 0 30px currentColor;
    }
}

/* Partikel-effekter (för framtida användning) */
.particle {
    position: absolute;
    pointer-events: none;
    border-radius: 50%;
}

.particle-diamond {
    background: linear-gradient(45deg, #00ffff, #ffffff);
    animation: particleFade 1s ease-out forwards;
}

.particle-explosion {
    background: linear-gradient(45deg, #ff4500, #ffff00);
    animation: particleExplode 0.5s ease-out forwards;
}

@keyframes particleFade {
    0% {
        opacity: 1;
        transform: scale(1);
    }
    100% {
        opacity: 0;
        transform: scale(0.5) translateY(-20px);
    }
}

@keyframes particleExplode {
    0% {
        opacity: 1;
        transform: scale(0.5);
    }
    50% {
        opacity: 1;
        transform: scale(1.5);
    }
    100% {
        opacity: 0;
        transform: scale(0) rotate(180deg);
    }
}

/* Mobil-kontroller styling - dold som standard */
#mobile-controls {
    position: fixed !important;
    bottom: 5px !important; /* ALLRA LÄNGST NER */
    left: 0 !important;
    right: 0 !important;
    display: none !important; /* Dold som standard */
    justify-content: space-between !important;
    align-items: center !important;
    padding: 0 10px !important; /* Mindre padding för att komma närmare kanterna */
    z-index: 1000 !important;
    pointer-events: none !important;
    gap: 10px !important;
    max-width: 100vw !important;
    box-sizing: border-box !important;
    margin: 0 !important;
}

/* När JavaScript aktiverar mobil-kontroller */
#mobile-controls.mobile-active {
    display: flex !important;
}

#mobile-controls button {
    min-height: 60px !important;
    font-size: 16px !important;
    user-select: none !important;
    -webkit-user-select: none !important;
    -webkit-touch-callout: none !important;
    background-color: rgba(55, 65, 81, 0.8) !important;
    border: 2px solid rgba(107, 114, 128, 0.8) !important;
    color: white !important;
    border-radius: 8px !important;
    padding: 16px !important;
    font-weight: bold !important;
    touch-action: manipulation !important;
    cursor: pointer !important;
    pointer-events: auto !important;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3) !important;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8) !important;
}

#mobile-controls button:active {
    background-color: rgba(85, 85, 85, 0.9) !important;
    transform: scale(0.95) !important;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5) !important;
}

/* Riktningsknappar */
#mobile-left, #mobile-right, #mobile-up, #mobile-down {
    font-size: 24px !important;
    padding: 16px 20px !important;
    min-width: 60px !important;
}

/* Spacer mellan vänster/höger och upp/ned knappar */
.mobile-spacer {
    flex: 1 !important;
}

/* Responsiv design för mobil */
@media (max-width: 1024px) {
    #boulder-dash-game-container {
        padding: 5px !important;
        margin: 0 !important;
        min-height: 100vh !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: center !important;
    }

    #boulder-dash-canvas {
        max-width: 100vw !important;
        max-height: calc(100vh - 100px) !important; /* Plats för kontroller */
        height: auto !important;
        width: auto !important;
        object-fit: contain !important;
    }

    /* Fullskärmsläge */
    #boulder-dash-game-container:-webkit-full-screen {
        background: #000 !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: center !important;
        align-items: center !important;
        height: 100vh !important;
        width: 100vw !important;
        padding: 20px !important;
        box-sizing: border-box !important;
    }

    #boulder-dash-game-container:-moz-full-screen {
        background: #000 !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: center !important;
        align-items: center !important;
        height: 100vh !important;
        width: 100vw !important;
        padding: 20px !important;
        box-sizing: border-box !important;
    }

    #boulder-dash-game-container:fullscreen {
        background: #000 !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: center !important;
        align-items: center !important;
        height: 100vh !important;
        width: 100vw !important;
        padding: 20px !important;
        box-sizing: border-box !important;
    }

    /* Canvas i fullskärmsläge */
    #boulder-dash-game-container:fullscreen #boulder-dash-canvas,
    #boulder-dash-game-container:-webkit-full-screen #boulder-dash-canvas,
    #boulder-dash-game-container:-moz-full-screen #boulder-dash-canvas {
        max-width: 90vw !important;
        max-height: 70vh !important;
        width: auto !important;
        height: auto !important;
        object-fit: contain !important;
        border: 2px solid #666 !important;
    }

    /* UI-element i fullskärmsläge */
    #boulder-dash-game-container:fullscreen #game-ui,
    #boulder-dash-game-container:-webkit-full-screen #game-ui,
    #boulder-dash-game-container:-moz-full-screen #game-ui {
        margin-bottom: 20px !important;
        font-size: 18px !important;
    }

    /* Mobilkontroller i fullskärmsläge */
    #boulder-dash-game-container:fullscreen #mobile-controls,
    #boulder-dash-game-container:-webkit-full-screen #mobile-controls,
    #boulder-dash-game-container:-moz-full-screen #mobile-controls {
        margin-top: 20px !important;
        position: relative !important;
        bottom: auto !important;
    }

    /* iOS Safari specifika anpassningar */
    @supports (-webkit-touch-callout: none) {
        /* iOS Safari */
        #boulder-dash-game-container {
            /* Förhindra zoom och scroll */
            touch-action: manipulation;
            -webkit-user-select: none;
            user-select: none;
        }

        /* Dölj adressfältet på iOS */
        body {
            height: 100vh;
            height: -webkit-fill-available;
        }

        /* Förbättra fullskärms-fallback för iOS */
        .ios-fullscreen-fallback {
            position: fixed !important;
            top: 0 !important;
            left: 0 !important;
            width: 100vw !important;
            height: 100vh !important;
            height: -webkit-fill-available !important;
            z-index: 9999 !important;
            background: #000 !important;
            display: flex !important;
            flex-direction: column !important;
            justify-content: center !important;
            align-items: center !important;
            padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left) !important;
        }
    }

    .speech-bubble {
        font-size: 14px !important;
        padding: 10px 15px !important;
        max-width: 200px !important;
    }

    #game-ui {
        flex-direction: column !important;
        gap: 5px !important;
        text-align: center !important;
        font-size: 14px !important;
    }

    #game-ui .flex {
        flex-wrap: wrap !important;
        justify-content: center !important;
        gap: 10px !important;
    }

    /* Dölj tangentbordsinstruktioner på mobil */
    .controls-info {
        display: none !important;
    }

    /* Justera knappar för mobil */
    .mt-8 {
        margin-top: 10px !important;
        margin-bottom: 80px !important; /* Plats för mobil-kontroller */
    }

    button {
        font-size: 14px !important;
        padding: 12px 16px !important;
        min-width: 150px !important;
    }
}

/* Extra små skärmar */
@media (max-width: 480px) {
    #mobile-controls {
        bottom: 40px !important; /* Flyttat upp 30px från 10px */
        padding: 0 10px !important;
        gap: 5px !important;
    }

    #mobile-controls button {
        min-height: 50px !important;
        font-size: 14px !important;
        padding: 12px !important;
    }

    #mobile-left, #mobile-right, #mobile-up, #mobile-down {
        font-size: 20px !important;
        padding: 12px 16px !important;
        min-width: 50px !important;
    }

    #mobile-dig {
        font-size: 16px !important;
        padding: 12px 20px !important;
    }
}
