:root {
  --abyss: #050b14;
  --deep: #0a1626;
  --glow-teal: #4ce0d2;
  --glow-violet: #9b8cf0;
  --hazard: #ff6b5e;
  --plankton: #ffd98e;
  --ink: #cfe8ea;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  background: transparent;
  overflow: hidden;
  font-family: 'Georgia', 'Iowan Old Style', serif;
  user-select: none;
  -webkit-user-select: none;
}

#wrap {
  position: relative;
  width: 100%;
  height: 100%;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: transparent;
}

#gameBox {
  position: relative;
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  aspect-ratio: 420 / 680;
  width: auto;
  max-width: 100vw;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: radial-gradient(ellipse at 50% 0%, var(--deep) 0%, var(--abyss) 70%);
  touch-action: none;
  cursor: crosshair;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.8);
}

#hud {
  position: absolute;
  top: max(16px, env(safe-area-inset-top, 16px));
  left: 50%;
  transform: translateX(-50%);
  color: var(--ink);
  letter-spacing: 0.12em;
  font-size: clamp(15px, 2.5vh, 18px);
  text-transform: uppercase;
  opacity: 0.9;
  pointer-events: none;
  text-shadow: 0 0 12px rgba(76, 224, 210, 0.5);
  font-weight: bold;
  z-index: 5;
  white-space: nowrap;
}

#bottomContainer {
  position: absolute;
  bottom: max(16px, env(safe-area-inset-bottom, 16px));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  z-index: 5;
  width: 90%;
}

#statusList {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.status-badge {
  font-size: clamp(13px, 2.2vh, 16px);
  font-weight: bold;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 4px 12px;
  border-radius: 8px;
  white-space: nowrap;
  box-sizing: border-box;
  /* Promote to own GPU compositor layer so animations never trigger DisplayList rebuilds */
  will-change: transform, opacity;
  /* Limit layout/paint scope to this element only */
  contain: layout style;
}

/* 1. Eat Mode Active: Crimson Heartbeat Scale */
.status-eat-active {
  color: #ff6b5e;
  background: rgba(255, 107, 94, 0.18);
  border: 1px solid rgba(255, 107, 94, 0.5);
  /* Static box-shadow is fine — only animated box-shadow causes DisplayList rebuilds */
  box-shadow: 0 0 18px rgba(255, 107, 94, 0.45);
  animation: pulseEat 0.75s ease-in-out infinite alternate;
}

/* Only transform — GPU compositable, never triggers a paint */
@keyframes pulseEat {
  0% {
    transform: scale(0.96);
    opacity: 0.85;
  }

  100% {
    transform: scale(1.05);
    opacity: 1;
  }
}

/* 2. Ready to Eat: Soft Teal Sway & Floating Bounce */
.status-eat-ready {
  color: var(--glow-teal);
  background: rgba(76, 224, 210, 0.14);
  border: 1px solid rgba(76, 224, 210, 0.4);
  animation: bounceReady 1.4s ease-in-out infinite;
}

/* translateY + opacity only — both compositable, no paint */
@keyframes bounceReady {

  0%,
  100% {
    transform: translateY(0);
    opacity: 0.75;
  }

  50% {
    transform: translateY(-3px);
    opacity: 1;
  }
}

/* 3. Magnetic Surge: Electric Cyan Skew */
.status-magnetic {
  color: #4ce0d2;
  background: rgba(76, 224, 210, 0.22);
  border: 1px solid rgba(76, 224, 210, 0.65);
  box-shadow: 0 0 20px rgba(76, 224, 210, 0.55);
  animation: magShimmer 0.55s linear infinite alternate;
}

/* skewX + scale only — filter:brightness() is NOT compositable and causes repaints */
@keyframes magShimmer {
  0% {
    transform: skewX(-3deg) scale(0.97);
    opacity: 0.8;
  }

  100% {
    transform: skewX(3deg) scale(1.03);
    opacity: 1;
  }
}

/* 4. Abyssal Dark Zone: Deep Violet Breath */
.status-darkzone {
  color: #b0a4f5;
  background: rgba(155, 140, 240, 0.18);
  border: 1px solid rgba(155, 140, 240, 0.45);
  animation: darkBreathe 1.8s ease-in-out infinite alternate;
}

/* opacity + subtle scale only — filter:hue-rotate and box-shadow are NOT compositable */
@keyframes darkBreathe {
  0% {
    opacity: 0.55;
    transform: scale(0.97);
  }

  100% {
    opacity: 1;
    transform: scale(1.01);
  }
}

/* 5. Paused Game Warning */
.status-paused {
  color: #ffd98e;
  background: rgba(255, 217, 142, 0.18);
  border: 1px solid rgba(255, 217, 142, 0.45);
  animation: flashPaused 1s step-end infinite;
}

@keyframes flashPaused {
  50% {
    opacity: 0.35;
  }
}

