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

body {
    font-family: 'Inter', 'Segoe UI', 'Roboto', 'Helvetica Neue', 'Arial', sans-serif;
    background: linear-gradient(45deg, #ff6b9d, #c44569);
    height: 100vh;
    overflow: hidden;
}

#game-container {
    width: 100vw;
    height: 100vh;
    position: relative;
    background: linear-gradient(to bottom, #87CEEB, #FFB6C1);
}

#game-screen {
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
}

#game-world {
    width: 100%;
    height: 100%;
    position: relative;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

.princess {
    width: 60px;
    height: 60px;
    position: absolute;
    background-image: url('images/princess.png');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    border-radius: 50%;
    transition: transform 0.1s ease;
    z-index: 10;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}

.room {
    width: 100%;
    height: 100%;
    position: absolute;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

.item {
    width: 40px;
    height: 40px;
    position: absolute;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    border-radius: 8px;
    animation: float 2s ease-in-out infinite, glow 2s ease-in-out infinite alternate;
    cursor: pointer;
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.8), 
                0 0 30px rgba(255, 215, 0, 0.6),
                0 0 45px rgba(255, 215, 0, 0.4);
    filter: brightness(1.2) saturate(1.3);
}

.portal {
    width: 50px;
    height: 50px;
    position: absolute;
    cursor: pointer;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    animation: arrowPulse 2s ease-in-out infinite;
}

.portal.forward {
    background-image: url('images/arrow-green-right.svg');
}

.portal.backward {
    background-image: url('images/arrow-red-left.svg');
}

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

@keyframes float {
    0%, 100% { transform: translateY(0px) scale(1); }
    50% { transform: translateY(-10px) scale(1.05); }
}

@keyframes glow {
    0% { 
        box-shadow: 0 0 15px rgba(255, 215, 0, 0.8), 
                    0 0 30px rgba(255, 215, 0, 0.6),
                    0 0 45px rgba(255, 215, 0, 0.4);
    }
    100% { 
        box-shadow: 0 0 25px rgba(255, 255, 255, 0.9), 
                    0 0 50px rgba(255, 215, 0, 0.8),
                    0 0 75px rgba(255, 215, 0, 0.6);
    }
}


#ui-overlay {
    position: fixed;
    top: max(20px, env(safe-area-inset-top, 0px));
    left: max(20px, env(safe-area-inset-left, 0px));
    z-index: 20;
    color: white;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.7);
    font-family: inherit;
}

#back-button {
    padding: 8px 16px;
    font-size: 14px;
    background-color: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 20px;
    cursor: pointer;
    font-family: inherit;
    font-weight: bold;
    margin-bottom: 10px;
    backdrop-filter: blur(5px);
    transition: background-color 0.3s ease;
}

#back-button:hover {
    background-color: rgba(255, 255, 255, 0.3);
}

#score-display, #room-display {
    background: rgba(0,0,0,0.5);
    padding: 10px 15px;
    border-radius: 10px;
    margin-bottom: 10px;
    font-size: 18px;
    font-weight: bold;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: linear-gradient(45deg, #fff, #f8f8ff);
    padding: 30px;
    border-radius: 20px;
    text-align: center;
    max-width: 90%;
    max-height: 90%;
    overflow-y: auto;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    border: 3px solid #ff6b9d;
}

.modal-content h2 {
    color: #c44569;
    margin-bottom: 20px;
    font-size: 24px;
}

.modal-content img {
    max-width: 80vw;
    max-height: 60vh;
    width: auto;
    height: auto;
    margin: 15px 0;
    border-radius: 10px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
    object-fit: contain;
}

.modal-content p {
    color: #333;
    margin: 15px 0;
    font-size: 16px;
    line-height: 1.4;
}

.modal-content ul {
    text-align: left;
    color: #333;
    margin: 15px 0;
}

.modal-content li {
    margin: 8px 0;
    padding-left: 10px;
}

.modal-content input {
    padding: 12px;
    font-size: 18px;
    border: 2px solid #ff6b9d;
    border-radius: 10px;
    margin: 15px 5px;
    min-width: 200px;
    text-align: center;
}

