* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: #111;
  overflow-y: auto; /* safety net: scrollable if the viewport calc below is ever off, instead of controls being unreachable */
  overflow-x: hidden;
  font-family: "Hiragino Sans", "Yu Gothic", sans-serif;
  touch-action: manipulation; /* blocks double-tap/pinch zoom but still allows the overflow-y fallback to scroll */
}

#game-container {
  position: relative;
  width: 100vw;
  /* mobile browsers' address bar makes 100vh taller than what's actually visible, cutting off
     the bottom controls; --app-height is kept in sync with the real visible height via JS
     (window.visualViewport), with 100dvh as a fallback for the instant before that JS runs. */
  height: 100dvh;
  height: var(--app-height, 100dvh);
  display: flex;
  align-items: center;
  justify-content: center;
}

#game-canvas {
  background: #222;
  display: block;
  /* actual on-screen size is set by JS to preserve the 1280x720 aspect ratio */
}

/* ---------- HUD ---------- */

#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  color: #fff;
  font-weight: bold;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
  pointer-events: none;
  font-size: 14px;
}

#hud-timer-wrap {
  flex: 1;
  height: 10px;
  background: rgba(0,0,0,0.4);
  border-radius: 6px;
  overflow: hidden;
}

#hud-timer-bar {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #ffb6c1, #ff6f91);
  transition: width 0.2s linear;
}

/* ---------- Screens (title / stage clear / game over / rotate) ---------- */

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(0,0,0,0.72);
  color: #fff;
  text-align: center;
  padding: 24px;
}

.screen.hidden {
  display: none;
}

.screen h1 {
  font-size: clamp(32px, 8vw, 56px);
  margin: 0;
  letter-spacing: 0.1em;
}

.screen h2 {
  font-size: clamp(24px, 6vw, 40px);
  margin: 0;
}

.screen p {
  margin: 0;
  font-size: 16px;
}

.screen .hint {
  opacity: 0.7;
  font-size: 13px;
  margin-top: 8px;
}

#title-screen button,
#gameover-screen button {
  padding: 12px 32px;
  font-size: 18px;
  font-weight: bold;
  border: none;
  border-radius: 999px;
  background: linear-gradient(90deg, #ff9eb5, #ff6f91);
  color: #fff;
  cursor: pointer;
}

#gameover-reward {
  max-width: min(220px, 40vw);
  max-height: 220px;
  width: auto;
  height: auto;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

#gameover-reward.hidden {
  display: none;
}

#stageclear-screen {
  background: rgba(255, 182, 193, 0.35);
  pointer-events: none;
}

#rotate-prompt {
  z-index: 50;
  background: rgba(0,0,0,0.9);
  font-size: 20px;
}

/* ---------- Stage intro banner ---------- */

#stage-intro {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(255, 105, 150, 0.55);
  color: #fff;
  text-align: center;
  padding: 24px;
  opacity: 1;
  transition: opacity 0.8s ease;
}

#stage-intro.hidden {
  display: none;
}

#stage-intro.fade-out {
  opacity: 0;
}

#stage-intro h2 {
  font-size: clamp(32px, 8vw, 52px);
  margin: 0;
  text-shadow: 0 2px 6px rgba(0,0,0,0.35);
}

#stage-intro p {
  font-size: clamp(15px, 3.2vw, 20px);
  margin: 0;
  text-shadow: 0 1px 4px rgba(0,0,0,0.35);
}

/* ---------- GO banner ---------- */

#go-banner {
  position: absolute;
  top: 50%;
  left: 0;
  z-index: 45;
  /* the X offset uses vw (viewport-relative), not %, because % on transform is relative to the
     element's OWN small text-box width — that made it travel only a short self-relative distance
     and fade out well before actually reaching the right edge of the screen. */
  transform: translate(-100vw, -50%);
  font-size: clamp(48px, 12vw, 96px);
  font-weight: 900;
  color: #fff;
  letter-spacing: 0.08em;
  text-shadow: 0 2px 10px rgba(0,0,0,0.5), 0 0 24px rgba(255,110,145,0.9);
  pointer-events: none;
  white-space: nowrap;
}

#go-banner.hidden {
  display: none;
}

#go-banner.slide {
  animation: go-slide 0.5s ease-in forwards;
}

@keyframes go-slide {
  0%   { transform: translate(-100vw, -50%); opacity: 0; }
  8%   { opacity: 1; }
  92%  { opacity: 1; }
  100% { transform: translate(100vw, -50%); opacity: 0; }
}

/* ---------- Touch controls ---------- */

#touch-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px calc(16px + env(safe-area-inset-bottom));
  pointer-events: none;
}

#touch-controls.visible {
  display: flex;
}

#touch-move-group {
  display: flex;
  gap: 18px;
}

.ctrl-btn {
  pointer-events: auto;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.25);
  color: #fff;
  font-size: 22px;
  font-weight: bold;
  -webkit-user-select: none;
  user-select: none;
}

.ctrl-btn.action {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: rgba(255, 111, 145, 0.85);
  font-size: 16px;
}

.ctrl-btn:active {
  background: rgba(255,255,255,0.45);
}

.ctrl-btn.action:active {
  background: rgba(255, 111, 145, 1);
}
