* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Courier New', Courier, monospace;
}

body {
    background-color: #ffffff;
    color: #000000;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100dvh;
    user-select: none;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
}

@media (display-mode: standalone) {
    html, body { height: 100dvh; }
}

/* --- FORZATURA ORIZZONTALE PER MOBILE --- */
@media screen and (orientation: portrait) {
    #portrait-warning {
        display: flex !important;
    }
}
#portrait-warning {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: #ffffff; color: #000000; z-index: 9999;
    display: none; flex-direction: column; justify-content: center; align-items: center;
    text-align: center; padding: 20px; font-weight: bold;
    border: 10px solid #000000;
}

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
}

/* --- SELETTORE COMANDI (COMPATTO E SPOSTATO) --- */
.controls-selector {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 110;
    border: 2px solid #000000;
    padding: 6px 10px;
    background: #ffffff;
    box-shadow: 4px 4px 0px #000000;
    max-width: 200px;
}
.controls-selector label {
    font-weight: bold;
    font-size: 0.65rem;
    display: block;
    margin-bottom: 4px;
    text-transform: uppercase;
}
.layout-options {
    display: flex; gap: 6px;
}
.layout-btn {
    flex: 1; padding: 4px 6px; border: 2px solid #000000; background: #fff;
    font-weight: bold; cursor: pointer; font-size: 0.65rem;
    white-space: nowrap;
}
.layout-btn.active {
    background: #000000; color: #fff;
}

/* --- DASHBOARD --- */
#dashboard-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: #ffffff;
    display: flex; justify-content: center; align-items: center;
    z-index: 100; padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
    transition: opacity 0.3s ease;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
}

.menu-card {
    background: #ffffff;
    border: 4px solid #000000;
    box-shadow: 12px 12px 0px #000000;
    width: 100%; max-width: 440px;
    padding: 25px;
    text-align: center;
    display: flex; flex-direction: column; gap: 15px;
}

.btn-home {
    align-self: flex-start;
    background: #ffffff;
    color: #000000;
    border: 3px solid #000000;
    padding: 6px 12px;
    font-size: 0.85rem;
    font-weight: bold;
    text-decoration: none;
    cursor: pointer;
    box-shadow: 4px 4px 0px #000000;
    transition: transform 0.1s, box-shadow 0.1s;
}

.btn-home:hover {
    transform: translate(2px, 2px);
    box-shadow: 2px 2px 0px #000000;
}

.game-title {
    font-size: 2.5rem;
    font-weight: 900;
    line-height: 1;
    letter-spacing: -1px;
}

.input-group {
    display: flex; flex-direction: column; gap: 6px; text-align: left;
}

.input-group input {
    background: #ffffff; border: 3px solid #000000;
    padding: 10px; font-size: 1.1rem; font-weight: bold; outline: none; width: 100%;
}

.info-box {
    background: #f5f5f5; border: 2px dashed #000000;
    padding: 10px; font-size: 0.8rem; text-align: left; line-height: 1.4;
}

.btn-start {
    background: #000000; color: #ffffff; border: none;
    padding: 14px; font-size: 1.2rem; font-weight: 900; cursor: pointer;
    box-shadow: 6px 6px 0px #888888;
}

.btn-fullscreen {
    display: none;
    background: #ffffff; color: #000000; border: 3px solid #000000;
    padding: 12px; font-size: 0.9rem; font-weight: 900; cursor: pointer;
}

.ios-fullscreen-note {
    display: none;
    font-size: 0.68rem;
    line-height: 1.35;
    text-align: left;
    border-left: 3px solid #000000;
    padding-left: 8px;
}

/* --- INTERFACCIA HUD --- */
#hud {
    position: absolute; top: 20px; left: 20px;
    background: #ffffff; padding: 12px 20px;
    border: 3px solid #000000; box-shadow: 5px 5px 0px #000000;
    z-index: 10; display: none;
}

.audio-ctrl {
    margin-top: 8px; border-top: 1px dashed #000000; padding-top: 6px;
    pointer-events: auto; cursor: pointer; font-size: 0.8rem; font-weight: bold;
}

#leaderboard {
    position: fixed; top: 184px; right: 20px;
    background: #ffffff; padding: 15px;
    border: 3px solid #000000; box-shadow: 5px 5px 0px #000000;
    width: 220px; pointer-events: auto; z-index: 20; display: none;
}

#leaderboard h2 {
    font-size: 1rem; text-align: center; margin-bottom: 10px;
    border-bottom: 2px solid #000000; text-transform: uppercase;
}

