*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --play-light: #d0eab8;
  --play-dark: #b8dc98;
  --board-shadow: rgba(0, 0, 0, 0.35);
  --toolbar-gap: clamp(0.5rem, 2vw, 1rem);
  --btn-min-h: clamp(2.5rem, 10vw, 2.75rem);
  --score-size: clamp(1.25rem, 5vw, 1.75rem);
}

html {
  height: 100%;
  touch-action: manipulation;
}

body {
  height: 100%;
  min-height: 100dvh;
  overflow: hidden;
  font-family: "Outfit", system-ui, sans-serif;
  background: #1a2d0f;
  color: #e8f5d6;
  -webkit-font-smoothing: antialiased;
}

.game-app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  height: 100vh;
  max-height: 100dvh;
  padding: max(6px, env(safe-area-inset-top))
    max(8px, env(safe-area-inset-right))
    max(8px, env(safe-area-inset-bottom))
    max(8px, env(safe-area-inset-left));
  background: radial-gradient(
    ellipse 85% 75% at 50% 40%,
    var(--play-dark) 0%,
    #2a3d1f 50%,
    #1a2d0f 100%
  );
}

.game-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--toolbar-gap);
  flex-shrink: 0;
  padding: clamp(0.35rem, 1.5vw, 0.6rem) clamp(0.25rem, 1vw, 0.5rem);
}

.score-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: clamp(0.75rem, 3vw, 1.5rem);
}

.score-block {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 3.5rem;
}

.score-label {
  font-size: clamp(0.65rem, 2.2vw, 0.75rem);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(232, 245, 214, 0.65);
}

