*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0c0a10;
  color: #f5f0ff;
  font-family: 'Chakra Petch', system-ui, sans-serif;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 100%;
  min-height: 100dvh;
  height: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#wrap.wrong-slice-shake {
  animation: wrongSliceShake 0.34s ease-out;
}

@keyframes wrongSliceShake {
  0%,
  100% {
    transform: translate3d(0, 0, 0);
  }
  15% {
    transform: translate3d(-5px, 2px, 0);
  }
  30% {
    transform: translate3d(4px, -3px, 0);
  }
  45% {
    transform: translate3d(-4px, -2px, 0);
  }
  60% {
    transform: translate3d(4px, 2px, 0);
  }
  75% {
    transform: translate3d(-2px, 1px, 0);
  }
  90% {
    transform: translate3d(1px, -1px, 0);
  }
}

/* Match planet-destroyer HUD: 48px from WebView top, grid: center score + avoid, lives row1 right, pause row2 right */
#hud {
  position: absolute;
  top: 48px;
  left: calc(20px + env(safe-area-inset-left, 0px));
  right: calc(20px + env(safe-area-inset-right, 0px));
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  grid-template-rows: auto auto;
  row-gap: 4px;
  align-items: center;
  z-index: 10;
  pointer-events: none;
}

#pause-wrap {
  grid-column: 3;
  grid-row: 2;
  justify-self: end;
  align-self: start;
  pointer-events: auto;
}

#pause-btn {
  width: 36px;
  height: 36px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  color: #fff;
  -webkit-tap-highlight-color: transparent;
}

#pause-btn:active {
  transform: scale(0.96);
  opacity: 0.92;
}

#pause-btn .icon-play {
  display: none;
}

#pause-btn.is-paused .icon-pause {
  display: none;
}

#pause-btn.is-paused .icon-play {
  display: block;
}

#hud-center {
  grid-column: 2;
  grid-row: 1;
  justify-self: center;
  align-self: center;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Same score treatment as planet-destroyer #score-wrap / #current-score */
#score-wrap {
  min-width: 6ch;
  font-size: clamp(1.5rem, 5.5vw, 2.5rem);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  text-align: center;
  color: #ffffff;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.8);
  /* Opacity flash avoids transform scale repainting HUD + WebView with canvas. */
}

#score-wrap.pulse {
  animation: scoreFlash 0.28s ease-out;
}

@keyframes scoreFlash {
  0% {
    opacity: 0.55;
  }
  100% {
    opacity: 1;
  }
}

#avoid-indicator {
  position: absolute;
  left: 50%;
  top: 100%;
  margin-top: 4px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 4px 12px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.08);
  color: rgba(245, 240, 255, 0.55);
  white-space: nowrap;
  max-width: min(92vw, 280px);
}

.avoid-indicator-label {
  flex-shrink: 0;
}

#lives-wrap {
  grid-column: 3;
  grid-row: 1;
  justify-self: end;
  align-self: center;
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
}

.life-icon {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ef4444;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
  transition: transform 0.2s, color 0.2s, filter 0.2s;
}

.life-icon svg {
  width: 34px;
  height: 34px;
}

.life-icon.lost {
  color: rgba(255, 255, 255, 0.25);
  filter: none;
  transform: scale(0.85);
}

#lives-wrap.last-life .life-icon:not(.lost) {
  animation: lastLifePulse 0.8s ease-in-out infinite;
  filter: drop-shadow(0 0 8px rgba(239, 68, 68, 0.9));
}

@keyframes lastLifePulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.15);
    opacity: 0.9;
  }
}

.target-swatch {
  display: inline-block;
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 50%;
  vertical-align: middle;
  flex-shrink: 0;
  box-shadow:
    inset -2px -2px 5px rgba(0, 0, 0, 0.2),
    inset 2px 2px 5px rgba(255, 255, 255, 0.4),
    0 0 0 2px rgba(0, 0, 0, 0.45),
    0 0 12px rgba(255, 255, 255, 0.3);
  background-color: #ff8fb3;
  position: relative;
}

.target-swatch::after {
  content: '';
  position: absolute;
  inset: 0;
  background: 
    radial-gradient(circle at 30% 40%, rgba(0,0,0,0.6) 10%, transparent 12%),
    radial-gradient(circle at 70% 40%, rgba(0,0,0,0.6) 10%, transparent 12%);
}

.target-swatch-hud {
  width: 0.95rem;
  height: 0.95rem;
}

.target-swatch.target-pulse {
  animation: target-pulse 0.55s ease-out 1;
}

@keyframes target-pulse {
  0% {
    transform: scale(1);
    box-shadow:
      0 0 0 2px rgba(0, 0, 0, 0.45),
      0 0 12px rgba(255, 255, 255, 0.35);
  }
  40% {
    transform: scale(1.35);
    box-shadow:
      0 0 0 3px rgba(255, 255, 255, 0.5),
      0 0 22px rgba(255, 255, 255, 0.45);
  }
  100% {
    transform: scale(1);
    box-shadow:
      0 0 0 2px rgba(0, 0, 0, 0.45),
      0 0 12px rgba(255, 255, 255, 0.2);
  }
}

.target-change-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.target-change-overlay.hidden {
  display: none;
}

.target-change-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.65rem;
  padding: 1.25rem 1.75rem 1.1rem;
  border-radius: 1.1rem;
  background: rgba(12, 10, 16, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.5),
    0 16px 48px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.target-countdown-center {
  font-size: clamp(3.5rem, 18vw, 5.5rem);
  line-height: 1;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #fde047;
  text-shadow:
    0 0 28px rgba(250, 204, 21, 0.75),
    0 0 4px rgba(0, 0, 0, 1);
}

.target-change-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: rgba(245, 240, 255, 0.5);
}

.target-next-swatch {
  display: block;
  width: clamp(3rem, 14vw, 4.25rem);
  height: clamp(3rem, 14vw, 4.25rem);
  border-radius: 50%;
  box-shadow:
    inset -4px -4px 10px rgba(0, 0, 0, 0.2),
    inset 4px 4px 10px rgba(255, 255, 255, 0.4),
    0 0 0 3px rgba(0, 0, 0, 0.5),
    0 0 24px rgba(255, 255, 255, 0.35);
  position: relative;
  animation: float-slime 3s ease-in-out infinite;
}

@keyframes float-slime {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-8px) scale(0.95, 1.05); }
}

.target-next-swatch::after {
  content: '';
  position: absolute;
  inset: 0;
  background: 
    radial-gradient(circle at 30% 40%, rgba(0,0,0,0.6) 10%, transparent 11%),
    radial-gradient(circle at 70% 40%, rgba(0,0,0,0.6) 10%, transparent 11%);
}

#game-canvas {
  display: block;
  flex: 1;
  min-height: 0;
  width: 100%;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  /* Own compositor layer: HUD/CSS animations less likely to reparent whole game view. */
  transform: translateZ(0);
  backface-visibility: hidden;
}

