:root {
  --bg: #0B0714;
  --ink: #FFF3E4;
  --ink-dim: #CBB6C6;
  --muted: #9B859C;
  --orange: #FF8A3D;
  --orange-deep: #D95A18;
  --orange-soft: #FFB36E;
  --panel: rgba(30, 20, 36, 0.86);
  --panel-2: rgba(22, 14, 28, 0.94);
  --line: rgba(255, 176, 120, 0.18);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

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

/* ---------- atmosphere ---------- */

.vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  background:
    linear-gradient(180deg, rgba(4, 3, 10, 0.46) 0%, rgba(4, 3, 10, 0) 18%, rgba(4, 3, 10, 0) 72%, rgba(4, 3, 10, 0.5) 100%),
    radial-gradient(120% 78% at 50% 42%, rgba(0, 0, 0, 0) 52%, rgba(3, 2, 8, 0.66) 100%);
}

.danger-flash {
  position: fixed;
  inset: 0;
  z-index: 8;
  pointer-events: none;
  opacity: 0;
  background:
    radial-gradient(110% 80% at 50% 100%, rgba(255, 62, 32, 0.5), rgba(255, 62, 32, 0) 62%),
    linear-gradient(180deg, rgba(255, 40, 20, 0.16), rgba(255, 40, 20, 0.02));
  transition: opacity 0.12s linear;
}
.danger-flash.on { opacity: 1; transition: none; }

/* ---------- hud ---------- */

.hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: calc(var(--safe-top) + 14px) 16px 0;
  pointer-events: none;
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.hud.is-hidden { opacity: 0; transform: translateY(-10px); }
.hud-col { display: flex; flex-direction: column; align-items: flex-start; gap: 7px; }
.hud-right { align-items: flex-end; }

.stat {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 40px;
  padding: 7px 12px 7px 10px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(46, 30, 52, 0.78), rgba(18, 11, 24, 0.82));
  border: 1px solid rgba(255, 175, 118, 0.2);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
.stat .mp-icon { width: 17px; height: 17px; color: var(--orange); }
.stat-label { font-size: 11px; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; }
.stat b {
  font-size: 20px;
  line-height: 1;
  font-weight: 900;
  letter-spacing: -0.02em;
  color: #FFF7EE;
  font-variant-numeric: tabular-nums;
}
.stat.score b { min-width: 22px; }
.stat.wave { padding-left: 11px; }
.stat.wave span { font-size: 11px; color: var(--muted); font-weight: 700; }
.stat.wave b { font-size: 19px; color: var(--orange-soft); }

.best-line {
  padding-left: 3px;
  font-size: 11px;
  color: rgba(219, 196, 208, 0.62);
  letter-spacing: 0.04em;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}
.best-line b { color: rgba(255, 202, 152, 0.9); font-weight: 800; }

.hp-row { display: flex; align-items: center; gap: 2px; padding-right: 2px; }
.hp-row .mp-icon {
  width: 18px;
  height: 18px;
  color: var(--orange);
  filter: drop-shadow(0 1px 4px rgba(255, 120, 40, 0.5));
  transition: color 0.16s ease, transform 0.16s ease, opacity 0.16s ease;
}
.hp-row .mp-icon.off { color: rgba(150, 128, 145, 0.28); filter: none; transform: scale(0.86); }
.hp-row.hp-hit { animation: hpShake 0.34s ease; }

@keyframes hpShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  45% { transform: translateX(4px); }
  70% { transform: translateX(-2px); }
}

.score-pop { animation: scorePop 0.3s cubic-bezier(0.2, 1.5, 0.4, 1); }
@keyframes scorePop {
  0% { transform: scale(1); }
  40% { transform: scale(1.16); color: #FFF0B8; }
  100% { transform: scale(1); }
}

/* ---------- wave banner ---------- */

.banner {
  position: fixed;
  top: 23%;
  left: 0;
  right: 0;
  z-index: 12;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  opacity: 0;
  transform: translateY(12px) scale(0.96);
}
.banner.show { animation: bannerIn 1.9s cubic-bezier(0.22, 1, 0.3, 1) forwards; }
.banner b {
  font-size: clamp(30px, 9vw, 42px);
  line-height: 1;
  font-weight: 900;
  letter-spacing: -0.03em;
  color: #FFF6E8;
  text-shadow: 0 3px 0 #A23E0F, 0 0 26px rgba(255, 130, 50, 0.7), 0 10px 30px rgba(0, 0, 0, 0.6);
}
.banner span {
  font-size: 12px;
  letter-spacing: 0.14em;
  color: #FFC79A;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.9);
}
@keyframes bannerIn {
  0% { opacity: 0; transform: translateY(18px) scale(0.9); }
  16% { opacity: 1; transform: translateY(0) scale(1.02); }
  26% { transform: translateY(0) scale(1); }
  78% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-14px) scale(1); }
}

/* ---------- hint ---------- */