.score-value {
  font-size: var(--score-size);
  font-weight: 700;
  line-height: 1;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

.score-block--speed .score-value {
  color: #b8e986;
}

.control-panel {
  display: flex;
  flex-wrap: wrap;
  gap: clamp(0.35rem, 1.5vw, 0.5rem);
  width: 100%;
}

@media (min-width: 480px) {
  .control-panel {
    width: auto;
  }
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  flex: 1 1 auto;
  min-height: var(--btn-min-h);
  min-width: clamp(4.5rem, 22vw, 5.5rem);
  padding: 0.45rem 0.85rem;
  border: none;
  border-radius: 10px;
  font-family: inherit;
  font-size: clamp(0.8rem, 2.8vw, 0.9rem);
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

@media (min-width: 480px) {
  .btn {
    flex: 0 1 auto;
  }
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-play {
  background: linear-gradient(180deg, #5cb85c 0%, #3d8b3d 100%);
  color: #fff;
  box-shadow: 0 2px 0 #2d6b2d, 0 4px 12px rgba(0, 0, 0, 0.2);
}

.btn-pause {
  background: linear-gradient(180deg, #f0ad4e 0%, #d9891e 100%);
  color: #fff;
  box-shadow: 0 2px 0 #b8730f, 0 4px 12px rgba(0, 0, 0, 0.2);
}

.btn-reset {
  background: linear-gradient(180deg, #6c8ebf 0%, #4a6fa5 100%);
  color: #fff;
  box-shadow: 0 2px 0 #3a5578, 0 4px 12px rgba(0, 0, 0, 0.2);
}

.btn-icon {
  font-size: 0.95em;
  line-height: 1;
}

.game-main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(0.35rem, 1.5vw, 0.65rem);
  container-type: size;
  container-name: game;
}

.game-shell {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.board-wrap {
  position: relative;
  width: 100%;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1;
  flex-shrink: 1;
  display: flex;
  align-items: center;
  justify-content: center;

  border-radius: 16px;
  overflow: hidden;

  /* Dark green boundary */
  border: 8px solid #1b5e20;

  /* Remove inner gap */
  padding: 0;
  background: #1b5e20;

  box-shadow: 0 12px 36px var(--board-shadow);
}

.board-wrap.eat-pulse {
  animation: eatPulse 0.35s ease-out;
}

.board-wrap.wall-hit {
  animation: wallHitShake 0.35s ease-out;
}

@keyframes eatPulse {
  50% {
    filter: brightness(1.05);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  }
}

@keyframes wallHitShake {
  0%,
  100% {
    transform: translate(0, 0);
  }
  20% {
    transform: translate(-3px, 1px);
  }
  40% {
    transform: translate(3px, -1px);
  }
  60% {
    transform: translate(-2px, -1px);
  }
  80% {
    transform: translate(2px, 1px);
  }
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  margin: 0;
  padding: 0;
}

.touch-pad {
  display: none;
  flex-shrink: 0;
  grid-template-columns: repeat(3, minmax(2.75rem, 1fr));
  grid-template-rows: repeat(2, minmax(2.75rem, 1fr));
  gap: clamp(0.35rem, 2vw, 0.5rem);
  width: min(100%, 14rem);
  max-width: 14rem;
  margin: 0 auto;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.pad-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: clamp(2.75rem, 12vw, 3.25rem);
  border: none;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.14) 0%, rgba(0, 0, 0, 0.12) 100%);
  color: #e8f5d6;
  font-size: clamp(1rem, 4.5vw, 1.2rem);
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
  transition: transform 0.1s ease, background 0.1s ease;
  touch-action: manipulation;
}

.pad-btn:active {
  transform: scale(0.94);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.22) 0%, rgba(0, 0, 0, 0.18) 100%);
}

.pad-up {
  grid-column: 2;
  grid-row: 1;
}

.pad-left {
  grid-column: 1;
  grid-row: 2;
}

.pad-right {
  grid-column: 3;
  grid-row: 2;
}

.pad-down {
  grid-column: 2;
  grid-row: 2;
}

.game-hint {
  flex-shrink: 0;
  font-size: clamp(0.65rem, 2.2vw, 0.78rem);
  font-weight: 500;
  color: rgba(232, 245, 214, 0.55);
  text-align: center;
  padding: 0 0.5rem 0.15rem;
  max-width: 36rem;
}

@media (hover: none) and (pointer: coarse), (max-width: 768px) {
  .touch-pad {
    display: grid;
  }

  .game-main--touch .game-hint {
    font-size: clamp(0.6rem, 2vw, 0.72rem);
  }
}

@media (min-width: 720px) {
  .game-toolbar {
    padding-inline: 0.75rem;
  }

  .control-panel {
    margin-left: auto;
  }

  .game-hint {
    font-size: 0.8rem;
  }
}

@supports (width: 100cqw) {
  .board-wrap {
    width: min(100%, 100cqw, 100cqh);
    height: min(100%, 100cqw, 100cqh);
  }
}

@media (min-width: 900px) and (min-height: 600px) {
  .game-app {
    padding-inline: max(12px, env(safe-area-inset-left));
  }

  @supports (width: 100cqw) {
    .board-wrap {
      width: min(100cqw, 100cqh, 700px);
      height: min(100cqw, 100cqh, 700px);
    }
  }
}

@media (max-height: 420px) and (orientation: landscape) {
  .game-hint {
    display: none;
  }

  .touch-pad {
    display: none;
  }

  .score-block--speed {
    display: none;
  }

  .btn-text {
    display: none;
  }

  .btn {
    min-width: 2.75rem;
    padding-inline: 0.65rem;
  }

  .game-main {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
  }

  .game-shell {
    flex: 1 1 55%;
    min-width: 0;
  }

  @supports (width: 100cqw) {
    .board-wrap {
      width: min(100cqw, 100cqh, 92vw);
      height: min(100cqw, 100cqh, 92vw);
    }
  }

  .board-wrap {
    margin: 0 auto;
  }
}

@media (max-width: 360px) {
  .score-panel {
    gap: 0.5rem;
  }

  .score-block {
    min-width: 2.75rem;
  }
}
