/* RESET E BASE */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    color: #fff;
    overflow: hidden;
    height: 100vh;
    height: 100dvh; /* altezza dinamica: tiene conto della barra URL su mobile */
    width: 100vw;
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
}

/* CONTAINER PRINCIPALE */
#game-container {
    width: 100%;
    height: 100%;
    position: relative;
}

/* SCHERMATE GENERALI */
.screen {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: flex-start; /* niente taglio in alto quando il contenuto è alto */
    justify-content: center;
    position: absolute;
    top: 0;
    left: 0;
    transition: opacity 0.5s ease;
    overflow-y: auto; /* scroll verticale se il contenuto supera lo schermo */
    -webkit-overflow-scrolling: touch;
}

.screen.hidden {
    opacity: 0;
    pointer-events: none;
    z-index: -1;
}

/* La schermata di gioco non deve mai scrollare (canvas FPS) */
#game-screen {
    overflow: hidden;
}

.content-box {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 40px;
    max-width: 600px;
    width: 90%;
    margin: auto; /* centra quando c'è spazio, resta raggiungibile con lo scroll */
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* REGISTRAZIONE */
h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
    text-align: center;
    background: linear-gradient(45deg, #f39c12, #e74c3c);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

h2 {
    font-size: 1.8em;
    margin-bottom: 30px;
    text-align: center;
    color: #ecf0f1;
}

.registration-form {
    margin: 30px 0;
}

.input-group {
    margin-bottom: 20px;
}

.input-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 1.1em;
    color: #bdc3c7;
}

.input-group input {
    width: 100%;
    padding: 15px;
    font-size: 1.2em;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.input-group input:focus {
    outline: none;
    border-color: #f39c12;
    background: rgba(255, 255, 255, 0.15);
    box-shadow: 0 0 15px rgba(243, 156, 18, 0.3);
}

.error {
    color: #e74c3c;
    font-size: 0.9em;
    margin-top: 5px;
    display: block;
    min-height: 20px;
}

.info-text {
    margin-top: 20px;
    padding: 15px;
    background: rgba(231, 76, 60, 0.1);
    border-left: 3px solid #e74c3c;
    border-radius: 5px;
}

.info-text p {
    margin: 5px 0;
    font-size: 0.9em;
    color: #e74c3c;
}

/* BUTTONS */
.btn-primary, .btn-secondary {
    width: 100%;
    padding: 15px 30px;
    font-size: 1.1em;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    margin: 10px 0;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn-primary {
    background: linear-gradient(45deg, #f39c12, #e67e22);
    color: #fff;
    box-shadow: 0 4px 15px rgba(243, 156, 18, 0.4);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(243, 156, 18, 0.6);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.5);
}

/* SELEZIONE PERSONAGGIO */
.character-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 20px;
    margin: 30px 0;
}

.character-card {
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 15px;
    padding: 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

.character-card:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: #f39c12;
    transform: translateY(-5px);
    box-shadow: 0 10px 30px rgba(243, 156, 18, 0.3);
}

.character-card.selected {
    border-color: #27ae60;
    background: rgba(39, 174, 96, 0.2);
    box-shadow: 0 0 20px rgba(39, 174, 96, 0.5);
}

.character-icon {
    font-size: 3em;
    margin-bottom: 10px;
}

.character-card h3 {
    margin: 10px 0;
    color: #f39c12;
}

.character-card .ability {
    font-weight: bold;
    color: #27ae60;
    margin: 5px 0;
}

.character-card .description {
    font-size: 0.85em;
    color: #bdc3c7;
}

.player-stats {
    margin-top: 20px;
    padding: 15px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    text-align: center;
}

.player-stats p {
    margin: 5px 0;
    font-size: 1.1em;
}

/* GAME SCREEN */
#game-screen {
    background: #000;
}

#game-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* HUD */
#game-hud {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

.hud-top {
    display: flex;
    justify-content: space-between;
    padding: 20px;
    background: linear-gradient(to bottom, rgba(0,0,0,0.7), transparent);
}

.hud-item {
    margin: 0 15px;
}

.hud-item .label {
    font-size: 0.9em;
    color: #bdc3c7;
    margin-right: 5px;
}

.hud-item .value {
    font-size: 1.2em;
    font-weight: bold;
    color: #f39c12;
    min-width: 60px;
    display: inline-block;
}

.hud-center {
    text-align: center;
}

.phase-badge {
    background: rgba(243, 156, 18, 0.3);
    border: 2px solid #f39c12;
    border-radius: 20px;
    padding: 8px 20px;
    font-size: 1.1em;
    font-weight: bold;
    color: #f39c12;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* GAME MESSAGE */
.game-message {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.9);
    border: 5px solid #f39c12;
    border-radius: 25px;
    padding: 40px 60px;
    font-size: 2.5em;
    font-weight: bold;
    text-align: center;
    color: #f39c12;
    animation: pulse 1.5s infinite;
    z-index: 2000;
    max-width: 90%;
    box-shadow: 0 0 30px rgba(243, 156, 18, 0.8);
}

.game-message.hidden {
    display: none;
}

@keyframes pulse {
    0%, 100% { transform: translate(-50%, -50%) scale(1); }
    50% { transform: translate(-50%, -50%) scale(1.05); }
}

/* OBJECTIVE */
.objective {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 15px;
    padding: 15px 30px;
    font-size: 1.1em;
    text-align: center;
    max-width: 80%;
}

.objective-icon {
    font-size: 1.5em;
    margin-right: 10px;
}

/* PAUSE MENU */
.menu-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    z-index: 100;
}