/* 6. Biome Badge */
.status-biome {
  color: #cfe8ea;
  background: rgba(10, 22, 38, 0.45);
  border: 1px solid rgba(76, 224, 210, 0.5);
  box-shadow: 0 0 12px rgba(0, 0, 0, 0.4);
}

#depth {
  color: var(--glow-teal);
  font-size: clamp(11px, 1.8vh, 13px);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  opacity: 0.65;
  pointer-events: none;
  white-space: nowrap;
}

#overlay,
#pauseOverlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  text-align: center;
  background: rgba(5, 11, 20, 0.82);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: opacity 0.4s ease;
  padding: 16px;
  box-sizing: border-box;
  z-index: 10;
}

#overlay .card,
#pauseOverlay .card {
  background: rgba(10, 22, 38, 0.92);
  border: 1px solid rgba(76, 224, 210, 0.35);
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.7), inset 0 0 15px rgba(76, 224, 210, 0.08);
  border-radius: 16px;
  padding: 20px 18px;
  max-width: 360px;
  width: 90%;
  max-height: 85dvh;
  overflow-y: auto;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#overlay h1,
#pauseOverlay h1 {
  font-weight: 600;
  font-size: clamp(28px, 5vh, 38px);
  letter-spacing: 0.12em;
  margin: 0 0 10px 0;
  color: var(--glow-teal);
  text-shadow: 0 0 20px rgba(76, 224, 210, 0.6);
}

#overlay .section,
#pauseOverlay .section {
  width: 100%;
  margin-bottom: 10px;
  text-align: left;
}

#overlay .sec-title,
#pauseOverlay .sec-title {
  font-size: clamp(10px, 1.6vh, 11px);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--glow-violet);
  margin-bottom: 4px;
  font-weight: bold;
}

#overlay .sec-body,
#pauseOverlay .sec-body {
  font-size: clamp(12px, 1.8vh, 13px);
  opacity: 0.88;
  line-height: 1.45;
}

#overlay .control-grid,
#pauseOverlay .control-grid {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-top: 4px;
}

#overlay .ctrl-item,
#pauseOverlay .ctrl-item {
  font-size: clamp(12px, 1.8vh, 13px);
  opacity: 0.9;
}

#overlay .key,
#pauseOverlay .key {
  display: inline-block;
  background: rgba(76, 224, 210, 0.15);
  border: 1px solid rgba(76, 224, 210, 0.4);
  color: var(--glow-teal);
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 11px;
  font-family: monospace;
  font-weight: bold;
}

#overlay .score-line {
  font-size: clamp(14px, 2.2vh, 16px);
  color: var(--plankton);
  margin: 8px 0 14px 0;
  opacity: 0.95;
  font-weight: bold;
}

#startBtn,
#resumeBtn {
  font-family: inherit;
  background: transparent;
  border: 1px solid var(--glow-teal);
  color: var(--glow-teal);
  padding: 10px 32px;
  border-radius: 999px;
  font-size: clamp(13px, 2vh, 14px);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  cursor: pointer;
  margin-top: 6px;
  transition: all 0.25s ease;
}

#startBtn:hover,
#resumeBtn:hover {
  background: var(--glow-teal);
  color: var(--abyss);
  box-shadow: 0 0 24px rgba(76, 224, 210, 0.6);
}

#pauseBtn {
  position: absolute;
  top: max(14px, env(safe-area-inset-top, 14px));
  left: max(14px, env(safe-area-inset-left, 14px));
  z-index: 15;
  background: rgba(10, 22, 38, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(76, 224, 210, 0.45);
  color: var(--glow-teal);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 0 14px rgba(0, 0, 0, 0.5), 0 0 8px rgba(76, 224, 210, 0.25);
  transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

#pauseBtn:hover {
  background: rgba(76, 224, 210, 0.25);
  border-color: var(--glow-teal);
  transform: scale(1.08);
  box-shadow: 0 0 20px rgba(76, 224, 210, 0.55);
}

#pauseBtn:active {
  transform: scale(0.92);
}

#fullscreenBtn {
  position: absolute;
  top: max(14px, env(safe-area-inset-top, 14px));
  right: max(14px, env(safe-area-inset-right, 14px));
  z-index: 15;
  background: rgba(10, 22, 38, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(76, 224, 210, 0.45);
  color: var(--glow-teal);
  width: 35px;
  height: 35px;
  border-radius: 50%;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 0 14px rgba(0, 0, 0, 0.5), 0 0 8px rgba(76, 224, 210, 0.25);
  transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

#fullscreenBtn:hover {
  background: rgba(76, 224, 210, 0.25);
  border-color: var(--glow-teal);
  transform: scale(1.08);
  box-shadow: 0 0 20px rgba(76, 224, 210, 0.55);
}

#fullscreenBtn:active {
  transform: scale(0.92);
}