:root {
    --primary-color: #e74c3c; /* Rosso Tombola */
    --secondary-color: #2c3e50;
    --bg-color: #f4f4f4;
    --board-bg: #fff;
    --highlight: #f1c40f;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-color);
    margin: 0;
    padding: 0;
    text-align: center;
    height: 100vh;
    height: 100dvh; /* Adatta l'altezza alle barre di sistema mobile */
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

header {
    background-color: var(--secondary-color);
    color: white;
    padding: 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
}

.header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

header h1 {
    margin: 0; /* Rimuove margini default per risparmiare spazio */
    font-size: 1.5rem;
}

.hamburger {
    display: none; /* Nascosto su desktop */
    background: transparent;
    border: 1px solid white;
    color: white;
    font-size: 1.2rem;
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
}

nav button {
    background: transparent;
    border: 1px solid white;
    color: white;
    padding: 8px 16px;
    margin: 0 5px;
    cursor: pointer;
    border-radius: 4px;
}

nav button.active {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

main {
    padding: 10px;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    box-sizing: border-box;
    flex: 1;
    overflow-y: auto; /* Abilita lo scorrimento verticale */
    min-height: 0; /* Impedisce al flex item di espandersi oltre il contenitore padre */
}

.view {
    display: none;
    height: 100%;
}

.view.active {
    display: flex;
    flex-direction: column;
}

/* Controlli */
.controls {
    margin-bottom: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.btn-action {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 10px 20px;
    font-size: 1.2rem;
    cursor: pointer;
    border-radius: 5px;
}

.btn-secondary {
    background-color: #95a5a6;
    color: white;
    border: none;
    padding: 10px 20px;
    cursor: pointer;
    border-radius: 5px;
}

/* Tabellone */
.last-extracted {
    font-size: 1.2rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 10px;
}

#current-number {
    font-size: 2rem;
    color: var(--primary-color);
    background: white;
    padding: 5px 15px;
    border-radius: 50%;
    border: 2px solid var(--primary-color);
    min-width: 40px;
}

.history-section {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 10px;
}

#extraction-history {
    display: flex;
    gap: 5px;
    min-height: 30px; /* Mantiene l'altezza anche se vuoto */
}

.history-num {
    background-color: #ddd;
    color: var(--secondary-color);
    padding: 5px 10px;
    border-radius: 4px;
    font-weight: bold;
    width: 30px;      /* Dimensione fissa */
    height: 30px;     /* Dimensione fissa */
    display: flex;    /* Centra il contenuto */
    align-items: center;
    justify-content: center;
}

.board-grid {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    grid-template-rows: repeat(9, 1fr);
    gap: 5px;
    background: var(--board-bg);
    padding: 15px;
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    flex: 1;
    min-height: 0;
}

.number-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-weight: bold;
    font-size: 1.1rem;
}

.number-cell.extracted {
    background-color: var(--primary-color);
    color: white;
}

/* Cartelle */
#view-cartelle {
    overflow-y: auto;
}

.cards-wrapper {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 20px;
}

.tombola-card {
    background: white;
    border: 2px solid var(--secondary-color);
    border-radius: 8px;
    padding: 10px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.card-header h3 {
    margin: 0;
    font-size: 1rem;
}

.win-label {
    font-weight: bold;
    color: var(--primary-color);
    font-size: 1.1rem;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 2px;
    background-color: #ccc; /* Bordi interni */
    border: 1px solid #ccc;
}

.card-cell {
    background-color: white;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    cursor: pointer;
    user-select: none;
}

.card-cell.empty {
    background-color: #f9f9f9;
}

.card-cell.marked {
    background-color: var(--highlight); /* Fagiolo/Segnalino */
    border-radius: 50%;
    width: 30px;
    height: 30px;
    margin: 5px auto; /* Centra il cerchio nella cella */
}

a {
    color: var(--primary-color);
    text-decoration: none;
    cursor: pointer;
}

a:hover {
    text-decoration: none;
}

/* Intro */
.intro-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
}

.intro-actions {
    margin-top: 30px;
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    justify-content: center;
}

/* Footer */
footer {
    background-color: var(--secondary-color);
    color: white;
    padding: 10px;
    text-align: center;
    font-size: 0.9rem;
    padding-bottom: calc(10px + env(safe-area-inset-bottom)); /* Spazio per barre gesture */
    flex-shrink: 0; /* Evita che il footer venga schiacciato */
}

/* Responsive */
@media (max-width: 600px) {
    body {
        height: auto;
        min-height: 100dvh;
        overflow-y: auto; /* Ripristina lo scroll nativo per permettere il refresh */
    }

    header {
        padding: 0.5rem; /* Header più compatto */
    }

    .header-top {
        width: 100%;
    }

    header h1 {
        font-size: 1.2rem; /* Titolo più piccolo */
    }

    .hamburger {
        display: block; /* Mostra hamburger */
    }

    #main-nav {
        display: none; /* Nascondi menu di default */
        width: 100%;
        flex-direction: column;
        margin-top: 10px;
    }

    #main-nav.open {
        display: flex; /* Mostra menu quando aperto */
    }

    nav button {
        margin: 5px 0;
        width: 100%;
        display: block;
    }

    main {
        overflow-y: visible; /* Rimuove lo scroll interno, lasciando espandere il contenuto */
    }

    .board-grid {
        grid-template-columns: repeat(5, 1fr); /* 5 colonne su mobile */
        grid-template-rows: auto; /* Altezza automatica per permettere lo scroll */
        flex: none; /* Rimuove il vincolo di adattamento altezza su mobile */
    }
    
    .card-cell {
        font-size: 0.8rem;
        height: 30px;
    }
    
    .card-cell.marked {
        width: 24px;
        height: 24px;
        margin: 3px auto;
    }
}

/* Flash Overlay (Numero a tutto schermo) */
.flash-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9); /* Sfondo scuro semitrasparente */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000; /* Sopra a tutto */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.5s ease-out, visibility 0.5s; /* Effetto fadeout */
    pointer-events: none;
}

.flash-overlay.active {
    opacity: 1;
    visibility: visible;
    transition: none; /* Appare istantaneamente */
    pointer-events: auto;
}

#flash-number {
    font-size: 15rem; /* Numero gigante */
    font-weight: bold;
    color: var(--primary-color);
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
}

@media (max-width: 600px) {
    #flash-number {
        font-size: 8rem; /* Ridimensiona su mobile */
    }
}