.menu-overlay.hidden {
    display: none;
}

.menu-content {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 40px;
    max-width: 400px;
    width: 90%;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.menu-content h2 {
    margin-bottom: 30px;
    font-size: 2em;
}

/* GAME OVER */
#gameover-title {
    font-size: 3em;
    margin-bottom: 20px;
}

#gameover-title.victory {
    background: linear-gradient(45deg, #27ae60, #2ecc71);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

#gameover-title.defeat {
    background: linear-gradient(45deg, #e74c3c, #c0392b);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.final-stats {
    margin: 30px 0;
    padding: 20px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
}

.final-stats p {
    margin: 10px 0;
    font-size: 1.2em;
}

.final-stats span {
    color: #f39c12;
    font-weight: bold;
}

.gameover-buttons {
    margin-top: 20px;
}

/* LEADERBOARD */
.leaderboard-tabs {
    display: flex;
    margin-bottom: 20px;
}

.tab-btn {
    flex: 1;
    padding: 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid rgba(255, 255, 255, 0.1);
    color: #fff;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: bold;
}

.tab-btn:first-child {
    border-radius: 10px 0 0 10px;
}

.tab-btn:last-child {
    border-radius: 0 10px 10px 0;
}

.tab-btn.active {
    background: rgba(243, 156, 18, 0.3);
    border-color: #f39c12;
    color: #f39c12;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
}

.leaderboard-table th,
.leaderboard-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.leaderboard-table th {
    background: rgba(243, 156, 18, 0.2);
    color: #f39c12;
    font-weight: bold;
}

.leaderboard-table tr:hover {
    background: rgba(255, 255, 255, 0.05);
}

.leaderboard-table .rank-1 {
    color: #f39c12;
    font-weight: bold;
}

.leaderboard-table .rank-2 {
    color: #bdc3c7;
    font-weight: bold;
}

.leaderboard-table .rank-3 {
    color: #cd7f32;
    font-weight: bold;
}

.your-stats {
    margin: 20px 0;
    padding: 15px;
    background: rgba(39, 174, 96, 0.1);
    border-left: 3px solid #27ae60;
    border-radius: 5px;
}

.your-stats h3 {
    margin-bottom: 10px;
    color: #27ae60;
}

.your-stats p {
    margin: 5px 0;
    font-size: 1em;
}

.your-stats span {
    color: #f39c12;
    font-weight: bold;
}

/* RESPONSIVE */
@media (max-width: 768px) {
    /* Riduce la base dei font: tutti i testi (titoli, HUD, card, sottotitoli)
       si rimpiccioliscono proporzionalmente senza toccare i pulsanti touch (px) */
    html {
        font-size: 14px;
    }

    h1 {
        font-size: 1.6em;
        margin-bottom: 6px;
    }

    h2 {
        font-size: 1.15em;
        margin-bottom: 15px;
    }

    .content-box {
        padding: 18px 14px;
        width: 94%;
        border-radius: 14px;
    }

    .registration-form {
        margin: 15px 0;
    }

    .input-group input {
        padding: 12px;
        font-size: 1.05em;
        letter-spacing: 1px;
    }

    /* Card custodi compatte in orizzontale (risparmiano altezza) */
    .character-grid {
        grid-template-columns: 1fr;
        gap: 10px;
        margin: 15px 0;
    }

    .character-card {
        display: flex;
        align-items: center;
        gap: 14px;
        padding: 10px 12px;
        text-align: left;
    }

    .character-card .lego-preview {
        width: 58px !important;
        height: 76px !important;
        margin: 0 !important;
        flex-shrink: 0;
    }

    .character-card h3 {
        font-size: 1.05em;
        margin: 0;
    }

    .character-card .ability {
        font-size: 0.8em;
        margin: 2px 0;
    }

    /* Descrizione nascosta su mobile: risparmia spazio */
    .character-card .description {
        display: none;
    }

    .player-stats {
        margin-top: 12px;
        padding: 10px;
    }

    .player-stats p {
        font-size: 0.95em;
    }

    /* HUD di gioco: riga unica compatta (non in colonna) */
    .hud-top {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        gap: 4px 14px;
        padding: 6px 8px;
    }

    .hud-item {
        margin: 0;
        font-size: 0.78em;
    }

    .hud-item .value {
        font-size: 1em;
    }

    /* Pulsanti touch più comodi */
    .btn-primary,
    .btn-secondary {
        padding: 12px 20px;
        min-height: 44px;
    }

    .info-text {
        padding: 10px;
        margin-top: 12px;
    }

    .info-text p {
        font-size: 0.8em;
    }
}

@media (max-width: 480px) {
    /* Telefoni piccoli: base font ancora più compatta (aspetto "zoom 50%") */
    html {
        font-size: 12.5px;
    }

    h1 {
        font-size: 1.35em;
    }

    h2 {
        font-size: 1.05em;
    }

    .content-box {
        padding: 14px 10px;
    }

    .tour-hint {
        font-size: 0.72em;
    }

    #tour-subtitle {
        bottom: 65px;
        font-size: 0.88em;
        padding: 10px 14px;
    }
}

