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

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: #071018;
  color: #FFF4E6;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  isolation: isolate;
}

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

.screen-fx {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  background:
    radial-gradient(120% 80% at 50% 46%, rgba(0, 0, 0, 0) 52%, rgba(3, 8, 12, 0.55) 100%),
    linear-gradient(180deg, rgba(3, 8, 12, 0.34) 0%, rgba(3, 8, 12, 0) 16%, rgba(3, 8, 12, 0) 74%, rgba(3, 8, 12, 0.42) 100%);
}

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

.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 12;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 0;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.28s ease, transform 0.28s ease;
}

body[data-state="playing"] .hud,
body[data-state="paused"] .hud,
body[data-state="dying"] .hud,
body[data-state="over"] .hud,
body[data-state="win"] .hud {
  opacity: 1;
  transform: translateY(0);
}

.hud-main {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hud-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 38px;
  padding: 0 12px;
  border-radius: 13px;
  background: rgba(7, 15, 21, 0.58);
  border: 1px solid rgba(255, 183, 122, 0.16);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.24), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.hud-label {
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: rgba(255, 210, 172, 0.58);
}

.hearts {
  display: flex;
  gap: 2px;
  align-items: center;
}

.hearts .mp-icon {
  width: 19px;
  height: 19px;
  color: #FF6D4A;
  filter: drop-shadow(0 0 6px rgba(255, 86, 54, 0.55));
  transition: color 0.16s ease, opacity 0.16s ease, transform 0.16s ease;
}

.hearts .mp-icon.empty {
  color: rgba(255, 255, 255, 0.14);
  filter: none;
  transform: scale(0.86);
}

.score {
  margin-left: auto;
  gap: 8px;
  min-width: 84px;
  justify-content: flex-end;
}

.score strong {
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: #FFE7CE;
  text-shadow: 0 0 14px rgba(255, 138, 61, 0.45);
  font-variant-numeric: tabular-nums;
}

.pause-btn {
  width: 38px;
  height: 38px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 13px;
  border: 1px solid rgba(255, 183, 122, 0.18);
  background: rgba(7, 15, 21, 0.58);
  color: #FFD9B8;
  padding: 0;
  pointer-events: auto;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.24), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  transition: transform 0.12s ease, background 0.12s ease;
}

.pause-btn .mp-icon { width: 20px; height: 20px; }
.pause-btn:active { transform: scale(0.9); background: rgba(255, 138, 61, 0.22); }

.stage-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 8px;
  padding: 0 3px;
}

.stage-tag {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: rgba(255, 213, 179, 0.68);
  white-space: nowrap;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

.progress-track {
  position: relative;
  flex: 1;
  height: 4px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.14);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.5);
  overflow: visible;
}

.progress-fill {
  position: absolute;
  inset: 0;
  border-radius: 99px;
  background: linear-gradient(90deg, #FFB066, #FF7A2F);
  transform-origin: left center;
  transform: scaleX(0);
  box-shadow: 0 0 10px rgba(255, 126, 47, 0.65);
}

.progress-head {
  position: absolute;
  top: 50%;
  left: 0;
  width: 8px;
  height: 8px;
  margin: -4px 0 0 -4px;
  border-radius: 50%;
  background: #FFF1DE;
  border: 1.5px solid #FF7A2F;
  box-shadow: 0 0 8px rgba(255, 138, 61, 0.9);
  transition: left 0.08s linear;
}

.stage-pct {
  width: 32px;
  text-align: right;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 9px;
  font-weight: 700;
  color: rgba(255, 222, 192, 0.72);
  font-variant-numeric: tabular-nums;
}

/* ---------------- In-game touch controls ---------------- */

.controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  z-index: 14;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 0 18px;
  pointer-events: none;
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.24s ease, transform 0.24s ease;
}

body[data-state="playing"] .controls,
body[data-state="dying"] .controls {
  opacity: 1;
  transform: translateY(0);
}

.move-group {
  display: flex;
  gap: 10px;
  pointer-events: none;
}

.action-group {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  pointer-events: none;
}

