:root {
  --bg: #11131c;
  --panel: rgba(18, 21, 32, 0.92);
  --accent: #7ab0ff;
  --good: #5fd35f;
  --fly: #ffe66d;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: #fff;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#app { position: fixed; inset: 0; }

#game {
  position: absolute;
  inset: 0;
  display: block;
  background: #2a2f3a;
}

.hidden { display: none !important; }

/* ----------------------------------------------------------------- HUD --- */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

#hud-top {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  left: calc(env(safe-area-inset-left, 0px) + 12px);
  right: calc(env(safe-area-inset-right, 0px) + 12px);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

#score-box {
  background: rgba(10, 12, 20, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 6px 14px;
  backdrop-filter: blur(4px);
}
#score { font-size: 30px; font-weight: 800; line-height: 1.05; letter-spacing: 0.5px; }
#highscore { font-size: 12px; opacity: 0.7; font-weight: 600; }

#mute-btn {
  pointer-events: auto;
  width: 48px; height: 48px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(10, 12, 20, 0.55);
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  backdrop-filter: blur(4px);
}
#mute-btn:active { transform: scale(0.94); }

#stamina {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 74px);
  left: calc(env(safe-area-inset-left, 0px) + 12px);
  width: min(260px, 56vw);
}
#stamina-label { font-size: 10px; letter-spacing: 2px; opacity: 0.75; margin-bottom: 3px; font-weight: 700; }
#stamina-bar {
  height: 14px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.15);
  overflow: hidden;
}
#stamina-fill {
  height: 100%;
  width: 100%;
  background: var(--good);
  border-radius: 8px;
  transition: width 0.08s linear, background 0.25s linear;
}
#stamina.low #stamina-bar { animation: pulse 0.5s infinite alternate; }
@keyframes pulse { from { box-shadow: 0 0 0 rgba(231,76,60,0); } to { box-shadow: 0 0 14px rgba(231,76,60,0.8); } }

/* banner: rain warnings */
#banner {
  position: absolute;
  top: 18%;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  font-size: clamp(20px, 5vw, 34px);
  font-weight: 900;
  letter-spacing: 1px;
  color: #fff;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.7);
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  white-space: nowrap;
}
#banner.show { opacity: 1; transform: translateX(-50%) translateY(0); animation: bannerPulse 0.7s infinite alternate; }
@keyframes bannerPulse { from { filter: drop-shadow(0 0 2px #6aa3ff); } to { filter: drop-shadow(0 0 16px #6aa3ff); } }

/* milestone toast */
#toast {
  position: absolute;
  top: 30%;
  left: 50%;
  transform: translateX(-50%);
  font-size: 40px;
  font-weight: 900;
  color: var(--fly);
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
  opacity: 0;
}
#toast.show { animation: toastPop 1.1s ease-out; }
@keyframes toastPop {
  0% { opacity: 0; transform: translateX(-50%) scale(0.6); }
  20% { opacity: 1; transform: translateX(-50%) scale(1.1); }
  60% { opacity: 1; transform: translateX(-50%) translateY(-10px) scale(1); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-40px) scale(0.9); }
}

/* ----------------------------------------------------------- joystick --- */
#joystick { position: absolute; inset: 0; z-index: 9; pointer-events: none; display: none; }
#joy-base {
  position: absolute;
  width: 124px; height: 124px;
  margin: -62px 0 0 -62px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.45);
  background: rgba(120, 160, 230, 0.14);
  box-shadow: 0 0 24px rgba(0, 0, 0, 0.4);
}
#joy-thumb {
  position: absolute;
  width: 60px; height: 60px;
  margin: -30px 0 0 -30px;
  border-radius: 50%;
  background: rgba(180, 205, 255, 0.85);
  border: 2px solid #fff;
  box-shadow: 0 0 18px rgba(120, 170, 255, 0.7);
}

/* ----------------------------------------------------------- overlays --- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at 50% 35%, rgba(40, 60, 110, 0.55), rgba(8, 9, 16, 0.92));
  backdrop-filter: blur(3px);
}

.panel {
  width: min(440px, 92vw);
  max-height: 92vh;
  overflow-y: auto;
  text-align: center;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  padding: 26px 24px 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

.spider-mark { font-size: 52px; line-height: 1; margin-bottom: 4px; animation: bob 2s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-8px) rotate(3deg); } }

h1 { font-size: clamp(26px, 7vw, 36px); font-weight: 900; letter-spacing: 0.5px; }
h1.dead { color: #ff7b7b; }
.tag { opacity: 0.8; margin: 6px 0 16px; font-size: 15px; }

ul.how {
  list-style: none;
  text-align: left;
  margin: 0 auto 20px;
  display: grid;
  gap: 9px;
  font-size: 14px;
  line-height: 1.4;
}
ul.how li {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 10px;
  padding: 8px 12px;
}
.key {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 12px;
}

.big-btn {
  width: 100%;
  padding: 16px;
  font-size: 19px;
  font-weight: 800;
  color: #07210e;
  background: linear-gradient(180deg, #74e98a, #43c463);
  border: none;
  border-radius: 14px;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(67, 196, 99, 0.4);
  transition: transform 0.08s;
}
.big-btn:active { transform: scale(0.97); }

.hint-small { font-size: 12px; opacity: 0.6; margin-top: 12px; }

.big-score { font-size: 56px; font-weight: 900; color: var(--accent); margin: 6px 0 2px; }
.sub { opacity: 0.8; margin-bottom: 18px; }
.badge {
  display: none;
  color: #ffe66d;
  font-weight: 900;
  letter-spacing: 2px;
  margin: 8px 0;
  animation: badgeGlow 0.8s infinite alternate;
}
@keyframes badgeGlow { from { text-shadow: 0 0 4px #ffe66d; } to { text-shadow: 0 0 18px #ffe66d; } }

/* On clearly desktop (fine pointer, hover) shrink the joystick hint usage —
   touch still works because the joystick is created on demand from real touches. */
@media (hover: hover) and (pointer: fine) {
  #stamina { width: min(280px, 40vw); }
}
