/* DizzyParty: vibrant + chunky + mobile first */
:root {
  --grape: #2B1055;
  --grape-2: #3D1A78;
  --grape-3: #55279b;
  --pink: #FF3D81;
  --yellow: #FFD23F;
  --cyan: #22D3EE;
  --lime: #9BEA3C;
  --orange: #FF8A1F;
  --cream: #FFF8EC;
  --ink: #1d0b3a;
  --radius: 20px;
  --font: "Fredoka", ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", system-ui, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overscroll-behavior: none; }
body {
  font-family: var(--font); color: var(--cream); font-size: 17px; line-height: 1.25;
  background:
    radial-gradient(circle at 15% 10%, #6a2fd0 0, transparent 40%),
    radial-gradient(circle at 90% 85%, #d6246e 0, transparent 38%),
    var(--grape);
  background-attachment: fixed;
  -webkit-user-select: none; user-select: none;
}
input { -webkit-user-select: text; user-select: text; }
#app { min-height: 100%; display: flex; flex-direction: column; padding: calc(16px + var(--safe-t)) calc(16px + var(--safe-r)) calc(16px + var(--safe-b)) calc(16px + var(--safe-l)); }

.screen { width: 100%; max-width: 520px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; flex: 1; }
.center { justify-content: center; }
.logo { width: min(100%, 470px); margin: 0 auto; display: block; filter: drop-shadow(0 6px 0 rgba(0,0,0,.25)); animation: bob 3.2s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0) rotate(-1deg); } 50% { transform: translateY(-6px) rotate(1deg); } }

.card { background: var(--grape-2); border: 3px solid var(--ink); border-radius: var(--radius); padding: 16px; box-shadow: 0 6px 0 var(--ink); }
h2 { margin: 0 0 8px; font-size: 20px; }
.muted { opacity: .7; font-size: 14px; }

input[type=text] {
  width: 100%; font: inherit; font-weight: 600; font-size: 20px; color: var(--ink); background: var(--cream);
  border: 3px solid var(--ink); border-radius: 14px; padding: 12px 14px; outline: none; text-align: center;
}
input[type=text]:focus { border-color: var(--cyan); box-shadow: 0 0 0 4px rgba(34,211,238,.35); }
input.code { text-transform: uppercase; letter-spacing: .35em; font-size: 26px; padding-left: calc(14px + .35em); }

.btn {
  font: inherit; font-weight: 700; font-size: 20px; color: var(--ink); background: var(--yellow);
  border: 3px solid var(--ink); border-radius: 16px; padding: 12px 18px; cursor: pointer;
  box-shadow: 0 5px 0 var(--ink); transition: transform .06s, box-shadow .06s; touch-action: manipulation;
}
.btn:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.pink { background: var(--pink); color: #fff; }
.btn.cyan { background: var(--cyan); }
.btn.lime { background: var(--lime); }
.btn.ghost { background: transparent; color: var(--cream); box-shadow: none; border-color: rgba(255,255,255,.35); }
.btn.small { font-size: 15px; padding: 8px 12px; border-radius: 12px; box-shadow: 0 3px 0 var(--ink); }
.btn.round { width: 54px; height: 54px; padding: 0; border-radius: 50%; font-size: 24px; display: grid; place-items: center; }
.btn.round.on { background: var(--lime); }
.btn.round.off { background: var(--cream); opacity: .85; }
.row { display: flex; gap: 10px; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }
.or { text-align: center; opacity: .65; font-weight: 600; }
.error { color: #ffd0dc; background: rgba(255,61,129,.25); border: 2px solid var(--pink); padding: 8px 12px; border-radius: 12px; text-align: center; min-height: 0; }
.error:empty { display: none; }

/* account chip */
.topbar { display: flex; justify-content: flex-end; min-height: 44px; align-items: center; gap: 8px; }
.chip { background: rgba(0,0,0,.28); border-radius: 999px; padding: 6px 12px; font-weight: 600; font-size: 15px; display: inline-flex; gap: 6px; align-items: center; }
.chip b { color: var(--yellow); }
#gbtn { display: flex; justify-content: center; min-height: 44px; }

/* lobby */
.roomcode { text-align: center; }
.roomcode .label { font-size: 13px; opacity: .7; letter-spacing: .1em; text-transform: uppercase; }
.roomcode .code { font-size: 56px; font-weight: 700; letter-spacing: .12em; padding-left: .12em; color: var(--yellow); text-shadow: 0 4px 0 var(--ink); cursor: pointer; line-height: 1.05; }
.roomcode .hint { font-size: 13px; opacity: .7; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.tile { position: relative; background: var(--grape-3); border: 3px solid var(--ink); border-radius: 18px; padding: 8px 6px 8px; text-align: center; box-shadow: 0 4px 0 var(--ink); }
.tile.me { outline: 3px solid var(--cyan); }
.tile.spec { opacity: .6; }
.face { width: 64px; height: 64px; margin: 0 auto 4px; border-radius: 50%; overflow: hidden; border: 3px solid var(--ink); background: var(--c, var(--pink)); display: grid; place-items: center; font-size: 34px; position: relative; flex: none; }
.face video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.face.mirror video { transform: scaleX(-1); }
.face .mic { position: absolute; right: -2px; bottom: -2px; font-size: 14px; background: var(--ink); border-radius: 50%; width: 22px; height: 22px; display: grid; place-items: center; }
.tile .name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .tag { font-size: 12px; opacity: .8; }
.tile .crown { position: absolute; top: -10px; left: 50%; transform: translateX(-50%); font-size: 22px; }
.tile .pill { margin-top: 4px; font-size: 12px; font-weight: 700; display: inline-block; padding: 2px 8px; border-radius: 99px; color: var(--ink); }
.pill.A { background: var(--pink); color: #fff; } .pill.B { background: var(--cyan); }

.games { display: flex; flex-direction: column; gap: 10px; }
.game { display: flex; gap: 12px; align-items: center; text-align: left; background: var(--grape-3); border: 3px solid var(--ink); border-radius: 18px; padding: 10px 12px; color: inherit; font: inherit; width: 100%; box-shadow: 0 4px 0 var(--ink); cursor: pointer; }
.game .em { font-size: 34px; width: 44px; text-align: center; flex: none; }
.game .t { font-weight: 700; font-size: 18px; }
.game .d { font-size: 13px; opacity: .75; }
.game.sel { background: var(--yellow); color: var(--ink); }
.game.soon { opacity: .45; cursor: default; }
.game.locked { cursor: default; }
.game .badge { margin-left: auto; font-size: 11px; font-weight: 700; background: var(--ink); color: var(--cream); padding: 3px 8px; border-radius: 99px; flex: none; }

.car-pick, .team-pick { display: flex; gap: 8px; }
.car-pick button, .team-pick button { flex: 1; font: inherit; font-weight: 600; color: var(--cream); background: var(--grape-3); border: 3px solid var(--ink); border-radius: 14px; padding: 8px 4px; cursor: pointer; }
.car-pick button.sel, .team-pick button.sel { background: var(--cyan); color: var(--ink); }
.car-pick small { display: block; font-weight: 400; font-size: 11px; opacity: .8; }

.sticky-bottom { position: sticky; bottom: 0; display: flex; gap: 10px; padding: 18px 0 calc(8px + var(--safe-b)); margin-top: auto; background: linear-gradient(to bottom, rgba(43,16,85,0), var(--grape) 38%); }
.sticky-bottom .btn { flex: 1; }

/* in-game */
#game { position: fixed; inset: 0; background: #000; overflow: hidden; touch-action: none; }
#game canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.faces { position: absolute; top: calc(8px + var(--safe-t)); left: calc(8px + var(--safe-l)); display: flex; flex-wrap: wrap; gap: 6px; max-width: 60%; pointer-events: none; z-index: 5; }
.faces .face { width: 46px; height: 46px; margin: 0; font-size: 24px; border-width: 2px; }
.faces .face.talking { box-shadow: 0 0 0 3px var(--lime); }
.game-buttons { position: absolute; top: calc(8px + var(--safe-t)); right: calc(8px + var(--safe-r)); display: flex; gap: 8px; z-index: 6; }
.game-buttons .btn.round { width: 44px; height: 44px; font-size: 20px; }
.overlay { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(43,16,85,.82); z-index: 20; padding: 20px; text-align: center; }
.overlay .box { max-width: 420px; display: flex; flex-direction: column; gap: 12px; align-items: center; }
.overlay h1 { margin: 0; font-size: 34px; color: var(--yellow); text-shadow: 0 4px 0 var(--ink); }
.hud { position: absolute; z-index: 4; pointer-events: none; font-weight: 700; text-shadow: 0 2px 0 rgba(0,0,0,.6); }
.hud-top { top: calc(8px + var(--safe-t)); left: 50%; transform: translateX(-50%); font-size: 22px; text-align: center; }
.big-msg { position: absolute; left: 0; right: 0; top: 30%; text-align: center; font-size: 84px; font-weight: 700; color: var(--yellow); text-shadow: 0 6px 0 var(--ink); z-index: 8; pointer-events: none; }
.pad { position: absolute; bottom: calc(18px + var(--safe-b)); z-index: 7; width: 92px; height: 92px; border-radius: 50%; border: 4px solid var(--ink); font-size: 40px; color: var(--ink); background: rgba(255,210,63,.85); display: grid; place-items: center; touch-action: none; }
.pad.left { left: calc(18px + var(--safe-l)); } .pad.right { left: calc(130px + var(--safe-l)); }
.pad.item { right: calc(18px + var(--safe-r)); background: rgba(255,61,129,.9); }
.pad.brake { right: calc(130px + var(--safe-r)); background: rgba(34,211,238,.85); width: 70px; height: 70px; font-size: 30px; }
.pad:active, .pad.down { transform: scale(.93); filter: brightness(1.2); }
.results { display: flex; flex-direction: column; gap: 6px; width: 100%; }
.results .r { display: flex; gap: 10px; align-items: center; background: var(--grape-3); border: 3px solid var(--ink); border-radius: 14px; padding: 8px 12px; font-weight: 600; }
.results .r.first { background: var(--yellow); color: var(--ink); }
.results .r .pts { margin-left: auto; font-weight: 700; }

#toast { position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translate(-50%, 30px); opacity: 0; transition: .25s; background: var(--cream); color: var(--ink); font-weight: 600; padding: 10px 16px; border-radius: 99px; border: 3px solid var(--ink); z-index: 100; pointer-events: none; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 700px) { body { font-size: 18px; } .tiles { grid-template-columns: repeat(4, 1fr); } }
@media (orientation: landscape) and (max-height: 500px) { .big-msg { font-size: 56px; top: 22%; } .pad { width: 80px; height: 80px; } .pad.right { left: calc(116px + var(--safe-l)); } }

.overlay.rotate-hint { display: none; }
@media (orientation: portrait) { .overlay.rotate-hint { display: grid; } }

/* full-screen DOM game screens (social / voice / drawing games) */
.gscreen { position: absolute; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y; padding: calc(66px + var(--safe-t)) calc(16px + var(--safe-r)) calc(24px + var(--safe-b)) calc(16px + var(--safe-l)); display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; background: radial-gradient(circle at 20% 10%, #6a2fd0 0, transparent 45%), radial-gradient(circle at 85% 90%, #d6246e 0, transparent 40%), var(--grape); }
.gscreen > * { width: 100%; max-width: 520px; }
.gscreen input[type=text] { font-size: 18px; }
.gcard { background: var(--grape-2); border: 3px solid var(--ink); border-radius: var(--radius); padding: 16px; box-shadow: 0 6px 0 var(--ink); display: flex; flex-direction: column; gap: 10px; align-items: center; }
.gtitle { font-size: 15px; letter-spacing: .12em; text-transform: uppercase; opacity: .75; font-weight: 700; }
.gbig { font-size: 34px; font-weight: 700; color: var(--yellow); text-shadow: 0 4px 0 var(--ink); line-height: 1.1; word-break: break-word; }
.gtimer { width: 100%; height: 14px; border-radius: 99px; background: rgba(0,0,0,.35); border: 3px solid var(--ink); overflow: hidden; }
.gtimer-fill { height: 100%; width: 100%; background: var(--lime); transition: width .2s linear; }
.gscreen .tiles .tile { cursor: pointer; }

/* in-game face strip: always one row; faces shrink when the room is full */
#game .faces { flex-wrap: nowrap; max-width: calc(100% - 215px - var(--safe-r)); overflow: hidden; }
#game .faces .face { flex: 0 1 46px; min-width: 26px; width: auto; height: auto; aspect-ratio: 1; font-size: clamp(14px, 5vw, 24px); }
