:root {
  --blue: #2f62e6;
  --blue-d: #1d2a56;
  --blue-l: #8fc0ff;
  --ink: #1d2350;
  --paper: #ffffff;
  --cream: #f4f8ff;
  --pink: #ff7fa0;
  --gold: #ffcf3f;
  --shadow: 0 10px 30px rgba(29, 42, 86, .25);
  --font: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", "WenQuanYi Micro Hei", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #cfe6ff; font-family: var(--font); color: var(--ink); user-select: none; -webkit-user-select: none; touch-action: none; }
#game { position: fixed; inset: 0; }
#game canvas { display: block; }
.hidden { display: none !important; }

/* ---------- 通用 ---------- */
.screen { position: fixed; inset: 0; display: none; z-index: 10; }
.screen.show { display: flex; }
.screen.dim { background: rgba(20, 30, 70, .45); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); align-items: center; justify-content: center; padding: 16px; }
.btn { font-family: inherit; border: 0; cursor: pointer; border-radius: 999px; font-weight: 800; letter-spacing: .04em; transition: transform .12s, box-shadow .12s, filter .12s; }
.btn:hover { transform: translateY(-2px); filter: brightness(1.05); }
.btn:active { transform: translateY(1px) scale(.98); }
.btn em { font-style: normal; font-size: .6em; opacity: .75; margin-left: .5em; padding: .15em .6em; border-radius: 99px; background: rgba(255,255,255,.22); vertical-align: middle; }
.btn-main { background: linear-gradient(180deg, #4f86ff, var(--blue)); color: #fff; font-size: 22px; padding: 16px 28px; box-shadow: 0 6px 0 #1f43a8, var(--shadow); width: 100%; }
.btn-sub { background: #fff; color: var(--blue); font-size: 16px; padding: 12px 18px; box-shadow: 0 4px 0 #b9c9ef; flex: 1; }
.btn-icon { background: #fff; font-size: 18px; width: 48px; height: 48px; padding: 0; box-shadow: 0 4px 0 #b9c9ef; flex: none; }
.btn-revive { background: linear-gradient(180deg, #ffe27a, var(--gold)); color: #6a4a00; font-size: 18px; padding: 13px 20px; box-shadow: 0 5px 0 #c99a10; width: 100%; margin-bottom: 12px; }
.btn-revive em { background: rgba(0,0,0,.08); }
.btn[disabled] { filter: grayscale(.9); opacity: .55; pointer-events: none; }
.btn-row { display: flex; gap: 10px; margin-top: 12px; }
.card { position: relative; background: linear-gradient(180deg, #fff, var(--cream)); border-radius: 26px; padding: 26px 26px 22px; box-shadow: var(--shadow); width: min(420px, 100%); max-height: calc(100vh - 32px); overflow: auto; border: 4px solid #fff; outline: 3px solid #cfe0ff; text-align: center; }
.card.wide { width: min(760px, 100%); text-align: left; }
.card h2 { margin: 0 0 6px; font-size: 26px; color: var(--blue-d); }
.card h3 { margin: 18px 0 8px; color: var(--blue); font-size: 17px; }
.card .muted { color: #6a7396; margin: 0 0 16px; font-size: 14px; }
.card.small .btn { margin-top: 10px; width: 100%; }
.close { position: absolute; right: 14px; top: 12px; border: 0; background: #e8efff; color: var(--blue); width: 36px; height: 36px; border-radius: 50%; font-size: 16px; cursor: pointer; font-weight: 800; }

/* ---------- 加载 ---------- */
#loading { background: radial-gradient(circle at 50% 35%, #ffffff, #cfe6ff 70%); align-items: center; justify-content: center; z-index: 50; }
.load-box { text-align: center; }
.load-img { height: min(42vh, 300px); filter: drop-shadow(0 12px 18px rgba(29,42,86,.25)); animation: bob 1.1s ease-in-out infinite; }
.load-title { font-size: 30px; font-weight: 900; color: var(--blue); margin: 10px 0 14px; letter-spacing: .1em; }
.load-bar { width: 240px; height: 14px; border-radius: 99px; background: #fff; box-shadow: inset 0 0 0 3px #cfe0ff; overflow: hidden; margin: 0 auto; }
.load-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--blue-l), var(--blue)); border-radius: 99px; transition: width .2s; }
.load-tip { margin-top: 10px; color: #6a7396; font-size: 14px; }
@keyframes bob { 50% { transform: translateY(-8px); } }

/* ---------- 菜单 ---------- */
#menu { pointer-events: none; padding: max(20px, env(safe-area-inset-top)) 24px 20px; flex-direction: column; justify-content: space-between; }
#menu > * { pointer-events: auto; }
.menu-panel { width: min(400px, 92vw); margin-top: 3vh; animation: slideIn .5s ease-out both; }
@keyframes slideIn { from { opacity: 0; transform: translateX(-30px); } }
.logo h1 { margin: 0; line-height: 1; font-size: clamp(46px, 8vw, 74px); font-weight: 900; letter-spacing: .02em; }
.logo h1 span { display: block; color: #fff; -webkit-text-stroke: 0; text-shadow: 0 4px 0 var(--blue), 0 -3px 0 var(--blue), 3px 0 0 var(--blue), -3px 0 0 var(--blue), 3px 3px 0 var(--blue), -3px 3px 0 var(--blue), 3px -3px 0 var(--blue), -3px -3px 0 var(--blue), 0 10px 0 var(--blue-d), 0 14px 20px rgba(29,42,86,.35); }
.logo h1 span:nth-child(2) { margin-left: .9em; color: #fff7d6; }
.logo-sub { display: inline-block; background: var(--blue-d); color: #fff; font-weight: 800; padding: 6px 14px; border-radius: 99px; font-size: 14px; letter-spacing: .2em; margin-bottom: 12px; }
.logo-tag { margin: 18px 0 14px; color: var(--blue-d); font-weight: 700; font-size: 15px; background: rgba(255,255,255,.75); display: inline-block; padding: 6px 14px; border-radius: 12px; }
.stats-row { display: flex; gap: 10px; margin-bottom: 14px; }
.stat { flex: 1; background: rgba(255,255,255,.85); border-radius: 16px; padding: 10px 8px; text-align: center; box-shadow: 0 4px 0 rgba(47,98,230,.18); }
.stat b { display: block; font-size: 22px; color: var(--blue); }
.stat small { color: #6a7396; font-size: 12px; }
.rivals { align-self: stretch; animation: slideIn .6s .1s ease-out both; }
.rivals-title { font-weight: 900; color: #fff; text-shadow: 0 2px 0 var(--blue-d); margin-bottom: 8px; font-size: 15px; letter-spacing: .1em; }
.rival-list { display: flex; gap: 10px; flex-wrap: wrap; }
.rival { display: flex; align-items: center; gap: 10px; background: rgba(255,255,255,.9); border-radius: 18px; padding: 6px 14px 6px 6px; box-shadow: 0 4px 0 rgba(29,42,86,.15); max-width: 300px; }
.rival img { width: 52px; height: 52px; border-radius: 14px; object-fit: cover; border: 3px solid var(--c); flex: none; }
.rival b { display: block; font-size: 15px; color: var(--c); }
.rival span { font-size: 12px; color: #5a6388; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
.hud-left { position: absolute; left: max(14px, env(safe-area-inset-left)); top: max(14px, env(safe-area-inset-top)); display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.rice-chip { display: flex; align-items: center; gap: 8px; background: rgba(255,255,255,.92); border-radius: 99px; padding: 6px 16px 6px 8px; box-shadow: 0 4px 0 rgba(29,42,86,.18); font-size: 24px; color: var(--blue-d); }
.rice-chip.bump { animation: bump .18s; }
@keyframes bump { 50% { transform: scale(1.12); } }
.oni { width: 30px; height: 28px; background: #fff; border-radius: 50% 50% 40% 40% / 60% 60% 40% 40%; position: relative; box-shadow: inset 0 0 0 2px #d8def0; }
.oni::after { content: ""; position: absolute; left: 9px; right: 9px; bottom: 0; height: 12px; background: #1f3a2c; border-radius: 2px; }
.combo-chip { display: flex; align-items: center; gap: 8px; background: rgba(29,42,86,.82); color: #fff; border-radius: 99px; padding: 5px 6px 5px 14px; font-size: 14px; font-weight: 700; transition: opacity .3s; }
.combo-chip b { background: var(--gold); color: #5a3a00; border-radius: 99px; padding: 2px 10px; font-size: 16px; }
.combo-chip.x2 b { background: linear-gradient(90deg, #ff9f1a, #ff5f7a); color: #fff; }
.combo-chip.dim { opacity: .55; }
.powers { display: flex; gap: 8px; }
.pw { width: 50px; height: 50px; border-radius: 50%; position: relative; background: conic-gradient(var(--c) var(--p), rgba(255,255,255,.5) 0); padding: 4px; box-shadow: 0 3px 0 rgba(29,42,86,.2); }
.pw img { width: 100%; height: 100%; border-radius: 50%; display: block; }
.pw.blink { animation: blink .3s infinite; }
@keyframes blink { 50% { opacity: .4; } }
.hud-right { position: absolute; right: max(70px, calc(env(safe-area-inset-right) + 70px)); top: max(14px, env(safe-area-inset-top)); text-align: right; }
.score { font-size: 40px; font-weight: 900; color: #fff; text-shadow: 0 3px 0 var(--blue), 0 -2px 0 var(--blue), 2px 0 0 var(--blue), -2px 0 0 var(--blue), 0 6px 10px rgba(29,42,86,.3); font-variant-numeric: tabular-nums; line-height: 1; }
.dist { margin-top: 4px; font-weight: 800; color: var(--blue-d); background: rgba(255,255,255,.8); display: inline-block; border-radius: 99px; padding: 3px 12px; font-size: 14px; font-variant-numeric: tabular-nums; }
.pause-btn { position: absolute; right: max(14px, env(safe-area-inset-right)); top: max(14px, env(safe-area-inset-top)); width: 46px; height: 46px; border-radius: 50%; border: 0; background: rgba(255,255,255,.92); color: var(--blue); font-weight: 900; font-size: 15px; pointer-events: auto; cursor: pointer; box-shadow: 0 4px 0 rgba(29,42,86,.18); }
.toast { position: absolute; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); display: flex; align-items: flex-end; gap: 8px; transform: translate(-50%, 140%); transition: transform .35s cubic-bezier(.3,1.4,.5,1); max-width: min(560px, 94vw); }
.toast.show { transform: translate(-50%, 0); }
.toast img { width: 72px; height: 72px; border-radius: 20px; border: 4px solid #fff; box-shadow: var(--shadow); flex: none; background: #fff; }
.bubble { background: #fff; border-radius: 18px 18px 18px 4px; padding: 10px 16px; box-shadow: var(--shadow); font-size: 15px; font-weight: 600; line-height: 1.45; }
.bubble b { display: block; font-size: 12px; color: var(--c, var(--blue)); letter-spacing: .05em; }
.milestone { position: absolute; left: 50%; top: 24%; transform: translate(-50%, -50%) scale(.6); opacity: 0; font-size: clamp(34px, 7vw, 60px); font-weight: 900; color: #fff7d6; text-shadow: 0 4px 0 var(--blue), 0 -3px 0 var(--blue), 3px 0 0 var(--blue), -3px 0 0 var(--blue), 0 10px 18px rgba(29,42,86,.35); white-space: nowrap; transition: all .35s cubic-bezier(.3,1.5,.5,1); }
.milestone.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.floater { position: absolute; left: 50%; top: 40%; transform: translate(-50%, 0); font-weight: 900; font-size: 26px; color: #fff; text-shadow: 0 3px 0 #e07a00, 0 6px 10px rgba(0,0,0,.2); opacity: 0; white-space: nowrap; }
.floater.go { animation: floatUp 1s ease-out; }
@keyframes floatUp { 0% { opacity: 0; transform: translate(-50%, 20px) scale(.8); } 20% { opacity: 1; transform: translate(-50%, 0) scale(1.05); } 100% { opacity: 0; transform: translate(-50%, -50px); } }
.warn { position: absolute; inset: 0; box-shadow: inset 0 0 120px 30px rgba(255, 60, 90, .55); opacity: 0; transition: opacity .3s; }
.warn.on { animation: warnPulse .7s infinite; }
@keyframes warnPulse { 50% { opacity: 1; } }
.ctrl-hint { position: absolute; left: 50%; top: 58%; transform: translateX(-50%); text-align: center; color: #fff; font-weight: 800; font-size: 18px; text-shadow: 0 2px 0 var(--blue-d), 0 4px 10px rgba(0,0,0,.25); opacity: 0; transition: opacity .5s; white-space: nowrap; }
.ctrl-hint small { font-size: 13px; opacity: .9; }
.ctrl-hint.show { opacity: 1; }

/* ---------- 结算 ---------- */
.over-card { padding-top: 20px; overflow: visible; max-height: none; }
.btn-row .btn-main { flex: 2; width: auto; }
.over-head { margin-bottom: 8px; }
.over-who { display: flex; align-items: center; gap: 12px; text-align: left; }
.over-who img { width: 92px; height: 92px; border-radius: 24px; border: 4px solid var(--c, var(--blue)); flex: none; object-fit: cover; }
.over-quote { background: #fff; border-radius: 18px 18px 18px 4px; padding: 10px 14px; font-size: 14px; font-weight: 600; box-shadow: 0 4px 0 rgba(29,42,86,.1); line-height: 1.5; position: relative; }
.over-head h2 { margin-top: 12px; font-size: 26px; }
.over-rank { margin: 2px 0 12px; }
.over-rank span { display: inline-block; background: var(--blue-d); color: #fff; font-weight: 800; padding: 5px 14px; border-radius: 99px; font-size: 14px; }
.new-best { display: none; font-style: normal; margin-left: 8px; background: var(--pink); color: #fff; padding: 5px 12px; border-radius: 99px; font-weight: 900; font-size: 14px; animation: bump .6s infinite; }
.new-best.on { display: inline-block; }
.over-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 14px; }
.over-stats div { background: #fff; border-radius: 14px; padding: 8px 4px; box-shadow: 0 3px 0 #dde6fb; }
.over-stats small { display: block; color: #6a7396; font-size: 12px; }
.over-stats b { font-size: 19px; color: var(--blue); font-variant-numeric: tabular-nums; white-space: nowrap; }
.over-ds { position: absolute; right: -14px; top: -22px; width: 74px; height: 74px; border-radius: 22px; border: 4px solid #fff; box-shadow: var(--shadow); transform: rotate(8deg); }

/* ---------- 商店 ---------- */
.bank { color: var(--blue); }
.shop-list { display: grid; gap: 10px; }
.shop-item { display: flex; align-items: center; gap: 14px; background: #fff; border-radius: 18px; padding: 12px 14px; box-shadow: 0 3px 0 #dde6fb; }
.shop-item img { width: 56px; height: 56px; flex: none; }
.shop-item .info { flex: 1; min-width: 0; }
.shop-item .info b { font-size: 16px; }
.shop-item .info p { margin: 2px 0 6px; color: #6a7396; font-size: 13px; }
.pips { display: flex; gap: 4px; }
.pips i { width: 22px; height: 8px; border-radius: 4px; background: #e2e8f6; }
.pips i.on { background: var(--blue); }
.shop-item .btn { font-size: 15px; padding: 10px 16px; background: var(--gold); color: #6a4a00; box-shadow: 0 4px 0 #c99a10; white-space: nowrap; flex: none; }
.shop-item .btn.max { background: #e2e8f6; color: #6a7396; box-shadow: none; }

/* ---------- 说明 ---------- */
.help-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.help-block { background: #fff; border-radius: 16px; padding: 4px 16px 10px; box-shadow: 0 3px 0 #dde6fb; font-size: 14px; line-height: 1.6; }
.help-block p { margin: 6px 0; }
kbd { display: inline-block; min-width: 24px; padding: 1px 6px; border-radius: 6px; background: #eef3ff; border: 1px solid #c9d6f5; border-bottom-width: 3px; font-family: inherit; font-size: 12px; text-align: center; margin-right: 2px; }
.help-rivals, .help-powers { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.help-rival, .help-power { display: flex; gap: 12px; align-items: center; background: #fff; border-radius: 16px; padding: 10px; box-shadow: 0 3px 0 #dde6fb; font-size: 13px; line-height: 1.5; }
.help-rival img { width: 58px; height: 58px; border-radius: 14px; border: 3px solid var(--c); flex: none; }
.help-power img { width: 46px; height: 46px; flex: none; }
.help-rival b, .help-power b { color: var(--c, var(--blue)); font-size: 15px; }

@media (max-width: 640px) {
  .help-grid, .help-rivals, .help-powers { grid-template-columns: 1fr; }
  .rival { padding-right: 10px; }
  .rival span { display: none; }
  .rival img { width: 44px; height: 44px; }
  .menu-panel { margin-top: 0; }
  .score { font-size: 32px; }
  .rice-chip { font-size: 20px; }
  .toast img { width: 56px; height: 56px; }
  .bubble { font-size: 13px; }
  .stat b { font-size: 18px; }
  .btn-main { font-size: 20px; padding: 14px 22px; }
}
@media (max-height: 600px) {
  .over-who img { width: 64px; height: 64px; border-radius: 18px; }
  .over-head h2 { font-size: 22px; margin-top: 8px; }
  .card { padding: 18px 20px 16px; }
  .btn-revive { padding: 10px 16px; font-size: 16px; }
  .btn-row .btn-main { font-size: 18px; padding: 12px 18px; }
}
@media (max-width: 480px) {
  .over-stats { grid-template-columns: 1fr 1fr; }
}
@media (max-height: 560px) {
  .menu-panel { margin-top: 0; }
  .logo h1 { font-size: 42px; }
  .logo-tag { margin: 10px 0 8px; }
  .rivals { display: none; }
}

@media (hover: none) and (pointer: coarse) { .btn em.key { display: none; } }
