* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #031E31;
  color: #FFF8EA;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

body { position: fixed; inset: 0; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  isolation: isolate;
  background: radial-gradient(120% 80% at 50% 0%, #167B9B 0%, #08445F 42%, #031E31 100%);
  touch-action: none;
}

.scene {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background: #062B45;
}

.scene-bg {
  position: absolute;
  inset: -2%;
  width: 104%;
  height: 104%;
  object-fit: cover;
  object-position: 50% 50%;
  pointer-events: none;
  user-select: none;
}

.caustics {
  position: absolute;
  inset: -18% -26% 0;
  background:
    radial-gradient(ellipse 34% 30% at 22% 2%, rgba(184, 255, 255, .2), rgba(184, 255, 255, 0) 68%),
    radial-gradient(ellipse 30% 34% at 78% 4%, rgba(151, 247, 255, .13), rgba(151, 247, 255, 0) 70%),
    repeating-linear-gradient(106deg,
      rgba(205, 255, 255, 0) 0 42px,
      rgba(205, 255, 255, .035) 44px 48px,
      rgba(205, 255, 255, 0) 50px 92px);
  mix-blend-mode: screen;
  opacity: .95;
  transform-origin: 48% 0%;
  animation: causticSway 11s ease-in-out infinite alternate;
  pointer-events: none;
}

.scene-glow {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 48% 18% at 50% 0%, rgba(236, 255, 255, .28), rgba(236, 255, 255, 0) 72%),
    linear-gradient(180deg, rgba(3, 26, 42, .08) 0%, rgba(3, 22, 36, 0) 28%, rgba(2, 17, 29, .34) 100%);
  pointer-events: none;
}

#gameCanvas {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.hud {
  position: absolute;
  z-index: 10;
  top: calc(11px + env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  right: max(14px, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}

.score-pill,
.air-pill,
.sound-btn {
  background: linear-gradient(180deg, rgba(8, 44, 66, .58), rgba(4, 28, 44, .42));
  border: 1px solid rgba(204, 247, 255, .26);
  box-shadow:
    0 8px 22px rgba(0, 14, 26, .26),
    inset 0 1px 0 rgba(255, 255, 255, .22);
  -webkit-backdrop-filter: blur(12px) saturate(140%);
  backdrop-filter: blur(12px) saturate(140%);
}

.score-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 44px;
  padding: 0 15px 0 10px;
  border-radius: 16px;
  color: #FFF9EC;
  transform-origin: 16px 50%;
}

.score-pill.pop { animation: scorePop .38s cubic-bezier(.2, 1.7, .45, 1); }

.pearl-gem {
  position: relative;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  flex: 0 0 auto;
  background:
    radial-gradient(circle at 33% 27%, #FFFFFF 0 18%, #FFF3FB 34%, #F0D7F0 55%, #C6B3E4 76%, #98A5D7 100%);
  box-shadow:
    0 0 12px rgba(208, 244, 255, .7),
    0 0 0 3px rgba(255, 255, 255, .08),
    inset -3px -4px 6px rgba(64, 57, 120, .3);
}

.pearl-gem::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 4px;
  width: 8px;
  height: 5px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .95);
  transform: rotate(-24deg);
  filter: blur(.2px);
}

.score-num {
  min-width: 1ch;
  font-size: 22px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -.03em;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 8px rgba(0, 18, 32, .5);
}

.score-unit {
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  color: rgba(230, 252, 255, .7);
  margin-top: 2px;
}

.hud-right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.air-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 44px;
  padding: 0 11px;
  border-radius: 16px;
}

.air-icon {
  width: 17px;
  height: 17px;
  color: #95F0FF;
  filter: drop-shadow(0 0 5px rgba(105, 232, 255, .55));
  flex: 0 0 auto;
}

.air-track {
  position: relative;
  width: 58px;
  height: 8px;
  border-radius: 99px;
  overflow: hidden;
  background: rgba(174, 239, 252, .18);
  box-shadow: inset 0 1px 3px rgba(0, 20, 32, .38);
}

.air-fill {
  position: absolute;
  inset: 0;
  width: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, #35C9E4 0%, #9DF6FF 70%, #EAFFFF 100%);
  box-shadow: 0 0 9px rgba(120, 238, 255, .7);
  transition: width .16s linear;
}

