:root {
  --orange: #ff9a62;
  --orange-glow: #ffd0a8;
  --purple: #9b7dff;
  --bg: #120e22;
  --bg-card: #241c3c;
  --cream: #fff6ec;
  --text: #fff8f2;
  --muted: #c9b8e6;
  --pink: #ffb3c9;
  --gold: #ffe0a3;
  --panel: #1e1634;
  --panel-hi: #2c2248;
  --panel-edge: #e8d5a8;
  --panel-out: #6b57a0;
  --night: #0c0a18;
  --pixel: "Press Start 2P", "Nunito", "PingFang TC", "Noto Sans TC", monospace;
  --font: "Nunito", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

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

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

body {
  background:
    radial-gradient(ellipse 90% 55% at 50% -10%, #3a2868 0%, transparent 55%),
    radial-gradient(ellipse 60% 40% at 80% 100%, #2a1838 0%, transparent 50%),
    linear-gradient(180deg, #14102a 0%, #120e22 50%, #1a1230 100%);
}

#game-wrap {
  max-width: 920px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 10px 12px calc(10px + var(--safe-b));
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  flex-shrink: 0;
}
.top-bar h1 {
  font-family: var(--font);
  font-size: clamp(0.95rem, 3.2vw, 1.15rem);
  font-weight: 900;
  letter-spacing: 0.02em;
  color: var(--gold);
  text-shadow: 0 2px 0 #3a1840, 0 0 18px rgba(255, 154, 98, 0.35);
}
.home-link, .mute-btn {
  color: var(--cream);
  text-decoration: none;
  font-family: var(--font);
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1.2;
  background: var(--panel);
  border: 2px solid var(--panel-edge);
  box-shadow: 0 0 0 2px var(--panel-out), 3px 3px 0 rgba(0,0,0,0.45);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
}
.mute-btn { font-size: 0.95rem; line-height: 1; min-width: 42px; padding: 8px 10px; }

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  border-radius: 14px;
  overflow: hidden;
  border: 3px solid #dcc890;
  box-shadow:
    0 0 0 3px #5a478a,
    0 0 0 6px #1a1230,
    0 12px 28px rgba(0,0,0,0.45),
    inset 0 0 0 1px rgba(255,246,236,0.12);
  background: #0a0c18;
}
.stage::after {
  content: "";
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 30;
  background: linear-gradient(180deg, rgba(255,255,255,0.03) 0%, transparent 18%, transparent 82%, rgba(0,0,0,0.18) 100%);
  opacity: 1;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #0a0c18;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.hud {
  position: absolute;
  inset: 0 0 auto 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 10px 12px 0;
  pointer-events: none;
  z-index: 5;
  gap: 10px;
}
.hud.hidden { display: none; }
.hp-side { flex: 1; min-width: 0; }
.hp-right { text-align: right; }
.hp-right .hp-bar, .hp-right .meter-bar { direction: rtl; }
.hp-name {
  display: inline-block;
  font-family: var(--font);
  font-size: 0.72rem;
  font-weight: 800;
  margin-bottom: 4px;
  padding: 3px 8px;
  background: rgba(10, 8, 24, 0.85);
  border: 2px solid rgba(255, 224, 163, 0.85);
  border-radius: 8px;
  color: var(--cream);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  box-shadow: 2px 2px 0 rgba(0,0,0,0.4);
}
.hp-bar, .meter-bar {
  height: 15px;
  background: rgba(8, 6, 18, 0.94);
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid #fff6ec;
  box-shadow:
    0 0 0 2px #5a478a,
    0 0 12px rgba(155, 125, 255, 0.25),
    2px 2px 0 rgba(0,0,0,0.35);
}
.meter-bar {
  height: 8px;
  margin-top: 5px;
  border-width: 2px;
  border-radius: 6px;
}
.hp-fill {
  height: 100%;
  width: 100%;
  transform-origin: left center;
  transition: transform 0.1s linear;
  background: linear-gradient(180deg, #ffb08a 0%, #ff6b4a 45%, #e03a3a 100%);
  box-shadow: inset 0 -2px 0 rgba(0,0,0,0.25), inset 0 2px 0 rgba(255,255,255,0.22);
}
.hp-fill.p2 {
  background: linear-gradient(180deg, #c4b0ff 0%, #8a6dff 45%, #5a3ad0 100%);
  transform-origin: right center;
}
.hp-right .hp-fill { transform-origin: left center; }
.meter-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #5a478a, #9b7dff 55%, #ffe0a3);
  transition: width 0.12s linear;
}
.hud-mid {
  text-align: center;
  min-width: 76px;
  background: linear-gradient(180deg, rgba(24, 16, 48, 0.95), rgba(10, 8, 24, 0.92));
  border: 2px solid var(--gold);
  border-radius: 12px;
  padding: 6px 10px 8px;
  box-shadow:
    0 0 0 2px #5a478a,
    0 0 14px rgba(255, 224, 163, 0.2),
    2px 2px 0 rgba(0,0,0,0.4);
}
.timer {
  font-family: var(--pixel);
  font-size: 0.95rem;
  font-weight: 400;
  color: var(--gold);
  text-shadow: 2px 2px 0 #3a1840;
  line-height: 1.2;
}
.round-tag {
  font-family: var(--font);
  font-size: 0.68rem;
  color: var(--pink);
  font-weight: 800;
  margin-top: 3px;
  line-height: 1.3;
}

.banner {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  z-index: 20;
  font-family: var(--font);
  font-size: clamp(1.05rem, 4vw, 1.55rem);
  font-weight: 900;
  color: var(--cream);
  background: rgba(12, 8, 28, 0.92);
  border: 3px solid var(--gold);
  box-shadow: 0 0 0 3px #5a478a, 6px 6px 0 rgba(0,0,0,0.45);
  border-radius: 14px;
  padding: 12px 18px;
  text-shadow: 0 2px 0 #3a1840;
  pointer-events: none;
  white-space: nowrap;
  animation: banner-pop 0.28s cubic-bezier(.2,1.4,.4,1);
  letter-spacing: 0.04em;
}
.banner.hidden { display: none; }
.banner.special-title {
  top: 14%;
  font-size: clamp(0.95rem, 3.4vw, 1.35rem);
  color: #ffe0a3;
  border-color: #ff6b8a;
  box-shadow: 0 0 0 3px #9b7dff, 0 0 22px rgba(255, 107, 138, 0.35), 6px 6px 0 rgba(0,0,0,0.45);
  animation: banner-slam 0.42s cubic-bezier(.15,1.6,.4,1);
}
@keyframes banner-slam {
  0% { transform: translate(-50%, -50%) scale(0.4); opacity: 0; }
  55% { transform: translate(-50%, -50%) scale(1.18); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}
@keyframes banner-pop {
  from { transform: translate(-50%, -50%) scale(0.72); opacity: 0; }
  to { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

.move-toast {
  position: absolute;
  left: 50%;
  bottom: 28%;
  transform: translateX(-50%);
  z-index: 18;
  font-family: var(--font);
  font-size: clamp(0.8rem, 2.4vw, 1rem);
  font-weight: 800;
  color: #fff6ec;
  background: rgba(12, 8, 28, 0.9);
  border: 2px solid var(--gold);
  box-shadow: 0 0 0 2px #5a478a, 4px 4px 0 rgba(0,0,0,0.4);
  border-radius: 12px;
  padding: 8px 14px;
  pointer-events: none;
  animation: toast-in 0.18s ease-out;
  line-height: 1.4;
}
.move-toast.hidden { display: none; }
.move-toast.pulse {
  border-color: #ff6b8a;
  box-shadow: 0 0 0 3px #9b7dff, 0 0 18px rgba(255, 154, 98, 0.45), 4px 4px 0 rgba(0,0,0,0.4);
  animation: toast-pulse 0.45s ease-out;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
@keyframes toast-pulse {
  0% { opacity: 0; transform: translateX(-50%) scale(0.7); }
  55% { opacity: 1; transform: translateX(-50%) scale(1.12); }
  100% { opacity: 1; transform: translateX(-50%) scale(1); }
}

.menu {
  position: absolute;
  inset: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  background:
    radial-gradient(ellipse 70% 50% at 50% 30%, rgba(90, 55, 140, 0.28), transparent 60%),
    rgba(6, 6, 16, 0.72);
  overflow-y: auto;
}
.menu.hidden { display: none; }
.menu-card {
  width: min(420px, 100%);
  background: linear-gradient(180deg, #2a2148 0%, #1a1430 100%);
  border: 3px solid var(--panel-edge);
  box-shadow: 0 0 0 3px var(--panel-out), 8px 10px 0 rgba(0,0,0,0.4);
  border-radius: 16px;
  padding: 18px 16px 16px;
  text-align: center;
  position: relative;
}
.menu-card::before {
  content: "";
  position: absolute;
  inset: 8px;
  border: 1px solid rgba(255, 224, 163, 0.28);
  border-radius: 12px;
  pointer-events: none;
}
.menu-card.select-wide { width: min(540px, 100%); }
.menu-card.hidden { display: none; }
.menu-hero {
  width: 104px;
  height: 138px;
  object-fit: contain;
  object-position: center bottom;
  border-radius: 12px;
  border: 2px solid rgba(255, 224, 163, 0.75);
  box-shadow: 0 0 0 2px #5a478a, 4px 4px 0 rgba(0,0,0,0.35);
  background: #1a1230;
  margin-bottom: 12px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.menu-card h2 {
  font-family: var(--font);
  font-size: clamp(1.05rem, 3.4vw, 1.35rem);
  font-weight: 900;
  margin-bottom: 8px;
  line-height: 1.35;
  color: var(--gold);
  text-shadow: 0 2px 0 #3a1840;
}
.menu-card p {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
  margin-bottom: 12px;
  line-height: 1.45;
}
.secret-hint {
  font-family: var(--font);
  font-size: 0.78rem !important;
  color: var(--pink) !important;
  opacity: 0.95;
  margin-top: 10px !important;
  line-height: 1.45 !important;
  font-weight: 800 !important;
}
.btn {
  display: block;
  width: 100%;
  border: 2px solid rgba(255,255,255,0.2);
  border-radius: 12px;
  padding: 12px 14px;
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  margin-top: 8px;
  box-shadow: 3px 3px 0 rgba(0,0,0,0.4);
  transition: transform 0.05s ease, box-shadow 0.05s ease;
}
.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 rgba(0,0,0,0.4); }
.btn.primary {
  background: linear-gradient(180deg, #ffb08a 0%, #ff9a62 55%, #f07840 100%);
  color: #1a1430;
  border-color: #ffe0a3;
  box-shadow: 0 0 0 2px #5a478a, 3px 3px 0 rgba(0,0,0,0.4);
  font-size: 1.02rem;
}
.btn.secondary {
  background: #3a2a68;
  color: var(--cream);
  border-color: #9b7dff;
}
.btn.ghost {
  background: rgba(18, 14, 34, 0.9);
  color: var(--muted);
  border-color: #5a478a;
}
.quiz-link {
  display: inline-block;
  margin-top: 14px;
  color: var(--orange-glow);
  font-family: var(--font);
  font-size: 0.82rem;
  font-weight: 800;
  line-height: 1.4;
}

.gender-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-bottom: 12px;
}
.gender-btn {
  flex: 1;
  max-width: 150px;
  border: 2px solid #5a478a;
  background: #160f2a;
  color: var(--muted);
  font-family: var(--font);
  font-weight: 800;
  font-size: 0.95rem;
  line-height: 1.3;
  padding: 10px 12px;
  cursor: pointer;
  border-radius: 999px;
  box-shadow: 2px 2px 0 rgba(0,0,0,0.35);
}
.gender-btn.active {
  background: linear-gradient(180deg, #ffb08a, #ff9a62);
  color: #1a1430;
  border-color: var(--gold);
  box-shadow: 0 0 0 2px #5a478a, 2px 2px 0 rgba(0,0,0,0.35);
}

.char-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 8px 0 12px;
}
.char-cell {
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid #5a478a;
  background: #160f2a;
  cursor: pointer;
  padding: 0;
  box-shadow: 3px 3px 0 rgba(0,0,0,0.35);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.char-cell img {
  width: 100%;
  height: calc(100% - 22px);
  object-fit: contain;
  object-position: center bottom;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: transparent;
  padding-top: 6px;
}
.char-cell span {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: rgba(8, 6, 20, 0.92);
  border-top: 1px solid rgba(255, 224, 163, 0.45);
  font-family: var(--font);
  font-size: 0.68rem;
  font-weight: 800;
  line-height: 1.3;
  padding: 4px 2px 5px;
  color: #fff6ec;
}
.char-cell.selected {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px #ff9a62, 0 0 14px rgba(255, 154, 98, 0.35), 3px 3px 0 rgba(0,0,0,0.35);
}
.char-cell.secret {
  border-style: dashed;
  border-color: rgba(255, 179, 201, 0.75);
}
.move-preview {
  font-family: var(--font);
  font-size: 0.78rem;
  color: var(--gold);
  font-weight: 800;
  margin-bottom: 10px;
  min-height: 2.2em;
  line-height: 1.45;
}
.select-picked {
  display: flex;
  gap: 8px;
  margin-bottom: 4px;
}
.picked {
  flex: 1;
  background: #160f2a;
  border: 2px solid #5a478a;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.85rem;
  box-shadow: 2px 2px 0 rgba(0,0,0,0.3);
}
.picked span {
  display: block;
  font-family: var(--font);
  font-size: 0.68rem;
  color: var(--muted);
  margin-bottom: 2px;
  font-weight: 700;
}
.picked strong {
  font-family: var(--font);
  font-size: 0.88rem;
  font-weight: 900;
  color: var(--cream);
  line-height: 1.3;
}
.select-hint {
  font-family: var(--font);
  font-size: 0.82rem !important;
  margin-bottom: 8px !important;
  line-height: 1.4 !important;
  font-weight: 700 !important;
}

.controls {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 12px 14px calc(14px + var(--safe-b));
  z-index: 10;
  pointer-events: none;
  background: linear-gradient(180deg, transparent 0%, rgba(8, 6, 20, 0.45) 70%);
}
.controls.hidden { display: none; }
.pad {
  display: flex;
  gap: 12px;
  pointer-events: auto;
  flex-wrap: wrap;
  max-width: 50%;
  align-items: flex-end;
}
.left-pad { justify-content: flex-start; }
.right-pad { justify-content: flex-end; align-items: flex-end; }
.dpad {
  display: grid;
  grid-template-columns: 70px 70px 70px;
  gap: 6px;
  padding: 6px;
  background: rgba(12, 8, 28, 0.35);
  border: 2px solid rgba(255, 224, 163, 0.35);
  border-radius: 22px;
  box-shadow: 0 0 0 2px rgba(58,40,96,0.5);
}
.ctrl {
  width: 72px;
  height: 78px;
  min-width: 72px;
  min-height: 72px;
  border-radius: 18px;
  border: none;
  box-shadow: 3px 4px 0 rgba(0,0,0,0.35);
  background: transparent;
  color: var(--cream);
  font-family: var(--font);
  font-size: 0.78rem;
  font-weight: 900;
  line-height: 1.05;
  cursor: pointer;
  touch-action: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  position: relative;
}
.ctrl .ctrl-art {
  width: 68px;
  height: 68px;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  pointer-events: none;
  filter: drop-shadow(0 2px 0 rgba(0,0,0,0.35));
  transition: transform 0.08s ease, filter 0.08s ease;
}
.ctrl .ctrl-ico {
  font-size: 1.05rem;
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 2px 0 rgba(0,0,0,0.35);
}
.ctrl small {
  font-size: 0.58rem;
  font-weight: 800;
  opacity: 0.95;
  letter-spacing: 0.02em;
  margin-top: -2px;
  text-shadow: 0 1px 0 #000, 0 0 4px rgba(0,0,0,0.8);
  color: #ffe0a3;
}
.ctrl:active, .ctrl.pressed {
  background: transparent;
  color: #ffe0a3;
  border-color: transparent;
  transform: translate(2px, 3px) scale(0.94);
  box-shadow: 1px 1px 0 rgba(0,0,0,0.35);
}
.ctrl:active .ctrl-art, .ctrl.pressed .ctrl-art {
  filter: drop-shadow(0 0 6px #ff9a62) brightness(1.15) saturate(1.2);
  transform: scale(0.96);
}
.ctrl.dir {
  width: 70px;
  height: 76px;
  min-width: 70px;
  min-height: 70px;
}
.ctrl.dir .ctrl-art { width: 64px; height: 64px; }
.ctrl.jump { background: transparent; border: none; }
.ctrl.atk {
  width: 76px;
  height: 82px;
  min-width: 76px;
  min-height: 76px;
  border-radius: 18px;
  background: transparent;
}
.ctrl.atk .ctrl-art { width: 70px; height: 70px; }
.ctrl.punch, .ctrl.kick { background: transparent; border: none; }
.ctrl.special {
  width: 88px;
  height: 94px;
  min-width: 88px;
  min-height: 88px;
  border-radius: 22px;
  background: transparent;
  border: none;
  box-shadow: 3px 4px 0 rgba(0,0,0,0.35);
  animation: none;
}
.ctrl.special .ctrl-art { width: 82px; height: 82px; }
.ctrl.special.ready .ctrl-art {
  animation: special-art-pulse 0.9s ease-in-out infinite;
  filter: drop-shadow(0 0 10px #ff9a62) drop-shadow(0 0 18px #ffe0a3) brightness(1.12);
}
@keyframes special-art-pulse {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 8px #ff9a62) brightness(1.05); }
  50% { transform: scale(1.08); filter: drop-shadow(0 0 16px #ffe0a3) brightness(1.2); }
}
.ctrl.special:active, .ctrl.special.pressed {
  background: transparent;
  box-shadow: 1px 1px 0 rgba(0,0,0,0.35);
}

.hint-keys {
  flex-shrink: 0;
  text-align: center;
  font-family: var(--font);
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 8px;
  opacity: 0.9;
  line-height: 1.5;
  font-weight: 700;
}
.hint-keys br { display: block; }
.ctrl-tip {
  pointer-events: none;
  position: absolute;
  left: 50%;
  bottom: calc(88px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 9;
  font-family: var(--font);
  font-size: 0.68rem;
  font-weight: 800;
  color: #ffe0a3;
  background: rgba(10, 8, 24, 0.82);
  border: 2px solid rgba(255, 224, 163, 0.65);
  border-radius: 10px;
  padding: 4px 10px;
  box-shadow: 0 0 0 2px #5a478a, 2px 2px 0 rgba(0,0,0,0.35);
  white-space: nowrap;
}
.controls.hidden ~ .ctrl-tip, .ctrl-tip.hidden { display: none; }

@media (max-width: 480px) {
  .dpad { grid-template-columns: 60px 60px 60px; gap: 6px; padding: 6px; border-radius: 18px; }
  .ctrl, .ctrl.dir { width: 60px; height: 68px; min-width: 60px; min-height: 60px; }
  .ctrl .ctrl-art { width: 56px; height: 56px; }
  .ctrl.atk { width: 64px; height: 72px; min-width: 64px; min-height: 64px; border-radius: 16px; }
  .ctrl.atk .ctrl-art { width: 60px; height: 60px; }
  .ctrl.special { width: 74px; height: 82px; min-width: 74px; min-height: 74px; }
  .ctrl.special .ctrl-art { width: 70px; height: 70px; }
  .ctrl .ctrl-ico { font-size: 0.95rem; }
  .ctrl small { font-size: 0.52rem; }
  .char-grid { grid-template-columns: repeat(4, 1fr); gap: 8px; }
  .hint-keys { display: none; }
  .top-bar h1 { font-size: 0.95rem; }
  .move-preview { font-size: 0.72rem; }
  .char-cell span { font-size: 0.62rem; }
  .menu { padding: 10px; }
}

@media (min-width: 700px) {
  .controls { opacity: 0.78; }
  .controls:hover, .controls:focus-within { opacity: 1; }
}
