* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  overflow: hidden;
  background: #8fcf6b;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei",
    "Helvetica Neue", Arial, sans-serif;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#app {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  min-height: -webkit-fill-available;
  overflow: hidden;
}

#game {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: max(10px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left));
  z-index: 5;
  /* #hud 本身必须禁用指针事件：否则即使子元素都设了 pointer-events，
     这个跨越整个顶部的容器仍会挡住下面的 canvas 点击（见 code review）。
     只有 #hudRight > * 显式打开 pointer-events: auto，按钮才可点。 */
  pointer-events: none;
}

#hud.hidden {
  display: none;
}

#hudLeft {
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

#hudRight {
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

#hudRight > * {
  pointer-events: auto;
}

#scoreText {
  font-size: 26px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.18), 0 0 6px rgba(255, 255, 255, 0.4);
  letter-spacing: 1px;
}

#comboText {
  font-size: 15px;
  font-weight: 700;
  color: #fff6b8;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
}

#comboText.hidden {
  display: none;
}

#rankText {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.2);
  opacity: 0.9;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.icon-btn:active {
  transform: scale(0.92);
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, rgba(135, 206, 250, 0.5), rgba(143, 207, 107, 0.55));
  z-index: 10;
  padding: 20px;
  overflow-y: auto;
}

.hidden {
  display: none;
}

.panel {
  width: min(86vw, 380px);
  max-height: 90vh;
  overflow-y: auto;
  background: #fffdf6;
  border-radius: 28px;
  padding: 28px 26px 26px;
  text-align: center;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.2);
  border: 4px solid #ffd977;
}

.panel h1 {
  font-size: 28px;
  color: #ff8a5c;
  margin-bottom: 2px;
  text-shadow: 1px 1px 0 #fff3d6;
}

.panel h2 {
  font-size: 22px;
  color: #ff8a5c;
  margin-bottom: 10px;
}

.subtitle {
  font-size: 13px;
  color: #c79a5b;
  letter-spacing: 2px;
  margin-bottom: 14px;
}

.cat-preview {
  font-size: 50px;
  line-height: 1;
  margin: 6px 0 14px;
}

.hint {
  font-size: 13px;
  color: #8a7a60;
  line-height: 1.6;
  margin-bottom: 16px;
}

.btn-primary,
.btn-secondary {
  display: inline-block;
  border: none;
  padding: 13px 34px;
  font-size: 17px;
  font-weight: 800;
  border-radius: 999px;
  cursor: pointer;
  margin: 6px 4px;
}

.btn-primary {
  color: #fff;
  background: linear-gradient(180deg, #ffa06b, #ff7a45);
  box-shadow: 0 6px 0 #e85f28, 0 10px 18px rgba(255, 122, 69, 0.4);
}

.btn-primary:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #e85f28, 0 4px 10px rgba(255, 122, 69, 0.4);
}

.btn-secondary {
  color: #6b5b43;
  background: #ffe9b0;
  box-shadow: 0 4px 0 #e0bf74, 0 6px 12px rgba(224, 191, 116, 0.35);
}

.btn-secondary:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #e0bf74, 0 2px 6px rgba(224, 191, 116, 0.35);
}

.btn-row {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
}

.best,
.score-line {
  margin-top: 14px;
  font-size: 15px;
  color: #6b5b43;
  font-weight: 600;
}

.best span,
.score-line span {
  color: #ff7a45;
  font-weight: 800;
}

.nickname-label {
  display: block;
  margin: 14px 0 6px;
  font-size: 13px;
  color: #8a7a60;
  font-weight: 600;
  text-align: left;
}

.nickname-label input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  font-size: 15px;
  border-radius: 12px;
  border: 2px solid #ffd977;
  background: #fff;
  color: #4a3f2e;
  box-sizing: border-box;
}

.nickname-label input:focus {
  outline: none;
  border-color: #ff7a45;
}

.nickname-hint {
  margin: -2px 0 4px;
  font-size: 12px;
  color: #d1442c;
  text-align: left;
}

.nickname-hint.hidden {
  display: none;
}