/* ========================================
   OPZIONI GIOCO (toggle tempo infinito)
   ======================================== */

.infinite-time-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin: 12px 0;
    padding: 10px 12px;
    background: rgba(243, 156, 18, 0.08);
    border: 1px solid rgba(243, 156, 18, 0.35);
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.88em;
    color: #ecf0f1;
    -webkit-user-select: none;
    user-select: none;
}

.infinite-time-toggle input {
    width: 20px;
    height: 20px;
    accent-color: #f39c12;
    cursor: pointer;
    flex-shrink: 0;
}

/* Pulsante schermo intero nell'HUD touch */
.touch-btn.fullscreen-btn {
    top: 15px;
    right: 66px;
    width: 45px;
    height: 45px;
    font-size: 1.1em;
    position: absolute;
}

/* ========================================
   LAYOUT ORIZZONTALE (LANDSCAPE) MOBILE
   Controlli ancorati ai lati: joystick a sinistra,
   pulsanti azione a destra, area visuale al centro
   ======================================== */
@media (orientation: landscape) and (max-height: 560px) {
    /* HUD ancora più compatto in orizzontale */
    .hud-top {
        padding: 4px 10px;
        padding-top: max(4px, env(safe-area-inset-top));
        gap: 4px 16px;
    }

    .hud-item {
        font-size: 0.72em;
    }

    /* Joystick saldamente a sinistra */
    .joystick-container {
        left: max(12px, env(safe-area-inset-left));
        bottom: 12px;
        width: 105px;
        height: 105px;
    }

    .joystick-stick {
        width: 44px;
        height: 44px;
    }

    /* Pulsanti azione ancorati a destra */
    .action-buttons {
        right: max(12px, env(safe-area-inset-right));
        bottom: 12px;
        gap: 10px;
    }

    .action-buttons .touch-btn {
        width: 58px;
        height: 58px;
        font-size: 1.25em;
    }

    /* Area visuale: zona centrale libera per guardarsi intorno */
    .touch-look-area {
        width: 55%;
        left: 22.5%;
        right: 22.5%;
    }

    /* Pausa e fullscreen in alto a destra */
    .pause-btn {
        top: 12px;
        right: max(12px, env(safe-area-inset-right));
    }

    .touch-btn.fullscreen-btn {
        top: 12px;
        right: calc(max(12px, env(safe-area-inset-right)) + 56px);
    }

    /* Pannelli informativi non coprono i comandi */
    #artwork-info {
        bottom: 14px;
        left: 50%;
        transform: translateX(-50%);
        max-width: 46%;
        font-size: 0.82em;
    }

    #tour-subtitle {
        bottom: 14px;
        max-width: 58%;
        font-size: 0.88em;
    }

    /* Minimappa più discreta in orizzontale */
    #minimap {
        top: 44px;
        right: max(8px, env(safe-area-inset-right));
    }

    .game-message {
        top: 40px;
        font-size: 1.05em;
    }
}

