:root {
    --bg-color: #111;
    --black: #000;
    --white: #fff;
    --red: #ff0000;
    --green: #00ff00;
    --yellow: #ffff00;
    --blue: #0000ff;
    --magenta: #ff00ff;
    --cyan: #00ffff;
    --font-main: 'VT323', monospace;
    --font-block: 'Press Start 2P', cursive;
}

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

body {
    background-color: #050505;
    color: var(--white);
    font-family: var(--font-main);
    font-size: 24px;
    height: 100vh;
    display: flex;
    justify-content: center;
    overflow: hidden; /* Desktop: no scroll body, scroll inside main */
}

a { color: inherit; text-decoration: none; border-bottom: 1px solid transparent; }
a:hover { background-color: var(--white); color: var(--black); }
.link-item { cursor: pointer; text-decoration: underline; }
.link-item:hover { background: var(--white); color: var(--black); }

.teletext-wrapper {
    width: 100%;
    max-width: 900px;
    height: 100vh;
    background-color: var(--black);
    display: flex;
    flex-direction: column;
    padding: 0 20px;
    position: relative;
    z-index: 10;
}

/* UTILS */
.white-text { color: var(--white); }
.yellow-text { color: var(--yellow); }
.cyan-text { color: var(--cyan); }
.red-text { color: var(--red); }
.green-text { color: var(--green); }
.black-text { color: var(--black); }
.magenta-text { color: var(--magenta); }

.bg-blue { background-color: var(--blue); }
.bg-red { background-color: var(--red); }
.bg-green { background-color: var(--green); }
.bg-yellow { background-color: var(--yellow); }
.bg-magenta { background-color: var(--magenta); }

.right { float: right; }
.text-center { text-align: center; }

/* HEADER */
.top-header {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    font-size: 1.5rem;
    border-bottom: 2px solid var(--white);
    margin-bottom: 20px;
    font-family: var(--font-main);
}

/* MAIN */
#screen-content { 
    flex-grow: 1; 
    overflow-y: auto; 
    scrollbar-width: none; 
    scroll-behavior: smooth; 
    padding-bottom: 40px; 
}
.page { display: none; padding-bottom: 40px; }
.page.active { display: block; }

/* FOTO STATICHE */
.hero-faces-row {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 30px;
    padding: 20px 0;
    border-top: 2px solid var(--blue);
}

.pixel-face-img {
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    height: 150px;
    width: auto;
    border: 2px solid #222;
}

/* TITOLO PIXEL ART */
.pixel-font-title {
    font-family: var(--font-block);
    font-size: 3.5rem;
    letter-spacing: -2px;
    margin-bottom: 10px;
    line-height: 1;
}

