:root {
  --bg: #12101a;
  --panel: #1c1930;
  --line: #2f2a4a;
  --ink: #ece9ff;
  --muted: #9c95c4;
  --gold: #f5c451;
  --red: #ff6b6b;
  --green: #62d295;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: radial-gradient(circle at 50% -10%, #2a2350, var(--bg) 60%);
  color: var(--ink);
  font-family: "Pretendard", "Noto Sans KR", system-ui, sans-serif;
  min-height: 100vh;
}
.topbar { text-align: center; padding: 28px 16px 8px; }
.topbar h1 { margin: 0; font-size: 30px; letter-spacing: -.5px; }
.sub { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
main { max-width: 900px; margin: 0 auto; padding: 16px; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
  margin-bottom: 18px;
}
.hidden { display: none !important; }
h2 { margin: 0 0 12px; font-size: 19px; }
h3 { margin: 18px 0 8px; font-size: 15px; color: var(--muted); font-weight: 600; }
label { display: block; font-size: 13px; margin-bottom: 6px; color: var(--muted); }
input {
  width: 100%; padding: 11px 12px; border-radius: 9px;
  border: 1px solid var(--line); background: #16142a; color: var(--ink); font-size: 14px;
}
.hint { color: var(--muted); font-size: 12px; margin: 6px 0 0; }
.msg { min-height: 20px; font-size: 13px; margin: 10px 0 0; }
.msg.err { color: var(--red); }
.msg.ok { color: var(--green); }

button {
  font-family: inherit; cursor: pointer; border-radius: 10px; font-size: 14px;
  border: 1px solid transparent; padding: 11px 18px;
}
.primary { background: var(--gold); color: #241d05; font-weight: 700; width: 100%; margin-top: 16px; }
.primary.big { width: auto; padding: 14px 30px; font-size: 16px; margin: 0; }
.primary:disabled { opacity: .45; cursor: not-allowed; }
.ghost { background: transparent; border-color: var(--line); color: var(--muted); padding: 7px 12px; }

.card-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.pick {
  text-align: left; background: #16142a; border: 1px solid var(--line);
  color: var(--ink); padding: 12px; display: block; width: 100%;
}
.pick.on { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold) inset; }
.pick .n { display: block; font-weight: 700; margin-bottom: 4px; }
.pick .s { display: block; font-size: 12px; color: var(--muted); }
.pick .f { display: block; font-size: 11px; color: #6f689a; margin-top: 6px; }

.arena-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.battlefield {
  display: grid; grid-template-columns: 1fr auto 1fr; gap: 18px;
  align-items: center; margin-top: 18px;
}
.side { text-align: center; }
.side-label { font-size: 11px; letter-spacing: 2px; color: var(--muted); }
.middle { text-align: center; }

.battle-card { perspective: 800px; width: 100%; max-width: 190px; margin: 10px auto; }
.flip {
  position: relative; width: 100%; aspect-ratio: 3/4;
  transform-style: preserve-3d; transition: transform .45s ease;
}
.battle-card.hit .flip { transform: rotateY(180deg); }
.face {
  position: absolute; inset: 0; backface-visibility: hidden;
  border-radius: 12px; border: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
}
.front { background: linear-gradient(160deg, #2b2550, #1a1730); }
.king .front { border-color: var(--gold); }
.back { transform: rotateY(180deg); background: #3a1f2b; font-size: 44px; }
.emoji { font-size: 40px; }
.cname { font-weight: 700; font-size: 14px; }
.stat { font-size: 12px; color: var(--muted); }

.hpbar { height: 10px; background: #16142a; border-radius: 6px; overflow: hidden; border: 1px solid var(--line); }
.fill { height: 100%; width: 100%; background: linear-gradient(90deg, #62d295, #f5c451); transition: width .3s ease; }
.hpnum { font-size: 13px; margin: 6px 0 0; }

.damage-pop {
  height: 34px; margin: 12px 0 0; font-size: 26px; font-weight: 800; color: var(--red);
  opacity: 0; transform: translateY(0);
}
.damage-pop.show { animation: pop .9s ease-out; }
@keyframes pop {
  0% { opacity: 0; transform: translateY(6px) scale(.8); }
  25% { opacity: 1; transform: translateY(-4px) scale(1.15); }
  100% { opacity: 0; transform: translateY(-22px) scale(1); }
}

.flag {
  margin-top: 18px; padding: 12px; border-radius: 10px;
  background: #17301f; border: 1px solid #2f5c3f; color: var(--green);
  font-family: ui-monospace, monospace; font-size: 13px; word-break: break-all;
}

.middle input { max-width: 160px; margin: 0 auto 12px; display: block; text-align: center; }
#king-tools { margin-top: 14px; }

.boards { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 18px; }
.board {
  margin: 0; padding: 0 0 0 22px; font-size: 13px; max-height: 260px; overflow-y: auto;
}
.board li { padding: 3px 0; color: var(--muted); }
.board li.me { color: var(--ink); font-weight: 700; }
.board li.king { color: var(--gold); }

@media (max-width: 700px) {
  .battlefield, .boards { grid-template-columns: 1fr; }
}
