* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #8fd0ff;
  font-family: "Trebuchet MS", "Arial Rounded MT Bold", system-ui, sans-serif;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  touch-action: none;
}
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#hud, .overlay, #thumb { height: 100vh; height: 100dvh; bottom: auto; }
.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; color: #fff;
  text-shadow: 0 2px 0 #c2185b, 0 0 6px rgba(0,0,0,.35); }
#posBox { position: absolute; top: max(10px, env(safe-area-inset-top)); left: max(10px, env(safe-area-inset-left));
  display: flex; align-items: center; gap: 6px; }
#posFace { width: 58px; height: 58px; border-radius: 50%; border: 4px solid #fff; box-shadow: 0 3px 8px rgba(0,0,0,.3); background: #fff; }
#posTxt { font-size: 52px; font-weight: 900; line-height: 1; }
#board { position: absolute; top: calc(max(10px, env(safe-area-inset-top)) + 70px); left: max(12px, env(safe-area-inset-left));
  display: flex; flex-direction: column; gap: 4px; }
#board .row { display: flex; align-items: center; gap: 5px; font-size: 15px; font-weight: 800; }
#board img { width: 26px; height: 26px; border-radius: 50%; border: 2px solid #fff; }
#board .row.me img { border-color: #ff4fa3; }
#lapBox { position: absolute; top: max(10px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); text-align: right; }
#lapTxt { font-size: 28px; font-weight: 900; }
#timeTxt { font-size: 17px; font-weight: 700; }
#map { position: absolute; top: calc(max(10px, env(safe-area-inset-top)) + 92px); right: max(10px, env(safe-area-inset-right));
  width: 110px; height: 110px; opacity: .92; }
#speedTxt { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 28px);
  font-size: 26px; font-weight: 900; }
#speedTxt small { font-size: 13px; }
#wrongWay, #lapMsg { position: absolute; left: 50%; top: 28%; transform: translateX(-50%);
  font-size: 34px; font-weight: 900; white-space: nowrap; }
#wrongWay { color: #ffeb3b; text-shadow: 0 2px 0 #b71c1c; }
#lapMsg { animation: pop .5s ease-out; }
@keyframes pop { from { transform: translateX(-50%) scale(.3); opacity: 0 } to { transform: translateX(-50%) scale(1); opacity: 1 } }

/* ---------- Semáforo ---------- */
#lights { position: fixed; top: 16%; left: 50%; transform: translateX(-50%); display: flex; gap: 10px;
  background: #222; padding: 10px 14px; border-radius: 18px; border: 4px solid #ff4fa3; pointer-events: none; }