.hint {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 18px);
  z-index: 11;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 13px;
  border-radius: 999px;
  background: rgba(16, 10, 22, 0.66);
  border: 1px solid rgba(255, 178, 120, 0.14);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: rgba(255, 226, 202, 0.82);
  font-size: 11.5px;
  letter-spacing: 0.03em;
  opacity: 0;
  transform: translate(-50%, 8px);
  pointer-events: none;
  transition: opacity 0.5s ease, transform 0.5s ease;
  white-space: nowrap;
}
.hint .mp-icon { width: 14px; height: 14px; color: var(--orange); }
.hint.show { opacity: 1; transform: translate(-50%, 0); }
.hint.gone { opacity: 0; transform: translate(-50%, 6px); }

/* ---------- overlays ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-top) + 26px) 16px calc(var(--safe-bottom) + 20px);
}
.is-hidden { display: none !important; }

.start-screen {
  justify-content: space-between;
  gap: 16px;
  background:
    linear-gradient(180deg,
      rgba(8, 5, 16, 0.42) 0%,
      rgba(8, 5, 16, 0) 18%,
      rgba(8, 5, 16, 0) 48%,
      rgba(8, 5, 16, 0.26) 66%,
      rgba(8, 5, 16, 0.66) 84%,
      rgba(8, 5, 16, 0.9) 100%);
}

.hero {
  margin-top: clamp(14px, 5vh, 54px);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  animation: heroIn 0.7s cubic-bezier(0.2, 1, 0.3, 1) both;
}
@keyframes heroIn {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.kicker {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 11px 6px 9px;
  border-radius: 999px;
  background: rgba(255, 138, 61, 0.13);
  border: 1px solid rgba(255, 160, 95, 0.32);
  color: #FFC79C;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.24);
}
.kicker .mp-icon { width: 15px; height: 15px; color: var(--orange); }
.kicker.danger {
  margin: 12px auto 0;
  color: #FFB08A;
  background: rgba(255, 74, 44, 0.13);
  border-color: rgba(255, 110, 70, 0.4);
}
.kicker.danger .mp-icon { color: #FF6B45; }

.game-title {
  position: relative;
  margin: 14px 0 0;
  font-size: clamp(44px, 13.6vw, 64px);
  line-height: 0.98;
  font-weight: 900;
  letter-spacing: -0.065em;
  color: #FFF6E8;
  text-shadow:
    0 3px 0 #572310,
    0 6px 0 rgba(21, 8, 16, 0.65),
    0 12px 26px rgba(0, 0, 0, 0.56);
  transform: rotate(-2.4deg);
  white-space: nowrap;
}
.game-title span { position: relative; }
.game-title em {
  font-style: normal;
  color: #FF8A3D;
  text-shadow:
    0 3px 0 #7A2D0B,
    0 6px 0 rgba(21, 8, 16, 0.65),
    0 12px 28px rgba(255, 110, 40, 0.32);
}
.game-title sup {
  position: relative;
  top: -1.9em;
  display: inline-block;
  margin-left: 3px;
  padding: 3px 7px 4px;
  border-radius: 9px;
  background: linear-gradient(180deg, #FFB05E, #F07824);
  color: #3A1608;
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 0;
  line-height: 1;
  transform: rotate(7deg);
  text-shadow: none;
  box-shadow: 0 3px 0 #8E3B10, 0 6px 14px rgba(0, 0, 0, 0.34);
}

.tagline {
  margin: 14px 0 0;
  font-size: 13px;
  letter-spacing: 0.11em;
  color: rgba(255, 219, 195, 0.8);
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.8);
}

.panel {
  width: 100%;
  max-width: 430px;
  margin: 0 auto;
  padding: 17px 16px 15px;
  border-radius: 24px;
  background:
    linear-gradient(165deg, rgba(48, 31, 48, 0.9), rgba(20, 13, 27, 0.95) 62%),
    var(--panel);
  border: 1px solid rgba(255, 172, 112, 0.2);
  box-shadow:
    0 24px 60px rgba(0, 0, 0, 0.6),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  -webkit-backdrop-filter: blur(16px) saturate(1.15);
  backdrop-filter: blur(16px) saturate(1.15);
}
.start-panel { animation: panelIn 0.66s 0.1s cubic-bezier(0.2, 1, 0.3, 1) both; }
@keyframes panelIn {
  from { opacity: 0; transform: translateY(26px); }
  to { opacity: 1; transform: translateY(0); }
}

.panel-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 13px;
}
.best-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--muted);
  font-weight: 700;
  letter-spacing: 0.04em;
}
.best-badge .mp-icon { width: 15px; height: 15px; color: #FFC04D; }
.best-badge b {
  font-size: 16px;
  color: #FFE0AE;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}
.live-dot {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 10.5px;
  letter-spacing: 0.08em;
  color: rgba(255, 196, 158, 0.66);
}
.live-dot span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #FF7A3C;
  box-shadow: 0 0 0 0 rgba(255, 122, 60, 0.5);
  animation: pulseDot 1.8s ease-out infinite;
}
@keyframes pulseDot {
  0% { box-shadow: 0 0 0 0 rgba(255, 122, 60, 0.5); }
  70% { box-shadow: 0 0 0 7px rgba(255, 122, 60, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 122, 60, 0); }
}

.how-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}
.how {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 10px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(255, 190, 140, 0.1);
}
.how > .mp-icon { width: 19px; height: 19px; flex: none; color: #FFA867; }
.how div { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.how b { font-size: 12px; font-weight: 800; color: #FFE9D6; letter-spacing: 0.01em; }
.how span { font-size: 10px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.btn {
  width: 100%;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 0;
  border-radius: 18px;
  font-family: inherit;
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 0.04em;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.09s ease, box-shadow 0.09s ease, filter 0.15s ease;
}
.btn .mp-icon { width: 23px; height: 23px; }
.btn-primary {
  color: #341505;
  background: linear-gradient(180deg, #FFAE62 0%, #FF8A3D 46%, #F2711C 100%);
  border: 1px solid rgba(255, 214, 170, 0.55);
  box-shadow:
    0 6px 0 #A8430E,
    0 14px 26px rgba(255, 106, 26, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.45);
  text-shadow: 0 1px 0 rgba(255, 228, 198, 0.4);
}
.btn-primary:active {
  transform: translateY(4px);
  box-shadow:
    0 2px 0 #A8430E,
    0 8px 16px rgba(255, 106, 26, 0.24),
    inset 0 1px 0 rgba(255, 255, 255, 0.35);
}
.btn-ghost {
  margin-top: 9px;
  min-height: 48px;
  color: #E9CFC0;
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid rgba(255, 190, 140, 0.16);
  font-size: 15px;
  font-weight: 800;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}
.btn-ghost:active { transform: translateY(2px); background: rgba(255, 255, 255, 0.08); }
.btn-ghost .mp-icon { width: 19px; height: 19px; color: #FFA867; }

.fine {
  margin: 11px 0 0;
  text-align: center;
  font-size: 10.5px;
  line-height: 1.5;
  letter-spacing: 0.02em;
  color: rgba(196, 172, 186, 0.62);
}

/* ---------- game over ---------- */

