body {
    margin: 0;
    padding: 0;
    background-color: #001a33;
    /* Vignette radial gradient + Blueprint grid lines */
    background-image: 
        radial-gradient(circle at center, rgba(0, 102, 204, 0.4) 0%, rgba(0, 26, 51, 1) 100%),
        linear-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px);
    background-size: 100% 100%, 20px 20px, 20px 20px;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: 'Courier New', Courier, monospace;
    color: white;
    overflow: hidden; /* Prevents scrollbars on mobile */
    touch-action: none; /* Prevents pull-to-refresh on mobile */
}

/* Master Scaling Container */
#game-container {
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    /* Removed the transform scale so your modal background covers the whole screen properly */
}

/* Page Toggling */
.page { display: none; width: 100%; height: 100%; flex-direction: column; justify-content: center; align-items: center; }
.page.active { display: flex; }

/* Home Page Typography & Buttons */
#home-page h1 { 
    font-size: clamp(2.5rem, 8vw, 4rem); /* Smoothly resizes the title */
    margin: 0; 
    letter-spacing: 5px; 
    color: #ffffff; 
    text-align: center;
}
.subtitle { font-size: clamp(1rem, 3vw, 1.2rem); margin-bottom: 40px; color: #aaddff; }

button {
    background-color: #ffffff;
    color: #003366;
    border: 2px solid #ffffff;
    padding: clamp(10px, 3vw, 15px) clamp(20px, 6vw, 40px); /* Resizes the button padding */
    font-size: clamp(1.2rem, 4vw, 1.5rem); /* Resizes the button text */
    font-family: 'Courier New', Courier, monospace;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    border-radius: 5px;
}
button:active { transform: scale(0.95); background-color: #aaddff; }


/* Gameplay Layout (Mobile & Tablet Grid) */
#game-ui {
    display: grid;
    grid-template-columns: 1fr 1fr; /* Creates two columns for the top boxes */
    gap: 15px;
    justify-items: center;
}

/* Put Score on Top Left */
.side-panel:first-child { grid-column: 1 / 2; grid-row: 1 / 2; }

/* Put Best Score on Top Right */
.side-panel:last-child { grid-column: 2 / 3; grid-row: 1 / 2; }

#tetris-canvas {
    background-color: rgba(0, 20, 40, 0.8);
    border: 2px solid #ffffff;
    height: 75vh; 
    max-height: 600px;
    width: auto;
    image-rendering: pixelated;
    grid-column: 1 / 3; /* Forces canvas to sit across the bottom */
    grid-row: 2 / 3;
}

.side-panel { display: flex; flex-direction: column; gap: 20px; }
.panel-box { border: 2px solid rgba(255, 255, 255, 0.5); padding: clamp(5px, 2vw, 10px); text-align: center; min-width: clamp(60px, 15vw, 80px);}
.panel-box h3 { margin: 0 0 10px 0; font-size: clamp(0.8rem, 2vw, 1rem); color: #aaddff;}
.panel-box p { margin: 0; font-size: clamp(1.2rem, 3vw, 1.5rem); font-weight: bold;}



/* Custom Modal (No alerts) */
/* Custom Modal */
.modal {
    position: fixed; /* FIX: Changed from absolute to fixed to cover the WHOLE screen */
    top: 0; 
    left: 0; 
    width: 100vw; 
    height: 100vh;
    background: rgba(0, 15, 30, 0.9);
    display: flex; 
    justify-content: center; 
    align-items: center;
    z-index: 9999; /* FIX: Made z-index massive so it sits above the 3D canvas and buttons are clickable */
}
.modal.hidden { display: none; }
.modal-content {
    background: #003366; 
    border: 2px solid white; 
    padding: clamp(20px, 5vw, 40px); 
    text-align: center;
    width: 85%; /* Ensures the box doesn't touch the screen edges on mobile */
    max-width: 450px;
}
.modal-content h2 {
    font-size: clamp(2rem, 6vw, 3rem); /* Resizes "GAME OVER" text */
    margin-top: 0;
}
.modal-content p {
    font-size: clamp(1.2rem, 4vw, 1.5rem); /* Resizes the final score text */
}

/* Fullscreen Special Effects Canvas */
#fx-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none; 
    z-index: 999; 
    /* FIX: Added these two lines to ensure it is invisible */
    background: transparent; 
    border: none; 
}

/* Apply Desktop Layout if screen is WIDE OR if it is LANDSCAPE */
@media (min-width: 768px), (orientation: landscape) {
    #game-ui {
        display: flex;
        flex-direction: row;
        align-items: flex-start;
        justify-content: center;
        gap: 20px;
    }

    #tetris-canvas {
        height: 80vh; /* Adjusted to fit better in landscape */
        grid-column: unset;
        grid-row: unset;
    }

    .side-panel:first-child { grid-column: unset; grid-row: unset; }
    .side-panel:last-child { grid-column: unset; grid-row: unset; }
    
    #home-page h1 { font-size: 3rem; } /* Slightly smaller text for landscape mobile */
}