.lamp { width: 44px; height: 44px; border-radius: 50%; background: #4a1010; }
.lamp.on { background: #ff2a2a; box-shadow: 0 0 18px #ff2a2a; }
#lights.go .lamp { background: #2bff5a; box-shadow: 0 0 18px #2bff5a; }
#goTxt { display: none; }
#lights.go #goTxt { display: block; position: absolute; top: 76px; left: 50%; transform: translateX(-50%);
  font-size: 54px; font-weight: 900; color: #fff; text-shadow: 0 3px 0 #1b9e3e; }

/* ---------- Controles de toque ---------- */
#controls { position: fixed; inset: auto 0 0 0; height: 0; pointer-events: none; }
.cgroup { position: fixed; bottom: max(14px, env(safe-area-inset-bottom)); display: flex; gap: 12px; align-items: flex-end; pointer-events: auto; }
.cgroup.left { left: max(14px, env(safe-area-inset-left)); }
.cgroup.right { right: max(14px, env(safe-area-inset-right)); }
.btn { width: 84px; height: 84px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 36px; font-weight: 900; color: #fff; background: rgba(255, 79, 163, .55);
  border: 4px solid rgba(255,255,255,.85); box-shadow: 0 4px 10px rgba(0,0,0,.25); }
.btn.small { width: 64px; height: 64px; font-size: 20px; background: rgba(60,60,80,.5); }
.btn.gas { width: 100px; height: 100px; background: rgba(43, 200, 90, .6); font-size: 42px; }
.btn.down { transform: scale(.92); filter: brightness(1.35); }

/* ---------- Polegar ---------- */
#thumb { position: fixed; top: 0; right: 0; bottom: 0; width: 62%; pointer-events: none; }
@media (orientation: portrait) {
  #thumb { top: 40%; width: 100%; height: 60dvh; }
  #thumbHint { left: 50%; right: auto; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 90px); white-space: nowrap; }
  #speedTxt { left: max(16px, env(safe-area-inset-left)); transform: none; }
}
#thumbHint { position: absolute; right: max(18px, env(safe-area-inset-right)); bottom: max(22px, env(safe-area-inset-bottom));
  color: #fff; font-weight: 800; font-size: 15px; text-align: center; background: rgba(255,79,163,.45);
  padding: 10px 14px; border-radius: 18px; border: 3px dashed rgba(255,255,255,.8); }
#thumb.active #thumbHint { display: none; }
#stick { display: none; position: fixed; width: 130px; height: 130px; margin: -65px 0 0 -65px; border-radius: 50%;
  background: rgba(255,255,255,.18); border: 4px solid rgba(255,255,255,.7); }
#thumb.active #stick { display: block; }
#knob { position: absolute; left: 50%; top: 50%; width: 58px; height: 58px; margin: -29px 0 0 -29px; border-radius: 50%;
  background: rgba(255,79,163,.85); border: 4px solid #fff; box-shadow: 0 3px 8px rgba(0,0,0,.3); }
#knob.brake { background: rgba(80,80,100,.9); }
#ctrlPick { margin-top: 12px; color: #8a4a6a; font-weight: 700; font-size: 15px; }
#ctrlPick b { display: inline-block; padding: 5px 10px; border-radius: 14px; border: 2px solid #ffc1de; cursor: pointer; margin: 2px; }
#ctrlPick b.on { background: #ff4fa3; color: #fff; border-color: #ff4fa3; }