.over-screen {
  justify-content: center;
  align-items: center;
  background:
    radial-gradient(90% 60% at 50% 42%, rgba(70, 18, 18, 0.5), rgba(8, 5, 14, 0) 70%),
    linear-gradient(180deg, rgba(8, 5, 14, 0.5), rgba(6, 4, 12, 0.88));
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}
.over-panel {
  position: relative;
  margin: auto;
  text-align: center;
  padding: 24px 16px 15px;
  animation: overIn 0.46s cubic-bezier(0.2, 1.25, 0.35, 1) both;
}
@keyframes overIn {
  from { opacity: 0; transform: translateY(22px) scale(0.94); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.over-icon {
  width: 58px;
  height: 58px;
  margin: -51px auto 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 18px;
  background: linear-gradient(180deg, #FF9E5C, #EE641E);
  border: 2px solid #FFD5B1;
  box-shadow: 0 8px 0 #7C2F0D, 0 14px 28px rgba(0, 0, 0, 0.45);
  transform: rotate(-4deg);
}
.over-icon .mp-icon { width: 30px; height: 30px; color: #3B1707; }
.over-panel h2 {
  margin: 10px 0 0;
  font-size: clamp(30px, 9vw, 38px);
  line-height: 1.08;
  font-weight: 900;
  letter-spacing: -0.045em;
  color: #FFF4E6;
  text-shadow: 0 3px 0 #5C2510, 0 10px 24px rgba(0, 0, 0, 0.6);
}
.over-sub {
  margin: 10px auto 16px;
  max-width: 260px;
  font-size: 11.5px;
  line-height: 1.6;
  color: rgba(211, 186, 198, 0.72);
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}
.stat-cell {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
  padding: 11px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 190, 140, 0.1);
  text-align: left;
}
.stat-cell span { font-size: 10px; color: var(--muted); letter-spacing: 0.08em; }
.stat-cell b {
  font-size: 22px;
  line-height: 1;
  font-weight: 900;
  color: #FFCD9E;
  font-variant-numeric: tabular-nums;
}
.stat-cell:first-child b { color: #FFF4E6; }
.stat-cell:first-child { background: rgba(255, 138, 61, 0.1); border-color: rgba(255, 160, 95, 0.24); }

/* ---------- short screens ---------- */

@media (max-height: 720px) {
  .hero { margin-top: 0; }
  .game-title { font-size: clamp(38px, 11.5vw, 52px); }
  .tagline { margin-top: 10px; font-size: 12px; }
  .panel { padding: 14px; border-radius: 21px; }
  .how-row { margin-bottom: 11px; }
  .how { padding: 8px 9px; }
  .btn { min-height: 52px; }
  .fine { display: none; }
}

@media (max-height: 640px) {
  .kicker { display: none; }
  .game-title { margin-top: 6px; }
  .tagline { display: none; }
  .how-row { display: none; }
  .over-sub { display: none; }
}

@media (min-width: 560px) {
  .overlay { padding-left: 24px; padding-right: 24px; }
  .panel { max-width: 430px; }
}
