:root {
  --red: #e3352b;
  --red-dark: #a0211a;
  --gold: #ffd23f;
  --gold-dark: #d99a00;
  --blue: #2f5bd6;
  --sky: #5c94fc;
  --ink: #14182b;
  --panel: #1b2138;
  --panel-edge: #3a4670;
  --text: #f3f0ff;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: radial-gradient(circle at 50% 20%, #1a2140 0%, #070a15 70%);
  color: var(--text);
  font-family: "Trebuchet MS", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#stage {
  position: relative;
  width: min(100vw, calc(100vh * 1.6667));
  height: min(100vh, calc(100vw / 1.6667));
  background: #000;
  overflow: hidden;
  box-shadow: 0 0 0 3px #000, 0 24px 80px rgba(0, 0, 0, 0.75), 0 0 60px rgba(47, 91, 214, 0.25);
}

canvas#game {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  pointer-events: none;
  font-weight: 800;
  letter-spacing: 1px;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.45);
}

.hearts {
  display: flex;
  gap: 6px;
  align-items: center;
  min-height: 22px;
  padding-left: 2px;
}

.heart {
  position: relative;
  width: 18px;
  height: 16px;
  background: #ff4d4d;
  transform: rotate(-45deg);
  border-radius: 2px;
  margin-top: 4px;
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.4));
}
.heart::before, .heart::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 16px;
  background: inherit;
  border-radius: 50%;
}
.heart::before { top: -9px; left: 0; }
.heart::after { left: 9px; top: 0; }
.heart.empty { background: #40263a; opacity: 0.55; }

.shield-pip {
  width: 12px;
  height: 12px;
  background: #7cc4ff;
  transform: rotate(45deg);
  border-radius: 2px;
  box-shadow: 0 0 8px rgba(124, 196, 255, 0.9);
}

.hud-center {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 15px;
  color: #fff;
  background: rgba(10, 14, 28, 0.5);
  border: 2px solid rgba(255, 255, 255, 0.15);
  padding: 5px 18px;
  border-radius: 20px;
  letter-spacing: 3px;
}

.hud-right {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 18px;
}

.coin-stat { display: flex; align-items: center; gap: 7px; color: var(--gold); }

.coin-dot {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff3b0, var(--gold) 55%, var(--gold-dark));
  box-shadow: inset 0 0 0 2px rgba(160, 100, 0, 0.5), 0 2px 0 rgba(0,0,0,.35);
}

.icon-btn {
  pointer-events: auto;
  cursor: pointer;
  background: rgba(10, 14, 28, 0.55);
  color: #cfe0ff;
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1px;
  font-family: inherit;
}
.icon-btn.off { color: #7a8399; text-decoration: line-through; }

/* ---------- Relic bar ---------- */
.relic-bar {
  position: absolute;
  top: 58px;
  left: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: 60%;
  pointer-events: none;
}

.relic-chip {
  display: flex;
  align-items: center;
  gap: 3px;
  background: rgba(10, 14, 28, 0.62);
  border: 2px solid var(--panel-edge);
  border-radius: 8px;
  padding: 2px 6px;
  font-size: 10px;
  font-weight: 800;
  color: #dfe7ff;
  letter-spacing: 0.5px;
  pointer-events: auto;
}
.relic-chip .ic { color: var(--gold); font-size: 10px; }
.relic-chip.rare { border-color: #b46bff; box-shadow: 0 0 8px rgba(180,107,255,.4); }
.relic-chip.legend { border-color: var(--gold); box-shadow: 0 0 10px rgba(255,210,63,.5); }

/* ---------- Screens ---------- */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 8, 18, 0.72);
  backdrop-filter: blur(3px);
  z-index: 20;
  padding: 16px;
}
.screen.hidden { display: none; }

