@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700;900&display=swap');

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

body {
    background: radial-gradient(ellipse at center, #1a0033 0%, #000011 70%, #000000 100%);
    min-height: 100vh;
    font-family: 'Orbitron', 'Courier New', monospace;
    color: #00ffff;
    overflow: auto;
    position: relative;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(circle at 20% 80%, rgba(120, 119, 198, 0.3) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(255, 119, 198, 0.3) 0%, transparent 50%),
        radial-gradient(circle at 40% 40%, rgba(120, 255, 198, 0.2) 0%, transparent 50%);
    z-index: -1;
    pointer-events: none;
}

.scene {
    display: none;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
    width: 100%;
    position: relative;
    z-index: 10;
}

.scene.active {
    display: flex;
}

.scene-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    max-width: 90vw;
    width: 100%;
}

/* Click to Start */
.click-to-start {
    margin-top: 50px;
    font-size: clamp(1rem, 3vw, 1.5rem);
    font-weight: 700;
    color: #00ffff;
    text-shadow: 
        0 0 5px #00ffff,
        0 0 10px #00ffff,
        0 0 20px #00ffff;
    animation: blink 1.5s infinite;
    cursor: pointer;
}

@keyframes blink {
    0%, 49% { opacity: 1; }
    50%, 99% { opacity: 0.3; }
    100% { opacity: 1; }
}

/* Intro scene clickable */
#introScene {
    cursor: pointer;
}

/* Animated Background Shapes - TETROMINI */
.bg-shapes {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
    overflow: hidden;
}

.bg-tetromino {
    position: absolute;
    opacity: 0;
    animation: floatShape 20s infinite ease-in-out;
}

.tetromino-grid {
    display: grid;
    gap: 2px;
}

.tetromino-block {
    width: var(--block-size, 40px);
    height: var(--block-size, 40px);
    border: 2px solid;
    border-radius: 3px;
    background: transparent;
}

@keyframes floatShape {
    0% {
        opacity: 0;
        transform: translateY(100vh) rotate(0deg) scale(0.5);
    }
    10% {
        opacity: 0.3;
    }
    50% {
        opacity: 0.5;
        transform: translateY(50vh) rotate(180deg) scale(1);
    }
    90% {
        opacity: 0.3;
    }
    100% {
        opacity: 0;
        transform: translateY(-100vh) rotate(360deg) scale(0.5);
    }
}

@keyframes floatShapeReverse {
    0% {
        opacity: 0;
        transform: translateY(-100vh) rotate(0deg) scale(0.5);
    }
    10% {
        opacity: 0.3;
    }
    50% {
        opacity: 0.5;
        transform: translateY(50vh) rotate(-180deg) scale(1);
    }
    90% {
        opacity: 0.3;
    }
    100% {
        opacity: 0;
        transform: translateY(100vh) rotate(-360deg) scale(0.5);
    }
}

@keyframes rotateShape {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) rotate(0deg) scale(0.3);
    }
    25% {
        opacity: 0.4;
    }
    50% {
        opacity: 0.6;
        transform: translate(-50%, -50%) rotate(180deg) scale(1.2);
    }
    75% {
        opacity: 0.4;
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) rotate(360deg) scale(0.3);
    }
}

.audio-controls {
    position: fixed;
    top: 20px;
    right: 20px;
    display: flex;
    gap: 10px;
    z-index: 1000;
}

.audio-button {
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid #00ffff;
    color: #00ffff;
    padding: 10px 15px;
    font-size: 20px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 0 15px rgba(0, 255, 255, 0.5);
    font-family: 'Orbitron', monospace;
}

.audio-button:hover {
    background: rgba(0, 255, 255, 0.2);
    box-shadow: 0 0 25px rgba(0, 255, 255, 0.8);
    transform: scale(1.1);
}

.audio-button:active {
    transform: scale(0.95);
}

.neon-title {
    font-size: clamp(2rem, 8vw, 3rem);
    font-weight: 900;
    text-align: center;
    margin-bottom: 2rem;
    letter-spacing: 0.1em;
    text-shadow: 
        0 0 5px #ff00ff,
        0 0 10px #ff00ff,
        0 0 20px #ff00ff,
        0 0 40px #ff00ff;
    animation: titlePulse 2s infinite alternate;
}

.game-content-wrapper {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 20;
    padding: 20px;
    transform-origin: center center;
}

.game-title {
    font-size: 2.5rem;
    font-weight: 900;
    letter-spacing: 0.1em;
    z-index: 100;
    white-space: nowrap;
    margin-bottom: 20px;
}

.game-title .glow {
    color: #ff00ff;
    text-shadow: 
        0 0 5px #ff00ff,
        0 0 10px #ff00ff,
        0 0 20px #ff00ff,
        0 0 40px #ff00ff;
}

