body {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100svh;
    min-height: 100dvh;
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    background-image: url("./assets/img/5_background/bg-image.jpg");
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    overflow: hidden;
    -webkit-text-size-adjust: 100%;

}

canvas {
    background-color: black;
    width: 100%; height: 100%; display: block;
}

/* Canvas*/
#game-container {
    position: relative;
    aspect-ratio: 720 / 480;
    width: min(720px, 100vw, calc(100dvh * 3 / 2));
    height: auto;
    font-family: Arial, Helvetica, sans-serif;
    border-radius: 18px;
    overflow: hidden;
    box-shadow: 0 18px 60px rgba(0,0,0,0.45);
  }

 /* Startscreen Overlay */
  #start-overlay {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  #start-screen-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
  }

  #start-button {
    position: relative;
    z-index: 11;
    background: #000;
    color: #fff;
    border: none;
    padding: 16px 38px;
    border-radius: 20px;
    font-weight: 700;
    font-size: 28px;
    cursor: pointer;
    transition: transform 120ms ease, background-color 120ms ease;
  }

  #start-button:hover {
    background: #111;
    transform: scale(1.03);
  }

  /* Gameover Overlay */
  #gameover-overlay {
    position: absolute;
    inset: 0;
    z-index: 20;
    display: none; 
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.753);
  }

  #gameover-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  #gameover-buttons {
    position: absolute;
    bottom: 50px;
    display: flex;
    gap: 16px;
    z-index: 21;
  }

  .gameover-btn {
    background: #f2a900; 
    color: #000;
    border: none;
    padding: 14px 20px;
    border-radius: 16px;
    font-weight: 700;
    font-size: 16px;
    cursor: pointer;
    transition: transform 120ms ease, background-color 120ms ease;
  }

  .gameover-btn:hover {
    background: #ffb300;
    transform: scale(1.04);
  }

/* Sound Toggle */
  #sound-toggle {
    position: absolute;
    right: 56px;
    bottom: 16px;
    width: 24px;
    height: 24px;
    z-index: 12;
    cursor: pointer;
    transition: transform 120ms ease;
  }

  #sound-toggle:hover {
    transform: scale(1.06);
  }

  /* Fullscreen Toggle */
#fullscreen-toggle {
  position: absolute;
  right: 16px;   
  bottom: 17px;
  width: 22px;
  height: 22px;
  z-index: 12;
  cursor: pointer;
  transition: transform 120ms ease;
}
#fullscreen-toggle:hover {
  transform: scale(1.06);
}

/* Win Overlay */
  #win-overlay {
    position: absolute;
    inset: 0;
    z-index: 30;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.863);
  }

  #win-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }

  #win-buttons {
    position: absolute;
    bottom: 50px;
    display: flex;
    gap: 16px;
    z-index: 31;
  }

/* Howto Overlay */
  #howto-button {
    position: absolute;
    left: 16px;
    bottom: 16px;
    z-index: 12;
    background: #000;
    color: #fff;
    border: none;
    padding: 10px 16px;
    border-radius: 14px;
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    transition: transform 120ms ease, background-color 120ms ease;
  }

  #howto-button:hover {
    background: #111;
    transform: scale(1.03);
  }

  #howto-overlay {
    position: absolute;
    inset: 0;
    z-index: 15; 
    display: none; 
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.78);
  }

  #howto-modal {
    width: min(560px, 92%);
    max-height: 86%;
    overflow: auto;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 18px;
    padding: 18px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.45);
  }

  #howto-back {
    position: sticky;
    top: 0;
    margin-bottom: 12px;
  }

  .howto-title {
    margin: 10px 0 8px 0;
    font-size: 20px;
  }

  .howto-grid {
    display: grid;
    gap: 8px;
    margin-bottom: 10px;
  }

  .howto-row {
    display: grid;
    grid-template-columns: 110px 1fr;
    gap: 12px;
    align-items: center;
    background: rgba(0,0,0,0.06);
    border-radius: 12px;
    padding: 10px 12px;
  }

  .howto-key {
    font-weight: 800;
    background: rgba(0,0,0,0.10);
    border-radius: 10px;
    padding: 6px 8px;
    text-align: center;
  }

  .howto-text {
    font-weight: 600;
  }