.lb-entry { display: flex; justify-content: space-between; font-size: 0.85rem; font-weight: bold; padding: 4px 0; }
.lb-player { text-decoration: underline; font-weight: 900; }

#leaderboard-toggle {
    display: none; background: #000000; color: #ffffff; border: 0;
    font: bold 1rem 'Courier New', monospace; cursor: pointer;
}
#leaderboard.is-collapsed { width: 38px; height: 42px; padding: 0; }
#leaderboard.is-collapsed h2, #leaderboard.is-collapsed #lb-rows { display: none; }
#leaderboard.is-collapsed #leaderboard-toggle { display: block; width: 100%; height: 100%; }

/* Tracciamento dell'arena: sempre visibile, pulito e separato dalla classifica. */
#minimap-panel {
    position: fixed; top: 20px; right: 20px; z-index: 20;
    width: 148px; padding: 6px; background: #ffffff;
    border: 3px solid #000000; box-shadow: 5px 5px 0 #000000; display: none;
}
#minimap { width: 132px; height: 132px; display: block; }
#minimap-panel span { display: block; margin-top: 4px; text-align: center; font-size: 0.68rem; font-weight: bold; letter-spacing: 1px; }

/* --- GAME OVER SCREEN --- */
#game-over-screen {
    position: absolute; display: none; flex-direction: column;
    align-items: center; justify-content: center;
    background: rgba(255, 255, 255, 0.95);
    top: 0; left: 0; width: 100%; height: 100%; z-index: 120;
    gap: 15px;
}

#game-over-screen h2 { font-size: 2.5rem; font-weight: 900; margin-bottom: 5px; }

.game-over-actions {
    display: flex; gap: 15px;
}

#btn-restart {
    background: #000000; color: #ffffff; border: none;
    padding: 12px 30px; font-size: 1rem; font-weight: bold; cursor: pointer;
    box-shadow: 5px 5px 0px #888888;
}

/* --- COMANDI TOUCH ON-SCREEN --- */
.touch-zone {
    position: absolute; bottom: 30px; z-index: 90; display: none;
}
#joystick-container {
    width: 100px; height: 100px; background: rgba(0,0,0,0.05);
    border: 4px solid #000000; border-radius: 50%;
    justify-content: center; align-items: center;
}
#joystick-knob {
    width: 40px; height: 40px; background: #000000; border-radius: 50%;
    position: relative;
}
#turbo-btn {
    width: 80px; height: 80px; background: #ffffff;
    border: 4px solid #000000; border-radius: 50%;
    box-shadow: 4px 4px 0px #000000;
    font-weight: 900; font-size: 1.1rem;
    justify-content: center; align-items: center;
}

canvas { display: block; background-color: #ffffff; }

/* Schermi touch: bersagli più grandi e HUD che non copre l'arena. */
@media (pointer: coarse) and (orientation: landscape) {
    #hud { top: 10px; left: 10px; padding: 8px 11px; font-size: 0.75rem; }
    #hud h2 { font-size: 0.8rem; }
    #minimap-panel { top: max(10px, env(safe-area-inset-top)); right: max(10px, env(safe-area-inset-right)); width: 122px; }
    #minimap { width: 106px; height: 106px; }
    #leaderboard { top: calc(max(10px, env(safe-area-inset-top)) + 138px); right: max(10px, env(safe-area-inset-right)); }
    .touch-zone { bottom: max(18px, env(safe-area-inset-bottom)); }
    #joystick-container { width: 132px; height: 132px; border-width: 4px; }
    #joystick-knob { width: 52px; height: 52px; }
    #turbo-btn { width: 96px; height: 96px; font-size: 1rem; }
    .btn-fullscreen { display: block; }
}

@media (max-height: 500px) and (orientation: landscape) {
    .controls-selector { top: 8px; right: 8px; }
    #dashboard-overlay { padding: 10px; }
    .menu-card { max-width: 560px; padding: 16px; gap: 9px; box-shadow: 7px 7px 0 #000; margin: auto; }
    .game-title { font-size: 1.8rem; }
    .info-box { font-size: 0.68rem; padding: 7px; }
    .btn-start { padding: 10px; font-size: 1rem; }
}

@media (pointer: coarse) {
    .controls-selector { display: none !important; }
    #dashboard-overlay { align-items: flex-start; }
    .menu-card { margin: auto; }
    .btn-fullscreen { display: block; }
    .ios-fullscreen-note { display: block; }
    .btn-start { min-height: 52px; }
}