.pad-btn,
.action-btn {
  position: relative;
  border: 0;
  margin: 0;
  padding: 0;
  display: grid;
  place-items: center;
  color: #FFE9D4;
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  background:
    linear-gradient(180deg, rgba(37, 55, 62, 0.72), rgba(10, 19, 25, 0.84));
  border: 1px solid rgba(255, 176, 112, 0.34);
  box-shadow:
    0 10px 24px rgba(0, 0, 0, 0.36),
    inset 0 1px 0 rgba(255, 255, 255, 0.14),
    inset 0 -8px 18px rgba(0, 0, 0, 0.24);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  transition: transform 0.08s ease, filter 0.08s ease, background 0.08s ease;
}

.pad-btn {
  width: 64px;
  height: 64px;
  border-radius: 20px;
}

.pad-btn .mp-icon {
  width: 32px;
  height: 32px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.4));
}

.action-btn {
  border-radius: 50%;
  flex-direction: column;
  gap: 1px;
}

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

.action-btn span {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: rgba(255, 238, 220, 0.86);
  margin-top: -1px;
}

.action-btn.jump {
  width: 62px;
  height: 62px;
  background: linear-gradient(180deg, rgba(52, 75, 70, 0.8), rgba(13, 26, 28, 0.9));
  border-color: rgba(186, 255, 190, 0.28);
}

.action-btn.fire {
  width: 82px;
  height: 82px;
  background:
    radial-gradient(circle at 50% 32%, #FFC078 0%, #FF8A3D 46%, #E85F1E 100%);
  border: 1px solid rgba(255, 226, 188, 0.7);
  color: #35170A;
  box-shadow:
    0 12px 30px rgba(255, 103, 35, 0.34),
    0 0 0 7px rgba(255, 138, 61, 0.10),
    inset 0 2px 0 rgba(255, 255, 255, 0.42),
    inset 0 -10px 18px rgba(166, 56, 7, 0.32);
}

.action-btn.fire .mp-icon {
  width: 34px;
  height: 34px;
  color: #33180B;
  filter: drop-shadow(0 1px 0 rgba(255, 255, 255, 0.3));
}

.action-btn.fire span { color: #3A1A08; }

.pad-btn.is-down,
.action-btn.is-down {
  transform: scale(0.91);
  filter: brightness(1.18);
}

.pad-btn.is-down {
  background: linear-gradient(180deg, rgba(255, 150, 82, 0.52), rgba(80, 38, 16, 0.82));
  border-color: rgba(255, 196, 140, 0.75);
}

.action-btn.fire.is-down {
  box-shadow:
    0 6px 18px rgba(255, 103, 35, 0.3),
    0 0 0 3px rgba(255, 180, 110, 0.18),
    inset 0 2px 0 rgba(255, 255, 255, 0.4);
}

/* ---------------- Screens ---------------- */

.screen {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

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

.title-screen {
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 50px) 22px calc(env(safe-area-inset-bottom, 0px) + 22px);
  background:
    linear-gradient(180deg, rgba(4, 10, 15, 0.9) 0%, rgba(4, 10, 15, 0.5) 26%, rgba(4, 10, 15, 0.06) 47%, rgba(4, 10, 15, 0.18) 58%, rgba(4, 10, 15, 0.86) 78%, rgba(4, 10, 15, 0.97) 100%);
}

.title-head {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 28px;
  padding: 0 12px;
  border-radius: 99px;
  background: rgba(255, 138, 61, 0.12);
  border: 1px solid rgba(255, 170, 102, 0.3);
  color: #FFD2A8;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.eyebrow-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #FF8A3D;
  box-shadow: 0 0 8px #FF8A3D;
  animation: dotPulse 1.8s ease-in-out infinite;
}

@keyframes dotPulse {
  0%, 100% { opacity: 0.55; transform: scale(0.85); }
  50% { opacity: 1; transform: scale(1.15); }
}

.game-title {
  margin: 16px 0 0;
  font-family: Impact, "Arial Black", "PingFang SC", "Noto Sans SC", sans-serif;
  font-size: clamp(60px, 18vw, 92px);
  line-height: 0.94;
  font-weight: 900;
  letter-spacing: 0.03em;
  transform: skewX(-5deg);
  background: linear-gradient(180deg, #FFF6E6 4%, #FFD08C 44%, #FF8A3D 72%, #E8581C 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 3px 0 rgba(90, 31, 4, 0.55)) drop-shadow(0 10px 28px rgba(255, 110, 40, 0.42));
}

.game-sub {
  margin-top: 8px;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.62em;
  color: rgba(255, 196, 143, 0.7);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.7);
}

.tagline {
  margin: 14px 0 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.16em;
  color: rgba(255, 235, 216, 0.86);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.7);
}

.mission-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-top: 16px;
  padding: 8px 12px;
  border-radius: 11px;
  background: rgba(8, 16, 22, 0.52);
  border: 1px solid rgba(255, 180, 122, 0.16);
  color: rgba(255, 226, 200, 0.8);
  font-size: 11px;
  letter-spacing: 0.04em;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.mission-chip .mp-icon {
  width: 15px;
  height: 15px;
  color: #FF9A55;
}

.title-foot {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
}

.brief-card {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 13px 10px;
  border-radius: 20px;
  background: rgba(9, 18, 24, 0.66);
  border: 1px solid rgba(255, 176, 112, 0.17);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  margin-bottom: 12px;
}

.brief {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
}

.key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 1px;
  height: 30px;
  min-width: 48px;
  padding: 0 8px;
  border-radius: 9px;
  background: rgba(255, 138, 61, 0.12);
  border: 1px solid rgba(255, 170, 102, 0.22);
  color: #FFBE86;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07);
}