.game-title .blocks {
    color: #00ffff;
    text-shadow: 
        0 0 5px #00ffff,
        0 0 10px #00ffff,
        0 0 20px #00ffff,
        0 0 40px #00ffff;
}

@keyframes titlePulse {
    0% { text-shadow: 0 0 5px #ff00ff, 0 0 10px #ff00ff, 0 0 20px #ff00ff, 0 0 40px #ff00ff; }
    100% { text-shadow: 0 0 10px #ff00ff, 0 0 20px #ff00ff, 0 0 30px #ff00ff, 0 0 60px #ff00ff; }
}

.neon-button {
    background: transparent;
    border: 2px solid #00ffff;
    color: #00ffff;
    padding: clamp(10px, 2vw, 15px) clamp(20px, 4vw, 30px);
    font-size: clamp(1rem, 2.5vw, 1.2rem);
    font-family: 'Orbitron', 'Courier New', monospace;
    font-weight: 700;
    cursor: pointer;
    margin: 10px;
    border-radius: 10px;
    transition: all 0.3s;
    text-shadow: 0 0 5px #00ffff;
    box-shadow: 
        0 0 5px #00ffff,
        inset 0 0 5px rgba(0, 255, 255, 0.1);
    white-space: nowrap;
}

.neon-button:hover {
    background: rgba(0, 255, 255, 0.1);
    box-shadow: 
        0 0 15px #00ffff,
        inset 0 0 15px rgba(0, 255, 255, 0.2);
    text-shadow: 0 0 10px #00ffff;
}

.game-wrapper {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    z-index: 20;
}

.game-container {
    display: flex;
    align-items: flex-start;
    gap: 20px;
    max-width: 100%;
    transform-origin: center center;
}

.game-board {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

#gameCanvas {
    border: 3px solid #00ffff;
    border-radius: 10px;
    box-shadow: 
        0 0 20px #00ffff,
        inset 0 0 20px rgba(0, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.8);
    display: block;
    max-width: 100%;
    height: auto;
}

.hud {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 150px;
    flex-shrink: 0;
    max-height: 600px;
}

.hud-item {
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid #00ffff;
    border-radius: 15px;
    padding: 10px;
    text-align: center;
    box-shadow: 
        0 0 15px rgba(0, 255, 255, 0.5),
        inset 0 0 15px rgba(0, 255, 255, 0.1);
    flex-shrink: 0;
}

.next-box {
    padding: 8px;
}

#nextCanvas {
    display: block;
    margin: 6px auto 0;
    background: rgba(10, 10, 31, 0.8);
    border-radius: 8px;
    width: 90px;
    height: 90px;
}

.hud-label {
    font-size: clamp(0.9rem, 2vw, 1.1rem);
    font-weight: 700;
    margin-bottom: 8px;
    text-shadow: 0 0 5px #00ffff;
}

.hud-value {
    font-size: clamp(1.3rem, 3vw, 1.8rem);
    font-weight: 900;
    text-shadow: 0 0 10px #ff00ff;
    color: #ff00ff;
}

/* Shake animation for line clears */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

.shake {
    animation: shake 0.4s ease-in-out;
}

/* Light shake for hard drop */
@keyframes shakeLight {
    0%, 100% { transform: translateX(0); }
    25%, 75% { transform: translateX(-3px); }
    50% { transform: translateX(3px); }
}

.shake-light {
    animation: shakeLight 0.2s ease-in-out;
}

.mapi-games {
    color: #00ff00;
    font-size: 1.5rem;
    font-weight: 900;
    letter-spacing: 0.2em;
    text-shadow: 
        0 0 5px #00ff00,
        0 0 10px #00ff00,
        0 0 20px #00ff00;
    text-align: center;
    width: 100%;
    margin-top: 30px;
}

.game-over-score {
    font-size: clamp(1.5rem, 4vw, 2rem);
    font-weight: 900;
    margin: 20px 0;
    text-shadow: 0 0 10px #ff00ff;
    color: #ff00ff;
}

.controls-info {
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid #00ffff;
    border-radius: 15px;
    padding: 20px;
    margin: 20px;
    text-align: center;
    max-width: 90vw;
}

.controls-info h3 {
    margin-bottom: 15px;
    color: #00ffff;
    font-size: clamp(1rem, 3vw, 1.2rem);
}

.controls-info p {
    font-size: clamp(0.9rem, 2.5vw, 1rem);
    margin: 5px 0;
}

/* Responsive scaling per schermi piccoli - MOBILE OPTIMIZED */
/* SCALING PER LARGHEZZA */
@media (max-width: 1200px) {
    .game-content-wrapper {
        transform: scale(0.95);
    }
}

@media (max-width: 1100px) {
    .game-content-wrapper {
        transform: scale(0.9);
    }
}

@media (max-width: 1000px) {
    .game-content-wrapper {
        transform: scale(0.85);
    }
}

@media (max-width: 900px) {
    .game-content-wrapper {
        transform: scale(0.8);
    }
}

@media (max-width: 768px) {
    .game-content-wrapper {
        transform: scale(1);
        padding: 10px;
    }
    
    .game-title {
        font-size: 1.8rem;
        margin-bottom: 10px;
    }
    
    .audio-controls {
        top: 5px;
        right: 5px;
        gap: 5px;
    }
    
    .audio-button {
        padding: 6px 10px;
        font-size: 16px;
    }
    
    .game-container {
        flex-direction: column;
        align-items: center;
        gap: 15px;
    }
    
    .hud {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        min-width: auto;
        gap: 8px;
        width: 100%;
        max-width: 320px;
    }
    
    .hud-item {
        flex: 1 1 calc(33.333% - 8px);
        min-width: 90px;
        padding: 8px;
    }
    
    .hud-label {
        font-size: 0.8rem;
        margin-bottom: 5px;
    }
    
    .hud-value {
        font-size: 1.3rem;
    }
    
    .next-box {
        flex: 1 1 100%;
        max-width: 120px;
        margin: 0 auto;
    }
    
    #nextCanvas {
        width: 90px;
        height: 90px;
    }
    
    #gameCanvas {
        width: 300px;
        height: 600px;
    }
}

