:root {
  --color-sky-top: #7fd6ff;
  --color-sky-bottom: #bdeeff;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #0d1b2a;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* Fixed phone-sized surface (1080x1920); main.js CSS-scales this to fit
   whatever window/viewport it's actually shown in. */
#app {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 1080px;
  height: 1920px;
  transform-origin: center center;
  overflow: hidden;
  touch-action: none;
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.5);
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#debug-overlay {
  position: absolute;
  top: env(safe-area-inset-top, 0px);
  left: 0;
  padding: 6px 10px;
  font-size: 12px;
  line-height: 1.5;
  font-family: "Consolas", "SFMono-Regular", monospace;
  color: #baffc9;
  background: rgba(0, 0, 0, 0.55);
  border-bottom-right-radius: 8px;
  pointer-events: none;
  white-space: pre;
  z-index: 10;
}

#debug-overlay.hidden {
  display: none;
}

#score-hud {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 28px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 360px;
  height: 187px;
  padding-top: 38px;
  background: url("/imgs/png/HUD.png") center / 100% 100% no-repeat;
  pointer-events: none;
}

#score-count {
  font-size: 64px;
  font-weight: 800;
  color: #ffffff;
  -webkit-text-stroke: 3px #a3164f;
  paint-order: stroke fill;
  text-shadow: 0 4px 0 rgba(120, 10, 60, 0.45);
  font-variant-numeric: tabular-nums;
  display: inline-block;
}

#score-hud.pop #score-count {
  animation: score-pop 0.3s ease;
}

@keyframes score-pop {
  0% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.35);
  }
  100% {
    transform: scale(1);
  }
}

/* Next Order preview: the PNG is the panel; the upcoming glass sits in its
   empty cream area, contained (never stretched or cropped). */
#next-order-panel {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 176px);
  right: 28px;
  z-index: 15;
  width: 230px;
  aspect-ratio: 500 / 510;
  pointer-events: none;
  filter: drop-shadow(0 8px 12px rgba(0, 0, 0, 0.3));
}

#next-order-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#next-order-icon {
  position: absolute;
  left: 14%;
  right: 14%;
  top: 28%;
  bottom: 16%;
  width: 72%;
  height: 56%;
  object-fit: contain;
  opacity: 0;
  transform-origin: 50% 80%;
}

#next-order-panel:not(.has-order) #next-order-icon {
  visibility: hidden;
}

#next-order-icon.swap {
  animation: next-order-pop 0.32s ease-out both;
}

@keyframes next-order-pop {
  0% {
    opacity: 0;
    transform: scale(0.6) translateY(10px);
  }
  70% {
    opacity: 1;
    transform: scale(1.08);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

#home-button {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 28px);
  left: 28px;
  z-index: 15;
  width: 125px;
  height: 125px;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
}

/* imgs/Home.png already has its own glossy rounded-square background and
   drop shadow baked in, so the button itself just frames the image instead
   of drawing a circular backdrop behind a plain icon like the old inline
   SVG needed. */
#home-button img {
  width: 100%;
  height: 100%;
  display: block;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.3));
}

#home-button:active img {
  transform: translateY(3px);
}

#splash-screen {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 72px;
  background: #7fd6ff url("/imgs/png/splash-bg.png") center / cover no-repeat;
  transition: opacity 0.35s ease, visibility 0.35s ease;
}

#sound-toggle-button {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 28px);
  right: 28px;
  /* #splash-screen is a full-cover overlay at z-index 20 — this needs to
     sit above that (unlike home-button, which is fine staying hidden
     behind it) so it's actually visible/tappable on the splash page too,
     not just once splash is hidden during gameplay. */
  z-index: 21;
  width: 125px;
  height: 125px;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
}

/* Same art style/pattern as Home.png and Play.png — background and shadow
   already baked into the uploaded image, button just frames it. */
#sound-toggle-button img {
  width: 100%;
  height: 100%;
  display: block;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.3));
}

#sound-toggle-button:active img {
  transform: translateY(3px);
}

#splash-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.splash-title {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 0.9;
  text-transform: uppercase;
  letter-spacing: 4px;
}

.splash-title .title-merge {
  font-size: 96px;
  font-weight: 800;
  color: #ffffff;
  -webkit-text-stroke: 4px #1c8a6e;
  text-shadow: 0 8px 0 rgba(0, 0, 0, 0.12);
}

.splash-title .title-juice {
  font-size: 148px;
  font-weight: 800;
  color: #ff9c33;
  -webkit-text-stroke: 6px #b34c00;
  text-shadow: 0 10px 0 rgba(0, 0, 0, 0.15), 0 20px 30px rgba(0, 0, 0, 0.25);
  margin-top: -8px;
}

#world1-button,
#world2-button {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font: inherit;
  font-size: 44px;
  font-weight: 800;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: #ffffff;
  background: linear-gradient(180deg, #ffb347 0%, #ff8a1f 100%);
  border: none;
  border-radius: 999px;
  padding: 20px 72px;
  box-shadow: 0 8px 0 #b3560a, 0 14px 24px rgba(0, 0, 0, 0.35);
  cursor: pointer;
}

.splash-logo {
  position: absolute;
  top: 110px;
  left: 50%;
  width: 800px;
  transform: translateX(-50%);
  filter: drop-shadow(0 12px 18px rgba(0, 0, 0, 0.3));
  pointer-events: none;
}

#world1-button {
  bottom: calc(env(safe-area-inset-bottom, 0px) + 224px);
  width: 560px;
  padding: 34px 0;
  font-size: 64px;
}

#world2-button {
  bottom: calc(env(safe-area-inset-bottom, 0px) + 60px);
  width: 560px;
  padding: 26px 0;
  font-size: 52px;
}

