* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  color: #fff;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  touch-action: none;
  position: fixed;
  inset: 0;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  padding:
    max(8px, env(safe-area-inset-top))
    max(8px, env(safe-area-inset-right))
    max(8px, env(safe-area-inset-bottom))
    max(8px, env(safe-area-inset-left));
}

#c {
  display: block;
  max-width: 100%;
  max-height: 100%;
  background: #000;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  z-index: 1;
}

#hud {
  position: absolute;
  top: max(6px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  right: max(48px, env(safe-area-inset-right));
  display: flex;
  justify-content: space-between;
  pointer-events: none;
  z-index: 5;
  font-family: ui-monospace, "Cascadia Mono", Menlo, monospace;
}

.hud-col .label {
  font-size: 10px;
  letter-spacing: 0.14em;
  color: #ffb8ae;
  opacity: 0.9;
}

.hud-col #score,
.hud-col #high,
.hud-col #level {
  font-size: clamp(16px, 4.2vw, 22px);
  color: #fff;
  letter-spacing: 0.06em;
  min-width: 3ch;
}

.hud-col.center { text-align: center; }
.hud-col.right { text-align: right; }

#lives, #fruit-tray {
  position: absolute;
  bottom: max(96px, calc(env(safe-area-inset-bottom) + 88px));
  z-index: 5;
  pointer-events: none;
  display: flex;
  gap: 6px;
  align-items: center;
}

#lives {
  left: max(12px, env(safe-area-inset-left));
}

#fruit-tray {
  right: max(12px, env(safe-area-inset-right));
}

.life-pip {
  width: 14px;
  height: 14px;
  border-radius: 50% 50% 50% 0;
  background: #ffe700;
  transform: rotate(-40deg);
  box-shadow: inset -2px -2px 0 #c4a800;
}

.fruit-pip {
  font-size: 16px;
  line-height: 1;
  filter: drop-shadow(0 1px 0 #000);
}

#btn-fs {
  position: absolute;
  top: max(6px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  z-index: 6;
  width: 36px;
  height: 36px;
  border: 1px solid #333;
  background: rgba(0, 0, 0, 0.55);
  color: #ffb8ff;
  font-size: 16px;
  border-radius: 6px;
  cursor: pointer;
}

#pad {
  position: absolute;
  bottom: max(10px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  opacity: 0.92;
}

#pad .mid {
  display: flex;
  gap: 48px;
}

#pad .dir {
  width: 58px;
  height: 48px;
  border: 1px solid #2a2a40;
  background: rgba(20, 20, 36, 0.85);
  color: #ffb8ff;
  font-size: 18px;
  border-radius: 10px;
  cursor: pointer;
  touch-action: manipulation;
}

#pad .dir:active {
  background: rgba(80, 40, 100, 0.9);
  border-color: #ffb8ff;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(0, 0, 0, 0.82);
  padding: 24px;
  text-align: center;
}

.overlay.hidden { display: none; }

.overlay h1 {
  font-size: clamp(36px, 10vw, 56px);
  color: #ffe700;
  letter-spacing: 0.08em;
  text-shadow: 0 0 24px rgba(255, 231, 0, 0.35);
  font-weight: 800;
}

.overlay .sub {
  color: #ffb8ff;
  font-size: 13px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.overlay .how {
  list-style: none;
  color: #ccc;
  font-size: 14px;
  line-height: 1.7;
  margin: 4px 0 12px;
}

.overlay .how b { color: #fff; }

.overlay .hint {
  color: #666;
  font-size: 12px;
  margin-top: 6px;
}

.overlay .final {
  font-family: ui-monospace, monospace;
  font-size: 28px;
  color: #fff;
  margin: 4px 0 12px;
}

#btn-start, #btn-again {
  min-width: 160px;
  padding: 14px 28px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.14em;
  border: none;
  border-radius: 8px;
  background: #ffe700;
  color: #000;
  cursor: pointer;
}

#btn-start:active, #btn-again:active {
  transform: scale(0.98);
}

.banner {
  position: absolute;
  left: 50%;
  top: 48%;
  transform: translate(-50%, -50%);
  z-index: 15;
  color: #ffe700;
  font-weight: 800;
  font-size: clamp(22px, 6vw, 32px);
  letter-spacing: 0.2em;
  pointer-events: none;
  text-shadow: 0 2px 0 #000;
}

.banner.hidden { display: none; }

/* Hide on-screen pad on wide desktop with keyboard preference */
@media (hover: hover) and (pointer: fine) and (min-width: 900px) {
  #pad { opacity: 0.35; }
}

@media (max-height: 640px) {
  #pad .dir { width: 50px; height: 40px; font-size: 15px; }
  #pad .mid { gap: 40px; }
  #lives, #fruit-tray {
    bottom: max(78px, calc(env(safe-area-inset-bottom) + 70px));
  }
}
