html, body {
  height: 100vh;
  margin: 0;
  padding: 0;
}

body {
  background: #3666F1;
  color: #fff;
  font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue",
    Helvetica, Arial, "Lucida Grande", sans-serif;
  font-weight: 300;
  touch-action: none;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
  box-sizing: border-box;
}

#game {
  width: 100%;
  height: calc(100vh - 40px);
  position: relative;
  touch-action: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

#game canvas {
  object-fit: contain;
  image-rendering: -moz-crisp-edges;
  image-rendering: -webkit-crisp-edges;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  width: 100%;
  max-width: min(80vh, 90vw);
  height: auto;
  border-radius: 10px !important;
  overflow: hidden;
}

#controller {
  display: flex;  /* Show by default */
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 20px;
  height: auto;
  box-sizing: border-box;
  width: 100%;
  padding: 0;
  transition: all 0.5s ease-out;
  filter: blur(0);
  opacity: 1;
}

#keyboard-hint {
  display: none;  /* Hide by default */
  text-align: center;
  margin-top: 40px;
  font-size: 20px;
  color: #CBF474;
  letter-spacing: 1px;
  font-weight: bold;
}

/* Desktop-only styles - based on device characteristics only */
@media (hover: hover) and (pointer: fine) {
  #controller {
    display: none !important;
  }
  
  #keyboard-hint {
    display: block;
  }
}

.controls_row {
  display: flex;
  justify-content: space-between;
  width: 100%;
  position: relative;
  margin: 0px 0;
  box-sizing: border-box;
}

#controller_dpad {
  position: relative;
  width: 150px;
  height: 180px;
  margin: 0;
  display: flex;
  justify-content: center;
  align-items: center;
}

#controller_dpad:before {
  content: "";
  display: block;
  width: 46px;
  height: 46px;
  background: #CBF474;
  background: radial-gradient(
    ellipse at center,
    #CBF474 0%,
    #CBF474 59%,
    #CBF474 60%
  );
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

#controller_left {
  position: absolute;
  left: calc(50% - 69px);  
  top: 50%;
  transform: translateY(-50%);
  width: 46px;
  height: 46px;
  background: #CBF474;
  background: radial-gradient(ellipse at center, #CBF474 0%, #CBF474 80%);
  border-top-left-radius: 4px;
  border-bottom-left-radius: 4px;
}

#controller_right {
  position: absolute;
  right: calc(50% - 69px);  
  top: 50%;
  transform: translateY(-50%);
  width: 46px;
  height: 46px;
  background: #CBF474;
  background: radial-gradient(ellipse at center, #CBF474 0%, #CBF474 80%);
  border-top-right-radius: 4px;
  border-bottom-right-radius: 4px;
}

#controller_up {
  position: absolute;
  left: 50%;
  top: calc(50% - 69px);  
  transform: translateX(-50%);
  width: 46px;
  height: 46px;
  background: #CBF474;
  background: radial-gradient(ellipse at center, #CBF474 0%, #CBF474 80%);
  border-top-left-radius: 4px;
  border-top-right-radius: 4px;
}

#controller_down {
  position: absolute;
  left: 50%;
  bottom: calc(50% - 69px);  
  transform: translateX(-50%);
  width: 46px;
  height: 46px;
  background: #CBF474;
  background: radial-gradient(ellipse at center, #CBF474 0%, #CBF474 80%);
  border-bottom-left-radius: 4px;
  border-bottom-right-radius: 4px;
}

#action_buttons {
  position: relative;
  width: 150px;
  height: 180px;
  margin: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 24px 0px;
  box-sizing: border-box;
}

.action_button_container {
  width: 100%;
  display: flex;
}

#button_b_container {
  justify-content: flex-start;
}

#button_a_container {
  justify-content: flex-end;
}

#controller_b, #controller_a {
  position: static;  /* Remove absolute positioning */
}

#menu_buttons {
  display: flex;
  gap: 20px;
  justify-content: center;
  margin: 15px 0 5px 0;
  width: 100%;
  position: relative;
}