#world1-button:active,
#world2-button:active {
  transform: translateX(-50%) translateY(5px);
  box-shadow: 0 3px 0 #b3560a, 0 8px 14px rgba(0, 0, 0, 0.3);
}

#game-over-screen {
  position: absolute;
  inset: 0;
  z-index: 25;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 40px;
  background: rgba(13, 27, 42, 0.82);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.35s ease, visibility 0.35s ease;
}

#game-over-screen.visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.game-over-title {
  width: 640px;
  height: auto;
  filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.4));
}

.game-over-score {
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding: 14px 40px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.32);
}

.game-over-score-label {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #ffffff;
  opacity: 0.85;
}

#final-score-count {
  font-size: 44px;
  font-weight: 800;
  color: #ffffff;
  font-variant-numeric: tabular-nums;
}

#retry-button {
  font: inherit;
  font-size: 48px;
  font-weight: 800;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: #ffffff;
  background: linear-gradient(180deg, #ffb347 0%, #ff8a1f 100%);
  border: none;
  border-radius: 999px;
  padding: 24px 80px;
  box-shadow: 0 10px 0 #b3560a, 0 18px 30px rgba(0, 0, 0, 0.35);
  cursor: pointer;
}

#retry-button:active {
  transform: translateY(6px);
  box-shadow: 0 4px 0 #b3560a, 0 10px 18px rgba(0, 0, 0, 0.3);
}

/* ======================= transitions & animations ======================= */

/* Splash: logo drops in then floats; buttons rise in one after another. Runs
   again every time the splash is shown (the selector starts matching). */
#splash-screen:not(.hidden) .splash-logo {
  animation: logo-drop 0.8s cubic-bezier(0.2, 1.3, 0.4, 1) both, logo-float 4s ease-in-out 0.8s infinite;
}

#splash-screen:not(.hidden) #world1-button {
  animation: btn-rise 0.55s cubic-bezier(0.2, 1.2, 0.4, 1) 0.45s backwards, btn-glow 2.4s ease-in-out 1.2s infinite;
}

#splash-screen:not(.hidden) #world2-button {
  animation: btn-rise 0.55s cubic-bezier(0.2, 1.2, 0.4, 1) 0.65s backwards;
}

@keyframes logo-drop {
  0% {
    opacity: 0;
    transform: translateX(-50%) translateY(-260px) scale(0.7) rotate(-4deg);
  }
  100% {
    opacity: 1;
    transform: translateX(-50%) translateY(0) scale(1) rotate(0);
  }
}

@keyframes logo-float {
  0%, 100% {
    transform: translateX(-50%) translateY(0);
  }
  50% {
    transform: translateX(-50%) translateY(-12px);
  }
}

@keyframes btn-rise {
  0% {
    opacity: 0;
    transform: translateX(-50%) translateY(60px) scale(0.92);
  }
  100% {
    opacity: 1;
    transform: translateX(-50%) translateY(0) scale(1);
  }
}

@keyframes btn-glow {
  0%, 100% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(1.12) drop-shadow(0 0 14px rgba(255, 220, 120, 0.9));
  }
}

#world1-button,
#world2-button,
#retry-button,
#home-button img,
#sound-toggle-button img {
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.2s ease;
}

@media (hover: hover) {
  #world1-button:hover,
  #world2-button:hover,
  #retry-button:hover {
    filter: brightness(1.08);
  }
  #home-button:hover img,
  #sound-toggle-button:hover img {
    transform: scale(1.06);
  }
}

/* Entering World 1: the HUD slides in around the board. */
#app.in-game #score-hud {
  animation: hud-drop 0.55s cubic-bezier(0.2, 1.2, 0.4, 1) 0.15s backwards;
}

#app.in-game #home-button {
  animation: hud-slide-left 0.5s cubic-bezier(0.2, 1.2, 0.4, 1) 0.25s backwards;
}

#app.in-game #next-order-panel {
  animation: hud-slide-right 0.55s cubic-bezier(0.2, 1.2, 0.4, 1) 0.35s backwards;
}

@keyframes hud-drop {
  0% {
    opacity: 0;
    transform: translateX(-50%) translateY(-200px);
  }
  100% {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

@keyframes hud-slide-left {
  0% {
    opacity: 0;
    transform: translateX(-200px);
  }
  100% {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes hud-slide-right {
  0% {
    opacity: 0;
    transform: translateX(300px);
  }
  100% {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Game over: title slams in, the score pill and button follow. */
#game-over-screen.visible .game-over-title {
  animation: over-title 0.7s cubic-bezier(0.2, 1.4, 0.4, 1) 0.05s backwards;
}

#game-over-screen.visible .game-over-score {
  animation: over-rise 0.45s ease-out 0.35s backwards;
}

#game-over-screen.visible #retry-button {
  animation: over-rise 0.5s cubic-bezier(0.2, 1.3, 0.4, 1) 0.55s backwards, over-pulse 1.8s ease-in-out 1.3s infinite;
}

@keyframes over-title {
  0% {
    opacity: 0;
    transform: scale(2.2) rotate(-6deg);
  }
  100% {
    opacity: 1;
    transform: scale(1) rotate(0);
  }
}

@keyframes over-rise {
  0% {
    opacity: 0;
    transform: translateY(60px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes over-pulse {
  0%, 100% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(1.12);
  }
}

@media (prefers-reduced-motion: reduce) {
  #splash-screen .splash-logo,
  #splash-screen #world1-button,
  #splash-screen #world2-button,
  #app.in-game #score-hud,
  #app.in-game #home-button,
  #app.in-game #next-order-panel,
  #game-over-screen .game-over-title,
  #game-over-screen .game-over-score,
  #game-over-screen #retry-button {
    animation: none !important;
  }
}