* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #4c5961;
  color: #ffffff;
  font-family: Avenir, "Helvetica Neue", Arial, sans-serif;
}

button {
  font: inherit;
}

.game-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  min-height: 420px;
  display: grid;
  place-items: center;
  background: linear-gradient(90deg, #4c5961 0%, #5f7279 18%, #65d0ea 18%, #65d0ea 82%, #5f7279 82%, #4c5961 100%);
}

canvas {
  width: min(100vw, 66.666vh);
  height: min(100vh, 150vw);
  max-width: 720px;
  max-height: 1080px;
  image-rendering: auto;
  touch-action: none;
}

.hud {
  position: fixed;
  top: max(22px, env(safe-area-inset-top));
  left: max(24px, env(safe-area-inset-left));
  display: grid;
  gap: 8px;
  color: #ffffff;
  text-shadow: 0 2px 3px rgba(27, 36, 59, 0.22);
  letter-spacing: 0;
  user-select: none;
}

.hud-block {
  min-width: 120px;
}

.score-label {
  font-size: 15px;
  line-height: 1;
  opacity: 0.8;
}

#height,
#best,
#star-value {
  font-size: 28px;
  line-height: 1;
  font-weight: 800;
}

#best,
#star-value {
  font-size: 22px;
}

.star-block {
  margin-top: 4px;
}

.star-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.star-flash {
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(255, 240, 150, 0.25);
  color: #fff8b0;
  font-size: 12px;
  font-weight: 800;
}

.items {
  position: fixed;
  top: max(22px, env(safe-area-inset-top));
  right: max(176px, calc(env(safe-area-inset-right) + 164px));
  display: block;
  z-index: 2;
}

.item-slot {
  width: 138px;
  min-height: 84px;
  padding: 10px 12px;
  display: grid;
  grid-template-columns: 42px 1fr;
  grid-template-areas:
    "icon key"
    "icon name"
    "icon count";
  align-items: center;
  gap: 2px 10px;
  border: 0;
  border-radius: 8px;
  background: rgba(35, 48, 79, 0.86);
  color: #ffffff;
  box-shadow: 0 8px 18px rgba(35, 48, 79, 0.18);
  cursor: pointer;
}

.item-slot:disabled {
  opacity: 0.7;
}

.item-slot img {
  grid-area: icon;
  width: 42px;
  height: 42px;
  object-fit: contain;
}

.item-key {
  grid-area: key;
  font-size: 12px;
  opacity: 0.8;
}

.item-name {
  grid-area: name;
  font-size: 15px;
  font-weight: 800;
}

.item-count {
  grid-area: count;
  font-size: 16px;
  font-weight: 800;
  color: #ffe68a;
}

.item-slot.active {
  background: rgba(255, 122, 141, 0.94);
}

.restart {
  position: fixed;
  top: max(26px, env(safe-area-inset-top));
  right: max(26px, env(safe-area-inset-right));
  min-width: 132px;
  height: 46px;
  border: 0;
  border-radius: 6px;
  background: #23304f;
  color: #ffffff;
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(35, 48, 79, 0.18);
}

.restart:active,
.result button:active {
  transform: translateY(1px);
}

.hint {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: max(18px, env(safe-area-inset-bottom));
  margin: 0;
  text-align: center;
  color: rgba(255, 255, 255, 0.92);
  font-size: 15px;
  text-shadow: 0 2px 4px rgba(30, 40, 70, 0.28);
  pointer-events: none;
}

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(31, 42, 73, 0.28);
}

.overlay.hidden {
  display: none;
}

.hidden {
  display: none;
}

.result {
  width: min(580px, 92vw);
  padding: 30px 28px;
  border-radius: 8px;
  background: rgba(34, 49, 82, 0.88);
  box-shadow: 0 18px 48px rgba(22, 29, 50, 0.26);
  text-align: center;
}

.result h1 {
  margin: 0 0 16px;
  font-size: clamp(27px, 6vw, 44px);
  line-height: 1.05;
  letter-spacing: 0;
}

.result p {
  margin: 0 auto 24px;
  max-width: 440px;
  font-size: 19px;
  line-height: 1.45;
}

.result button {
  min-width: 170px;
  height: 48px;
  border: 0;
  border-radius: 6px;
  background: #ff6f7e;
  color: #ffffff;
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
}

@media (max-width: 620px) {
  .hud {
    top: max(14px, env(safe-area-inset-top));
    left: max(14px, env(safe-area-inset-left));
  }

  #height {
    font-size: 22px;
  }

  #best,
  #star-value {
    font-size: 18px;
  }

  .items {
    top: auto;
    left: auto;
    right: max(14px, env(safe-area-inset-right));
    bottom: max(56px, calc(env(safe-area-inset-bottom) + 44px));
  }

  .item-slot {
    width: 138px;
    min-height: 76px;
  }

  .restart {
    top: max(14px, env(safe-area-inset-top));
    right: max(14px, env(safe-area-inset-right));
    min-width: 104px;
    height: 40px;
    font-size: 15px;
  }

  .hint {
    font-size: 13px;
  }
}
