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

:root {
    --christmas-red: #c41e3a;
    --christmas-green: #0f8558;
    --christmas-gold: #ffd700;
    --snow-white: #ffffff;
    --dark-bg: #1a1a2e;
    --light-bg: #f5f5f5;
    --extracted-color: #e74c3c;
    --covered-color: #27ae60;
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, var(--christmas-red) 0%, var(--christmas-green) 100%);
    min-height: 100vh;
    color: #333;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

.hidden {
    display: none !important;
}

/* LANDING PAGE */
.landing {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.landing-content {
    text-align: center;
    background: white;
    padding: 60px 40px;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.landing-content h1 {
    font-size: 3em;
    color: var(--christmas-red);
    margin-bottom: 10px;
}

.subtitle {
    font-size: 1.2em;
    color: #666;
    margin-bottom: 40px;
}

.options {
    display: flex;
    gap: 30px;
    justify-content: center;
    flex-wrap: wrap;
}

.option-card {
    background: var(--light-bg);
    padding: 30px;
    border-radius: 15px;
    min-width: 250px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s;
}

.option-card:hover {
    transform: translateY(-5px);
}

.option-card h2 {
    color: var(--christmas-green);
    margin-bottom: 10px;
    font-size: 1.8em;
}

.option-card p {
    color: #666;
    margin-bottom: 20px;
}

/* BUTTONS */
.btn {
    padding: 12px 30px;
    border: none;
    border-radius: 8px;
    font-size: 1em;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    transition: all 0.3s;
    font-weight: bold;
}

.btn-primary {
    background: var(--christmas-red);
    color: white;
}

.btn-primary:hover {
    background: #a01729;
    transform: scale(1.05);
}

.btn-secondary {
    background: var(--christmas-green);
    color: white;
}

.btn-secondary:hover {
    background: #0c6b47;
    transform: scale(1.05);
}

.btn-danger {
    background: #e74c3c;
    color: white;
}

.btn-danger:hover {
    background: #c0392b;
}

.btn-small {
    padding: 8px 16px;
    font-size: 0.9em;
}

.btn-large {
    padding: 20px 50px;
    font-size: 1.3em;
}

/* LOGIN SCREEN */
.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.login-box {
    background: white;
    padding: 50px;
    border-radius: 15px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    text-align: center;
    min-width: 400px;
}

.login-box h1 {
    color: var(--christmas-red);
    margin-bottom: 10px;
}

.login-box p {
    color: #666;
    margin-bottom: 30px;
}

#login-form input {
    width: 100%;
    padding: 15px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 1em;
    margin-bottom: 20px;
}

#login-form input:focus {
    outline: none;
    border-color: var(--christmas-red);
}

.error-message {
    color: var(--extracted-color);
    margin-top: 10px;
    font-size: 0.9em;
}

/* HEADER */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: white;
    padding: 20px 30px;
    border-radius: 15px;
    margin-bottom: 20px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.header h1 {
    color: var(--christmas-red);
    font-size: 2em;
}

/* CARTELLONE - 3 Column Layout */
.cartellone-screen {
    background: none;
    height: 100vh;
    overflow: hidden;
    padding: 0;
    box-sizing: border-box;
}

.cartellone-layout {
    display: grid;
    grid-template-columns: 200px 1fr 220px;
    gap: 10px;
    height: 100vh;
    padding: 10px;
    box-sizing: border-box;
}

/* LEFT COLUMN */
.left-column {
    background: white;
    border-radius: 15px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    overflow-y: auto;
}

.header-left {
    text-align: center;
}

.header-left h1 {
    color: var(--christmas-red);
    font-size: 1.5em;
    margin-bottom: 10px;
}

.current-number {
    text-align: center;
}

.number-display {
    background: var(--christmas-gold);
    color: var(--dark-bg);
    font-size: 3.5em;
    font-weight: bold;
    padding: 15px;
    border-radius: 15px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
}

.current-number p {
    margin-top: 8px;
    color: #666;
    font-weight: bold;
    font-size: 0.85em;
}

.control-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.control-buttons .btn {
    width: 100%;
    padding: 12px;
    font-size: 1em;
}

.btn-reset {
    margin-top: auto;
    padding: 8px 12px;
    font-size: 0.85em;
    width: 100%;
}

.stats {
    text-align: center;
    background: var(--light-bg);
    padding: 15px;
    border-radius: 10px;
}

.stats p {
    font-size: 0.9em;
    color: #666;
    margin: 5px 0;
}

.stats-number {
    font-size: 1.8em !important;
    color: var(--christmas-red) !important;
    font-weight: bold !important;
}

.stats span {
    color: var(--christmas-red);
    font-size: 1.5em;
}

