:root {
  --bg: #170f2e;
  --bg2: #221842;
  --card: #2c2154;
  --card-hi: #392b6a;
  --line: #4a3c80;
  --text: #f7f3ff;
  --muted: #b7acdd;
  --accent: #ffcc33;
  --accent-2: #ff9b3d;
  --accent-ink: #2a1600;
  --hot: #ff5a5f;
  --pink: #ff5ca8;
  --good: #3ddc97;
  --sky: #4cc9f0;
  --radius: 18px;

  /* 움직임: 등장은 강한 ease-out, 화면 위 이동은 ease-in-out, 튀는 연출은 스프링 */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --press: 140ms;

  --font-fun: "Jua", system-ui, -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  --font-body: system-ui, -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
}

* { box-sizing: border-box; }
/* display 를 지정한 요소도 hidden 이면 확실히 숨긴다 */
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
html { overflow-x: hidden; }

/* 배경 빛: 화면 크기 그대로 고정 (움직이지 않음, 넘치지 않음) */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(circle at 0% 0%, rgba(108, 60, 255, .42), transparent 55%),
    radial-gradient(circle at 100% 100%, rgba(255, 61, 139, .26), transparent 55%);
}

#app { max-width: 520px; margin: 0 auto; padding: 16px; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }

h1, h2 { margin: 0; line-height: 1.2; font-family: var(--font-fun); font-weight: 400; }
.muted { color: var(--muted); }
.center-text { text-align: center; }
.row { display: flex; gap: 8px; }
.center-row { justify-content: center; }

/* ───── 버튼: 누르면 바로 반응 ───── */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--bg2); color: var(--text);
  border-radius: 14px; padding: 10px 16px; font: inherit; font-weight: 700; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
  transition: transform var(--press) var(--ease-out), background-color 200ms ease, opacity 200ms ease, box-shadow 200ms ease;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary {
  background: linear-gradient(180deg, #ffd84d, var(--accent) 45%, var(--accent-2));
  color: var(--accent-ink); border-color: transparent;
  box-shadow: 0 6px 0 #c4661c, 0 10px 24px rgba(255, 160, 50, .25);
}
.btn.primary:active:not(:disabled) { transform: translateY(4px) scale(0.99); box-shadow: 0 2px 0 #c4661c, 0 4px 10px rgba(255, 160, 50, .2); }
.btn.ghost { background: transparent; }
.btn.big { width: 100%; padding: 16px; font-size: 20px; border-radius: var(--radius); font-family: var(--font-fun); font-weight: 400; letter-spacing: .01em; }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 10px; }
.btn.glow:not(:disabled) { animation: breathe 2.4s ease-in-out infinite; }
@keyframes breathe {
  50% { box-shadow: 0 6px 0 #c4661c, 0 10px 34px rgba(255, 190, 60, .55); }
}

.card { background: var(--card); border-radius: var(--radius); padding: 16px; border: 1px solid rgba(255,255,255,.06); }
.tag { font-style: normal; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--line); color: var(--text); white-space: nowrap; }
.tag.off { background: transparent; color: var(--muted); }
.tag.hot { background: var(--hot); color: #fff; }
.tag.pulse { animation: tagpulse 1.2s ease-in-out infinite; }
@keyframes tagpulse { 50% { transform: scale(1.06); } }

/* 아바타 */
.av {
  --c: var(--pink);
  flex: none; display: inline-grid; place-items: center;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--c); color: #1b1030; font-family: var(--font-fun); font-size: 16px;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.18);
}
.av.lg { width: 44px; height: 44px; font-size: 22px; }
.av.xl { width: 64px; height: 64px; font-size: 30px; border: 3px solid var(--bg); }
.av.xxl { width: 96px; height: 96px; font-size: 46px; border: 4px solid var(--accent); }

/* ───── 등장 ───── */
.rise { animation: rise 520ms var(--ease-out) both; animation-delay: calc(var(--i, 0) * 70ms); }
:where(.scr.enter > section) > * { animation: rise 420ms var(--ease-out) both; animation-delay: calc(var(--i, 0) * 45ms); }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
.pop-in { animation: popin 380ms var(--spring) both; }
@keyframes popin { from { opacity: 0; transform: scale(.9) translateY(6px); } }
.bump { animation: bump 320ms var(--spring); }
@keyframes bump { 40% { transform: scale(1.12); } }
.shake { animation: shake 420ms var(--ease-out); }
.shake-hard { animation: shakehard 560ms var(--ease-out); }
@keyframes shake { 20% { transform: translateX(-6px) rotate(-1deg); } 40% { transform: translateX(6px) rotate(1deg); } 60% { transform: translateX(-4px); } 80% { transform: translateX(3px); } }
@keyframes shakehard { 10% { transform: translate(-10px, 4px) rotate(-2deg); } 25% { transform: translate(10px, -6px) rotate(2deg); } 40% { transform: translate(-8px, 6px); } 55% { transform: translate(7px, -3px); } 70% { transform: translate(-4px, 2px); } 85% { transform: translate(2px, -1px); } }
.flash { position: fixed; inset: 0; z-index: 50; pointer-events: none; animation: flash 520ms ease-out forwards; }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }
.fx-canvas { position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: 60; pointer-events: none; }