.result-stats {
  text-align: left;
  font-size: 14px;
  color: #6b5b43;
  line-height: 1.9;
  margin: 10px 0;
}

.result-stats span {
  color: #ff7a45;
  font-weight: 800;
}

#resultRankStatus {
  font-size: 13px;
  color: #8a7a60;
  margin-bottom: 6px;
}

.leaderboard-list {
  max-height: 50vh;
  overflow-y: auto;
  margin: 10px 0;
  text-align: left;
}

.lb-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px;
  border-bottom: 1px solid #f1e4bf;
  font-size: 14px;
  color: #4a3f2e;
}

.lb-rank {
  width: 26px;
  color: #c79a5b;
  font-weight: 700;
  flex-shrink: 0;
}

.lb-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 6px;
}

.lb-score {
  font-weight: 800;
  color: #ff7a45;
  flex-shrink: 0;
}

.lb-badge {
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  padding: 2px 7px;
  margin-left: 6px;
  flex-shrink: 0;
}

.lb-badge.live {
  background: #ffdede;
  color: #d1442c;
}

.lb-badge.paused {
  background: #e6e6e6;
  color: #777;
}

.lb-empty,
.lb-loading,
.lb-error {
  font-size: 13px;
  color: #8a7a60;
  text-align: center;
  padding: 16px 0;
}