/* LINKS LISTS */
.info-box { border: 2px solid var(--blue); padding: 10px; margin-bottom: 20px; background: #000033; }
.news-item { padding: 5px 0; border-bottom: 1px dotted #333; cursor: pointer; }
.news-item:hover { background: var(--blue); }
.portfolio-block { margin-bottom: 20px; border-left: 2px solid #333; padding-left: 10px; }

/* GAMES */
.game-select-btn {
    width: 100%; background: transparent; border: 2px solid var(--green);
    color: var(--green); padding: 15px; font-family: var(--font-main);
    font-size: 1.5rem; text-align: left; margin-bottom: 10px; cursor: pointer;
}
.game-select-btn:hover { background: var(--green); color: var(--black); }
#game-area { border: 4px solid var(--white); background: #000; margin-top: 10px; margin-bottom: 50px;}
canvas { display: block; width: 100%; background: #000; }
.game-header { display: flex; justify-content: space-between; padding: 5px; background: #fff; color: #000; }
.game-stats { font-weight: bold; }
.controls-info { text-align: center; font-size: 0.9rem; margin-top: 5px; }

/* POPUP GAME OVER */
#game-msg-overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.8);
    display: flex; justify-content: center; align-items: center;
    z-index: 50;
}
.game-msg-box {
    background: #000;
    border: 4px solid #fff;
    padding: 20px;
    text-align: center;
    font-family: var(--font-block);
    box-shadow: 10px 10px 0px rgba(0,0,0,0.5);
    width: 80%;
}

/* CONTROLLI TOUCH (Default nascosti) */
#mobile-controls {
    display: none; 
    margin-top: 20px;
    text-align: center;
    padding-bottom: 20px;
}
.controls-wrapper {
    display: flex;
    justify-content: space-around;
    align-items: center;
    width: 100%;
    max-width: 400px;
    margin: 0 auto;
}
.d-pad { display: inline-block; vertical-align: middle; }
.d-row { display: flex; justify-content: center; gap: 10px; margin: 10px 0; }
.d-btn { 
    width: 60px; height: 60px; 
    background: #222; border: 2px solid #fff; 
    color: #fff; font-size: 24px; 
    touch-action: manipulation; /* Evita zoom al doppio tocco */
    border-radius: 8px;
}
.d-btn:active { background: #555; transform: scale(0.95); }
.action-game-btn { 
    width: 80px; height: 80px; 
    border-radius: 50%; background: #f00; 
    border: 4px solid #fff; color: #fff; 
    font-size: 24px; vertical-align: middle; 
    touch-action: manipulation;
}
.action-game-btn:active { background: #900; transform: scale(0.95); }

/* CASINO */
.casino-machine { border: 2px solid #333; padding: 15px; margin-bottom: 20px; text-align: center; }
.roulette-display { display: flex; justify-content: center; align-items: center; height: 100px; background: #000; border: 4px solid var(--red); margin: 20px 0; }
.wheel-anim { font-family: var(--font-block); font-size: 3rem; color: var(--white); }
.slot-window { font-size: 3rem; font-family: var(--font-block); margin: 20px 0; color: var(--yellow); text-shadow: 2px 2px var(--red); letter-spacing: 20px; text-align: center; }
.spin-btn { width: 100%; border: none; padding: 15px; font-family: var(--font-main); font-size: 1.5rem; color: var(--white); cursor: pointer; }
.spin-btn:disabled { opacity: 0.5; cursor: wait; }

/* FOOTER */
.fastext-bar { display: flex; gap: 10px; padding: 20px 0; margin-top: auto; border-top: 2px solid #333; }
.fastext-btn { flex: 1; border: none; padding: 10px 0; font-family: var(--font-main); font-size: 1.2rem; font-weight: bold; cursor: pointer; color: var(--white); text-align: center; }
.red-btn { background: var(--red); }
.green-btn { background: var(--green); color: var(--black); }
.cyan-btn { background: var(--cyan); color: var(--black); }
.yellow-btn { background: var(--yellow); color: var(--black); }

/* MODAL IMAGES */
#img-modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.9); z-index: 2000;
    display: flex; justify-content: center; align-items: center;
}
.modal-wrapper {
    background: black; border: 2px solid white; max-width: 90%; max-height: 90%;
    display: flex; flex-direction: column; padding: 10px;
}
.modal-header { display: flex; justify-content: space-between; margin-bottom: 10px; border-bottom: 1px dashed #555; padding-bottom: 5px;}
.modal-img-container img { max-width: 100%; max-height: 70vh; display: block; margin: 0 auto; border: 1px solid #333; }
.modal-footer { margin-top: 10px; display: flex; justify-content: space-between; align-items: center; border-top: 1px dashed #555; padding-top: 10px;}
.action-btn { background: transparent; border: 1px solid white; color: white; padding: 5px 10px; cursor: pointer; font-family: var(--font-main); font-size: 1.2rem; margin-right: 10px;}
.action-btn:hover { background: #333; }
.close-btn-x { background: red; color: white; border: none; padding: 0 10px; font-weight: bold; cursor: pointer; }
.heart { color: red; }

/* ANIMAZIONI & EFFETTI SPECIALI */
.blinking-slow { animation: blink 2s infinite; }
@keyframes blink { 50% { opacity: 0; } }
.crt-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: repeating-linear-gradient(rgba(0,0,0,0.1) 0, transparent 1px, transparent 3px); pointer-events: none; z-index: 99; }
.hidden { display: none !important; }

/* GRAVITA' REALISTICA */
.crashing {
    animation: dropToFloor 0.5s cubic-bezier(0.8, 0, 1, 1) forwards;
}
@keyframes dropToFloor { 0% { transform: translateY(0); } 100% { transform: translateY(110vh); } }

/* GLITCH SERIO */
#signal-noise {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI1IiBoZWlnaHQ9IjUiPgo8cmVjdCB3aWR0aD0iNSIgaGVpZ2h0PSI1IiBmaWxsPSIjZmZmIiBmaWxsLW9wYWNpdHk9IjAuMSIvPgo8L3N2Zz4=');
    background-color: #111; opacity: 0.8; z-index: 1000; pointer-events: none;
    animation: staticNoise 0.05s infinite;
}
@keyframes staticNoise { 0% { transform: translate(0,0); } 100% { transform: translate(5px,5px); } }

/* TV OFF */
#tv-off-effect {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: #000; z-index: 1100;
    animation: turnOff 0.4s cubic-bezier(0.23, 1, 0.32, 1) forwards;
}
@keyframes turnOff {
    0% { transform: scale(1, 1.3); opacity: 0; background: #fff;}
    60% { transform: scale(1, 0.002); opacity: 1; background: #fff;}
    100% { transform: scale(0, 0); opacity: 1; background: #fff;}
}

/* COUNTDOWN OVERLAY */
#destruct-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    display: flex; justify-content: center; align-items: center;
    font-family: var(--font-block); font-size: 15rem;
    color: red; text-shadow: 5px 5px 0px black; z-index: 500;
}

/* --- MOBILE RESPONSIVENESS CRITICA --- */
@media (max-width: 768px) {
    /* Reset scroll body */
    body {
        font-size: 18px; 
        overflow-y: scroll; /* Permette lo scroll nativo */
        display: block; /* Toglie il flex center che rompe lo scroll */
        height: auto;
    }

    .teletext-wrapper {
        width: 100%;
        max-width: 100%;
        height: auto; /* Adatta l'altezza al contenuto */
        min-height: 100vh;
        overflow: visible; /* Lascia scrollare */
        padding-bottom: 120px; /* SPAZIO CRUCIALE PER I TASTI FISSI IN BASSO */
    }

    #screen-content {
        overflow: visible; /* Disabilita lo scroll interno, usa quello del body */
    }

    /* BARRA MENU FISSA IN BASSO (OVERLAY) */
    .fastext-bar {
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 70px;
        background: #000;
        z-index: 9999; /* DEVE ESSERE SOPRA TUTTO */
        border-top: 4px solid #fff;
        padding: 5px;
        box-shadow: 0px -5px 10px rgba(0,0,0,0.8);
    }

    .fastext-btn {
        font-size: 1rem;
        padding: 15px 0;
    }

    /* Adattamento Giochi */
    #game-area {
        margin-bottom: 20px;
    }
    
    canvas {
        max-width: 100%; /* Impedisce al gioco di uscire dallo schermo */
        height: auto;
    }

    /* Mostra i controlli quando serve */
    #mobile-controls {
        display: none; /* JS lo cambierà in block */
    }

    .hero-faces-row {
        flex-direction: column;
        align-items: center;
    }
}