@import url('https://fonts.googleapis.com/css2?family=Lexend:wght@300;500;700&display=swap');

:root { 
    --bg-color: #020617; 
    --accent-color: #38bdf8; 
    --danger-color: #fb7185; 
    --text-color: #f8fafc; 
    --gold: #fbbf24; 
    --success: #22c55e;
}

/* SETUP BASE E FIX QUADRATINO BIANCO SCROLLBAR */
html, body {
    height: 100%; 
    margin: 0;
    padding: 0;
}

::-webkit-scrollbar-corner {
    background: transparent;
}

body { 
    overflow-y: auto; 
    overflow-x: hidden; 
    background-color: var(--bg-color); 
    color: var(--text-color); 
    font-family: 'Lexend', Verdana, sans-serif; 
    user-select: none; 
    background-image: linear-gradient(to bottom, #020617 0%, #0f172a 100%);
    background-attachment: fixed;
}

/* STELLE FISSE */
.stars { 
    position: fixed; top: 0; left: 0; width: 100%; height: 100%; 
    pointer-events: none; z-index: 0; 
}
.star { position: absolute; background: white; border-radius: 50%; animation: twinkle infinite alternate; }
@keyframes twinkle { 0% { opacity: 0.2; transform: scale(0.5); } 100% { opacity: 1; transform: scale(1.2); } }

/* BLOCCO MOBILE */
#mobile-warning {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: #020617; z-index: 9999;
    flex-direction: column; justify-content: center; align-items: center;
    text-align: center; padding: 20px; box-sizing: border-box;
}
@media only screen and (max-width: 900px) {
    #mobile-warning { display: flex !important; }
    .screen, #game-interface, .stars { display: none !important; }
}

/* --- SIDEBAR MENU E OVERLAY --- */
#sidebar-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(2, 6, 23, 0.7); z-index: 1999; display: none;
    backdrop-filter: blur(3px);
}
.sidebar {
    position: fixed; top: 0; left: -400px;
    width: 360px; max-width: 85%; height: 100%;
    background: #0f172a; z-index: 2000; box-shadow: 5px 0 25px rgba(0,0,0,0.8);
    transition: left 0.3s ease-in-out; overflow-y: auto; padding: 30px 0; box-sizing: border-box;
    border-right: 2px solid var(--accent-color);
}
.sidebar.open { left: 0; }
.close-sidebar {
    position: absolute; top: 15px; right: 15px; background: transparent; border: none;
    color: var(--danger-color); font-size: 1.8rem; cursor: pointer; padding: 0; margin: 0; box-shadow: none;
}
.close-sidebar:hover { transform: scale(1.1); box-shadow: none; }

/* STILE DEI BOTTONI NELLA SIDEBAR */
.sidebar-btn {
    display: block; width: 100%; padding: 20px 25px; text-align: left;
    background: transparent; border: none; border-bottom: 1px solid rgba(255,255,255,0.05);
    color: white; font-size: 1.2rem; cursor: pointer; transition: 0.3s;
    font-family: 'Lexend', Verdana, sans-serif; text-transform: uppercase; font-weight: bold;
    box-shadow: none; margin: 0; border-radius: 0; box-sizing: border-box;
}
.sidebar-btn:hover {
    color: var(--accent-color); background: rgba(56, 189, 248, 0.1); padding-left: 35px;
    transform: none; box-shadow: none;
}


/* --- SCHERMATE E MENU TOP --- */
.top-bar { position: absolute; top: 30px; left: 30px; z-index: 20; }
.icon-btn { background: transparent; border: none; color: white; font-size: 2.2rem; cursor: pointer; box-shadow: none; padding: 0; margin: 0; transition: 0.2s; }
.icon-btn:hover { transform: scale(1.1); color: var(--accent-color); box-shadow: none; }

.screen { 
    position: relative; 
    width: 100%; 
    min-height: 100vh; 
    display: none; 
    flex-direction: column; 
    justify-content: center; 
    align-items: center;     
    padding-top: 100px; 
    padding-bottom: 60px; 
    box-sizing: border-box;
    background: rgba(2, 6, 23, 0.9); 
    z-index: 10; 
}
#login-screen { display: flex; }

