@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

/* --- 1. Config --- */
:root {
  --orange-main: #ff9f43; --orange-shadow: #e58e26; --orange-light: #ffc048;
  --blue-main: #54a0ff; --blue-shadow: #2e86de;
  --pink-main: #ff9ff3; --pink-shadow: #f368e0;
  --red-main: #e74c3c; --red-shadow: #c0392b; /* สีแดงสำหรับปุ่ม Reset */
  --screen-bg: #cbf0da;
}
body { background-color: #2f3640; font-family: 'Press Start 2P', monospace; display: flex; justify-content: center; align-items: center; min-height: 100vh; margin: 0; user-select: none; overflow: hidden; }

.game-wrapper { position: relative; width: 400px; height: 700px; overflow: hidden; display: flex; justify-content: center; align-items: center; }

/* Speech Bubble */
.speech-bubble {
  position: absolute;
  bottom: 90px;
  left: 50%; transform: translateX(-50%);
  background: #fff;
  color: #333;
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 2px solid #aaa;
  white-space: nowrap;
  z-index: 500;
  pointer-events: none;
  animation: bubblePop 2s ease forwards;
}
.speech-bubble::after {
  content: '';
  position: absolute;
  bottom: -8px; left: 50%; transform: translateX(-50%);
  border: 4px solid transparent;
  border-top-color: #aaa;
}
@keyframes bubblePop {
  0%   { opacity: 0; transform: translateX(-50%) scale(0.8); }
  15%  { opacity: 1; transform: translateX(-50%) scale(1); }
  75%  { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) scale(0.95); }
}

/* --- 2. UI Overlays (Title, Settings, Select, Achievements) --- */
.start-overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  
  /* 👇 แก้ตรงนี้: เปลี่ยนจากสีดำ เป็นรูปภาพ */
  background-image: url('bg_cover.png'); 
  background-size: cover;      /* ขยายรูปให้เต็มจอ */
  background-position: center; /* จัดกึ่งกลาง */
  background-repeat: no-repeat;
  
  /* เพิ่มสีดำจางๆ ทับรูปนิดนึง (Overlay) ตัวหนังสือจะได้อ่านง่าย */
  background-color: rgba(0,0,0,0.2); 
  background-blend-mode: overlay;

  display: flex; 
  flex-direction: column;
  justify-content: center; 
  align-items: center; 
  z-index: 999; 
  color: white; 
  text-align: center;
}
.game-title {
  color: var(--orange-main); text-shadow: 4px 4px 0 #000;
  margin-bottom: 40px; line-height: 1.5; font-size: 24px;
  animation: bounce 2s infinite alternate; /* บรรทัดนี้จะทำให้มันเด้งค่ะ */
}

