/* --- STILE CSS --- */
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #2c3e50;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding-top: 10px;
    height: 100vh;
    margin: 0;
    overflow: hidden;
    box-sizing: border-box;
    user-select: none;
}

.game-card {
    background-color: white;
    border-radius: 10px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.3);
    width: 100%;
    max-width: 500px;
    height: 98vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* TASTI ANGOLO */
.corner-btn {
    position: absolute;
    top: 10px;
    font-size: 0.8rem;
    font-weight: bold;
    border: none;
    background: none;
    cursor: pointer;
    color: #7f8c8d;
    z-index: 20;
    padding: 5px;
    text-transform: uppercase;
}
.corner-btn:hover { color: #3498db; text-decoration: underline; }
#btnNew { left: 10px; }
#btnReveal { right: 10px; }

.header-section {
    background-color: #fff;
    padding: 10px 15px;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    text-align: center;
    flex-shrink: 0;
    padding-bottom: 15px;
}

h1 { margin: 5px 0 0 0; color: #333; font-size: 1.2rem; }
p.subtitle { color: #666; margin: 2px 0 8px 0; font-size: 0.8rem; }

.pin-container {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 8px;
}

.pin-box {
    width: 40px;
    height: 45px;
    font-size: 24px;
    text-align: center;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-weight: bold;
    color: #333;
    transition: border-color 0.3s;
}

.pin-box:focus { border-color: #3498db; outline: none; background-color: #f0f8ff; }

/* BOTTONI STORICO / GRAFICO */
.stats-buttons {
    display: flex;
    justify-content: center;
    gap: 6px;
}
.stats-btn {
    background: none;
    border: 1px solid #ddd;
    border-radius: 5px;
    color: #7f8c8d;
    font-size: 0.72rem;
    padding: 3px 10px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 4px;
}
.stats-btn:hover { background-color: #f0f0f0; color: #333; border-color: #ccc; }
.stats-btn:active { transform: scale(0.95); }

/* BARRA AZIONI */
.actions-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 5px;
    padding: 0 2px;
    box-sizing: border-box;
}
.actions-bar > :first-child { min-width: 110px; }
.actions-bar > :last-child  { min-width: 110px; text-align: right; justify-content: flex-end; }

.timer-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-pause {
    background: none;
    border: 1px solid #ddd;
    border-radius: 5px;
    color: #7f8c8d;
    font-size: 0.85rem;
    padding: 2px 7px;
    cursor: pointer;
    transition: all 0.2s;
    line-height: 1;
}
.btn-pause:hover { background-color: #f0f0f0; color: #333; border-color: #ccc; }
.btn-pause:active { transform: scale(0.95); }
.btn-pause.paused { background-color: #e74c3c; color: white; border-color: #e74c3c; }

.timer-display {
    font-family: monospace;
    font-size: 0.9rem;
    color: #555;
    font-weight: bold;
}

/* PAUSA: blur sulla sezione tentativi */
.history-section.blurred #historyList {
    filter: blur(12px);
    pointer-events: none;
    transition: filter 0.3s ease;
}
.history-section.blurred #instructions {
    filter: blur(12px);
    pointer-events: none;
}
.history-section .pause-overlay {
    display: none;
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 5;
    background: rgba(249,249,249,0.4);
    justify-content: center;
    align-items: center;
    font-size: 1.4rem;
    color: #2c3e50;
    font-weight: bold;
    letter-spacing: 1px;
}
.history-section.blurred .pause-overlay {
    display: flex;
}

.btn-reset-marks {
    background: none;
    border: 1px solid #ddd;
    border-radius: 5px;
    color: #7f8c8d;
    font-size: 0.75rem;
    padding: 3px 8px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 5px;
}
.btn-reset-marks:hover { background-color: #f0f0f0; color: #333; border-color: #ccc; }
.btn-reset-marks:active { transform: scale(0.95); }

/* BOTTONE DINAMICO */
.btn-check {
    background-color: #3498db;
    color: white;
    border: none;
    padding: 10px;
    font-size: 1rem;
    border-radius: 6px;
    cursor: pointer;
    width: 100%;
    font-weight: bold;
    transition: background 0.2s, transform 0.1s;
}
.btn-check:hover { background-color: #2980b9; }
.btn-check:active { transform: scale(0.98); }

.btn-error { background-color: #e74c3c !important; animation: shake 0.3s; }
.btn-success { background-color: #27ae60 !important; cursor: default; }
.btn-reveal { background-color: #e67e22 !important; cursor: default; }

@keyframes shake {
    0% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    50% { transform: translateX(5px); }
    75% { transform: translateX(-5px); }
    100% { transform: translateX(0); }
}

.history-section {
    flex-grow: 1;
    overflow-y: auto;
    padding: 10px;
    background-color: #f9f9f9;
    border-top: 1px solid #eee;
    position: relative;
}
.history-section::-webkit-scrollbar { width: 6px; }
.history-section::-webkit-scrollbar-thumb { background-color: #ccc; border-radius: 3px; }

/* --- ISTRUZIONI --- */
.instructions-overlay {
    color: #555;
    text-align: center;
    padding: 15px;
    font-size: 0.9rem;
    line-height: 1.5;
}
.instructions-overlay h3 { color: #2c3e50; margin-bottom: 8px; margin-top: 0; }
.instructions-overlay ul { list-style: none; padding: 0; text-align: left; display: inline-block; margin: 0; }
.instructions-overlay li { margin-bottom: 5px; }

.key-instruction {
    background: white;
    border: 2px solid #e0e0e0;
    padding: 15px;
    border-radius: 8px;
    margin-top: 20px;
    font-size: 0.9rem;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.mouse-row { margin-top: 8px; display: block; color: #333; }

/* --- TENTATIVI --- */
.attempt-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: white;
    padding: 5px 10px;
    margin-bottom: 4px;
    border-radius: 6px;
    border-left: 4px solid #bdc3c7;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

.left-group { display: flex; align-items: center; }
.attempt-index { color: #999; font-size: 0.75rem; margin-right: 8px; min-width: 18px;}

.attempt-nums {
    font-weight: bold;
    font-size: 1.1rem;
    color: #2c3e50;
    display: flex;
    gap: 8px;
}

.single-digit { cursor: pointer; padding: 0 3px; transition: all 0.2s; border-radius: 3px; }
.single-digit.crossed { text-decoration: line-through; text-decoration-thickness: 2px; color: #bdc3c7; }
.single-digit.green-mark { color: white; background-color: #27ae60; }
.single-digit.yellow-mark { color: #333; background-color: #f1c40f; }

.attempt-time { color: #95a5a6; font-size: 0.75rem; font-family: monospace; margin: 0 8px; }

.score { display: flex; gap: 6px; font-size: 0.7rem; text-transform: uppercase; align-items: center; }
.badge { padding: 3px 6px; border-radius: 3px; color: white; font-weight: bold; text-align: center; white-space: nowrap; min-width: 50px; }
.badge-strike { background-color: #27ae60; }
.badge-ball { background-color: #f1c40f; color: #333; }
.win { border-left-color: #27ae60; background-color: #eafaf1; }

/* --- MODAL OVERLAY --- */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.55);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.2s;
}
.modal-overlay.active { display: flex; }

.modal-content {
    background: white;
    border-radius: 12px;
    width: 94%;
    max-width: 520px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    overflow: hidden;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    border-bottom: 1px solid #eee;
    flex-shrink: 0;
}
.modal-header h2 {
    margin: 0;
    font-size: 1rem;
    color: #2c3e50;
}
.modal-close {
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: #999;
    padding: 0 4px;
    line-height: 1;
}
.modal-close:hover { color: #333; }

.modal-body {
    padding: 15px 18px;
    overflow-y: auto;
    flex-grow: 1;
}
.modal-body::-webkit-scrollbar { width: 5px; }
.modal-body::-webkit-scrollbar-thumb { background-color: #ccc; border-radius: 3px; }

/* TABELLA STORICO */
.stats-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}
.stats-table th {
    background: #2c3e50;
    color: white;
    padding: 8px 6px;
    text-align: left;
    font-weight: 600;
    position: sticky;
    top: 0;
}
.stats-table th:first-child { border-radius: 6px 0 0 0; }
.stats-table th:last-child { border-radius: 0 6px 0 0; }
.stats-table td {
    padding: 7px 6px;
    border-bottom: 1px solid #f0f0f0;
    color: #444;
}
.stats-table tr:nth-child(even) td { background: #fafafa; }
.stats-table tr:hover td { background: #eef6ff; }
.stats-table .col-num { text-align: center; font-family: monospace; }

.empty-state {
    text-align: center;
    color: #999;
    padding: 40px 20px;
    font-size: 0.9rem;
}

/* CHART */
.chart-container {
    position: relative;
    width: 100%;
    padding-bottom: 10px;
}
.chart-canvas-wrap {
    position: relative;
    width: 100%;
    overflow-x: auto;
}
.chart-canvas-wrap canvas {
    display: block;
}

/* MODALE GRAFICO */
#modalGrafico .modal-content {
    width: 96%;
    max-width: none;
    height: 92vh;
}
#graficoBody {
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
}
#graficoBody .chart-container {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    padding-bottom: 0;
}
#graficoBody .chart-canvas-wrap {
    flex: 0 0 auto;
    overflow-x: auto;
    display: flex;
    align-items: stretch;
}
#graficoBody .chart-canvas-wrap svg {
    display: block;
}

/* FOOTER MODALE */
.modal-footer {
    padding: 10px 18px;
    border-top: 1px solid #eee;
    display: flex;
    justify-content: flex-end;
    flex-shrink: 0;
}
.btn-danger-small {
    background: none;
    border: 1px solid #e74c3c;
    color: #e74c3c;
    font-size: 0.75rem;
    padding: 4px 12px;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-danger-small:hover { background: #e74c3c; color: white; }
