/* style.css */
@font-face {
  font-family: 'Orbitron';
  src: url('fonts/Orbitron-Regular.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
}

:root {
    --glow-cyan: rgba(0, 255, 255, 0.8);
    --glow-magenta: rgba(255, 0, 255, 0.8);
    --glow-green: rgba(0, 255, 128, 0.8);
    --glass-bg: rgba(10, 10, 40, 0.5);
    --border-cyan: #00ffff;
    --border-magenta: #ff00ff;
    --danger-red: #ff3333;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #020210;
    font-family: 'Orbitron', sans-serif;
    color: #fff;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    display: flex;
    justify-content: center;
    align-items: center;
    position: fixed; /* Previene scroll su mobile */
    top: 0;
    left: 0;
}

#background-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

#game-wrapper {
    position: relative;
    z-index: 10;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.5s ease;
    pointer-events: none;
}
#game-wrapper.visible {
    opacity: 1;
    pointer-events: auto;
}

#game-hud {
    width: 100%;
    max-width: 800px;
    padding: clamp(5px, 1.5vw, 10px) clamp(10px, 3vw, 20px);
    display: flex;
    justify-content: space-around;
    flex-wrap: wrap;
    font-size: clamp(14px, 3vw, 28px); /* Font completamente responsive */
    text-transform: uppercase;
    font-weight: bold;
    gap: clamp(5px, 1vw, 10px);
}
#game-hud span {
    text-shadow: 0 0 5px var(--glow-cyan), 0 0 10px var(--glow-cyan);
    transition: transform 0.2s, text-shadow 0.2s;
    min-width: fit-content;
    text-align: center;
}
#game-hud span.flash {
    transform: scale(1.2);
    text-shadow: 0 0 10px #fff, 0 0 20px var(--glow-cyan);
}

#game-container {
    width: 100%;
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    /* Assicura che il container utilizzi tutto lo spazio disponibile */
    min-height: 0; /* Importante per il flex shrink */
}

#game-canvas {
    display: block;
    /* Il canvas mantiene sempre le proporzioni e si adatta allo spazio disponibile */
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    transition: transform 0.2s ease-out;
}
#game-canvas.shake {
    animation: screen-shake 0.15s 2;
}

@keyframes screen-shake {
    0%, 100% { transform: translate(0, 0); }
    25% { transform: translate(-3px, 2px); }
    50% { transform: translate(2px, -3px); }
    75% { transform: translate(3px, 3px); }
}

#ui-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 20;
    pointer-events: none;
    overflow: hidden;
}