@media (max-width: 650px) {
    .game-content-wrapper {
        transform: scale(0.95);
    }
}

@media (max-width: 600px) {
    .game-content-wrapper {
        transform: scale(0.9);
    }
    
    .game-title {
        font-size: 1.5rem;
    }
}

@media (max-width: 550px) {
    .game-content-wrapper {
        transform: scale(0.85);
    }
}

@media (max-width: 500px) {
    .game-content-wrapper {
        transform: scale(0.8);
    }
}

@media (max-width: 450px) {
    .game-content-wrapper {
        transform: scale(0.75);
    }
}

@media (max-width: 400px) {
    .game-content-wrapper {
        transform: scale(0.7);
    }
}

@media (max-width: 350px) {
    .game-content-wrapper {
        transform: scale(0.65);
    }
}

@media (max-width: 300px) {
    .game-content-wrapper {
        transform: scale(0.6);
    }
}

/* SCALING PER ALTEZZA */
@media (max-height: 900px) {
    .game-content-wrapper {
        transform: scale(0.9);
    }
}

@media (max-height: 850px) {
    .game-content-wrapper {
        transform: scale(0.85);
    }
}

@media (max-height: 800px) {
    .game-content-wrapper {
        transform: scale(0.8);
    }
    
    .game-title {
        font-size: 1.8rem;
        margin-bottom: 8px;
    }
}

@media (max-height: 750px) {
    .game-content-wrapper {
        transform: scale(0.75);
    }
}

@media (max-height: 700px) {
    .game-content-wrapper {
        transform: scale(0.7);
    }
}

@media (max-height: 650px) {
    .game-content-wrapper {
        transform: scale(0.65);
    }
}

@media (max-height: 600px) {
    .game-content-wrapper {
        transform: scale(0.6);
    }
}

@media (max-height: 550px) {
    .game-content-wrapper {
        transform: scale(0.55);
    }
}

@media (max-height: 500px) {
    .game-content-wrapper {
        transform: scale(0.5);
    }
}

@media (max-height: 450px) {
    .game-content-wrapper {
        transform: scale(0.45);
    }
}

@media (max-height: 400px) {
    .game-content-wrapper {
        transform: scale(0.4);
    }
}

/* LANDSCAPE MODE - Prioritize game area */
@media (max-height: 500px) and (orientation: landscape) {
    .game-content-wrapper {
        transform: scale(0.7);
        padding: 5px;
    }
    
    .game-title {
        font-size: 1.2rem;
        margin-bottom: 5px;
    }
    
    .game-container {
        flex-direction: row;
        gap: 10px;
    }
    
    .hud {
        flex-direction: column;
        max-width: 120px;
        gap: 5px;
    }
    
    .hud-item {
        padding: 5px;
        min-width: 100px;
    }
    
    .hud-label {
        font-size: 0.7rem;
    }
    
    .hud-value {
        font-size: 1.1rem;
    }
    
    .next-box {
        max-width: 100px;
    }
    
    #nextCanvas {
        width: 70px;
        height: 70px;
    }
    
    .mapi-games {
        font-size: 0.8rem;
        margin-top: 10px;
    }
}

@media (max-height: 400px) and (orientation: landscape) {
    .game-content-wrapper {
        transform: scale(0.6);
    }
}

@media (max-height: 350px) and (orientation: landscape) {
    .game-content-wrapper {
        transform: scale(0.5);
    }
}