/* Titoli e Testi */
.title-container { display: flex; align-items: center; gap: 15px; margin-bottom: 10px; }
h1 { font-size: 3rem; text-transform: uppercase; letter-spacing: 2px; text-shadow: 0 0 20px var(--accent-color); text-align: center; color: white; margin: 0; }
.title-rocket { font-size: 3.5rem; animation: floatRocket 3s ease-in-out infinite; display: inline-block; }
@keyframes floatRocket { 0%, 100% { transform: translateY(0) rotate(-45deg); } 50% { transform: translateY(-15px) rotate(-45deg); } }

.switch-link { margin-top: 20px; color: var(--accent-color); text-decoration: underline; cursor: pointer; transition: 0.2s; font-size: 0.95rem; }
.switch-link:hover { color: white; }

.footer-container { position: absolute; bottom: 20px; left: 0; width: 100%; text-align: center; }
.footer-credit { font-size: 0.9rem; color: var(--accent-color); opacity: 0.7; letter-spacing: 1px; text-transform: uppercase; font-weight: 300; }

/* Input UI */
.form-group { display: flex; flex-direction: column; align-items: center; gap: 15px; width: 100%; margin-bottom: 15px; }
input[type="text"], input[type="password"] { 
    padding: 15px 20px; font-size: 1.1rem; border-radius: 12px; 
    border: 2px solid var(--accent-color); background: #0f172a; color: white; 
    outline: none; width: 280px; text-align: center; transition: 0.3s; 
}

.password-wrapper { position: relative; width: 324px; display: flex; justify-content: center; }
.password-toggle { position: absolute; right: 15px; top: 50%; transform: translateY(-50%); cursor: pointer; font-size: 1.2rem; color: var(--accent-color); z-index: 5; background: none; border: none; padding: 0; }
.password-toggle:hover { color: white; }

