/* =========================================
           LAYOUT BASE E DESKTOP
           ========================================= */
        .dashboard-container {
            display: flex;
            gap: 20px;
        }

        .sidebar {
            width: 300px;
            flex-shrink: 0;
            background: rgba(0, 0, 0, 0.3);
            border-right: 1px solid var(--border);
            padding: 25px 20px;
        }

        /* Bottone Hamburger (X di chiusura) dentro la sidebar - nascosto su PC */
        .mobile-toggle-btn {
            display: none;
            background: transparent;
            border: 1px solid var(--border);
            color: white;
            padding: 5px 10px;
            border-radius: 5px;
            cursor: pointer;
            font-size: 14px;
            transition: 0.2s;
        }

        .mobile-toggle-btn:hover {
            background: rgba(255, 255, 255, 0.1);
        }

        /* Tasto Fluttuante Rotondo per Mobile (Nascosto su PC) */
        .mobile-fab {
            display: none;
            position: fixed;
            bottom: 20px;
            right: 20px;
            width: 60px;
            height: 60px;
            background: var(--secondary);
            color: var(--primary);
            border-radius: 50%;
            font-size: 28px;
            border: none;
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.6);
            z-index: 9998;
            cursor: pointer;
            align-items: center;
            justify-content: center;
            transition: transform 0.2s;
        }

        .mobile-fab:active {
            transform: scale(0.9);
        }

        /* Controls for drop/DQ buttons in score modal */
        #modal_p1_name, #modal_p2_name {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            font-weight: 800;
            font-size: 16px;
            text-align: center;
            gap: 10px;
            padding: 12px;
            background: linear-gradient(135deg, rgba(255, 175, 38, 0.08) 0%, rgba(255, 175, 38, 0.04) 100%);
            border-radius: 12px;
            border: 1px solid rgba(255, 175, 38, 0.15);
        }

        .player-controls {
            display: flex;
            flex-direction: row;
            justify-content: center;
            align-items: center;
            gap: 8px;
            margin-bottom: 8px;
            flex-wrap: wrap;
        }

        .small-ghost {
            display: inline-block;
            padding: 10px 16px;
            border-radius: 8px;
            border: none;
            font-size: 11px;
            font-weight: 800;
            text-transform: uppercase;
            cursor: pointer;
            transition: all 0.2s ease;
            letter-spacing: 0.5px;
            text-align: center;
            white-space: nowrap;
            background: rgba(100, 150, 255, 0.15);
            color: #64b4ff;
            box-shadow: 0 2px 6px rgba(100, 150, 255, 0.2);
        }

        .small-ghost:hover {
            transform: translateY(-2px);
            filter: brightness(1.15);
            box-shadow: 0 4px 12px rgba(100, 150, 255, 0.35);
            background: rgba(100, 150, 255, 0.25);
        }

        .small-ghost:active {
            transform: translateY(0);
        }

        .small-ghost.danger {
            border: none;
            color: #fff;
            background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
            box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
        }

        .small-ghost.danger:hover {
            filter: brightness(1.1);
            box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
        }

        .small-ghost.drop {
            border: none;
            color: #000;
            background: linear-gradient(135deg, #ffaf26 0%, #f59e0b 100%);
            box-shadow: 0 2px 8px rgba(255, 175, 38, 0.4);
            font-weight: 900;
        }

        .small-ghost.drop:hover {
            filter: brightness(1.1);
            box-shadow: 0 4px 12px rgba(255, 175, 38, 0.5);
        }

        .small-ghost.secondary {
            border: 1px solid var(--secondary);
            color: var(--secondary);
            background: rgba(255, 175, 38, 0.1);
        }
        * {
            box-sizing: border-box;
            outline: none;
        }

        :root {
            --primary: #00012a;
            --secondary: #ffaf26;
            --card-bg: rgba(255, 255, 255, 0.05);
            --border: rgba(255, 255, 255, 0.1);
            --success: #4ade80;
            --danger: #ef4444;
        }

        body {
            margin: 0;
            font-family: 'Inter', sans-serif;
            background: var(--primary);
            color: white;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
        }

        .dashboard {
            display: flex;
            flex: 1;
            overflow: hidden;
        }

        .main-area {
            flex: 1;
            padding: 30px 40px;
            overflow-y: auto;
        }

        /* =========================================
           BOTTONI E NAVIGAZIONE
           ========================================= */
        .action-btn {
            width: 100%;
            padding: 12px;
            border-radius: 10px;
            font-weight: 800;
            border: none;
            cursor: pointer;
            margin-bottom: 12px;
            font-size: 13px;
            text-transform: uppercase;
            transition: 0.2s;
            letter-spacing: 0.5px;
            display: block;
            text-align: center;
        }

        .btn-green {
            background: var(--success);
            color: #000;
        }

        .btn-yellow {
            background: var(--secondary);
            color: var(--primary);
        }

        .btn-red {
            background: var(--danger);
            color: white;
        }

        .btn-outline {
            background: transparent;
            border: 1px solid var(--border);
            color: #fff;
        }

        .action-btn:disabled {
            opacity: 0.25;
            cursor: not-allowed;
        }

        .action-btn:hover:not(:disabled) {
            filter: brightness(1.1);
            transform: translateY(-2px);
        }

        .round-nav {
            display: flex;
            gap: 10px;
            overflow-x: auto;
            padding-bottom: 10px;
            margin-bottom: 20px;
        }

        .round-tab.disabled-nav {
            filter: grayscale(1);
            border-color: rgba(255, 255, 255, 0.1) !important;
        }

        .round-tab {
            padding: 8px 16px;
            border-radius: 8px;
            background: rgba(255, 255, 255, 0.05);
            color: white;
            text-decoration: none;
            font-weight: 800;
            font-size: 14px;
            border: 1px solid transparent;
            transition: 0.2s;
            white-space: nowrap;
        }

        .round-tab:hover {
            background: rgba(255, 255, 255, 0.1);
        }

        .round-tab.active {
            background: var(--secondary);
            color: var(--primary);
            border-color: var(--secondary);
        }

        .round-timer-banner {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            gap: 16px;
            margin: 30px auto 40px;
            padding: 30px 40px;
            border-radius: 20px;
            background: rgba(255, 175, 38, 0.1);
            border: 2px solid rgba(255, 175, 38, 0.3);
            font-size: 16px;
            color: #ffffff;
            max-width: 500px;
        }

        .round-timer-banner span {
            font-size: 13px;
            letter-spacing: 0.12em;
            text-transform: uppercase;
            opacity: 0.8;
            font-weight: 600;
        }

        .round-timer-banner strong {
            font-size: 56px;
            letter-spacing: 0.05em;
            font-weight: 900;
            color: var(--secondary);
        }

        .timer-controls-container {
            display: flex;
            gap: 8px;
            align-items: center;
            justify-content: center;
            width: 100%;
        }

        /* =========================================
           MATCH CARDS (DESKTOP)
           ========================================= */
        .match-card {
            background: var(--card-bg);
            border: 1px solid var(--border);
            border-radius: 12px;
            padding: 15px 20px;
            margin-bottom: 12px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            transition: 0.2s;
        }

        .match-card.clickable {
            cursor: pointer;
        }

        .match-card.clickable:hover {
            border-color: var(--secondary);
            background: rgba(255, 175, 38, 0.05);
        }

        .match-card.finished {
            border-color: var(--success);
            background: rgba(74, 222, 128, 0.03);
            opacity: 0.8;
        }

        .match-card.draft-mode {
            border-style: dashed;
            opacity: 0.6;
        }

        .match-card.conflict {
            border-color: var(--danger);
            background: rgba(239, 68, 68, 0.05);
            animation: pulse 2s infinite;
        }

        @keyframes pulse {
            0% {
                box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
            }

            70% {
                box-shadow: 0 0 0 10px rgba(239, 68, 68, 0);
            }

            100% {
                box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
            }
        }

        /* =========================================
           MODALI E INSERIMENTO PUNTEGGIO
           ========================================= */
        .modal-overlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.85);
            z-index: 99999;
            
            /* Quando il tuo JS fa apparire la modale, userà queste regole: */
            display: none; /* Gestito dal JS */
            align-items: center; 
            justify-content: center;
            padding: 20px; /* Crea una "cornice" invisibile per non far toccare i bordi */
            box-sizing: border-box;
        }

        .modal-box {
            background: #00023a;
            border: 2px solid var(--border);
            padding: 25px;
            border-radius: 20px;
            width: 100%;
            max-width: 450px;
            text-align: center;
            box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
            
            /* --- IL SEGRETO PER NON FAR SFORARE I CONTENUTI --- */
            max-height: 95vh; /* La modale non può mai essere più alta dell'85% dello schermo */
            overflow-y: auto; /* Se i contenuti (game, form) sono troppi, appare lo scroll interno */
            
            /* Previeni che i figli escano dai bordi */
            display: flex;
            flex-direction: column;
        }

        /* Assicuriamoci che il form dentro si adatti allo spazio */
        .modal-box form {
            display: flex;
            flex-direction: column;
            flex-shrink: 0; /* Impedisce che il form venga "schiacciato" male */
        }

        select.custom-select {
            width: 100%;
            padding: 15px;
            border-radius: 10px;
            background: rgba(0, 0, 0, 0.5);
            border: 1px solid var(--border);
            color: white;
            font-size: 14px;
            margin-bottom: 20px;
        }

        .game-row {
            display: grid;
            grid-template-columns: 1fr 50px 1fr;
            align-items: center;
            justify-items: center;
            gap: 12px;
            margin-bottom: 12px;
            padding: 14px;
            background: linear-gradient(135deg, rgba(255, 255, 255, 0.04) 0%, rgba(255, 255, 255, 0.02) 100%);
            border-radius: 10px;
            border: 1px solid rgba(255, 175, 38, 0.1);
            transition: all 0.3s ease;
        }

        .game-row:hover {
            background: linear-gradient(135deg, rgba(255, 175, 38, 0.08) 0%, rgba(255, 175, 38, 0.04) 100%);
            border-color: rgba(255, 175, 38, 0.2);
            box-shadow: 0 4px 12px rgba(255, 175, 38, 0.1);
        }

        .game-row.disabled {
            opacity: 0.2;
            pointer-events: none;
            filter: grayscale(1);
        }

        .game-number {
            font-size: 11px;
            font-weight: 900;
            opacity: 0.5;
            text-align: center;
            letter-spacing: 0.5px;
            text-transform: uppercase;
        }

        .win-loss-toggle {
            display: flex;
            gap: 8px;
            justify-content: center;
            align-items: center;
        }

        .wl-btn {
            width: 40px;
            height: 40px;
            border-radius: 8px;
            border: none;
            background: rgba(255, 255, 255, 0.08);
            color: #fff;
            font-weight: 900;
            font-size: 13px;
            cursor: pointer;
            transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
            box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
        }

        .wl-btn:hover:not(.active-win):not(.active-loss) {
            background: rgba(255, 255, 255, 0.15);
            transform: translateY(-2px);
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
        }

        .wl-btn.active-win {
            background: linear-gradient(135deg, #4ade80 0%, #22c55e 100%);
            color: #000;
            border: none;
            font-weight: 900;
            box-shadow: 0 4px 12px rgba(74, 222, 128, 0.4);
            transform: scale(1.05);
        }

        .wl-btn.active-win:hover {
            filter: brightness(1.1);
            transform: scale(1.08) translateY(-2px);
            box-shadow: 0 6px 15px rgba(74, 222, 128, 0.5);
        }

        .wl-btn.active-loss {
            background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
            color: #fff;
            border: none;
            font-weight: 900;
            box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
            transform: scale(1.05);
        }

        .wl-btn.active-loss:hover {
            filter: brightness(1.1);
            transform: scale(1.08) translateY(-2px);
            box-shadow: 0 6px 15px rgba(239, 68, 68, 0.5);
        }

        .wl-btn.disabled {
            opacity: 0.35;
            pointer-events: none;
            cursor: not-allowed;
        }

        #match_status_hint {
            font-size: 11px;
            color: var(--secondary);
            margin-top: 10px;
            font-weight: 700;
            text-transform: uppercase;
            height: 15px;
        }

        /* =====================================
           REGOLE PER MOBILE (Max-Width: 768px)
           ===================================== */
        @media (max-width: 768px) {

            /* Mostriamo il bottone rotondo fluttuante */
            .mobile-fab {
                display: flex;
            }

            .dashboard-container {
                flex-direction: column !important;
                display: block;
            }

            .main-area {
                padding: 10px !important;
            }

            /* --- SIDEBAR SCORREVOLE (OFF-CANVAS) --- */
            .sidebar {
                position: fixed !important;
                inset: 0;
                left: 0;
                width: 100vw !important;
                max-width: none;
                height: 100dvh;
                margin-bottom: 0;
                background: var(--primary) !important;
                border-right: none !important;
                border-bottom: none !important;
                z-index: 9999;
                transform: translateX(100%);
                transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
                box-shadow: none;
                overflow-y: auto;
                padding: 25px 20px !important;
            }

            /* Classe applicata col JS per farla scivolare dentro */
            .sidebar.open {
                transform: translateX(0);
            }

            /* Il bottone dentro la sidebar diventa una X per chiuderla */
            .mobile-toggle-btn {
                display: block;
                background: transparent;
                border: none;
                color: var(--danger);
                font-size: 24px;
                padding: 0;
                margin: 0;
            }

            .sidebar h3 {
                font-size: 16px;
                margin: 0;
            }

            .action-btn {
                width: 100%;
                padding: 15px !important;
                font-size: 14px !important;
                margin-bottom: 10px;
            }

            /* --- MATCH CARD SCALATE SU UN'UNICA RIGA --- */
            .match-card {
                padding: 10px 8px !important;
                /* Meno spazio interno */
                margin-bottom: 8px !important;
                /* Forziamo la riga singola in caso il flex salti */
                display: flex !important;
                flex-direction: row !important;
                align-items: center !important;
                justify-content: space-between !important;
                gap: 5px !important;
            }

            /* Colonna 1: Numero Tavolo (T1, T2...) */
            .match-card>div:nth-child(1) {
                font-size: 14px !important;
                width: 30px !important;
                flex-shrink: 0;
            }

            /* Colonna 2 e 4: Nomi Giocatori */
            .match-card>div:nth-child(2),
            .match-card>div:nth-child(4) {
                font-size: 12px !important;
                flex: 1 !important;
                /* Queste 3 regole permettono i puntini sospensivi se il nome è lungo */
                white-space: nowrap !important;
                overflow: hidden !important;
                text-overflow: ellipsis !important;
                min-width: 0;
                /* Necessario per il text-overflow su Flexbox */
            }

            /* Nascondiamo il record "W-D-L" su mobile per fare spazio ai nomi */
            .match-card small {
                display: none !important;
            }

            /* Colonna 3: Il punteggio o il VS centrale */
            .match-card>div:nth-child(3) {
                font-size: 14px !important;
                margin: 0 4px !important;
                /* Rimuoviamo il grosso margine centrale */
                flex-shrink: 0;
                background: rgba(255, 255, 255, 0.05);
                /* Effetto bottoncino */
                padding: 2px 6px;
                border-radius: 4px;
            }

            /* --- TIMER CONTROLS MOBILE --- */
            .timer-controls-container {
                flex-wrap: wrap;
                gap: 5px;
            }
            .timer-controls-container button,
            .timer-controls-container input {
                flex: 1 1 45%;
                font-size: 12px !important;
            }
            .timer-controls-container form {
                flex: 1 1 45%;
                display: flex;
            }
            .timer-controls-container form button {
                width: 100%;
            }
            

        }