/* --- CONFIGURAZIONE BASE --- */
:root {
    --bg: #0f172a; --card: #111c33; --muted: #93a4c7; --text: #e8eefc;
    --accent: #60a5fa; --border: rgba(255, 255, 255, .10);
    --success: #34d399; --danger: #ef4444; --gold: #fbbf24;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body {
    margin: 0; font-family: system-ui, -apple-system, sans-serif;
    background: radial-gradient(circle at top right, rgba(96, 165, 250, 0.12), transparent 50%), 
                radial-gradient(circle at bottom left, rgba(52, 211, 153, 0.08), transparent 50%), 
                var(--bg);
    color: var(--text); padding: 20px; overscroll-behavior: none; 
    padding-bottom: calc(80px + env(safe-area-inset-bottom)); 
}

button:focus-visible, input:focus-visible, .game-card:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.nav-header { max-width: 800px; margin: 0 auto 20px; }
.btn-home { text-decoration: none; color: var(--accent); font-weight: 700; }
.page-title { max-width: 800px; margin: 0 auto 24px; text-align: left; }
.page-title h2 { font-family: 'MedievalSharp', cursive; font-size: 32px; color: var(--gold); margin:0; text-shadow: 0 2px 5px rgba(0,0,0,0.5); }
.page-title p { color: var(--muted); margin: 5px 0 0 0; font-size: 14px; }

.glass-panel {
    background: rgba(17, 28, 51, .80); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border); border-radius: 24px; padding: 20px; max-width: 800px; margin: 0 auto;
    box-shadow: 0 10px 40px rgba(0,0,0,0.4);
}

/* --- GRIGLIA GIOCHI --- */
.games-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 15px; }
.game-card {
    background: rgba(255,255,255,0.03); border: 1px solid var(--border); border-radius: 16px;
    padding: 15px; text-align: center; cursor: pointer; transition: 0.2s; position: relative;
}
.game-card:active { transform: scale(0.95); background: rgba(255,255,255,0.08); }
.game-card .icon { font-size: 3em; margin-bottom: 5px; }
.game-card h3 { font-family: 'MedievalSharp', cursive; color: var(--text); margin: 5px 0; font-size: 1.1em; }
.btn-fake { background: var(--accent); color: #0f172a; padding: 6px; border-radius: 12px; font-weight: 800; font-size: 0.8em; margin-top: 10px; }

/* --- CHAT AREA --- */
.chat-header { 
    color: var(--gold); 
    font-family: 'MedievalSharp', cursive; 
    font-size: 1.4em; 
    border-bottom: 1px solid var(--border); 
    padding-bottom: 10px; 
    margin-bottom: 10px; 
}

#tavern-chat-box { 
    height: 300px; 
    overflow-y: auto; 
    background: rgba(0,0,0,0.3); 
    border-radius: 10px; 
    padding: 15px; 
    margin-bottom: 15px; 
    font-size: 14px; 
    border: 1px solid var(--border);
}

.chat-msg { 
    display: flex; justify-content: space-between; align-items: flex-start;
    margin-bottom: 10px; border-bottom: 1px solid rgba(255,255,255,0.05); padding-bottom: 8px; 
}