/* MENU A TENDINA PERSONALIZZATO */
.custom-select-wrapper { position: relative; width: 320px; user-select: none; margin-bottom: 5px; font-weight: bold; z-index: 20; }
.custom-select-trigger {
    padding: 15px 20px; font-size: 1.1rem; background: #0f172a; color: var(--gold); 
    border: 2px solid var(--accent-color); border-radius: 50px; cursor: pointer;
    display: flex; justify-content: center; align-items: center; gap: 10px; transition: 0.3s; text-transform: uppercase;
}
.custom-select-trigger:hover { box-shadow: 0 0 20px var(--accent-color); border-color: white; }
.arrow { font-size: 0.8rem; color: var(--gold); margin-left: 10px; transition: 0.3s; }
.custom-options { position: absolute; top: 110%; left: 0; right: 0; background: #0f172a; border: 2px solid var(--accent-color); border-radius: 15px; z-index: 100; opacity: 0; visibility: hidden; transform: translateY(-10px); transition: 0.3s; overflow: hidden; box-shadow: 0 10px 30px rgba(0,0,0,0.8); }
.custom-select-wrapper.open .custom-options { opacity: 1; visibility: visible; transform: translateY(0); }
.custom-select-wrapper.open .arrow { transform: rotate(180deg); }
.custom-option { padding: 15px; text-align: center; color: white; cursor: pointer; border-bottom: 1px solid rgba(56, 189, 248, 0.2); transition: 0.2s; text-transform: uppercase; }
.custom-option:last-child { border-bottom: none; }
.custom-option:hover { background: var(--accent-color); color: #020617; font-weight: bold; }
.custom-option.selected { background: rgba(56, 189, 248, 0.2); color: var(--gold); }
.custom-option.special { color: var(--gold); }

/* Bottoni */
button { margin-top: 15px; padding: 15px 40px; font-size: 1.3rem; background: linear-gradient(45deg, #0ea5e9, #3b82f6); color: white; border: none; border-radius: 50px; cursor: pointer; font-weight: bold; transition: 0.2s; box-shadow: 0 5px 20px rgba(14, 165, 233, 0.4); text-transform: uppercase; }
button:hover { transform: translateY(-3px) scale(1.05); box-shadow: 0 10px 25px rgba(14, 165, 233, 0.6); }
.secondary-btn { background: transparent; border: 2px solid var(--accent-color); color: var(--accent-color); box-shadow: none; font-size: 1rem; padding: 10px 20px; }

/* IMPOSTAZIONI CUSTOM */
.custom-panel { background: #1e293b; padding: 25px; border-radius: 15px; border: 2px solid var(--accent-color); text-align: left; width: 320px; box-sizing: border-box; margin-top: 15px; display: none; box-shadow: 0 0 30px rgba(56, 189, 248, 0.15); }
.custom-row { margin-bottom: 20px; width: 100%; }
.custom-label { font-size: 0.85rem; color: var(--accent-color); margin-bottom: 8px; display: block; font-weight: bold; letter-spacing: 1px; text-transform: uppercase; }
.checkbox-group { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; width: 100%; }
.checkbox-item { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 1rem; text-transform: uppercase; margin: 0; }
input[type="checkbox"] { width: 22px; height: 22px; border-color: var(--accent-color); accent-color: var(--accent-color); cursor: pointer; margin: 0; }
input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 8px; background: rgba(255,255,255,0.2); border-radius: 5px; outline: none; margin: 10px 0; cursor: pointer; background-image: linear-gradient(var(--accent-color), var(--accent-color)); background-repeat: no-repeat; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 24px; height: 24px; background: var(--accent-color); border-radius: 50%; box-shadow: 0 0 15px var(--accent-color); cursor: pointer; border: 2px solid white; }

/* Tabs e Classifiche */
.tabs-container { display: flex; gap: 10px; margin-bottom: 15px; }
.tab-btn { padding: 8px 15px; font-size: 0.9rem; border: 1px solid var(--accent-color); border-radius: 20px; background: rgba(0,0,0,0.3); color: var(--text-color); cursor: pointer; box-shadow: none; text-transform: uppercase; }
.tab-btn.active { background: var(--accent-color); color: #020617; font-weight: bold; }
#history-list { list-style: none; padding: 0; width: 90%; max-width: 500px; max-height: 400px; overflow-y: auto; background: rgba(255,255,255,0.05); border-radius: 10px; }
#history-list li { padding: 15px; border-bottom: 1px solid rgba(255,255,255,0.1); display: flex; justify-content: space-between; font-size: 1.1rem; }

#gameover-leaderboard { list-style: none; padding: 0; width: 100%; max-height: 200px; overflow-y: auto; background: rgba(0,0,0,0.3); border-radius: 10px; margin-bottom: 20px; border: 1px solid rgba(255,255,255,0.1); }
#gameover-leaderboard li { padding: 10px; border-bottom: 1px solid rgba(255,255,255,0.1); display: flex; justify-content: space-between; font-size: 1rem; }

/* Gioco e HUD */
#game-interface { display: none; width: 100%; height: 100vh; position: relative; overflow: hidden; }
#hud-top { position: absolute; top: 20px; left: 20px; right: 20px; display: flex; justify-content: space-between; align-items: center; z-index: 5; font-size: 1.3rem; font-weight: bold; text-shadow: 0 0 5px black; }
.hud-item { background: rgba(15, 23, 42, 0.9); padding: 10px 20px; border-radius: 12px; border: 1px solid var(--accent-color); display: flex; gap: 10px; color: white; text-transform: uppercase; }
#input-display { position: absolute; bottom: 40px; left: 50%; transform: translateX(-50%); font-size: 2.5rem; padding: 10px 50px; border-radius: 15px; background: rgba(15, 23, 42, 0.9); border: 2px solid var(--accent-color); min-width: 300px; text-align: center; box-shadow: 0 0 20px var(--accent-color); color: white; height: 60px; line-height: 60px; text-transform: uppercase; pointer-events: none; }

/* Razzo */
.rocket-container { position: absolute; display: flex; flex-direction: column; align-items: center; filter: drop-shadow(0 0 15px var(--accent-color)); width: 200px; text-align: center; }
.rocket-icon { font-size: 60px; transform: rotate(-45deg); z-index: 1; margin-bottom: 15px; }
.rocket-text { padding: 10px 15px; background: #0f172a; border: 3px solid var(--accent-color); border-radius: 10px; font-size: 1.5rem; font-weight: bold; color: white; z-index: 2; box-shadow: 0 5px 15px rgba(0,0,0,0.5); letter-spacing: 2px; white-space: nowrap; }

/* POPUP E TUTORIAL TEXT */
.overlay-popup { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(2, 6, 23, 0.95); display: none; flex-direction: column; justify-content: center; align-items: center; z-index: 999; }
.popup-content { background: #1e293b; padding: 40px; border-radius: 20px; border: 2px solid var(--accent-color); text-align: center; box-shadow: 0 0 50px rgba(56, 189, 248, 0.2); max-width: 500px; width: 90%; max-height: 85vh; overflow-y: auto; overflow-x: hidden; }

/* SCROLLBAR STILIZZATA GLOBALE PER POPUP E TASTIERA */
.popup-content::-webkit-scrollbar, .modal-contenuto::-webkit-scrollbar, .tastiera-scroll-wrapper::-webkit-scrollbar { width: 10px; height: 10px; }
.popup-content::-webkit-scrollbar-track, .modal-contenuto::-webkit-scrollbar-track, .tastiera-scroll-wrapper::-webkit-scrollbar-track { background: rgba(0,0,0,0.3); border-radius: 10px; margin: 10px; }
.popup-content::-webkit-scrollbar-thumb, .modal-contenuto::-webkit-scrollbar-thumb, .tastiera-scroll-wrapper::-webkit-scrollbar-thumb { background: var(--accent-color); border-radius: 10px; }

.tutorial-text p { font-size: 1.1rem; line-height: 1.6; color: #cbd5e1; margin-bottom: 15px; }
.tutorial-level { color: var(--gold); font-weight: bold; font-size: 1.2rem; }

/* STILE PER IL LINK NEL FOOTER */
.footer-credit a {
    color: inherit; 
    text-decoration: none; 
    transition: 0.2s ease; 
    font-weight: bold; 
}
.footer-credit a:hover {
    color: white; 
    text-shadow: 0 0 10px white; 
}

/* --- STILE MODALE TASTIERA DEFINITIVA E GIGANTE --- */
.modal-nascosta {
    display: none; 
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(2, 6, 23, 0.95); 
    align-items: center; 
    justify-content: center;
    padding: 0;
}

.modal-contenuto {
    background-color: #1e1e2e;
    color: white;
    padding: 30px 10px; 
    border-radius: 12px;
    width: 98%; 
    max-width: 1450px; 
    max-height: 90vh; 
    text-align: center;
    border: 2px solid var(--accent-color); 
    position: relative;
    box-shadow: 0px 0px 30px rgba(56, 189, 248, 0.3); 
    transform: translateY(-5vh); 
    display: flex;
    flex-direction: column;
}

#chiudi-tastiera {
    color: #aaa;
    position: absolute;
    top: 10px;
    right: 20px;
    font-size: 30px;
    font-weight: bold;
    cursor: pointer;
}
#chiudi-tastiera:hover { color: var(--danger-color); }

.legenda-tastiera {
    margin-bottom: 20px;
    font-size: 1rem;
    color: #cbd5e1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

/* --- IL WRAPPER CHE PREVIENE I TAGLI DELLA TASTIERA --- */
.tastiera-scroll-wrapper {
    width: 100%;
    overflow-x: auto; 
    padding-bottom: 15px; 
}

/* --- LAYOUT COMPLETO TASTIERA --- */
.tastiera-layout {
    display: inline-flex; 
    gap: 15px;
    align-items: flex-end; 
    margin: 0 auto;
    padding: 0 10px; 
}

.sezione-main, .sezione-nav, .sezione-num { flex-shrink: 0; }

.sezione-main { display: flex; flex-direction: column; gap: 6px; width: 836px; /* Forza la larghezza assoluta! */ }
.sezione-nav { display: flex; flex-direction: column; justify-content: space-between; height: 100%; padding-bottom: 2px; }
.nav-cluster { display: grid; grid-template-columns: repeat(3, 48px); gap: 6px; }

/* SEZIONE NUMPAD 100% PERFETTA */
.sezione-num {
    display: grid;
    grid-template-columns: repeat(4, 48px); 
    grid-template-rows: repeat(5, 48px); 
    gap: 6px;
}
.tasto-num-tall-plus { grid-column: 4; grid-row: 2 / span 2; height: 100% !important; }
.tasto-num-tall-enter { grid-column: 4; grid-row: 4 / span 2; height: 100% !important; }
.tasto-num-wide-zero { grid-column: 1 / span 2; grid-row: 5; width: 100% !important; }

.riga-tastiera {
    display: flex;
    justify-content: flex-start;
    align-items: flex-start; 
    gap: 6px;
}

/* STILE TASTI BASE GIGANTI (48px) */
.tasto {
    background-color: #2b2b36;
    color: white;
    width: 48px; 
    height: 48px; 
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: bold;
    border-bottom: 4px solid #111; 
    cursor: pointer; 
    transition: all 0.1s;
    user-select: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    line-height: 1.1;
    box-sizing: border-box;
    flex-shrink: 0; 
    overflow: hidden; 
}
.tasto span:first-child { font-size: 0.85rem; color: #cbd5e1; } 
.tasto span:last-child { font-size: 1.3rem; } 

/* FIX DIMENSIONI TESTI TASTI SPECIALI */
.tasto.text-sm span:last-child {
    font-size: 0.85rem !important; 
    white-space: pre-wrap; 
    text-align: center;
}

/* TASTI IN EVIDENZA (GIALLO TENUE) */
.tasto.in-gioco {
    background-color: #3b3a24;
    border-bottom: 4px solid #242312;
    color: #fde047;
}
.tasto.in-gioco span:first-child { color: #fde047; opacity: 0.8; }

/* HOVER PER TUTTI I TASTI (DIVENTANO AZZURRI) */
.tasto:hover, .tasto.in-gioco:hover {
    background-color: var(--accent-color); 
    color: #020617;
    border-bottom: 4px solid #0284c7;
    transform: translateY(2px); 
}
.tasto:hover span:first-child, .tasto.in-gioco:hover span:first-child { color: #020617; }

/* LARGHEZZE MATEMATICHE PERFETTE (Totale riga = 836px) */
.w-backspace { width: 134px; align-items: flex-end; padding-right: 12px; }
.w-tab { width: 72px; align-items: flex-start; padding-left: 12px; }
.w-enter { width: 110px; align-items: flex-end; padding-right: 12px; }
.w-caps { width: 106px; align-items: flex-start; padding-left: 12px; }
.w-u-key { width: 130px; align-items: flex-end; padding-right: 12px; }
.w-shift-l { width: 86px; align-items: flex-start; padding-left: 12px; }
.w-shift-r { width: 150px; align-items: flex-end; padding-right: 12px; }
.w-ctrl-l { width: 72px; align-items: flex-start; padding-left: 12px; }
.w-space { width: 410px; }
.w-ctrl-r { width: 72px; align-items: flex-end; padding-right: 12px; }

.invisibile { opacity: 0; pointer-events: none; }

/* --- EFFETTO MINI-ESPLOSIONE RAZZO (MIGLIORATA: GRANDE, LENTA, CONTENUTA) --- */
.particella-esplosione {
    position: absolute;
    width: 10px; /* Più grandi */
    height: 10px; /* Più grandi */
    background-color: #ffaa00; 
    border-radius: 50%;
    pointer-events: none; 
    /* Più lenta (0.8s), svanisce dolcemente */
    animation: esplodi 0.8s cubic-bezier(0.1, 0.5, 0.5, 1) forwards;
    z-index: 500;
}
@keyframes esplodi {
    0% { transform: scale(1) translate(0, 0); opacity: 1; }
    20% { opacity: 1; } /* Rimane visibile un po' di più all'inizio */
    100% { transform: scale(0) translate(var(--tx), var(--ty)); opacity: 0; }
}