/* ANIMAZIONI SPECIALI */
@keyframes flash {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.alarm-flash {
    animation: flash 0.5s infinite;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.shake {
    animation: shake 0.5s;
}

/* ========================================
   TOUR GUIDATO (DEMO CINEMATOGRAFICA)
   ======================================== */

.tour-hint {
    color: #7f8c8d;
    font-size: 0.8em;
    margin-top: 6px;
    text-align: center;
}

#tour-btn {
    margin-top: 10px;
}

#tour-subtitle {
    position: absolute;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    max-width: 640px;
    width: calc(100% - 40px);
    padding: 14px 22px;
    background: rgba(8, 8, 22, 0.88);
    border: 1px solid rgba(243, 156, 18, 0.6);
    border-radius: 12px;
    color: #fff;
    font-size: 1em;
    line-height: 1.45;
    text-align: center;
    z-index: 870;
    pointer-events: none;
    backdrop-filter: blur(4px);
}

#tour-subtitle em {
    color: #f39c12;
    font-style: normal;
}

#tour-skip {
    position: absolute;
    top: 70px;
    right: 14px;
    z-index: 871;
    background: rgba(8, 8, 22, 0.75);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 8px;
    padding: 8px 14px;
    cursor: pointer;
    font-size: 0.85em;
}

#tour-skip:hover {
    background: rgba(231, 76, 60, 0.8);
}

/* Overlay nero per i fade del tour (intro e finale) */
#tour-fade {
    position: absolute;
    inset: 0;
    background: #000;
    opacity: 0;
    transition: opacity 0.9s ease;
    pointer-events: none;
    z-index: 880;
}

/* ========================================
   PANNELLO INFORMAZIONI OPERA
   ======================================== */

#artwork-info {
    position: absolute;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%);
    max-width: 420px;
    padding: 12px 18px;
    background: rgba(10, 10, 25, 0.85);
    border: 1px solid rgba(243, 156, 18, 0.6);
    border-radius: 10px;
    color: #fff;
    font-size: 0.95em;
    line-height: 1.4;
    z-index: 850;
    pointer-events: none;
    text-align: center;
    backdrop-filter: blur(4px);
}

