html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
  font-family: sans-serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  user-select: none;
}

.scene-bg-layer {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  background-color: #87CEEB;
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  pointer-events: none;
  transform: translateZ(0);
}

.scene-bg-layer2 {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  background-color: #e8e4f0;
  background-position: center center;
  background-size: auto 100%;
  background-repeat: no-repeat;
  pointer-events: none;
  transform: translateZ(0);
}

.scene-game-layer {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: transparent;
  container-type: size;
  --ui-unit: min(0.28vw, 0.45vh);
  --ui-unit: min(1cqw, 1.6cqh);
}

.scene-hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: auto;
  gap: clamp(1px, 0.4cqh, 4px) clamp(2px, 0.8cqw, 6px);
  padding: clamp(2px, 0.6cqh, 8px) clamp(3px, 1.2cqw, 10px);
  align-items: center;
  pointer-events: none;
}

#score, #timer, #total-score {
  position: static;
  font-size: clamp(7px, calc(var(--ui-unit) * 3.2), 22px);
  color: #333;
  background: rgba(255, 255, 130, 0.919);
  padding: clamp(2px, calc(var(--ui-unit) * 1), 10px) clamp(4px, calc(var(--ui-unit) * 1.8), 18px);
  border-radius: clamp(3px, calc(var(--ui-unit) * 0.9), 10px);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  box-sizing: border-box;
}

#score {
  grid-column: 1;
  grid-row: 1;
  justify-self: start;
}

#timer {
  grid-column: 3;
  grid-row: 1;
  justify-self: end;
}

#total-score {
  grid-column: 2;
  grid-row: 1;
  justify-self: center;
  font-size: clamp(6px, calc(var(--ui-unit) * 2.6), 16px);
}

.fish, .scene-target {
  position: absolute;
  background-size: contain;
  background-repeat: no-repeat;
  cursor: pointer;
  z-index: 1;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.fish.frog {
  transform-origin: center bottom;
}

.fish.sway {
  transform-origin: center center;
}

.fish.spin {
  transform-origin: center center;
}

.point {
  position: absolute;
  font-size: 50px;
  color: gold;
  font-weight: bold;
  animation: pop 0.5s ease;
  pointer-events: none;
  z-index: 100;
}

@keyframes pop {
  0% { transform: scale(1); opacity: 1; }
  100% { transform: scale(2); opacity: 0; }
}

.star-particle {
  position: fixed;
  font-size: 28px;
  line-height: 1;
  pointer-events: none;
  z-index: 100;
  text-shadow: 0 0 4px rgba(255, 255, 255, 0.8);
  animation: star-scatter 0.65s ease-out forwards;
}

@keyframes star-scatter {
  0% {
    transform: translate(-50%, -50%) scale(0.4) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translate(calc(-50% + var(--tx)), calc(-50% + var(--ty))) scale(1.2) rotate(180deg);
    opacity: 0;
  }
}

#scene-end-msg {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
  color: #333;
  font-size: clamp(8px, calc(var(--ui-unit) * 3.6), 26px);
  padding: clamp(6px, calc(var(--ui-unit) * 2), 20px) clamp(8px, calc(var(--ui-unit) * 3.5), 36px);
  border-radius: clamp(6px, calc(var(--ui-unit) * 2), 20px);
  display: none;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
  z-index: 100;
  white-space: pre-line;
  line-height: 1.5;
  max-width: min(92vw, 28em);
  max-height: 55vh;
  overflow-y: auto;
  box-sizing: border-box;
}

#scene-next-btn {
  position: fixed;
  right: clamp(6px, 2cqw, 20px);
  bottom: clamp(6px, 2cqh, 20px);
  z-index: 110;
  font-size: clamp(8px, calc(var(--ui-unit) * 3), 20px);
  padding: clamp(5px, calc(var(--ui-unit) * 1.4), 14px) clamp(8px, calc(var(--ui-unit) * 2.5), 26px);
  border: none;
  border-radius: clamp(4px, calc(var(--ui-unit) * 1.2), 12px);
  background: #28a745;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

#scene-next-btn:hover {
  background: #218838;
}

#scene-next-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

#bucket {
  position: fixed;
  top: 40px;
  left: 150px;
  width: 200px;
  height: auto;
  z-index: 100;
  display: none;
}

.scene-label {
  position: absolute;
  top: clamp(28px, 11cqh, 60px);
  left: 50%;
  width: min(92%, 100%);
  transform: translateX(-50%);
  font-size: clamp(8px, calc(var(--ui-unit) * 5.5), 56px);
  white-space: nowrap;
  text-align: center;
  color: rgba(0, 0, 0, 0.5);
  z-index: 5;
  line-height: 1.1;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* game-end */
.end-screen {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#final-result {
  position: absolute;
  inset: 0;
  width: 100%;
  max-width: none;
  box-sizing: border-box;
  background: transparent;
  color: #333;
  font-size: 32px;
  padding: 0;
  border-radius: 0;
  box-shadow: none;
  text-align: left;
  margin-bottom: 0;
  pointer-events: none;
}

#final{
  font-size: 20px;
  margin-top: 15px;
  color: #e67e22;
}

.final-story {
  position: absolute;
  top: 30px;
  left: 30px;
  max-width: 50vw;
  box-sizing: border-box;
  background: #fff;
  font-size: 26px;
  padding: 24px 40px;
  border-radius: 20px;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
  white-space: pre-line;
  line-height: 1.5;
}

.final-bottom-row {
  position: absolute;
  right: 30px;
  bottom: 30px;
  display: flex;
  align-items: center;
  gap: 20px;
  pointer-events: auto;
}

.final-score-panel {
  display: flex;
  align-items: baseline;
  gap: 16px;
  box-sizing: border-box;
  background: #fff;
  padding: 24px 40px;
  border-radius: 20px;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
  text-align: center;
}

#final-total {
  font-size: 44px;
  font-weight: bold;
  color: #e67e22;
  margin-top: 0;
  line-height: 1.3;
  white-space: pre-line;
}

#final-breakdown {
  font-size: 28px;
  margin-top: 15px;
  color: #1b89ff;
}

#replayBtn {
  position: relative;
  z-index: 10;
  margin-top: 0;
  font-size: 20px;
  padding: 12px 24px;
  border: none;
  background: #28a745;
  color: white;
  border-radius: 10px;
  cursor: pointer;
}

#replayBtn:hover {
  background: #218838;
}