.size-control {
    background: var(--light-bg);
    padding: 12px;
    border-radius: 10px;
    text-align: center;
}

.size-label {
    display: block;
    margin-bottom: 8px;
}

.size-text {
    font-size: 0.85em;
    color: #666;
    font-weight: bold;
}

.size-slider {
    width: 100%;
    height: 6px;
    border-radius: 5px;
    background: #ddd;
    outline: none;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
}

.size-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--christmas-red);
    cursor: pointer;
    transition: all 0.3s;
}

.size-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    background: var(--christmas-green);
}

.size-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--christmas-red);
    cursor: pointer;
    border: none;
    transition: all 0.3s;
}

.size-slider::-moz-range-thumb:hover {
    transform: scale(1.2);
    background: var(--christmas-green);
}

.size-value {
    margin-top: 8px;
    font-size: 0.9em;
    font-weight: bold;
    color: var(--christmas-red);
}

.duration-control {
    background: var(--light-bg);
    padding: 12px;
    border-radius: 10px;
    text-align: center;
}

.duration-label {
    display: block;
    margin-bottom: 8px;
}

.duration-text {
    font-size: 0.85em;
    color: #666;
    font-weight: bold;
}

.duration-slider {
    width: 100%;
    height: 6px;
    border-radius: 5px;
    background: #ddd;
    outline: none;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
}

.duration-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--christmas-green);
    cursor: pointer;
    transition: all 0.3s;
}

.duration-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    background: var(--christmas-red);
}

.duration-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--christmas-green);
    cursor: pointer;
    border: none;
    transition: all 0.3s;
}

.duration-slider::-moz-range-thumb:hover {
    transform: scale(1.2);
    background: var(--christmas-red);
}

.duration-value {
    margin-top: 8px;
    font-size: 0.9em;
    font-weight: bold;
    color: var(--christmas-green);
}

/* CENTER COLUMN - Board Grid */
.center-column {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 20px;
}

.board-grid {
    display: grid;
    grid-template-columns: repeat(10, var(--cell-size, 1fr));
    grid-template-rows: repeat(9, var(--cell-size, 1fr));
    gap: var(--board-gap, 4px);
    background: white;
    padding: 10px;
    border-radius: 15px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    width: fit-content;
    height: fit-content;
    transition: all 0.3s ease;
}

.board-number {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--board-font-size, 1em);
    font-weight: bold;
    border-radius: var(--board-border-radius, 5px);
    background: var(--light-bg);
    color: #333;
    transition: all 0.3s;
    border: 2px solid transparent;
}

.board-number.extracted {
    background: var(--extracted-color);
    color: white;
    transform: scale(1.05);
    border-color: #c0392b;
}

.board-number.highlight {
    background: var(--christmas-gold);
    color: var(--dark-bg);
    transform: scale(1.15);
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.8);
    animation: pulse-glow 0.3s ease-in-out;
}

@keyframes pulse-glow {
    0%, 100% { transform: scale(1.15); }
    50% { transform: scale(1.25); }
}

