html,
body {
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  box-sizing: border-box;
  font-family: "Poppins", Arial, sans-serif;
}

body {
  color: rgb(250, 249, 249);
  background: #222;
  font-size: 22px;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

.menu_icon {
  width: 1.5em;
  height: 1.5em;
  vertical-align: middle;
  margin-right: 0.5em;
}
.main_div {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  margin: 0;
  align-items: center;
  justify-content: center;
  padding-top: 5vh;
  padding-bottom: 5vh; /* 5% vertical padding */
  box-sizing: border-box;
}

.main_div.hidden {
  visibility: hidden;
}

.score_div {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  width: min(600px, 95vw);
  max-width: 600px;
  background-color: rgb(57, 80, 66);
  border-radius: 10px 10px 0px 0px;
  border-style: solid;
  border-width: 2px;
  border-color: rgb(57, 80, 66);
  position: relative;
}

.sound-toggle {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 1.2rem;
  padding: 0;
  margin: 0;
  cursor: pointer;
  transition: all 0.2s ease;
}

.sound-toggle:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translate(-50%, -50%) scale(1.1);
}

.controls-info {
  background: rgba(81, 152, 114, 0.2);
  padding: 1em;
  border-radius: 8px;
  font-size: 0.85rem;
  line-height: 1.6;
}

.controls-info p {
  margin: 0.3em 0;
}

.controls-info strong {
  font-size: 1rem;
  color: #519872;
}

.highest_score {
  padding: 0px 20px 0px 0px;
}
.current_score {
  padding: 0px 0px 0px 20px;
}
.score_div div {
  display: flex;
  align-items: center;
  justify-content: center;
}
.game_board {
  display: grid;
  width: min(600px, 95vw);
  height: min(600px, 95vw);
  max-width: 600px;
  max-height: 600px;
  aspect-ratio: 1 / 1; /* Keep it square */
  background-color: rgb(30, 47, 29);
  border-radius: 0px 0px 10px 10px;
  border-style: solid;
  border-width: 2px;
  border-color: rgb(57, 80, 66);
  touch-action: none; /* Prevent default touch actions for better swipe detection */
  user-select: none; /* Prevent text selection during gameplay */
}

/* Responsive adjustments for mobile */
@media (max-width: 650px) {
  body {
    font-size: 18px;
  }

  .current_score,
  .highest_score {
    font-size: 0.9rem;
  }

  .sound-toggle {
    width: 35px;
    height: 35px;
    font-size: 1rem;
  }

  .controls-info {
    font-size: 0.75rem;
    padding: 0.8em;
  }

  .menu-content h1 {
    font-size: 1.8rem;
  }
}

@media (max-width: 400px) {
  body {
    font-size: 16px;
  }

  .current_score,
  .highest_score {
    font-size: 0.8rem;
    padding: 0 10px;
  }

  .sound-toggle {
    width: 30px;
    height: 30px;
    font-size: 0.9rem;
  }
}

/* Landscape mobile orientation */
@media (max-height: 500px) and (orientation: landscape) {
  .main_div {
    padding-top: 2vh;
    padding-bottom: 2vh;
  }

  .game_board {
    height: min(85vh, 95vw);
    width: min(85vh, 95vw);
  }

  .score_div {
    width: min(85vh, 95vw);
  }
}

.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: #222;
  justify-content: center;
  align-items: center;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.modal.show {
  display: flex;
  animation: fadeIn 0.3s ease forwards;
}

.game_over_title {
  font-size: 4rem;
  color: #d82828;
  margin-bottom: 1rem;
  margin-bottom: 40px;
  animation: shake 0.5s ease;
}

.modal-content {
  background: #222;
  color: rgb(255, 255, 255);
  padding: 2em 3em;
  border-radius: 8px;
  text-align: center;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from {
    transform: translateY(30px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* Shake animation */
@keyframes shake {
  0% {
    transform: translate(1px, 1px) rotate(0deg);
  }
  10% {
    transform: translate(-1px, -2px) rotate(-1deg);
  }
  20% {
    transform: translate(-3px, 0px) rotate(1deg);
  }
  30% {
    transform: translate(3px, 2px) rotate(0deg);
  }
  40% {
    transform: translate(1px, -1px) rotate(1deg);
  }
  50% {
    transform: translate(-1px, 2px) rotate(-1deg);
  }
  60% {
    transform: translate(-3px, 1px) rotate(0deg);
  }
  70% {
    transform: translate(3px, 1px) rotate(-1deg);
  }
  80% {
    transform: translate(-1px, -1px) rotate(1deg);
  }
  90% {
    transform: translate(1px, 2px) rotate(0deg);
  }
  100% {
    transform: translate(1px, -2px) rotate(-1deg);
  }
}

.shake {
  animation: shake 0.5s;
  animation-timing-function: ease-in-out;
}

.head {
  overflow: hidden;
  background-image: url("images/head.png");
  background-size: 100% 100%;
  background-position: center;
  background-repeat: no-repeat;
}

.tail {
  overflow: hidden;
  background-image: url("images/tail.png");
  background-size: 100% 100%;
  background-position: center;
  background-repeat: no-repeat;
}

.vertical {
  overflow: hidden;
  background-image: url("images/body_v.png");
  background-size: 100% 100%;
  background-position: center;
  background-repeat: no-repeat;
}
.horizontal {
  overflow: hidden;
  background-image: url("images/body_h.png");
  background-size: 100% 100%;
  background-position: center;
  background-repeat: no-repeat;
}
.corner {
  overflow: hidden;
  background-image: url("images/body-corner.png");
  background-size: 100% 100%;
  background-position: center;
  background-repeat: no-repeat;
}

.foodcase {
  overflow: hidden;
  background-image: url("images/food.png");
  background-size: 100% 100%;
  background-position: center;
  background-repeat: no-repeat;
}

.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(5px);
  z-index: 1000;
  display: none;
  justify-content: center;
  align-items: center;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.overlay.show {
  display: flex;
  animation: fadeIn 0.3s ease forwards;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
.menu-content,
.pause-content {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 20px;
  align-items: center;
  background: #222;
  padding: 2rem 3rem;
  border-radius: 12px;
  color: #f6f6f6;
  text-align: center;
  width: 100%;
  height: 100%;
}
.menu-content h1 {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
.pause-content div {
  display: flex;
}
button {
  padding: 0.8em 1.5em;
  margin: 0.6em;
  border: none;
  background: #519872;
  color: white;
  font-size: 1rem;
  border-radius: 6px;
}
button:hover {
  background: #36735c;
  cursor: pointer;
}
select {
  font-size: 1rem;
  padding: 0.4em;
}
.highest_score_icon,
.play_icon,
.quit_to_menu_icon,
.pause_icon {
  width: 1.5em;
  height: 1.5em;
  vertical-align: middle;
  margin-right: 0.5em;
  color: #f6f6f6;
}
