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

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #3a2110;
  color: #4a2a16;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
}

button {
  font-family: inherit;
  -webkit-user-select: none;
  user-select: none;
}

[hidden] { display: none !important; }

.stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #ffe3b8;
  touch-action: none;
}

.stage::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 96px;
  background: linear-gradient(to bottom, rgba(91, 46, 12, 0.16), rgba(91, 46, 12, 0));
  z-index: 2;
  pointer-events: none;
}

.stage::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  box-shadow: inset 0 0 70px rgba(94, 48, 12, 0.18);
  pointer-events: none;
}

.game-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  z-index: 1;
}

/* ================= HUD ================= */
.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 6;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: calc(9px + env(safe-area-inset-top, 0px)) 15px 0;
  pointer-events: none;
}

.hud-left,
.hud-right {
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
  min-width: 0;
}

.hud-right { gap: 9px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 39px;
  padding: 0 12px 0 7px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(255, 253, 247, 0.97), rgba(255, 245, 229, 0.94));
  border: 1.5px solid rgba(255, 255, 255, 0.95);
  box-shadow:
    inset 0 1px 0 #ffffff,
    0 3px 0 rgba(210, 121, 49, 0.24),
    0 7px 16px rgba(112, 56, 16, 0.16);
  flex: 0 0 auto;
}

.chip-ico {
  width: 27px;
  height: 27px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fffdf6;
  font-size: 16px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.5),
    0 2px 4px rgba(158, 82, 22, 0.22);
}

.chip-score .chip-ico {
  background: linear-gradient(150deg, #ffc552, #ff8a3d 72%);
}

.chip-len .chip-ico {
  background: linear-gradient(150deg, #a3e874, #54be55 76%);
}

.chip-best .chip-ico {
  background: linear-gradient(150deg, #ffc06e, #f2701f 76%);
}

.chip-text {
  display: flex;
  flex-direction: column;
  line-height: 1;
  padding-top: 1px;
}

.chip-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: #aa7a52;
  transform: scale(0.96);
  transform-origin: left center;
}

.chip-value {
  margin-top: 3px;
  font-size: 16px;
  line-height: 1;
  font-weight: 900;
  color: #d9550c;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.chip-value.pop { animation: valuePop 0.3s cubic-bezier(0.2, 1.4, 0.4, 1); }

@keyframes valuePop {
  0% { transform: scale(1); }
  40% { transform: scale(1.28); }
  100% { transform: scale(1); }
}

.icon-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.95);
  background: linear-gradient(180deg, rgba(255, 253, 247, 0.97), rgba(255, 244, 226, 0.94));
  color: #e85d04;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 #ffffff,
    0 3px 0 rgba(210, 121, 49, 0.24),
    0 7px 15px rgba(112, 56, 16, 0.16);
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}

.icon-btn:active {
  transform: translateY(2px) scale(0.96);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.8),
    0 1px 0 rgba(210, 121, 49, 0.2),
    0 3px 8px rgba(112, 56, 16, 0.16);
  background: #ffe6c8;
}

.icon-btn:focus-visible,
.primary-btn:focus-visible {
  outline: 3px solid rgba(255, 255, 255, 0.9);
  outline-offset: 2px;
}

/* ================= 结算 / 开始面板 ================= */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: radial-gradient(ellipse at 50% 44%, rgba(80, 40, 12, 0.12) 0%, rgba(58, 28, 9, 0.58) 100%);
  -webkit-backdrop-filter: blur(3px) saturate(1.05);
  backdrop-filter: blur(3px) saturate(1.05);
  opacity: 1;
  visibility: visible;
  transition: opacity 0.24s ease, visibility 0s linear 0s;
}

.overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.22s ease, visibility 0s linear 0.22s;
}

