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

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

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(to bottom, #87CEEB 0%, #98D8C8 50%, #7FB069 100%);
    background-attachment: fixed;
    color: #fff;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    margin: 0;
    padding: 0;
    position: fixed;
    top: 0;
    left: 0;
}

#gameContainer {
    width: 100%;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height per mobile */
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(to bottom, #87CEEB 0%, #98D8C8 50%, #7FB069 100%);
}

.screen {
    width: 100%;
    height: 100%;
    height: 100dvh; /* Dynamic viewport height per mobile */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 10px;
    position: absolute;
    top: 0;
    left: 0;
    background: linear-gradient(to bottom, #87CEEB 0%, #98D8C8 50%, #7FB069 100%);
}

.screen.hidden {
    display: none;
}

h1 {
    font-size: 2.5em;
    margin-bottom: 8px;
    text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.8);
    color: #dc1e1e;
}

h2 {
    font-size: 2em;
    margin-bottom: 20px;
    color: #dc1e1e;
}

.chef-display {
    width: auto;
    max-width: 150px;
    max-height: 150px;
    margin-bottom: 10px;
    display: block;
    object-fit: contain;
}

.btn {
    background: linear-gradient(135deg, #dc1e1e 0%, #b01a1a 100%);
    color: white;
    border: none;
    padding: 15px 30px;
    font-size: 1.2em;
    font-weight: bold;
    border-radius: 25px;
    cursor: pointer;
    margin-top: 10px;
    box-shadow: 0 4px 15px rgba(220, 30, 30, 0.4);
    transition: transform 0.1s, box-shadow 0.1s;
    touch-action: manipulation;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    position: relative;
}

.btn:active,
.btn:focus {
    transform: scale(0.95);
    box-shadow: 0 2px 8px rgba(220, 30, 30, 0.3);
    outline: none;
}

.btn:hover {
    transform: scale(1.05);
}

.btn:hover {
    transform: scale(1.05);
}

#gameScreen {
    padding: 0;
    position: relative;
}

#hud {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 10px 15px;
    background: rgba(0, 0, 0, 0.7);
    font-size: 0.9em;
    z-index: 10;
    margin: 0;
}

#hud > div {
    flex: 1;
    text-align: center;
}

#gameCanvas {
    display: block;
    width: 100%;
    height: calc(100vh - 100px); /* Spazio per HUD (50px) + footer iniziale (50px) */
    max-height: 400px; /* Limita l'altezza per orientamento orizzontale */
    background: linear-gradient(to bottom, #87ceeb 0%, #98d8c8 50%, #7fb069 100%);
    touch-action: none;
    margin-top: 50px; /* Spazio per HUD fixed */
    transition: height 0.5s ease-out;
}

#controls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
    background: rgba(0, 0, 0, 0.5);
    width: 100%;
    min-height: 50px;
    transition: opacity 0.5s ease-out;
    opacity: 1;
    z-index: 10;
}

.control-btn {
    width: 60px;
    height: 60px;
    background: rgba(220, 30, 30, 0.8);
    color: white;
    border: 2px solid #fff;
    border-radius: 50%;
    font-size: 1.5em;
    font-weight: bold;
    cursor: pointer;
    touch-action: manipulation;
    user-select: none;
    transition: background 0.1s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
    position: relative;
}

.control-btn:active {
    background: rgba(220, 30, 30, 1);
    transform: scale(0.9);
}

.control-btn:focus {
    outline: none;
}

#codeBox {
    background: rgba(0, 0, 0, 0.8);
    border: 3px solid #dc1e1e;
    padding: 20px;
    margin: 20px auto;
    font-size: 2em;
    font-weight: bold;
    letter-spacing: 5px;
    color: #dc1e1e;
    border-radius: 10px;
    max-width: 300px;
}

#victoryScreen {
    gap: 10px;
}

#allCodes {
    margin: 0;
    padding: 10px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 10px;
    max-width: 90%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

#allCodes h3 {
    color: #dc1e1e;
    margin: 20px 0 15px 0;
    font-size: 1.5em;
}

.completion-badge {
    font-size: 1.5em;
    font-weight: bold;
    color: #ffd700;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    margin: 15px 0;
    padding: 10px;
    background: rgba(220, 30, 30, 0.2);
    border: 2px solid #ffd700;
    border-radius: 10px;
}

.codes-compact {
    margin: 15px 0;
    font-size: 1.1em;
    color: #dc1e1e;
    padding: 10px;
    background: rgba(220, 30, 30, 0.1);
    border-radius: 5px;
    text-align: center;
}

.codes-compact strong {
    color: #ffd700;
}

.code-sum-compact {
    margin: 10px 0;
    font-size: 1.2em;
    color: #ffd700;
    padding: 10px;
    background: rgba(220, 30, 30, 0.3);
    border: 2px solid #ffd700;
    border-radius: 8px;
    text-align: center;
}

.code-sum-compact strong {
    color: #ffd700;
}

#allCodes div:not(.completion-badge):not(.codes-compact):not(.code-sum-compact) {
    margin: 10px 0;
    font-size: 1.2em;
    color: #dc1e1e;
}

/* Schermo orientamento */
#orientationScreen {
    background: rgba(0, 0, 0, 0.9);
    z-index: 1000;
}

#orientationScreen h1 {
    font-size: 2em;
    margin-bottom: 30px;
}

#orientationScreen p {
    margin: 15px 0;
}

/* Guida */
#guideContent {
    max-width: 95%;
    width: 100%;
    margin: 0 auto;
    overflow-y: auto;
    max-height: calc(100vh - 40px);
    display: flex;
    flex-direction: column;
    padding: 10px;
}

.guide-section {
    margin-bottom: 15px;
    background: rgba(0, 0, 0, 0.8);
    padding: 15px 20px;
    border-radius: 15px;
    border: 3px solid rgba(220, 30, 30, 0.5);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.guide-section h1 {
    font-size: 1.8em;
    margin-bottom: 10px;
}

.guide-section h3 {
    font-size: 1.1em;
    color: #dc1e1e;
    margin-bottom: 10px;
    margin-top: 15px;
    text-align: center;
}

.guide-section p {
    margin: 5px 0;
    line-height: 1.4;
    font-size: 0.85em;
}

.guide-items {
    display: flex;
    flex-wrap: nowrap;
    justify-content: center;
    gap: 15px;
    margin-top: 10px;
}

.guide-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    flex: 0 0 auto;
    min-width: 140px;
    max-width: 180px;
}

.guide-icon {
    width: 90px;
    height: 90px;
    padding: 12px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    margin-bottom: 8px;
    border: 3px solid rgba(220, 30, 30, 0.6);
    border-radius: 12px;
    background-color: rgba(255, 255, 255, 0.15);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.guide-item p {
    font-size: 0.85em;
    margin: 0;
}

.guide-item strong {
    color: #dc1e1e;
    display: block;
    margin-bottom: 5px;
}

@media (max-width: 480px) {
    h1 {
        font-size: 1.8em;
    }
    
    h2 {
        font-size: 1.5em;
    }
    
    .control-btn {
        width: 50px;
        height: 50px;
        font-size: 1.2em;
    }
    
    #hud {
        font-size: 0.8em;
    }
}