.panel {
  width: min(560px, 92%);
  background: linear-gradient(180deg, #232a48 0%, #171c31 100%);
  border: 3px solid var(--panel-edge);
  border-radius: 16px;
  padding: 26px 26px 22px;
  text-align: center;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.6), inset 0 2px 0 rgba(255, 255, 255, 0.06);
  animation: pop 0.28s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.panel.wide { width: min(820px, 96%); }

@keyframes pop {
  from { transform: scale(0.9); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.logo { margin-bottom: 6px; }
.logo-small {
  display: inline-block;
  font-size: 14px;
  letter-spacing: 8px;
  color: var(--gold);
  margin-bottom: -4px;
  text-shadow: 0 2px 0 #7a5200;
}
.title {
  margin: 0;
  font-size: clamp(40px, 7vw, 72px);
  line-height: 0.95;
  letter-spacing: 4px;
  color: var(--red);
  text-shadow: 0 4px 0 var(--red-dark), 0 8px 0 rgba(0, 0, 0, 0.4), 0 0 30px rgba(227, 53, 43, 0.5);
}
.title.over { color: #fff; text-shadow: 0 4px 0 #6a1620, 0 8px 0 rgba(0,0,0,.5); }
.title span { color: #fff; }

.tagline {
  margin: 14px 0 18px;
  color: #a9b6dd;
  font-size: 14px;
  letter-spacing: 1px;
}

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
  padding: 14px 16px;
  margin: 0 auto 20px;
  background: rgba(0, 0, 0, 0.25);
  border: 2px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  font-size: 13px;
  color: #c9d4f5;
}
.controls b { color: var(--gold); }

.btn {
  cursor: pointer;
  font-family: inherit;
  font-weight: 800;
  letter-spacing: 2px;
  font-size: 16px;
  color: #fff;
  background: linear-gradient(180deg, #3a4670, #262f4e);
  border: 3px solid #4c5c92;
  border-radius: 12px;
  padding: 12px 34px;
  margin: 4px 6px;
  transition: transform 0.08s ease, filter 0.15s ease;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.35);
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0,0,0,.35); }
.btn.primary {
  color: #2a1200;
  background: linear-gradient(180deg, #ffe36e, var(--gold) 55%, var(--gold-dark));
  border-color: #fff0a8;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.6);
}
.best { margin-top: 16px; font-size: 13px; color: #8b98c0; letter-spacing: 1px; }
.best span { color: var(--gold); font-weight: 800; }

.subtitle {
  margin: 0 0 6px;
  font-size: 26px;
  letter-spacing: 3px;
  color: var(--gold);
  text-shadow: 0 3px 0 #7a5200;
}
.hint { margin: 0 0 18px; color: #a9b6dd; font-size: 14px; }
.hint.small { font-size: 12px; margin: 16px 0 0; color: #7f8cba; }

/* ---------- Upgrade cards ---------- */
.cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-top: 8px;
}

.card {
  position: relative;
  cursor: pointer;
  background: linear-gradient(180deg, #20283f, #141a2b);
  border: 3px solid var(--panel-edge);
  border-radius: 14px;
  padding: 18px 12px 14px;
  text-align: center;
  transition: transform 0.12s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  animation: cardIn 0.35s backwards;
}
.card:nth-child(2) { animation-delay: 0.06s; }
.card:nth-child(3) { animation-delay: 0.12s; }
@keyframes cardIn { from { transform: translateY(14px) scale(0.95); opacity: 0; } to { transform: none; opacity: 1; } }

.card:hover { transform: translateY(-5px); border-color: var(--gold); box-shadow: 0 10px 26px rgba(255, 210, 63, 0.2); }
.card:active { transform: translateY(-1px) scale(0.99); }

.card .emoji {
  width: 54px;
  height: 54px;
  margin: 0 auto 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  font-size: 20px;
  font-weight: 900;
  letter-spacing: 1px;
  color: #fff;
  background: radial-gradient(circle at 40% 30%, #4a5c9a, #232c47);
  border: 2px solid var(--panel-edge);
}
.card.rare .emoji { background: radial-gradient(circle at 40% 30%, #8a5cff, #3a1f6e); border-color: #b46bff; }
.card.legend .emoji { background: radial-gradient(circle at 40% 30%, #ffe36e, #a06a00); border-color: var(--gold); color: #2a1200; }

.card .name { font-size: 15px; font-weight: 800; letter-spacing: 1px; margin-bottom: 6px; }
.card.rare .name { color: #d7b5ff; }
.card.legend .name { color: var(--gold); }
.card .desc { font-size: 12px; line-height: 1.45; color: #a9b6dd; min-height: 34px; }
.card .key {
  position: absolute;
  top: 8px;
  left: 10px;
  font-size: 11px;
  color: #6d7aa8;
  font-weight: 800;
}
.card .stack { position: absolute; top: 8px; right: 10px; font-size: 11px; color: var(--gold); font-weight: 800; }

/* ---------- Game over stats ---------- */
.stats {
  display: flex;
  justify-content: center;
  gap: 26px;
  margin: 20px 0 24px;
  flex-wrap: wrap;
}
.stat { text-align: center; }
.stat .v { display: block; font-size: 30px; font-weight: 900; color: var(--gold); text-shadow: 0 3px 0 #7a5200; }
.stat .l { font-size: 12px; color: #8b98c0; letter-spacing: 1px; }

/* ---------- Touch controls ---------- */
.touch-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 12px;
  display: flex;
  justify-content: space-between;
  padding: 0 14px;
  z-index: 15;
  pointer-events: none;
}
.touch-controls.hidden { display: none; }
.tc-group { display: flex; gap: 10px; pointer-events: auto; }
.tc-btn {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.25);
  background: rgba(20, 26, 46, 0.55);
  color: #fff;
  font-size: 20px;
  font-weight: 800;
  font-family: inherit;
  backdrop-filter: blur(2px);
  touch-action: none;
}
.tc-btn.jump { width: 76px; height: 76px; font-size: 14px; background: rgba(227, 53, 43, 0.55); border-color: rgba(255, 140, 130, 0.6); }
.tc-btn.fire { width: 58px; height: 58px; font-size: 12px; background: rgba(255, 140, 40, 0.5); }
.tc-btn.dash { width: 58px; height: 58px; font-size: 11px; background: rgba(47, 91, 214, 0.5); }
.tc-btn:active { filter: brightness(1.3); }

@media (max-width: 620px) {
  .controls { grid-template-columns: 1fr; font-size: 12px; }
  .cards { grid-template-columns: 1fr; }
  .card { display: flex; align-items: center; text-align: left; gap: 12px; padding: 12px; }
  .card .emoji { margin: 0; width: 44px; height: 44px; flex: 0 0 auto; font-size: 16px; }
  .card .desc { min-height: 0; }
  .card .name { margin-bottom: 2px; }
  .relic-bar { top: 52px; max-width: 70%; }
}