/* แปะก้อนนี้เพิ่มต่อท้ายข้างล่าง .game-title เลยก็ได้ค่ะ */
@keyframes bounce {
  from { transform: translateY(0); }
  to { transform: translateY(-10px); }
}
.select-title { color: #fff; margin-bottom: 20px; font-size: 22px; }
.copyright { margin-top: 50px; font-size: 14px; color: black; }
.back-btn { background: none; border: 2px solid #fff; color: #fff; padding: 8px 16px; font-family: inherit; cursor: pointer; font-size: 10px; margin-top: 20px;}

/* Menu Boxes & Buttons (ปรับปรุงใหม่) */
.menu-box {
  background: #fff; padding: 20px; border-radius: 10px;
  border: 4px solid var(--orange-main); color: #333;
}
.main-menu-list { display: flex; flex-direction: column; gap: 15px; width: 200px; }
.settings-box { display: flex; flex-direction: column; gap: 20px; width: 220px; }

.menu-btn {
  background: var(--orange-main); border: none; padding: 15px 10px;
  font-family: inherit; color: #fff; cursor: pointer; font-size: 14px;
  box-shadow: 0 4px 0 var(--orange-shadow); width: 100%;
}
.menu-btn:active { transform: translateY(4px); box-shadow: none; }

/* ปุ่ม Danger (สีแดง) */
.danger-btn {
  background: var(--red-main); box-shadow: 0 4px 0 var(--red-shadow);
}

/* Language Switcher ในหน้า Settings */
.setting-row { display: flex; justify-content: space-between; align-items: center; font-size: 15px; }
.lang-switch { display: flex; gap: 5px; }
.lang-btn { background: #eee; border: 2px solid #ccc; padding: 5px 10px; cursor: pointer; font-family: inherit; font-size: 10px; }
.lang-btn.active { background: var(--orange-main); color: white; border-color: var(--orange-shadow); }

/* --- 3. Character Select Cards --- */
.char-grid { display: flex; gap: 10px; }
.char-card {
  background: #fff; border: 4px solid #fff; border-radius: 10px;
  width: 80px; padding: 10px 5px; cursor: pointer; position: relative; text-align: center; color: #333;
}
.char-card:hover { transform: translateY(-5px); border-color: #f1c40f; }
.card-img { width: 40px; height: 40px; margin: 0 auto 5px; border-radius: 5px; display: flex; justify-content: center; align-items: center; font-size: 20px; border: 2px solid rgba(0,0,0,0.1); }
.card-name { font-size: 8px; font-weight: bold; margin-bottom: 5px; }
.card-status { font-size: 6px; color: #777; }
.char-card.locked { background: #bdc3c7; opacity: 0.8; cursor: not-allowed; }
.lock-icon { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-size: 24px; z-index: 2; text-shadow: 0 0 5px #000; }

/* --- 4. Device Style (เหมือนเดิม) --- */
.tamagotchi-device { width: 300px; border-radius: 40px; padding: 20px; display: flex; flex-direction: column; align-items: center; position: relative; animation: popup 0.5s ease-out; }
@keyframes popup { from { transform: scale(0.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.theme-orange { background-color: var(--orange-main); box-shadow: inset 5px 5px 10px var(--orange-light), inset -5px -5px 10px var(--orange-shadow), 0 10px 20px rgba(0,0,0,0.5); border: 4px solid var(--orange-shadow); }
.theme-blue { background-color: var(--blue-main); box-shadow: inset 5px 5px 10px #82ccdd, inset -5px -5px 10px var(--blue-shadow), 0 10px 20px rgba(0,0,0,0.5); border: 4px solid var(--blue-shadow); }
.theme-pink { background-color: var(--pink-main); box-shadow: inset 5px 5px 10px #ffc3f9, inset -5px -5px 10px var(--pink-shadow), 0 10px 20px rgba(0,0,0,0.5); border: 4px solid var(--pink-shadow); }

.top-bar { width: 100%; display: flex; justify-content: space-between; margin-bottom: 10px; color: #fff; font-size: 10px; text-shadow: 1px 1px 0 #000; }
.mute-btn { background: none; border: none; cursor: pointer; font-size: 14px; color: white; }
.button-row { display: flex; gap: 8px; margin: 5px 0; }
.button-row button { width: 45px; height: 45px; border-radius: 50%; border: 3px solid rgba(255,255,255,0.5); background-color: rgba(255,255,255,0.2); cursor: pointer; font-size: 18px; display: flex; justify-content: center; align-items: center; box-shadow: 0 4px 0 rgba(0,0,0,0.2); transition: 0.1s; }
.button-row button:active { transform: translateY(4px); box-shadow: none; }
.screen-border { background-color: #57606f; padding: 12px; border-radius: 20px; margin: 10px 0; width: 100%; box-sizing: border-box; box-shadow: inset 0 0 10px #000; }
.screen-display { background-color: var(--screen-bg); height: 160px; border-radius: 10px; position: relative; border: 2px solid #889098; display: flex; justify-content: center; align-items: center; overflow: hidden; }
.pixel-sprite { font-size: 50px; animation: bounce 2s infinite; }
@keyframes bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
.info-panel { background-color: rgba(255,255,255,0.9); width: 100%; border-radius: 15px; padding: 10px; display: flex; gap: 10px; border: 2px solid rgba(0,0,0,0.1); margin-top: 10px; box-sizing: border-box; height: 80px; }
.portrait-box { width: 50px; height: 50px; background-color: #dfe6e9; border: 2px solid #b2bec3; border-radius: 8px; display: flex; justify-content: center; align-items: center; font-size: 30px; align-self: center; }
.text-box { flex: 1; display: flex; flex-direction: column; justify-content: center; }
.name-tag { font-size: 10px; color: #e58e26; font-weight: bold; margin-bottom: 5px; }
#message-log { 
    font-size: 16px; /* 👈 แก้ตรงนี้ (เดิม 8px) */
    line-height: 1.6; 
    color: #2d3436; 
    padding-right: 5px; 
    display: flex; 
    align-items: center; 
    height: 100%; 
}

/* 2. ขนาดสำหรับภาษาไทย (ตัวนี้สำคัญ! เพราะเราเล่นภาษาไทยอยู่) */
#device[data-lang="th"] #message-log { 
    font-size: 16px; /* 👈 แก้ตรงนี้ด้วย! (เดิม 12px) */
    font-weight: bold; 
    line-height: 1.4; 
}
@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}
/* --- แก้ไข Status Bar (ฉบับแก้ตัว ย่อส่วน!) --- */

.status-bar {
    display: flex;            /* เรียงแนวนอนเหมือนเดิม */
    justify-content: space-between; /* จัดระยะห่างให้พอดีๆ ไม่เบียดกัน */
    align-items: center;      /* จัดกึ่งกลางแนวตั้ง */
    width: 90%;               /* กว้างเกือบเต็มจอ (เหลือขอบนิดหน่อย) */
    margin: 0 auto;           /* จัดให้อยู่ตรงกลางเป๊ะๆ */
    padding-top: 15px;        /* ดันลงมาจากขอบบนนิดนึง */
}

.stat-item {
    font-size: 12px;          /* ✨ ลดขนาดลงมาเหลือ 12px (กำลังน่ารัก) */
    font-weight: bold;        
    color: #ffffff;           /* สีขาว */
    text-shadow: 2px 2px 0px #000000; /* ✨ เพิ่มขอบดำให้ตัวหนังสืออ่านง่ายขึ้น (สไตล์เกม Pixel) */
    display: flex;            /* จัดไอคอนกับตัวเลขให้อยู่บรรทัดเดียวกัน */
    align-items: center;      
}

/* --- สไตล์ Status Bar (ฉบับสมบูรณ์) --- */

.status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 90%;
    margin: 0 auto;
    padding-top: 15px;
}

.stat-item {
    font-size: 12px;   /* ขนาดตัวเลข (เอาเท่าเดิม 12px หรือแก้เป็น 14px ก็ได้) */
    font-weight: bold;
    color: #ffffff;
    text-shadow: 2px 2px 0px #000000;
    display: flex;
    align-items: center;
}

/* ✨ สั่งขยายเฉพาะไอคอนตรงนี้ ✨ */
.big-icon {
    font-size: 16px;   /* 👈 ปรับเลขนี้ให้ใหญ่สะใจพี่เลย! (20px, 24px, 30px) */
    margin-right: 5px; /* เว้นระยะห่างจากตัวเลข */
    filter: drop-shadow(2px 2px 0px #000000); /* เพิ่มขอบเงาให้ไอคอนด้วยจะได้ชัดๆ */
}

/* --- เพิ่มโค้ดสำหรับระบบเดิน --- */

.screen-display {
    position: relative; /* สร้างขอบเขตให้เดินแค่ในจอนี้ */
    overflow: hidden;   /* ถ้าเดินตกขอบ ให้หายไปเลย ไม่ต้องทะลุออกมา */
    /* จัดกึ่งกลางเหมือนเดิม */
    display: flex;
    justify-content: center;
    align-items: center;
}

#pet-img {
    width: 64px;       /* ปรับขนาดตัวตามชอบ (ถ้าเล็กไปแก้ตรงนี้) */
    image-rendering: pixelated; /* สั่งให้ภาพชัดแบบ Pixel Art (ไม่เบลอ) */
    position: relative; /* เตรียมพร้อมสำหรับการขยับซ้ายขวา */
}

/* --- จัดปุ่มให้กระจายตัวสวยๆ --- */
.actions, .controls, .button-row, .menu {
    display: flex;
    justify-content: space-evenly !important; /* สั่งให้เว้นระยะห่างเท่าๆ กัน */
    width: 100%; /* ขยายความกว้างให้เต็มพื้นที่ */
    padding: 0 10px; /* เว้นขอบซ้ายขวานิดนึงจะได้ไม่ชิดขอบจอเกินไป */
}

/* --- เอฟเฟกต์ตอนนอน (Zzz Animation) --- */
@keyframes floatZ {
  0% { transform: translateY(0) translateX(0) scale(0.8); opacity: 0; }
  20% { opacity: 1; }
  100% { transform: translateY(-30px) translateX(15px) scale(1.2); opacity: 0; }
}

.zzz-effect {
  position: absolute;
  top: 30%;       /* ปรับความสูงให้อยู่เหนือหัวนิดหน่อย */
  right: 25%;     /* ให้อยู่ทางขวาของตัวละคร */
  color: #fff;    /* สีขาว */
  font-size: 24px;
  font-weight: bold;
  font-family: 'Press Start 2P', monospace;
  animation: floatZ 2s infinite linear; /* ลอยขึ้นเรื่อยๆ */
  z-index: 100;
  pointer-events: none; /* กดทะลุได้ */
}

/* --- 💩 ระบบอึ (Poop) --- */
.poop-item {
    position: absolute;
    bottom: 20px;       /* อยู่ระดับเท้า */
    font-size: 24px;    /* ขนาดอึ */
    z-index: 5;         /* อยู่หลังตัวละครนิดนึง */
    animation: poopBounce 1s infinite; /* ดุ๊กดิ๊ก */
}

@keyframes poopBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}

/* --- 🧹 ระบบไม้กวาด (Broom) --- */
.broom-effect {
    position: absolute;
    right: -50px;       /* เริ่มต้นซ่อนอยู่ขวานอกจอ */
    bottom: 30px;
    font-size: 30px;    /* ขนาดไม้กวาด */
    z-index: 20;        /* อยู่หน้าสุด */
    animation: sweepAnim 2s ease-in-out; /* กวาด 2 วิ */
}

@keyframes sweepAnim {
    0% { right: -50px; transform: rotate(0deg); }
    30% { right: 40px; transform: rotate(-10deg); } /* โผล่มา */
    70% { right: 20px; transform: rotate(-20deg); } /* กวาดๆ */
    100% { right: -50px; transform: rotate(0deg); } /* กลับไป */
}

/* --- Game Overlay (ฉบับแก้จบปัญหา) --- */
#game-overlay {
    position: absolute; 
    top: 0; left: 0; 
    width: 100%; height: 100%; 
    background-color: rgba(236, 240, 241, 0.95);
    z-index: 100;
    display: flex; flex-direction: column; 
    align-items: center; justify-content: center;
    border-radius: 8px;
}

/* จัดเมนูให้เรียงแนวตั้ง และระยะห่างพอดีๆ */
#game-menu-list {
    display: flex;
    flex-direction: column; 
    align-items: center;    
    gap: 6px;  /* ลดช่องว่างลง (จาก 10px เหลือ 6px) */
    width: 100%;
}
/* ลดขนาดหัวข้อ */
.game-header-title {
    margin: 0 0 8px 0; /* ลดระยะห่างด้านล่าง */
    color: #2d3436;
    font-size: 12px;   /* ลดขนาดตัวอักษรลงนิดนึง */
    font-weight: bold;
    text-transform: uppercase;
}
/* ปรับปุ่มให้ผอมลง จะได้ไม่ล้นจอ */
.mini-game-btn {
    width: 80%;       
    padding: 8px;     /* ลดความอ้วนปุ่ม (จาก 12px เหลือ 8px) */
    background: #ff9f43; 
    color: white; 
    border: none;
    border-radius: 6px; 
    font-family: inherit; 
    font-size: 10px;  /* ลดขนาดตัวหนังสือในปุ่ม */
    cursor: pointer;
    box-shadow: 0 3px 0 #e58e26; /* ลดเงาลงนิดนึง */
    transition: 0.1s;
}
.mini-game-btn:active { transform: translateY(2px); box-shadow: none; }.mini-game-btn:active { transform: translateY(3px); box-shadow: none; }

/* เกม RPS: บังคับปุ่มใหญ่ !important */
.rps-choice-box { 
    display: flex; 
    justify-content: center; 
    gap: 15px; 
}

.rps-btn { 
    font-size: 30px !important;    /* ไอคอนใหญ่ขึ้น */
    width: 60px !important;        /* กว้าง 60px แน่นอน */
    height: 60px !important;       /* สูง 60px แน่นอน */
    background: #fff; 
    border: 3px solid #b2bec3; 
    border-radius: 12px; 
    cursor: pointer; 
    display: flex; 
    justify-content: center; 
    align-items: center;
    box-shadow: 0 4px 0 rgba(0,0,0,0.1);
}
.rps-btn:active { transform: scale(0.95); background: #ffeaa7; }

/* แก้ข้อ 3: XO Grid (บังคับขนาดและสี) */
.xo-grid { 
    display: grid; 
    grid-template-columns: repeat(3, 1fr); 
    gap: 4px; 
    background: #2d3436; 
    padding: 4px; 
    width: 100px; /* กำหนดขนาดชัดเจน */
    height: 100px;
    margin: 0 auto;
    border-radius: 5px;
}
.xo-cell { 
    background: #fff; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    font-size: 20px; 
    cursor: pointer; 
    font-weight: bold; 
    height: 100%; /* ยืดเต็มช่อง */
}
.xo-cell.x { color: #e74c3c; } 
.xo-cell.o { color: #3498db; }

/* แก้ข้อ 4: RPS & Math (ขยายปุ่ม) */
.game-stage { text-align: center; width: 100%; }

.rps-choice-box { display: flex; justify-content: center; gap: 10px; }
.rps-btn { 
    font-size: 24px; /* ขยายไอคอน */
    width: 50px; /* ขยายปุ่ม */
    height: 50px; 
    background: #fff; 
    border: 3px solid #b2bec3; 
    border-radius: 10px; 
    cursor: pointer; 
    display: flex; justify-content: center; align-items: center;
}
.rps-btn:active { background: #ffeaa7; border-color: #fdcb6e; transform: scale(0.95); }

#math-question { font-size: 16px; margin-bottom: 10px; color: #2d3436; font-weight: bold; }
.math-answers { display: flex; justify-content: center; gap: 5px; } /* เรียงแนวนอน */
.math-ans-btn { 
    padding: 8px 12px; 
    background: #74b9ff; 
    border: none; 
    color: white; 
    font-family: inherit; 
    font-size: 12px; 
    cursor: pointer; 
    border-radius: 5px; 
    box-shadow: 0 3px 0 #0984e3;
}
.math-ans-btn:active { transform: translateY(3px); box-shadow: none; }

/* =========================================
   10. Item & Shop Styling (เมนูของ/ร้านค้า)
   ========================================= */

/* ฉากหลังเมนู (สีขาวบังหน้าจอ) */
.item-menu-overlay {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(255, 255, 255, 0.98);
    z-index: 150;
    display: flex; flex-direction: column; 
    align-items: center; justify-content: center;
    border-radius: 8px;
}

/* ตารางจัดวางของ (2 ช่อง) */
.menu-grid { 
    display: flex; gap: 15px; 
}

/* ช่องเก็บของ (Item Slot) */
.item-slot {
    width: 60px; height: 80px;
    background: #dfe6e9; 
    border: 3px solid #b2bec3; 
    border-radius: 10px;
    display: flex; flex-direction: column; 
    align-items: center; justify-content: center;
    cursor: pointer; 
    transition: 0.1s;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.1);
}
.item-slot:active { transform: scale(0.95); background: #81ecec; border-color: #00cec9; }

.item-icon { font-size: 32px; margin-bottom: 5px; filter: drop-shadow(2px 2px 0 rgba(0,0,0,0.2)); }
.item-qty { 
    font-size: 10px; font-weight: bold; color: #2d3436; 
    background: #fff; padding: 2px 6px; border-radius: 4px; 
    border: 1px solid #ccc;
}

/* --- ร้านค้า (Shop) --- */
.shop-title { 
    margin: 0 0 10px 0; color: #e17055; 
    font-size: 14px; font-weight: bold; 
    text-transform: uppercase; letter-spacing: 1px;
}

.shop-grid { 
    display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; 
}

.shop-item {
    width: 60px; height: 70px; 
    background: #fff; border: 2px solid #fab1a0; border-radius: 8px;
    display: flex; flex-direction: column; 
    align-items: center; justify-content: center;
    cursor: pointer; box-shadow: 0 3px 0 #e17055;
}
.shop-item:active { transform: translateY(3px); box-shadow: none; background: #ffeaa7; }

.item-price { 
    font-size: 9px; color: #d63031; font-weight: bold; margin-top: 4px; 
    background: #fad390; padding: 2px 4px; border-radius: 3px;
}

/* ปุ่มปิดเล็กๆ (กากบาท / ย้อนกลับ) */
.close-small-btn { 
    position: absolute; top: 5px; right: 5px; 
    background: #ff7675; border: none; color: white; 
    width: 20px; height: 20px; border-radius: 50%;
    cursor: pointer; font-weight: bold; font-size: 10px;
    display: flex; justify-content: center; align-items: center;
}
.back-btn { 
    background: none; 
    border: 2px solid #fff; 
    color: #fff; 
    padding: 10px 20px; /* นาริขยายกรอบให้กว้างขึ้นด้วย จะได้ไม่อึดอัด */
    font-family: inherit; 
    cursor: pointer; 
    font-size: 16px;    /* 👈 แก้ตรงนี้เป็น 16px ค่ะ */
    margin-top: 20px;
    background-color: rgba(0,0,0,0.3); /* นาริแถมพื้นหลังสีดำจางๆ ให้ด้วย จะได้อ่านง่ายขึ้นบนพื้นหิมะ */
}
.back-btn-shop:active { transform: translateY(3px); box-shadow: none; }

/* --- ไอคอนป่วย (ฉบับ SVG โค้ดล้วน) --- */
.sick-alert {
    position: absolute;
    top: 45%;          /* ระดับความสูง */
    right: 60px;       /* ระยะห่างจากขวา */
    transform: translateY(-50%);
    
    /* ไม่ต้องกำหนด width/height/color แล้ว เพราะ SVG จัดการเองในตัว */
    
    z-index: 50;       /* อยู่ชั้นบนสุด */
    animation: blinkSick 1s infinite; /* กระพริบเหมือนเดิม */
    
    /* เพิ่มเงาเล็กน้อยให้ดูมีมิติเข้ากับเกม */
    filter: drop-shadow(2px 2px 0px rgba(0,0,0,0.3));
}

/* Animation กระพริบ (ของเดิมใช้ได้แล้ว) */
@keyframes blinkSick { 
    0%, 100% { opacity: 1; transform: translateY(-50%) scale(1); } 
    50% { opacity: 0.5; transform: translateY(-50%) scale(1.2); } 
}

/* --- เอฟเฟกต์ของลอย (Float Animation) --- */
.item-effect-float {
    position: absolute; top: 50%; left: 50%; 
    transform: translate(-50%, -50%);
    font-size: 50px; z-index: 200; 
    animation: floatUpFade 1.5s forwards;
    pointer-events: none;
}
@keyframes floatUpFade {
    0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
    50% { transform: translate(-50%, -80%) scale(1.2); opacity: 1; }
    100% { transform: translate(-50%, -120%) scale(1); opacity: 0; }
}

/* =========================================
   ปรับแต่งเฉลยเกมคณิตศาสตร์ (Math Solution)
   ========================================= */
#math-solution-text {
    font-size: 10px !important;   /* บังคับให้ตัวเล็ก 10px */
    font-weight: bold;            /* ตัวหนา */
    margin-top: 15px;             /* ขยับลงมาห่างจากปุ่มคำตอบหน่อย */
    text-align: center;           /* จัดกึ่งกลาง */
    white-space: nowrap;          /* ห้ามขึ้นบรรทัดใหม่ (ให้ยาวต่อกันไปเลย) */
    text-shadow: 1px 1px 0 #fff;  /* เพิ่มขอบขาวนิดๆ ให้อ่านง่ายขึ้น */
}

/* =========================================
   12. Achievements & Popup Styles (ส่วนเพิ่มใหม่)
   ========================================= */

/* กล่องรวมรายการ (กรอบใหญ่) */
.achieve-box {
    background: #fff;
    border: 4px solid #e58e26;
    border-radius: 10px;
    padding: 10px;
    width: 260px; /* กว้างพอประมาณ */
    height: 300px; /* สูงคงที่ */
    display: flex;
    flex-direction: column;
}

/* ตัวลิสต์รายการ (ให้เลื่อนขึ้นลงได้) */
.achieve-list {
    flex: 1;
    overflow-y: auto; /* ถ้าล้นให้มี Scrollbar */
    padding-right: 5px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* ปรับแต่ง Scrollbar ให้ดูน่ารัก (เฉพาะ Chrome/Edge) */
.achieve-list::-webkit-scrollbar { width: 8px; }
.achieve-list::-webkit-scrollbar-track { background: #ffeaa7; border-radius: 4px; }
.achieve-list::-webkit-scrollbar-thumb { background: #e58e26; border-radius: 4px; }

/* --- หน้าตาของ "แถบถ้วยรางวัล" แต่ละอัน --- */
.achieve-item {
    background: #f1f2f6;
    border: 2px solid #ccc;
    border-radius: 8px;
    padding: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
    position: relative; /* เพื่อให้วางกุญแจล็อกได้ */
    transition: 0.2s;
}

/* ไอคอนถ้วย/รูปภาพ */
.ach-icon {
    font-size: 24px;
    min-width: 40px;
    text-align: center;
}

/* ข้อความในแถบ */
.ach-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    text-align: left;
}
.ach-title { font-size: 10px; font-weight: bold; color: #2d3436; margin-bottom: 2px; }
.ach-desc { font-size: 8px; color: #636e72; }

/* --- 🔒 สไตล์ตอนที่ยัง "ล็อกอยู่" (Locked) --- */
.achieve-item.locked {
    background: #dfe6e9; /* สีเทาๆ */
    border-color: #b2bec3;
    opacity: 0.7; /* จางลงนิดนึง */
    cursor: not-allowed;
}

/* ทำให้ข้อความจางลงไปอีก ตามที่พี่ขอ */
.achieve-item.locked .ach-info,
.achieve-item.locked .ach-icon {
    opacity: 0.3; 
    filter: blur(0.5px); /* เบลอนิดๆ ให้รู้ว่ายังไม่ได้ */
}

/* รูปแม่กุญแจ 🔒 แปะทับตรงกลาง */
.achieve-item.locked::after {
    content: "🔒";
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    font-size: 24px;
    text-shadow: 2px 2px 0 #fff;
    opacity: 1 !important; /* กุญแจต้องชัด! */
    z-index: 10;
}

/* --- ✨ สไตล์ตอน "ปลดล็อกแล้ว" (Unlocked) --- */
.achieve-item.unlocked {
    background: #fff;
    border-color: #f1c40f; /* ขอบสีทอง */
    box-shadow: 0 2px 0 #f39c12;
}
.achieve-item.unlocked .ach-title { color: #d35400; }
.achieve-item.unlocked .ach-icon { animation: bounce 2s infinite; }

/* --- 🔔 Pop-up แจ้งเตือน (เด้งมาจากข้างบน) --- */
.achieve-popup {
    position: fixed;
    top: -100px; /* ซ่อนไว้เหนือจอ */
    left: 50%;
    transform: translateX(-50%);
    background: #fff;
    border: 3px solid #f1c40f;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    border-radius: 50px;
    padding: 10px 25px;
    display: flex;
    align-items: center;
    gap: 15px;
    z-index: 3000;
    transition: top 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275); /* เด้งดึ๋ง */
    min-width: 250px;
}

/* สั่งให้เด้งลงมา */
.achieve-popup.show { top: 30px; }

.popup-icon { font-size: 30px; animation: bounce 1s infinite; }
.popup-text { text-align: left; }
.popup-title { font-size: 10px; font-weight: bold; color: #f39c12; text-transform: uppercase; }
.popup-name { font-size: 12px; font-weight: bold; color: #2d3436; margin-top: 2px; }

/* =========================================
   13. Thai Font Fix (แก้สระจมภาษาไทย)
   ========================================= */

/* ถ้าเป็นภาษาไทย (data-lang="th") ให้ขยายใหญ่ขึ้น */
.achieve-list[data-lang="th"] .ach-title {
    font-size: 12px !important; /* จากเดิม 10px */
    line-height: 1.4;
    margin-bottom: 4px; /* เพิ่มระยะห่างบรรทัดนิดนึง */
}

.achieve-list[data-lang="th"] .ach-desc {
    font-size: 10px !important; /* จากเดิม 8px */
    color: #636e72;
    font-weight: bold; /* เพิ่มความหนานิดนึงจะอ่านง่ายขึ้น */
}

/* =========================================
   14. Mute Button Style (ปุ่มปิดเสียง)
   ========================================= */
.mute-btn {
    background: none;       /* เอาพื้นหลังออก */
    border: none;           /* เอาขอบออก */
    font-size: 32px;        /* 👈 ขยายขนาดตรงนี้ (จากเดิมเล็กๆ) */
    cursor: pointer;
    line-height: 1;         /* จัดบรรทัดให้พอดี */
    
    /* เพิ่มเงาให้ตัวไอคอนเด่นขึ้นมาจากพื้นหลัง */
    filter: drop-shadow(2px 2px 0px rgba(0,0,0,0.5));
    transition: transform 0.1s; /* เอฟเฟกต์กดแล้วยุบ */
}

.mute-btn:active {
    transform: scale(0.9);  /* กดแล้วยุบนิดนึง */
}

// ==========================================
// 🔇 ระบบปุ่มปิดเสียง (Mute Button Logic)
// ==========================================

let isGameMusicMuted = false; // ตัวแปรจำค่าว่าปิดเสียงอยู่ไหม

function toggleSound() {
    // 1. สลับสถานะ (จริง <-> เท็จ)
    isGameMusicMuted = !isGameMusicMuted;

    // 2. จัดการตัวเพลง (เฉพาะเพลงในเกม game_bgm)
    const gameAudio = document.getElementById('snd-game_bgm');
    if (gameAudio) {
        gameAudio.muted = isGameMusicMuted; // สั่งใบ้เสียง/เปิดเสียง
    }

    // 3. จัดการเปลี่ยนรูปไอคอน (🔊 <-> 🔇)
    // หาปุ่มที่มี class="mute-btn" ทั้งหมด (เผื่อมีหลายที่)
    const buttons = document.querySelectorAll('.mute-btn');
    buttons.forEach(btn => {
        if (isGameMusicMuted) {
            btn.innerText = '🔇'; // รูปปิดเสียง (กากบาท)
            btn.style.opacity = '0.6'; // ทำให้จางลงนิดนึงจะได้รู้ว่าปิด
        } else {
            btn.innerText = '🔊'; // รูปเปิดเสียงปกติ
            btn.style.opacity = '1'; // กลับมาสว่าง
        }
    });

/* บังคับขยายตัวหนังสือในกล่องถ้วยรางวัลทั้งหมด */
#achieve-list-container div {
    font-size: 16px !important; /* ตัวหนังสือปกติให้ใหญ่ขึ้น */
}

/* ถ้ามีหัวข้อ (ตัวหนา) ในนั้น ให้ใหญ่เบิ้มๆ */
#achieve-list-container strong, 
#achieve-list-container h3, 
#achieve-list-container h4 {
    font-size: 20px !important;
    margin-bottom: 5px;
}

/* ขยายไอคอนข้างหน้าด้วย */
#achieve-list-container span {
    font-size: 24px !important; 
}

/* --- แก้ไขขนาดตัวหนังสือหน้ารางวัล (ท่าไม้ตาย!) --- */

/* 1. หัวข้อรางวัล (เช่น เซียนเป่ายิ้งฉุบ) */
.ach-title, .achieve-name, .achievement-title { 
    font-size: 20px !important; 
    font-weight: bold !important;
    margin-bottom: 5px !important;
}

/* 2. รายละเอียด (เช่น ชนะ 5 ครั้ง) */
.ach-desc, .achieve-desc, .achievement-desc { 
    font-size: 16px !important; 
    color: #555 !important;
}

/* 3. ไอคอนข้างหน้า */
.ach-icon, .achieve-icon {
    font-size: 28px !important;
    margin-right: 15px !important;
}

/* 4. ขยายกล่องให้สูงขึ้นหน่อย ตัวหนังสือจะได้ไม่เบียด */
.achieve-item, .achievement-item {
    padding: 15px !important;
}

/* --- แก้ไขขนาดตัวหนังสือหน้ารางวัล (อันนี้ชัวร์ 100% ค่ะ!) --- */

/* กล่องแต่ละรางวัล */
.achieve-item {
    padding: 15px !important;  /* ขยายพื้นที่ในกล่อง */
}

/* 1. ไอคอนด้านซ้าย */
.ach-icon {
    font-size: 30px !important; /* ขยายไอคอนให้ใหญ่ */
    width: 50px !important;     /* เพิ่มพื้นที่วางไอคอน */
}

/* 2. ชื่อรางวัล (ตัวหนา) */
.ach-title {
    font-size: 18px !important; /* ขยายชื่อรางวัล */
    font-weight: bold;
    margin-bottom: 5px;
}

/* 3. คำอธิบายรางวัล (ตัวเล็ก) */
.ach-desc {
    font-size: 14px !important; /* ขยายคำอธิบาย */
    color: #555;
}

/* === บังคับขนาดตัวหนังสือในกล่องข้อความ === */
#message-log {
    font-size: 16px !important; /* ปรับตัวเลขตรงนี้ได้ตามใจชอบ */
    line-height: 1.6 !important; /* เพิ่มระยะห่างบรรทัดให้อ่านง่าย */
    font-weight: normal !important;
}