/* ---------- Telas ---------- */
.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: radial-gradient(circle at 50% 30%, rgba(255,214,236,.25), rgba(255,79,163,.3)); }
.card { background: #fff; border-radius: 28px; padding: 20px 22px; text-align: center; max-width: 420px; width: 100%;
  max-height: 100%; overflow: auto; touch-action: pan-y; border: 5px solid #ff4fa3; box-shadow: 0 10px 30px rgba(194,24,91,.35);
  background-image: repeating-linear-gradient(45deg, #fff 0 14px, #fff5fa 14px 28px); }
.bigFace { width: 120px; height: 120px; border-radius: 50%; border: 6px solid #ff4fa3; background: #fff;
  box-shadow: 0 6px 16px rgba(0,0,0,.2); }
.bigFace.gold { border-color: #ffc61a; box-shadow: 0 0 0 6px #fff3c4, 0 0 28px #ffc61a; animation: bounce 1s ease-in-out infinite alternate; }
@keyframes bounce { from { transform: translateY(0) rotate(-4deg) } to { transform: translateY(-8px) rotate(4deg) } }
h1 { margin: 8px 0 2px; font-size: 38px; color: #ff2d8f; text-shadow: 0 3px 0 #ffd1e6; }
.sub { margin: 0 0 14px; color: #8a4a6a; font-weight: 700; }
.hint { color: #8a4a6a; font-size: 14px; margin: 14px 0 0; line-height: 1.45; }
button { font: inherit; font-size: 26px; font-weight: 900; color: #fff; background: linear-gradient(#ff6fb5, #ff2d8f);
  border: none; border-radius: 40px; padding: 14px 36px; box-shadow: 0 5px 0 #b3125f; cursor: pointer; }
button:active { transform: translateY(3px); box-shadow: 0 2px 0 #b3125f; }
#results { list-style: none; padding: 0; margin: 10px 0 16px; text-align: left; }
#results li { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-radius: 14px; font-weight: 800; color: #5a2a44; font-size: 18px; }
#results li.me { background: #ffe1ef; }
#results li img { width: 36px; height: 36px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.25); }
#results li .t { margin-left: auto; font-size: 15px; color: #a0607e; }

#rotate { position: fixed; left: 50%; top: 40%; transform: translateX(-50%); background: rgba(0,0,0,.55); color: #fff;
  padding: 10px 16px; border-radius: 14px; font-weight: 800; pointer-events: none; animation: fade 3.5s forwards; }
@keyframes fade { 0%,75% { opacity: 1 } 100% { opacity: 0 } }
#fps { position: fixed; top: 4px; left: 50%; transform: translateX(-50%); color: #fff; font: 700 13px monospace;
  background: rgba(0,0,0,.45); padding: 2px 8px; border-radius: 8px; pointer-events: none; }
#confettiLayer { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.bubble { position: absolute; bottom: -90px; border-radius: 50%; animation: rise ease-in forwards;
  background: radial-gradient(circle at 30% 28%, rgba(255,255,255,.95) 0 9%, rgba(255,255,255,0) 14%),
              radial-gradient(circle at 50% 50%, rgba(220,240,255,.08) 0 62%, rgba(255,140,210,.45) 76%, rgba(140,210,255,.55) 88%, rgba(255,255,255,0) 100%);
  box-shadow: inset 0 0 6px rgba(255,255,255,.7); }
@keyframes rise {
  0% { transform: translate(0, 0) scale(.6); opacity: 0 }
  10% { opacity: 1 }
  50% { transform: translate(18px, -55vh) scale(1) }
  100% { transform: translate(-14px, -120vh) scale(1.05); opacity: .9 }
}

/* telas baixas (celular deitado) */
@media (max-height: 500px) {
  .btn { width: 70px; height: 70px; font-size: 30px; }
  .btn.gas { width: 84px; height: 84px; }
  .btn.small { width: 54px; height: 54px; }
  #posTxt { font-size: 42px; } #posFace { width: 46px; height: 46px; }
  #board { top: calc(max(8px, env(safe-area-inset-top)) + 56px); }
  .bigFace { width: 64px; height: 64px; border-width: 4px; } h1 { font-size: 26px; margin: 4px 0 0; }
  .card { padding: 10px 18px; } .sub { margin-bottom: 8px; } .hint { margin-top: 8px; font-size: 13px; }
  #results { margin: 4px 0 10px; } #results li { padding: 2px 10px; font-size: 15px; } #results li img { width: 28px; height: 28px; }
  button { font-size: 22px; padding: 10px 30px; }
  #map { width: 90px; height: 90px; top: 88px; }
}

/* celular em pé, tela baixa */
@media (orientation: portrait) and (max-height: 760px) {
  .bigFace { width: 86px; height: 86px; border-width: 5px; }
  h1 { font-size: 30px; margin-top: 4px; }
  .sub { font-size: 14px; margin-bottom: 10px; }
  .hint { font-size: 13px; margin-top: 8px; }
  button { font-size: 22px; padding: 11px 30px; }
  .card { padding: 14px 16px; }
}

#popTxt { font-size: 20px; font-weight: 900; margin-top: 2px; }
#popTxt.pulse { animation: pulse .3s ease-out; }
@keyframes pulse { 0% { transform: scale(1.6) } 100% { transform: scale(1) } }
.mute { display: inline-block; margin-top: 10px; padding: 6px 14px; border-radius: 16px; font-weight: 800; font-size: 14px;
  color: #8a4a6a; border: 2px solid #ffc1de; cursor: pointer; background: #fff; }
.popEnd { margin: -6px 0 12px; font-weight: 800; color: #5a8ad8; font-size: 17px; }