@keyframes gradient-flow {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.ui-panel {
    position: relative;
    overflow: hidden;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    pointer-events: auto;
    background: rgba(2, 2, 16, 0.5);
    backdrop-filter: blur(5px);
    opacity: 0;
    transition: opacity 0.5s ease-in-out;
}
.ui-panel::before {
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(-45deg, var(--glow-cyan), var(--glow-magenta), var(--glow-green), var(--glow-cyan));
    background-size: 400% 400%;
    animation: gradient-flow 20s ease infinite;
    z-index: -1;
    opacity: 0.25;
}
.ui-panel.visible {
    opacity: 1;
}

@keyframes title-pulse {
    0%, 100% { text-shadow: 0 0 15px var(--glow-cyan), 0 0 25px var(--glow-cyan); }
    50% { text-shadow: 0 0 25px #fff, 0 0 40px var(--glow-cyan); }
}
.ui-title {
    font-size: clamp(32px, 10vw, 80px);
    font-weight: bold;
    text-align: center;
    line-height: 1.1;
    margin-bottom: 40px;
    text-shadow: 0 0 15px var(--glow-cyan);
    animation: title-pulse 4s ease-in-out infinite;
}

/* --- SPLASH SCREEN --- */
.splash-screen {
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    align-items: center;
    padding: 5vh 5vw;
    min-height: 100vh;
}
.splash-title {
    font-size: clamp(32px, 10vw, 100px);
    font-weight: bold;
    text-align: center;
    line-height: 1.1;
    text-shadow: 0 0 20px var(--glow-cyan), 0 0 30px var(--glow-cyan);
    animation: title-pulse 3s ease-in-out infinite;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 2vh 0;
}
.splash-prompt {
    font-size: clamp(18px, 5vw, 40px);
    font-weight: bold;
    text-align: center;
    letter-spacing: 4px;
    text-shadow: 0 0 10px #fff, 0 0 20px var(--glow-cyan);
    animation: prompt-blink 2s ease-in-out infinite;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 2vh 0;
}
.splash-credit {
    font-size: clamp(16px, 4vw, 32px);
    font-weight: bold;
    text-align: center;
    letter-spacing: 3px;
    color: #ff3333;
    text-shadow: 0 0 10px #ff3333, 0 0 20px #ff3333;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 2vh 0;
}
@keyframes prompt-blink {
    0%, 49%, 100% { opacity: 1; }
    50%, 99% { opacity: 0.3; }
}

/* Media query per schermi molto piccoli o stretti */
@media (max-height: 500px) {
    .splash-screen {
        padding: 2vh 5vw;
    }
    .splash-title {
        font-size: clamp(24px, 8vw, 60px);
        padding: 1vh 0;
    }
    .splash-prompt {
        font-size: clamp(14px, 4vw, 24px);
        padding: 1vh 0;
    }
    .splash-credit {
        font-size: clamp(12px, 3vw, 20px);
        padding: 1vh 0;
    }
}

@media (max-width: 400px) {
    .splash-title {
        font-size: clamp(28px, 9vw, 70px);
        line-height: 1;
    }
    .splash-prompt {
        font-size: clamp(16px, 4.5vw, 28px);
        letter-spacing: 2px;
    }
    .splash-credit {
        font-size: clamp(14px, 3.5vw, 24px);
        letter-spacing: 2px;
    }
}
/* --- END SPLASH SCREEN --- */

.ui-button {
    background: var(--glass-bg);
    border: 2px solid var(--border-cyan);
    color: #fff;
    padding: 15px 30px;
    margin: 10px;
    cursor: pointer;
    font-size: clamp(16px, 3vw, 22px);
    font-family: inherit;
    text-transform: uppercase;
    letter-spacing: 3px;
    box-shadow: 0 0 10px var(--glow-cyan), inset 0 0 10px rgba(0, 255, 255, 0.3);
    transition: all 0.3s ease;
    min-width: 300px;
    text-align: center;
}
.ui-button:hover {
    background: rgba(0, 255, 255, 0.1);
    color: var(--border-cyan);
    border-color: #fff;
    box-shadow: 0 0 20px var(--glow-cyan), inset 0 0 15px rgba(0, 255, 255, 0.5);
    transform: translateY(-3px) scale(1.02);
}

.ui-button.primary { border-color: var(--border-magenta); }
.ui-button.primary:hover {
    color: var(--border-magenta);
    background: rgba(255, 0, 255, 0.1);
    box-shadow: 0 0 20px var(--glow-magenta), inset 0 0 15px rgba(255, 0, 255, 0.5);
}
.ui-button.danger { border-color: var(--danger-red); }
.ui-button.danger:hover {
    color: var(--danger-red);
    background: rgba(255, 51, 51, 0.1);
    box-shadow: 0 0 20px var(--danger-red), inset 0 0 15px rgba(255, 51, 51, 0.5);
}


/* Container scrollabile per la griglia livelli */
.level-select-container {
    width: 100%;
    max-width: 900px;
    max-height: 65vh;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 10px;
    margin: 20px 0;
}

/* Scrollbar personalizzato */
.level-select-container::-webkit-scrollbar {
    width: 8px;
}

.level-select-container::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
}

.level-select-container::-webkit-scrollbar-thumb {
    background: var(--border-magenta);
    border-radius: 4px;
    box-shadow: 0 0 10px var(--glow-magenta);
}

.level-select-container::-webkit-scrollbar-thumb:hover {
    background: var(--border-cyan);
    box-shadow: 0 0 15px var(--glow-cyan);
}

.level-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(clamp(70px, 12vw, 100px), 1fr));
    gap: clamp(10px, 2vw, 20px);
    width: 100%;
    padding: 10px;
}
.level-tile {
    aspect-ratio: 1;
    background: var(--glass-bg);
    border: 2px solid var(--border-magenta);
    border-radius: 8px;
    box-shadow: 0 0 10px var(--glow-magenta), inset 0 0 10px rgba(255, 0, 255, 0.3);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    min-height: 70px;
}
.level-tile:hover {
    background: rgba(255, 0, 255, 0.15);
    transform: scale(1.05);
    border-color: #fff;
    box-shadow: 0 0 25px var(--glow-magenta), inset 0 0 20px rgba(255, 0, 255, 0.5);
}
.level-number { 
    font-size: clamp(1.2em, 3vw, 2em); 
    font-weight: bold; 
}
.level-tile.locked {
    background: rgba(30, 30, 60, 0.7);
    border-color: #404080;
    cursor: not-allowed;
    box-shadow: none;
}
.level-tile.locked:hover { 
    transform: none; 
    background: rgba(30, 30, 60, 0.7); 
    border-color: #404080; 
}
.padlock { 
    font-size: clamp(1.5em, 4vw, 2.5em); 
    animation: blink-red 2s infinite; 
}
@keyframes blink-red { 50% { color: #f00; text-shadow: 0 0 10px #f00; } }

.stars { 
    display: flex; 
    gap: 2px; 
    margin-top: 3px; 
    font-size: clamp(0.8em, 2vw, 1.2em); 
    color: #ff0; 
}
.stars .star.lit { text-shadow: 0 0 5px #ff0, 0 0 10px #ff0; }
.stars .star.unlit { color: rgba(255, 255, 0, 0.2); }

@keyframes star-bounce-in {
    0% { transform: scale(3); opacity: 0; }
    60% { transform: scale(0.9); opacity: 1; }
    80% { transform: scale(1.1); }
    100% { transform: scale(1); }
}
.level-complete-panel .ui-title { animation: none; text-shadow: 0 0 15px var(--glow-magenta); }
.level-complete-panel .stars { font-size: 3em; }
.level-complete-panel .star { transform: scale(0); opacity: 0; }
.level-complete-panel .star.animate { animation: star-bounce-in 0.5s forwards ease-out; }
.level-complete-panel .ui-button { opacity: 0; transform: translateY(20px); }
.level-complete-panel .ui-button.animate { animation: fade-slide-up 0.5s forwards ease-out; }
@keyframes fade-slide-up { to { opacity: 1; transform: translateY(0); } }

/* --- Leaderboard Styles (NUOVO) --- */
.leaderboard-container {
    width: 100%;
    max-width: 600px;
    height: 70vh;
    overflow-y: auto;
    padding: 0 20px;
}
.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    font-size: clamp(14px, 2.5vw, 18px);
    letter-spacing: 1px;
}
.leaderboard-table th, .leaderboard-table td {
    padding: 12px 15px;
    text-align: center;
}
.leaderboard-table th {
    color: var(--border-cyan);
    text-shadow: 0 0 8px var(--glow-cyan);
    text-transform: uppercase;
    border-bottom: 2px solid var(--border-cyan);
}
.leaderboard-table td {
    border-bottom: 1px solid rgba(0, 255, 255, 0.2);
}
.leaderboard-table tr:last-child td {
    border-bottom: none;
}
.leaderboard-table .stars { font-size: 1.5em; }


/* --- Options Panel --- */
.options-container { width: 100%; max-width: 400px; }
.slider-group { margin: 20px 0; text-align: center; }
.slider-group label { display: block; font-size: 1.2em; letter-spacing: 2px; margin-bottom: 10px; text-shadow: 0 0 8px var(--glow-cyan); }
input[type=range] { -webkit-appearance: none; width: 80%; background: transparent; }
input[type=range]:focus { outline: none; }
input[type=range]::-webkit-slider-runnable-track { width: 100%; height: 8px; cursor: pointer; background: rgba(0, 0, 0, 0.5); border-radius: 5px; border: 1px solid var(--border-cyan); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; height: 24px; width: 12px; border-radius: 3px; background: var(--border-cyan); cursor: pointer; margin-top: -9px; box-shadow: 0 0 10px var(--glow-cyan); }
input[type=range]::-moz-range-track { width: 100%; height: 8px; cursor: pointer; background: rgba(0, 0, 0, 0.5); border-radius: 5px; border: 1px solid var(--border-cyan); }
input[type=range]::-moz-range-thumb { height: 24px; width: 12px; border-radius: 3px; border: 0; background: var(--border-cyan); cursor: pointer; box-shadow: 0 0 10px var(--glow-cyan); }

/* --- Particles --- */
.particle, .confetti { position: absolute; pointer-events: none; }
.particle { border-radius: 50%; }
.confetti { width: 10px; height: 10px; clip-path: polygon(50% 0%, 0% 100%, 100% 100%); }

.toast-notification {
    position: absolute;
    top: 20%; left: 50%;
    transform: translateX(-50%);
    background: rgba(10, 10, 26, 0.9);
    color: #fff;
    padding: 15px 30px;
    border-radius: 5px;
    border: 2px solid var(--border-magenta);
    box-shadow: 0 0 20px var(--glow-magenta);
    font-size: 24px; letter-spacing: 2px;
    z-index: 1000; pointer-events: none;
    animation: fade-in-out 3s forwards;
}
.toast-notification .stars { font-size: 20px; color: #ffff00; margin-right: 10px; }

@keyframes fade-in-out {
    0% { opacity: 0; transform: translate(-50%, -20%); }
    20% { opacity: 1; transform: translate(-50%, 0); }
    80% { opacity: 1; transform: translate(-50%, 0); }
    100% { opacity: 0; transform: translate(-50%, 20%); }
}

@media (max-width: 600px) {
    #game-hud { 
        font-size: clamp(12px, 2.5vw, 16px); 
        padding: clamp(3px, 1vw, 5px) clamp(5px, 2vw, 10px); 
        flex-wrap: wrap; 
        justify-content: center;
        gap: clamp(3px, 0.5vw, 5px);
    }
    #game-hud span { 
        min-width: fit-content; 
        text-align: center; 
        margin: 2px 3px; 
    }
    .ui-title { 
        font-size: clamp(24px, 8vw, 48px); 
        letter-spacing: 2px; 
    }
    .ui-button { 
        font-size: clamp(12px, 3vw, 18px); 
        padding: clamp(8px, 2vw, 12px) clamp(15px, 4vw, 25px); 
        min-width: clamp(150px, 50vw, 200px);
    }
    .level-grid { 
        grid-template-columns: repeat(auto-fit, minmax(clamp(60px, 12vw, 80px), 1fr)); 
        gap: clamp(6px, 1.5vw, 12px); 
        padding: 5px;
    }
    .level-select-container {
        max-height: 60vh;
        padding: 5px;
    }
    .toast-notification { 
        font-size: clamp(14px, 4vw, 20px); 
        padding: clamp(8px, 2vw, 12px) clamp(15px, 4vw, 25px); 
        width: 90%; 
        text-align: center;
    }
}

/* Media query per schermi extra-piccoli in portrait */
@media (max-width: 400px), (max-height: 500px) {
    #game-hud {
        font-size: clamp(10px, 2vw, 14px);
        padding: 3px 5px;
    }
    
    .splash-title {
        font-size: clamp(20px, 7vw, 50px);
    }
    
    .splash-prompt {
        font-size: clamp(12px, 3.5vw, 24px);
    }
    
    .splash-credit {
        font-size: clamp(10px, 3vw, 18px);
    }
    
    .ui-title {
        font-size: clamp(20px, 6vw, 36px);
        margin-bottom: 20px;
    }
    
    .ui-button {
        font-size: clamp(10px, 2.5vw, 14px);
        padding: 8px 15px;
        margin: 5px;
        min-width: 140px;
    }
    
    .level-grid {
        grid-template-columns: repeat(auto-fit, minmax(55px, 1fr));
        gap: 6px;
        padding: 5px;
    }
    
    .level-select-container {
        max-height: 55vh;
        padding: 5px;
    }
    
    .level-tile {
        min-height: 55px;
    }
    
    .level-number {
        font-size: clamp(1em, 2.5vw, 1.5em);
    }
    
    .padlock {
        font-size: clamp(1.2em, 3vw, 1.8em);
    }
    
    .stars {
        font-size: clamp(0.6em, 1.5vw, 0.9em);
        gap: 1px;
    }
}

/* Media query per schermi landscape molto bassi */
@media (max-height: 400px) and (orientation: landscape) {
    #game-hud {
        padding: 2px 5px;
        font-size: clamp(8px, 1.5vh, 12px);
    }
    
    .ui-title {
        font-size: clamp(16px, 4vh, 28px);
        margin-bottom: 10px;
    }
    
    .ui-button {
        padding: 5px 10px;
        margin: 3px;
        font-size: clamp(8px, 2vh, 12px);
        min-width: 100px;
    }
    
    .level-select-container {
        max-height: 50vh;
        padding: 5px;
    }
    
    .level-grid {
        grid-template-columns: repeat(auto-fit, minmax(50px, 1fr));
        gap: 5px;
    }
    
    .level-tile {
        min-height: 50px;
    }
    
    .level-number {
        font-size: 1em;
    }
    
    .padlock {
        font-size: 1.3em;
    }
    
    .stars {
        font-size: 0.7em;
        gap: 1px;
    }
}