/* Beatles Brainrot: Merch Heist. Client styles (menus + HUD). */
:root {
    --gold: #FFD700;
    --purple: #9370DB;
    --pink: #FF69B4;
    --orange: #FFA500;
    --teal: #20B2AA;
    --red: #ff3b5c;
    --green: #4CD964;
    --dark: #1a0a2e;
    --dark2: #2d1b4e;
    --panel: rgba(26, 10, 46, 0.82);
    --panel-solid: linear-gradient(145deg, rgba(45, 27, 78, 0.96), rgba(26, 10, 46, 0.97));
    --border: rgba(147, 112, 219, 0.55);
    --font: 'Fredoka', 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
    background: var(--dark);
    color: #fff;
    font-family: var(--font);
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
}
body.in-game { touch-action: none; user-select: none; -webkit-user-select: none; }
button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }
.hidden { display: none !important; }

/* ------------------------------------------------ psychedelic background */
#bg {
    position: fixed; inset: 0; z-index: 0; overflow: hidden;
    background: radial-gradient(ellipse at center, #2d1b4e 0%, #1a0a2e 100%);
}
#bg .ring { position: absolute; border-radius: 50%; animation: bb-rot 40s linear infinite; }
#bg .ring:nth-child(1) { width: 640px; height: 640px; top: -220px; right: -220px; background: radial-gradient(circle, transparent 30%, var(--purple) 31%, transparent 32%, transparent 45%, var(--pink) 46%, transparent 47%); }
#bg .ring:nth-child(2) { width: 420px; height: 420px; bottom: -120px; left: -120px; animation-direction: reverse; background: radial-gradient(circle, transparent 40%, var(--pink) 41%, transparent 42%); }
#bg .ring:nth-child(3) { width: 300px; height: 300px; top: 55%; left: 60%; background: radial-gradient(circle, transparent 35%, var(--gold) 36%, transparent 37%); }
#bg .ring:nth-child(4) { width: 200px; height: 200px; top: 12%; left: 8%; background: radial-gradient(circle, transparent 30%, var(--teal) 31%, transparent 33%); }
@keyframes bb-rot { to { transform: rotate(360deg); } }

#stage { position: fixed; inset: 0; z-index: 1; }
#stage canvas { display: block; width: 100%; height: 100%; touch-action: none; }

