:root {
  color-scheme: light;
  --ink: #15344c;
  --soft-ink: #4b6a7f;
  --sun: #ffd85c;
  --sun-hot: #ff9f2e;
  --grass: #54b95f;
  --sky: #9ddcff;
  --panel: rgba(255, 255, 255, 0.74);
  --panel-strong: rgba(255, 255, 255, 0.9);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  overscroll-behavior: none;
  overflow: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 10%, rgba(255, 252, 199, 0.95), transparent 22rem),
    linear-gradient(180deg, #8ed7ff 0%, #e5f8ff 48%, #c8f2a6 100%);
}

button {
  font: inherit;
}

.game-shell {
  display: grid;
  width: 100vw;
  height: 100vh;
  place-items: center;
  padding: clamp(10px, 2vw, 24px);
}

.stage-wrap {
  position: relative;
  width: min(100%, 1280px);
  aspect-ratio: 16 / 9;
  max-height: calc(100vh - clamp(20px, 4vw, 48px));
  overflow: hidden;
  border: 1px solid rgba(65, 150, 150, 0.28);
  border-radius: 8px;
  background: #9ddcff;
  box-shadow: 0 22px 70px rgba(50, 123, 138, 0.26);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.hud {
  position: absolute;
  z-index: 5;
  top: clamp(8px, 1.6vw, 18px);
  right: clamp(8px, 1.6vw, 18px);
  left: clamp(8px, 1.6vw, 18px);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
}

.hud-group {
  display: flex;
  gap: 8px;
  min-width: 0;
}

.hud-group.right {
  align-items: center;
}

.stat,
.energy,
.hearts {
  min-height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.76);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 26px rgba(41, 116, 124, 0.14);
  backdrop-filter: blur(10px);
}

.stat {
  min-width: 94px;
  padding: 7px 12px 8px;
}

.stat-label {
  display: block;
  color: var(--soft-ink);
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0;
}

.stat strong {
  display: block;
  margin-top: 4px;
  font-size: clamp(17px, 2.5vw, 27px);
  line-height: 1;
}

.hearts {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 9px;
}

.hearts img {
  width: clamp(20px, 3.2vw, 31px);
  height: clamp(20px, 3.2vw, 31px);
  object-fit: contain;
}

.energy {
  position: relative;
  width: clamp(96px, 15vw, 178px);
  height: 22px;
  min-height: 22px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.64);
}

.energy::before {
  position: absolute;
  inset: 3px;
  border-radius: 5px;
  background: rgba(69, 155, 186, 0.18);
  content: "";
}

.energy span {
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 3px;
  width: 100%;
  max-width: calc(100% - 6px);
  border-radius: 5px;
  background: linear-gradient(90deg, #54d8ff, #ffe266 72%, #ffb13d);
  box-shadow: 0 0 18px rgba(255, 205, 62, 0.42);
  transition: width 140ms ease;
}

.stage-strip {
  position: absolute;
  z-index: 5;
  right: clamp(8px, 1.6vw, 18px);
  bottom: clamp(8px, 1.6vw, 18px);
  left: clamp(8px, 1.6vw, 18px);
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}

.stage-strip strong {
  min-width: 132px;
  border: 1px solid rgba(255, 255, 255, 0.78);
  border-radius: 8px;
  padding: 8px 11px;
  color: #174263;
  background: var(--panel);
  box-shadow: 0 8px 26px rgba(41, 116, 124, 0.14);
  font-size: clamp(13px, 1.8vw, 17px);
  line-height: 1;
  backdrop-filter: blur(10px);
}

.stage-progress {
  position: relative;
  flex: 1;
  height: 12px;
  min-width: 80px;
  max-width: 520px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.78);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.52);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65);
}

.stage-progress i {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #55d590, #ffe46c, #ffaf46);
  transition: width 160ms linear;
}

.stage-banner {
  position: absolute;
  z-index: 7;
  top: 50%;
  left: 50%;
  display: grid;
  min-width: min(430px, 76vw);
  place-items: center;
  gap: 8px;
  border: 1px solid rgba(255, 255, 255, 0.78);
  border-radius: 8px;
  padding: 18px 22px;
  color: #174263;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 18px 46px rgba(45, 126, 140, 0.18);
  text-align: center;
  transform: translate(-50%, -50%) scale(0.96);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 220ms ease,
    transform 220ms ease;
  backdrop-filter: blur(12px);
}

.stage-banner.show {
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
}

.stage-banner span {
  color: #4b6a7f;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
}

.stage-banner strong {
  font-size: clamp(26px, 5vw, 48px);
  line-height: 1;
}

.overlay {
  position: absolute;
  z-index: 8;
  inset: 0;
  display: grid;
  place-items: center;
  padding: clamp(18px, 5vw, 56px);
  background:
    radial-gradient(circle at 50% 42%, rgba(255, 247, 197, 0.56), transparent 18rem),
    linear-gradient(180deg, rgba(178, 229, 255, 0.38), rgba(255, 255, 255, 0.08));
}

.overlay.hidden {
  display: none;
}

.title-lockup {
  display: grid;
  justify-items: center;
  gap: clamp(12px, 2vw, 20px);
  text-align: center;
}

