:root {
  --ink: #263342;
  --paper: #fffdf7;
  --blue: #2479bd;
  --blue-dark: #175e96;
  --sun: #ffd65c;
  --coral: #ff746e;
  --mint: #68d39b;
  --shadow: 0 14px 34px rgba(38, 51, 66, 0.22);
}

* {
  box-sizing: border-box;
}

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

body,
button {
  color: var(--ink);
  font-family:
    ui-rounded,
    "SF Pro Rounded",
    "PingFang SC",
    "Hiragino Sans GB",
    "Microsoft YaHei",
    system-ui,
    sans-serif;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
}

button:focus-visible,
a:focus-visible {
  outline: 4px solid #155c93;
  outline-offset: 4px;
}

.game {
  width: 100vw;
  min-height: 100vh;
  min-height: 100dvh;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.scene-picker {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-y: auto;
  padding:
    max(18px, env(safe-area-inset-top))
    max(18px, env(safe-area-inset-right))
    max(24px, env(safe-area-inset-bottom))
    max(18px, env(safe-area-inset-left));
  background:
    radial-gradient(circle at 10% 14%, rgba(255, 255, 255, 0.9) 0 5%, transparent 5.3%),
    radial-gradient(circle at 91% 18%, rgba(255, 255, 255, 0.65) 0 7%, transparent 7.3%),
    linear-gradient(180deg, #cdefff 0%, #f8fdff 54%, #fff8e7 100%);
  touch-action: pan-y;
}

.picker-copy {
  width: min(1080px, 100%);
  margin: 0 auto 20px;
  text-align: center;
}

.home-link {
  position: absolute;
  top: max(18px, env(safe-area-inset-top));
  left: max(18px, env(safe-area-inset-left));
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  padding: 0 18px;
  border: 3px solid rgba(36, 121, 189, 0.2);
  border-radius: 999px;
  color: var(--blue-dark);
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 6px 16px rgba(38, 51, 66, 0.11);
  font-size: 15px;
  font-weight: 900;
  text-decoration: none;
  touch-action: manipulation;
}

.eyebrow {
  margin: 8px 0 2px;
  color: var(--blue-dark);
  font-size: clamp(11px, 2.5vw, 14px);
  font-weight: 900;
  letter-spacing: 0.16em;
}

.picker-copy h1 {
  margin: 0;
  color: #1e659c;
  font-size: clamp(38px, 8vw, 72px);
  line-height: 1;
  text-shadow: 0 4px 0 white;
}

.picker-copy > p:last-child {
  margin: 10px 0 0;
  font-size: clamp(16px, 3vw, 22px);
  font-weight: 800;
}

.scene-grid {
  width: min(1080px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(14px, 2vw, 24px);
}

.scene-card {
  position: relative;
  min-height: 260px;
  overflow: hidden;
  padding: 0;
  border: 6px solid white;
  border-radius: 28px;
  background: white;
  box-shadow:
    0 8px 0 rgba(36, 121, 189, 0.22),
    var(--shadow);
  transition:
    transform 180ms ease-out,
    box-shadow 180ms ease-out;
  touch-action: manipulation;
}

.scene-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 42%, rgba(20, 43, 62, 0.78) 100%);
  pointer-events: none;
}

.scene-card picture,
.scene-card img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.scene-card img {
  object-fit: cover;
  transition: transform 240ms ease-out;
}

.scene-name,
.scene-hint {
  position: absolute;
  z-index: 1;
  left: 20px;
  color: white;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

.scene-name {
  bottom: 42px;
  font-size: clamp(28px, 4vw, 42px);
  font-weight: 1000;
}

.scene-hint {
  bottom: 18px;
  font-size: 15px;
  font-weight: 900;
}

@media (hover: hover) {
  .scene-card:hover {
    transform: translateY(-4px);
    box-shadow:
      0 12px 0 rgba(36, 121, 189, 0.22),
      0 22px 42px rgba(38, 51, 66, 0.24);
  }

  .scene-card:hover img {
    transform: scale(1.035);
  }
}

.scene-card:active {
  transform: translateY(4px) scale(0.985);
  box-shadow:
    0 3px 0 rgba(36, 121, 189, 0.22),
    0 8px 20px rgba(38, 51, 66, 0.19);
}

.play-screen {
  position: fixed;
  inset: 0;
  display: none;
  overflow: hidden;
  background: #bdeaff;
}

.game[data-screen="play"] .scene-picker {
  display: none;
}

.game[data-screen="play"] .play-screen {
  display: block;
}

.scene-background,
.scene-background img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.scene-background img {
  object-fit: cover;
  object-position: center;
  pointer-events: none;
}

@media (orientation: portrait) {
  .scene-background img {
    object-position: center bottom;
  }
}

.scene-wash {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.13), transparent 34%, rgba(31, 54, 70, 0.06));
  pointer-events: none;
}

