:root {
  --font: "Arial Black", "Trebuchet MS", sans-serif;
  --navy: #141a33; --orange: #ff8a2a; --cyan: #3fe0ff; --cream: #fff3dc; --ink: #1a1230;
  --ol: 0 2px 0 var(--ink), 2px 0 0 var(--ink), -2px 0 0 var(--ink), 0 -2px 0 var(--ink), 2px 2px 0 var(--ink), -2px 2px 0 var(--ink), 2px -2px 0 var(--ink), -2px -2px 0 var(--ink), 0 4px 0 rgba(0,0,0,.45);
}
html, body { margin: 0; height: 100%; background: #0a0d1c; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; }
#app { position: fixed; top: 0; bottom: 0; width: min(100vw, 56.25vh); left: max(0px, calc(50vw - 28.125vh)); overflow: hidden; font-family: var(--font); background: #10152c; }
#stage, #fx2d { position: absolute; left: 0; top: 0; width: 100%; height: 100%; display: block; }
#fx2d { pointer-events: none; }
.hidden { display: none !important; }

/* HUD */
#hud { position: absolute; inset: 0; pointer-events: none; }
.hudbox { position: absolute; left: 10px; background: rgba(14, 18, 40, .78); border: 2px solid rgba(255, 138, 42, .75); border-radius: 10px; color: #fff; text-shadow: var(--ol); box-shadow: 0 3px 0 rgba(0,0,0,.35); }
#hudRound { top: calc(10px + env(safe-area-inset-top)); max-width: calc(100% - 96px); padding: 5px 12px 6px; }
#hudRoundT { font-size: 16px; color: #ffb35c; font-weight: 900; }
#hudTheme { font-size: 14px; font-weight: 900; margin-top: 1px; }
#hudGold { top: calc(74px + env(safe-area-inset-top)); display: flex; align-items: center; gap: 5px; padding: 3px 10px 3px 5px; font-size: 17px; font-weight: 900; }
#hudGold img { width: 24px; height: 24px; }

#caption { position: absolute; left: 10px; right: 10px; top: calc(118px + env(safe-area-inset-top)); display: flex; align-items: center; gap: 8px; pointer-events: none; animation: capIn .25s cubic-bezier(.2,1.5,.4,1); }
#capFace { width: 44px; height: 44px; flex: none; border-radius: 10px; border: 2px solid var(--cyan); background: #223 url(assets/judge.webp) 50% 6% / 280% no-repeat; }
#capText { background: rgba(14,18,40,.85); border: 2px solid rgba(63,224,255,.6); border-radius: 10px; padding: 6px 10px; color: #fff; font-size: 15px; font-weight: 900; text-shadow: var(--ol); line-height: 1.3; }
@keyframes capIn { from { transform: translateY(-14px); opacity: 0; } }

/* Title */
#title { position: absolute; inset: 0; background: #0d1124 url(assets/cover-bg.webp) center / cover no-repeat; overflow: hidden; }
#title::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 32%; background: linear-gradient(transparent, rgba(8,10,25,.7)); pointer-events: none; }
#titleLogo { position: absolute; left: 50%; top: 8%; width: 82%; max-height: 30%; object-fit: contain; transform: translateX(-50%); animation: logoIn .7s cubic-bezier(.2,1.5,.4,1) both, logoFloat 3.2s ease-in-out .7s infinite; filter: drop-shadow(0 6px 0 rgba(0,0,0,.35)); }
@keyframes logoIn { from { transform: translateX(-50%) scale(.3) translateY(-60px); opacity: 0; } }
@keyframes logoFloat { 50% { transform: translateX(-50%) translateY(-6px); } }
#titlePrompt { position: absolute; left: 12%; right: 12%; bottom: 13%; text-align: center; font-size: 24px; font-weight: 900; color: #fff; text-shadow: var(--ol); animation: pulse 1.4s ease-in-out infinite; z-index: 1; padding: 0 16px; }
#titleKeys { position: absolute; left: 0; right: 0; bottom: 8%; text-align: center; font-size: 14px; color: #cfe6ff; text-shadow: var(--ol); z-index: 1; padding: 0 16px; }
@keyframes pulse { 50% { transform: scale(1.07); opacity: .8; } }
.corner { position: absolute; top: calc(10px + env(safe-area-inset-top)); width: 48px; height: 48px; border-radius: 50%; background: rgba(16, 22, 48, .62); border: 2px solid rgba(255, 190, 110, .55); display: flex; align-items: center; justify-content: center; padding: 0; cursor: pointer; z-index: 2; transition: transform .1s; }
.corner:active { transform: scale(.9); }
.corner.right { right: 10px; }
.corner.left { left: 10px; }
.corner.left2 { left: 66px; }
#btnShop.hidden + #btnBag { left: 10px; }
#titleGold { position: absolute; top: calc(18px + env(safe-area-inset-top)); left: 122px; display: flex; align-items: center; gap: 4px; padding: 3px 10px 3px 4px; border-radius: 16px; background: rgba(16,22,48,.62); color: #fff; font-size: 16px; font-weight: 900; text-shadow: var(--ol); z-index: 2; }
#titleGold img { width: 24px; height: 24px; }

/* Panels and buttons */
#modal { position: absolute; inset: 0; pointer-events: none; z-index: 20; }
.layer { position: absolute; inset: 0; background: rgba(6, 8, 20, .5); pointer-events: auto; animation: fadeIn .2s; }
.layer.clear { background: transparent; pointer-events: none; }
.layer.clear .panel { pointer-events: auto; }
@keyframes fadeIn { from { opacity: 0; } }
.panel { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(90%, 380px); max-height: 86%; box-sizing: border-box; overflow: hidden auto;
  border: 22px solid #2b3150; border-image: url(assets/ui-panel.webp) 64 fill / 22px stretch; background: transparent;
  padding: 6px 8px; color: var(--cream); display: flex; flex-direction: column; align-items: stretch; gap: 10px; animation: pop .28s cubic-bezier(.2,1.6,.4,1); text-align: center; }
.panel.low { top: auto; bottom: 22%; transform: translate(-50%, 0); animation: popLow .28s cubic-bezier(.2,1.6,.4,1); }
.panel.closing { animation: popOut .16s ease-in forwards; }
.panel.low.closing { animation: popOutLow .16s ease-in forwards; }
@keyframes pop { from { transform: translate(-50%, -50%) scale(.6); opacity: 0; } }
@keyframes popOut { to { transform: translate(-50%, -50%) scale(.8); opacity: 0; } }
@keyframes popLow { from { transform: translate(-50%, 20px) scale(.7); opacity: 0; } }
@keyframes popOutLow { to { transform: translate(-50%, 10px) scale(.85); opacity: 0; } }
.ptitle { font-size: 22px; font-weight: 900; color: #ffb35c; text-shadow: var(--ol); line-height: 1.2; }
.psub { font-size: 15px; font-weight: 900; color: #fff; text-shadow: var(--ol); line-height: 1.4; }
.pbig { font-size: 30px; font-weight: 900; color: #fff; text-shadow: var(--ol); line-height: 1.15; }
.pnote { font-size: 13px; color: #b9c8ea; line-height: 1.4; font-family: var(--font); }
.prow { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 4px; }
.btn { font-family: var(--font); font-weight: 900; font-size: 18px; color: #fff; text-shadow: var(--ol); min-height: 54px; min-width: 120px; padding: 6px 24px 9px; box-sizing: border-box;
  border: 0; background: url(assets/ui-button.webp) 52.8% 47.8% / 108.2% 268.8% no-repeat; image-rendering: pixelated; cursor: pointer; transition: transform .1s, filter .1s;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; line-height: 1.1; }
.btn img { width: 26px; height: 26px; }
.btn:active, .btn.press { transform: scale(.92); }
.btn.focus { filter: brightness(1.25) drop-shadow(0 0 6px #3fe0ff); transform: scale(1.05); }
.btn.sec { filter: hue-rotate(185deg) saturate(.7) brightness(.95); }
.btn.sec.focus { filter: hue-rotate(185deg) saturate(.7) brightness(1.2) drop-shadow(0 0 6px #ffcc66); }
.btn.small { font-size: 15px; min-height: 46px; min-width: 96px; }
.btn.wide { width: 100%; }
#skipBtn { position: absolute; bottom: calc(26px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); z-index: 2; }
#skipBtn:active { transform: translateX(-50%) scale(.92); }

/* Contestants, cards, ranking */
.face { width: 52px; height: 52px; border-radius: 10px; border: 2px solid rgba(255,255,255,.5); background-color: #2a3358; background-repeat: no-repeat; background-size: 260%; background-position: 50% 7%; flex: none; image-rendering: auto; }
.face.pix { background-size: cover; background-position: center; image-rendering: pixelated; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px 4px; }
.cell { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 12px; font-weight: 900; color: #fff; text-shadow: var(--ol); animation: rowIn .3s both; }
.cell.me .face { border-color: #ffb35c; box-shadow: 0 0 0 2px #ffb35c; }
.cell.rv .face { border-color: #ff5a5a; }
.rank { display: flex; flex-direction: column; gap: 4px; }
.rrow { display: flex; align-items: center; gap: 8px; padding: 3px 8px 3px 4px; border-radius: 10px; background: rgba(255,255,255,.07); animation: rowIn .3s both; }
.rrow .face { width: 38px; height: 38px; }
.rrow .nm { flex: 1; text-align: left; font-size: 15px; font-weight: 900; color: #fff; text-shadow: var(--ol); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rrow .sc { font-size: 19px; font-weight: 900; color: #ffd27a; text-shadow: var(--ol); min-width: 38px; text-align: right; }
.rrow.me { background: rgba(255,138,42,.28); outline: 2px solid #ffb35c; }
.rrow.out { opacity: .42; filter: grayscale(1); }
.rrow .tag { font-size: 12px; font-weight: 900; padding: 2px 6px; border-radius: 6px; color: #fff; text-shadow: var(--ol); }
.tag.go { background: #1d9c5a; } .tag.no { background: #b3302a; }
.cutline { height: 0; border-top: 3px dashed #ff5a5a; margin: 2px 0; position: relative; }
@keyframes rowIn { from { transform: translateX(-30px); opacity: 0; } }
.judges { display: flex; gap: 6px; justify-content: center; }
.jcard { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 4px; border-radius: 10px; background: rgba(255,255,255,.08); animation: cardIn .35s cubic-bezier(.2,1.6,.4,1) both; }
.jcard .face { width: 46px; height: 46px; }
.jcard .jn { font-size: 12px; font-weight: 900; color: #cfe6ff; text-shadow: var(--ol); }
.jcard .js { font-size: 32px; font-weight: 900; color: #ffd27a; text-shadow: var(--ol); }
@keyframes cardIn { from { transform: rotateY(90deg) scale(.6); opacity: 0; } }
.vs { display: flex; align-items: center; justify-content: space-around; gap: 6px; }
.vs .side { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.vs .face { width: 72px; height: 72px; }
.vs .big { font-size: 40px; font-weight: 900; color: #ffd27a; text-shadow: var(--ol); }
.vs .mid { font-size: 26px; font-weight: 900; color: #ff5a5a; text-shadow: var(--ol); }
.win .face { box-shadow: 0 0 0 3px #ffd27a, 0 0 18px #ffd27a; }
.items { display: flex; flex-direction: column; gap: 6px; }
.irow { display: flex; align-items: center; gap: 8px; padding: 4px 8px; border-radius: 10px; background: rgba(255,255,255,.07); text-align: left; }
.irow img { width: 44px; height: 44px; flex: none; }
.irow .in { flex: 1; min-width: 0; }
.irow .in b { display: block; font-size: 15px; color: #fff; text-shadow: var(--ol); }
.irow .in span { font-size: 12px; color: #b9c8ea; }
.irow .cnt { font-size: 18px; font-weight: 900; color: #ffd27a; text-shadow: var(--ol); }
.gold { display: inline-flex; align-items: center; gap: 4px; font-weight: 900; color: #ffd27a; text-shadow: var(--ol); font-size: 18px; }
.gold img { width: 26px; height: 26px; }
canvas.sil { display: block; margin: 0 auto; max-width: 100%; }
.howto { text-align: left; font-size: 14px; line-height: 1.5; color: #fff; text-shadow: 0 1px 0 #000; }
.howto b { color: #ffb35c; }

/* Banner */
#banner { position: absolute; left: 0; right: 0; top: 54%; pointer-events: none; z-index: 25; text-align: center; }
.bn { display: inline-block; padding: 10px 26px; font-size: 38px; font-weight: 900; color: #fff; text-shadow: var(--ol); background: linear-gradient(90deg, transparent, rgba(255,138,42,.85) 15%, rgba(255,138,42,.85) 85%, transparent); animation: slam .45s cubic-bezier(.2,1.8,.4,1) both; max-width: 92%; box-sizing: border-box; }
.bn.sub { font-size: 20px; display: block; margin: 0 auto; background: none; animation-delay: .1s; }
.bn.bad { background: linear-gradient(90deg, transparent, rgba(190,40,40,.9) 15%, rgba(190,40,40,.9) 85%, transparent); }
.bn.cyan { background: linear-gradient(90deg, transparent, rgba(30,150,200,.9) 15%, rgba(30,150,200,.9) 85%, transparent); }
.bn.gold { background: linear-gradient(90deg, transparent, rgba(230,170,30,.92) 15%, rgba(230,170,30,.92) 85%, transparent); font-size: 46px; }
.bn.out { animation: slamOut .25s ease-in forwards; }
@keyframes slam { from { transform: scale(2.6); opacity: 0; } }
@keyframes slamOut { to { transform: scale(.7) translateY(-20px); opacity: 0; } }

#intro { position: absolute; inset: 0; z-index: 30; background: #000 url(assets/cover-bg.webp) center / cover no-repeat; }
#introVideo { width: 100%; height: 100%; object-fit: cover; display: block; }
#fade { position: absolute; inset: 0; background: #0a0d1c; opacity: 0; pointer-events: none; z-index: 40; transition: opacity .35s; }
#fade.on { opacity: 1; }