.panel {
  position: relative;
  width: min(620px, 88vw);
  display: flex;
  align-items: center;
  gap: clamp(10px, 2.2vw, 22px);
  padding: clamp(14px, 2.1vw, 22px) clamp(18px, 2.6vw, 28px);
  border-radius: 28px;
  border: 3px solid rgba(255, 206, 156, 0.92);
  background:
    radial-gradient(circle at 8% 0%, rgba(255, 255, 255, 0.9), transparent 42%),
    linear-gradient(158deg, #fffdf6 0%, #fff5e3 62%, #ffe9c9 100%);
  box-shadow:
    inset 0 2px 0 #ffffff,
    inset 0 0 0 1px rgba(255, 255, 255, 0.5),
    0 26px 60px rgba(78, 37, 8, 0.42),
    0 6px 18px rgba(78, 37, 8, 0.18);
  text-align: left;
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  scrollbar-width: none;
}

.panel::-webkit-scrollbar { display: none; }

.overlay:not(.hidden) .panel {
  animation: panelIn 0.36s cubic-bezier(0.18, 1.28, 0.4, 1) both;
}

@keyframes panelIn {
  0% { opacity: 0; transform: translateY(14px) scale(0.94); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

.panel-art {
  position: relative;
  flex: 0 0 auto;
  width: clamp(104px, 16vh, 150px);
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 12px 16px rgba(133, 75, 20, 0.18));
}

.panel-art::before {
  content: "";
  position: absolute;
  inset: 8%;
  border-radius: 50%;
  background: radial-gradient(circle at 36% 30%, #fffdf3 0%, #ffeccd 58%, rgba(255, 226, 180, 0) 72%);
}

.mascot {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: block;
  animation: mascotFloat 3.6s ease-in-out infinite;
}

@keyframes mascotFloat {
  0%, 100% { transform: translateY(0) rotate(-1deg); }
  50% { transform: translateY(-5px) rotate(1.5deg); }
}

.art-dot {
  position: absolute;
  z-index: 2;
  border-radius: 50%;
  background: #ffb057;
  opacity: 0.75;
  animation: dotTwinkle 2.8s ease-in-out infinite;
}

.art-dot-a { width: 10px; height: 10px; top: 10%; right: 4%; }
.art-dot-b { width: 7px; height: 7px; bottom: 16%; left: 1%; background: #8ad66a; animation-delay: -0.9s; }
.art-dot-c { width: 5px; height: 5px; top: 36%; left: 5%; background: #ffd36b; animation-delay: -1.7s; }

@keyframes dotTwinkle {
  0%, 100% { transform: scale(0.7); opacity: 0.35; }
  50% { transform: scale(1.15); opacity: 0.85; }
}

.panel-body {
  flex: 1 1 auto;
  min-width: 0;
}

.panel-kicker {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  line-height: 1.2;
  font-weight: 800;
  letter-spacing: 0.13em;
  color: #e27a2a;
}

.kicker-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: linear-gradient(150deg, #ffc552, #ff8a3d 70%);
  box-shadow: 0 0 0 3px rgba(255, 138, 61, 0.14);
}

.panel-title {
  margin: 3px 0 0;
  font-size: clamp(26px, 5.2vh, 38px);
  line-height: 1.08;
  font-weight: 900;
  letter-spacing: 0.01em;
  color: #e85d04;
  text-shadow:
    0 1px 0 #ffffff,
    0 3px 0 #ffd9ae,
    0 6px 14px rgba(221, 108, 23, 0.18);
}

.panel-desc {
  margin: 6px 0 0;
  font-size: clamp(12px, 1.8vh, 14px);
  line-height: 1.5;
  color: #8d6646;
  font-weight: 500;
}

.panel-record {
  margin-top: 9px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 12px 0 9px;
  border-radius: 999px;
  background: #fff3dd;
  border: 1.5px solid #ffd7a6;
  color: #a9744a;
  font-size: 11.5px;
  font-weight: 700;
  box-shadow: inset 0 1px 0 #ffffff;
}

.panel-record .mp-icon {
  font-size: 16px;
  color: #f59226;
}

.panel-record b {
  margin-left: 1px;
  font-size: 16px;
  line-height: 1;
  font-weight: 900;
  color: #e85d04;
  font-variant-numeric: tabular-nums;
}

.new-record {
  margin-top: 9px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 29px;
  padding: 0 13px 0 10px;
  border-radius: 999px;
  background: linear-gradient(135deg, #ffb050, #ff8a3d 60%, #f06a16);
  color: #fffdf7;
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: 0.04em;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.45),
    0 4px 0 rgba(201, 91, 14, 0.5),
    0 8px 15px rgba(235, 108, 19, 0.28);
  animation: recordPulse 1.5s ease-in-out infinite;
}

.new-record .mp-icon { font-size: 15px; }

@keyframes recordPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.045); }
}

.panel-stats {
  display: flex;
  gap: 8px;
  margin-top: 11px;
}

.stat {
  flex: 1 1 0;
  min-width: 0;
  padding: 8px 9px 9px;
  border-radius: 14px;
  background: linear-gradient(180deg, #fff9ee, #ffefd6);
  border: 1.5px solid #ffd9ad;
  box-shadow: inset 0 1px 0 #ffffff;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.stat-label {
  font-size: 10px;
  line-height: 1;
  font-weight: 700;
  color: #aa7950;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.stat-value {
  font-size: clamp(18px, 3vh, 23px);
  line-height: 1.1;
  font-weight: 900;
  color: #e85d04;
  font-variant-numeric: tabular-nums;
}

.primary-btn {
  margin-top: 12px;
  width: 100%;
  height: clamp(46px, 12vh, 52px);
  padding: 0 18px;
  border: none;
  border-radius: 16px;
  background: linear-gradient(180deg, #ffb266 0%, #ff8a3d 52%, #f2711f 100%);
  color: #fffdf7;
  font-size: clamp(15px, 2.3vh, 18px);
  font-weight: 900;
  letter-spacing: 0.06em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  cursor: pointer;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.42),
    0 5px 0 #cf5a10,
    0 10px 20px rgba(222, 96, 15, 0.32);
  transition: transform 0.1s ease, box-shadow 0.1s ease, filter 0.1s ease;
}

.primary-btn .mp-icon { font-size: 22px; }

.primary-btn:active {
  transform: translateY(4px);
  filter: saturate(1.04);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.35),
    0 1px 0 #cf5a10,
    0 4px 10px rgba(222, 96, 15, 0.26);
}

.panel-tip {
  margin: 9px 0 0;
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10.5px;
  line-height: 1.2;
  color: #b08863;
  font-weight: 600;
}

.panel-tip .mp-icon {
  font-size: 14px;
  color: #e79a55;
}

/* 小屏横屏再紧一点 */
@media (max-height: 430px) {
  .hud { padding-top: calc(7px + env(safe-area-inset-top, 0px)); }
  .chip { height: 35px; padding-right: 10px; }
  .chip-ico { width: 24px; height: 24px; font-size: 14px; }
  .chip-value { font-size: 14.5px; margin-top: 2px; }
  .icon-btn { width: 38px; height: 38px; font-size: 18px; }
  .panel { padding: 13px 20px; gap: 12px; border-radius: 24px; }
  .panel-art { width: clamp(96px, 27vh, 126px); }
  .panel-title { font-size: clamp(24px, 7.2vh, 31px); }
  .panel-desc { margin-top: 4px; font-size: 12px; }
  .panel-record { margin-top: 7px; height: 27px; font-size: 11px; }
  .panel-record b { font-size: 14.5px; }
  .panel-stats { margin-top: 8px; gap: 7px; }
  .stat { padding: 6px 8px 7px; }
  .stat-value { font-size: 18px; }
  .primary-btn { margin-top: 9px; height: 44px; font-size: 15px; border-radius: 14px; }
  .panel-tip { margin-top: 7px; font-size: 10px; }
}

@media (max-width: 620px) {
  .hud { padding-left: 11px; padding-right: 11px; gap: 6px; }
  .hud-left { gap: 6px; }
  .chip { padding: 0 9px 0 5px; gap: 5px; height: 34px; }
  .chip-ico { width: 23px; height: 23px; font-size: 13px; }
  .chip-label { display: none; }
  .chip-value { font-size: 15px; margin-top: 0; }
  .icon-btn { width: 38px; height: 38px; font-size: 18px; }
  .panel { width: 91vw; padding: 12px 15px; gap: 9px; border-radius: 22px; }
  .panel-art { width: 92px; }
  .panel-kicker { font-size: 10px; letter-spacing: 0.08em; }
  .panel-title { font-size: 25px; }
  .panel-desc { font-size: 11.5px; line-height: 1.4; }
  .panel-record { height: 25px; font-size: 10px; margin-top: 6px; padding-right: 9px; }
  .panel-record b { font-size: 13.5px; }
  .stat { padding: 6px; }
  .stat-label { font-size: 9px; }
  .stat-value { font-size: 17px; }
  .primary-btn { height: 43px; margin-top: 8px; font-size: 15px; }
  .panel-tip { font-size: 9.5px; margin-top: 6px; }
}

@media (max-aspect-ratio: 1 / 1) {
  .overlay { padding: 20px 14px; }
  .panel {
    width: min(420px, 90vw);
    flex-direction: column;
    text-align: center;
    padding: 20px 22px 18px;
    gap: 2px;
  }
  .panel-art { width: 118px; }
  .panel-kicker { justify-content: center; }
  .panel-title { font-size: 31px; }
  .panel-desc { font-size: 13px; }
  .panel-record { margin-top: 10px; }
  .panel-stats { width: 100%; }
  .primary-btn { margin-top: 14px; }
  .panel-tip { justify-content: center; }
  .hud-left .chip-len { display: none; }
}

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