body {
  font-family: sans-serif;
  text-align: center;
  background: #000;
  color: #fff;
  margin: 0;
  padding: 0;
  overflow-x: hidden; /* Prevent horizontal scroll */
}

#game {
  display: grid;
  grid-template-columns: repeat(20, 1fr); /* flexible columns */
  grid-template-rows: repeat(20, 1fr); /* flexible rows */
  gap: 0px;
  background: #222;
  margin: 20px auto;
  max-width: 100vw; /* never wider than viewport */
  aspect-ratio: 1 / 1; /* keep square shape */
  width: 90vw; /* take 90% of viewport width on small screens */
  height: auto; /* height auto to keep aspect ratio */
  max-height: 90vh; /* don't overflow vertically on smaller screens */
  touch-action: manipulation; /* improve touch responsiveness */
  max-width: 600px;
}

.cell {
  /* cells fill grid equally and stay square */
  width: 100%;
  height: 0;
  padding-bottom: 100%; /* 1:1 aspect ratio square */
  position: relative;
}

.wall {
  background: #444;
}

.dot {
  background: transparent;
  position: relative;
}

.dot::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20%;
  height: 20%;
  max-width: 5px;
  max-height: 5px;
  background: yellow;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.player-image, .enemy-image {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  object-fit: contain;
  z-index: 2;
}

.player-image.flipped, .enemy-image.flipped {
  transform: scaleX(-1);
}

.overlay-message {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 48px;
  color: white;
  background-color: rgba(0, 0, 0, 0.7);
  padding: 20px 40px;
  border-radius: 10px;
  display: none;
  z-index: 1000;
  text-align: center;
}

#dpad {
  width: 120px;
  margin: 10px auto 30px;
  user-select: none;
}

.dpad-button {
  font-size: 30px;
  width: 50px;
  height: 50px;
  line-height:50px;
  text-align:center;
  margin: 4px;
  background: #444;
  border: none;
  border-radius: 6px;
  color: white;
  cursor: pointer;
  transition: background-color 0.2s;
  outline: none;
}

.dpad-button:active {
  background-color: #888;
}

/* Layout the buttons in a cross shape */
#dpad {
  display: grid;
  grid-template-columns: 40px 40px 40px;
  grid-template-rows: 40px 40px 40px;
  justify-content: center;
  align-items: center;
  gap: 8px;
}

.dpadWrapper {
  width: 100%;
  height: auto;
  background-color: transparent;
}

/* Hide dpadWrapper in landscape */
@media (orientation: landscape) {
  .dpadWrapper {
    display: none;
  }
}

/* Show dpadWrapper in portrait */
@media (orientation: portrait) {
  .dpadWrapper {
    display: block;
  }
}

#up {
  grid-column: 2 / 3;
  grid-row: 1 / 2;
}

#left {
  grid-column: 1 / 2;
  grid-row: 2 / 3;
}

#down {
  grid-column: 2 / 3;
  grid-row: 3 / 4;
}

#right {
  grid-column: 3 / 4;
  grid-row: 2 / 3;
}
#game-over-screen {
  position: fixed;
  top: 15%;
  left: 50%;
  transform: translateX(-50%);
  background: #111;
  color: #fff;
  padding: 30px;
  border-radius: 10px;
  text-align: center;
  z-index: 999;
}

@media (orientation: portrait) {
  #game-over-screen {
    top: 7%;
    padding:10px;
    padding-bottom:10px;
    width:80vw !important;
  }
}

#game-over-screen button {
  padding: 10px 20px;
  font-size: 18px;  
  cursor: pointer;
}
@media (orientation: portrait) {
  h2 {
    font-size:1em;
    margin-top: 0px !important;
    padding-top: -30px !important;
  }
  #final-score-text{
    font-size:24px;
  }
  #high-score-message{
    font-size:24px;
  }
}
.desktopText{
  display: block;
}
.mobileText {
  display: none;
}

/* Show only in portrait orientation */
@media screen and (orientation: portrait) {
  .mobileText {
    display: block;
  }
  .desktopText{
  display: none;
}
}

/* Optionally, hide again in landscape */
@media screen and (orientation: landscape) {
  .mobileText {
    display: none;
  }
  .desktopText{
  display: block;
}
}