/* RIGHT COLUMN */
.right-column {
    background: white;
    border-radius: 15px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.last-number-section {
    text-align: center;
    padding-bottom: 15px;
    border-bottom: 2px solid var(--light-bg);
}

.last-number-section h3 {
    color: var(--christmas-green);
    margin-bottom: 10px;
    font-size: 0.95em;
}

.last-number-display {
    background: var(--christmas-gold);
    color: var(--dark-bg);
    font-size: 2.5em;
    font-weight: bold;
    padding: 15px;
    border-radius: 12px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    min-height: 70px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.history-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.history-section h3 {
    color: var(--christmas-green);
    margin-bottom: 10px;
    font-size: 0.9em;
    text-align: center;
}

.history-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.history-number {
    background: var(--extracted-color);
    color: white;
    padding: 8px;
    border-radius: 8px;
    font-weight: bold;
    font-size: 1.1em;
    text-align: center;
}

.qr-section {
    text-align: center;
    padding-top: 15px;
    border-top: 2px solid var(--light-bg);
}

.qr-section h3 {
    color: var(--christmas-green);
    margin-bottom: 10px;
    font-size: 0.95em;
}

.qr-code {
    background: white;
    padding: 10px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 8px;
}

.qr-code img {
    max-width: 100%;
    height: auto;
    border-radius: 5px;
}

.qr-label {
    font-size: 0.8em;
    color: #666;
    margin: 0;
}

/* CARTELLA - Ottimizzata per smartphone orizzontale senza scroll */
.cartella-screen {
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 10px;
    box-sizing: border-box;
}

.cartella-screen .header {
    flex-shrink: 0;
    padding: 8px 15px;
    margin-bottom: 8px;
}

.cartella-screen .header h1 {
    font-size: 1.3em;
}

.card-info {
    background: white;
    padding: 8px;
    border-radius: 10px;
    text-align: center;
    margin-bottom: 8px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

.card-info p {
    font-size: 0.9em;
    color: #666;
    margin: 0;
}

.card-info span {
    color: var(--christmas-red);
    font-weight: bold;
}

.generation-time {
    font-size: 0.8em;
    color: #888;
    margin-top: 4px;
}

.generation-time span {
    color: var(--christmas-green);
}

/* Achievement Notification */
.achievement-notification {
    background: linear-gradient(135deg, var(--christmas-gold), #ffed4e);
    color: var(--dark-bg);
    padding: 15px 30px;
    border-radius: 12px;
    text-align: center;
    font-size: 1.2em;
    font-weight: bold;
    box-shadow: 0 8px 25px rgba(255, 215, 0, 0.5);
    margin-bottom: 10px;
    animation: slideDown 0.5s ease-out, pulse 0.5s ease-in-out 0.5s 3;
    border: 3px solid var(--christmas-red);
}

.achievement-notification.hidden {
    display: none;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

.cartella-grid {
    background: white;
    padding: 15px;
    border-radius: 15px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 8px;
    flex-grow: 1;
    height: 0;
}

.cartella-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1.2em, 3vw, 2em);
    font-weight: bold;
    border-radius: 8px;
    background: var(--light-bg);
    color: #333;
    cursor: pointer;
    transition: all 0.3s;
    border: 3px solid transparent;
    position: relative;
}

.cartella-cell:not(.empty):hover {
    background: #e0e0e0;
    transform: scale(1.05);
}

.cartella-cell.covered {
    background: var(--covered-color);
    color: white;
    border-color: #229954;
}

.cartella-cell.covered::after {
    content: '✓';
    position: absolute;
    font-size: 0.6em;
    top: 3px;
    right: 5px;
}

.cartella-cell.empty {
    background: transparent;
    cursor: default;
}

.instructions {
    background: white;
    padding: 10px;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
    margin-top: 8px;
}

.instructions h3 {
    color: var(--christmas-green);
    margin-bottom: 8px;
    text-align: center;
    font-size: 1em;
}

.instructions p {
    color: #666;
    margin: 3px 0;
    font-size: 0.85em;
}

/* RESPONSIVE */
@media (max-width: 1024px) {
    .board-grid {
        grid-template-columns: repeat(9, 1fr);
    }

    .number-display {
        font-size: 3.5em;
    }
}

@media (max-width: 768px) {
    .landing-content h1 {
        font-size: 2em;
    }

    .options {
        flex-direction: column;
    }

    .board-grid {
        grid-template-columns: repeat(6, 1fr);
    }

    .controls {
        flex-direction: column;
    }

    .cartella-grid {
        gap: 8px;
        padding: 20px;
    }

    .cartella-cell {
        font-size: 1.4em;
    }
}

@media (max-width: 480px) {
    .login-box {
        min-width: auto;
        padding: 30px 20px;
    }

    .board-grid {
        grid-template-columns: repeat(5, 1fr);
        gap: 5px;
    }

    .board-number {
        font-size: 1.2em;
    }
}

/* QR CODE MODAL */
.qr-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 20px;
    box-sizing: border-box;
}

.qr-modal-content {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 30px;
    max-width: 90vw;
    max-height: 90vh;
}

.qr-modal-credits {
    color: white;
    font-size: 1.1em;
    font-style: italic;
    text-align: center;
    margin: 0;
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    letter-spacing: 0.5px;
}

.qr-modal-close {
    position: absolute;
    top: -50px;
    right: -50px;
    background: white;
    color: #333;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 2em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.qr-modal-close:hover {
    background: var(--christmas-red);
    color: white;
    transform: scale(1.1);
}

.qr-modal-image {
    width: min(600px, 70vh, 70vw);
    height: min(600px, 70vh, 70vw);
    background: white;
    padding: 20px;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.qr-modal-link {
    color: white;
    font-size: 1.2em;
    text-align: center;
    word-break: break-all;
    background: rgba(255, 255, 255, 0.1);
    padding: 15px 30px;
    border-radius: 10px;
    max-width: 80vw;
}

.qr-code {
    cursor: pointer;
    transition: transform 0.3s;
}

.qr-code:hover {
    transform: scale(1.05);
}

@media (max-width: 768px) {
    .qr-modal-close {
        top: -40px;
        right: -20px;
        width: 35px;
        height: 35px;
        font-size: 1.5em;
    }

    .qr-modal-image {
        width: min(500px, 60vh, 80vw);
        height: min(500px, 60vh, 80vw);
        padding: 15px;
    }

    .qr-modal-link {
        font-size: 1em;
        padding: 12px 20px;
    }
}
