* {
    box-sizing: border-box;
}

body, html {
    touch-action: manipulation;
}

body {
    margin: 0;
    padding: 0;
    background: linear-gradient(135deg, #e6e6fa 0%, #dda0dd 100%);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    padding: 20px;
    padding-top: 40px;
}

.container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    margin-bottom: 50px;
}

h1 {
    color: #663399;
    font-size: 64px;
    font-weight: bold;
    margin: 0;
    text-shadow: 2px 2px 4px rgba(138, 43, 226, 0.2);
    letter-spacing: 3px;
}

.instructions, #credits {
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(8px);
    border-radius: 0.3rem;
    padding: 25px 35px;
    color: #5a4a6a;
    font-size: 18px;
    line-height: 1.8;
    text-align: center;
    width: min(85vw, 85vh);
    margin: 0;
    box-shadow: 0 4px 15px rgba(138, 43, 226, 0.2);
}

canvas {
    width: min(85vw, 80vh) !important;
    height: auto !important;

    border-radius: 0.3rem;
    overflow: hidden;
    display: block;
}

#game-ui {
    padding: 1.5rem;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(8px);
    box-shadow: 0 4px 15px rgba(138, 43, 226, 0.2);

    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;

    width: min(95vw, 950px) !important;
    height: auto; 
    min-height: 80px; 
    margin-bottom: 20px; 
    border-radius: 0.3rem;

    position: sticky;
    top: 0;
}

#change-level {
    font-size: 1.2rem;
    font-weight: bold;
    color: #5a4a6a;
    background: rgba(255, 255, 255, 0.6);
    padding: 8px 16px;
    border-radius: 0.3rem;
    box-shadow: 0 2px 8px rgba(138, 43, 226, 0.1);
    border: none;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s ease;
}
#change-level:hover {
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 4px 12px rgba(138, 43, 226, 0.2);
    transform: translateY(-1px);
}
#change-level:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(138, 43, 226, 0.1);
}

#change-level-modal {
    position: absolute;
    background-color: rgba(0, 0, 0, 0.5);
    top: 100px;
    left: 0;
    width: 100%;
    height: calc(100% - 105px);

    grid-template-columns: 1fr 1fr 1fr;
    overflow-y: scroll;
}
#change-level-modal > button {
    background-color: transparent;
    color: white;
    font-size: 1.1rem;
    border: none;
    cursor: pointer;
}
#change-level-modal > button:hover {
    background-color: rgba(255, 255, 255, 0.4);
}
#change-level-modal button:disabled {
    color: white;                            
    cursor: not-allowed; 
    transform: none !important;  
    opacity: 0.6;
}
#change-level-modal button:disabled:hover {
    transform: none;               
}

#game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;

    margin-bottom: 1.5rem;

    width: 100%; 
    max-width: 1000px;
}

#mobile-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;

    margin-bottom: 1.5rem;
}

#mobile-controls button {
    border-radius: 8px;
    border: 2px solid #663399;
    background: rgba(255, 255, 255, 0.9);
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;

    width: auto;
    min-width: 20vw;
    height: 20vw;
    padding: 0 10px;
    font-size: 18px;
    overflow: hidden;
    white-space: normal;
    word-wrap: break-word;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
#mobile-controls button:hover {
    background: rgba(102, 51, 153, 0.2);
    transform: scale(1.05);
}
#mobile-controls button:active {
    background: rgba(102, 51, 153, 0.4);
    transform: scale(0.95);
}

#mobile-controls .button-row {
    display: flex;
    gap: 10px;
}

#game-stats {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 20px;
}

.stat-item {
    font-size: 1.2rem;
    font-weight: bold;
    color: #5a4a6a;
    background: rgba(255, 255, 255, 0.6);
    padding: 8px 16px;
    border-radius: 0.3rem;
    box-shadow: 0 2px 8px rgba(138, 43, 226, 0.1);
}

.world-header {
    grid-column: 1 / -1;
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
    font-weight: bold;
    font-size: 1.2rem;
    padding: 7px 15px;
    display: flex;
    align-items: center;
}

.instructions, #credits {
    width: min(95vw, 950px); 
    margin: 0 auto; 
}

@media screen and (max-width: 800px) {
    #change-level {
        font-size: 1rem;
        padding: 8px 10px;
    }
    #game-stats {
        gap: 8px;
    }
    .stat-item {
        font-size: 1rem;
    }
}

@media screen and (max-width: 650px) {
    #game-stats {
        gap: 8px;
        align-items: end;
        flex-direction: column;
    }
    #game-ui {
        height: fit-content;
        padding: 0.8rem;
    }
}

@media screen and (max-width: 480px) {
    h1 {
    font-size: 48px;
    }

    .instructions {
    font-size: 16px;
    padding: 20px 25px;
    }

    main {
    width: 95%;
    }
}