/* ------------------------------------------------ screens & panels */
.screen {
    position: fixed; inset: 0; z-index: 30;
    overflow-y: auto; -webkit-overflow-scrolling: touch;
    display: flex; justify-content: center; align-items: flex-start;
    padding: 24px 16px 40px;
}
.screen.dim { background: rgba(10, 4, 22, 0.72); backdrop-filter: blur(3px); }
.panel {
    width: 100%; max-width: 780px; margin: auto;
    background: var(--panel-solid);
    border: 2px solid var(--border);
    border-radius: 22px;
    padding: 22px;
    box-shadow: 0 0 30px rgba(147, 112, 219, 0.35), 0 0 60px rgba(255, 105, 180, 0.12);
}
.logo {
    font-size: clamp(2.1rem, 8vw, 3.6rem);
    line-height: 1.02; font-weight: 700; text-align: center;
    background: linear-gradient(90deg, var(--gold), var(--pink), var(--purple), var(--teal), var(--gold));
    background-size: 300% 100%;
    -webkit-background-clip: text; background-clip: text;
    -webkit-text-fill-color: transparent; color: transparent;
    animation: bb-shift 6s ease infinite;
}
@keyframes bb-shift { 0%, 100% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } }
.subtitle {
    text-align: center; color: var(--gold); letter-spacing: 0.3em; text-transform: uppercase;
    font-size: clamp(0.85rem, 3.4vw, 1.15rem); margin: 4px 0 18px; font-weight: 600;
}
.tagline { text-align: center; color: #d9c8ff; font-size: 0.95rem; margin: -8px 0 18px; }
h2.section { font-size: 1rem; color: var(--pink); text-transform: uppercase; letter-spacing: 0.12em; margin: 18px 0 8px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.text-input {
    width: 100%; padding: 12px 14px; border-radius: 12px; font-size: 1.1rem;
    background: rgba(0, 0, 0, 0.35); color: #fff; border: 2px solid var(--border); outline: none;
}
.text-input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(255, 215, 0, 0.2); }

.btn {
    border: none; border-radius: 14px; padding: 12px 18px; font-size: 1.05rem; font-weight: 700;
    color: #1a0a2e; background: linear-gradient(135deg, var(--gold), var(--orange));
    box-shadow: 0 4px 0 #a86d00, 0 6px 18px rgba(255, 165, 0, 0.3);
    transition: transform 0.08s, filter 0.15s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #a86d00; }
.btn:disabled { filter: grayscale(0.8) brightness(0.7); cursor: not-allowed; transform: none; }
.btn.pink { background: linear-gradient(135deg, var(--pink), var(--purple)); color: #fff; box-shadow: 0 4px 0 #6b2f8f, 0 6px 18px rgba(255, 105, 180, 0.3); }
.btn.teal { background: linear-gradient(135deg, #36d6c8, var(--teal)); color: #08201f; box-shadow: 0 4px 0 #0d6b66; }
.btn.ghost { background: rgba(255, 255, 255, 0.08); color: #fff; box-shadow: none; border: 2px solid var(--border); }
.btn.big { font-size: 1.25rem; padding: 15px 22px; width: 100%; }

.row { display: flex; gap: 10px; align-items: stretch; flex-wrap: wrap; }
.row > .grow { flex: 1 1 160px; }

/* beatle picker */
.beatle-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.beatle-card {
    border: 2px solid var(--border); border-radius: 16px; padding: 10px 6px; text-align: center;
    background: rgba(0, 0, 0, 0.25); color: #fff; transition: transform 0.12s, border-color 0.12s, box-shadow 0.12s;
}
.beatle-card:hover { transform: translateY(-2px); }
.beatle-card .em { font-size: 2rem; display: block; }
.beatle-card .nm { font-weight: 700; font-size: 1.05rem; display: block; }
.beatle-card .mv { font-size: 0.75rem; color: #cbb8f5; display: block; }
.beatle-card.sel { border-color: var(--gold); box-shadow: 0 0 16px rgba(255, 215, 0, 0.55); background: rgba(255, 215, 0, 0.1); }
.move-desc {
    margin-top: 10px; padding: 10px 12px; border-radius: 12px; background: rgba(32, 178, 170, 0.12);
    border: 1px solid rgba(32, 178, 170, 0.5); font-size: 0.92rem; color: #dffbf8;
}

/* map picker */
.map-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.map-card {
    text-align: left; border: 2px solid var(--border); border-radius: 14px; padding: 10px 12px; color: #fff;
    background: rgba(0, 0, 0, 0.25); min-height: 74px; position: relative; overflow: hidden;
}
.map-card::before { content: ''; position: absolute; inset: 0; opacity: 0.28; pointer-events: none; }
.map-card[data-map="abbey"]::before { background: repeating-linear-gradient(90deg, #fff 0 14px, #333 14px 28px); opacity: 0.12; }
.map-card[data-map="submarine"]::before { background: radial-gradient(circle at 80% 30%, #ffe14d 0 14%, transparent 15%), linear-gradient(180deg, #0f6a7a, #0a3350); }
.map-card[data-map="pepper"]::before { background: linear-gradient(135deg, #d4202c, #f7b733 60%, #2f8f3a); }
.map-card[data-map="mystery"]::before { background: linear-gradient(135deg, #ff5fd2, #8a5cff, #3ad7ff, #ffe35a); }
.map-card .mn { position: relative; font-weight: 700; font-size: 1.02rem; }
.map-card .mb { position: relative; font-size: 0.8rem; color: #e8dcff; margin-top: 3px; }
.map-card.sel { border-color: var(--gold); box-shadow: 0 0 16px rgba(255, 215, 0, 0.5); }
.map-card:disabled { cursor: default; }
.map-card.readonly:not(.sel) { opacity: 0.45; }

.join-row { display: flex; gap: 10px; }
.join-row .text-input { text-transform: uppercase; letter-spacing: 0.35em; text-align: center; font-weight: 700; max-width: 170px; }
.or { text-align: center; color: #9b87c9; margin: 14px 0 8px; font-size: 0.85rem; letter-spacing: 0.2em; }
.classic-link { display: block; text-align: center; margin-top: 18px; color: var(--teal); font-weight: 600; text-decoration: none; }
.classic-link:hover { text-decoration: underline; }
.howto { margin-top: 14px; background: rgba(0, 0, 0, 0.22); border-radius: 12px; padding: 10px 14px; font-size: 0.9rem; color: #e2d6ff; }
.howto summary { cursor: pointer; color: var(--gold); font-weight: 600; }
.howto ul { margin: 8px 0 2px 18px; }
.howto li { margin: 3px 0; }

/* lobby */
.code-box { text-align: center; margin: 4px 0 6px; }
.code-box .lbl { color: #b9a5e8; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.2em; }
.code-box .code {
    font-size: clamp(3rem, 16vw, 4.6rem); font-weight: 700; letter-spacing: 0.18em; color: var(--gold);
    text-shadow: 0 0 22px rgba(255, 215, 0, 0.55);
}
.player-list { list-style: none; display: grid; gap: 8px; }
.player-list li {
    display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 12px;
    background: rgba(0, 0, 0, 0.28); border-left: 6px solid var(--c, #888);
}
.player-list .em { font-size: 1.4rem; }
.player-list .pn { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-size: 0.72rem; padding: 2px 8px; border-radius: 99px; background: rgba(255, 255, 255, 0.12); color: #ddd; }
.tag.host { background: rgba(255, 215, 0, 0.2); color: var(--gold); }
.tag.you { background: rgba(255, 105, 180, 0.22); color: var(--pink); }
.waiting { text-align: center; color: #cbb8f5; padding: 14px; font-size: 1.05rem; animation: bb-pulse 1.8s ease-in-out infinite; }
@keyframes bb-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

/* end screen */
.end-title { text-align: center; font-size: clamp(1.8rem, 7vw, 2.6rem); font-weight: 700; color: var(--gold); text-shadow: 0 0 20px rgba(255, 215, 0, 0.5); }
.end-sub { text-align: center; color: #e2d6ff; margin: 4px 0 16px; }
.rank-list { list-style: none; display: grid; gap: 8px; }
.rank-list li { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 14px; background: rgba(0, 0, 0, 0.3); font-size: 1.05rem; }
.rank-list li.first { background: linear-gradient(90deg, rgba(255, 215, 0, 0.35), rgba(255, 165, 0, 0.12)); border: 2px solid var(--gold); font-size: 1.2rem; }
.rank-list li.me { outline: 2px solid var(--pink); }
.rank-list .pos { width: 2.2em; text-align: center; font-weight: 700; }
.rank-list .pn { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-list .w { font-weight: 700; color: var(--gold); }

/* ------------------------------------------------ HUD */
#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
#hud .pe { pointer-events: auto; }
.hud-box {
    background: var(--panel); border: 2px solid var(--border); border-radius: 16px;
    backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
}
#hud-money { position: absolute; top: 10px; left: 10px; padding: 8px 14px 9px; min-width: 150px; }
#hud-coins { font-size: 1.9rem; font-weight: 700; color: var(--gold); text-shadow: 0 0 12px rgba(255, 215, 0, 0.45); line-height: 1.1; display: inline-block; transition: transform 0.12s; }
#hud-coins.bump { transform: scale(1.18); }
#hud-coins.drop { color: #ffb0b0; }
#hud-till { font-size: 0.85rem; color: #bff7f2; margin-top: 1px; }
#hud-till b { color: #fff; }
#hud-income { font-size: 0.78rem; color: #9fe39f; }

#hud-timer {
    position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
    padding: 6px 16px; font-size: 1.6rem; font-weight: 700; letter-spacing: 0.05em; text-align: center;
}
#hud-timer .map-name { display: block; font-size: 0.68rem; font-weight: 500; color: #cbb8f5; letter-spacing: 0.08em; text-transform: uppercase; }
#hud-timer.warn { color: var(--red); border-color: var(--red); animation: bb-pulse 0.8s infinite; }

#hud-board { position: absolute; top: 10px; right: 10px; width: 210px; padding: 8px 10px; font-size: 0.86rem; }
#hud-board .ttl { font-size: 0.7rem; color: var(--pink); text-transform: uppercase; letter-spacing: 0.15em; margin-bottom: 4px; display: flex; justify-content: space-between; }
#hud-board ol { list-style: none; }
#hud-board li { display: flex; gap: 6px; padding: 2px 0; align-items: center; }
#hud-board li .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
#hud-board li .pn { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#hud-board li .w { color: var(--gold); font-weight: 600; }
#hud-board li.me { color: var(--pink); font-weight: 700; }
#hud-board li.sep { justify-content: center; color: #8d7ab8; padding: 0; line-height: 0.8; }

#hud-buttons { position: absolute; top: 10px; right: 230px; display: flex; gap: 6px; }
.icon-btn {
    width: 40px; height: 40px; border-radius: 12px; font-size: 1.15rem; color: #fff;
    background: var(--panel); border: 2px solid var(--border);
}

#announcer {
    position: absolute; top: 92px; left: 50%; transform: translateX(-50%);
    width: min(92vw, 640px); text-align: center; font-weight: 700;
    font-size: clamp(1.15rem, 4.6vw, 1.9rem); color: #fff; line-height: 1.15;
    text-shadow: 0 0 10px rgba(0, 0, 0, 0.9), 0 3px 0 rgba(0, 0, 0, 0.6), 0 0 26px var(--ann, var(--pink));
    opacity: 0;
}
#announcer.show { animation: bb-ann 3.4s ease forwards; }
@keyframes bb-ann {
    0% { opacity: 0; transform: translateX(-50%) scale(0.6) rotate(-3deg); }
    8% { opacity: 1; transform: translateX(-50%) scale(1.12) rotate(1deg); }
    14% { transform: translateX(-50%) scale(1) rotate(0); }
    85% { opacity: 1; }
    100% { opacity: 0; transform: translateX(-50%) translateY(-10px); }
}

#toasts { position: fixed; z-index: 70; pointer-events: none; left: 10px; top: 110px; display: flex; flex-direction: column; gap: 6px; width: min(340px, 70vw); }
body:not(.in-game) #toasts { left: 50%; transform: translateX(-50%); top: 12px; align-items: center; width: min(420px, 92vw); }
.toast {
    padding: 7px 12px; border-radius: 12px; font-size: 0.88rem; background: var(--panel);
    border-left: 5px solid var(--teal); animation: bb-toast-in 0.25s ease; transition: opacity 0.4s, transform 0.4s;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}
.toast.err { border-left-color: var(--red); }
.toast.good { border-left-color: var(--gold); }
.toast.bad { border-left-color: var(--pink); }
.toast.out { opacity: 0; transform: translateX(-20px); }
@keyframes bb-toast-in { from { opacity: 0; transform: translateX(-20px); } to { opacity: 1; transform: none; } }

#steal-alert {
    position: absolute; top: 140px; left: 50%; transform: translateX(-50%);
    background: rgba(200, 20, 50, 0.9); border: 2px solid #ffb3c0; border-radius: 14px;
    padding: 8px 16px; font-weight: 700; font-size: clamp(0.95rem, 3.8vw, 1.2rem); white-space: nowrap;
    max-width: 94vw; overflow: hidden; text-overflow: ellipsis;
    animation: bb-shake 0.5s infinite;
}
@keyframes bb-shake { 0%, 100% { transform: translateX(-50%); } 25% { transform: translateX(calc(-50% - 3px)); } 75% { transform: translateX(calc(-50% + 3px)); } }
#edge-flash {
    position: absolute; inset: 0; box-shadow: inset 0 0 70px 18px rgba(255, 30, 60, 0.85); opacity: 0;
}
#edge-flash.on { animation: bb-edge 0.9s ease-in-out infinite; }
@keyframes bb-edge { 0%, 100% { opacity: 0.15; } 50% { opacity: 1; } }
#flash { position: absolute; inset: 0; opacity: 0; background: #fff; }
#flash.go { animation: bb-flash 0.5s ease-out; }
@keyframes bb-flash { from { opacity: var(--fo, 0.55); } to { opacity: 0; } }
#stun-overlay { position: absolute; inset: 0; background: radial-gradient(circle, transparent 40%, rgba(255, 220, 60, 0.28)); opacity: 0; transition: opacity 0.2s; }
#stun-overlay.on { opacity: 1; }

#prompt {
    position: absolute; bottom: 116px; left: 50%; transform: translateX(-50%);
    padding: 10px 18px; border-radius: 16px; font-size: 1.1rem; font-weight: 600; white-space: nowrap;
    background: var(--panel); border: 2px solid var(--gold); display: flex; align-items: center; gap: 10px;
    max-width: 94vw; overflow: hidden; text-overflow: ellipsis;
}
#prompt .key {
    display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 8px;
    background: var(--gold); color: #1a0a2e; font-weight: 800; flex: none; position: relative;
}
#prompt.bad { border-color: var(--red); color: #ffc3cc; }
#prompt.bad .key { background: #77606a; }
#prompt.info { border-color: var(--teal); }
#prompt.info .key { display: none; }
#prompt .ring { width: 30px; height: 30px; border-radius: 50%; flex: none; background: conic-gradient(var(--gold) calc(var(--p, 0) * 1turn), rgba(255, 255, 255, 0.15) 0); display: none; }
#prompt.stealing .ring { display: block; }
#prompt.stealing .key { display: none; }

#upgrades {
    position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%);
    display: flex; gap: 8px; padding: 8px; max-width: 96vw;
}
#upgrades .ttl { writing-mode: vertical-rl; transform: rotate(180deg); font-size: 0.65rem; letter-spacing: 0.15em; color: var(--pink); text-transform: uppercase; text-align: center; }
.up-btn {
    border: 2px solid var(--border); border-radius: 12px; background: rgba(0, 0, 0, 0.35); color: #fff;
    padding: 6px 10px; min-width: 112px; text-align: left; line-height: 1.15;
}
.up-btn .ul { font-weight: 700; font-size: 0.9rem; display: block; }
.up-btn .uv { font-size: 0.74rem; color: #cbb8f5; display: block; }
.up-btn .uc { font-size: 0.85rem; color: var(--gold); font-weight: 700; display: block; }
.up-btn .hk { float: right; font-size: 0.7rem; color: #9b87c9; margin-left: 6px; }
.up-btn.can { border-color: var(--gold); box-shadow: 0 0 10px rgba(255, 215, 0, 0.35); }
.up-btn:disabled { opacity: 0.5; cursor: default; }

/* ability button (desktop + touch) */
#ability-btn {
    position: absolute; right: 18px; bottom: 18px; width: 74px; height: 74px; border-radius: 50%;
    border: 3px solid var(--teal); background: conic-gradient(rgba(10, 4, 22, 0.75) calc(var(--cd, 0) * 1turn), rgba(32, 178, 170, 0.55) 0);
    color: #fff; font-size: 1.9rem; display: flex; align-items: center; justify-content: center; flex-direction: column; line-height: 1;
    box-shadow: 0 0 16px rgba(32, 178, 170, 0.5);
}
#ability-btn .k { font-size: 0.62rem; font-weight: 700; margin-top: 2px; }
#ability-btn.ready { animation: bb-ready 1.6s ease-in-out infinite; }
#ability-btn.cooling { border-color: #555; box-shadow: none; }
#ability-btn.active { border-color: var(--gold); box-shadow: 0 0 26px var(--gold); }
@keyframes bb-ready { 0%, 100% { box-shadow: 0 0 10px rgba(32, 178, 170, 0.5); } 50% { box-shadow: 0 0 26px rgba(32, 178, 170, 0.95); } }

/* touch controls */
#touch { position: absolute; inset: 0; }
#joy-zone { position: absolute; left: 0; top: 30%; bottom: 0; width: 55%; pointer-events: auto; touch-action: none; }
#joy-base {
    position: absolute; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.35); background: rgba(255, 255, 255, 0.08); opacity: 0.55; transition: opacity 0.15s;
    left: 90px; bottom: 30px; top: auto;
}
#joy-base.on { opacity: 1; }
#joy-knob {
    position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px 0 0 -27px; border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, #fff, var(--pink)); box-shadow: 0 0 14px var(--pink);
}
#action-btn {
    position: absolute; right: 16px; bottom: 22px; width: 104px; height: 104px; border-radius: 50%;
    border: 4px solid var(--gold); color: #1a0a2e; font-weight: 800; font-size: 0.8rem; line-height: 1.05;
    background: radial-gradient(circle at 35% 30%, #fff6b0, var(--gold) 55%, var(--orange));
    box-shadow: 0 6px 0 #a86d00, 0 0 20px rgba(255, 215, 0, 0.5); padding: 8px; overflow: hidden; touch-action: none;
}
#action-btn.idle { opacity: 0.45; }
#action-btn.bad { background: radial-gradient(circle at 35% 30%, #ffd0d8, #c9566a); border-color: #ffb3c0; color: #fff; box-shadow: 0 6px 0 #6b1b2a; }
#action-btn.pressed { transform: translateY(4px); box-shadow: 0 2px 0 #a86d00; }
#action-btn .ring { position: absolute; inset: -4px; border-radius: 50%; pointer-events: none; background: conic-gradient(rgba(255, 59, 92, 0.65) calc(var(--p, 0) * 1turn), transparent 0); }
#action-btn span { position: relative; }
body.touch #ability-btn { right: 132px; bottom: 30px; width: 66px; height: 66px; font-size: 1.6rem; }
body.touch #prompt { bottom: 136px; left: auto; right: 12px; transform: none; font-size: 0.95rem; padding: 7px 12px; max-width: 70vw; }
body.touch #prompt .key { display: none; }
body.touch #upgrades { bottom: auto; top: 118px; left: auto; right: 8px; transform: none; flex-direction: column; padding: 6px; }
body.touch #upgrades .ttl { writing-mode: horizontal-tb; transform: none; }
body.touch .up-btn { min-width: 0; width: 132px; padding: 5px 8px; }
body.touch .up-btn .hk { display: none; }

/* base marker */
#base-arrow {
    position: absolute; left: 0; top: 0; width: 64px; height: 64px; margin: -32px 0 0 -32px;
    display: flex; align-items: center; justify-content: center;
}
#base-arrow .arr {
    position: absolute; width: 0; height: 0; border-left: 14px solid transparent; border-right: 14px solid transparent;
    border-bottom: 24px solid var(--mc, var(--gold)); top: -6px; left: 18px; transform-origin: 14px 38px;
    filter: drop-shadow(0 0 6px rgba(0, 0, 0, 0.8));
}
#base-arrow .ico {
    width: 40px; height: 40px; border-radius: 50%; background: var(--panel); border: 3px solid var(--mc, var(--gold));
    display: flex; align-items: center; justify-content: center; font-size: 1.2rem;
}
#base-arrow .dist { position: absolute; top: 46px; font-size: 0.7rem; font-weight: 700; text-shadow: 0 1px 3px #000; white-space: nowrap; }
#base-arrow.urgent .ico { animation: bb-pulse 0.6s infinite; }

/* world-anchored DOM bits */
#world-ui { position: absolute; inset: 0; overflow: hidden; }
.pop {
    position: absolute; left: 0; top: 0; transform: translate(-50%, -50%); font-weight: 800; white-space: nowrap;
    font-size: 1.4rem; color: var(--gold); text-shadow: 0 2px 0 #000, 0 0 10px rgba(0, 0, 0, 0.7); will-change: transform, opacity;
}
.pop.big { font-size: 2.1rem; }
.steal-ring {
    position: absolute; left: 0; top: 0; width: 44px; height: 44px; margin: -22px 0 0 -22px; border-radius: 50%;
    background: conic-gradient(var(--red) calc(var(--p, 0) * 1turn), rgba(0, 0, 0, 0.45) 0);
    border: 3px solid #fff; display: flex; align-items: center; justify-content: center; font-size: 1.1rem;
}

/* overlays */
#disconnected { z-index: 60; align-items: center; }
#disconnected .panel { max-width: 380px; text-align: center; }
#loading { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 14px; background: rgba(10, 4, 22, 0.75); }
.spinner { width: 54px; height: 54px; border-radius: 50%; border: 4px solid var(--dark2); border-top-color: var(--gold); animation: bb-rot 0.9s linear infinite; }

/* ------------------------------------------------ phones */
@media (max-width: 640px) {
    .panel { padding: 16px; border-radius: 18px; }
    .beatle-grid { grid-template-columns: repeat(2, 1fr); }
    .map-grid { grid-template-columns: 1fr; }
    .map-card { min-height: 0; }
    #hud-money { padding: 6px 10px; min-width: 0; top: 8px; left: 8px; }
    #hud-coins { font-size: 1.45rem; }
    #hud-till { font-size: 0.74rem; }
    #hud-income { font-size: 0.7rem; }
    #hud-timer { top: 8px; font-size: 1.2rem; padding: 4px 10px; }
    #hud-timer .map-name { display: none; }
    #hud-board { width: 132px; top: 8px; right: 8px; font-size: 0.72rem; padding: 6px 8px; }
    #hud-board .ttl span:last-child { display: none; }
    #hud-buttons { top: 54px; right: auto; left: 50%; transform: translateX(-50%); }
    #hud-buttons .icon-btn { width: 34px; height: 34px; font-size: 0.95rem; border-radius: 10px; }
    #announcer { top: 140px; }
    body.in-game #toasts { top: 200px; left: 8px; width: 52vw; }
    .toast { font-size: 0.78rem; padding: 5px 9px; }
    #steal-alert { top: 96px; }
    body.touch #upgrades { top: 150px; }
}
@media (max-width: 380px) {
    #hud-board { width: 118px; }
    .up-btn .uv { display: none; }
}

/* v3 polish: lobby bots + collapsible upgrades on touch */
#btn-add-bot { width: 100%; margin-top: 8px; }
.player-list .tag.bot { background: rgba(32, 178, 170, 0.25); color: #9ff3ec; }
.player-list .tag.kick { cursor: pointer; border: 0; background: rgba(255, 80, 110, 0.25); color: #ffb3c0; font: inherit; }
.player-list .tag.kick:hover { background: rgba(255, 80, 110, 0.45); }
body.touch #upgrades .ttl { cursor: pointer; padding: 4px 6px; }
body.touch #upgrades .ttl::after { content: ' ▾'; }
body.touch #upgrades.collapsed .ttl::after { content: ' ▸'; }
body.touch #upgrades.collapsed .up-btn { display: none; }

/* v3.1: reconnect overlay */
#reconnecting {
    position: fixed; inset: 0; z-index: 66; display: flex; align-items: center; justify-content: center; padding: 16px;
    background: rgba(10, 4, 22, 0.66); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
#reconnecting .panel { max-width: 360px; width: 100%; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 6px; }
#reconnecting .rc-title { font-size: 1.6rem; }
#reconnecting .end-sub { margin: 2px 0 10px; min-height: 2.4em; }
#reconnecting #btn-rc-leave { min-width: 140px; }

/* v3.1: touch layout. Joystick zone stops before the right-hand button column; the ability button
   sits above the action button so the two never overlap, and the prompt sits above both. */
body.touch #joy-zone { width: auto; right: 150px; }
body.touch #ability-btn { right: 35px; bottom: 140px; width: 64px; height: 64px; font-size: 1.55rem; }
body.touch #prompt { bottom: 218px; right: 10px; max-width: calc(100vw - 20px); }
body.touch #upgrades { top: 182px; max-height: calc(100vh - 420px); overflow-y: auto; }
@media (max-width: 640px) {
    #hud-board { max-height: 132px; overflow: hidden; }
    body.touch #upgrades { top: 150px; max-height: calc(100vh - 400px); }
    body.touch #joy-zone { right: 140px; top: 35%; }
    body.touch #joy-base { left: 76px; }
}
@media (max-height: 520px) {
    /* landscape phones: put the ability button beside the action button instead of above it */
    body.touch #ability-btn { right: 130px; bottom: 26px; }
    body.touch #joy-zone { right: 210px; }
    body.touch #prompt { bottom: 140px; }
    #hud-buttons { top: 98px; left: 10px; right: auto; transform: none; }
    #hud-board { width: 150px; right: 8px; font-size: 0.74rem; padding: 6px 8px; }
    #hud-board .ttl span:last-child { display: none; }
    body.touch #upgrades { top: 72px; right: auto; left: 50%; transform: translateX(-50%); flex-direction: row; max-height: none; overflow: visible; }
    body.touch .up-btn { width: 96px; }
    body.touch .up-btn .uv { display: none; }
}

/* =====================================================================================
   v4: skin tiers, encore events, collection book, outfits, juice
   ===================================================================================== */

/* ---- one top-centre column: event banner, steal alert, announcer. They stack, never overlap. */
#hud-stack {
    position: absolute; top: 84px; left: 0; right: 0; margin: 0 auto; transform: none;
    width: min(92vw, 600px); display: flex; flex-direction: column; align-items: center; gap: 8px;
}
/* the upgrade panel is a child of the stack: pinned to the bottom of the screen on desktop,
   in the column (right under the event banner) on touch screens */
#upgrades { position: fixed; }
body.touch #upgrades {
    position: static; top: auto; right: auto; left: auto; bottom: auto; transform: none; align-self: flex-end;
    max-height: 38vh; overflow-y: auto; flex: none;
}
#announcer { position: static; top: auto; left: auto; transform: none; width: 100%; display: none; }
#announcer.show { display: block; animation: bb-ann 3.4s ease forwards; }
@keyframes bb-ann {
    0% { opacity: 0; transform: scale(0.6) rotate(-3deg); }
    8% { opacity: 1; transform: scale(1.12) rotate(1deg); }
    14% { transform: scale(1) rotate(0); }
    85% { opacity: 1; transform: none; }
    100% { opacity: 0; transform: translateY(-10px); }
}
#steal-alert { position: static; top: auto; left: auto; transform: none; animation: bb-shake 0.5s infinite; }
@keyframes bb-shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }

/* ---- encore event banner */
#event-banner {
    --ev: #FFD700; --ev-glow: rgba(255, 215, 0, 0.45);
    position: relative; display: flex; align-items: center; gap: 10px; max-width: 100%;
    padding: 7px 16px 13px 12px; border-radius: 16px; overflow: hidden;
    background: linear-gradient(135deg, rgba(26, 10, 46, 0.94), rgba(45, 27, 78, 0.94));
    border: 2px solid var(--ev);
    box-shadow: 0 0 22px var(--ev-glow), inset 0 0 26px -6px var(--ev-glow), 0 4px 18px rgba(0, 0, 0, 0.4);
    animation: bb-eb-in 0.55s cubic-bezier(0.2, 1.5, 0.4, 1);
    transition: padding 0.45s ease, opacity 0.4s ease, transform 0.4s ease;
}
#event-banner::before {
    content: ''; position: absolute; inset: 0; pointer-events: none; opacity: 0.5;
    background: linear-gradient(105deg, transparent 35%, var(--ev-glow) 50%, transparent 65%);
    background-size: 250% 100%; animation: bb-eb-sheen 2.6s linear infinite;
}
@keyframes bb-eb-sheen { from { background-position: 130% 0; } to { background-position: -130% 0; } }
@keyframes bb-eb-in { from { opacity: 0; transform: scale(0.4) translateY(-20px); } to { opacity: 1; transform: none; } }
#event-banner.out { opacity: 0; transform: translateY(-12px) scale(0.92); }
.eb-ico { position: relative; font-size: 1.7rem; line-height: 1; flex: none; transition: font-size 0.45s ease; filter: drop-shadow(0 0 8px var(--ev-glow)); }
.eb-main { position: relative; min-width: 0; }
.eb-top { display: flex; align-items: center; gap: 8px; font-size: 0.6rem; letter-spacing: 0.18em; text-transform: uppercase; color: #cbb8f5; font-weight: 600; }
.eb-time { margin-left: auto; padding: 1px 8px; border-radius: 99px; background: rgba(0, 0, 0, 0.4); color: #fff; font-weight: 700; letter-spacing: 0.04em; font-size: 0.7rem; }
.eb-name { font-weight: 700; font-size: 1.15rem; line-height: 1.1; color: var(--ev); text-shadow: 0 0 14px var(--ev-glow), 0 2px 0 rgba(0, 0, 0, 0.5); transition: font-size 0.45s ease; white-space: nowrap; }
.eb-desc { font-size: 0.78rem; color: #f1e9ff; line-height: 1.2; transition: font-size 0.45s ease; }
.eb-bar { position: absolute; left: 10px; right: 10px; bottom: 5px; height: 4px; border-radius: 99px; background: rgba(255, 255, 255, 0.14); overflow: hidden; }
.eb-bar i { display: block; width: 100%; height: 100%; border-radius: 99px; background: var(--ev); transform-origin: left center; box-shadow: 0 0 8px var(--ev); will-change: transform; }
#event-banner.intro { padding: 12px 24px 18px 18px; }
#event-banner.intro .eb-ico { font-size: 2.9rem; animation: bb-eb-wob 0.6s ease-in-out infinite; }
#event-banner.intro .eb-name { font-size: clamp(1.6rem, 6.4vw, 2.3rem); }
#event-banner.intro .eb-desc { font-size: clamp(0.9rem, 3.4vw, 1.05rem); }
@keyframes bb-eb-wob { 0%, 100% { transform: rotate(-9deg) scale(1); } 50% { transform: rotate(9deg) scale(1.14); } }

#event-tint {
    --ev: #FFD700; position: absolute; inset: 0; opacity: 0; transition: opacity 0.9s ease; pointer-events: none;
    box-shadow: inset 0 0 120px 26px var(--ev);
}
#event-tint.on { opacity: 0.3; }
#hud-income.boost { color: var(--gold); font-weight: 700; text-shadow: 0 0 8px rgba(255, 215, 0, 0.6); }

/* ---- HUD buttons: sound, music, book, leave */
.icon-btn { position: relative; display: inline-flex; align-items: center; justify-content: center; padding: 0; line-height: 1; background: rgba(74, 50, 122, 0.88); }
.icon-btn.off { opacity: 0.55; }
.icon-btn.off::after { content: ''; position: absolute; left: 18%; right: 18%; top: 50%; height: 3px; margin-top: -1.5px; border-radius: 2px; background: #ff5c7a; transform: rotate(-38deg); box-shadow: 0 0 0 1.5px rgba(26, 10, 46, 0.9); }
.icon-btn .badge {
    position: absolute; top: -6px; right: -6px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 99px;
    background: var(--pink); color: #fff; font-size: 0.62rem; font-weight: 800; font-style: normal; line-height: 17px; text-align: center;
    box-shadow: 0 0 0 2px #1a0a2e;
}
#btn-book.ping { animation: bb-ping 0.7s cubic-bezier(0.2, 1.6, 0.4, 1) 2; border-color: var(--gold); }
@keyframes bb-ping { 0%, 100% { transform: scale(1); } 45% { transform: scale(1.32) rotate(-8deg); box-shadow: 0 0 18px var(--gold); } }

.title-tools { display: flex; justify-content: center; margin: -6px 0 6px; }
.chip-btn {
    display: inline-flex; align-items: center; gap: 8px; padding: 7px 14px; border-radius: 99px; font-size: 0.95rem; font-weight: 600;
    color: #fff; background: rgba(255, 255, 255, 0.07); border: 2px solid var(--border); transition: transform 0.1s, border-color 0.15s, box-shadow 0.15s;
}
.chip-btn:hover { border-color: var(--gold); box-shadow: 0 0 14px rgba(255, 215, 0, 0.35); transform: translateY(-1px); }
.chip-btn b { color: var(--gold); background: rgba(0, 0, 0, 0.35); border-radius: 99px; padding: 1px 9px; font-size: 0.85rem; }

/* ---- outfit picker with live 3D preview */
.look-row { display: grid; grid-template-columns: 210px 1fr; gap: 12px; align-items: stretch; }
.look-stage {
    position: relative; height: 250px; border-radius: 16px; border: 2px solid var(--border); overflow: hidden; cursor: grab; touch-action: pan-y;
    background:
        radial-gradient(ellipse 70% 46% at 50% 0%, rgba(255, 215, 0, 0.3), transparent 70%),
        radial-gradient(ellipse 90% 40% at 50% 104%, rgba(255, 105, 180, 0.4), transparent 70%),
        linear-gradient(180deg, rgba(20, 8, 40, 0.75), rgba(55, 30, 100, 0.55));
}
.look-stage:active { cursor: grabbing; }
.look-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.look-spot {
    position: absolute; left: 50%; top: -12%; width: 150%; height: 105%; transform: translateX(-50%); pointer-events: none;
    background: conic-gradient(from 180deg at 50% 0%, transparent 157deg, rgba(255, 244, 200, 0.2) 168deg, rgba(255, 244, 200, 0.3) 180deg, rgba(255, 244, 200, 0.2) 192deg, transparent 203deg);
}
.look-name {
    position: absolute; left: 6px; right: 6px; bottom: 7px; text-align: center; font-size: 0.8rem; font-weight: 700; color: var(--gold);
    text-shadow: 0 1px 3px #000, 0 0 8px rgba(0, 0, 0, 0.8); pointer-events: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.outfit-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.outfit-card {
    display: flex; flex-direction: column; justify-content: center; gap: 5px; text-align: left; color: #fff;
    border: 2px solid var(--border); border-radius: 14px; padding: 10px 12px; background: rgba(0, 0, 0, 0.25);
    transition: transform 0.12s, border-color 0.12s, box-shadow 0.12s;
}
.outfit-card:hover { transform: translateY(-2px); }
.outfit-card .sw { display: block; height: 10px; border-radius: 99px; box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.35); }
.outfit-card .on { font-weight: 700; font-size: 1rem; line-height: 1.1; }
.outfit-card .ot { font-size: 0.76rem; color: #cbb8f5; line-height: 1.15; }
.outfit-card.sel { border-color: var(--gold); box-shadow: 0 0 16px rgba(255, 215, 0, 0.55); background: rgba(255, 215, 0, 0.1); }
.player-list .tag.fit { background: rgba(147, 112, 219, 0.28); color: #dccbff; }

/* ---- collection book */
#book {
    position: fixed; inset: 0; z-index: 80; display: flex; align-items: center; justify-content: center; padding: 14px;
    background: rgba(10, 4, 22, 0.8); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); animation: bb-fade 0.18s ease;
}
@keyframes bb-fade { from { opacity: 0; } to { opacity: 1; } }
.book-panel {
    width: 100%; max-width: 880px; max-height: 100%; display: flex; flex-direction: column; overflow: hidden;
    background: var(--panel-solid); border: 2px solid var(--border); border-radius: 22px;
    box-shadow: 0 0 30px rgba(147, 112, 219, 0.4), 0 0 70px rgba(255, 105, 180, 0.15);
    animation: bb-book-in 0.28s cubic-bezier(0.2, 1.3, 0.5, 1);
}
@keyframes bb-book-in { from { transform: scale(0.9) translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }
.book-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px 8px; }
.book-title { flex: 1; font-size: clamp(1.15rem, 5vw, 1.5rem); font-weight: 700; color: var(--gold); text-shadow: 0 0 14px rgba(255, 215, 0, 0.4); }
.book-count { font-weight: 600; font-size: 1.05rem; color: #cbb8f5; white-space: nowrap; }
.book-count b { color: #fff; font-size: 1.6rem; }
.book-bar { height: 9px; margin: 0 16px; border-radius: 99px; background: rgba(255, 255, 255, 0.1); overflow: hidden; flex: none; }
.book-bar i { display: block; height: 100%; width: 0; border-radius: 99px; background: linear-gradient(90deg, var(--gold), var(--pink), var(--purple), var(--teal)); transition: width 0.6s ease; }
.book-tiers { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 16px 8px; flex: none; }
.tier-chip {
    --tc: #fff; border: 1.5px solid var(--tc); color: var(--tc); border-radius: 99px; padding: 3px 11px; font-size: 0.78rem; font-weight: 700;
    background: rgba(0, 0, 0, 0.3); white-space: nowrap;
}
.tier-chip b { color: #fff; margin-left: 4px; font-weight: 600; }
.tier-chip.done { background: var(--tc); color: #1a0a2e; }
.tier-chip.done b { color: #1a0a2e; }
.book-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 16px 16px; overscroll-behavior: contain; }
.book-sec { --tc: #fff; }
.book-sec h3 { display: flex; align-items: baseline; gap: 8px; margin: 12px 0 7px; font-size: 0.98rem; color: var(--tc); text-transform: uppercase; letter-spacing: 0.12em; }
.book-sec h3 small { font-size: 0.74rem; font-weight: 500; color: #b9a5e8; letter-spacing: 0; text-transform: none; }
.book-sec h3 .pg { margin-left: auto; font-size: 0.8rem; color: #fff; letter-spacing: 0; }
.book-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
.book-cell {
    position: relative; overflow: hidden; text-align: center; border-radius: 13px; padding: 4px 4px 5px;
    background: #1d1233; border: 1.5px solid rgba(147, 112, 219, 0.28);
}
.book-cell canvas { display: block; width: 78%; height: auto; margin: 0 auto; border-radius: 9px; background: #1d1233; }
.book-cell .nm { display: flex; align-items: center; justify-content: center; min-height: 2.3em; margin-top: 3px; font-size: 0.7rem; line-height: 1.12; color: #efe6ff; font-weight: 600; }
.book-cell .q { position: absolute; left: 0; right: 0; top: 24%; font-size: 1.9rem; font-weight: 700; color: rgba(255, 255, 255, 0.28); pointer-events: none; }
.book-cell.has { border-color: var(--tc); box-shadow: inset 0 0 16px -5px var(--tc), 0 0 10px -4px var(--tc); }
.book-cell.has .q { display: none; }
.book-cell:not(.has) .nm { color: #6f5d99; }
.book-cell.new::after { content: 'NEW'; position: absolute; top: 5px; right: 5px; padding: 1px 5px; border-radius: 6px; background: var(--pink); color: #fff; font-size: 0.55rem; font-weight: 800; letter-spacing: 0.06em; }
.book-cell.wait canvas { animation: bb-pulse 1.2s ease-in-out infinite; }

/* ---- toasts for collection finds */
.toast.collect { border-left-color: var(--tc, var(--gold)); background: linear-gradient(90deg, rgba(60, 34, 104, 0.95), rgba(26, 10, 46, 0.9)); font-weight: 600; }

/* ---- flying coins + confetti (screen-space juice) */
#fx-layer { position: fixed; inset: 0; z-index: 75; pointer-events: none; overflow: hidden; }
.coin-fly {
    position: absolute; left: 0; top: 0; width: 18px; height: 18px; margin: -9px 0 0 -9px; border-radius: 50%; display: none;
    background: radial-gradient(circle at 35% 30%, #fff8c4, #ffd700 55%, #c98a00); border: 1.5px solid #8a5a00;
    box-shadow: 0 0 8px rgba(255, 215, 0, 0.8); will-change: transform, opacity;
}
.confetto { position: absolute; left: 0; top: 0; width: 9px; height: 14px; border-radius: 2px; will-change: transform, opacity; }

/* ---- phones */
@media (max-width: 640px) {
    #hud-buttons { top: 84px; left: 8px; right: auto; transform: none; gap: 5px; }
    #hud-stack { top: 126px; width: 94vw; gap: 6px; }
    body.in-game #toasts { top: max(200px, calc(var(--stack-bottom, 0px) + 8px)); }
    #event-banner { padding: 5px 12px 11px 9px; gap: 8px; }
    .eb-ico { font-size: 1.35rem; }
    .eb-name { font-size: 1rem; }
    .eb-desc { font-size: 0.7rem; }
    #event-banner.intro { padding: 9px 16px 15px 12px; }
    #event-banner.intro .eb-ico { font-size: 2.2rem; }
    .look-row { grid-template-columns: 138px 1fr; gap: 8px; }
    .look-stage { height: 200px; }
    .look-name { font-size: 0.66rem; bottom: 5px; }
    #event-tint { box-shadow: inset 0 0 46px 6px var(--ev); }
    .outfit-grid { grid-template-columns: 1fr; gap: 6px; }
    .outfit-card { padding: 6px 10px; gap: 4px; border-radius: 12px; }
    .outfit-card .ot { display: none; }
    .outfit-card .sw { height: 7px; }
    #book { padding: 8px; }
    .book-head { padding: 10px 12px 6px; }
    .book-bar { margin: 0 12px; }
    .book-tiers { padding: 8px 12px 6px; gap: 5px; }
    .tier-chip { font-size: 0.7rem; padding: 2px 8px; }
    .book-body { padding: 0 12px 12px; }
    .book-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
    .book-cell canvas { width: 100%; }
    .book-cell .nm { font-size: 0.62rem; }
}
@media (min-width: 641px) and (max-width: 1100px) {
    body.in-game #toasts { top: max(110px, calc(var(--stack-bottom, 0px) + 8px)); }
}
@media (max-width: 640px) {
    body.touch #upgrades { max-height: 34vh; }
}
@media (max-height: 520px) {
    #hud-stack { top: 76px; width: min(48vw, 440px); gap: 5px; }
    #announcer { font-size: 1.05rem; }
    #steal-alert { font-size: 0.9rem; padding: 5px 12px; }
    body.touch #upgrades { align-self: center; flex-direction: row; max-height: none; overflow: visible; top: auto; left: auto; transform: none; }
    #hud-buttons { top: 98px; left: 10px; right: auto; transform: none; }
    .eb-desc { display: none; }
    #event-banner.intro .eb-desc { display: block; }
}
@media (prefers-reduced-motion: reduce) {
    #event-banner::before, #event-banner.intro .eb-ico, #btn-book.ping { animation: none; }
}