#controller_start {
  position: static;
}

#controller_select {
  position: static;
}

@media only screen and (max-device-width: 812px) and (orientation: portrait) {
  html, body {
    height: auto;
    overflow: auto;
  }

  #game {
    height: auto;
    justify-content: flex-start;
  }

  body {
    overflow: auto;
  }

  #game canvas {
    margin: 0;
    display: block;
    width: 100% !important;
    height: auto !important;
  }

  #controller {
    display: flex;
    position: relative;
    margin-top: 20px;
    width: 100%;
    touch-action: none;
  }
  
  .controls_row {
    max-width: 100%;
  }

  #controller_dpad,
  #action_buttons {
    margin: 0;
  }
}

@media only screen and (max-width: 640px) {
  #game canvas {
    margin-top: 0;
    width: 100%;
    max-width: 512px;
  }
}

@media only screen and (max-device-width: 320px) and (orientation: portrait) {
  #controller_dpad {
    left: -5px;
    bottom: -5px;
  }

  #controller_a {
    right: 5px;
    bottom: 95px;
  }

  #controller_b {
    right: 80px;
  }

  #controller_start {
    right: 5px;
  }

  #controller_select {
    right: 80px;
  }
}

@media only screen and (max-width: 500px) and (max-height: 400px) {
  #controller {
    display: none;
  }
}

@media only screen and (max-width: 400px) {
  #controller_dpad,
  #action_buttons {
    transform: scale(0.9);
    margin: 0;
  }
}

/* Small devices in landscape */
@media only screen and (max-device-width: 300px) and (orientation: landscape) {
  html,
  body {
    height: 100%;
  }
  body {
    display: flex;
    justify-content: center;
    align-items: center;
  }

  #game:after {
    content: "PLEASE ROTATE ↻";
    font-size: 24px;
    font-weight: bold;
    color: #fff;
  }

  #game canvas {
    display: none;
    max-width: 480px;
  }

  #controller {
    display: none;
  }
}

/* Devices large enough for landscape */
@media only screen and (min-width: 300px) and (orientation: landscape) {
  #controller {
    bottom: 50%;
    transform: translateY(50%);
  }
}

#debug {
  display:flex;
  flex-direction:column;
  align-items:center;
  padding:10px;
  position:fixed;
  top:0px;
  left:0px;
  right:0px;
  bottom:0px;
  background:rgba(0,0,0,0.5);
}

#debug div {
  background: white;
  color: black;
  border: 1px solid #ddd;
  border-radius: 4px;
  transform: position;
  font-size: 11px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  display: flex;
  align-items: center;
}

#debug span {
  padding: 5px 8px;
}

#debug button {
  background: transparent;
  border: none;
  border-left: 1px solid #ddd;
  display: flex;
  align-items: center;
  height: 100%;
}

#debug button:hover {
  background: #eee;
}

#debug button:active {
  background: #ddd;
}