/* ===== Q版重设计 ===== */
html, body { background: #a8de8e; }
.overlay { background: linear-gradient(180deg, rgba(255, 236, 214, 0.55), rgba(168, 222, 142, 0.55)); }
.panel { background: rgba(255, 255, 255, 0.96); border: 4px solid #ffc58f; box-shadow: 0 14px 34px rgba(224, 122, 51, 0.22); }
.panel h1 { font-size: 30px; color: #ff8a3d; text-shadow: 0 2px 0 #fff, 0 3px 0 #ffd9b8; letter-spacing: 1px; }
.panel h2 { color: #ff8a3d; }
.start-panel { padding: 18px 18px 16px; }
.skin-preview { width: 94px; height: 84px; display: block; margin: 2px auto 0; }
.skin-name { font-size: 19px; font-weight: 800; color: #7a4a2a; }
.skin-desc { font-size: 12px; color: #b08a6a; margin-bottom: 4px; }
.section-title { text-align: left; font-size: 14px; font-weight: 800; color: #7a4a2a; margin: 4px 2px 6px; }
.skin-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.skin-card { position: relative; border: 2px solid #ece6df; background: #f7f5f2; border-radius: 16px; padding: 4px 0 4px; cursor: pointer; font: inherit; color: #7a4a2a; font-size: 13px; font-weight: 700; }
.skin-card canvas { width: 56px; height: 52px; display: block; margin: 0 auto; }
.skin-card.selected { border: 3px solid #ff9d4d; background: #fff1e2; }
.skin-card.selected::after { content: "✓"; position: absolute; top: -7px; right: -7px; width: 20px; height: 20px; line-height: 18px; border-radius: 50%; background: #ff9d4d; color: #fff; font-size: 12px; border: 2px solid #fff; }
.skin-card:active { transform: scale(0.95); }
.nickname-label { color: #7a4a2a; font-size: 14px; font-weight: 800; margin: 10px 2px 6px; }
.nickname-row { display: flex; gap: 8px; align-items: center; }
.nickname-row input, .nickname-label input { flex: 1; min-width: 0; padding: 11px 16px; font-size: 16px; border-radius: 999px; border: 3px solid #ffc58f; background: #fff; color: #5a3a30; }
.nickname-row input:focus { outline: none; border-color: #ff9d4d; }
.dice-btn { flex-shrink: 0; width: 46px; height: 46px; border-radius: 14px; border: 3px solid #e07a33; background: #ff9d4d; display: flex; align-items: center; justify-content: center; cursor: pointer; box-shadow: 0 3px 0 #e07a33; padding: 0; }
.dice-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #e07a33; }
.dice-btn.rolling .dice-face { animation: dice-roll 0.45s ease-out; }
@keyframes dice-roll { 0% { transform: rotate(0) scale(1); } 50% { transform: rotate(200deg) scale(0.8); } 100% { transform: rotate(360deg) scale(1); } }
.dice-face { position: relative; width: 26px; height: 26px; background: #fff; border-radius: 7px; display: block; }
.dice-face i { position: absolute; width: 5px; height: 5px; border-radius: 50%; background: #ff7a3d; }
.dice-face i:nth-child(1) { left: 4px; top: 4px; } .dice-face i:nth-child(2) { right: 4px; top: 4px; }
.dice-face i:nth-child(3) { left: 10.5px; top: 10.5px; }
.dice-face i:nth-child(4) { left: 4px; bottom: 4px; } .dice-face i:nth-child(5) { right: 4px; bottom: 4px; }
.btn-wide { display: block; width: 100%; margin: 12px 0 6px; font-size: 19px; }
.start-panel .hint { font-size: 12px; margin: 6px 0 0; }
.start-panel .best { margin-top: 6px; }
.hud-pill { background: rgba(255, 255, 255, 0.9); border: 3px solid #ffb36b; border-radius: 999px; color: #7a4a2a !important; text-shadow: none !important; padding: 2px 16px; display: inline-block; align-self: flex-start; }
#scoreText.hud-pill { font-size: 22px; }
#scoreText.hud-pill::before { content: "🐭 "; font-size: 16px; }
#rankText.hud-pill { font-size: 13px; font-weight: 800; padding: 2px 12px; opacity: 1; margin-top: 4px; }
#comboText { color: #ff7a9a; text-shadow: 0 0 3px #fff, 0 0 3px #fff; font-weight: 900; padding-left: 8px; }
.icon-btn { background: #ff9d4d; border: 3px solid #fff; color: #fff; box-shadow: 0 3px 8px rgba(224, 122, 51, 0.35); }
.lb-avatar { width: 30px; height: 30px; flex-shrink: 0; margin-right: 2px; }
.lb-row { border-bottom: 1px dashed #f3d9bf; }
.lb-score { color: #ff8a3d; }
#leaderboardScreen { background: rgba(255, 244, 232, 0.94); }
.lb-badge { margin-right: 8px; }

.lb-hud-btn { width: auto; padding: 0 12px 0 9px; border-radius: 999px; gap: 3px; font-size: 16px; }
.lb-hud-btn span { font-size: 13px; font-weight: 900; color: #fff; }
.lb-sub { font-size: 12px; color: #b08a6a; margin: -6px 0 4px; }
.lb-row.me { background: #fff1e2; border-radius: 12px; border-bottom-color: transparent; box-shadow: inset 0 0 0 2px #ff9d4d; }
.lb-row.me .lb-name { font-weight: 900; color: #e0602a; }
.lb-me-tag { font-size: 11px; font-weight: 800; background: #ff9d4d; color: #fff; border-radius: 999px; padding: 1px 7px; margin-right: 6px; flex-shrink: 0; }

/* ---- 被动能力 ---- */
.ability-badge { display: inline-flex; align-items: center; gap: 4px; pointer-events: none; transition: transform .15s; }
.ability-badge .ab-ic { font-size: 1.1em; }
.ability-badge.flash { transform: scale(1.12); background: #fff3c4; box-shadow: 0 0 0 3px #ffd84a; }
.skin-ability { margin: 0 auto 2px; max-width: 300px; padding: 3px 10px; border-radius: 14px; background: #fff3e2; border: 2px dashed #ffc58f; font-size: 12px; color: #7a4a2a; line-height: 1.28; }
.skin-ability b { display: block; font-size: 14px; color: #e07a33; }
.lb-filter { display: flex; gap: 4px; justify-content: center; flex-wrap: wrap; margin: 4px 0 8px; }
.lb-chip { border: 2px solid #ffd2a8; background: #fff; border-radius: 999px; height: 30px; min-width: 30px; padding: 0 3px; font-weight: 700; color: #7a4a2a; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.lb-chip img { width: 22px; height: 22px; }
.lb-chip.on { background: #ff9d4d; border-color: #ff9d4d; color: #fff; }

/* ---- 全面屏适配 ---- */
.overlay { padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
.overlay > .panel { max-height: 100%; overflow-y: auto; }
.lb-flag { margin-right: 4px; font-size: 15px; cursor: default; }
.lb-row.lb-changed { animation: lb-changed 1.2s ease-out; }
@keyframes lb-changed { 0% { background: #fff1c2; } 100% { background: transparent; } }
.lb-hud-btn, .ability-badge { white-space: nowrap; }

/* ---- 进化技能 ---- */
.ability-badge { flex-direction: row; align-items: center; gap: 6px; padding: 4px 10px 4px 6px; }
.ability-badge .ab-ic { font-size: 20px; display: inline-block; }
.ability-badge .ab-txt { display: grid; grid-template-columns: auto 1fr; column-gap: 4px; align-items: center; line-height: 1.15; }
.ability-badge .ab-lv { color: #ff7a3d; font-weight: 900; }
.ability-badge .ab-name { font-weight: 700; font-size: 12px; }
.ability-badge .ab-bar { grid-column: 1 / 3; display: block; height: 6px; width: 104px; border-radius: 3px; background: #f3e3d3; overflow: hidden; margin-top: 2px; }
.ability-badge .ab-bar > i { display: block; height: 100%; background: linear-gradient(90deg, #ffb36b, #ff7a3d); border-radius: 3px; transition: width .3s; }
.ability-badge .ab-prog { grid-column: 1 / 3; font-size: 10px; color: #a07a5a; }
.ability-badge.max { box-shadow: 0 0 0 2px #ffd84a; }
.ability-badge.max .ab-bar > i { background: linear-gradient(90deg, #ffd84a, #ffb000); }
.ability-badge.evo .ab-ic { animation: ab-flip .7s ease-out; }
@keyframes ab-flip { 0% { transform: rotateY(0) scale(1); } 50% { transform: rotateY(180deg) scale(1.5); } 100% { transform: rotateY(360deg) scale(1); } }
.evo-banner { position: absolute; top: calc(max(10px, env(safe-area-inset-top)) + 150px); left: 50%; transform: translateX(-50%) scale(.6); z-index: 6; pointer-events: none;
  background: #fff7d6; border: 3px solid #ffc94d; border-radius: 22px; padding: 8px 18px; text-align: center; box-shadow: 0 6px 18px rgba(224,122,51,.25); opacity: 0; white-space: nowrap; }
.evo-banner b { display: block; color: #e07a33; font-size: 17px; }
.evo-banner span { font-size: 12px; color: #8a6a4a; }
.evo-banner.show { animation: evo-pop 2s ease-out forwards; }
@keyframes evo-pop { 0% { opacity: 0; transform: translateX(-50%) scale(.6); } 12% { opacity: 1; transform: translateX(-50%) scale(1.08); } 20% { transform: translateX(-50%) scale(1); } 85% { opacity: 1; } 100% { opacity: 0; transform: translateX(-50%) scale(1); } }
.skin-ability .evo-row { display: flex; justify-content: center; gap: 4px; margin: 2px 0; }
.skin-ability .evo-step { font-size: 10px; color: #a07a5a; display: inline-flex; flex-direction: column; align-items: center; min-width: 30px; }
.skin-ability .evo-step em { font-style: normal; font-size: 15px; }
.skin-ability .evo-desc { display: block; font-size: 11px; }

/* v9 技能图鉴面板（点左上角 Lv 徽章打开，暂停游戏） */
#hud #abilityBadge { pointer-events: auto; cursor: pointer; }
.ab-panel { width: min(360px, 100%); }
.ab-tabs { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; margin: 6px 0 8px; }
.ab-tab { border: 0; border-radius: 12px; padding: 5px 9px; background: #f1ece6; font: inherit; font-size: 13px; color: #6b4a35; }
.ab-tab.on { background: #ffc58f; font-weight: 700; }
.ab-tab.mine::after { content: " ★"; color: #ff8a3d; }
.ab-stages { display: flex; flex-direction: column; gap: 6px; text-align: left; margin-bottom: 10px; }
.ab-st { display: flex; gap: 8px; align-items: center; padding: 7px 9px; border-radius: 12px; background: #eaf8e4; border: 2px solid transparent; }
.ab-st .ic { font-size: 26px; width: 32px; text-align: center; }
.ab-st .tx { flex: 1; min-width: 0; }
.ab-st b { font-size: 14px; color: #5a3a2a; }
.ab-st .d { font-size: 12px; color: #7a6a5a; }
.ab-st .tag { font-size: 12px; margin-left: 4px; }
.ab-st.cur { background: #ffe9a8; border-color: #ff9a3d; }
.ab-st.lock { background: #eee; opacity: .55; }
.ab-st .bar { height: 6px; background: #d8d0c8; border-radius: 3px; margin-top: 4px; overflow: hidden; }
.ab-st .bar i { display: block; height: 100%; background: #ff9a3d; }

/* 版本号（开始页右下角，避开安全区） */
.build-tag { position: absolute; right: max(10px, env(safe-area-inset-right)); bottom: max(8px, env(safe-area-inset-bottom)); z-index: 2;
  font-size: 11px; color: #a0764f; background: rgba(255,255,255,.75); border: 2px solid #ffd9b8; border-radius: 10px; padding: 2px 8px; pointer-events: none; letter-spacing: .3px; }
/* 开始页给版本号留出底部一条，面板不会压到它 */
#startScreen { padding-bottom: calc(max(8px, env(safe-area-inset-bottom)) + 26px); }
#startScreen .build-tag { bottom: max(6px, env(safe-area-inset-bottom)); }

.audio-set { display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; align-items: center; margin-top: 12px; font-size: 14px; color: #6b4a35; text-align: left; }
.audio-set input[type=range] { width: 100%; accent-color: #ff9a3d; }
.audio-set input[type=checkbox] { accent-color: #ff9a3d; }
.build-tag small { font-size: 10px; opacity: .7; }

/* ---- v10 体验优化 ---- */
#scoreText.hud-pill { font-size: 24px; font-weight: 900; }
#rankText.hud-pill { font-size: 14px; }
#comboText { font-size: 22px; -webkit-text-stroke: 1px #fff; text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 2px 0 rgba(122, 74, 42, .35); }
#hud.steering #hudRight > * { pointer-events: none; opacity: .55; }
#hudRight .lb-hud-btn span { display: none; }
.game-set { display: grid; gap: 6px; margin-top: 10px; text-align: left; font-size: 14px; color: #6b4a35; }
.game-set label { display: flex; align-items: center; gap: 6px; }
.onboard-panel { max-width: 340px; text-align: center; }
.onboard-panel .ob-ic { font-size: 56px; line-height: 1.1; margin-top: 4px; }
.onboard-panel .ob-d { color: #6b4a35; line-height: 1.55; margin: 6px 0 10px; }
.onboard-panel .ob-dots { color: #ff9d4d; letter-spacing: 4px; margin-bottom: 10px; }
.result-gap { margin: 6px 0; font-weight: 800; color: #e0682a; }
.btn-big { font-size: 20px; padding: 14px 18px; margin: 8px 0; }
button:focus-visible, [role=button]:focus-visible, input:focus-visible { outline: 3px solid #3b82f6; outline-offset: 2px; }
body.reduce-motion * { animation-duration: .001s !important; transition-duration: .001s !important; }
#hudRight .lb-hud-btn { width: 40px; padding: 0; border-radius: 50%; }

/* ---- v11 地图 / 昼夜 ---- */
.day-pill { margin-top: 4px; font-size: 13px; font-weight: 800; }
.day-pill.night { background: rgba(40, 46, 90, .9) !important; color: #fff3b0 !important; border-color: #8c96ff !important; }
.mini-map { position: fixed; right: calc(10px + env(safe-area-inset-right)); bottom: calc(10px + env(safe-area-inset-bottom)); width: 96px; height: 96px; border-radius: 14px; border: 3px solid #ffb36b; box-shadow: 0 3px 8px rgba(0,0,0,.18); z-index: 6; cursor: pointer; background: #b8e6a0; }
.map-panel { text-align: center; }
.big-map { border-radius: 16px; border: 3px solid #ffb36b; display: block; margin: 8px auto; max-width: 100%; }
