* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0d2a10;
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  color: #fff;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  padding: calc(8px + env(safe-area-inset-top)) 10px 0 10px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  z-index: 5;
}
.hud-left { display: flex; align-items: center; gap: 8px; }
#avatar {
  width: 64px; height: 64px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 3px 10px rgba(0,0,0,.5);
  overflow: hidden;
  background: #222;
}
#avatarCanvas { width: 100%; height: 100%; display: block; }
.hud-stats { text-shadow: 0 2px 4px rgba(0,0,0,.7); line-height: 1.1; }
.hud-name { font-size: 13px; opacity: .85; letter-spacing: 1px; text-transform: uppercase; }
.hud-score { font-size: 30px; font-weight: 900; }
.hud-score .unit { font-size: 22px; }
.hud-combo { font-size: 15px; font-weight: 700; color: #ffd54f; min-height: 18px; }

.hud-center { position: absolute; left: 50%; top: calc(8px + env(safe-area-inset-top)); transform: translateX(-50%); }
#timer {
  font-size: 34px;
  font-weight: 900;
  padding: 2px 16px;
  background: rgba(0,0,0,.45);
  border-radius: 999px;
  border: 2px solid rgba(255,255,255,.4);
  min-width: 80px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
#timer.urgent { color: #ff5252; border-color: #ff5252; animation: pulse .5s infinite alternate; }
@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.12); } }

.hud-right { display: flex; gap: 6px; pointer-events: auto; }
.icon-btn {
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.5);
  background: rgba(0,0,0,.45);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
}
.icon-btn:active { background: rgba(255,255,255,.25); }

/* ---------- Overlays ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 25, 8, .72);
  backdrop-filter: blur(3px);
  z-index: 10;
  padding: 12px;
  overflow: auto;
}
.panel {
  width: min(92vw, 460px);
  background: linear-gradient(160deg, #2e7d32, #1b5e20);
  border: 4px solid #fff;
  border-radius: 24px;
  padding: 22px 20px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
  animation: pop .35s cubic-bezier(.2,1.4,.4,1);
}
@keyframes pop { from { transform: scale(.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.hero {
  width: 120px; height: 120px;
  object-fit: cover;
  object-position: 50% 45%;
  border-radius: 50%;
  border: 4px solid #fff;
  box-shadow: 0 6px 16px rgba(0,0,0,.5);
  animation: wobble 1.6s ease-in-out infinite;
}
@keyframes wobble {
  0%, 100% { transform: rotate(-6deg) scale(1); }
  50% { transform: rotate(6deg) scale(1.06); }
}
h1 {
  margin: 10px 0 4px;
  font-size: clamp(28px, 7vw, 40px);
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: 1px;
  text-shadow: 3px 3px 0 #0d2a10;
}
h2 { margin: 8px 0; font-size: 28px; text-shadow: 2px 2px 0 #0d2a10; }
.tagline { margin: 6px 0 12px; font-size: 14px; opacity: .92; line-height: 1.35; }
.rules {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 10px;
  text-align: left;
  font-size: 13px;
  background: rgba(0,0,0,.25);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 10px;
}
.rules .k { display: inline-block; width: 22px; }
.controls { font-size: 13px; margin-bottom: 14px; opacity: .95; }
.ctl { padding: 4px 0; }
.mobile-only { display: none; }
@media (pointer: coarse) {
  .mobile-only { display: block; }
  .desktop-only { display: none; }
}

.big-btn {
  display: block;
  width: 100%;
  padding: 16px 12px;
  font-size: clamp(16px, 4.5vw, 20px);
  font-weight: 900;
  letter-spacing: 1px;
  color: #1b1b1b;
  background: linear-gradient(#ffe082, #ffb300);
  border: 3px solid #fff;
  border-radius: 16px;
  cursor: pointer;
  box-shadow: 0 6px 0 #b27a00, 0 10px 20px rgba(0,0,0,.4);
  transition: transform .08s, box-shadow .08s;
}
.big-btn:active { transform: translateY(5px); box-shadow: 0 1px 0 #b27a00, 0 4px 10px rgba(0,0,0,.4); }
.small-btn {
  margin-top: 10px;
  background: transparent;
  border: 2px solid rgba(255,255,255,.6);
  color: #fff;
  border-radius: 999px;
  padding: 8px 20px;
  font-size: 14px;
  cursor: pointer;
}
.best { margin-top: 12px; font-size: 14px; opacity: .9; }
.newbest { color: #ffd54f; font-weight: 900; animation: pulse .4s infinite alternate; display: inline-block; }

#goAvatar {
  width: 150px; height: 150px;
  margin: 0 auto;
  border-radius: 50%;
  border: 4px solid #fff;
  overflow: hidden;
  box-shadow: 0 6px 16px rgba(0,0,0,.5);
}
#goAvatarCanvas { width: 100%; height: 100%; display: block; }
.final-score { font-size: 56px; font-weight: 900; text-shadow: 3px 3px 0 #0d2a10; line-height: 1; }
.go-msg { font-size: 16px; margin-top: 6px; font-style: italic; opacity: .95; }

@media (max-height: 560px) {
  .hero { width: 80px; height: 80px; }
  .panel { padding: 14px; }
  .tagline { display: none; }
}
