:root {
  --bg: #031220;
  --glass: rgba(8, 28, 46, 0.55);
  --glass-strong: rgba(6, 22, 38, 0.8);
  --border: rgba(140, 220, 255, 0.16);
  --cyan: #3ef2ff;
  --teal: #19b8d6;
  --coral: #ff5d73;
  --red: #ff3b5c;
  --amber: #ffb347;
  --gold: #ffd36b;
  --text: #e9f7ff;
  --muted: #8eb1c6;
  --font-display: 'Russo One', 'Outfit', sans-serif;
  --font-body: 'Outfit', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
}

#app { position: fixed; inset: 0; }
#game { position: absolute; inset: 0; display: block; touch-action: none; }
body.playing #game { cursor: none; }
.hidden { display: none !important; }

#vignette {
  position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at 50% 45%, transparent 50%, rgba(1, 8, 18, 0.62) 100%);
}

#damage-flash {
  position: absolute; inset: 0; pointer-events: none; opacity: 0;
  background: radial-gradient(ellipse at center, transparent 38%, rgba(255, 40, 70, 0.6) 100%);
}
body.low-hp #damage-flash { animation: lowhp 1.1s ease-in-out infinite; }
#damage-flash.hit, body.low-hp #damage-flash.hit { animation: dmg 0.55s ease-out; }
@keyframes dmg { 0% { opacity: 1; } 100% { opacity: 0; } }
@keyframes lowhp { 0%, 100% { opacity: 0.2; } 50% { opacity: 0.65; } }

/* ---------------- HUD ---------------- */
#hud {
  position: absolute; top: 0; left: 0; right: 0;
  display: grid; grid-template-columns: 1fr auto 1fr;
  align-items: start; gap: 14px; padding: 18px 22px;
  pointer-events: none;
  animation: fadeDown 0.5s ease;
}

.panel {
  background: var(--glass);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  padding: 10px 16px;
}

.label {
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--muted);
}

.hud-left { justify-self: start; display: flex; flex-direction: column; gap: 6px; }
.hud-right { justify-self: end; display: flex; align-items: center; gap: 18px; }

#hearts { display: flex; gap: 6px; }
.heart { display: inline-flex; }
.heart svg {
  width: 26px; height: 26px; fill: var(--coral);
  filter: drop-shadow(0 0 6px rgba(255, 93, 115, 0.75));
  transition: transform 0.3s, fill 0.3s, filter 0.3s;
}
.heart.lost svg { fill: rgba(255, 255, 255, 0.12); filter: none; transform: scale(0.82); }
.heart.lost { animation: heartLose 0.45s ease-out; }
.heart.gain { animation: heartGain 0.6s ease-out; }
@keyframes heartLose {
  0% { transform: scale(1.45); }
  45% { transform: scale(0.7) rotate(-14deg); }
  100% { transform: scale(1); }
}
@keyframes heartGain {
  0% { transform: scale(0.4); }
  60% { transform: scale(1.35); }
  100% { transform: scale(1); }
}

.stat { display: flex; flex-direction: column; align-items: flex-end; }
.stat-value {
  font-family: var(--font-display);
  font-size: 24px; line-height: 1.15;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 14px rgba(62, 242, 255, 0.35);
}

.icon-btn {
  pointer-events: auto;
  width: 38px; height: 38px; border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  display: grid; place-items: center; cursor: pointer;
  transition: background 0.2s, transform 0.2s;
}
.icon-btn svg { width: 18px; height: 18px; fill: var(--text); }
.icon-btn:hover { background: rgba(62, 242, 255, 0.15); transform: translateY(-1px); }

.hud-center { justify-self: center; min-width: 260px; text-align: left; }
.progress-row { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; }
.progress-text { font-family: var(--font-display); font-size: 13px; color: var(--cyan); }
.progress-text.boss { color: var(--red); }
.progress {
  margin-top: 7px; height: 6px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.08); overflow: hidden;
}
.progress-fill {
  height: 100%; width: 0;
  background: linear-gradient(90deg, var(--teal), var(--cyan));
  box-shadow: 0 0 10px var(--cyan);
  transition: width 0.35s ease;
}

#boss-wrap { border-color: rgba(255, 59, 92, 0.45); animation: bossGlow 1.6s ease-in-out infinite; }
.boss-title {
  font-family: var(--font-display); font-size: 14px; letter-spacing: 0.22em;
  color: var(--red); text-shadow: 0 0 12px rgba(255, 59, 92, 0.75);
}
#boss-segments { display: flex; gap: 6px; margin-top: 8px; }
.seg {
  flex: 1; height: 11px; border-radius: 3px; transform: skewX(-18deg);
  background: rgba(255, 255, 255, 0.08);
  transition: background 0.25s, box-shadow 0.25s;
}
.seg.on {
  background: linear-gradient(180deg, #ff7a91, #d81b45);
  box-shadow: 0 0 10px rgba(255, 59, 92, 0.75);
}
@keyframes bossGlow {
  0%, 100% { box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35), 0 0 0 rgba(255, 59, 92, 0); }
  50% { box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35), 0 0 26px rgba(255, 59, 92, 0.45); }
}

