:root {
  --blue: #1667d9;
  --blue-deep: #0d4fae;
  --yellow: #f5b301;
  --ink: #142236;
  --muted: #5b6b80;
  --card: rgba(255, 255, 255, .86);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #cfe3f5; color: var(--ink);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", "Noto Sans CJK SC", system-ui, sans-serif;
  -webkit-user-select: none; user-select: none; touch-action: none; overscroll-behavior: none; }
#app, #app canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }
.screen { position: fixed; inset: 0; z-index: 10; }

/* 设备相关提示 */
body.touch .desktop-only { display: none; }
body:not(.touch) .touch-only { display: none; }

/* 加载 */
#loading { display: grid; place-items: center; background: linear-gradient(180deg, #a9d0f2 0%, #e8f2fb 70%, #f6f1e4 100%); }
.load-card { width: min(86vw, 360px); text-align: center; }
.load-card h1 { margin: 14px 0 22px; font-size: clamp(19px, 5.4vw, 26px); letter-spacing: .06em; }
.brand-dot { width: 46px; height: 46px; border-radius: 50%; margin: 0 auto; background: radial-gradient(circle at 35% 35%, #ffd862, var(--yellow) 60%, #d89a00);
  box-shadow: 0 6px 18px rgba(245, 179, 1, .45); animation: bob 1.1s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-8px); } }
