/* ตัวแปรสีสำหรับการจัดการที่ง่ายขึ้น */
:root {
  --primary-green: #9acd32;
  --dark-green: #6b8e23;
  --light-green: #adff2f;
  --accent-red: #ff4d4d;
  --accent-blue: #4d79ff;
  --accent-yellow: #ffd700;
  --accent-purple: #b84dff;
  --glass-bg: rgba(255, 255, 255, 0.2);
  --glass-border: rgba(255, 255, 255, 0.18);
  --dark-bg: rgba(30, 30, 30, 0.8);
  --darker-bg: rgba(17, 17, 17, 0.6);
}

/* พื้นฐาน */
* {
  box-sizing: border-box;
}

body {
  background: #222 url('snakebg.png') no-repeat center center fixed;
  background-size: cover;
  color: white;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  text-align: center;
  margin: 0;
  padding: 10px;
  overflow: hidden;
  touch-action: none;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ป้องกันการซูมบนมือถือ */
@media (max-width: 768px) {
  body {
    touch-action: manipulation;
    padding: 5px;
    font-size: 14px;
  }
}

/* หน้าจอ */
.screen {
  display: none;
  flex: 1;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 100%;
}

.screen.active {
  display: flex;
}

/* หน้าจอเริ่มเกม */
#startScreen {
  background: rgba(0, 0, 0, 0.7);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1000;
}

.start-container {
  background: var(--dark-bg);
  padding: 40px;
  border-radius: 20px;
  -webkit-backdrop-filter: blur(15px);
  backdrop-filter: blur(15px);
  border: 1px solid var(--glass-border);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  max-width: 500px;
  width: 90%;
  margin: 20px;
}

@media (max-width: 768px) {
  .start-container {
    padding: 20px;
    margin: 10px;
  }
}

.start-container h1 {
  font-size: 3rem;
  margin-bottom: 30px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  background: linear-gradient(to right, var(--primary-green), var(--light-green));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

@media (max-width: 768px) {
  .start-container h1 {
    font-size: 2rem;
  }
}

/* อนิเมชั่นงู */
.snake-animation {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 30px 0;
  gap: 5px;
}

.snake-segment {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary-green), var(--dark-green));
  animation: snakeMove 2s infinite;
}

.snake-segment.head {
  background: linear-gradient(135deg, var(--light-green), var(--primary-green));
  position: relative;
}

.snake-segment.head::before {
  content: '';
  position: absolute;
  width: 8px;
  height: 8px;
  background: white;
  border-radius: 50%;
  top: 6px;
  left: 6px;
}

.snake-segment.head::after {
  content: '';
  position: absolute;
  width: 8px;
  height: 8px;
  background: white;
  border-radius: 50%;
  top: 6px;
  right: 6px;
}

@keyframes snakeMove {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(10px); }
}

/* เมนูเลือกโหมดเกม */
.game-mode-selector,
.difficulty-selector,
.sound-settings {
  margin: 15px 0;
  padding: 15px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  text-align: center;
}

.game-mode-selector h3,
.difficulty-selector h3,
.sound-settings h3 {
  margin-top: 0;
  color: var(--primary-green);
  margin-bottom: 15px;
}

.mode-buttons,
.difficulty-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.mode-btn,
.difficulty-btn {
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 20px;
  color: white;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 0.9rem;
}

.mode-btn.active,
.difficulty-btn.active {
  background: var(--primary-green);
  border-color: var(--light-green);
  transform: scale(1.05);
}

.mode-btn:hover,
.difficulty-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* การตั้งค่าเสียง */
.volume-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

.volume-controls label {
  font-size: 0.9rem;
  margin-bottom: 5px;
}

.volume-controls input[type="range"] {
  width: 80%;
  max-width: 200px;
}

/* สถิติผู้เล่น */
.player-stats {
  display: flex;
  justify-content: space-around;
  margin: 15px 0;
  flex-wrap: wrap;
  gap: 15px;
}

.stat-item {
  text-align: center;
  background: rgba(255, 255, 255, 0.1);
  padding: 10px 15px;
  border-radius: 10px;
  min-width: 120px;
}

.stat-label {
  display: block;
  font-size: 0.9rem;
  opacity: 0.8;
  margin-bottom: 5px;
}

.stat-value {
  font-size: 1.2rem;
  font-weight: bold;
  color: var(--light-green);
}

/* คำแนะนำ */
.instructions {
  background: rgba(255, 255, 255, 0.1);
  padding: 20px;
  border-radius: 15px;
  margin: 20px 0;
  text-align: left;
}

.instructions h3 {
  margin-top: 0;
  color: var(--primary-green);
  text-align: center;
}

.instructions p {
  margin: 8px 0;
  font-size: 0.9rem;
}