.modal-content button {
    background: linear-gradient(45deg, #ff6b9d, #c44569);
    color: white;
    border: none;
    padding: 12px 20px;
    font-size: 16px;
    border-radius: 10px;
    cursor: pointer;
    margin: 10px 5px;
    min-width: 120px;
    font-weight: bold;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
    transition: transform 0.2s ease;
}

.modal-content button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.4);
}

.modal-content button:active {
    transform: translateY(0);
}

#spelling-feedback {
    font-weight: bold;
    font-size: 18px;
    margin-top: 15px;
}

.correct {
    color: #28a745;
}

.incorrect {
    color: #dc3545;
}

/* Room-specific backgrounds */
.room-0 { background-image: url('images/room-throne.png'); }
.room-1 { background-image: url('images/room-library.png'); }
.room-2 { background-image: url('images/room-kitchen.png'); }
.room-3 { background-image: url('images/room-garden.png'); }
.room-4 { background-image: url('images/room-bedroom.png'); }
.room-5 { background-image: url('images/room-ballroom.png'); }
.room-6 { background-image: url('images/room-tower.png'); }
.room-7 { background-image: url('images/room-dungeon.png'); }
.room-8 { background-image: url('images/room-treasury.png'); }
.room-9 { background-image: url('images/room-observatory.png'); }

/* Item-specific backgrounds */
.item-crown { background-image: url('images/item-crown.png'); }
.item-book { background-image: url('images/item-book.png'); }
.item-cake { background-image: url('images/item-cake.png'); }
.item-flower { background-image: url('images/item-flower.png'); }
.item-pillow { background-image: url('images/item-pillow.png'); }
.item-mask { background-image: url('images/item-mask.png'); }
.item-telescope { background-image: url('images/item-telescope.png'); }
.item-key { background-image: url('images/item-key.png'); }
.item-jewel { background-image: url('images/item-jewel.png'); }
.item-star { background-image: url('images/item-star.png'); }

/* Mobile optimizations */
@media (max-width: 768px) {
    .princess {
        width: 50px;
        height: 50px;
    }
    
    .item {
        width: 35px;
        height: 35px;
    }
    
    .door {
        width: 40px;
        height: 65px;
    }
    
    #ui-overlay {
        top: max(10px, env(safe-area-inset-top, 0px));
        left: max(10px, env(safe-area-inset-left, 0px));
    }
    
    #score-display, #room-display {
        font-size: 14px;
        padding: 8px 12px;
        font-family: inherit;
        white-space: nowrap;
        overflow: visible;
    }
    
    .modal-content {
        padding: 20px;
        margin: 20px;
    }
    
    .modal-content h2 {
        font-size: 20px;
    }
    
    .modal-content input {
        min-width: 150px;
        font-size: 16px;
    }
    
    .modal-content button {
        min-width: 100px;
        font-size: 14px;
    }
}

/* Firefox-specific font fixes */
@-moz-document url-prefix() {
    body, #ui-overlay, #score-display, #room-display {
        font-family: 'Inter', 'Segoe UI', 'Roboto', 'Helvetica Neue', 'Arial', sans-serif !important;
    }
}

/* Additional mobile browser compatibility */
@media screen and (max-width: 768px) {
    /* Ensure visibility on mobile browsers with dynamic viewports */
    #ui-overlay {
        position: fixed;
        top: max(env(safe-area-inset-top, 10px), 10px);
        left: max(env(safe-area-inset-left, 10px), 10px);
        transform: translateZ(0); /* Force hardware acceleration */
        will-change: transform;
    }
    
    /* Firefox Android specific fixes */
    @supports (-moz-appearance: none) {
        #ui-overlay {
            top: max(env(safe-area-inset-top, 15px), 15px);
            left: max(env(safe-area-inset-left, 15px), 15px);
        }
        
        #score-display, #room-display {
            backdrop-filter: blur(5px);
            -webkit-backdrop-filter: blur(5px);
        }
    }
}