#artwork-info .desc {
    color: #bdc3c7;
    font-size: 0.85em;
}

/* ========================================
   TOUCH CONTROLS PER MOBILE
   ======================================== */

.touch-controls {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    display: none; /* Attivato via JS su mobile */
}

.touch-controls.active {
    display: block;
}

/* Joystick Container */
.joystick-container {
    position: absolute;
    bottom: 20px;
    left: 20px;
    width: 120px;
    height: 120px;
    pointer-events: auto;
}

.joystick-base {
    position: relative;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    backdrop-filter: blur(5px);
}

.joystick-stick {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 50px;
    height: 50px;
    background: rgba(243, 156, 18, 0.8);
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: transform 0.1s ease-out;
    box-shadow: 0 2px 10px rgba(243, 156, 18, 0.5);
}

.joystick-stick.active {
    background: rgba(243, 156, 18, 1);
    transform: translate(-50%, -50%) scale(1.1);
}

/* Touch Look Area */
.touch-look-area {
    position: absolute;
    top: 0;
    right: 0;
    width: 60%;
    height: 100%;
    pointer-events: auto;
    touch-action: none;
}

.touch-look-area.active {
    background: rgba(255, 255, 255, 0.05);
}

/* Action Buttons */
.action-buttons {
    position: absolute;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    pointer-events: auto;
}

.touch-btn {
    width: 70px;
    height: 70px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    color: #fff;
    font-size: 1.5em;
    cursor: pointer;
    transition: all 0.2s ease;
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.touch-btn:active {
    background: rgba(243, 156, 18, 0.8);
    transform: scale(0.95);
    box-shadow: 0 2px 15px rgba(243, 156, 18, 0.6);
}

.touch-btn.sprint-btn {
    background: rgba(39, 174, 96, 0.3);
    border-color: rgba(39, 174, 96, 0.5);
}

.touch-btn.sprint-btn:active {
    background: rgba(39, 174, 96, 0.8);
}

.touch-btn.jump-btn {
    background: rgba(231, 76, 60, 0.3);
    border-color: rgba(231, 76, 60, 0.5);
}

.touch-btn.map-btn {
    background: rgba(52, 152, 219, 0.3);
    width: 56px;
    height: 56px;
    font-size: 1.2em;
}

.touch-btn.map-btn:active {
    background: rgba(52, 152, 219, 0.7);
}

.touch-btn.jump-btn:active {
    background: rgba(231, 76, 60, 0.8);
}

.btn-icon {
    font-size: 1.8em;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5));
}

/* Pause Button */
.pause-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    pointer-events: auto;
    z-index: 1001;
}

/* Touch Status */
.touch-status {
    position: absolute;
    top: 20px;
    left: 20px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 20px;
    padding: 8px 15px;
    font-size: 0.9em;
    backdrop-filter: blur(5px);
}

.status-icon {
    margin-right: 5px;
}

/* Responsive per schermi molto piccoli */
@media (max-width: 480px) {
    .joystick-container {
        width: 100px;
        height: 100px;
        bottom: 15px;
        left: 15px;
    }

    .joystick-stick {
        width: 40px;
        height: 40px;
    }

    .action-buttons {
        bottom: 15px;
        right: 15px;
        gap: 10px;
    }

    .touch-btn {
        width: 60px;
        height: 60px;
        font-size: 1.3em;
    }

    .btn-icon {
        font-size: 1.5em;
    }

    .pause-btn {
        width: 45px;
        height: 45px;
        top: 15px;
        right: 15px;
    }

    /* Ottimizza HUD per mobile: riga unica compatta */
    .hud-top {
        padding: 6px 8px;
        padding-top: max(6px, env(safe-area-inset-top));
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        gap: 4px 12px;
    }

    .hud-item {
        margin: 0;
        font-size: 0.78em;
    }

    .hud-item .label {
        font-size: 0.8em;
    }

    .hud-item .value {
        font-size: 1em;
    }

    .phase-badge {
        font-size: 0.9em;
        padding: 6px 15px;
    }

    /* Ottimizza messaggi per mobile */
    .game-message {
        font-size: 1.5em;
        padding: 20px 30px;
        max-width: 90%;
    }

    .objective {
        font-size: 1em;
        padding: 12px 20px;
        bottom: 20px;
    }

    /* Nascondi alcuni elementi su mobile */
    .content-box {
        max-width: 95%;
        padding: 20px;
    }

    h1 {
        font-size: 1.8em;
    }

    h2 {
        font-size: 1.4em;
    }

    /* Leaderboard responsive */
    .leaderboard-table {
        font-size: 0.9em;
    }

    .leaderboard-table th,
    .leaderboard-table td {
        padding: 8px 5px;
    }

    /* Menu responsive */
    .menu-content {
        padding: 30px 20px;
        max-width: 90%;
    }

    .menu-content h2 {
        font-size: 1.6em;
    }
}