.air-pill.low .air-fill {
  background: linear-gradient(90deg, #FF6A3D 0%, #FFAE4D 70%, #FFE7A0 100%);
  box-shadow: 0 0 10px rgba(255, 128, 70, .7);
}

.air-pill.low .air-icon {
  color: #FFB25E;
  filter: drop-shadow(0 0 5px rgba(255, 149, 75, .6));
  animation: lowPulse 1s ease-in-out infinite;
}

.air-time {
  width: 27px;
  text-align: right;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  color: #E9FDFF;
  font-variant-numeric: tabular-nums;
}

.sound-btn {
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #E7FBFF;
  cursor: pointer;
  pointer-events: auto;
  -webkit-appearance: none;
  appearance: none;
  transition: transform .12s ease, background .2s ease;
}

.sound-btn .mp-icon { width: 21px; height: 21px; }

.sound-btn:active { transform: scale(.92); background: rgba(8, 52, 76, .75); }

.hint {
  position: absolute;
  z-index: 8;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 7px;
  max-width: calc(100% - 32px);
  padding: 10px 15px;
  border-radius: 99px;
  white-space: nowrap;
  color: rgba(243, 254, 255, .94);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .01em;
  background: linear-gradient(180deg, rgba(5, 38, 57, .68), rgba(3, 25, 40, .6));
  border: 1px solid rgba(190, 244, 255, .22);
  box-shadow: 0 8px 22px rgba(0, 15, 27, .3), inset 0 1px 0 rgba(255, 255, 255, .16);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  pointer-events: none;
  animation: hintFloat 2.6s ease-in-out infinite;
  transition: opacity .32s ease, transform .32s ease;
}

.hint .mp-icon {
  width: 18px;
  height: 18px;
  color: #FFB068;
  animation: touchBounce 1.8s ease-in-out infinite;
}

.hint.hide {
  opacity: 0;
  transform: translate(-50%, 8px);
  animation: none;
}

.result-layer {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(24px, env(safe-area-inset-top)) 22px max(24px, env(safe-area-inset-bottom));
  background:
    radial-gradient(ellipse 90% 65% at 50% 46%, rgba(20, 98, 127, .34), rgba(2, 17, 29, .76) 72%),
    rgba(2, 16, 28, .5);
  -webkit-backdrop-filter: blur(9px) saturate(120%);
  backdrop-filter: blur(9px) saturate(120%);
  animation: layerIn .28s ease-out both;
}

.result-layer[hidden] { display: none; }

.result-card {
  position: relative;
  width: min(336px, 100%);
  max-height: calc(100dvh - 48px);
  overflow: hidden auto;
  padding: 30px 24px 22px;
  text-align: center;
  border-radius: 30px;
  background:
    linear-gradient(180deg, rgba(20, 78, 102, .96) 0%, rgba(8, 47, 69, .98) 44%, rgba(4, 30, 47, 1) 100%);
  border: 1px solid rgba(197, 246, 255, .24);
  box-shadow:
    0 28px 70px rgba(0, 8, 16, .6),
    inset 0 1px 0 rgba(255, 255, 255, .2),
    inset 0 -1px 0 rgba(0, 0, 0, .25);
  animation: cardIn .5s cubic-bezier(.18, 1.32, .36, 1) both;
}

.result-card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background:
    radial-gradient(ellipse 70% 32% at 50% 0%, rgba(110, 232, 255, .18), transparent 68%),
    radial-gradient(ellipse 55% 28% at 50% 100%, rgba(255, 138, 61, .09), transparent 72%);
  pointer-events: none;
}

.result-halo {
  position: absolute;
  top: 10px;
  left: 50%;
  width: 166px;
  height: 166px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(144, 236, 255, .22) 0%, rgba(144, 236, 255, 0) 68%);
  pointer-events: none;
}

.pearl-orb {
  position: relative;
  width: 78px;
  height: 78px;
  margin: 0 auto 17px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 34% 27%, #FFFFFF 0%, #FFF8FD 17%, #F8E7F6 33%, #E4CFEF 52%, #BEB4E6 72%, #8E9FD4 100%);
  box-shadow:
    0 0 0 7px rgba(255, 255, 255, .07),
    0 0 36px rgba(142, 233, 255, .5),
    0 16px 26px rgba(0, 11, 21, .35),
    inset -10px -12px 20px rgba(77, 63, 137, .38);
  animation: orbFloat 3.4s ease-in-out infinite;
}

.pearl-orb::before {
  content: "";
  position: absolute;
  inset: 9px;
  border-radius: 50%;
  background: conic-gradient(from 210deg, rgba(255, 143, 185, .36), rgba(119, 238, 255, .26), rgba(255, 236, 160, .3), rgba(255, 143, 185, .36));
  filter: blur(4px);
  mix-blend-mode: screen;
  opacity: .65;
}

.pearl-orb::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 92px;
  height: 92px;
  margin: -46px 0 0 -46px;
  border-radius: 50%;
  border: 1px solid rgba(180, 246, 255, .5);
  animation: ringPulse 2.4s ease-out infinite;
}

