* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #0b0d1a; color: #eef; font-family: 'gg sans', 'Segoe UI', system-ui, sans-serif; overflow: hidden; user-select: none; -webkit-user-select: none; touch-action: none; }
button { font: inherit; cursor: pointer; border: 0; border-radius: 10px; padding: 10px 16px; background: #2a2f55; color: #fff; font-weight: 700; transition: transform .08s, background .15s; }
button:hover { background: #363c6e; }
button:active { transform: scale(.96); }
button.primary { background: linear-gradient(135deg, #7c5cff, #ff4fd8); }
.hidden { display: none !important; }

#app { position: relative; height: 100%; display: flex; flex-direction: column; max-width: 640px; margin: 0 auto; }

#hud-top { display: flex; align-items: center; justify-content: space-between; padding: 6px 10px; background: #12152b; gap: 8px; }
.player { display: flex; align-items: center; gap: 8px; font-weight: 700; min-width: 0; flex: 1; }
.player span:not(.crowns) { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player.me { justify-content: flex-end; }
.crowns { display: inline-flex; align-items: center; justify-content: center; min-width: 34px; height: 26px; border-radius: 8px; font-weight: 800; }
.enemy .crowns { background: #ff4d6d33; color: #ff7b93; }
.me .crowns { background: #4d8bff33; color: #7fb0ff; }
.crowns::before { content: '👑'; margin-right: 3px; font-size: 13px; }
#timer { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; padding: 2px 12px; border-radius: 8px; background: #0b0d1a; }
#timer.double { color: #ff4fd8; }
#timer.overtime { color: #ffb02e; }

#stage { position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
#arena { display: block; touch-action: none; }
#banner { position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%); font-size: 26px; font-weight: 900; padding: 10px 22px; border-radius: 12px; background: #000a; pointer-events: none; text-align: center; animation: pop .4s; }
.emote { position: absolute; left: 50%; transform: translateX(-50%); font-size: 40px; pointer-events: none; animation: pop .3s; }
#emote-enemy { top: 8%; }
#emote-me { bottom: 8%; }
@keyframes pop { from { transform: translate(-50%, -50%) scale(.5); opacity: 0; } }
.emote { animation-name: popE; }
@keyframes popE { from { transform: translateX(-50%) scale(.4); opacity: 0; } }

#hud-bottom { background: #12152b; padding: 6px 8px 8px; }
#hand { display: flex; gap: 6px; align-items: flex-end; }
#next { width: 48px; text-align: center; color: #99a; font-size: 10px; }
.cards { flex: 1; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.card { position: relative; height: clamp(62px, 13vh, 112px); border-radius: 10px; background: #1d2142; border: 2px solid #2d3366; display: flex; flex-direction: column; align-items: center; justify-content: center; cursor: grab; transition: transform .1s, border-color .1s, opacity .2s; touch-action: none; }
.card .icon { font-size: clamp(22px, 6vh, 38px); line-height: 1; }
.card .nm { font-size: 10px; margin-top: 4px; text-align: center; color: #ccd; padding: 0 2px; }
.card .cost { position: absolute; top: -6px; left: -6px; width: 22px; height: 22px; border-radius: 50%; background: linear-gradient(135deg, #b44dff, #ff4fd8); font-size: 12px; font-weight: 800; display: flex; align-items: center; justify-content: center; box-shadow: 0 0 6px #ff4fd8aa; }
.card.selected { transform: translateY(-8px); border-color: #ffd84d; box-shadow: 0 0 12px #ffd84d88; }
.card.poor { opacity: .45; filter: grayscale(.6); }
.mini { height: clamp(40px, 8vh, 70px); border-radius: 6px; background: #1d2142; border: 1px solid #2d3366; display: flex; align-items: center; justify-content: center; font-size: 20px; margin-top: 2px; }

#energy { position: relative; height: 20px; margin-top: 8px; border-radius: 10px; background: #1d2142; overflow: hidden; }
#energy-fill { height: 100%; width: 50%; background: linear-gradient(90deg, #b44dff, #ff4fd8); transition: width .1s linear; }
#energy-ticks { position: absolute; inset: 0; background: repeating-linear-gradient(90deg, transparent 0 calc(10% - 2px), #0b0d1a88 calc(10% - 2px) 10%); }
#energy-num { position: absolute; left: 8px; top: 0; line-height: 20px; font-weight: 800; text-shadow: 0 1px 2px #000; }
#emotes { display: flex; gap: 6px; justify-content: center; margin-top: 6px; }
#emotes button { padding: 2px 10px; font-size: 16px; background: #1d2142; }

.overlay { position: absolute; inset: 0; background: #0b0d1aee; display: flex; align-items: center; justify-content: center; z-index: 10; padding: 16px; }
.panel { width: 100%; max-width: 420px; background: #151935; border: 1px solid #2d3366; border-radius: 16px; padding: 20px; text-align: center; }
.panel h1 { margin: 0; font-size: 34px; letter-spacing: 2px; font-weight: 900; }
.panel h1 span { background: linear-gradient(135deg, #7c5cff, #ff4fd8); -webkit-background-clip: text; background-clip: text; color: transparent; }
.sub { color: #99a; margin: 4px 0 16px; }
.seats { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.seat { flex: 1; background: #1d2142; border-radius: 12px; padding: 12px 6px; display: flex; flex-direction: column; gap: 4px; border: 2px solid transparent; }
.seat span { color: #99a; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat.taken span { color: #fff; font-weight: 700; }
.seat.you { border-color: #7c5cff; }
.vs { font-weight: 900; color: #ff4fd8; }
.actions { display: flex; flex-direction: column; gap: 8px; }
#lobby-status { min-height: 1.2em; color: #ffd84d; font-weight: 700; }
#spectators { color: #99a; font-size: 13px; }
.howto { text-align: left; color: #bbc; font-size: 13px; margin-top: 8px; }
.howto summary { cursor: pointer; color: #ccd; }
.howto ul { padding-left: 18px; }
#result-crowns { font-size: 22px; }

/* --- v2 --- */
.panel { max-height: calc(100% - 8px); overflow-y: auto; }
.panel.wide { max-width: 560px; }
.panel h2 { margin: 0 0 10px; font-size: 22px; }
.panel h2 small { font-size: 14px; color: #99a; font-weight: 600; margin-left: 6px; }
#bot-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: center; }
#bot-row span { color: #99a; font-size: 13px; width: 100%; }
#bot-row button { flex: 1; padding: 8px 6px; font-size: 14px; }
#deck-preview { display: flex; align-items: center; gap: 8px; margin: 8px 0; padding: 8px; background: #1d2142; border-radius: 12px; cursor: pointer; }
.dp-cards { flex: 1; display: grid; grid-template-columns: repeat(8, 1fr); gap: 3px; font-size: 18px; }
.dp-cards span { background: #12152b; border-radius: 6px; padding: 3px 0; }
#btn-deck { padding: 6px 10px; font-size: 13px; white-space: nowrap; }
#me-stats { color: #ffd84d; font-weight: 700; margin: 6px 0; }
#leaderboard { margin: 6px 0; padding-left: 26px; }
#leaderboard li { padding: 2px 0; }
#leaderboard li b { float: right; color: #ffd84d; }
.seat em { font-style: normal; font-size: 12px; color: #ffd84d; }
.seat.dc span { color: #ff7b93; }
#result-trophies { font-size: 18px; font-weight: 800; }
#db-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
#db-grid .card { height: auto; aspect-ratio: auto; padding: 10px 2px 6px; cursor: pointer; }
#db-grid .card.in { border-color: #ffd84d; box-shadow: 0 0 10px #ffd84d55; }
#db-grid .card:not(.in) { opacity: .55; }
#db-info { min-height: 3em; color: #ccd; font-size: 13px; margin: 10px 0; }
.db-actions { display: flex; gap: 8px; justify-content: center; }
.db-actions button { flex: 1; }
#btn-mute { position: absolute; top: 46px; left: 8px; z-index: 20; padding: 4px 8px; background: #12152bcc; font-size: 16px; }
#toast { position: absolute; top: 50px; left: 50%; transform: translateX(-50%); z-index: 30; background: #000c; padding: 8px 14px; border-radius: 10px; font-weight: 700; font-size: 14px; pointer-events: none; text-align: center; }
#btn-forfeit { margin-left: 10px; }
#btn-forfeit.armed { background: #ff4d6d; }
.card .cd { position: absolute; inset: 0; border-radius: 8px; background: #0b0d1a99; pointer-events: none; transform-origin: bottom; }