/* ปุ่มเริ่มเกม */
.start-button {
  padding: 15px 40px;
  font-size: 1.3rem;
  background: linear-gradient(135deg, var(--primary-green), var(--dark-green));
  border: none;
  border-radius: 25px;
  color: white;
  cursor: pointer;
  transition: all 0.3s ease;
  margin-top: 20px;
  box-shadow: 0 4px 15px rgba(154, 205, 50, 0.3);
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  display: block;
  width: 100%;
  max-width: 300px;
  margin-left: auto;
  margin-right: auto;
}

.start-button:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 20px rgba(154, 205, 50, 0.4);
  background: linear-gradient(135deg, var(--light-green), var(--primary-green));
}

.start-button:focus {
  outline: 2px solid var(--primary-green);
  outline-offset: 2px;
}

.start-button.pulse {
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

/* หัวข้อเกม */
h1 {
  font-size: 2.2rem;
  margin: 10px 0;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  background: linear-gradient(to right, var(--primary-green), var(--light-green));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* พื้นหลังกระจกสำหรับ Canvas */
.canvas-container {
  position: relative;
  display: inline-block;
}

canvas {
  background: rgba(30, 30, 30, 0.6); 
  display: block;
  margin: auto;
  max-width: 100%;
  height: auto;
  border-radius: 20px;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.5);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
}

/* ปุ่มแบบกระจก */
button {
  padding: 12px 24px;
  font-size: 1rem;
  margin: 5px;
  cursor: pointer;
  border-radius: 16px;
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: white;
  border: 1px solid var(--glass-border);
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  transition: all 0.3s ease;
  font-weight: bold;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

button:hover {
  background: rgba(255, 255, 255, 0.4);
  transform: translateY(-2px);
  box-shadow: 0 8px 15px rgba(0, 0, 0, 0.2);
}

button:focus {
  outline: 2px solid var(--primary-green);
  outline-offset: 2px;
}

@media (max-width: 768px) {
  button {
    width: 90%;
    max-width: 300px;
  }
}

/* แถบบน */
#topBar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  background: var(--darker-bg);
  border-bottom: 2px solid rgba(51, 51, 51, 0.5);
  border-radius: 15px;
  margin-bottom: 10px;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
  width: 100%;
  max-width: 800px;
}

@media (max-width: 768px) {
  #topBar {
    flex-direction: column;
    gap: 10px;
    padding: 15px;
  }
}

#topBar .left { 
  text-align: left;
  flex: 1;
}

#topBar .right { 
  text-align: right;
  flex: 1;
}

#topBar h2 { 
  margin: 0; 
  font-size: 24px; 
  color: var(--accent-red);
  text-shadow: 0 0 10px rgba(255, 77, 77, 0.7);
}

.current-mode {
  margin-top: 5px;
}

.current-mode span {
  display: block;
  font-size: 0.9rem;
  opacity: 0.8;
}

.top-buttons {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 10px;
}

/* การแสดงผลคะแนน */
.score-display {
  background: rgba(0, 0, 0, 0.5);
  padding: 10px 20px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.high-score {
  color: gold;
  text-shadow: 0 0 5px rgba(255, 215, 0, 0.5);
  margin: 5px 0;
}

.current-score {
  color: var(--primary-green);
  margin: 5px 0;
}

/* แถบสถานะ */
.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  max-width: 800px;
  margin: 10px 0;
  padding: 0 10px;
}

.power-up-indicator {
  background: rgba(255, 255, 255, 0.1);
  padding: 5px 15px;
  border-radius: 20px;
  font-size: 0.9rem;
}

/* ปรับ Mobile Controls */
#mobile-controls {
  width: 160px;
  height: 160px;
  position: fixed;
  left: 50%;
  bottom: 40px; /* ยกขึ้นจากขอบล่าง ปรับได้ */
  transform: translateX(-50%);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0);
  border: none;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: none;
  box-shadow: none;
  user-select: none;
  touch-action: none;
  z-index: 50;
  margin: 0;
}



.arrow {
  position: absolute;
  width: 50px;
  height: 50px;
  background: rgba(85, 107, 47, 0.8);
  color: white;
  border: 2px solid rgba(154, 205, 50, 0.5);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  transition: all 0.2s ease;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.arrow:hover, .arrow:active {
  background: rgba(154, 205, 50, 0.9);
  transform: scale(1.1);
}

.arrow:active {
  transform: scale(0.95);
}

#upBtn { top: 10px; left: 55px; }
#downBtn { bottom: 10px; left: 55px; }
#leftBtn { left: 10px; top: 55px; }
#rightBtn { right: 10px; top: 55px; }

/* สถานะเกม */
#status {
  font-size: 1.2rem;
  margin: 10px 0;
  height: 24px;
  font-weight: bold;
}

.loading-dots::after {
  content: '';
  animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
  0%, 20% { content: '.'; }
  40% { content: '..'; }
  60% { content: '...'; }
  80%, 100% { content: ''; }
}

