:root {
  --bg: #120f1c;
  --panel: rgba(20, 18, 32, 0.92);
  --panel-2: #252137;
  --line: rgba(255, 255, 255, 0.12);
  --text: #f4f2fa;
  --dim: #a8a3bd;
  --red: #ff3b3b;
  --blue: #3b8cff;
  --green: #46d65a;
  --gold: #ffd23c;
  --font: "Gotham SSm", "Montserrat", "Segoe UI", system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: var(--font); -webkit-user-select: none; user-select: none; }
button { font-family: inherit; color: inherit; cursor: pointer; }
input { font-family: inherit; }
.hidden { display: none !important; }
#scene, #scene canvas { position: fixed; inset: 0; display: block; }

/* ── overlays & panels ─────────────────────────────────────────────────── */
.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 30; padding: 16px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 22px; box-shadow: 0 20px 60px rgba(0,0,0,0.5); max-height: calc(100vh - 32px); overflow: auto; }
button.primary, .start-row button, #join-btn, #create-btn {
  background: linear-gradient(#3fd06a, #22a04a); border: 0; border-bottom: 4px solid #187a36; border-radius: 10px;
  padding: 11px 18px; font-weight: 800; font-size: 16px; color: #fff; text-shadow: 0 1px 0 rgba(0,0,0,0.3);
}
button.primary:active { transform: translateY(2px); border-bottom-width: 2px; }
button.primary:disabled { filter: grayscale(1); opacity: 0.5; cursor: default; }
#create-btn, #join-btn { background: linear-gradient(#4a8cff, #2c64d0); border-bottom-color: #1f4aa0; }
button.link { background: none; border: 0; color: var(--dim); text-decoration: underline; font-size: 14px; padding: 4px; }
.pill { background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; font-weight: 700; }
.pill.on { background: var(--gold); color: #222; }
.hint { color: var(--dim); font-size: 13px; }

/* start screen */
#start { background: radial-gradient(ellipse at center, rgba(18,15,28,0.35), rgba(18,15,28,0.85)); }
.start-panel { width: min(440px, 100%); display: flex; flex-direction: column; gap: 12px; }
.start-panel h1 { margin: 0 0 4px; text-align: center; font-size: 40px; line-height: 1; letter-spacing: 1px; font-weight: 900; }
.start-panel h1 .mm { color: #fff; text-shadow: 0 3px 0 #000; }
.start-panel h1 .mm2 { color: var(--red); text-shadow: 0 3px 0 #4a0000; }
#profile-line { text-align: center; color: var(--dim); font-size: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--dim); }
.field input, #code-input { background: #0e0c16; border: 1px solid var(--line); border-radius: 8px; color: var(--text); padding: 11px 12px; font-size: 16px; }
#code-input { width: 110px; text-transform: uppercase; letter-spacing: 4px; text-align: center; font-weight: 800; }
#quick-btn { font-size: 22px; padding: 14px; }
.start-or { text-align: center; color: var(--dim); font-size: 13px; }
.start-row { display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; }
.start-row.small { gap: 18px; }
.check { display: flex; align-items: center; gap: 6px; color: var(--dim); }
#start-error { color: #ff7a7a; text-align: center; min-height: 18px; font-size: 14px; }
.howto { background: rgba(0,0,0,0.25); border-radius: 10px; padding: 10px 14px; font-size: 14px; color: #ddd; }
.howto summary { cursor: pointer; font-weight: 700; }
.howto ul { padding-left: 18px; }
b.r, .r { color: var(--red); } b.b, .b { color: var(--blue); } b.g, .g { color: var(--green); } .y { color: var(--gold); }

#room-code { position: fixed; bottom: 10px; right: 10px; z-index: 20; display: flex; gap: 8px; align-items: center; font-size: 13px; background: rgba(0,0,0,0.45); padding: 6px 8px; border-radius: 8px; }
#room-code button { background: rgba(255,255,255,0.12); border: 0; border-radius: 6px; padding: 5px 9px; font-size: 12px; font-weight: 700; }

/* ── HUD ──────────────────────────────────────────────────────────────── */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud button, #hud input, #hud .vote-card { pointer-events: auto; }
#top-bar { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 4px; }
#phase-pill { background: rgba(0,0,0,0.6); border-radius: 10px; padding: 8px 18px; font-weight: 900; font-size: 20px; display: flex; gap: 12px; text-shadow: 0 2px 0 #000; }
#phase-pill.urgent #phase-time { color: var(--red); animation: pulse 1s infinite; }
#map-label { font-size: 14px; color: var(--gold); font-weight: 700; text-shadow: 0 1px 2px #000; }
@keyframes pulse { 50% { opacity: 0.45; } }

#role-badge { position: absolute; top: 64px; left: 50%; transform: translateX(-50%); padding: 4px 16px; border-radius: 8px; font-weight: 900; font-size: 15px; text-transform: uppercase; letter-spacing: 1px; text-shadow: 0 1px 0 rgba(0,0,0,0.4); }

#coin-hud { position: absolute; right: 14px; bottom: 120px; background: rgba(0,0,0,0.55); padding: 8px 14px; border-radius: 12px; text-align: right; }
#coin-hud .coin-row { font-size: 26px; font-weight: 900; display: flex; gap: 8px; align-items: center; justify-content: flex-end; text-shadow: 0 2px 0 #000; }
#coin-hud .coin-total { font-size: 12px; color: var(--dim); }
#coin-hud.full #coin-bag { color: var(--gold); }

#player-list { position: absolute; top: 10px; right: 10px; width: 190px; background: rgba(0,0,0,0.45); border-radius: 8px; overflow: hidden; font-size: 13px; }
.pl-head { padding: 6px 10px; font-weight: 800; background: rgba(255,255,255,0.08); }
.pl-row { display: flex; justify-content: space-between; padding: 4px 10px; }
.pl-row.me { background: rgba(255,210,60,0.18); }
.pl-lv { color: var(--dim); }

#chat { position: absolute; top: 10px; left: 10px; width: min(360px, 44vw); display: flex; flex-direction: column; gap: 4px; }
#chat-log { max-height: 180px; overflow-y: auto; background: rgba(0,0,0,0.3); border-radius: 8px; padding: 6px 8px; font-size: 13px; line-height: 1.35; text-shadow: 0 1px 1px #000; pointer-events: auto; }
#chat-log:empty { display: none; }
.chat-line.dead { color: #aaa; font-style: italic; }
.chat-line.sys { color: var(--gold); }
#chat-input { background: rgba(0,0,0,0.5); border: 1px solid var(--line); border-radius: 8px; color: #fff; padding: 7px 9px; font-size: 13px; }

#announce { position: absolute; top: 24%; left: 50%; transform: translate(-50%, -50%) scale(0.9); font-size: clamp(22px, 4vw, 40px); font-weight: 900; text-align: center; text-shadow: 0 3px 0 #000, 0 0 18px rgba(0,0,0,0.6); opacity: 0; transition: opacity 0.25s, transform 0.25s; white-space: nowrap; }
#announce.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
#toast { position: absolute; bottom: 190px; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,0.7); padding: 8px 16px; border-radius: 10px; font-weight: 700; opacity: 0; transition: opacity 0.2s; }
#toast.show { opacity: 1; }

#hotbar { position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; gap: 8px; }
.slot { position: relative; width: 74px; height: 74px; border-radius: 10px; background: rgba(30,30,40,0.75); border: 2px solid rgba(255,255,255,0.25); display: flex; flex-direction: column; align-items: center; justify-content: center; overflow: hidden; }
.slot.on { border-color: #fff; background: rgba(90,90,110,0.85); box-shadow: 0 0 0 2px rgba(255,255,255,0.4); }
.slot .key { position: absolute; top: 3px; left: 6px; font-size: 11px; font-weight: 800; color: var(--dim); }
.slot .icon { font-size: 30px; }
.slot .name { font-size: 10px; font-weight: 700; max-width: 70px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot .cool { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.6); pointer-events: none; }
#throw-charge { position: absolute; bottom: 104px; left: 50%; transform: translateX(-50%); width: 160px; height: 8px; background: rgba(0,0,0,0.6); border-radius: 4px; overflow: hidden; }
#throw-fill { height: 100%; width: 0; background: #ffb030; }
#throw-fill.ready { background: var(--red); }

#side-menu { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 8px; }
#side-menu button { width: 46px; height: 46px; border-radius: 10px; border: 0; background: rgba(0,0,0,0.5); font-size: 22px; }
#shiftlock-btn { position: absolute; right: 14px; bottom: 60px; border: 0; border-radius: 8px; padding: 7px 12px; background: rgba(0,0,0,0.5); font-weight: 700; font-size: 13px; }
#shiftlock-btn.on { background: var(--gold); color: #222; }
body.touch #shiftlock-btn, body.touch #controls-hint { display: none; }
#shiftlock-icon { position: fixed; left: 50%; top: 50%; width: 48px; height: 48px; transform: translate(-50%, -50%); z-index: 11; pointer-events: none; image-rendering: auto; }
#aim-dot { position: absolute; left: 50%; top: 50%; width: 8px; height: 8px; margin: -4px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 2px rgba(0,0,0,0.5); }
#gun-marker { position: absolute; transform: translate(-50%, -50%); background: rgba(40,100,220,0.85); border: 2px solid #9cd0ff; border-radius: 10px; padding: 3px 7px; font-size: 18px; font-weight: 900; display: flex; gap: 4px; align-items: center; }
#gun-marker span { font-size: 11px; }

#emote-wheel { position: absolute; left: 66px; top: 50%; transform: translateY(-10%); display: grid; grid-template-columns: repeat(3, 64px); gap: 6px; background: rgba(0,0,0,0.6); padding: 8px; border-radius: 12px; }
#emote-wheel button { background: rgba(255,255,255,0.08); border: 0; border-radius: 8px; height: 58px; font-size: 22px; display: flex; flex-direction: column; align-items: center; justify-content: center; }
#emote-wheel span { font-size: 10px; text-transform: capitalize; }

#spectate { position: absolute; bottom: 110px; left: 50%; transform: translateX(-50%); display: flex; gap: 8px; align-items: center; background: rgba(0,0,0,0.6); border-radius: 10px; padding: 6px; }
#spectate button, #spec-btn { background: rgba(255,255,255,0.12); border: 0; border-radius: 8px; padding: 8px 12px; font-weight: 800; }
#spec-name { min-width: 120px; text-align: center; font-weight: 800; }
#spec-btn { position: absolute; bottom: 110px; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,0.6); }

#vote { position: absolute; top: 100px; left: 50%; transform: translateX(-50%); text-align: center; }
.vote-title { font-weight: 900; font-size: 18px; margin-bottom: 8px; text-shadow: 0 2px 0 #000; }
#vote-cards { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.vote-card { width: 92px; background: rgba(0,0,0,0.6); border: 2px solid rgba(255,255,255,0.2); border-radius: 10px; padding: 8px 4px; }
.vote-card.on { border-color: var(--gold); background: rgba(80,60,0,0.6); }
.vote-icon { font-size: 30px; } .vote-name { font-weight: 800; font-size: 13px; } .vote-count { font-size: 22px; font-weight: 900; color: var(--gold); }

#controls-hint { position: absolute; bottom: 4px; left: 10px; font-size: 11px; color: rgba(255,255,255,0.5); max-width: 40vw; }

#vignette { position: fixed; inset: 0; pointer-events: none; z-index: 5; transition: box-shadow 0.3s; }
#vignette.trapped { box-shadow: inset 0 0 160px 40px rgba(255,110,40,0.7); }
#vignette.ghost { box-shadow: inset 0 0 160px 40px rgba(170,200,255,0.55); }
#vignette.haste { box-shadow: inset 0 0 140px 30px rgba(255,230,80,0.45); }

/* role reveal */
#reveal { flex-direction: column; background: rgba(0,0,0,0.55); pointer-events: none; transition: opacity 1s; }
#reveal.fade { opacity: 0; }
.reveal-sub { font-size: 26px; font-weight: 800; color: #ddd; }
#reveal-role { font-size: clamp(54px, 11vw, 110px); font-weight: 900; text-transform: uppercase; text-shadow: 0 6px 0 rgba(0,0,0,0.6); animation: pop 0.5s ease-out; }
#reveal-goal { font-size: 20px; font-weight: 700; }
@keyframes pop { from { transform: scale(0.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* results */
#results { background: rgba(0,0,0,0.45); pointer-events: none; }
.results-panel { width: min(520px, 100%); text-align: center; pointer-events: auto; }
#results-title { font-size: 38px; font-weight: 900; text-shadow: 0 3px 0 #000; }
#results-why { margin: 4px 0 12px; font-size: 17px; }
#results-roles { display: flex; gap: 18px; justify-content: center; flex-wrap: wrap; font-weight: 700; }
#results-mine { margin: 12px 0; color: var(--gold); font-weight: 800; font-size: 18px; }
#results-table { width: 100%; border-collapse: collapse; font-size: 14px; }
#results-table th { color: var(--dim); font-weight: 600; text-align: left; padding: 4px; }
#results-table td { padding: 4px; text-align: left; border-top: 1px solid var(--line); }
#results-table tr.me td { background: rgba(255,210,60,0.12); }

/* big panel */
#panel { background: rgba(0,0,0,0.5); z-index: 40; }
.big-panel { background: #1a1726; width: min(820px, 100%); height: min(640px, calc(100vh - 32px)); display: flex; flex-direction: column; position: relative; }
.close { position: absolute; top: 10px; right: 10px; background: rgba(255,255,255,0.1); border: 0; border-radius: 8px; width: 34px; height: 34px; font-size: 16px; }
#panel-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; padding-right: 40px; }
#panel-tabs button { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; font-weight: 700; }
#panel-tabs button.on { background: var(--gold); color: #222; }
#panel-body { overflow-y: auto; overflow-x: hidden; flex: 1; padding-right: 4px; }
.pill-row { display: flex; gap: 8px; }
#panel-body h3 { margin: 14px 0 8px; font-size: 15px; }
.panel-coins { font-size: 20px; font-weight: 900; margin-bottom: 10px; }
.boxes { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }
.box-card { background: var(--panel-2); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.box-art { font-size: 52px; filter: drop-shadow(0 6px 10px rgba(0,0,0,0.5)); }
.box-name { font-weight: 900; font-size: 18px; }
.box-odds { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; }
.odd { font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 6px; background: color-mix(in srgb, var(--tier) 25%, transparent); color: var(--tier); }
.odd.tier-chroma, .unbox-name.chroma { background-image: linear-gradient(90deg, #f33, #fd3, #3f6, #3cf, #a3f, #f33); background-size: 300% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: chroma 3s linear infinite; }
@keyframes chroma { to { background-position: 300% 0; } }

.item-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.item-card { position: relative; background: linear-gradient(180deg, color-mix(in srgb, var(--tier, #888) 35%, #1a1726), #1a1726); border: 2px solid var(--tier, #888); border-radius: 10px; padding: 8px 6px; text-align: center; cursor: pointer; min-height: 112px; }
.item-card.chroma { border-image: linear-gradient(90deg, #f33, #fd3, #3f6, #3cf, #a3f) 1; background: linear-gradient(180deg, #3a2a4a, #1a1726); }
.item-card.none.eq { border-color: var(--gold); }
.item-art { font-size: 34px; height: 46px; display: flex; align-items: center; justify-content: center; filter: drop-shadow(0 0 6px var(--swatch, transparent)); }
.item-name { font-size: 12px; font-weight: 800; }
.item-tier { font-size: 10px; color: var(--tier, #ccc); font-weight: 700; text-transform: uppercase; }
.item-card.chroma .item-tier { color: #fff; }
.item-count { position: absolute; top: 4px; right: 6px; font-size: 11px; font-weight: 800; }
.item-eq { position: absolute; top: 4px; left: 6px; font-size: 9px; font-weight: 900; color: var(--gold); }

.swatches { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.swatch { width: 34px; height: 34px; border-radius: 8px; border: 2px solid rgba(255,255,255,0.2); }
.swatch.on { border-color: #fff; box-shadow: 0 0 0 2px var(--gold); }
.swatch-pick { width: 40px; height: 34px; border: 0; background: none; padding: 0; }

.perks { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.perk-card { background: var(--panel-2); border: 2px solid var(--line); border-radius: 12px; padding: 14px; text-align: left; }
.perk-card.on { border-color: var(--red); }
.perk-icon { font-size: 30px; } .perk-name { font-weight: 900; font-size: 17px; } .perk-desc { font-size: 13px; color: var(--dim); margin: 4px 0; } .perk-cd { font-size: 12px; color: var(--gold); }

.cursor-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.cursor-tile { background: var(--panel-2); border: 2px solid var(--line); border-radius: 10px; padding: 8px 4px; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 11px; font-weight: 700; }
.cursor-tile img { width: 40px; height: 40px; }
.cursor-tile .arrow { font-size: 26px; transform: rotate(-135deg); height: 40px; display: flex; align-items: center; }
.cursor-tile.on { border-color: var(--gold); background: rgba(255,210,60,0.15); }
.cursor-sizes { grid-column: 1 / -1; display: flex; gap: 8px; margin-top: 4px; }
input[type=range] { width: 100%; }

/* unboxing */
#unbox { background: rgba(0,0,0,0.75); z-index: 50; }
.unbox-frame { width: min(760px, 100%); text-align: center; }
#unbox-title { font-size: 26px; font-weight: 900; margin-bottom: 14px; }
#unbox-window { position: relative; overflow: hidden; height: 140px; border-radius: 12px; background: #0b0a12; border: 2px solid var(--line); }
#unbox-reel { display: flex; gap: 0; height: 100%; align-items: center; will-change: transform; }
#unbox-reel .item-card { flex: 0 0 120px; margin: 0 4px; width: 112px; min-height: 124px; }
#unbox-pointer { position: absolute; left: 50%; top: 0; bottom: 0; width: 4px; margin-left: -2px; background: var(--gold); box-shadow: 0 0 12px var(--gold); }
#unbox-result { min-height: 70px; margin-top: 16px; }
.unbox-name { font-size: 34px; font-weight: 900; animation: pop 0.4s ease-out; }
.unbox-tier { color: var(--dim); text-transform: capitalize; }
#unbox-ok { margin-top: 10px; }

/* ── touch ────────────────────────────────────────────────────────────── */
#touch-ui { position: fixed; inset: 0; z-index: 9; }
#stick-zone { position: absolute; left: 0; bottom: 0; width: 45%; height: 60%; }
#look-zone { position: absolute; right: 0; top: 0; width: 55%; height: 100%; }
#stick-base { position: absolute; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%; background: rgba(255,255,255,0.12); border: 2px solid rgba(255,255,255,0.3); }
#stick-knob { position: absolute; left: 30px; top: 30px; width: 60px; height: 60px; border-radius: 50%; background: rgba(255,255,255,0.45); }
.tb { position: absolute; border-radius: 50%; border: 2px solid rgba(255,255,255,0.35); background: rgba(0,0,0,0.35); font-size: 22px; font-weight: 900; width: 56px; height: 56px; }
.tb.down { background: rgba(255,255,255,0.3); }
.tb.big { width: 76px; height: 76px; font-size: 30px; }
#tb-jump { right: 24px; bottom: 120px; }
#tb-act { right: 112px; bottom: 150px; background: rgba(200,40,40,0.45); }
#touch-side { position: absolute; right: 16px; top: 38%; display: flex; flex-direction: column; gap: 10px; }
#touch-side .tb { position: static; }
.tb.cooling { opacity: 0.4; }
.tb.on { background: rgba(255,210,60,0.75); border-color: #fff; }
body.touch #hotbar { bottom: 12px; }
body.touch #coin-hud { bottom: auto; top: 110px; right: 10px; }
body.touch #player-list { display: none; }
body.touch #chat { width: 42vw; }
body.touch #chat-log { max-height: 90px; }
body.touch #side-menu { top: 46%; }

@media (max-width: 640px) {
  #player-list { display: none; }
  #chat { width: 60vw; }
  #controls-hint { display: none; }
  .slot { width: 62px; height: 62px; }
  #phase-pill { font-size: 16px; padding: 6px 12px; }
}