/* ---------------- Banner ---------------- */
.banner {
  position: absolute; top: 27%; left: 50%;
  transform: translate(-50%, -18px) scale(0.96);
  opacity: 0; text-align: center; pointer-events: none;
  transition: opacity 0.45s ease, transform 0.45s ease;
  width: min(760px, 92vw);
}
.banner.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
.banner-title {
  font-family: var(--font-display);
  font-size: clamp(34px, 6vw, 66px); letter-spacing: 0.12em;
  background: linear-gradient(180deg, #ffffff, #9ff6ff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 18px rgba(62, 242, 255, 0.45));
}
.banner-sub {
  margin-top: 6px; color: #cfe7f3;
  font-size: clamp(14px, 1.8vw, 18px); letter-spacing: 0.08em;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.6);
}
.banner.boss .banner-title {
  background: linear-gradient(180deg, #ffd6dd, #ff3b5c);
  -webkit-background-clip: text; background-clip: text;
  filter: drop-shadow(0 0 22px rgba(255, 59, 92, 0.85));
  animation: blink 0.55s steps(2) infinite;
}
.banner.boss::before, .banner.boss::after {
  content: ''; display: block; height: 9px; margin: 12px auto;
  width: min(520px, 80vw); border-radius: 3px;
  background: repeating-linear-gradient(-45deg, var(--red) 0 14px, rgba(0, 0, 0, 0.35) 14px 28px);
  background-size: 39.6px 100%;
  animation: stripes 0.7s linear infinite;
  box-shadow: 0 0 16px rgba(255, 59, 92, 0.6);
}
.banner.victory .banner-title {
  background: linear-gradient(180deg, #fff6d8, var(--gold));
  -webkit-background-clip: text; background-clip: text;
  filter: drop-shadow(0 0 22px rgba(255, 211, 107, 0.7));
}
@keyframes blink { 50% { opacity: 0.55; } }
@keyframes stripes { to { background-position: 39.6px 0; } }

/* ---------------- Overlays ---------------- */
.overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 24px; overflow-y: auto;
  background: radial-gradient(ellipse at center, rgba(3, 18, 32, 0.35), rgba(1, 8, 16, 0.82));
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  animation: fadeIn 0.4s ease;
}

.card {
  position: relative; overflow: hidden;
  width: min(620px, 100%); margin: auto;
  padding: 34px 36px 28px;
  background: var(--glass-strong);
  border: 1px solid var(--border); border-radius: 24px;
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  animation: rise 0.55s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: linear-gradient(90deg, transparent, var(--cyan), transparent);
}
.card::after {
  content: ''; position: absolute; width: 340px; height: 340px; top: -170px; right: -120px;
  background: radial-gradient(circle, rgba(62, 242, 255, 0.14), transparent 70%);
  pointer-events: none;
}
.card.danger::before { background: linear-gradient(90deg, transparent, var(--red), transparent); }
.card.danger::after { background: radial-gradient(circle, rgba(255, 59, 92, 0.16), transparent 70%); }
.card-compact { width: min(420px, 100%); text-align: center; }

.eyebrow {
  font-size: 12px; font-weight: 600; letter-spacing: 0.35em;
  text-transform: uppercase; color: var(--cyan);
}
.eyebrow.red { color: var(--coral); }

.title {
  font-family: var(--font-display); font-weight: 400;
  font-size: clamp(40px, 7vw, 66px); line-height: 1; letter-spacing: 0.06em;
  margin: 10px 0 12px;
  background: linear-gradient(180deg, #ffffff 0%, #bdf7ff 45%, #3ec9e0 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 24px rgba(62, 242, 255, 0.35));
}
.title-sm {
  font-family: var(--font-display); font-weight: 400;
  font-size: clamp(28px, 5vw, 44px); letter-spacing: 0.06em; line-height: 1.1;
  margin: 10px 0 20px;
  background: linear-gradient(180deg, #ffffff, #9ff6ff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.title-sm.red {
  background: linear-gradient(180deg, #ffe0e5, var(--red));
  -webkit-background-clip: text; background-clip: text;
  filter: drop-shadow(0 4px 22px rgba(255, 59, 92, 0.4));
}

.tagline { color: var(--muted); font-size: 16px; line-height: 1.5; }

.legend { display: grid; gap: 10px; margin: 22px 0; }
.legend-row {
  display: grid; grid-template-columns: 120px 1fr auto; align-items: center; gap: 14px;
  padding: 10px 14px; border-radius: 14px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  transition: transform 0.2s, background 0.2s, border-color 0.2s;
}
.legend-row:hover {
  transform: translateX(4px);
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(62, 242, 255, 0.25);
}
.legend-icon { width: 120px; height: 44px; }
.legend-name { font-weight: 700; font-size: 15px; }
.legend-desc { font-size: 13px; color: var(--muted); margin-top: 2px; }

.hp-badge {
  font-family: var(--font-display); font-size: 13px;
  padding: 5px 11px; border-radius: 999px; white-space: nowrap;
}
.hp-badge.player { color: var(--cyan); background: rgba(62, 242, 255, 0.1); border: 1px solid rgba(62, 242, 255, 0.3); }
.hp-badge.enemy { color: var(--amber); background: rgba(255, 179, 71, 0.1); border: 1px solid rgba(255, 179, 71, 0.3); }
.hp-badge.boss { color: var(--red); background: rgba(255, 59, 92, 0.1); border: 1px solid rgba(255, 59, 92, 0.35); }

.controls { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.control {
  text-align: center; padding: 10px 6px; border-radius: 12px;
  background: rgba(0, 0, 0, 0.22); border: 1px solid rgba(255, 255, 255, 0.05);
}
.control .label { display: block; margin-bottom: 7px; }
kbd {
  display: inline-block; margin: 1px;
  font-family: var(--font-body); font-weight: 700; font-size: 12px;
  padding: 3px 7px; border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14); border-bottom-width: 2px;
  color: var(--text);
}
.touch-hint { font-size: 12px; color: var(--muted); text-align: center; margin: 10px 0 22px; opacity: 0.8; }

.btn {
  position: relative; overflow: hidden;
  display: block; width: 100%;
  padding: 15px 22px; border-radius: 14px; border: none;
  font-family: var(--font-display); font-size: 17px; letter-spacing: 0.14em; text-transform: uppercase;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}
.btn::after {
  content: ''; position: absolute; top: 0; bottom: 0; width: 40%; left: -60%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.45), transparent);
  transform: skewX(-20deg);
  transition: left 0.6s ease;
}
.btn:hover::after { left: 120%; }
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(0) scale(0.98); }
.btn-primary {
  color: #02202e;
  background: linear-gradient(135deg, #6ff6ff, #1aa6c9);
  box-shadow: 0 10px 30px rgba(62, 242, 255, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.55);
}
.btn-primary:hover { box-shadow: 0 16px 40px rgba(62, 242, 255, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.55); }
.btn-ghost { color: var(--text); background: rgba(255, 255, 255, 0.05); border: 1px solid var(--border); }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.1); }

