* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

body {
  background: #111;
  font-family: 'Fredoka', sans-serif;
}

#game-viewport {
  height: 100vh;
  height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  background: #111;
}

#game-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  max-width: calc(100vh * 575 / 1024);
  max-height: calc(100vw * 1024 / 575);
  aspect-ratio: 575 / 1024;
  background: #40558b; /* Flat matte blue background */
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.8);
}

#game-center-wrap {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  height: 100%;
  width: 100%;
  pointer-events: none;
  z-index: 30;
  display: flex;
  flex-direction: column;
}

@media (min-aspect-ratio: 1/1) {
  #game-container {
    max-width: 100vw;
    max-height: 100vh;
    aspect-ratio: 2972 / 1672;
  }
  #game-center-wrap {
    width: calc(100% * 575 / 1024 * 1672 / 2972);
  }
}

/* Enable pointer events on active elements */
#game-center-wrap .back-home-btn,
#game-center-wrap .gameover:not(.hidden) {
  pointer-events: auto;
}

/* Header Area */
#header-area {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px 5px 24px;
  pointer-events: auto;
}

#best-score-container {
  display: flex;
  align-items: center;
  gap: 8px;
}

#best-score-val {
  font-size: 26px;
  color: #ffcc00;
  font-family: 'Fredoka One', cursive;
}

.hud-btn {
  background: none;
  border: none;
  cursor: pointer;
  outline: none;
  transition: transform 0.1s;
}
.hud-btn:active {
  transform: scale(0.85);
}

#main-score-area {
  display: flex;
  justify-content: center;
  margin-top: 5px;
  margin-bottom: 10px;
}

#score-val {
  font-size: 72px;
  color: #fff;
  font-family: 'Fredoka One', cursive;
  text-shadow: 0 4px 10px rgba(0,0,0,0.2);
}

/* Grid & Tray Areas */
#grid-area {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  padding: 20px;
  pointer-events: auto;
}

#grid-bg {
  position: absolute;
  top: 20px; left: 20px; right: 20px; bottom: 20px;
  background: #1d2138;
  border-radius: 12px;
  /* Deep inset shadow */
  box-shadow: 
    inset 0 8px 12px rgba(0,0,0,0.4),
    inset 0 2px 4px rgba(0,0,0,0.6),
    0 2px 0 rgba(255,255,255,0.1);
}

#game-canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  pointer-events: auto;
}

/* Game Over Overlay */
.gameover {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.85);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  transition: opacity .3s;
  pointer-events: auto;
}
.gameover.hidden {
  opacity: 0;
  pointer-events: none;
}

.gameover-card {
  width: 78%;
  background: #1f1f3a;
  border: 5px solid #00d2ff;
  border-radius: 22px;
  padding: 36px 20px;
  text-align: center;
  box-shadow: 0 20px 40px rgba(0,0,0,.7);
  animation: popIn .35s cubic-bezier(.175,.885,.32,1.275);
}
.gameover-title {
  font-family: 'Fredoka One', cursive;
  font-size: 32px;
  color: #00d2ff;
  margin-bottom: 10px;
}
.gameover-score-text {
  font-size: 20px;
  color: #fff;
  margin-bottom: 26px;
}
.game-btn {
  font-family: 'Fredoka One', cursive;
  font-size: 22px;
  color: #fff;
  background: linear-gradient(180deg, #00d2ff, #3a7bd5);
  border: none;
  border-radius: 28px;
  padding: 11px 36px;
  cursor: pointer;
  box-shadow: 0 6px 0 #005a80, 0 8px 16px rgba(0,0,0,.3);
  transition: transform .1s, box-shadow .1s;
  outline: none;
}
.game-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #005a80;
}

@keyframes popIn {
  from { transform: scale(.65); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}