.title-lockup h1 {
  max-width: min(820px, 88vw);
  margin: 0;
  color: #174263;
  font-size: clamp(38px, 8vw, 104px);
  font-weight: 950;
  line-height: 0.92;
  letter-spacing: 0;
  text-shadow:
    0 4px 0 rgba(255, 255, 255, 0.78),
    0 16px 36px rgba(45, 126, 140, 0.2);
}

.title-lockup h1 span {
  display: inline;
}

.result {
  min-height: 24px;
  margin: 0;
  color: #246079;
  font-size: clamp(16px, 2.6vw, 25px);
  font-weight: 850;
  line-height: 1.15;
}

.primary-button {
  min-width: 160px;
  min-height: 52px;
  border: 0;
  border-radius: 8px;
  color: #593700;
  background: linear-gradient(180deg, #fff073, #ffb037);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.74),
    0 14px 26px rgba(177, 113, 8, 0.24);
  cursor: pointer;
  font-size: 18px;
  font-weight: 950;
  letter-spacing: 0;
}

.primary-button:hover,
.primary-button:focus-visible {
  transform: translateY(-1px);
  outline: 3px solid rgba(255, 255, 255, 0.86);
  outline-offset: 3px;
}

.primary-button:active {
  transform: translateY(1px);
}

.touch-controls {
  position: absolute;
  z-index: 4;
  right: max(10px, env(safe-area-inset-right));
  bottom: max(10px, env(safe-area-inset-bottom));
  left: max(10px, env(safe-area-inset-left));
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}

.touch-button {
  width: clamp(86px, 28vw, 136px);
  height: clamp(48px, 12vw, 62px);
  border: 1px solid rgba(255, 255, 255, 0.82);
  border-radius: 8px;
  color: #174263;
  background: rgba(255, 255, 255, 0.72);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.85),
    0 12px 28px rgba(41, 116, 124, 0.16);
  font-size: clamp(14px, 3.8vw, 18px);
  font-weight: 950;
  letter-spacing: 0;
  pointer-events: auto;
  touch-action: manipulation;
  backdrop-filter: blur(10px);
}

.touch-button.jump {
  color: #593700;
  background: linear-gradient(180deg, rgba(255, 240, 115, 0.9), rgba(255, 176, 55, 0.86));
}

.touch-button:active {
  transform: translateY(2px);
}

@media (max-width: 700px), (max-height: 520px) {
  html,
  body {
    height: 100%;
  }

  .game-shell {
    height: 100dvh;
    padding:
      env(safe-area-inset-top)
      env(safe-area-inset-right)
      env(safe-area-inset-bottom)
      env(safe-area-inset-left);
  }

  .stage-wrap {
    width: 100%;
    height: 100%;
    max-height: none;
    border: 0;
    border-radius: 0;
  }

  .hud {
    top: max(6px, env(safe-area-inset-top));
    right: max(7px, env(safe-area-inset-right));
    left: max(7px, env(safe-area-inset-left));
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 6px;
  }

  .hud-group {
    gap: 5px;
  }

  .stat {
    min-width: 62px;
    min-height: 34px;
    padding: 5px 7px 6px;
  }

  .stat-label {
    font-size: 9px;
  }

  .stat strong {
    margin-top: 3px;
    font-size: 16px;
  }

  .stage-stat {
    display: none;
  }

  .hearts {
    min-height: 34px;
    padding: 4px 6px;
  }

  .hearts img {
    width: 21px;
    height: 21px;
  }

  .hud-group.right {
    align-items: center;
    gap: 5px;
    margin-left: auto;
  }

  .energy {
    width: 92px;
    height: 18px;
    min-height: 18px;
  }

  .title-lockup h1 {
    max-width: 92vw;
    font-size: clamp(30px, 9vw, 42px);
  }

  .title-lockup h1 span {
    display: block;
  }

  .primary-button {
    min-width: 160px;
  }

  .stage-strip {
    right: max(8px, env(safe-area-inset-right));
    bottom: calc(max(8px, env(safe-area-inset-bottom)) + 68px);
    left: max(8px, env(safe-area-inset-left));
    gap: 7px;
  }

  .stage-strip strong {
    min-width: 0;
    max-width: 42vw;
    padding: 7px 8px;
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .stage-progress {
    height: 10px;
  }

  .stage-banner {
    min-width: min(340px, 82vw);
    padding: 14px 16px;
  }

  .touch-controls {
    display: flex;
  }
}

@media (max-width: 430px) {
  .hud {
    gap: 5px;
  }

  .stat {
    min-width: 56px;
    padding-inline: 6px;
  }

  .energy {
    width: 78px;
  }
}

@media (max-height: 430px) and (orientation: landscape) {
  .hud {
    top: max(5px, env(safe-area-inset-top));
  }

  .stat {
    min-height: 30px;
    padding: 4px 7px;
  }

  .stat strong {
    font-size: 15px;
  }

  .stage-strip {
    bottom: calc(max(6px, env(safe-area-inset-bottom)) + 52px);
  }

  .touch-button {
    width: 108px;
    height: 42px;
    font-size: 14px;
  }
}
