:root {
  --orange: #FF8A3D;
  --orange-deep: #F26A16;
  --orange-dark: #C9560F;
  --yellow: #FFD24D;
  --cream: #FFF6E3;
  --cream-deep: #FFE9C8;
  --brown: #5A3218;
  --brown-soft: #8B5A31;
  --ink: #3B2110;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #171008;
  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-tap-highlight-color: transparent;
}

body {
  position: fixed;
  inset: 0;
  overscroll-behavior: none;
}

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

.app-shell {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(120% 80% at 50% 12%, #48331b 0%, #261a0d 48%, #120c06 100%);
}

.game {
  position: relative;
  width: min(100vw, 560px, 62vh);
  width: min(100vw, 560px, 62dvh);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: #8ECBE8;
  box-shadow: 0 0 70px rgba(0, 0, 0, 0.6);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.world {
  position: absolute;
  inset: 0;
  z-index: 1;
  will-change: transform;
}

.world.shake-sm { animation: shakeSm 0.22s ease-out; }
.world.shake-lg { animation: shakeLg 0.3s ease-out; }

@keyframes shakeSm {
  0% { transform: translate3d(0, 0, 0); }
  20% { transform: translate3d(-2px, 2px, 0) rotate(-0.15deg); }
  45% { transform: translate3d(3px, -1px, 0) rotate(0.18deg); }
  70% { transform: translate3d(-2px, 1px, 0) rotate(-0.1deg); }
  100% { transform: translate3d(0, 0, 0); }
}

@keyframes shakeLg {
  0% { transform: translate3d(0, 0, 0); }
  18% { transform: translate3d(-5px, 3px, 0) rotate(-0.35deg) scale(1.004); }
  42% { transform: translate3d(6px, -2px, 0) rotate(0.35deg) scale(1.004); }
  66% { transform: translate3d(-4px, 2px, 0) rotate(-0.2deg); }
  100% { transform: translate3d(0, 0, 0); }
}

.scene {
  position: absolute;
  inset: 0;
  background-image: url("images/gen/bg.jpg");
  background-repeat: no-repeat;
  background-position: center bottom;
  background-size: cover;
  transform: translateZ(0);
}

.scene-tint {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(58% 34% at 22% 5%, rgba(255, 247, 204, 0.28), transparent 72%),
    linear-gradient(180deg, rgba(18, 56, 84, 0.12) 0%, rgba(18, 56, 84, 0) 26%, rgba(18, 56, 84, 0) 68%, rgba(44, 25, 5, 0.2) 100%);
  box-shadow: inset 0 0 96px rgba(24, 66, 36, 0.2);
}

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

/* ---------- HUD ---------- */

.hud {
  position: absolute;
  z-index: 20;
  left: 11px;
  right: 11px;
  top: calc(var(--safe-top) + 8px);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: start;
  pointer-events: none;
  animation: hudIn 0.55s cubic-bezier(0.2, 0.9, 0.3, 1.12) both;
}

@keyframes hudIn {
  from { opacity: 0; transform: translateY(-18px); }
  to { opacity: 1; transform: translateY(0); }
}

.hud-side {
  display: flex;
  flex-direction: column;
  gap: 7px;
  align-items: flex-start;
}

.hud-right { align-items: flex-end; }

.icon-btn {
  pointer-events: auto;
  width: 43px;
  height: 43px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  color: #FF7A1A;
  background: linear-gradient(180deg, #FFFCF3 0%, #FFEAC9 100%);
  border: 2px solid rgba(255, 249, 235, 0.96);
  box-shadow: 0 4px 0 rgba(146, 81, 28, 0.34), 0 7px 14px rgba(78, 39, 0, 0.2);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.icon-btn .mp-icon { width: 23px; height: 23px; }

.icon-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(146, 81, 28, 0.34), 0 3px 7px rgba(78, 39, 0, 0.16);
}

.score-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  height: 27px;
  padding: 0 10px 0 7px;
  border-radius: 999px;
  color: #FFF7E7;
  font-size: 13px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  background: rgba(55, 29, 8, 0.58);
  border: 1.5px solid rgba(255, 240, 210, 0.5);
  box-shadow: 0 3px 8px rgba(40, 20, 0, 0.18);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.score-chip .score-star {
  width: 14px;
  height: 14px;
  color: var(--yellow);
  filter: drop-shadow(0 1px 0 rgba(96, 48, 0, 0.35));
}

.score-chip b { line-height: 1; }
.score-chip.pop { animation: scorePop 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.4); }

@keyframes scorePop {
  0% { transform: scale(1); }
  45% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

.hud-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding-top: 1px;
  min-width: 0;
}

.level-pill {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 36px;
  padding: 0 17px;
  border-radius: 999px;
  color: #FFFFFF;
  font-size: 16px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0.02em;
  white-space: nowrap;
  background: linear-gradient(180deg, #FFB45F 0%, #FF8A3D 52%, #F26A16 100%);
  border: 2px solid rgba(255, 248, 232, 0.96);
  box-shadow: 0 4px 0 var(--orange-dark), 0 7px 14px rgba(112, 51, 0, 0.26), inset 0 2px 0 rgba(255, 255, 255, 0.35);
  text-shadow: 0 1.5px 0 rgba(145, 62, 0, 0.42);
  transform-origin: 50% 60%;
}

.level-pill b {
  font-size: 20px;
  font-weight: 900;
  margin: 0 1px;
  font-variant-numeric: tabular-nums;
}

.level-pill.pop { animation: levelPop 0.42s cubic-bezier(0.2, 0.9, 0.3, 1.35); }

@keyframes levelPop {
  0% { transform: scale(0.86); }
  55% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

.progress {
  position: relative;
  width: 100%;
  max-width: 208px;
  height: 12px;
  margin-right: 6px;
  border-radius: 999px;
  background: rgba(45, 57, 62, 0.42);
  border: 2px solid rgba(255, 246, 227, 0.95);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.28), 0 2px 6px rgba(0, 0, 0, 0.14);
}

.progress-fill {
  position: absolute;
  left: -2px;
  top: -2px;
  bottom: -2px;
  width: 0;
  min-width: 4px;
  border-radius: 999px;
  background: linear-gradient(90deg, #FFE983 0%, #FFC24D 48%, #FF8A3D 100%);
  border: 2px solid rgba(255, 244, 213, 0.96);
  box-shadow: 0 0 10px rgba(255, 193, 66, 0.7);
  transition: width 0.32s cubic-bezier(0.2, 0.8, 0.3, 1.1);
}

.progress-star {
  position: absolute;
  right: -10px;
  top: 50%;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  transform: translateY(-50%) rotate(9deg);
  color: var(--yellow);
  filter: drop-shadow(0 2px 1px rgba(93, 48, 0, 0.45));
}

.progress-star .mp-icon { width: 21px; height: 21px; }

.target-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 43px;
  padding: 3px 12px 3px 4px;
  border-radius: 16px;
  background: linear-gradient(180deg, #FFFCEE 0%, #FFE9C8 100%);
  border: 2px solid rgba(255, 249, 235, 0.96);
  box-shadow: 0 4px 0 rgba(146, 81, 28, 0.3), 0 7px 14px rgba(78, 39, 0, 0.18);
}

.target-chip img {
  width: 34px;
  height: 34px;
  object-fit: contain;
  filter: drop-shadow(0 2px 1px rgba(70, 30, 0, 0.18));
}

.target-num {
  display: inline-flex;
  align-items: baseline;
  gap: 1px;
  color: var(--brown);
  font-size: 15px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.target-num b { color: #F26A16; font-size: 18px; }
.target-num em { font-style: normal; color: #B98A5D; font-size: 13px; margin: 0 1px; }

/* ---------- In-scene controls ---------- */

.hint {
  position: absolute;
  z-index: 15;
  left: 50%;
  top: 51.5%;
  transform: translate(-50%, -50%);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: calc(100% - 26px);
  padding: 8px 14px;
  border-radius: 999px;
  color: #FFF8E9;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  background: rgba(58, 32, 11, 0.66);
  border: 1px solid rgba(255, 241, 212, 0.42);
  box-shadow: 0 5px 14px rgba(44, 22, 0, 0.22);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  pointer-events: none;
  opacity: 0;
  animation: hintIn 0.55s 0.9s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
  transition: opacity 0.4s ease, transform 0.4s ease;
}

@keyframes hintIn {
  from { opacity: 0; transform: translate(-50%, -42%); }
  to { opacity: 1; transform: translate(-50%, -50%); }
}

.hint.hide {
  opacity: 0;
  transform: translate(-50%, -58%);
  animation: none;
}

.hint .mp-icon {
  width: 17px;
  height: 17px;
  color: #FFD46B;
  flex: none;
}

.ammo-chip {
  position: absolute;
  z-index: 15;
  left: 14px;
  bottom: calc(var(--safe-bottom) + 14px);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px 0 9px;
  border-radius: 999px;
  color: #FFF4DE;
  font-size: 12px;
  font-weight: 700;
  background: rgba(55, 29, 8, 0.62);
  border: 1.5px solid rgba(255, 240, 210, 0.38);
  box-shadow: 0 4px 12px rgba(40, 20, 0, 0.22);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  pointer-events: none;
}

.ammo-chip b { color: #FFFFFF; font-size: 14px; font-weight: 900; font-variant-numeric: tabular-nums; }
.ammo-chip .ammo-label { color: #FFDDAE; font-weight: 600; }

.stone-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 28%, #FBF8F0 0%, #D3CDC1 34%, #9B958A 62%, #625C53 100%);
  border: 1px solid rgba(255, 255, 255, 0.55);
  box-shadow: inset -2px -2px 3px rgba(0, 0, 0, 0.32), 0 1px 2px rgba(0, 0, 0, 0.25);
}

.ammo-chip.low {
  border-color: rgba(255, 157, 120, 0.7);
  animation: lowPulse 1s ease-in-out infinite;
}

@keyframes lowPulse {
  0%, 100% { box-shadow: 0 4px 12px rgba(40, 20, 0, 0.22); }
  50% { box-shadow: 0 0 0 4px rgba(255, 122, 61, 0.2), 0 4px 12px rgba(40, 20, 0, 0.22); }
}

.sound-btn {
  position: absolute;
  z-index: 16;
  right: 14px;
  bottom: calc(var(--safe-bottom) + 14px);
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #7A4A22;
  background: rgba(255, 246, 227, 0.9);
  border: 2px solid rgba(255, 250, 238, 0.88);
  box-shadow: 0 3px 0 rgba(146, 81, 28, 0.25), 0 5px 10px rgba(55, 26, 0, 0.2);
  pointer-events: auto;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.sound-btn .mp-icon { width: 18px; height: 18px; }
.sound-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(146, 81, 28, 0.25); }

/* ---------- Overlay / panel ---------- */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 26px 18px calc(26px + var(--safe-bottom));
  background:
    radial-gradient(90% 60% at 50% 42%, rgba(72, 39, 11, 0.34), rgba(31, 15, 3, 0.72));
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.24s ease, visibility 0.24s ease;
}

.overlay.show {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.confetti {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  pointer-events: none;
}

.confetti-piece {
  position: absolute;
  top: -24px;
  border-radius: 2px;
  animation-name: confettiFall;
  animation-timing-function: cubic-bezier(0.16, 0.6, 0.5, 1);
  animation-fill-mode: forwards;
}

@keyframes confettiFall {
  0% { transform: translate3d(0, 0, 0) rotate(0deg); opacity: 1; }
  85% { opacity: 1; }
  100% { transform: translate3d(var(--x, 0px), 108vh, 0) rotate(var(--r, 540deg)); opacity: 0.15; }
}

.panel {
  position: relative;
  z-index: 2;
  width: min(100%, 340px);
  padding: 36px 20px 20px;
  border-radius: 26px;
  text-align: center;
  background: linear-gradient(180deg, #FFFDF4 0%, #FFEFD3 100%);
  border: 3px solid rgba(255, 250, 238, 0.98);
  box-shadow:
    0 26px 60px rgba(36, 16, 0, 0.46),
    0 2px 0 rgba(255, 255, 255, 0.95) inset,
    0 -5px 0 rgba(208, 137, 68, 0.14) inset;
  transform: translateY(18px) scale(0.93);
  opacity: 0;
  transition: transform 0.38s cubic-bezier(0.2, 0.9, 0.3, 1.24), opacity 0.26s ease;
}

.overlay.show .panel {
  transform: translateY(0) scale(1);
  opacity: 1;
}

.panel-badge {
  position: absolute;
  top: -31px;
  left: 50%;
  width: 62px;
  height: 62px;
  transform: translateX(-50%);
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #FFFFFF;
  background: linear-gradient(180deg, #FFB45F 0%, #FF8A3D 50%, #F26A16 100%);
  border: 4px solid #FFF9EA;
  box-shadow: 0 8px 18px rgba(140, 60, 0, 0.34), inset 0 2px 0 rgba(255, 255, 255, 0.4);
}

.panel-badge .mp-icon {
  width: 30px;
  height: 30px;
  filter: drop-shadow(0 1.5px 0 rgba(140, 60, 0, 0.35));
}

.panel-title {
  margin: 0 0 6px;
  color: var(--brown);
  font-size: 23px;
  font-weight: 900;
  letter-spacing: 0.01em;
  line-height: 1.22;
  text-shadow: 0 1px 0 #FFFFFF;
}

.panel-sub {
  margin: 0;
  color: #9A6A3C;
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.5;
}

.stats {
  display: flex;
  margin: 18px 0 19px;
  padding: 12px 0;
  border-top: 1px dashed rgba(180, 120, 60, 0.3);
  border-bottom: 1px dashed rgba(180, 120, 60, 0.3);
}

.stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.stat + .stat { border-left: 1px dashed rgba(180, 120, 60, 0.3); }

.stat span {
  color: #A77A4C;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.stat b {
  color: var(--orange-deep);
  font-size: 23px;
  font-weight: 900;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  pointer-events: auto;
}

.btn-primary {
  height: 52px;
  border-radius: 16px;
  color: #FFFFFF;
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 0.03em;
  background: linear-gradient(180deg, #FFB45F 0%, #FF8A3D 52%, #F26A16 100%);
  border: 2px solid rgba(255, 245, 222, 0.96);
  box-shadow: 0 5px 0 var(--orange-dark), 0 10px 18px rgba(160, 70, 0, 0.28), inset 0 2px 0 rgba(255, 255, 255, 0.4);
  text-shadow: 0 1.5px 0 rgba(145, 62, 0, 0.4);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.btn-primary .mp-icon { width: 21px; height: 21px; }
.btn-primary:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--orange-dark), 0 4px 8px rgba(160, 70, 0, 0.22); }

.btn-ghost {
  height: 40px;
  margin-top: 8px;
  color: #8B5A31;
  font-size: 13px;
  font-weight: 700;
  background: transparent;
  border-radius: 12px;
}

.btn-ghost .mp-icon { width: 17px; height: 17px; }
.btn-ghost:active { background: rgba(214, 156, 92, 0.14); }
.btn.is-hidden { display: none; }

/* ---------- Small screens ---------- */

@media (max-width: 350px) {
  .hud { left: 8px; right: 8px; gap: 6px; }
  .icon-btn { width: 39px; height: 39px; border-radius: 12px; }
  .icon-btn .mp-icon { width: 21px; height: 21px; }
  .level-pill { height: 33px; padding: 0 13px; font-size: 14px; }
  .level-pill b { font-size: 18px; }
  .target-chip { height: 39px; padding-right: 9px; }
  .target-chip img { width: 30px; height: 30px; }
  .target-num { font-size: 13px; }
  .target-num b { font-size: 16px; }
  .score-chip { height: 24px; font-size: 12px; padding: 0 8px 0 6px; }
  .hint { font-size: 11.5px; padding: 7px 11px; }
  .ammo-chip { left: 10px; height: 31px; font-size: 11px; }
  .sound-btn { right: 10px; width: 33px; height: 33px; }
  .panel-title { font-size: 21px; }
}

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