/* Background Credit */
  .bg-credit{
    position: fixed;
    right: 12px;
    bottom: 10px;
    z-index: 1000;
    font-size: 12px;
    color: rgba(255,255,255,0.85);
    background: rgba(0,0,0,0.45);
    padding: 6px 10px;
    border-radius: 12px;
    backdrop-filter: blur(6px);
  }

  .bg-credit a{
    color: rgba(255,255,255,0.95);
    font-weight: 700;
    text-decoration: none;
  }

  .bg-credit a:hover{
    text-decoration: underline;
  }

  /* ===== Pause Overlay ===== */
#pause-overlay{
  position: absolute;
  inset: 0;
  z-index: 25;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.75);
}
#pause-modal{
  width: min(520px, 92%);
  background: rgba(255,255,255,0.95);
  border-radius: 18px;
  padding: 22px 18px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.45);
}
#pause-title{
  font-size: 34px;
  font-weight: 900;
  letter-spacing: 2px;
  margin-bottom: 8px;
}
#pause-hint{
  font-size: 14px;
  font-weight: 700;
  opacity: 0.85;
  margin-bottom: 16px;
}
#pause-buttons{
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* Rotate Overlay */
#rotate-overlay{
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0,0,0,0.95);
  display: none;  
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 26px;
}
#rotate-icon{
  width: 140px;
  height: auto;
  filter: invert(1) brightness(1.2) contrast(1.2);
  animation: rotateIcon 1.2s ease-in-out infinite;
}
#rotate-text{
  color: #fff;
  font-weight: 400;
  font-size: 18px;
  text-align: center;
  padding: 0 18px;
}

@keyframes rotateIcon {
  0%   { transform: rotate(0deg) scale(1); }
  40%  { transform: rotate(-18deg) scale(1.02); }
  70%  { transform: rotate(18deg) scale(1.02); }
  100% { transform: rotate(0deg) scale(1); }
}

/* Mobile Controls */
#mobile-controls{
  position: absolute;
  inset: 0;
  pointer-events: none; 
  display: none;
  z-index: 50;
}
#dpad, #action-buttons{
  position: absolute;
  bottom: calc(18px + env(safe-area-inset-bottom));
  pointer-events: auto;
  display: grid;
  gap: 5px;
}
#dpad{
  left: calc(72px + env(safe-area-inset-left));
  display: grid;
  grid-template-columns: 54px 18px 54px;
  grid-template-rows: 54px 54px;
  gap: 4px;
  align-items: center;
  justify-items: center;
}

#dpad-left { grid-column: 1; grid-row: 2; }
#dpad-right { grid-column: 3; grid-row: 2; }
#action-buttons{ right: calc(18px + env(safe-area-inset-right)); grid-auto-flow: row; }

.dpad-btn, .action-btn{
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.25);
  background: rgba(255,255,255,0.12);
  color: white;
  font-size: 12px;
  font-weight: 800;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.dpad-btn{
  width: 54px;
  height: 54px;
}

.action-btn{
  width: 72px;
  height: 42px;
}

/* Media Queries */
@media (max-aspect-ratio: 1/1) {
  #rotate-overlay {
    display: flex;
  }
}

@media (pointer: coarse) {
  #howto-overlay {
    position: fixed;
    inset: 0;
    z-index: 20000;
  }

  #howto-modal {
    width: min(560px, 94vw);
    max-height: 90svh;
  }
}

@media (pointer: coarse) and (min-aspect-ratio: 1/1) {
  body.game-started #mobile-controls {
    display: block;
  }
}