.hud {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 30;
  width: 100%;
  display: grid;
  grid-template-columns: minmax(82px, 1fr) auto minmax(82px, 1fr);
  align-items: start;
  gap: 12px;
  padding:
    max(12px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    0
    max(12px, env(safe-area-inset-left));
  pointer-events: none;
}

.hud-button,
.score-card {
  min-height: 50px;
  border: 3px solid rgba(28, 82, 121, 0.18);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 7px 18px rgba(38, 51, 66, 0.18);
  backdrop-filter: blur(8px);
}

.hud-button {
  min-width: 96px;
  padding: 0 16px;
  color: var(--blue-dark);
  font-size: 15px;
  font-weight: 1000;
  pointer-events: auto;
  touch-action: manipulation;
}

.hud-button:first-child {
  justify-self: start;
}

.sound-button {
  justify-self: end;
}

.hud-button:active {
  transform: scale(0.96);
}

.score-card {
  min-width: min(42vw, 230px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 13px;
  padding: 5px 18px;
}

.round-name {
  color: #5a6270;
  font-size: 14px;
  font-weight: 900;
}

.score {
  display: flex;
  align-items: baseline;
  gap: 4px;
  white-space: nowrap;
}

.score span {
  color: #5a6270;
  font-size: 13px;
  font-weight: 900;
}

.score strong {
  min-width: 1ch;
  color: #cf3f49;
  font-size: 25px;
  font-variant-numeric: tabular-nums;
  font-weight: 1000;
}

.score b {
  color: #6b7682;
  font-size: 17px;
}

.balloon-field {
  position: absolute;
  inset: 0;
  z-index: 10;
  overflow: hidden;
  touch-action: none;
}

.balloon {
  --size: 90px;
  --duration: 6s;
  --drift: 20px;
  position: absolute;
  left: var(--left);
  bottom: calc(-1 * var(--size) - 50px);
  width: var(--size);
  height: calc(var(--size) * 1.38);
  padding: 0;
  border: 0;
  background: transparent;
  transform: translateX(-50%);
  animation: rise var(--duration) cubic-bezier(0.34, 0.05, 0.76, 0.94) forwards;
  touch-action: none;
}

.balloon-body {
  position: absolute;
  top: 0;
  left: 5%;
  width: 90%;
  height: 72%;
  border: 3px solid rgba(85, 33, 49, 0.2);
  border-radius: 50% 50% 46% 46%;
  background:
    radial-gradient(circle at 31% 25%, rgba(255, 255, 255, 0.85) 0 8%, rgba(255, 255, 255, 0.2) 9% 17%, transparent 18%),
    var(--balloon-color);
  box-shadow:
    inset -9px -10px 14px rgba(79, 25, 45, 0.13),
    0 9px 15px rgba(38, 51, 66, 0.17);
  animation: sway 1.2s ease-in-out infinite alternate;
  transform-origin: 50% 100%;
}

.balloon-body::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -9px;
  width: 18px;
  height: 14px;
  background: var(--balloon-color);
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
  transform: translateX(-50%);
}

.balloon-string {
  position: absolute;
  top: 73%;
  left: 50%;
  width: 2px;
  height: 27%;
  background: rgba(76, 70, 73, 0.58);
  transform: translateX(-50%) rotate(2deg);
  transform-origin: top;
}

.balloon:active .balloon-body {
  transform: scale(0.94);
}

.balloon.is-popped {
  animation-play-state: paused;
  pointer-events: none;
}

.balloon.is-popped .balloon-body {
  animation: pop 260ms ease-out forwards;
}

.balloon.is-popped .balloon-string {
  animation: string-away 220ms ease-in forwards;
}

.pop-ring {
  position: absolute;
  top: 29%;
  left: 50%;
  width: calc(var(--size) * 0.62);
  aspect-ratio: 1;
  border: 8px solid rgba(255, 255, 255, 0.92);
  border-radius: 50%;
  transform: translate(-50%, -50%) scale(0.2);
  animation: ring 320ms ease-out forwards;
}

.pop-particle {
  --angle: 0deg;
  position: absolute;
  top: 29%;
  left: 50%;
  width: 12px;
  height: 12px;
  border: 3px solid white;
  border-radius: 50%;
  background: var(--balloon-color);
  transform: translate(-50%, -50%) rotate(var(--angle)) translateY(-8px);
  animation: particle 350ms ease-out forwards;
}

@keyframes rise {
  0% {
    transform: translateX(-50%) translateY(0);
  }
  48% {
    transform: translateX(calc(-50% + var(--drift))) translateY(-55vh);
  }
  100% {
    transform: translateX(calc(-50% - var(--drift))) translateY(calc(-100vh - var(--size) - 90px));
  }
}

@keyframes sway {
  from {
    transform: rotate(-3deg) translateX(-2px);
  }
  to {
    transform: rotate(3deg) translateX(2px);
  }
}

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

@keyframes string-away {
  to {
    opacity: 0;
    transform: translateX(-50%) translateY(30px) rotate(13deg);
  }
}

@keyframes ring {
  to {
    opacity: 0;
    transform: translate(-50%, -50%) scale(2.15);
  }
}

@keyframes particle {
  to {
    opacity: 0;
    transform: translate(-50%, -50%) rotate(var(--angle)) translateY(calc(-0.72 * var(--size))) scale(0.35);
  }
}

.ready-message {
  position: absolute;
  inset: 0;
  z-index: 35;
  display: grid;
  place-items: center;
  pointer-events: none;
  opacity: 0;
}

.ready-message span {
  padding: 16px 28px;
  border: 5px solid white;
  border-radius: 28px;
  color: #174e78;
  background: var(--sun);
  box-shadow: var(--shadow);
  font-size: clamp(30px, 7vw, 62px);
  font-weight: 1000;
  transform: scale(0.72);
}

.ready-message.is-visible {
  animation: message-wrap 920ms ease-out forwards;
}

.ready-message.is-visible span {
  animation: message 920ms ease-out forwards;
}

@keyframes message-wrap {
  0%,
  100% {
    opacity: 0;
  }
  16%,
  72% {
    opacity: 1;
  }
}

@keyframes message {
  0% {
    transform: scale(0.72) rotate(-3deg);
  }
  28%,
  70% {
    transform: scale(1) rotate(0);
  }
  100% {
    transform: scale(0.9);
  }
}

.victory {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding:
    max(18px, env(safe-area-inset-top))
    max(18px, env(safe-area-inset-right))
    max(18px, env(safe-area-inset-bottom))
    max(18px, env(safe-area-inset-left));
  background: rgba(26, 53, 71, 0.52);
  backdrop-filter: blur(7px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease-out;
}

.victory.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.victory-card {
  width: min(520px, 100%);
  padding: clamp(26px, 5vw, 46px);
  border: 7px solid white;
  border-radius: 34px;
  background: #fff9e8;
  box-shadow:
    0 10px 0 #efba3d,
    0 28px 60px rgba(19, 43, 58, 0.36);
  text-align: center;
  transform: translateY(26px) scale(0.86);
  transition: transform 300ms cubic-bezier(0.18, 0.86, 0.36, 1.25);
}

.victory.is-visible .victory-card {
  transform: translateY(0) scale(1);
}

.stars {
  height: 62px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.stars i {
  width: 44px;
  height: 44px;
  display: block;
  background: #ffc83d;
  clip-path: polygon(50% 0, 61% 34%, 98% 35%, 68% 56%, 79% 93%, 50% 71%, 21% 93%, 32% 56%, 2% 35%, 39% 34%);
  filter: drop-shadow(0 4px 0 #e49a26);
  transform: rotate(-8deg);
}

.stars i:nth-child(2) {
  width: 58px;
  height: 58px;
  transform: translateY(-8px);
}

.stars i:nth-child(3) {
  transform: rotate(8deg);
}

.victory-kicker {
  margin: 8px 0 0;
  color: #b34c45;
  font-size: 15px;
  font-weight: 1000;
  letter-spacing: 0.16em;
}

.victory h2 {
  margin: 2px 0 8px;
  color: #1e659c;
  font-size: clamp(44px, 10vw, 76px);
  line-height: 1;
}

.victory p:not(.victory-kicker) {
  margin: 0 0 24px;
  font-size: clamp(18px, 4vw, 26px);
  font-weight: 800;
}

.victory p strong {
  color: #d13f4a;
  font-size: 1.25em;
}

.victory-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.victory-actions button {
  min-height: 62px;
  border: 0;
  border-radius: 20px;
  color: white;
  background: var(--blue);
  box-shadow: 0 7px 0 var(--blue-dark);
  font-size: 18px;
  font-weight: 1000;
  touch-action: manipulation;
}

.victory-actions button.secondary {
  color: #7e431f;
  background: #ffd26b;
  box-shadow: 0 7px 0 #dba13c;
}

.victory-actions button:active {
  transform: translateY(5px);
  box-shadow: 0 2px 0 var(--blue-dark);
}

.victory-actions button.secondary:active {
  box-shadow: 0 2px 0 #dba13c;
}

@media (max-width: 760px) {
  .scene-picker {
    padding-top: max(78px, calc(env(safe-area-inset-top) + 68px));
  }

  .scene-grid {
    grid-template-columns: 1fr;
    max-width: 560px;
  }

  .scene-card {
    min-height: 185px;
  }

  .hud {
    grid-template-columns: 1fr auto 1fr;
    gap: 7px;
  }

  .hud-button {
    min-width: 74px;
    padding: 0 10px;
    font-size: 13px;
  }

  .score-card {
    min-width: 146px;
    gap: 7px;
    padding: 4px 10px;
  }

  .round-name {
    display: none;
  }
}

@media (max-width: 430px) {
  .sound-button {
    width: 74px;
    min-width: 74px;
    padding: 0 5px;
  }
}

@media (orientation: landscape) and (max-height: 620px) {
  .scene-picker {
    display: grid;
    grid-template-columns: minmax(220px, 0.72fr) minmax(0, 1.8fr);
    align-items: center;
    gap: 20px;
    padding-top: max(18px, env(safe-area-inset-top));
  }

  .picker-copy {
    margin: 0;
    padding-left: 10px;
  }

  .home-link {
    position: static;
    margin-bottom: 18px;
  }

  .scene-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .scene-card {
    min-height: min(72vh, 330px);
  }

  .scene-name {
    left: 14px;
    bottom: 36px;
    font-size: clamp(23px, 4vw, 34px);
  }

  .scene-hint {
    left: 14px;
    bottom: 15px;
    font-size: 12px;
  }

  .hud-button,
  .score-card {
    min-height: 44px;
  }

  .balloon {
    --size: 74px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .scene-card,
  .scene-card img,
  .victory,
  .victory-card {
    transition-duration: 0.01ms;
  }

  .balloon {
    animation-timing-function: ease-out;
  }

  .balloon-body {
    animation: none;
  }

  .pop-particle,
  .pop-ring {
    display: none;
  }
}
