:root {
  --orange: #FF8A3D;
  --orange-deep: #F06A1E;
  --orange-soft: #FFF1E5;
  --ink: #223D56;
  --ink-2: #4D6578;
  --muted: #8395A4;
  --line: #EDE4D7;
  --cream: #FFFDF8;
  --shadow-card: 0 10px 30px rgba(22, 60, 92, .14);
  --shadow-soft: 0 6px 18px rgba(22, 60, 92, .10);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

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

body {
  background: radial-gradient(120% 100% at 50% 0%, #4A90C2 0%, #22506F 55%, #163A54 100%);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

button {
  border: 0;
  padding: 0;
  margin: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.mp-icon { flex: 0 0 auto; }

.app {
  position: fixed;
  inset: 0;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  overflow: hidden;
  background: linear-gradient(180deg, #7FC6F4 0%, #C9EBFF 55%, #F4FCFF 100%);
  isolation: isolate;
}

@media (min-width: 600px) {
  .app {
    box-shadow: 0 0 90px rgba(2, 18, 34, .5);
  }
}

/* ---------- 场景：生成图铺满 ---------- */
.scene {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background: linear-gradient(180deg, #86CBF6 0%, #C7E9FF 52%, #F5FCFF 100%);
}

.scene-img {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 30% 52%;
  filter: saturate(1.04) brightness(1.01);
  transform: scale(1.02);
  transition: filter .55s ease, transform 1.1s ease;
}

.app.is-playing .scene-img {
  filter: blur(3.2px) saturate(1.05) brightness(1.03);
  transform: scale(1.06);
}

.scene-wash {
  position: absolute;
  inset: 0;
  z-index: 1;
  background:
    linear-gradient(180deg,
      rgba(53, 132, 196, .16) 0%,
      rgba(123, 198, 245, .06) 24%,
      rgba(203, 236, 255, .26) 43%,
      rgba(232, 249, 255, .78) 60%,
      rgba(245, 252, 255, .96) 76%,
      #F5FCFF 100%);
  transition: background .55s ease;
}

.app.is-playing .scene-wash {
  background:
    linear-gradient(180deg,
      rgba(49, 126, 188, .20) 0%,
      rgba(118, 190, 238, .12) 20%,
      rgba(202, 236, 255, .50) 41%,
      rgba(234, 249, 255, .91) 57%,
      #F5FCFF 72%,
      #F5FCFF 100%);
}

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

/* ---------- 顶部 HUD ---------- */
.hud {
  position: absolute;
  z-index: 10;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 14px 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity .3s ease;
}

.app.is-playing .hud { opacity: 1; }

.score-card {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 7px 12px 7px 8px;
  border-radius: 18px;
  background: rgba(31, 77, 119, .60);
  border: 1px solid rgba(255, 255, 255, .30);
  box-shadow: 0 8px 24px rgba(17, 59, 96, .22), inset 0 1px 0 rgba(255, 255, 255, .18);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  color: #fff;
}

.score-crown {
  width: 34px;
  height: 34px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: #8A4C00;
  background: linear-gradient(145deg, #FFE7A1, #FFB33E);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .72), 0 3px 8px rgba(128, 72, 5, .18);
}

.score-crown .mp-icon { width: 22px; height: 22px; }

.score-k {
  font-size: 10px;
  letter-spacing: .10em;
  opacity: .74;
}

.score-card strong {
  display: inline-block;
  font-size: 26px;
  font-weight: 900;
  letter-spacing: -.04em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.score-card strong.pop { animation: scorePop .28s cubic-bezier(.2, .8, .3, 1.4); }

@keyframes scorePop {
  0% { transform: scale(1); }
  45% { transform: scale(1.28); color: #FFE08A; }
  100% { transform: scale(1); }
}

.best-mini {
  align-self: flex-end;
  padding-bottom: 2px;
  font-size: 10px;
  color: rgba(255, 255, 255, .75);
  white-space: nowrap;
}

.best-mini b { font-size: 12px; color: #FFE09A; }

.coin-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 48px;
  padding: 0 13px 0 7px;
  border-radius: 17px;
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  background: rgba(31, 77, 119, .60);
  border: 1px solid rgba(255, 255, 255, .30);
  box-shadow: 0 8px 24px rgba(17, 59, 96, .22), inset 0 1px 0 rgba(255, 255, 255, .18);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}

.coin-pill.pop { animation: coinPop .32s cubic-bezier(.2, .8, .3, 1.4); }

@keyframes coinPop {
  0% { transform: scale(1); }
  45% { transform: scale(1.10); }
  100% { transform: scale(1); }
}

.coin-env {
  width: 34px;
  height: 34px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  color: #FFE8A6;
  background: linear-gradient(145deg, #FF7C52, #E83D2A);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .38), 0 3px 9px rgba(117, 27, 13, .24);
}

.coin-env .mp-icon { width: 21px; height: 21px; }

.coin-label {
  font-size: 10px;
  font-weight: 600;
  opacity: .72;
}

/* ---------- 连击徽章 ---------- */
.combo-badge {
  position: absolute;
  z-index: 9;
  top: calc(env(safe-area-inset-top, 0px) + 72px);
  left: 50%;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px 6px 7px;
  border-radius: 999px;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  background: linear-gradient(135deg, #FFB03E, #FF7028);
  box-shadow: 0 8px 20px rgba(238, 100, 25, .32), inset 0 1px 0 rgba(255, 255, 255, .4);
  opacity: 0;
  transform: translate(-50%, -8px) scale(.82);
  transition: opacity .18s ease, transform .24s cubic-bezier(.2, .9, .3, 1.35);
  pointer-events: none;
}

.combo-badge.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
.combo-badge.pulse { animation: comboPulse .3s ease; }

@keyframes comboPulse {
  0% { transform: translate(-50%, 0) scale(1); }
  45% { transform: translate(-50%, 0) scale(1.12); }
  100% { transform: translate(-50%, 0) scale(1); }
}

.combo-bolt {
  width: 23px;
  height: 23px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #934600;
  background: #FFE39A;
}

.combo-bolt .mp-icon { width: 15px; height: 15px; }
.combo-badge b { font-size: 13px; font-weight: 900; }

/* ---------- 操作提示 ---------- */
.hint-bubble {
  position: absolute;
  z-index: 9;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 156px);
  display: flex;
  align-items: center;
  gap: 7px;
  max-width: calc(100% - 32px);
  padding: 8px 14px 8px 8px;
  border-radius: 999px;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  background: rgba(32, 62, 88, .68);
  border: 1px solid rgba(255, 255, 255, .22);
  box-shadow: 0 10px 28px rgba(11, 42, 69, .24);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  transform: translate(-50%, 6px);
  opacity: 0;
  transition: opacity .3s ease, transform .3s ease;
  pointer-events: none;
}

.hint-bubble.show { opacity: 1; transform: translate(-50%, 0); }
.hint-bubble.hide { opacity: 0; transform: translate(-50%, 8px); }

.hint-finger {
  width: 27px;
  height: 27px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #234C6A;
  background: #FFE39A;
  animation: fingerNudge 1.4s ease-in-out infinite;
}

.hint-finger .mp-icon { width: 16px; height: 16px; }

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

/* ---------- 蓄力条 ---------- */
.power-panel {
  position: absolute;
  z-index: 9;
  left: 16px;
  right: 16px;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 88px);
  padding: 9px 13px 12px;
  border-radius: 16px;
  background: rgba(255, 255, 255, .64);
  border: 1px solid rgba(255, 255, 255, .82);
  box-shadow: 0 8px 24px rgba(30, 70, 104, .10), inset 0 1px 0 rgba(255, 255, 255, .7);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  pointer-events: none;
  opacity: 0;
  transition: opacity .28s ease, transform .28s ease;
}

.app.is-playing .power-panel { opacity: 1; }

.power-panel.charging {
  background: rgba(255, 255, 255, .82);
  transform: translateY(-2px);
  box-shadow: 0 12px 30px rgba(30, 70, 104, .16), inset 0 1px 0 rgba(255, 255, 255, .8);
}

.power-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 7px;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-2);
}

.power-top #powerPct {
  font-variant-numeric: tabular-nums;
  color: var(--orange-deep);
}

.power-track {
  position: relative;
  height: 9px;
  border-radius: 999px;
  background: rgba(34, 61, 86, .10);
  overflow: visible;
}

.power-fill {
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #FFD46A 0%, #FFA53D 45%, #FF6A2A 100%);
  box-shadow: 0 2px 8px rgba(255, 122, 43, .35);
  transition: width .05s linear;
}

.power-knob {
  position: absolute;
  top: 50%;
  left: 0%;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid #FF8A3D;
  box-shadow: 0 2px 7px rgba(150, 70, 10, .28);
  transform: translate(-50%, -50%);
  transition: left .05s linear;
}

/* ---------- Toast ---------- */
.toast-layer {
  position: absolute;
  z-index: 24;
  top: calc(env(safe-area-inset-top, 0px) + 90px);
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}

.toast {
  max-width: calc(100% - 40px);
  padding: 8px 16px;
  border-radius: 999px;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  background: rgba(31, 66, 96, .86);
  box-shadow: 0 8px 22px rgba(10, 40, 70, .22);
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity .22s ease, transform .22s ease;
}

.toast.show { opacity: 1; transform: translateY(0); }
.toast.gold { background: linear-gradient(135deg, #FF9A3D, #F05E24); }
.toast.soft { background: rgba(61, 96, 124, .88); }

/* ---------- 开始弹层 ---------- */
.start-overlay {
  position: absolute;
  z-index: 30;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(env(safe-area-inset-top, 0px) + 18px) 20px calc(env(safe-area-inset-bottom, 0px) + 18px);
  background:
    radial-gradient(90% 55% at 50% 30%, rgba(255, 255, 255, .08), rgba(12, 48, 78, .34) 78%),
    linear-gradient(180deg, rgba(18, 55, 88, .10) 0%, rgba(16, 52, 84, .48) 100%);
  opacity: 1;
  visibility: visible;
  transition: opacity .34s ease, visibility .34s ease;
}

.start-overlay.hide {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.start-card {
  width: 100%;
  max-width: 360px;
  padding: 22px 20px 18px;
  border-radius: 26px;
  background: rgba(255, 253, 248, .96);
  border: 1px solid rgba(255, 255, 255, .78);
  box-shadow: 0 20px 60px rgba(8, 37, 64, .34), inset 0 1px 0 #fff;
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  animation: cardIn .42s cubic-bezier(.2, .85, .3, 1.1);
}

@keyframes cardIn {
  0% { opacity: 0; transform: translateY(14px) scale(.97); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

.start-player {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.avatar {
  position: relative;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  overflow: hidden;
  border-radius: 50%;
  color: #fff;
  font-weight: 800;
  background: linear-gradient(145deg, #7C9FE2, #556FC9);
  background-size: cover;
  background-position: center;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .55), 0 4px 10px rgba(21, 57, 89, .18);
}

.avatar-sm {
  width: 40px;
  height: 40px;
  font-size: 17px;
}

.start-player-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.start-player-info span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
}

.start-player-info small {
  margin-top: 2px;
  font-size: 10px;
  letter-spacing: .08em;
  color: var(--muted);
}

.start-card h1 {
  margin: 0 0 10px;
  font-size: 28px;
  line-height: 1.26;
  font-weight: 900;
  letter-spacing: -.02em;
  color: var(--ink);
}

.start-card h1 span { color: var(--orange-deep); }

.start-desc {
  margin: 0 0 16px;
  font-size: 13px;
  line-height: 1.7;
  color: var(--ink-2);
}

.start-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.start-stats > div {
  padding: 10px 12px;
  border-radius: 14px;
  background: linear-gradient(160deg, #FFF8F0, #FFF1E3);
  border: 1px solid #F6E7D5;
}

.start-stats span {
  display: block;
  margin-bottom: 3px;
  font-size: 10px;
  color: var(--muted);
}

.start-stats b {
  font-size: 20px;
  font-weight: 900;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  min-height: 54px;
  border-radius: 18px;
  color: #fff;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: .02em;
  background: linear-gradient(135deg, #FFA24D 0%, #FF7A2E 55%, #F26418 100%);
  box-shadow: 0 10px 24px rgba(233, 100, 26, .34), inset 0 1px 0 rgba(255, 255, 255, .38);
  transition: transform .12s ease, box-shadow .12s ease;
}

.btn-primary .mp-icon { width: 22px; height: 22px; }
.btn-primary:active { transform: scale(.975); box-shadow: 0 5px 16px rgba(233, 100, 26, .30); }

.start-foot {
  margin: 11px 0 0;
  text-align: center;
  font-size: 10px;
  line-height: 1.6;
  color: var(--muted);
}

/* ---------- 结算弹层 ---------- */
.over-overlay {
  position: absolute;
  z-index: 28;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(env(safe-area-inset-top, 0px) + 20px) 20px calc(env(safe-area-inset-bottom, 0px) + 20px);
  background: rgba(12, 44, 72, .46);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  animation: fadeIn .26s ease;
}

.over-overlay[hidden] { display: none; }

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

.over-card {
  width: 100%;
  max-width: 340px;
  padding: 22px 20px 20px;
  border-radius: 26px;
  text-align: center;
  background: rgba(255, 253, 248, .98);
  border: 1px solid rgba(255, 255, 255, .8);
  box-shadow: 0 22px 60px rgba(7, 34, 60, .4), inset 0 1px 0 #fff;
  animation: cardIn .38s cubic-bezier(.2, .85, .3, 1.1);
}

.over-eyebrow {
  display: inline-block;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-2);
  background: #F2F6F8;
}

.over-eyebrow.new {
  color: #9A4A00;
  background: #FFEBCF;
}

.over-score {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 5px;
  margin: 10px 0 4px;
  color: var(--ink);
}

.over-score span {
  font-size: 62px;
  line-height: 1;
  font-weight: 900;
  letter-spacing: -.05em;
  font-variant-numeric: tabular-nums;
}

.over-score small { font-size: 14px; font-weight: 700; color: var(--muted); }

.over-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 16px 0 18px;
}

.over-stats > div {
  padding: 10px 4px;
  border-radius: 13px;
  background: #FFF8F0;
  border: 1px solid #F6E9DA;
}

.over-stats span {
  display: block;
  margin-bottom: 3px;
  font-size: 10px;
  color: var(--muted);
}

.over-stats b {
  font-size: 18px;
  font-weight: 900;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* ---------- 小屏适配 ---------- */
@media (max-height: 660px) {
  .start-card { padding: 18px 16px 15px; }
  .start-card h1 { font-size: 24px; margin-bottom: 8px; }
  .start-desc { font-size: 12px; margin-bottom: 12px; }
  .start-player { margin-bottom: 12px; }
  .start-stats { margin-bottom: 12px; }
  .btn-primary { min-height: 50px; font-size: 16px; }
  .start-foot { margin-top: 8px; }
  .hint-bubble { bottom: calc(env(safe-area-inset-bottom, 0px) + 138px); }
  .power-panel { bottom: calc(env(safe-area-inset-bottom, 0px) + 76px); }
}

@media (max-height: 560px) {
  .start-card h1 { font-size: 22px; }
  .start-desc { display: none; }
  .start-stats { display: none; }
  .start-foot { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