/* ───── 첫 화면 ───── */
.landing { padding-top: 48px; display: grid; gap: 24px; position: relative; }
.brand { font-size: 48px; letter-spacing: -0.01em; }
.brand.small { font-size: 32px; }
.wobble span { display: inline-block; animation: letter 700ms var(--spring) both; animation-delay: calc(var(--i) * 45ms); }
@keyframes letter { from { opacity: 0; transform: translateY(24px) rotate(-8deg) scale(.8); } }
.wobble span:nth-child(odd) { color: var(--accent); }
.tagline { margin: -12px 0 0; color: var(--muted); font-size: 18px; }
.steps { margin: 0; padding-left: 20px; color: var(--muted); display: grid; gap: 6px; }
.games { display: grid; gap: 10px; }
.games h2 { font-size: 18px; color: var(--muted); }
.game-card { display: flex; gap: 14px; align-items: center; background: var(--card); border-radius: var(--radius); padding: 14px 16px; border: 1px solid rgba(255,255,255,.06); }
.game-card p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.gicon { font-size: 32px; line-height: 1; display: inline-block; }
.game-card:nth-child(2) .gicon { animation: bob 3s ease-in-out infinite; }
.game-card:nth-child(3) .gicon { animation: bob 3s ease-in-out .6s infinite; }
.gicon.sm { font-size: 18px; margin-right: 6px; vertical-align: -2px; }
@keyframes bob { 50% { transform: translateY(-5px) rotate(-6deg); } }
.langs { text-align: center; color: var(--muted); }
.langs a { color: var(--muted); }
.floaters { position: absolute; inset: 0; pointer-events: none; }
.floaters span { position: absolute; font-size: 28px; opacity: .55; animation: float 6s ease-in-out infinite; }
.floaters span:nth-child(1) { top: 6px; right: 8%; animation-delay: 0s; }
.floaters span:nth-child(2) { top: 92px; right: 0; font-size: 22px; animation-delay: -1.5s; }
.floaters span:nth-child(3) { top: 150px; right: 24%; font-size: 20px; animation-delay: -3s; }
.floaters span:nth-child(4) { top: -14px; left: 58%; font-size: 18px; animation-delay: -4.5s; }
@keyframes float { 50% { transform: translateY(-12px) rotate(10deg); } }

/* 이름 입력 */
.center { padding-top: 64px; display: grid; gap: 16px; text-align: center; }
.code { color: var(--muted); font-weight: 700; letter-spacing: .1em; margin: 0; }
.name-form { display: grid; gap: 12px; text-align: left; }
input {
  font: inherit; font-size: 18px; padding: 14px 16px; border-radius: 14px; border: 2px solid var(--line);
  background: var(--bg2); color: var(--text); width: 100%;
  transition: border-color 200ms ease, box-shadow 200ms ease;
}
input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px rgba(255, 204, 51, .18); }

