/* ============================================================
   Super 말랑이 — 세로 모바일 아케이드 스타일
   ============================================================ */

:root {
  --bg-1: #2a1a4a;
  --bg-2: #4a2270;
  --candy-pink: #ff5fa2;
  --candy-yellow: #ffd23f;
  --candy-cyan: #3fe0e0;
  --candy-mint: #57e88b;
  --ink: #241238;
  --paper: #fff6fb;
  --radius-lg: 22px;
  --radius-md: 14px;
  --ease-back: cubic-bezier(0.34, 1.56, 0.64, 1);
  --font: "Trebuchet MS", "Segoe UI", "Apple SD Gothic Neo", system-ui, sans-serif;
}

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

html, body {
  height: 100%;
  background: #16102a;
  font-family: var(--font);
  color: var(--paper);
  overflow: hidden;
  display: grid;
  place-items: center;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
  touch-action: none;
}

/* 세로 9:16(450:800) 비율을 화면 안에 레터박스로 꼭 맞춤 (contain) */
#game-wrap {
  position: relative;
  width: min(100vw, calc(100dvh * 450 / 800));
  height: min(100dvh, calc(100vw * 800 / 450));
  aspect-ratio: 450 / 800;
  overflow: hidden;
  background: #16102a;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
}

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

.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 58px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  z-index: 5;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(0,0,0,0.35), transparent);
}
.hud-hearts { display: flex; gap: 3px; font-size: 1.2rem; filter: drop-shadow(0 2px 3px rgba(0,0,0,0.4)); }
.hud-center { flex: 1; display: flex; justify-content: center; }
.hud-prog {
  font-size: 0.85rem; font-weight: 800;
  background: rgba(0,0,0,0.3); padding: 4px 12px; border-radius: 999px;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.15);
}
.hud-prog span { color: var(--candy-yellow); }
.hud-score { display: flex; align-items: baseline; gap: 2px; font-weight: 900; }
.hud-score span { font-size: 1.25rem; text-shadow: 0 2px 0 rgba(0,0,0,0.3); }
.hud-score small { font-size: 0.7rem; opacity: 0.8; }
.icon-btn {
  pointer-events: auto;
  width: 34px; height: 34px;
  border: none; border-radius: 10px;
  background: rgba(0,0,0,0.35);
  color: #fff; font-size: 1rem; cursor: pointer;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.15);
}
.icon-btn:active { transform: scale(0.92); }

/* ---------- 화면 오버레이 ---------- */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 8% 7%;
  padding-bottom: max(8%, env(safe-area-inset-bottom));
  text-align: center;
  background:
    radial-gradient(500px 380px at 50% 22%, rgba(123, 63, 176, 0.6), transparent 70%),
    linear-gradient(160deg, rgba(42, 26, 74, 0.92), rgba(74, 34, 112, 0.94));
  backdrop-filter: blur(2px);
  animation: screen-in 0.35s var(--ease-back);
  overflow-y: auto;
}
@keyframes screen-in { from { opacity: 0; transform: scale(0.97); } to { opacity: 1; transform: scale(1); } }

.title-blob {
  font-size: clamp(2.6rem, 16vw, 4.5rem);
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.3));
  animation: wobble 2.4s ease-in-out infinite;
}
@keyframes wobble {
  0%, 100% { transform: translateY(0) rotate(-4deg) scale(1, 1); }
  30% { transform: translateY(-8px) rotate(3deg) scale(1.08, 0.92); }
  60% { transform: translateY(3px) rotate(-2deg) scale(0.94, 1.06); }
}

