:root {
  --bg: #f4eee4;
  --bg-deep: #e8dfd0;
  --ink: #1e293b;
  --muted: rgba(30, 41, 59, 0.48);
  --teal: #0d9488;
  --indigo: #6366f1;
  --life: #e11d48;
  --font: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-display: "Fraunces", "IBM Plex Sans", Georgia, serif;
}

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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(ellipse 85% 65% at 50% 38%, #fbf7f0 0%, transparent 55%),
    linear-gradient(168deg, var(--bg) 0%, var(--bg-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%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

#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(26px, 7vw, 34px);
  height: clamp(26px, 7vw, 34px);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--life);
  transform-origin: center;
  will-change: transform, opacity;
}

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

.life-icon.lost {
  color: rgba(30, 41, 59, 0.18);
  opacity: 0.55;
}

.life-icon.just-lost {
  animation: heart-break 0.55s ease-out forwards;
  color: var(--life);
  opacity: 1;
}

#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: 700;
  letter-spacing: 0.04em;
  color: #be123c;
  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 {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 16px;
}

#hud .label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--muted);
}

#streak {
  font-family: var(--font-display);
  font-size: clamp(1.9rem, 7vw, 2.45rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--teal);
  letter-spacing: -0.02em;
  line-height: 1;
}

#game-canvas {
  width: min(88vw, 360px);
  height: min(88vw, 360px);
  max-height: min(52vh, 420px);
  border-radius: 50%;
  touch-action: none;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.7) inset,
    0 16px 40px rgba(30, 41, 59, 0.12),
    0 4px 12px rgba(30, 41, 59, 0.06);
}

.hint {
  margin-top: 18px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--muted);
  text-align: center;
  max-width: 280px;
  line-height: 1.35;
}

.hint.hidden {
  visibility: hidden;
}

@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 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);
  }
}

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

@media (min-width: 600px) {
  #wrap {
    padding: max(22px, env(safe-area-inset-top)) max(28px, env(safe-area-inset-right))
      max(22px, env(safe-area-inset-bottom)) max(28px, env(safe-area-inset-left));
  }

  #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;
    margin-bottom: 22px;
  }

  #hud .label {
    font-size: 0.92rem;
    letter-spacing: 0.18em;
  }

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

  #game-canvas {
    width: min(62vw, 58vh, 460px);
    height: min(62vw, 58vh, 460px);
    max-height: none;
  }

  .hint {
    margin-top: 24px;
    font-size: 1.05rem;
    max-width: 360px;
  }
}

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

  #game-canvas {
    width: min(52vw, 56vh, 540px);
    height: min(52vw, 56vh, 540px);
  }

  .hint {
    margin-top: 28px;
    font-size: 1.12rem;
  }
}
