* {
    box-sizing: border-box;
    font-family: 'Sarabun', 'Segoe UI', Tahoma, sans-serif;
    user-select: none;
}

body {
    margin: 0; padding: 20px;
    background-color: #f0f8ff;
    /* จัดกึ่งกลางหน้าจอแบบสมบูรณ์ ทั้งแนวตั้งและแนวนอน */
    display: flex; 
    min-height: 100vh;
}

.game-container {
    margin: auto; /* ทำให้กล่องอยู่ตรงกลางเสมอ */
    width: 100%; max-width: 950px;
    background: white; border-radius: 24px; padding: 25px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.08); text-align: center;
}

.status-bar {
    display: flex; justify-content: space-around;
    background: #eef2f7; padding: 12px; border-radius: 16px;
    margin-bottom: 20px; font-size: 18px; font-weight: bold; color: #34495e;
}
.status-item span { color: #3498db; }

.menu-title { font-size: 32px; color: #2c3e50; margin-bottom: 30px; }
.menu-grid { display: grid; grid-template-columns: 1fr; gap: 15px; max-width: 500px; margin: 0 auto; }
.menu-btn {
    background: #fff; color: #34495e; border: 3px solid #3498db;
    padding: 18px 20px; border-radius: 16px; cursor: pointer;
    font-size: 20px; font-weight: bold; display: flex; justify-content: space-between;
    transition: all 0.3s;
}
.menu-btn:hover { background: #3498db; color: white; transform: translateY(-3px); box-shadow: 0 10px 20px rgba(52,152,219,0.3); }

.top-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.back-btn { background: #e74c3c; color: white; border: none; padding: 10px 20px; border-radius: 12px; cursor: pointer; font-weight: bold; transition: 0.2s; }
.back-btn:hover { background: #c0392b; }

.display-area { background: #fdfefe; border: 3px solid #e0e6ed; border-radius: 20px; padding: 30px; margin-bottom: 20px; }
.target-word { font-size: 64px; font-weight: bold; letter-spacing: 2px; color: #ccc; margin-bottom: 15px; }
.char-active { color: #2c3e50; border-bottom: 5px solid #3498db; }
.char-typed { color: #2ecc71; }
.hint-text { color: #e67e22; font-size: 18px; font-weight: bold; margin-top: 5px; }

.keyboard { background: #2c3e50; padding: 15px; border-radius: 20px; width: 100%; overflow-x: auto; white-space: nowrap; }
.keyboard-row { display: flex; justify-content: center; margin-bottom: 6px; min-width: 700px; }
.key {
    width: 50px; height: 50px; margin: 0 3px; background: #fff; border-radius: 8px;
    display: flex; justify-content: center; align-items: center; font-size: 18px; font-weight: bold;
    box-shadow: 0 3px 0 #bdc3c7; position: relative; transition: all 0.1s;
}

.f-left-pinky { background-color: #ffc6c6; }
.f-left-ring { background-color: #ffe2c6; }
.f-left-middle { background-color: #fffec6; }
.f-left-index { background-color: #c6ffc6; }
.f-right-index { background-color: #c6f1ff; }
.f-right-middle { background-color: #d5c6ff; }
.f-right-ring { background-color: #f5c6ff; }
.f-right-pinky { background-color: #e2e2e2; }
.key.space { width: 350px; background-color: #f5f6fa; }

@keyframes pulse { 0% { box-shadow: 0 0 0 0px rgba(241,196,15,0.7); } 70% { box-shadow: 0 0 0 12px rgba(241,196,15,0); } 100% { box-shadow: 0 0 0 0px rgba(241,196,15,0); } }
.key.target-hint { animation: pulse 1.2s infinite; border: 3px solid #f1c40f !important; z-index: 10; }
.key.active { transform: translateY(3px); box-shadow: 0 0px 0 #bdc3c7; filter: brightness(0.85); }

/* Modals */
.modal-overlay {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.6); z-index: 1000; justify-content: center; align-items: center;
}
.modal-content { background: white; padding: 30px; border-radius: 20px; width: 90%; max-width: 500px; text-align: center; border: 4px solid #3498db; box-shadow: 0 10px 40px rgba(0,0,0,0.2); }
.input-name { width: 80%; padding: 12px; font-size: 20px; border: 2px solid #bdc3c7; border-radius: 10px; margin: 15px 0; text-align: center; }
.btn-save { background: #2ecc71; color: white; border: none; padding: 12px 25px; border-radius: 10px; font-size: 18px; cursor: pointer; font-weight: bold; }
.btn-save:disabled { background: #95a5a6; }
.btn-close { background: #e74c3c; color: white; border: none; padding: 10px 20px; border-radius: 10px; cursor: pointer; margin-top: 15px; font-weight: bold; }

/* Styles สำหรับ Tabs บอร์ดคะแนน */
.tabs { display: flex; justify-content: center; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.tab-btn {
    background: #e0e6ed; color: #34495e; border: none; padding: 10px 16px;
    border-radius: 10px; cursor: pointer; font-size: 16px; font-weight: bold; transition: 0.2s;
}
.tab-btn:hover { background: #bdc3c7; }
.tab-btn.active { background: #3498db; color: white; box-shadow: 0 4px 10px rgba(52,152,219,0.4); }

.leaderboard-table { width: 100%; border-collapse: collapse; }
.leaderboard-table th, .leaderboard-table td { padding: 12px; border-bottom: 1px solid #eee; text-align: center; font-size: 18px; }
.leaderboard-table th { background: #3498db; color: white; }
.leaderboard-btn { background: #f1c40f; color: #2c3e50; border: none; padding: 12px 25px; border-radius: 12px; cursor: pointer; font-size: 18px; font-weight: bold; margin-bottom: 25px; box-shadow: 0 4px 6px rgba(241,196,15,0.3); transition: transform 0.2s; }
.leaderboard-btn:hover { transform: scale(1.05); }