/* ───── 방 공통 ───── */
.hdr { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.hdr { gap: 8px; }
.brand-s { font-family: var(--font-fun); font-size: 18px; display: inline-flex; align-items: center; gap: 6px; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logo-dot { display: inline-block; animation: spin-slow 8s linear infinite; }
@keyframes spin-slow { to { transform: rotate(360deg); } }
.hdr-r { display: flex; gap: 6px; align-items: center; flex: none; }
.banner { background: var(--hot); color: #fff; border-radius: 12px; padding: 8px 12px; margin-bottom: 12px; text-align: center; animation: rise 300ms var(--ease-out); }
.scr section { display: grid; gap: 16px; }
.round { margin: 0; color: var(--muted); text-align: center; font-weight: 700; }
.round.tb { color: var(--hot); font-family: var(--font-fun); font-size: 22px; animation: tagpulse 1s ease-in-out infinite; }
.status { text-align: center; font-size: 26px; min-height: 32px; }
.slam { animation: slam 420ms var(--spring); }
@keyframes slam { from { transform: scale(1.8); opacity: 0; } }
.note { margin: 0; text-align: center; background: var(--bg2); border-radius: 12px; padding: 8px; color: var(--muted); }
.waiting-dots::after { content: ""; display: inline-block; width: 1.2em; text-align: left; animation: dots 1.4s steps(4) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }

.plist { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.plist li {
  display: flex; align-items: center; gap: 10px; background: var(--card); border-radius: 14px; padding: 8px 12px;
  border: 2px solid transparent;
  transition: background-color 260ms ease, border-color 260ms ease, opacity 260ms ease, transform 260ms var(--ease-out);
}
.plist .pname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.plist li.off { opacity: .45; }
.plist li.hot { border-color: var(--accent); background: var(--card-hi); }
.plist li.out { opacity: .6; transform: scale(.98); }
.plist li.lost { background: var(--hot); color: #fff; }
.plist em { font-style: normal; color: var(--muted); font-size: 13px; font-weight: 400; }
.plist li.lost em { color: #ffe; }
.tags { display: flex; gap: 6px; align-items: center; font-size: 14px; }

/* 로비 */
.lobby h2 { font-size: 20px; }
.invite p { margin: 0 0 10px; }
.invite .btn { flex: 1; }
.hostctl { display: grid; gap: 10px; }
.hostctl label { font-size: 14px; color: var(--muted); }
.segs { display: flex; gap: 6px; background: var(--bg2); padding: 4px; border-radius: 14px; }
.seg {
  flex: 1; padding: 10px; border-radius: 10px; border: 0; background: transparent; color: var(--muted);
  font: inherit; font-weight: 700; cursor: pointer;
  transition: background-color 200ms ease, color 200ms ease, transform var(--press) var(--ease-out);
}
.seg:active { transform: scale(.97); }
.seg.on { background: var(--text); color: var(--bg); }

/* ───── 카드 뒤집기 ───── */
.timebar { height: 6px; border-radius: 99px; background: var(--bg2); overflow: hidden; }
.timebar i { display: block; height: 100%; background: linear-gradient(90deg, var(--good), var(--accent)); transform-origin: left; transition: transform 120ms linear, background 300ms ease; }
.timebar i.low { background: var(--hot); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 12px; perspective: 900px; }
.cards.deal .pcard { animation: deal 520ms var(--spring) both; animation-delay: calc(var(--d) * 70ms); }
@keyframes deal { from { opacity: 0; transform: translateY(-40px) rotate(-14deg) scale(.7); } }
.pcard {
  position: relative; display: grid; gap: 6px; padding: 0; border: 0; background: none; color: var(--text);
  font: inherit; cursor: pointer;
  transition: transform 220ms var(--ease-out);
}
.pcard:not(:disabled):active { transform: scale(.95); }
.pcard:disabled { cursor: default; }
.pcard .flip {
  position: relative; display: block; aspect-ratio: 3 / 4;
  transform-style: preserve-3d;
  transition: transform 620ms var(--spring);
}
.pcard.flipped .flip { transform: rotateY(180deg); }
.pcard .side {
  position: absolute; inset: 0; border-radius: 16px; display: grid; place-items: center; align-content: center; gap: 4px;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  box-shadow: 0 6px 0 rgba(0,0,0,.25);
}
.pcard .back {
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,.06) 0 10px, transparent 10px 20px),
    linear-gradient(160deg, #5b3fd1, #3a2690);
  border: 3px solid rgba(255,255,255,.18);
}
.pcard .mark { font-family: var(--font-fun); font-size: 36px; color: rgba(255,255,255,.85); }
.pcard:not(:disabled):not(.taken) .back { animation: idle 2.6s ease-in-out infinite; animation-delay: calc(var(--d) * -.4s); }
@keyframes idle { 50% { transform: translateY(-4px); } }
.pcard.taken .back { background: linear-gradient(160deg, #3a2f66, #2a2150); border-color: rgba(255,255,255,.1); }
.pcard.mine .back { border-color: var(--accent); box-shadow: 0 6px 0 rgba(0,0,0,.25), 0 0 0 4px rgba(255,204,51,.25); }
.pcard.mine .flip { transform: translateY(-8px); }
.pcard.mine.flipped .flip { transform: translateY(-8px) rotateY(180deg); }
.pcard.claim .mark { animation: popin 360ms var(--spring); }
.pcard .front { transform: rotateY(180deg); background: var(--card-hi); }
.pcard .res { display: grid; justify-items: center; gap: 4px; }
.pcard .front b { font-size: 34px; line-height: 1; }
.pcard .front span { font-family: var(--font-fun); font-size: 18px; }
.pcard.safe .front { background: linear-gradient(160deg, #5ff0b0, var(--good)); color: #053d26; }
.pcard.bomb .front { background: linear-gradient(160deg, #ff7b7f, var(--hot)); color: #fff; }
.pcard.bomb.flipped .flip { animation: bombpop 700ms 360ms var(--spring) both; }
@keyframes bombpop { 0% { scale: 1; } 40% { scale: 1.18; } 100% { scale: 1.06; } }
.pcard .owner { font-size: 13px; min-height: 18px; color: var(--muted); text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pcard.mine .owner { color: var(--accent); font-weight: 700; }

/* ───── 치킨 버튼 ───── */
.bigtime { text-align: center; font-family: var(--font-fun); font-size: 64px; line-height: 1; font-variant-numeric: tabular-nums; }
.bigtime.pop { animation: digit 600ms var(--spring); }
@keyframes digit { from { transform: scale(1.9); opacity: 0; } }
.hold-wrap { --beat: 1s; position: relative; width: 236px; height: 236px; margin: 4px auto; display: grid; place-items: center; }
.hold-wrap .ring {
  position: absolute; inset: 0; border-radius: 50%;
  background: conic-gradient(from 0deg, var(--accent), var(--pink), var(--sky), var(--accent));
  opacity: .5; filter: blur(10px);
  animation: spin-slow 6s linear infinite;
}
.hold-wrap.beating .ring { opacity: .8; animation: spin-slow 2s linear infinite, beat var(--beat) ease-in-out infinite; }
.hold-wrap.beating.mine .hold-btn { animation: beat var(--beat) ease-in-out infinite; }
@keyframes beat { 0%, 100% { scale: 1; } 15% { scale: 1.07; } 30% { scale: .98; } 45% { scale: 1.04; } }
.hold-btn {
  position: relative; width: 210px; height: 210px; border-radius: 50%; border: 0;
  background: radial-gradient(circle at 35% 30%, #4a3a8a, var(--bg2) 70%);
  box-shadow: 0 10px 0 #120a26, inset 0 0 0 6px var(--accent);
  color: var(--text); font: inherit; cursor: pointer;
  display: grid; place-items: center; align-content: center; gap: 4px;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  transition: transform 120ms var(--ease-out), box-shadow 120ms var(--ease-out), background 240ms ease;
}
.hb-icon { font-size: 54px; line-height: 1; transition: transform 200ms var(--spring); }
.hb-label { font-family: var(--font-fun); font-size: 20px; }
.hold-btn.pressing, .hold-btn.holding {
  transform: translateY(8px);
  background: radial-gradient(circle at 35% 30%, #ffe27a, var(--accent) 60%, var(--accent-2));
  box-shadow: 0 2px 0 #120a26, inset 0 0 0 6px #fff3;
  color: var(--accent-ink);
}
.hold-btn.holding .hb-icon { transform: scale(1.1) rotate(-8deg); }
.hold-btn.boom { background: radial-gradient(circle at 35% 30%, #ff9a9c, var(--hot)); color: #fff; }
.hold-btn.boom .hb-icon { transform: scale(1.3) rotate(12deg); }
.hold-btn:disabled { opacity: .45; }
.chk.exploded .bigtime { color: var(--hot); }

/* ───── 결과 ───── */
.loser-wrap { display: grid; justify-items: center; gap: 10px; }
.loser-avs { display: flex; }
.loser-avs .av + .av { margin-left: -14px; }
.loser-avs .av { animation: drop 600ms var(--spring) both; }
@keyframes drop { from { opacity: 0; transform: translateY(-50px) rotate(-20deg); } }
.loser { text-align: center; font-size: 34px; color: var(--accent); text-shadow: 0 3px 0 rgba(0,0,0,.3); }
.stamp { animation: stamp 520ms 180ms var(--spring) both; }
@keyframes stamp { from { opacity: 0; transform: scale(2.4) rotate(-10deg); } to { transform: rotate(-3deg); } }
.board { width: 100%; border-collapse: collapse; }
.board th { font-size: 12px; color: var(--muted); font-weight: 600; padding: 4px 8px; }
.board td { padding: 8px; border-top: 1px solid var(--line); }
.board tbody tr { animation: rise 420ms var(--ease-out) both; animation-delay: calc(500ms + var(--r) * 70ms); }
.board tr.lost td { color: var(--hot); }
.board .who { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; }
.board .who .av { width: 26px; height: 26px; font-size: 13px; }
.board em { font-style: normal; color: var(--muted); font-size: 13px; font-weight: 400; }
.board .ok { color: var(--good); opacity: 0; transform: scale(.4); transition: opacity 200ms ease, transform 300ms var(--spring); }
.board .ok.on { opacity: 1; transform: none; }
.board .plus { display: inline-block; color: var(--hot); font-weight: 800; animation: floatup 700ms var(--spring) both; animation-delay: calc(650ms + var(--r) * 70ms); }
@keyframes floatup { from { opacity: 0; transform: translateY(10px) scale(.6); } }
.board b { display: inline-block; font-family: var(--font-fun); font-weight: 400; font-size: 18px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.king-wrap { display: grid; justify-items: center; gap: 8px; position: relative; padding-top: 40px; }
.king-wrap .av { animation: popin 600ms 200ms var(--spring) both; }
.crown { position: absolute; top: 0; z-index: 2; font-size: 44px; line-height: 1; animation: crown 900ms 500ms var(--spring) both; }
@keyframes crown { from { opacity: 0; transform: translateY(-80px) rotate(-30deg); } 70% { transform: translateY(4px) rotate(6deg); } to { transform: rotate(-8deg); } }
.king { text-align: center; font-size: 52px; color: var(--hot); text-shadow: 0 4px 0 rgba(0,0,0,.3); animation: stamp 600ms 350ms var(--spring) both; }
.stake { text-align: center; font-size: 18px; margin: 0; background: var(--card); border: 2px dashed var(--accent); border-radius: 14px; padding: 10px; }
.standings li { animation: rise 420ms var(--ease-out) both; animation-delay: calc(700ms + var(--r) * 70ms); }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 99px; font-weight: 700; max-width: 90vw; z-index: 70;
}
.toast.show { animation: toast 320ms var(--ease-out); }
@keyframes toast { from { opacity: 0; transform: translate(-50%, 12px); } }

/* 광고 자리: 승인 전에는 아무것도 보이지 않음 */
.ad-slot { display: none; }
/* 채워진 광고 자리: 화면 맨 아래, 위 버튼과 충분히 떨어뜨리고 자리를 미리 잡아 둔다(광고가 뜨며 화면이 밀려 잘못 누르지 않게) */
.ad-slot.on { display: block; margin-top: 40px; min-height: 120px; text-align: center; }
.landing .ad-slot.on { margin-top: 8px; }
.ad-label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 4px; letter-spacing: .04em; }
.ad-fake { height: 100px; display: grid; place-items: center; border: 2px dashed var(--line); border-radius: 12px; color: var(--muted); font-size: 13px; }

/* 움직임 줄이기: 장식 움직임은 끄고 상태 변화만 남긴다 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    animation-delay: 0ms !important;
    transition-duration: .01ms !important;
  }
  .pcard .flip { transition: none; }
}