.key .mp-icon { width: 18px; height: 18px; }
.key.fire-key { background: rgba(255, 138, 61, 0.2); border-color: rgba(255, 170, 102, 0.44); }
.key.fire-key .mp-icon { color: #FFA45F; }

.brief b {
  font-size: 12px;
  font-weight: 800;
  color: #FFEBD9;
  letter-spacing: 0.06em;
}

.brief small {
  font-size: 9px;
  color: rgba(255, 219, 188, 0.52);
  letter-spacing: 0.05em;
}

.primary-btn {
  width: 100%;
  height: 56px;
  border: 0;
  border-radius: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 0 18px;
  cursor: pointer;
  font-family: inherit;
  font-size: 17px;
  font-weight: 900;
  letter-spacing: 0.16em;
  color: #2C1204;
  background: linear-gradient(180deg, #FFC079 0%, #FF9A4D 46%, #FF7228 100%);
  box-shadow:
    0 12px 28px rgba(255, 100, 34, 0.4),
    0 2px 0 rgba(255, 222, 180, 0.7) inset,
    0 -8px 16px rgba(163, 53, 6, 0.26) inset;
  touch-action: manipulation;
  transition: transform 0.1s ease, filter 0.1s ease;
}

.primary-btn .mp-icon { width: 24px; height: 24px; color: #2C1204; }
.primary-btn:active { transform: scale(0.972); filter: brightness(1.06); }
.primary-btn:disabled { opacity: 0.6; }

.best-line {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 11px;
  font-size: 10px;
  letter-spacing: 0.06em;
  color: rgba(255, 221, 190, 0.5);
}

.best-line b {
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  color: #FFC48E;
  font-size: 11px;
}

.dot-sep { opacity: 0.45; }

/* Result / pause */

.result-screen,
.pause-screen {
  align-items: center;
  justify-content: center;
  padding: calc(env(safe-area-inset-top, 0px) + 24px) 20px calc(env(safe-area-inset-bottom, 0px) + 24px);
  background: rgba(3, 8, 12, 0.72);
  -webkit-backdrop-filter: blur(7px);
  backdrop-filter: blur(7px);
}

.result-card,
.pause-card {
  position: relative;
  width: min(100%, 400px);
  padding: 28px 22px 22px;
  border-radius: 26px;
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(255, 138, 61, 0.15), rgba(255, 138, 61, 0) 55%),
    linear-gradient(180deg, rgba(24, 31, 34, 0.97), rgba(10, 16, 20, 0.98));
  border: 1px solid rgba(255, 179, 116, 0.22);
  box-shadow:
    0 30px 70px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  transform: translateY(14px) scale(0.97);
  opacity: 0;
  transition: transform 0.32s cubic-bezier(0.2, 0.9, 0.3, 1.15), opacity 0.25s ease;
}

.screen.show .result-card,
.screen.show .pause-card {
  transform: translateY(0) scale(1);
  opacity: 1;
}

.result-kicker {
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.28em;
  color: rgba(255, 170, 102, 0.72);
  text-align: center;
}

.result-card h2,
.pause-card h2 {
  margin: 8px 0 0;
  text-align: center;
  font-size: 28px;
  font-weight: 900;
  letter-spacing: 0.05em;
  color: #FFF1E0;
  text-shadow: 0 3px 18px rgba(255, 115, 45, 0.25);
}

.result-card > p,
.pause-card > p {
  margin: 8px 0 0;
  text-align: center;
  font-size: 12px;
  line-height: 1.6;
  color: rgba(255, 226, 200, 0.55);
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin: 20px 0 0;
  padding: 14px 0;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(255, 255, 255, 0.055);
}

.stat {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.stat + .stat::before {
  content: "";
  position: absolute;
  left: 0;
  top: 12%;
  height: 76%;
  width: 1px;
  background: rgba(255, 255, 255, 0.08);
}

.stat span {
  font-size: 10px;
  letter-spacing: 0.12em;
  color: rgba(255, 220, 190, 0.48);
}

.stat b {
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 21px;
  font-weight: 800;
  color: #FFD6A9;
  font-variant-numeric: tabular-nums;
}

.record-line {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 13px 0 18px;
  font-size: 11px;
  color: rgba(255, 220, 190, 0.52);
}

.record-line b {
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  color: #FFBE86;
  font-size: 13px;
}

.new-record {
  display: none;
  margin-left: 4px;
  padding: 2px 7px;
  border-radius: 99px;
  background: rgba(255, 138, 61, 0.18);
  border: 1px solid rgba(255, 170, 102, 0.35);
  color: #FFC38E;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.new-record.show { display: inline-block; }

.ghost-btn {
  width: 100%;
  height: 46px;
  margin-top: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  background: rgba(255, 255, 255, 0.025);
  color: rgba(255, 232, 214, 0.82);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.1s ease, background 0.1s ease;
}

.ghost-btn .mp-icon { width: 18px; height: 18px; }
.ghost-btn:active { transform: scale(0.98); background: rgba(255, 138, 61, 0.12); }

.sound-btn {
  width: 100%;
  height: 42px;
  margin-top: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: rgba(255, 220, 190, 0.48);
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  cursor: pointer;
  touch-action: manipulation;
}

.sound-btn .mp-icon { width: 17px; height: 17px; }
.sound-btn:active { color: #FFC38E; }

.pause-card .primary-btn { margin-top: 20px; }
.pause-card h2 { margin-bottom: 2px; }

/* ---------------- Toast ---------------- */

.toast {
  position: absolute;
  left: 50%;
  top: calc(env(safe-area-inset-top, 0px) + 92px);
  z-index: 16;
  max-width: 82vw;
  padding: 9px 15px;
  border-radius: 99px;
  background: rgba(8, 16, 22, 0.82);
  border: 1px solid rgba(255, 180, 122, 0.25);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.4);
  color: #FFE4C8;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -8px);
  transition: opacity 0.22s ease, transform 0.22s ease;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------------- Responsive ---------------- */

@media (max-height: 720px) {
  .title-screen {
    padding-top: calc(env(safe-area-inset-top, 0px) + 28px);
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 14px);
  }
  .game-title { font-size: clamp(50px, 15vw, 70px); margin-top: 10px; }
  .tagline { margin-top: 9px; font-size: 12px; }
  .mission-chip { margin-top: 10px; padding: 6px 10px; font-size: 10px; }
  .brief-card { padding: 10px 8px; margin-bottom: 9px; }
  .primary-btn { height: 50px; font-size: 16px; }
  .best-line { margin-top: 7px; font-size: 9px; }
  .pad-btn { width: 58px; height: 58px; border-radius: 18px; }
  .action-btn.jump { width: 56px; height: 56px; }
  .action-btn.fire { width: 74px; height: 74px; }
  .action-btn .mp-icon { width: 27px; height: 27px; }
  .controls { bottom: calc(env(safe-area-inset-bottom, 0px) + 12px); }
}

@media (max-height: 620px) {
  .game-sub, .mission-chip { display: none; }
  .tagline { margin-top: 7px; }
  .brief-card { display: none; }
  .game-title { font-size: clamp(46px, 13vw, 60px); }
}

@media (min-width: 700px) {
  .title-head, .title-foot { max-width: 460px; }
  .hud { padding-left: max(16px, calc((100vw - 560px) / 2)); padding-right: max(16px, calc((100vw - 560px) / 2)); }
  .controls { padding-left: max(24px, calc((100vw - 620px) / 2)); padding-right: max(24px, calc((100vw - 620px) / 2)); }
}

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