.chat-content-wrapper { flex-grow: 1; padding-right: 10px; }
.chat-name { color: var(--accent); font-weight: bold; font-size: 0.9em; }
.chat-text { color: #e8eefc; word-wrap: break-word; white-space: pre-wrap; display: block; margin-top: 2px; }
.chat-time { color: #666; font-size: 0.75em; margin-right: 5px; }

.btn-report {
    background: transparent; border: none; cursor: pointer; font-size: 18px; 
    color: #ef4444; opacity: 0.6; transition: opacity 0.2s, transform 0.2s; padding: 0 0 0 5px; min-width: 24px;
}
.btn-report:hover { opacity: 1; transform: scale(1.2); }

.chat-input-area { display: flex; gap: 8px; }
#chat-user-name { width: 25%; background: rgba(0,0,0,0.4); border: 1px solid var(--border); color: var(--gold); border-radius: 8px; padding: 10px; text-align: center; font-weight: bold;}
#chat-message { width: 65%; background: rgba(0,0,0,0.4); border: 1px solid var(--border); color: #fff; border-radius: 8px; padding: 10px; }
.btn-chat-send { width: 10%; background: var(--success); color: #0f172a; border: none; border-radius: 8px; cursor: pointer; font-weight: 800; font-size: 1.2em; }

/* --- MODALE GIOCO --- */
.modal-overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(15, 23, 42, 0.95); z-index: 99999; justify-content: center; align-items: center; backdrop-filter: blur(5px); }
.modal-content { background: var(--card); border: 1px solid var(--gold); width: 95%; max-width: 500px; height: 90vh; border-radius: 20px; position: relative; display: flex; flex-direction: column; padding: 15px; }

.close-btn { 
    position: absolute; top: -15px; right: -10px; background: var(--danger); color: white; width: 44px; height: 44px; 
    border-radius: 50%; border: 3px solid var(--bg); z-index: 999999; font-size: 24px; touch-action: manipulation; 
    cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0; box-shadow: 0 4px 10px rgba(0,0,0,0.5);
}

.game-header-modal { display: flex; justify-content: space-between; border-bottom: 1px solid var(--border); padding-bottom: 10px; margin-bottom: 10px; flex-shrink: 0; flex-direction: column; }
#modal-title { margin: 0; color: var(--gold); font-family: 'MedievalSharp', cursive; text-align: center; }
.hud { width: 100%; display: flex; justify-content: space-around; color: var(--text); font-weight: bold; margin-top:5px; }
#global-score { color: var(--success); }

/* --- AREA DI GIOCO & TEMI DINAMICI --- */
#game-stage { 
    flex-grow: 1; width: 100%; 
    background: #111c33; 
    border: 1px solid var(--border); border-radius: 12px; 
    position: relative; overflow: hidden; touch-action: none; user-select: none; 
    box-shadow: inset 0 0 50px rgba(0,0,0,0.9); 
    transition: background 0.3s ease;
}

/* Tema 1: Tavolo/Pavimento di Legno */
.theme-wood {
    background: 
        radial-gradient(circle at 50% 0%, rgba(251, 191, 36, 0.15), transparent 70%),
        repeating-linear-gradient(to right, #2b170b 0, #2b170b 38px, #120a05 38px, #120a05 40px) !important;
}

/* Tema 2: Muro di Legno Orizzontale (Freccette) */
.theme-wall {
    background: 
        radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.05), transparent 60%),
        repeating-linear-gradient(to bottom, #3e2723 0, #3e2723 28px, #1a0f0a 28px, #1a0f0a 30px) !important;
}

/* Tema 3: Cantina in Pietra (Barili) */
.theme-stone {
    background: 
        radial-gradient(circle at 50% 0%, rgba(96, 165, 250, 0.1), transparent 70%),
        repeating-conic-gradient(from 45deg at 10% 10%, #1e293b 0% 25%, #0f172a 0% 50%) 50% / 40px 40px !important;
}

/* Tema 4: Terreno Scuro (Ratti) */
.theme-dirt {
    background: radial-gradient(circle at 50% 50%, #4e342e, #1a0f0a) !important;
}

/* ELEMENTI GIOCHI ORIGINALI */
.grid-ratti { display: flex; flex-wrap: wrap; height: 100%; width: 100%; padding: 10px; }
.hole { flex: 1 0 30%; height: 30%; margin: 5px; position: relative; background: radial-gradient(at bottom, #1a1a1a, #3e2723); border-radius: 50% 50% 10px 10px; border-bottom: 3px solid rgba(255,255,255,0.1); overflow: hidden; }
.mole { position: absolute; width: 100%; height: 100%; display: flex; justify-content: center; align-items: flex-end; font-size: 50px; bottom: -80px; transition: bottom 0.1s; cursor: pointer; z-index: 10; will-change: bottom; }
.mole.up { bottom: 0px; }

#basket { position: absolute; bottom: 10px; width: 80px; height: 80px; font-size: 70px; line-height: 80px; text-align: center; z-index: 99; transform: translateX(-50%); will-change: left; }
.falling-item { position: absolute; font-size: 40px; z-index: 90; font-weight: bold; will-change: top, left; }

#dart-target { width: 140px; height: 140px; background: radial-gradient(circle, #e74c3c 20%, #ecf0f1 20%, #ecf0f1 40%, #e74c3c 40%, #e74c3c 60%, #2c3e50 60%); border-radius: 50%; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); border: 3px solid #fff; z-index: 1; will-change: transform; }
.center-mark { position: absolute; top: 50%; left: 50%; width: 10px; height: 10px; background: #00ff00; border-radius: 50%; transform: translate(-50%, -50%); z-index: 50; box-shadow: 0 0 10px #0f0; }

#tower-world { position: absolute; width: 100%; height: 100%; bottom: 0; left: 0; transition: transform 0.3s; will-change: transform; }
.barile { position: absolute; height: 30px; background: linear-gradient(to bottom, #8b4513, #5d2e0a); border: 2px solid #3e2723; border-radius: 6px; box-shadow: inset 0 0 8px rgba(0,0,0,0.6); box-sizing: border-box; z-index: 5; will-change: left; }
#moving-block { position: absolute; height: 30px; background: linear-gradient(to bottom, #d35400, #a04000); border: 2px solid #fff; border-radius: 6px; z-index: 100; bottom: 0; will-change: left; }

.simon-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 20px; height: 100%; width: 100%; }
.simon-btn { border-radius: 10px; opacity: 0.3; border: 2px solid #fff; width: 100%; height: 100%; }
.active-light { opacity: 1 !important; box-shadow: 0 0 30px currentColor; transform: scale(0.95); }

/* OVERLAY GIOCHI */
.overlay-panel { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); background: rgba(17, 28, 51, 0.95); width: 85%; padding: 24px; border: 1px solid var(--gold); border-radius: 16px; text-align: center; z-index: 200; backdrop-filter: blur(10px); }
.hidden { display: none !important; }
.btn-action { width: 100%; padding: 14px; background: var(--gold); border: none; font-weight: 800; cursor: pointer; border-radius: 12px; margin-top: 10px; color: #0f172a; text-transform: uppercase; }
.btn-retry { width: 100%; padding: 14px; background: rgba(255,255,255,0.1); color: #fff; border: 1px solid var(--border); margin-top: 5px; border-radius: 12px; cursor: pointer;}
input[type="text"] { width: 100%; padding: 12px; margin-bottom: 5px; border-radius: 12px; border: 1px solid var(--border); background: rgba(0,0,0,0.3); color: #fff; text-align: center; }

/* LEADERBOARD */
.leaderboard-section { background: rgba(0,0,0,0.2); margin-top: 10px; padding: 10px; border-radius: 12px; border: 1px solid var(--border); max-height: 100px; overflow-y: auto; text-align: left; font-family: monospace; font-size: 13px; }
.leaderboard-section li { border-bottom: 1px solid var(--border); padding: 4px 0; display: flex; justify-content: space-between; color: var(--muted); }
.leaderboard-section li:first-child { color: var(--gold); font-weight: bold; }

/* --- NUOVI GIOCHI --- */
.table-boccale { position: absolute; width: 100%; height: 100%; background: linear-gradient(to top, rgba(0,0,0,0.8), transparent); }
.target-zone { position: absolute; top: 10%; width: 100%; height: 20%; background: rgba(52, 211, 153, 0.3); border-top: 2px dashed #34d399; border-bottom: 2px dashed #34d399; }
.sliding-mug { position: absolute; left: 50%; transform: translateX(-50%); font-size: 50px; z-index: 10; will-change: bottom; }

.cup-wrap { position: absolute; cursor: pointer; display: flex; align-items: flex-end; justify-content: center; height: 100px; width: 80px; transition: transform 0.3s ease-in-out; will-change: transform; bottom: 20%; left: 50%; }
.cup-icon { font-size: 60px; transition: transform 0.3s; z-index: 2; position: relative; }
.coin-icon { position: absolute; bottom: 0; font-size: 40px; z-index: 1; opacity: 0; transition: opacity 0.2s; }

.glass-bevuta { width: 100px; height: 160px; border: 4px solid rgba(255,255,255,0.5); border-top: none; border-radius: 0 0 15px 15px; position: relative; overflow: hidden; background: rgba(0,0,0,0.5); margin-bottom: 20px;}
.liquid-level { position: absolute; bottom: 0; left: 0; width: 100%; height: 100%; background: linear-gradient(to top, #b45309, #fbbf24); border-top: 8px solid rgba(255, 255, 255, 0.9); transition: height 0.1s; will-change: height;}

.balance-bar { width: 80%; height: 30px; border: 2px solid var(--border); border-radius: 15px; background: #333; position: relative; margin: auto; overflow: hidden;}
.balance-safe { position: absolute; left: 35%; width: 30%; height: 100%; background: rgba(52, 211, 153, 0.4); }
.balance-cursor { position: absolute; top: -2px; width: 16px; height: 34px; background: var(--success); border-radius: 4px; transform: translateX(-50%); border: 2px solid #fff; will-change: left; transition: background-color 0.2s; }