/* คำแนะนำ */
#instructions {
  margin: 10px 0;
  font-size: 0.9rem;
  opacity: 0.8;
}

/* คอนเทนเนอร์ปุ่ม */
.button-container {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

@media (max-width: 768px) {
  .button-container {
    flex-direction: column;
    align-items: center;
  }
}

/* ปุ่ม Fullscreen */
#fullscreenBtn {
  padding: 10px 20px;
  font-size: 1rem;
  cursor: pointer;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 14px;
  color: #fff;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  transition: background 0.25s, transform 0.25s;
  font-weight: bold;
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}

#fullscreenBtn:hover {
  background: rgba(255, 255, 255, 0.4);
  transform: translateY(-2px);
}

/* ปุ่มรีสตาร์ทและกลับบ้าน */
#restartBtn, #homeBtn {
  display: none;
  padding: 12px 24px;
  background: rgba(255, 255, 255, 0.25);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 16px;
  color: white;
  font-weight: bold;
  cursor: pointer;
  transition: 0.3s;
}

#restartBtn:hover, #homeBtn:hover {
  background: rgba(255, 255, 255, 0.4);
  transform: translateY(-2px);
}

/* สไตล์สำหรับเกมโอเวอร์ */
.game-over-message {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.8);
  padding: 30px;
  border-radius: 20px;
  text-align: center;
  -webkit-backdrop-filter: blur(15px);
  backdrop-filter: blur(15px);
  border: 2px solid rgba(255, 77, 77, 0.5);
  box-shadow: 0 0 30px rgba(255, 77, 77, 0.3);
  z-index: 100;
  min-width: 300px;
}

.game-over-message h2 {
  color: var(--accent-red);
  font-size: 2.5rem;
  margin-bottom: 20px;
  text-shadow: 0 0 10px rgba(255, 77, 77, 0.7);
}

.game-over-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 20px;
}

/* เมนูตั้งค่าในเกม */
.settings-menu {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.settings-content {
  background: var(--dark-bg);
  padding: 30px;
  border-radius: 20px;
  -webkit-backdrop-filter: blur(15px);
  backdrop-filter: blur(15px);
  border: 1px solid var(--glass-border);
  max-width: 400px;
  width: 90%;
}

.settings-content h3 {
  margin-top: 0;
  color: var(--primary-green);
  text-align: center;
}

.setting-group {
  margin: 15px 0;
  text-align: left;
}

.setting-group label {
  display: block;
  margin-bottom: 5px;
}

.setting-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 20px;
}

/* ฟุตเตอร์ */
footer {
  margin-top: 30px; 
  padding: 20px; 
  background: var(--darker-bg);
  color: white;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-top: 2px solid rgba(51, 51, 51, 0.5);
  border-radius: 15px;
  width: 100%;
}

.footer-content {
  display: flex;
  justify-content: space-around;
  align-items: center;
  flex-wrap: wrap;
  gap: 20px;
}

.footer-section {
  flex: 1;
  min-width: 200px;
}

.stars-container {
  margin: 10px 0;
}

/* ดาวให้คะแนน */
.star {
  font-size: 30px;
  cursor: pointer;
  color: gray;
  transition: transform 0.2s;
  text-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
}

.star.selected { 
  color: gold; 
  text-shadow: 0 0 10px gold;
}
.star:hover { 
  transform: scale(1.2); 
  color: gold;
}

.social-links {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.social-btn {
  padding: 8px 16px;
  font-size: 0.9rem;
}

/* หน้าต่างโมดอล */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-content {
  background: var(--dark-bg);
  padding: 30px;
  border-radius: 20px;
  -webkit-backdrop-filter: blur(15px);
  backdrop-filter: blur(15px);
  border: 1px solid var(--glass-border);
  max-width: 500px;
  width: 90%;
  position: relative;
}

.close {
  position: absolute;
  top: 15px;
  right: 15px;
  font-size: 2rem;
  cursor: pointer;
  color: var(--accent-red);
}

.credits-info {
  text-align: left;
}

.feature-list ul {
  text-align: left;
  padding-left: 20px;
}

.feature-list li {
  margin: 5px 0;
}

/* การเข้าถึงสำหรับผู้ใช้พิการ */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ปรับปรุงสำหรับอุปกรณ์ขนาดเล็กมาก */
@media (max-width: 480px) {
  .footer-content {
    flex-direction: column;
    text-align: center;
  }
  
  .game-over-buttons {
    flex-direction: column;
  }
  
  .settings-content {
    padding: 20px;
  }
  
  .modal-content {
    padding: 20px;
  }
  
  .start-button {
    padding: 12px 30px;
    font-size: 1.1rem;
  }
  
  .snake-animation {
    margin: 20px 0;
  }
  
  .snake-segment {
    width: 25px;
    height: 25px;
  }
}