.spinner {
  height: 50px;
  width: 50px;
  margin: 0px auto;
  -webkit-animation: rotation 0.8s linear infinite;
  -moz-animation: rotation 0.8s linear infinite;
  -o-animation: rotation 0.8s linear infinite;
  animation: rotation 0.8s linear infinite;
  border-left: 10px solid #306850;
  border-right: 10px solid #306850;
  border-bottom: 10px solid #306850;
  border-top: 10px solid #88c070;
  border-radius: 100%;
  background-color: #031921;
}
@-webkit-keyframes rotation {
  from {
    -webkit-transform: rotate(0deg);
  }
  to {
    -webkit-transform: rotate(360deg);
  }
}
@-moz-keyframes rotation {
  from {
    -moz-transform: rotate(0deg);
  }
  to {
    -moz-transform: rotate(360deg);
  }
}
@-o-keyframes rotation {
  from {
    -o-transform: rotate(0deg);
  }
  to {
    -o-transform: rotate(360deg);
  }
}
@keyframes rotation {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.btnPressed {
  opacity: 0.5;
}

.roundBtn {
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: bold;
  font-size: 30px;
  color: #000000;
  line-height: 70px;
  width: 70px;
  height: 70px;
  border-radius: 35px;
  background: #CBF474;
  background: radial-gradient(ellipse at center, #CBF474 0%, #CBF474 100%);
  box-shadow: 0px 4px 5px rgba(0, 0, 0, 0.2);
}

.capsuleBtn {
  font-weight: bold;
  font-size: 10px;
  color: #000000;
  display: flex;
  justify-content: center;
  align-items: center;
  line-height: 40px;
  text-transform: uppercase;
  width: 64px;
  height: 32px;
  border-radius: 40px;
  background: #FFFFFF;
  background: radial-gradient(ellipse at center, #FFFFFF 0%, #FFFFFF 100%);
  box-shadow: 0px 4px 5px rgba(0, 0, 0, 0.2);
}

@media only screen and (min-width: 641px) {
  .controls_row {
    max-width: 90%;  
  }
}

/* Base state for controls */
.controls_text,
#controller {
  transition: filter 0.5s ease-out, opacity 0.5s ease-out;
  filter: blur(0);
  opacity: 1;
}

/* Blurred state when cover is present */
body:has(#cover-screen:not(.hidden)) .controls_text,
body:has(#cover-screen:not(.hidden)) #controller {
  filter: blur(3px);
  opacity: 0.3;
}

/* Hide keyboard text while cover screen is visible */
#cover-screen:not(.hidden) ~ #keyboard-hint {
  visibility: hidden;
}

@keyframes buttonPulse {
  0% {
    box-shadow: 0 0 10px rgba(203, 244, 116, 0.4),
                0 0 20px rgba(203, 244, 116, 0.2),
                0 0 30px rgba(203, 244, 116, 0.1);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 15px rgba(203, 244, 116, 0.6),
                0 0 30px rgba(203, 244, 116, 0.4),
                0 0 45px rgba(203, 244, 116, 0.2);
    transform: scale(1.02);
  }
  100% {
    box-shadow: 0 0 10px rgba(203, 244, 116, 0.4),
                0 0 20px rgba(203, 244, 116, 0.2),
                0 0 30px rgba(203, 244, 116, 0.1);
    transform: scale(1);
  }
}

#cover-screen {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 1000;
  pointer-events: auto;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#cover-screen.hidden {
  opacity: 0;
  transform: scale(1.02);
  pointer-events: none;
}

#cover-screen.hidden #cover-image {
  animation: pixelFade 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes pixelFade {
  0% {
    opacity: 1;
    transform: scale(1);
    filter: none;
  }
  100% {
    opacity: 0;
    transform: scale(1.05);
    filter: blur(2px) brightness(1.1) sepia(0.3) hue-rotate(160deg) saturate(1.8);
  }
}

#cover-image {
  object-fit: contain;
  image-rendering: -moz-crisp-edges;
  image-rendering: -webkit-crisp-edges;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  width: 100%;
  max-width: min(80vh, 90vw);
  height: auto;
  border-radius: 10px !important;
  will-change: transform, opacity, filter;
}

#play-button {
  border: none;
  background: #CBF474;
  color: #000;
  padding: 15px 40px;
  font-size: 24px;
  border-radius: 30px;
  cursor: pointer;
  font-weight: bold;
  transition: transform 0.2s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  margin-top: 60px;
  animation: buttonPulse 2s ease-in-out infinite;
  will-change: transform, box-shadow;
}

#play-button:hover {
  transform: scale(1.05);
  box-shadow: 0 0 20px rgba(203, 244, 116, 0.7),
              0 0 40px rgba(203, 244, 116, 0.5),
              0 0 60px rgba(203, 244, 116, 0.3);
}

@keyframes pixelFade {
  0% {
    opacity: 1;
    transform: scale(1);
    filter: none;
  }
  100% {
    opacity: 0;
    transform: scale(1.05);
    filter: blur(2px) brightness(1.1) sepia(0.3) hue-rotate(160deg) saturate(1.8);
  }
}