.bar { height: 8px; border-radius: 8px; background: rgba(20, 34, 54, .12); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--blue), #3d8bff); border-radius: 8px; transition: width .2s; }
.load-card p { margin: 12px 0 0; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
#fatal { display: grid; place-items: center; background: #eef4fa; }
#fatal p { line-height: 1.7; color: var(--ink); }

/* 标题 */
#title { pointer-events: none; display: flex; flex-direction: column; justify-content: space-between; }
.title-top { padding: calc(18px + var(--safe-t)) 22px 0; }
.title-top h1 { margin: 0; font-size: clamp(20px, 3vw, 34px); letter-spacing: .06em; color: #fff; text-shadow: 0 2px 12px rgba(10, 40, 80, .45); }
.title-top p { margin: 6px 0 0; font-size: clamp(12px, 1.4vw, 15px); color: #fff; text-shadow: 0 1px 8px rgba(10, 40, 80, .5); letter-spacing: .04em; }
.title-bottom { padding: 0 20px calc(26px + var(--safe-b)); text-align: center; }
.title-bottom .hint { margin: 12px 0 0; font-size: 13px; color: #fff; text-shadow: 0 1px 6px rgba(0, 0, 0, .45); letter-spacing: .06em; }

.btn { pointer-events: auto; border: 0; cursor: pointer; font: inherit; font-weight: 600; letter-spacing: .3em; padding: 14px 44px 14px calc(44px + .3em);
  border-radius: 999px; font-size: 18px; transition: transform .12s, box-shadow .12s; }
.btn.primary { color: #fff; background: linear-gradient(180deg, #2b7cf0, var(--blue-deep)); box-shadow: 0 8px 24px rgba(13, 79, 174, .38), inset 0 1px 0 rgba(255, 255, 255, .3); }
.btn:active { transform: scale(.96); }
.btn:focus-visible { outline: 3px solid var(--yellow); outline-offset: 3px; }

/* HUD */
#hud { position: fixed; inset: 0; z-index: 5; pointer-events: none; }
.hud-bar { position: absolute; top: calc(12px + var(--safe-t)); left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 14px;
  padding: 7px 16px; border-radius: 999px; background: var(--card); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 4px 16px rgba(20, 34, 54, .16); white-space: nowrap; }
.hud-bar .sep { width: 1px; height: 22px; background: rgba(20, 34, 54, .18); }
.stars { display: flex; gap: 6px; }
.stars span { display: flex; flex-direction: column; align-items: center; gap: 1px; }
.stars em { font-style: normal; font-size: 9px; font-weight: 700; color: var(--muted); letter-spacing: .02em; line-height: 1; }
.stars span.on em { color: #c27a00; }
.stars i { width: 24px; height: 24px; display: block; background: rgba(20, 34, 54, .18);
  clip-path: polygon(50% 2%, 62% 36%, 98% 37%, 69% 59%, 79% 95%, 50% 74%, 21% 95%, 31% 59%, 2% 37%, 38% 36%); transition: background .2s; }
.stars span.on i { background: linear-gradient(180deg, #ffe066, #f5a800); animation: starpop .55s cubic-bezier(.2, 1.8, .4, 1); }
@keyframes starpop { 0% { transform: scale(.3); } 60% { transform: scale(1.5); } 100% { transform: scale(1); } }
.stat { display: flex; flex-direction: column; align-items: center; line-height: 1.05; min-width: 34px; }
.stat b { font-size: 16px; font-variant-numeric: tabular-nums; }
.stat small { font-size: 10px; color: var(--muted); }
#hudDmg.up { color: #e08a00; animation: starpop .5s; }
.hud-hint { position: absolute; bottom: calc(20px + var(--safe-b)); left: 0; right: 0; text-align: center; margin: 0; font-size: 14px; font-weight: 600; color: #fff;
  text-shadow: 0 1px 6px rgba(0, 0, 0, .6); letter-spacing: .05em; transition: opacity .4s; padding: 0 16px; }
body.touch .hud-hint { bottom: auto; top: calc(66px + var(--safe-t)); font-size: 13px; }
.banner { position: absolute; top: 28%; left: 50%; transform: translate(-50%, -50%); padding: 12px 26px; border-radius: 14px; background: rgba(12, 40, 90, .78);
  color: #fff; font-size: clamp(15px, 2.4vw, 22px); font-weight: 700; letter-spacing: .08em; text-align: center; opacity: 0; transition: opacity .35s, transform .35s; max-width: 90vw; }
.banner.show { opacity: 1; transform: translate(-50%, -50%) scale(1.03); }
.banner.gold { background: linear-gradient(180deg, rgba(255, 196, 40, .95), rgba(224, 138, 0, .95)); color: #3a2400; }
#vignette { position: absolute; inset: 0; opacity: 0; background: radial-gradient(ellipse at center, transparent 45%, rgba(220, 20, 30, .65) 100%); transition: opacity .2s; }

/* 浮动伤害数字、屏幕边缘指示 */
#fxLayer { position: fixed; inset: 0; z-index: 4; pointer-events: none; overflow: hidden; }
.dmg { position: absolute; left: 0; top: 0; font-weight: 800; font-size: 18px; color: #fff; text-shadow: 0 2px 0 #b3261e, 0 0 6px rgba(0, 0, 0, .5); white-space: nowrap; will-change: transform, opacity; }
.dmg.big { font-size: 24px; color: #ffe066; text-shadow: 0 2px 0 #a35b00, 0 0 8px rgba(0, 0, 0, .5); }
.dmg.ice { font-size: 20px; color: #e6f8ff; text-shadow: 0 2px 0 #1b6fb5, 0 0 10px rgba(80, 190, 255, .9); }
.dmg.rage { font-size: 22px; color: #fff1ec; text-shadow: 0 2px 0 #b3170c, 0 0 10px rgba(255, 60, 30, .9); }
.edge { position: absolute; left: 0; top: 0; width: 0; height: 0; border-left: 11px solid transparent; border-right: 11px solid transparent; border-bottom: 20px solid #ff4338;
  filter: drop-shadow(0 0 4px rgba(0, 0, 0, .5)); will-change: transform; }
.edge.gold { border-bottom-color: #ffc21a; }

.icon-btn { position: fixed; top: calc(12px + var(--safe-t)); right: calc(12px + env(safe-area-inset-right, 0px)); z-index: 7; width: 40px; height: 40px; border-radius: 50%;
  border: 0; background: var(--card); box-shadow: 0 4px 12px rgba(20, 34, 54, .16); font-size: 18px; cursor: pointer; }
#fireBtn { position: fixed; right: calc(26px + env(safe-area-inset-right, 0px)); bottom: calc(40px + var(--safe-b)); z-index: 6; width: 104px; height: 104px; border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, .85); background: radial-gradient(circle at 40% 35%, #ff8a5c, #e5402a 70%); box-shadow: 0 8px 22px rgba(160, 30, 10, .45);
  touch-action: none; -webkit-user-select: none; user-select: none; }
#fireBtn span { position: absolute; inset: 30px; border-radius: 50%; border: 3px solid #fff; }
#fireBtn span::before, #fireBtn span::after { content: ''; position: absolute; background: #fff; left: 50%; top: -12px; bottom: -12px; width: 3px; margin-left: -1.5px; }
#fireBtn span::after { transform: rotate(90deg); }
#fireBtn.active { transform: scale(.94); filter: brightness(1.15); }

/* 摇杆 */
#stickZone { position: fixed; left: 0; bottom: 0; width: 55vw; height: 55vh; z-index: 6; touch-action: none; }
#stickBase { position: absolute; left: calc(28px + env(safe-area-inset-left, 0px)); bottom: calc(34px + var(--safe-b)); width: 128px; height: 128px; border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, .28) 0 55%, rgba(255, 255, 255, .42) 56% 100%); border: 2px solid rgba(255, 255, 255, .75);
  box-shadow: 0 6px 20px rgba(20, 34, 54, .2); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); transition: opacity .2s; opacity: .85; }
#stickBase.active { opacity: 1; }
#stickKnob { position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; margin: -28px 0 0 -28px; border-radius: 50%;
  background: linear-gradient(180deg, #2b7cf0, var(--blue-deep)); box-shadow: 0 4px 12px rgba(13, 79, 174, .45), inset 0 1px 0 rgba(255, 255, 255, .35); }

/* 结算 */
#result { display: grid; place-items: center; background: rgba(16, 36, 64, .28); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); animation: fade .5s ease both; }
@keyframes fade { from { opacity: 0; } }
.result-card { width: min(88vw, 380px); padding: 30px 26px 26px; border-radius: 22px; background: rgba(255, 255, 255, .94); text-align: center;
  box-shadow: 0 20px 60px rgba(10, 30, 60, .3); animation: pop .5s cubic-bezier(.2, 1.4, .4, 1) both; }
@keyframes pop { from { transform: translateY(18px) scale(.94); opacity: 0; } }
.badge.fail { background: linear-gradient(180deg, #ff7a6b, #d93a2b); box-shadow: 0 6px 16px rgba(217, 58, 43, .4); }
.badge { width: 58px; height: 58px; margin: 0 auto 10px; border-radius: 50%; display: grid; place-items: center; font-size: 30px; color: #fff; font-weight: 700;
  background: linear-gradient(180deg, #ffcc33, var(--yellow)); box-shadow: 0 6px 16px rgba(245, 179, 1, .45); }
.result-card h2 { margin: 6px 0 18px; font-size: 16px; font-weight: 600; letter-spacing: .1em; color: var(--muted); line-height: 1.6; }
.res-name { display: block; font-size: clamp(18px, 5.2vw, 22px); color: var(--ink); letter-spacing: .04em; }
.stats { display: flex; justify-content: center; gap: 12px; margin-bottom: 22px; }
.stats div { flex: 1; padding: 12px 6px; border-radius: 14px; background: #eef4fb; }
.stats b { display: block; font-size: 24px; color: var(--blue); font-variant-numeric: tabular-nums; }
.stats span { font-size: 12px; color: var(--muted); }

/* 矮屏（手机横屏） */
@media (max-height: 500px) {
  .title-top { padding-top: calc(10px + var(--safe-t)); }
  .title-top h1 { font-size: 20px; }
  .title-top p { font-size: 12px; margin-top: 2px; }
  .title-bottom { padding-bottom: calc(12px + var(--safe-b)); }
  .btn { font-size: 16px; padding: 10px 34px 10px calc(34px + .3em); }
  .title-bottom .hint { margin-top: 6px; font-size: 12px; }
  #stickBase { width: 108px; height: 108px; bottom: calc(18px + var(--safe-b)); }
  .result-card { padding: 16px 20px; }
  .result-card h2 { margin: 2px 0 10px; font-size: 18px; }
  .badge { width: 40px; height: 40px; font-size: 22px; margin-bottom: 4px; }
  .stats { margin-bottom: 12px; }
  .stats b { font-size: 20px; }
}

@media (max-height: 500px) {
  .hud-bar { padding: 4px 12px; gap: 10px; }
  .stars i { width: 20px; height: 20px; }
  #fireBtn { width: 84px; height: 84px; bottom: calc(20px + var(--safe-b)); }
  #fireBtn span { inset: 24px; }
}