/* Orientamento landscape su mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .joystick-container {
        bottom: 10px;
        left: 10px;
        width: 80px;
        height: 80px;
    }

    .joystick-stick {
        width: 35px;
        height: 35px;
    }

    .action-buttons {
        bottom: 10px;
        right: 10px;
        flex-direction: row;
        gap: 10px;
    }

    .touch-btn {
        width: 50px;
        height: 50px;
    }

    .pause-btn {
        top: 10px;
        right: 10px;
        width: 40px;
        height: 40px;
    }

    .hud-top {
        padding: 5px 10px;
    }

    .game-message {
        font-size: 1.2em;
        padding: 15px 25px;
    }

    .objective {
        bottom: 80px;
        font-size: 0.9em;
        padding: 8px 15px;
    }
}

/* Ottimizzazioni per tablet */
@media (min-width: 768px) and (max-width: 1024px) {
    .joystick-container {
        width: 140px;
        height: 140px;
    }

    .joystick-stick {
        width: 60px;
        height: 60px;
    }

    .action-buttons .touch-btn {
        width: 80px;
        height: 80px;
    }
}

/* Prevent text selection e highlight su touch */
* {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Allow text selection solo per input */
input, textarea {
    -webkit-touch-callout: text;
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

/* Optimizzazione rendering per mobile */
@media (max-width: 768px) {
    /* Riduci effetti blur su mobile per performance */
    .content-box,
    .joystick-base,
    .touch-btn,
    .touch-status {
        backdrop-filter: none;
        background: rgba(255, 255, 255, 0.15);
    }

    /* Riduci ombre */
    .touch-btn {
        box-shadow: none;
    }

    /* Ottimizza animazioni */
    * {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
    }
}

/* Stato di caricamento mobile */
.mobile-loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    flex-direction: column;
    color: #fff;
}

.mobile-loading.hidden {
    display: none;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top: 3px solid #f39c12;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Mobile-specific UI hints */
.mobile-hint {
    position: absolute;
    bottom: 50%;
    left: 50%;
    transform: translate(-50%, 50%);
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 15px 25px;
    border-radius: 10px;
    font-size: 1em;
    text-align: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 500;
}

.mobile-hint.visible {
    opacity: 1;
}

/* Feedback visivo per touch */
.touch-feedback {
    position: absolute;
    width: 20px;
    height: 20px;
    background: rgba(243, 156, 18, 0.6);
    border-radius: 50%;
    pointer-events: none;
    animation: touchRipple 0.5s ease-out forwards;
    z-index: 1100;
}

@keyframes touchRipple {
    0% {
        transform: scale(0);
        opacity: 1;
    }
    100% {
        transform: scale(3);
        opacity: 0;
    }
}

/* Performance optimizations */
@media (max-width: 768px) {
    /* Riduci complessità grafica su mobile */
    .character-card,
    .btn-primary,
    .btn-secondary {
        will-change: transform;
    }

    /* Semplifica ombre */
    .content-box,
    .menu-content {
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    }
}
