:root {
  --wall: #eef4f8;
  --counter: #c9a66a;
  --counter-deep: #8f6838;
  --ink: #1f2937;
  --muted: rgba(31, 41, 55, 0.52);
  --butter: #f5c84c;
  --life: #e11d48;
  --font: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-display: "Nunito", "IBM Plex Sans", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: linear-gradient(
    180deg,
    var(--wall) 0%,
    var(--wall) 58%,
    var(--counter) 58%,
    var(--counter-deep) 100%
  );
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#wrap {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#lives-wrap {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 5px;
  pointer-events: none;
  will-change: transform;
}

#lives-wrap.life-hit {
  animation: lives-shake 0.32s ease-out;
}

.life-icon {
  width: clamp(28px, 7.5vw, 36px);
  height: clamp(28px, 7.5vw, 36px);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #e11d48;
  opacity: 1;
  transform-origin: center;
  will-change: transform, opacity;
  filter: drop-shadow(0 1px 2px rgba(255, 255, 255, 0.75)) drop-shadow(0 2px 6px rgba(190, 18, 60, 0.3));
  animation: heart-idle 1.6s ease-in-out infinite;
}

.life-icon:nth-child(2) {
  animation-delay: 0.2s;
}

.life-icon:nth-child(3) {
  animation-delay: 0.4s;
}

.life-icon svg {
  width: 88%;
  height: 88%;
}

.life-icon.lost {
  color: rgba(31, 41, 55, 0.22);
  opacity: 0.5;
  filter: none;
  animation: none;
}

.life-icon.just-lost {
  animation: heart-break 0.55s ease-out forwards;
  color: #e11d48;
  opacity: 1;
  filter: drop-shadow(0 1px 0 rgba(255, 255, 255, 0.55));
}

#lives-wrap.last-life .life-icon:not(.lost):not(.just-lost) {
  color: #be123c;
  animation: last-life-pulse 1.2s ease-in-out infinite;
}

#life-loss-flash {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background: rgba(190, 18, 60, 0.14);
  opacity: 0;
  will-change: opacity;
}

#life-loss-flash.show {
  animation: life-flash 0.4s ease-out forwards;
}

#life-loss-banner {
  position: absolute;
  top: max(56px, calc(env(safe-area-inset-top) + 44px));
  right: max(12px, env(safe-area-inset-right));
  z-index: 5;
  pointer-events: none;
  font-family: var(--font-display);
  font-size: clamp(1.05rem, 4.2vw, 1.35rem);
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #be123c;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
  opacity: 0;
  transform: translate3d(0, -6px, 0) scale(0.9);
  will-change: transform, opacity;
}

#life-loss-banner.show {
  animation: life-banner 0.7s ease-out forwards;
}

#hud {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  display: flex;
  align-items: baseline;
  gap: 10px;
  pointer-events: none;
}

#hud .label {
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: #1f2937;
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.9),
    0 0 10px rgba(255, 255, 255, 0.65);
}

#streak {
  font-family: var(--font-display);
  font-size: clamp(1.9rem, 7vw, 2.45rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #b45309;
  letter-spacing: -0.02em;
  line-height: 1;
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.85),
    0 2px 10px rgba(180, 83, 9, 0.35);
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 0;
  touch-action: none;
  display: block;
  box-shadow: none;
}

.hint {
  position: absolute;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 4;
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  color: rgba(255, 248, 235, 0.98);
  text-align: center;
  max-width: min(320px, 90vw);
  line-height: 1.35;
  pointer-events: none;
  text-shadow:
    0 1px 2px rgba(31, 41, 55, 0.55),
    0 0 14px rgba(40, 24, 10, 0.4);
}

.hint.hidden {
  visibility: hidden;
  opacity: 0;
}

.action-cue {
  position: absolute;
  left: 50%;
  bottom: max(52px, calc(env(safe-area-inset-bottom) + 40px));
  transform: translateX(-50%);
  z-index: 5;
  margin: 0;
  padding: 18px 32px;
  min-width: min(280px, 84vw);
  border: none;
  border-radius: 999px;
  font-family: var(--font-display);
  font-size: clamp(1.35rem, 6vw, 1.75rem);
  font-weight: 800;
  letter-spacing: 0.02em;
  text-align: center;
  white-space: nowrap;
  color: #1f2937;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 4px 16px rgba(31, 41, 55, 0.18);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.action-cue.show {
  opacity: 1;
  visibility: visible;
}

.action-cue:active,
.action-cue.holding {
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 2px 10px rgba(31, 41, 55, 0.22);
}

.controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  pointer-events: none;
}

.controls .hint {
  position: absolute;
  left: 50%;
  bottom: max(138px, calc(env(safe-area-inset-bottom) + 128px));
  transform: translateX(-50%);
  z-index: 6;
  pointer-events: none;
}

.controls .action-cue {
  pointer-events: auto;
}

@keyframes heart-break {
  0% {
    transform: translate3d(0, 0, 0) scale(1);
    opacity: 1;
  }
  25% {
    transform: translate3d(0, 0, 0) scale(1.45);
    opacity: 1;
  }
  100% {
    transform: translate3d(0, 0, 0) scale(1);
    opacity: 0.55;
  }
}

@keyframes heart-idle {
  0%,
  100% {
    transform: translate3d(0, 0, 0) scale(1);
  }
  50% {
    transform: translate3d(0, 0, 0) scale(1.08);
  }
}

@keyframes last-life-pulse {
  0%,
  100% {
    transform: translate3d(0, 0, 0) scale(1);
  }
  50% {
    transform: translate3d(0, 0, 0) scale(1.14);
  }
}

@keyframes lives-shake {
  0%,
  100% {
    transform: translate3d(0, 0, 0);
  }
  25% {
    transform: translate3d(-4px, 0, 0);
  }
  50% {
    transform: translate3d(4px, 0, 0);
  }
  75% {
    transform: translate3d(-2px, 0, 0);
  }
}

@keyframes life-flash {
  0% {
    opacity: 0;
  }
  20% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

@keyframes life-banner {
  0% {
    opacity: 0;
    transform: translate3d(0, -8px, 0) scale(0.88);
  }
  25% {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1.05);
  }
  70% {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate3d(0, 6px, 0) scale(0.98);
  }
}

@media (min-width: 600px) {
  #lives-wrap {
    top: max(18px, env(safe-area-inset-top));
    right: max(20px, env(safe-area-inset-right));
    gap: 8px;
  }

  .life-icon {
    width: clamp(34px, 4.5vw, 44px);
    height: clamp(34px, 4.5vw, 44px);
  }

  #hud {
    gap: 12px;
  }

  #streak {
    font-size: clamp(2.4rem, 4.5vw, 3.1rem);
  }

  .hint {
    bottom: max(24px, env(safe-area-inset-bottom));
    font-size: 1.05rem;
    max-width: 380px;
  }

  .controls .hint {
    bottom: max(160px, calc(env(safe-area-inset-bottom) + 148px));
  }

  .action-cue {
    bottom: max(64px, calc(env(safe-area-inset-bottom) + 52px));
    font-size: 1.85rem;
    padding: 20px 40px;
    min-width: 320px;
  }
}

@media (min-width: 900px) {
  #streak {
    font-size: clamp(2.8rem, 3.8vw, 3.5rem);
  }

  .hint {
    font-size: 1.12rem;
  }
}