.game-title {
  font-size: clamp(1.9rem, 9vw, 3rem);
  font-weight: 900; line-height: 1.05;
  max-width: 100%;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.25), 0 10px 20px rgba(0, 0, 0, 0.35);
}
.game-title span { background: linear-gradient(120deg, var(--candy-yellow), var(--candy-pink)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.game-title.win { color: var(--candy-mint); }
.game-title.lose { color: var(--candy-pink); }

.tagline { font-size: clamp(0.95rem, 4vw, 1.2rem); opacity: 0.92; max-width: 26ch; line-height: 1.4; }
.screen-h { font-size: clamp(1.1rem, 5vw, 1.5rem); color: var(--candy-yellow); }
.story { max-width: 34ch; line-height: 1.7; font-size: clamp(0.85rem, 3.6vw, 1rem); opacity: 0.95; }
.story b { color: var(--candy-cyan); }
.controls { list-style: none; display: grid; gap: 10px; font-size: clamp(0.85rem, 3.6vw, 1rem); text-align: left; max-width: 32ch; }
.controls b { color: var(--candy-yellow); }

/* ---------- 버튼 ---------- */
.btn {
  appearance: none; border: none; cursor: pointer;
  font-family: var(--font); font-weight: 800;
  font-size: clamp(1rem, 4.4vw, 1.2rem);
  padding: 14px 40px; border-radius: 999px; color: var(--ink);
  transition: transform 0.15s var(--ease-back), box-shadow 0.15s ease, filter 0.15s ease;
}
.btn-primary { background: linear-gradient(120deg, var(--candy-yellow), var(--candy-pink)); box-shadow: 0 7px 0 #b02f66, 0 12px 20px rgba(0, 0, 0, 0.35); }
.btn-primary:active { transform: translateY(5px); box-shadow: 0 2px 0 #b02f66; }
.btn-ghost { background: rgba(255, 255, 255, 0.12); color: var(--paper); box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.25); }
.btn-ghost:active { transform: translateY(2px); }

/* ---------- 히어로 선택 카드 ---------- */
.hero-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  width: 100%;
  max-width: 340px;
}
.hero-card {
  position: relative;
  border-radius: var(--radius-md);
  padding: 10px 8px 12px;
  background: rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.12);
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  transition: transform 0.16s var(--ease-back), box-shadow 0.16s ease, background 0.16s ease;
  overflow: hidden;
}
.hero-card::before {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(90px 70px at 50% 0%, var(--hc, #fff), transparent 70%);
  opacity: 0.3; pointer-events: none;
}
.hero-card:active { transform: scale(0.97); }
.hero-card.selected { box-shadow: inset 0 0 0 3px var(--hc, var(--candy-yellow)), 0 8px 18px rgba(0, 0, 0, 0.4); background: rgba(255, 255, 255, 0.16); transform: translateY(-3px); }
.hero-portrait { width: 84px; height: 84px; }
.hero-name { font-weight: 900; font-size: 0.95rem; }
.hero-tag { font-size: 0.66rem; font-weight: 800; padding: 2px 10px; border-radius: 999px; background: var(--hc, #fff); color: var(--ink); }
.hero-power { font-size: 0.68rem; opacity: 0.82; line-height: 1.25; }

/* 홀수 마지막 카드 가운데 정렬 */
.hero-card:last-child:nth-child(odd) { grid-column: 1 / -1; }

/* ---------- 배너 ---------- */
.banner {
  position: absolute; top: 40%; left: 50%;
  transform: translate(-50%, -50%); z-index: 6;
  font-size: clamp(1.4rem, 8vw, 2.2rem); font-weight: 900; text-align: center;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.3), 0 10px 20px rgba(0, 0, 0, 0.4);
  pointer-events: none; animation: banner-pop 0.5s var(--ease-back);
}
.banner .sub { display: block; font-size: 0.42em; opacity: 0.9; margin-top: 5px; }
@keyframes banner-pop { from { opacity: 0; transform: translate(-50%, -50%) scale(0.6); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }

/* ---------- 결과 ---------- */
.result {
  display: flex; gap: 20px; font-size: 1rem; font-weight: 700;
  background: rgba(0, 0, 0, 0.25); padding: 12px 22px; border-radius: var(--radius-md);
}
.result b { color: var(--candy-yellow); font-size: 1.3rem; }