.pearl-shine {
  position: absolute;
  left: 20px;
  top: 15px;
  width: 22px;
  height: 13px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .98);
  transform: rotate(-28deg);
  filter: blur(.4px);
  z-index: 2;
}

.result-kicker {
  position: relative;
  margin: 0 0 5px;
  color: #8FE9F7;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .14em;
}

.result-card h2 {
  position: relative;
  margin: 0;
  color: #FFF8EA;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: .02em;
}

.result-score {
  position: relative;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  margin: 7px 0 2px;
}

.result-score b {
  color: #FFFDF4;
  font-size: 62px;
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -.04em;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 3px 20px rgba(120, 232, 255, .3), 0 2px 0 rgba(0, 0, 0, .16);
}

.result-score span {
  color: rgba(228, 250, 255, .72);
  font-size: 14px;
  font-weight: 600;
}

.result-best {
  position: relative;
  min-height: 18px;
  margin: 3px 0 19px;
  color: #FFCE8E;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .02em;
}

.result-best.new-best { color: #FFE59A; text-shadow: 0 0 14px rgba(255, 207, 108, .4); }

.again-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 54px;
  padding: 0 18px;
  border: 0;
  border-radius: 17px;
  color: #FFFDF7;
  font-family: inherit;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: .06em;
  background: linear-gradient(180deg, #FFA45C 0%, #FF8A3D 48%, #F37327 100%);
  box-shadow:
    0 6px 0 #B9551C,
    0 14px 26px rgba(0, 10, 20, .36),
    inset 0 1px 0 rgba(255, 255, 255, .42);
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  transition: transform .1s ease, box-shadow .1s ease, filter .18s ease;
}

.again-btn .mp-icon {
  width: 20px;
  height: 20px;
  transition: transform .4s ease;
}

.again-btn:active {
  transform: translateY(4px);
  box-shadow:
    0 2px 0 #B9551C,
    0 7px 16px rgba(0, 10, 20, .34),
    inset 0 1px 0 rgba(255, 255, 255, .34);
}

.again-btn:active .mp-icon { transform: rotate(-160deg); }

.again-btn:focus-visible { outline: 3px solid rgba(173, 243, 255, .8); outline-offset: 3px; }

.result-tip {
  position: relative;
  margin: 15px 0 0;
  color: rgba(205, 240, 248, .55);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .05em;
}

.white-flash {
  position: absolute;
  inset: 0;
  z-index: 15;
  opacity: 0;
  pointer-events: none;
  background: radial-gradient(circle at 50% 55%, rgba(220, 255, 255, .9), rgba(150, 238, 255, .3) 46%, transparent 72%);
}

.white-flash.on { animation: flashOut .42s ease-out both; }

@keyframes causticSway {
  from { transform: translate3d(-1.6%, 0, 0) scale(1.03); opacity: .72; }
  to { transform: translate3d(1.6%, 1.2%, 0) scale(1.08); opacity: 1; }
}

@keyframes hintFloat {
  0%, 100% { transform: translate(-50%, 0); }
  50% { transform: translate(-50%, -4px); }
}

@keyframes touchBounce {
  0%, 100% { transform: translateY(0) scale(1); }
  45% { transform: translateY(-2px) scale(1.08); }
}

@keyframes scorePop {
  0% { transform: scale(1); }
  38% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

@keyframes lowPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .55; }
}

@keyframes layerIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(22px) scale(.92); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes orbFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

@keyframes ringPulse {
  0% { transform: scale(.9); opacity: .7; }
  72%, 100% { transform: scale(1.34); opacity: 0; }
}

@keyframes flashOut {
  0% { opacity: .8; }
  100% { opacity: 0; }
}

@media (max-width: 350px) {
  .hud { left: 11px; right: 11px; }
  .score-pill { padding-right: 11px; gap: 5px; height: 41px; }
  .score-num { font-size: 20px; }
  .air-pill { gap: 5px; padding: 0 9px; height: 41px; }
  .air-track { width: 44px; }
  .sound-btn { width: 40px; height: 40px; }
  .hint { font-size: 12px; padding: 9px 13px; }
}

@media (max-height: 660px) {
  .result-card { padding: 22px 20px 17px; }
  .pearl-orb { width: 62px; height: 62px; margin-bottom: 13px; }
  .pearl-orb::after { width: 74px; height: 74px; margin: -37px 0 0 -37px; }
  .result-score b { font-size: 50px; }
  .result-best { margin-bottom: 14px; }
  .again-btn { height: 50px; }
  .result-tip { margin-top: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  .caustics,
  .hint,
  .hint .mp-icon,
  .pearl-orb,
  .pearl-orb::after,
  .air-pill.low .air-icon {
    animation: none !important;
  }
}