.actions { display: flex; gap: 12px; }
.actions .btn { flex: 1; }

.best-line { margin-top: 14px; text-align: center; color: var(--muted); font-size: 13px; }
.best-line span { color: var(--gold); font-weight: 700; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 6px 0 22px; }
.stat-card {
  display: flex; flex-direction: column; gap: 4px;
  padding: 14px 16px; border-radius: 14px;
  background: rgba(255, 255, 255, 0.04); border: 1px solid rgba(255, 255, 255, 0.06);
}
.stat-card .stat-value { font-size: 28px; }

.new-best {
  display: inline-block; margin-bottom: 14px;
  padding: 6px 14px; border-radius: 999px;
  font-weight: 700; letter-spacing: 0.12em; font-size: 13px; text-transform: uppercase;
  color: #2a1a00; background: linear-gradient(135deg, #fff1b8, var(--gold));
  box-shadow: 0 0 24px rgba(255, 211, 107, 0.55);
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeDown { from { opacity: 0; transform: translateY(-12px); } to { opacity: 1; transform: none; } }
@keyframes rise { from { opacity: 0; transform: translateY(24px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes pulse { 50% { transform: scale(1.05); } }

@media (max-width: 680px) {
  #hud { padding: 10px; gap: 8px; grid-template-columns: auto 1fr auto; }
  .panel { padding: 8px 10px; border-radius: 12px; }
  .hud-center { min-width: 0; width: 100%; }
  .hud-right { gap: 10px; }
  .stat-value { font-size: 18px; }
  .heart svg { width: 20px; height: 20px; }
  .label { font-size: 9px; letter-spacing: 0.12em; }
  .card { padding: 26px 20px 22px; }
  .controls { grid-template-columns: repeat(2, 1fr); }
  .legend-row { grid-template-columns: 84px 1fr auto; gap: 10px; padding: 8px 10px; }
  .legend-icon { width: 84px; height: 31px; }
}
