* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  color: #fff;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background: radial-gradient(circle at 50% 18%, #ffc65e 0%, #d98925 42%, #9f5e1f 100%);
}

body::after {
  position: fixed;
  inset: 0;
  z-index: 1;
  content: "";
  pointer-events: none;
  background:
    radial-gradient(circle at 50% 28%, transparent 0 42%, rgb(76 29 0 / 16%) 100%),
    linear-gradient(180deg, rgb(255 255 255 / 10%), transparent 32%, rgb(78 36 4 / 18%));
}

button {
  border: 0;
  border-radius: 999px;
  padding: 0.7rem 1.1rem;
  color: #08111f;
  font: inherit;
  font-weight: 800;
  background: linear-gradient(135deg, #ffd86b, #ff9d42);
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 12px 24px rgb(0 0 0 / 26%);
}

button:hover {
  filter: brightness(1.05);
}

#game {
  position: fixed;
  inset: 0;
  z-index: 0;
  display: block;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  touch-action: none;
  cursor: crosshair;
}

.hud {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  left: max(16px, env(safe-area-inset-left));
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  grid-template-rows: auto auto;
  align-items: center;
  justify-items: center;
  gap: 8px 12px;
  pointer-events: none;
}

.hud-card,
.hud button {
  pointer-events: auto;
}

.hud-card {
  min-width: 108px;
  padding: 0.55rem 0.85rem;
  border: 2px solid rgb(255 255 255 / 26%);
  border-radius: 14px;
  background: linear-gradient(180deg, rgb(255 255 255 / 34%), rgb(75 85 99 / 68%));
  box-shadow:
    inset 0 2px 0 rgb(255 255 255 / 35%),
    0 10px 18px rgb(89 42 8 / 28%);
  backdrop-filter: blur(8px);
  text-align: center;
}

.score-card {
  grid-column: 2;
  grid-row: 1;
  min-width: 76px;
  padding: 0.05rem 0.8rem 0.2rem;
  border: 0;
  background: transparent;
  box-shadow: none;
  text-align: center;
  text-shadow: 0 3px 0 rgb(70 38 8 / 60%);
}

.ammo-card {
  grid-column: 1;
  grid-row: 2;
  justify-self: end;
  background: linear-gradient(180deg, #86d337, #31920f);
}

.blocks-card {
  grid-column: 2;
  grid-row: 2;
}

.level-card {
  grid-column: 3;
  grid-row: 2;
  justify-self: start;
  min-width: 76px;
}

.settings-button {
  grid-column: 3;
  grid-row: 1 / span 2;
  justify-self: end;
  width: 58px;
  height: 58px;
  overflow: hidden;
  border: 4px solid rgb(255 255 255 / 92%);
  border-radius: 50%;
  padding: 0;
  color: transparent;
  background:
    linear-gradient(#fff, #fff) center / 26px 8px no-repeat,
    linear-gradient(90deg, #fff, #fff) center / 8px 26px no-repeat,
    rgb(107 114 128 / 72%);
  box-shadow: 0 8px 16px rgb(89 42 8 / 30%);
}

.hud-card strong {
  display: block;
  margin-bottom: 0.15rem;
  color: rgb(255 255 255 / 82%);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.score-card strong {
  display: none;
}

.hud-card span {
  color: #fff;
  font-size: 1.35rem;
  font-weight: 900;
  text-shadow: 0 2px 0 rgb(0 0 0 / 26%);
}

.score-card span {
  font-size: 2.5rem;
  line-height: 1;
}

.message {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-content: center;
  padding: 24px;
  text-align: center;
  background: linear-gradient(180deg, rgb(3 7 18 / 72%), rgb(3 7 18 / 36%));
}

.message-panel {
  width: min(680px, calc(100vw - 32px));
  padding: clamp(1.6rem, 4vw, 2.4rem);
  border: 1px solid rgb(255 255 255 / 22%);
  border-radius: 32px;
  background: linear-gradient(180deg, rgb(255 255 255 / 20%), rgb(17 24 39 / 54%));
  box-shadow:
    inset 0 2px 0 rgb(255 255 255 / 18%),
    0 28px 70px rgb(0 0 0 / 30%);
  backdrop-filter: blur(14px);
}

.message.hidden {
  display: none;
}

.message h1 {
  max-width: min(620px, calc(100vw - 64px));
  margin: 0 0 0.75rem;
  font-size: clamp(2rem, 8vw, 5rem);
  line-height: 0.95;
  text-shadow: 0 10px 28px rgb(0 0 0 / 42%);
}

.message p {
  max-width: 580px;
  margin: 0 auto 1.35rem;
  color: rgb(255 255 255 / 78%);
  font-size: clamp(1rem, 2.4vw, 1.25rem);
}

@media (max-width: 640px) {
  #game {
    cursor: default;
  }

  .hud {
    top: 10px;
    right: 10px;
    left: 10px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-template-rows: auto auto;
    gap: 6px;
  }

  .hud-card {
    width: 100%;
    min-width: 0;
    padding: 0.45rem 0.35rem;
    border-radius: 12px;
  }

  .ammo-card {
    grid-column: 1;
    justify-self: stretch;
  }

  .blocks-card {
    grid-column: 2 / span 2;
  }

  .level-card {
    display: block;
    grid-column: 4;
    justify-self: stretch;
  }

  .score-card {
    grid-column: 1 / span 4;
    grid-row: 1;
  }

  .hud-card span {
    font-size: 1rem;
  }

  .score-card span {
    font-size: 1.8rem;
  }

  .settings-button {
    position: fixed;
    right: 10px;
    bottom: max(10px, env(safe-area-inset-bottom));
    width: 48px;
    height: 48px;
  }

  .message {
    padding: 16px;
  }

  .message-panel {
    width: calc(100vw - 32px);
    padding: 1.35rem;
    border-radius: 24px;
  }

  .message h1 {
    margin-bottom: 0.75rem;
  }

  .message p {
    max-width: calc(100vw - 56px);
    margin-top: 0;
    font-size: 0.98rem;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  .hud {
    top: 6px;
    right: 8px;
    left: 8px;
    grid-template-columns: repeat(5, auto);
    grid-template-rows: auto;
    justify-content: center;
  }

  .score-card,
  .ammo-card,
  .blocks-card,
  .level-card {
    grid-row: 1;
    grid-column: auto;
    min-width: 72px;
    padding: 0.35rem 0.55rem;
  }

  .score-card span,
  .hud-card span {
    font-size: 1rem;
  }

  .settings-button {
    position: fixed;
    right: 8px;
    bottom: 8px;
    width: 42px;
    height: 42px;
  }

  .message-panel {
    width: min(520px, calc(100vw - 24px));
    padding: 1rem;
  }

  .message h1 {
    font-size: clamp(1.6rem, 7vw, 3rem);
  }

  .message p {
    font-size: 0.9rem;
  }
}
