* { margin: 0; padding: 0; box-sizing: border-box; }
/* Safe areas come from two places in a Telegram Mini App: the device notch
   (env()) and Telegram's own chrome (JS sets --tg-sa-* from safeAreaInset +
   contentSafeAreaInset, which is the only way to clear the floating close
   button in fullscreen). Everything fixed positions against these. */
:root {
  --sa-top: max(env(safe-area-inset-top), var(--tg-sa-top, 0px));
  --sa-bottom: max(env(safe-area-inset-bottom), var(--tg-sa-bottom, 0px));
  --sa-left: max(env(safe-area-inset-left), var(--tg-sa-left, 0px));
  --sa-right: max(env(safe-area-inset-right), var(--tg-sa-right, 0px));
}
html, body { height: 100%; overflow: hidden; background: #050510; overscroll-behavior: none; }
body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  color: #cfe7ff;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
  touch-action: none;
}
/* the controls setting only makes sense where there is a finger */
.touch-only { display: none; }
body.touch .touch-only { display: block; }
.hidden { display: none !important; }
button { font-family: inherit; }

/* neon cursor: glowing cyan arrow, magenta over anything clickable */
body {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='26' height='26'%3E%3Cdefs%3E%3Cfilter id='g' x='-50%25' y='-50%25' width='200%25' height='200%25'%3E%3CfeGaussianBlur stdDeviation='1.6'/%3E%3C/filter%3E%3C/defs%3E%3Cpath d='M4 2l16 9-7 1.5L9 20z' fill='%2300ffff' filter='url(%23g)' opacity='.85'/%3E%3Cpath d='M4 2l16 9-7 1.5L9 20z' fill='%23061018' stroke='%2300ffff' stroke-width='1.4'/%3E%3C/svg%3E") 4 2, auto;
}
button, a, input[type=range], .flagbtn, .swatches button, .mrow, #showroom {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='26' height='26'%3E%3Cdefs%3E%3Cfilter id='g' x='-50%25' y='-50%25' width='200%25' height='200%25'%3E%3CfeGaussianBlur stdDeviation='1.6'/%3E%3C/filter%3E%3C/defs%3E%3Cpath d='M4 2l16 9-7 1.5L9 20z' fill='%23ff0055' filter='url(%23g)' opacity='.85'/%3E%3Cpath d='M4 2l16 9-7 1.5L9 20z' fill='%23140610' stroke='%23ff0055' stroke-width='1.4'/%3E%3C/svg%3E") 4 2, pointer;
}

#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

#minimap {
  position: fixed; right: 10px; top: 52px;
  border: 1px solid rgba(0, 255, 255, .35);
  background: rgba(5, 5, 20, .65);
  border-radius: 2px;
  pointer-events: none;
}

/* ---------------- HUD ---------------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }

#topbar {
  position: fixed; top: calc(var(--sa-top) + 8px); left: 50%; transform: translateX(-50%);
  display: flex; gap: 18px; align-items: baseline;
  padding: 6px 16px;
  background: rgba(5, 8, 24, .6);
  border: 1px solid rgba(0, 255, 255, .25);
  border-radius: 3px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
#alivecount { font-weight: 800; color: #00ffff; letter-spacing: .08em; font-size: 14px; }
#racelap { font-weight: 800; color: #ff6ec7; letter-spacing: .08em; font-size: 14px; font-variant-numeric: tabular-nums; }
#roundtime { color: #9fb8d8; font-size: 13px; }
#shrinkwarn {
  color: #ff0055; font-weight: 800; font-size: 12px; letter-spacing: .1em;
  animation: blink 0.8s step-end infinite;
}
#shrinkwarn-text { margin-left: 5px; }
#leavegame {
  pointer-events: auto; cursor: pointer;
  padding: 3px 9px; font-size: 10px; font-weight: 700; letter-spacing: .1em;
  color: #6f8fb5; background: transparent;
  border: 1px solid rgba(120, 160, 220, .35); border-radius: 2px;
}
#leavegame.armed {
  color: #ff0055; border-color: rgba(255, 0, 85, .7);
  background: rgba(255, 0, 85, .12); animation: blink 0.8s step-end infinite;
}
@keyframes blink { 50% { opacity: 0.25; } }

#statbox {
  position: fixed; left: 10px; top: calc(var(--sa-top) + 8px); width: min(210px, 42vw);
  padding: 8px 11px;
  background: rgba(5, 8, 24, .6);
  border: 1px solid rgba(0, 255, 255, .25);
  border-radius: 3px;
}
#statrow { display: flex; justify-content: space-between; font-size: 12px; letter-spacing: .08em; color: #9fb8d8; }
#mykills { color: #00ff66; font-weight: 700; }
.bar { height: 6px; border-radius: 2px; overflow: hidden; background: rgba(120, 160, 220, .15); margin-top: 6px; }
#energybar { height: 100%; width: 100%; background: linear-gradient(90deg, #ff6600, #ffe600); box-shadow: 0 0 8px rgba(255,102,0,.8); transition: width .12s; }
#itemrow { display: flex; align-items: center; gap: 7px; margin-top: 7px; font-size: 12px; font-weight: 800; letter-spacing: .08em; }
#itemrow .itemkey {
  padding: 1px 6px; border: 1px solid rgba(207, 231, 255, .5); border-radius: 3px;
  font: 700 10px ui-monospace, monospace; color: #cfe7ff;
}
@media (hover: none) { #itemrow .itemkey { display: none; } }
#itemname { text-shadow: 0 0 10px currentColor; animation: itempulse 1.2s ease-in-out infinite; }
@keyframes itempulse { 50% { opacity: .65; } }

#roster {
  position: fixed; right: 10px; top: 196px; width: min(180px, 40vw);
  padding: 7px 10px;
  background: rgba(5, 8, 24, .6);
  border: 1px solid rgba(0, 255, 255, .25);
  border-radius: 3px;
  font-size: 11px;
}
#roster .r { display: flex; align-items: center; gap: 6px; line-height: 1.8; white-space: nowrap; }
#roster .r.dead { opacity: .35; text-decoration: line-through; }
#roster .r.me { color: #00ffff; font-weight: 700; }
#roster .dot { width: 8px; height: 8px; border-radius: 1px; flex: none; box-shadow: 0 0 6px currentColor; }
#roster .n { overflow: hidden; text-overflow: ellipsis; flex: 1; }
#roster .w { color: #9fb8d8; font-variant-numeric: tabular-nums; }

#feed {
  position: fixed; left: 10px; top: 70px;
  display: flex; flex-direction: column; gap: 3px; align-items: flex-start;
}
.feeditem {
  font-size: 11px; padding: 3px 8px; border-radius: 2px;
  background: rgba(5, 8, 24, .6); border-left: 2px solid #ff0055;
  animation: feedin .2s ease-out; transition: opacity .6s;
}
@keyframes feedin { from { transform: translateX(-20px); opacity: 0; } }

#toasts {
  position: fixed; left: 50%; top: 24%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center;
}
.toast {
  font-weight: 800; letter-spacing: .12em; font-size: clamp(16px, 3.4vw, 26px);
  color: #fff; text-shadow: 0 0 18px currentColor;
  animation: toastin .25s ease-out; transition: opacity .5s;
}
@keyframes toastin { from { transform: scale(1.6); opacity: 0; } }

#spectate {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  text-align: center; font-weight: 800; letter-spacing: .15em; font-size: 14px;
  color: #ff0055; text-shadow: 0 0 14px rgba(255, 0, 85, .7);
}
#spectate small { display: block; font-weight: 400; letter-spacing: .1em; font-size: 10px; color: #6f8fb5; margin-top: 4px; }

#ping { position: fixed; left: 10px; bottom: 8px; font-size: 10px; color: #55708f; font-family: ui-monospace, monospace; }

/* ---------------- touch controls ---------------- */
/* --vh is window.innerHeight: on mobile browsers with a retracting URL bar
   that is the height the thumb can actually reach */
#pads { position: fixed; left: 0; right: 0; top: 0; height: var(--vh, 100%); z-index: 6; pointer-events: none; }

/* the drag-steer surface: everything below the HUD strip, so the thumb can
   land anywhere instead of hunting for a 96px pad */
#steerzone {
  position: absolute; left: 0; right: 0; bottom: 0;
  top: calc(var(--sa-top) + 96px);
  pointer-events: auto; touch-action: none;
}
body.pads-mode #steerzone, body.pads-mode #steerknob, body.pads-mode #steerhint { display: none !important; }
body.wheel-mode .pad { display: none !important; }

/* joystick metaphor: the ring stays where the thumb landed, the dot follows it,
   and the gap between them is exactly the steering input */
#steerknob {
  position: absolute; left: 0; top: 0; width: 0; height: 0;
  pointer-events: none; z-index: 2;
}
#steerknob .sk-base {
  position: absolute; left: -52px; top: -20px; width: 104px; height: 40px;
  border-radius: 20px;
  border: 1.5px solid rgba(0, 255, 255, .35);
  background: rgba(0, 255, 255, .06);
  box-shadow: 0 0 18px rgba(0, 255, 255, .18);
}
#steerknob .sk-dot {
  position: absolute; top: -22px; left: -22px; width: 44px; height: 44px; border-radius: 50%;
  transform: translateX(var(--dx, 0px));
  border: 2px solid rgba(0, 255, 255, .9);
  background: radial-gradient(circle, rgba(0, 255, 255, .35), rgba(0, 255, 255, .08) 70%);
  box-shadow: 0 0 24px rgba(0, 255, 255, .5);
}
#steerhint {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--sa-bottom) + 200px);
  font-size: 12px; font-weight: 800; letter-spacing: .2em; color: #00ffff;
  text-shadow: 0 0 14px rgba(0, 255, 255, .7);
  animation: hintfade 2.4s ease-in-out infinite;
  pointer-events: none;
}
@keyframes hintfade { 50% { opacity: .3; } }

.pad, #boostbtn, #usebtn {
  position: absolute; z-index: 3;
  display: flex; align-items: center; justify-content: center;
  border-radius: 14px; pointer-events: auto; touch-action: none;
  font-weight: 800; color: #00ffff;
  background: rgba(0, 255, 255, .07);
  border: 1.5px solid rgba(0, 255, 255, .4);
}
/* pads scheme: wide, easy-to-hit corner zones (a 96px square asks for aim) */
.pad {
  bottom: calc(var(--sa-bottom) + 16px);
  width: min(34vw, 150px); height: min(150px, 26vh); font-size: 34px;
}
#padL { left: 10px; }
#padR { right: 10px; }
.pad.on { background: rgba(0, 255, 255, .25); box-shadow: 0 0 24px rgba(0, 255, 255, .4); }

#boostbtn {
  bottom: calc(var(--sa-bottom) + 16px);
  right: 16px; width: 104px; height: 78px; border-radius: 39px;
  font-size: 13px; letter-spacing: .12em; color: #ffb300;
  background: rgba(255, 145, 0, .12);
  border-color: rgba(255, 145, 0, .5);
}
body.pads-mode #boostbtn {
  right: auto; left: 50%; transform: translateX(-50%);
  width: min(96px, 22vw); height: 66px;
}
#boostbtn.on { background: rgba(255, 145, 0, .4); box-shadow: 0 0 30px rgba(255, 145, 0, .6); }
#usebtn {
  bottom: calc(var(--sa-bottom) + 106px);
  right: 16px; min-width: 104px; max-width: 46vw; padding: 0 12px; height: 54px; border-radius: 27px;
  white-space: nowrap; overflow: hidden;
  font-size: 12px; letter-spacing: .1em; color: #b000ff;
  background: rgba(176, 0, 255, .14); border-color: rgba(176, 0, 255, .55);
  animation: itempulse 1.2s ease-in-out infinite;
}
body.pads-mode #usebtn { right: auto; left: 50%; transform: translateX(-50%); bottom: 96px; }
/* a real mouse never needs any of this */
@media (hover: hover) and (pointer: fine) { #pads { display: none !important; } }

/* ---------------- night ride (free roam) ---------------- */
#cruisehud { position: fixed; inset: 0; pointer-events: none; z-index: 6; }
#cruiseexit {
  position: fixed; top: calc(var(--sa-top) + 10px); left: 50%; transform: translateX(-50%);
  pointer-events: auto; cursor: pointer;
  padding: 8px 16px; font-size: 12px; font-weight: 800; letter-spacing: .14em;
  color: #ff6ec7; background: rgba(20, 5, 24, .6);
  border: 1px solid rgba(255, 110, 199, .5); border-radius: 3px;
}
#cruisehint {
  position: fixed; bottom: calc(var(--sa-bottom) + 14px); left: 50%; transform: translateX(-50%);
  font-size: 11px; color: #9b7fb5; letter-spacing: .1em; white-space: nowrap;
}
@media (hover: none) { #cruisehint { bottom: calc(var(--sa-bottom) + 180px); } }

/* ---------------- countdown ---------------- */
#bigcount {
  position: fixed; left: 50%; top: 38%; transform: translate(-50%, -50%);
  font-size: clamp(80px, 22vw, 170px); font-weight: 900; z-index: 7;
  color: #00ffff; text-shadow: 0 0 40px rgba(0, 255, 255, .9), 0 0 120px rgba(0, 255, 255, .4);
  animation: countpulse .9s ease-out infinite;
  pointer-events: none;
}
@keyframes countpulse { from { transform: translate(-50%, -50%) scale(1.25); opacity: 1; } to { transform: translate(-50%, -50%) scale(.95); opacity: .8; } }

/* ---------------- lobby ---------------- */
#lobbyui {
  position: fixed; inset: 0; z-index: 8;
  display: flex; align-items: flex-end; justify-content: center;
  padding-bottom: calc(var(--sa-bottom) + 20px);
  pointer-events: none;
}
.lob-box {
  pointer-events: auto;
  width: min(430px, 94vw);
  padding: 16px 18px;
  background: rgba(5, 8, 24, .82);
  border: 1px solid rgba(0, 255, 255, .35);
  border-radius: 4px;
  backdrop-filter: blur(4px);
  text-align: center;
}
.kicker { font-family: ui-monospace, monospace; font-size: 11px; letter-spacing: .22em; color: #6f8fb5; margin-bottom: 8px; }
#lob-status { font-size: 15px; font-weight: 700; letter-spacing: .06em; color: #00ffff; min-height: 20px; }
#lob-members { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 12px 0; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; padding: 4px 9px; border-radius: 2px;
  background: rgba(120, 160, 220, .08); border: 1px solid rgba(120, 160, 220, .2);
}
.chip .dot { width: 8px; height: 8px; border-radius: 1px; box-shadow: 0 0 6px currentColor; }
.chip.bot { opacity: .55; }
#lob-standings { margin: 10px 0 2px; font-size: 12px; }
#lob-standings .row { display: flex; justify-content: space-between; gap: 10px; line-height: 1.9; }
#lob-standings .row.winner { color: #ffe600; text-shadow: 0 0 10px rgba(255, 230, 0, .5); font-weight: 700; }
.lob-actions { display: flex; gap: 8px; justify-content: center; margin-top: 10px; }
button.ghost {
  padding: 8px 14px; font-size: 11px; font-weight: 700; letter-spacing: .12em;
  color: #9fd8ff; background: transparent; cursor: pointer;
  border: 1px solid rgba(0, 255, 255, .4); border-radius: 3px;
}
button.ghost:hover { background: rgba(0, 255, 255, .12); }
button.ghost.warn { color: #ffb300; border-color: rgba(255, 145, 0, .5); }

/* ---------------- winner banner ---------------- */
#winbanner {
  position: fixed; left: 50%; top: 26%; transform: translateX(-50%);
  z-index: 8; text-align: center; pointer-events: none;
  font-size: clamp(26px, 6vw, 48px); font-weight: 900; letter-spacing: .1em;
  color: #ffe600; text-shadow: 0 0 30px rgba(255, 230, 0, .8);
  animation: toastin .3s ease-out;
  white-space: nowrap;
}
#winbanner small { display: block; font-size: .38em; letter-spacing: .3em; color: #9fb8d8; text-shadow: none; margin-bottom: 8px; }

/* ---------------- menu ---------------- */
#overlay {
  position: fixed; inset: 0; z-index: 10;
  display: flex; justify-content: center;
  /* the menu can outgrow a phone screen: let it scroll instead of clipping */
  overflow-y: auto; touch-action: pan-y; -webkit-overflow-scrolling: touch;
  background: radial-gradient(ellipse at center, rgba(8, 12, 40, .55), rgba(3, 4, 14, .88));
  transition: opacity .3s;
}
#overlay.gone { opacity: 0; pointer-events: none; }
/* margin:auto centers when there is room and lets the overlay scroll when not */
#menu {
  text-align: center; max-width: 94vw; margin: auto;
  padding: calc(var(--sa-top) + 24px) 20px calc(var(--sa-bottom) + 24px);
}
#menu h1 {
  font-size: clamp(46px, 12vw, 84px); font-weight: 900; letter-spacing: .03em;
  color: #00ffff; text-shadow: 0 0 30px rgba(0, 255, 255, .9), 0 0 90px rgba(0, 255, 255, .4);
  line-height: .95; margin-bottom: 18px;
}
#menu h1 span { color: #ff0055; text-shadow: 0 0 24px rgba(255, 0, 85, .8); }
#showroom {
  display: block; width: 440px; max-width: 100%; aspect-ratio: 2 / 1;
  margin: -8px auto 10px; touch-action: none;
}
#name {
  display: block; width: 460px; max-width: 100%; margin: 0 auto 14px;
  padding: 14px 16px; font-size: 18px; text-align: center; letter-spacing: .12em;
  color: #cfe7ff; background: rgba(10, 16, 40, .8);
  border: 1px solid rgba(0, 255, 255, .4); border-radius: 4px; outline: none;
  text-transform: uppercase;
}
#name:focus { border-color: #00ffff; box-shadow: 0 0 16px rgba(0, 255, 255, .35); }

/* --- main menu hub: play + sectioned list ------------------------------------ */
.msection { width: 460px; max-width: 100%; margin: 0 auto; }
#play {
  width: 100%; padding: 18px; font-size: 20px; font-weight: 800;
  letter-spacing: .24em; color: #041018;
  background: linear-gradient(180deg, #3dffff, #00e0e0); border: 0; border-radius: 4px;
  box-shadow: 0 0 26px rgba(0, 255, 255, .5), inset 0 0 0 1px rgba(255, 255, 255, .35);
  transition: transform .12s, box-shadow .12s;
}
#play:hover { transform: translateY(-1px); box-shadow: 0 0 44px rgba(0, 255, 255, .85), inset 0 0 0 1px rgba(255, 255, 255, .5); }
#play:disabled { opacity: .4; }

#mainmenu { display: flex; flex-direction: column; gap: 9px; margin-top: 16px; }
.mrow {
  display: flex; align-items: center; gap: 14px; width: 100%;
  padding: 15px 15px; text-align: left;
  color: #cfe7ff; background: rgba(6, 10, 28, .82);
  border: 1px solid color-mix(in srgb, var(--mc) 38%, transparent); border-radius: 4px;
  box-shadow: inset 2px 0 0 var(--mc);
  transition: background .12s, box-shadow .12s, border-color .12s;
}
.mrow:hover {
  background: color-mix(in srgb, var(--mc) 9%, rgba(6, 10, 28, .85));
  border-color: color-mix(in srgb, var(--mc) 75%, transparent);
  box-shadow: inset 2px 0 0 var(--mc), 0 0 14px color-mix(in srgb, var(--mc) 30%, transparent);
}
.mico {
  width: 30px; height: 30px; flex: none;
  fill: none; stroke: var(--mc); stroke-width: 1.6;
  filter: drop-shadow(0 0 3px var(--mc));
}
.mlabel { flex: 1; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.mlabel > span { font-size: 16px; font-weight: 800; letter-spacing: .12em; }
.mlabel small {
  font: 12px ui-monospace, monospace; letter-spacing: .08em; color: #6f8fb5;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.mlabel small:empty { display: none; }
.mchev { color: var(--mc); font-size: 24px; line-height: 1; opacity: .8; }

/* --- sub-sections ------------------------------------------------------------- */
.msection.sub {
  padding: 12px 14px 16px; text-align: left;
  background: rgba(6, 10, 28, .82); border: 1px solid rgba(0, 255, 255, .3); border-radius: 4px;
  animation: secin .16s ease-out;
}
@keyframes secin { from { transform: translateX(14px); opacity: 0; } }
.backbtn {
  display: block; margin-bottom: 8px; padding: 6px 10px 6px 0;
  background: transparent; border: 0; color: #6f8fb5;
  font-size: 11px; font-weight: 700; letter-spacing: .16em;
}
.backbtn:hover { color: #00ffff; }
.seckicker {
  font-family: ui-monospace, monospace; font-size: 13px; letter-spacing: .24em;
  color: #00ffff; text-shadow: 0 0 10px rgba(0, 255, 255, .5);
  border-bottom: 1px solid rgba(0, 255, 255, .25); padding-bottom: 8px; margin-bottom: 12px;
}
.pickcol { margin-bottom: 12px; }
.pickcol > span {
  display: block; margin-bottom: 6px;
  font: 12px ui-monospace, monospace; letter-spacing: .18em; color: #6f8fb5;
}
#modehint, #roomnote, #chnote, #ctrlschemenote { margin-top: 5px; font-size: 12px; color: #55708f; line-height: 1.6; }

.customizer { margin: 0; }
.pickrow { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 40px; }
.pickrow > span { flex: none; width: 74px; text-align: left; font: 12px ui-monospace, monospace; letter-spacing: .13em; color: #6f8fb5; }
.swatches, .optionpick { display: flex; gap: 6px; flex: 1; justify-content: flex-end; flex-wrap: wrap; }
.swatches button {
  width: 34px; height: 26px; padding: 0; background: var(--pick);
  border: 2px solid rgba(255, 255, 255, .12); border-radius: 3px; box-shadow: 0 0 7px color-mix(in srgb, var(--pick) 55%, transparent);
}
.swatches button.selected { border-color: #fff; outline: 1px solid var(--pick); outline-offset: 2px; }
.optionpick button {
  min-width: 0; flex: 1; padding: 9px 7px;
  color: #7090b8; background: rgba(20, 34, 70, .55); border: 1px solid rgba(100, 150, 210, .22);
  border-radius: 3px; font-size: 12px; font-weight: 700; letter-spacing: .05em;
  transition: color .1s, border-color .1s, background .1s;
}
.optionpick button:hover { border-color: rgba(0, 255, 255, .5); color: #9fd8ff; }
.optionpick button.selected { color: #00ffff; border-color: #00ffff; background: rgba(0, 255, 255, .1); box-shadow: 0 0 8px rgba(0, 255, 255, .18); }
.optionpick button.disabled { opacity: .35; pointer-events: none; }

#privrow { display: flex; gap: 8px; margin-bottom: 12px; }
#roomcode {
  flex: 1; min-width: 0; padding: 10px; font-size: 13px; letter-spacing: .18em; text-align: center;
  color: #cfe7ff; background: rgba(10, 16, 40, .8); text-transform: uppercase;
  border: 1px solid rgba(0, 255, 255, .3); border-radius: 4px; outline: none;
}
#roomcode:focus { border-color: #00ffff; }
button.wide { display: block; width: 100%; margin-bottom: 10px; }
#mkroom {
  display: block; width: 100%; padding: 12px; font-size: 12px; font-weight: 800; letter-spacing: .14em;
  color: #041018; background: #00ff66; border: 0; border-radius: 4px;
  box-shadow: 0 0 18px rgba(0, 255, 102, .4);
}
#mkroom:hover { box-shadow: 0 0 30px rgba(0, 255, 102, .7); }

/* daily challenges */
#chlist { display: flex; flex-direction: column; gap: 8px; }
.chrow {
  padding: 10px 12px; border-radius: 4px;
  background: rgba(120, 160, 220, .06); border: 1px solid rgba(120, 160, 220, .18);
}
.chrow.done { border-color: rgba(0, 255, 102, .45); background: rgba(0, 255, 102, .06); }
.chtop { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; font-weight: 700; letter-spacing: .05em; }
.chreward { color: #ffe600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.chrow.done .chreward { color: #00ff66; }
.chbar { height: 5px; margin-top: 8px; border-radius: 2px; overflow: hidden; background: rgba(120, 160, 220, .15); }
.chbar div { height: 100%; background: linear-gradient(90deg, #00ffff, #00ff66); box-shadow: 0 0 8px rgba(0, 255, 255, .6); }
.chprog { margin-top: 5px; font: 10px ui-monospace, monospace; color: #6f8fb5; letter-spacing: .1em; }
#chlist .chempty { font-size: 11px; color: #6f8fb5; text-align: center; padding: 14px 0; }

#help { margin-top: 12px; font-size: 11px; color: #6f8fb5; line-height: 1.9; }
@media (hover: hover) and (pointer: fine) { .help-touch { display: none; } }
@media (hover: none) { .help-pc { display: none; } }
#connmsg { margin-top: 12px; font-size: 12px; color: #ff5252; min-height: 16px; text-align: center; }
#langpick { justify-content: flex-start; }
#langpick button { flex: none; padding: 7px 14px; font-size: 10px; }

#ctrlhint {
  margin: 10px 0 2px; padding: 9px 12px; text-align: left;
  background: rgba(120, 160, 220, .06); border: 1px solid rgba(120, 160, 220, .15); border-radius: 3px;
}
#ctrlhint .kicker { margin-bottom: 6px; }
.ctrlrow { display: flex; justify-content: space-between; gap: 12px; font-size: 11px; line-height: 1.9; }
.ctrlrow span { color: #6f8fb5; letter-spacing: .1em; font-size: 10px; }
.ctrlrow b { color: #cfe7ff; font-weight: 600; }
#ctrlgoal { margin-top: 6px; font-size: 10px; color: #55708f; line-height: 1.5; }

#audiobtn {
  position: fixed; right: 12px; top: calc(var(--sa-top) + 10px); width: 36px; height: 36px;
  background: rgba(5, 8, 24, .65); color: #6f8fb5; border: 1px solid rgba(0, 255, 255, .3);
  border-radius: 3px; font-size: 16px; cursor: pointer; z-index: 21;
}
#audiobtn.off { color: #334; text-decoration: line-through; }
#audiopanel {
  position: fixed; right: 12px; top: 52px; z-index: 21;
  display: flex; flex-direction: column; gap: 10px;
  padding: 12px 14px;
  background: rgba(5, 8, 24, .88); border: 1px solid rgba(0, 255, 255, .3);
  border-radius: 3px; backdrop-filter: blur(4px);
}
.volrow { display: flex; align-items: center; gap: 8px; }
.volrow > span { width: 40px; font: 9px ui-monospace, monospace; letter-spacing: .12em; color: #6f8fb5; text-align: left; }
.volico {
  width: 26px; height: 26px; flex: none; cursor: pointer;
  background: transparent; color: #9fd8ff; font-size: 13px;
  border: 1px solid rgba(0, 255, 255, .3); border-radius: 3px;
}
.volico.off { color: #334; text-decoration: line-through; }
#audiopanel input[type=range] {
  width: 130px; accent-color: #00ffff; touch-action: none;
}

/* previewing a locked item in the showroom */
.optionpick button.preview, #flagopen.preview {
  color: #ffe600; border-color: rgba(255, 230, 0, .8); border-style: dashed;
  background: rgba(255, 230, 0, .08);
}
.flagbtn.preview { border-color: rgba(255, 230, 0, .9); border-style: dashed; }

/* flag picker modal */
.flagbox { width: min(430px, 94vw); }
#flagsearchrow { margin: 4px 0 10px; }
#flagsearch {
  width: 100%; padding: 9px 11px; font-size: 13px; letter-spacing: .08em;
  color: #cfe7ff; background: rgba(10, 16, 40, .8); text-transform: uppercase;
  border: 1px solid rgba(0, 255, 255, .3); border-radius: 3px; outline: none;
}
#flaggrid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: 6px;
  max-height: 52vh; overflow-y: auto; padding: 2px;
}
.flagbtn {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 2px 4px; cursor: pointer;
  background: rgba(20, 34, 70, .55); border: 1px solid rgba(100, 150, 210, .2); border-radius: 2px;
}
.flagbtn span { font-size: 20px; line-height: 1; }
.flagbtn small { font: 700 8px ui-monospace, monospace; color: #7090b8; letter-spacing: .08em; }
.flagbtn.selected { border-color: #00ffff; background: rgba(0, 255, 255, .12); }
.flagbtn.locked { opacity: .55; }
.flagbtn.locked::after { content: '🔒'; font-size: 8px; }

/* ---------------- profile / economy ---------------- */
#profilebtn {
  position: fixed; left: 12px; top: calc(var(--sa-top) + 10px); z-index: 11;
  display: flex; align-items: center; gap: 10px;
  max-width: min(280px, calc(100vw - 76px));
  padding: 10px 14px; cursor: pointer; text-align: left;
  color: #cfe7ff; font-size: 14px; font-weight: 800; letter-spacing: .08em;
  background: rgba(5, 8, 24, .8); border: 1px solid rgba(0, 255, 255, .45); border-radius: 4px;
  box-shadow: 0 0 18px rgba(0, 255, 255, .18);
}
#profilebtn:hover { border-color: rgba(0, 255, 255, .9); background: rgba(0, 255, 255, .1); }
#profilebtn .dot { width: 12px; height: 12px; flex: none; border-radius: 2px; box-shadow: 0 0 9px currentColor; }
.pb-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
#pb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#pb-cur { font: 12px ui-monospace, monospace; color: #9fb8d8; letter-spacing: .06em; }
#pb-alert {
  flex: none; padding: 4px 7px; border-radius: 2px;
  font: 700 9px ui-monospace, monospace; letter-spacing: .1em; white-space: nowrap;
  color: #ffe600; background: rgba(255, 230, 0, .12); border: 1px solid rgba(255, 230, 0, .5);
  animation: blink 1.6s step-end infinite;
}

/* --- "save your progress" nudge: menu card + lobby row ----------------------- */
.savecard {
  display: flex; align-items: center; gap: 12px; width: 100%;
  margin-top: 12px; padding: 13px 14px; text-align: left; cursor: pointer;
  color: #ffe600; background: rgba(255, 230, 0, .07);
  border: 1px solid rgba(255, 230, 0, .5); border-radius: 4px;
  box-shadow: 0 0 20px rgba(255, 230, 0, .12);
  animation: savepulse 2.8s ease-in-out infinite;
}
.savecard:hover { background: rgba(255, 230, 0, .14); border-color: rgba(255, 230, 0, .9); }
@keyframes savepulse {
  50% { box-shadow: 0 0 30px rgba(255, 230, 0, .3); border-color: rgba(255, 230, 0, .85); }
}
.sc-ico { font-size: 24px; line-height: 1; flex: none; text-shadow: 0 0 12px rgba(255, 230, 0, .7); }
.sc-txt { flex: 1; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.sc-txt b { font-size: 15px; font-weight: 800; letter-spacing: .1em; }
.sc-txt small { font: 11px ui-monospace, monospace; letter-spacing: .06em; color: #c9b877; line-height: 1.5; }
.sc-cta {
  flex: none; padding: 9px 12px; border-radius: 3px;
  font-size: 11px; font-weight: 800; letter-spacing: .12em;
  color: #1a1400; background: #ffe600; box-shadow: 0 0 16px rgba(255, 230, 0, .5);
}
.savecard.slim { margin: 10px 0 0; padding: 10px 12px; animation: none; }
.savecard.slim .sc-ico { font-size: 19px; }
.savecard.slim .sc-txt b { font-size: 12px; }
.savecard.slim .sc-txt small { font-size: 10px; }
.savecard.slim .sc-cta { padding: 7px 10px; font-size: 10px; }
@media (max-width: 520px) {
  .savecard { flex-wrap: wrap; }
  .sc-cta { width: 100%; text-align: center; }
}
.optionpick button.locked { opacity: .5; }
.optionpick button.locked::after { content: ' 🔒'; font-size: 7px; }
#buyhint {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-top: 8px; padding: 7px 9px; font-size: 11px; letter-spacing: .06em;
  color: #ffe600; background: rgba(255, 230, 0, .06); border: 1px solid rgba(255, 230, 0, .3); border-radius: 2px;
  text-align: left;
}
.modal {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  background: rgba(2, 3, 10, .78); backdrop-filter: blur(3px);
}
.modalbox {
  position: relative;
  width: min(420px, 94vw); max-height: 86dvh; overflow-y: auto;
  touch-action: pan-y; -webkit-overflow-scrolling: touch;
  padding: 20px 22px; text-align: center;
  background: rgba(6, 10, 28, .96); border: 1px solid rgba(0, 255, 255, .4); border-radius: 4px;
}
.modalclose {
  position: absolute; right: 8px; top: 8px; width: 30px; height: 30px;
  background: transparent; border: 0; color: #6f8fb5; font-size: 14px; cursor: pointer;
}
#pc-name { font-size: 24px; font-weight: 900; letter-spacing: .1em; color: #00ffff; }
#pc-league { font-size: 13px; font-weight: 800; letter-spacing: .14em; margin: 6px 0 8px; }
.leaguebar { max-width: 220px; margin: 0 auto; }
#pc-leaguebar { height: 100%; background: linear-gradient(90deg, #00ffff, #b000ff); transition: width .3s; }
#pc-cp { font-size: 11px; color: #6f8fb5; margin: 5px 0 10px; }
#pc-currencies { display: flex; justify-content: center; gap: 18px; font-size: 14px; font-weight: 700; margin-bottom: 12px; }
#pc-stats {
  display: grid; grid-template-columns: 1fr 1fr; gap: 5px 14px;
  font-size: 12px; color: #9fb8d8; text-align: left;
  padding: 10px 12px; margin-bottom: 12px;
  background: rgba(120, 160, 220, .06); border: 1px solid rgba(120, 160, 220, .15); border-radius: 3px;
}
#pc-stats b { color: #cfe7ff; float: right; font-variant-numeric: tabular-nums; }
#leaguesbtn { margin-bottom: 12px; }
#leagueladder { display: flex; flex-direction: column; gap: 6px; margin: 12px 0 10px; }
.lgrow {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 10px; font-size: 11px; text-align: left;
  background: rgba(120, 160, 220, .06); border: 1px solid rgba(120, 160, 220, .15); border-radius: 3px;
}
.lgrow .dot { width: 9px; height: 9px; border-radius: 2px; flex: none; box-shadow: 0 0 7px currentColor; }
.lgrow .lgname { font-weight: 800; letter-spacing: .08em; flex: 1; white-space: nowrap; }
.lgrow .lgcp { color: #9fb8d8; font-variant-numeric: tabular-nums; }
.lgrow .lgreward { width: 100%; padding-left: 17px; color: #6f8fb5; font-size: 10px; }
.lgrow.current { border-color: rgba(0, 255, 255, .6); background: rgba(0, 255, 255, .07); }
.lgrow.passed { opacity: .6; }
.lgrow .lgyou { width: 100%; padding-left: 17px; color: #00ffff; font-weight: 700; font-size: 10px; letter-spacing: .1em; }
#lg-note { font-size: 10px; color: #55708f; line-height: 1.6; text-align: left; }

#watchad { width: 100%; color: #d9b0ff; border-color: rgba(176, 0, 255, .5); }
#watchad:hover { background: rgba(176, 0, 255, .12); }
#pc-adsleft { font-size: 10px; color: #55708f; margin: 6px 0 14px; }
#starshop { border-top: 1px solid rgba(120, 160, 220, .15); padding-top: 12px; margin-bottom: 14px; }
#starpacks { display: grid; gap: 6px; }
.starpack {
  display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 10px;
  width: 100%; padding: 10px 12px; text-align: left; cursor: pointer;
  font-family: inherit; color: #cfe7ff;
  background: rgba(10, 16, 40, .8); border: 1px solid rgba(255, 214, 0, .3); border-radius: 3px;
}
.starpack:hover:not(:disabled) { background: rgba(255, 214, 0, .1); }
.starpack:disabled { opacity: .45; cursor: default; }
.starpack.bundle { border-color: rgba(255, 214, 0, .75); background: rgba(255, 214, 0, .07); }
.sp-title { font-size: 12px; letter-spacing: .08em; }
.sp-title em { font-style: normal; font-size: 10px; color: #00ff66; }
.sp-gain { font-size: 11px; color: #d9b0ff; }
.sp-price { font-size: 13px; font-weight: 700; color: #ffd700; }
#linkbox {
  padding: 14px; margin-bottom: 14px; text-align: left;
  background: rgba(255, 230, 0, .06);
  border: 1px solid rgba(255, 230, 0, .45); border-radius: 4px;
}
#linkbox.linked { background: rgba(0, 255, 102, .06); border-color: rgba(0, 255, 102, .4); }
.linkhead {
  font-size: 15px; font-weight: 800; letter-spacing: .1em; color: #ffe600;
  text-shadow: 0 0 12px rgba(255, 230, 0, .4);
}
#linkbox.linked .linkhead { color: #00ff66; text-shadow: none; font-size: 13px; }
#linknote {
  margin: 7px 0 11px;
  font: 11px ui-monospace, monospace; letter-spacing: .05em; color: #9fb8d8; line-height: 1.6;
}
#linkbox input {
  display: block; width: 100%; margin: 0 0 8px;
  padding: 11px 12px; font-size: 14px; letter-spacing: .05em;
  color: #cfe7ff; background: rgba(10, 16, 40, .85);
  border: 1px solid rgba(255, 230, 0, .35); border-radius: 3px; outline: none;
}
#linkbox input:focus { border-color: #ffe600; box-shadow: 0 0 14px rgba(255, 230, 0, .25); }
#linkacc {
  width: 100%; padding: 13px; margin-top: 2px; cursor: pointer;
  font-size: 14px; font-weight: 800; letter-spacing: .14em;
  color: #1a1400; background: #ffe600; border: 0; border-radius: 3px;
  box-shadow: 0 0 20px rgba(255, 230, 0, .45);
}
#linkacc:hover { background: #fff04d; }
#loginacc { width: 100%; margin-top: 8px; color: #9fb8d8; border-color: rgba(120, 160, 220, .35); }
#accmsg { margin-top: 8px; font-size: 11px; color: #ff5252; }
#accmsg:empty { display: none; }
#accmsg.ok { color: #00ff66; }
.admode { border-color: rgba(176, 0, 255, .55); }
#adart {
  margin: 14px 0; padding: 34px 8px; font-size: 15px; font-weight: 800; letter-spacing: .3em; color: #fff;
  background: linear-gradient(120deg, #b000ff33, #00ffff33, #ff005533, #b000ff33);
  background-size: 300% 300%; animation: adshift 2.2s linear infinite;
  border: 1px solid rgba(176, 0, 255, .4); border-radius: 3px;
}
@keyframes adshift { 0% { background-position: 0% 50%; } 100% { background-position: 300% 50%; } }
#adcount { font-size: 30px; font-weight: 900; color: #b000ff; text-shadow: 0 0 18px rgba(176, 0, 255, .8); }
#adclaim {
  width: 100%; padding: 12px; margin-top: 10px; font-size: 14px; font-weight: 800; letter-spacing: .14em;
  color: #041018; background: #b000ff; border: 0; border-radius: 3px; cursor: pointer;
  box-shadow: 0 0 22px rgba(176, 0, 255, .55);
}

/* narrow screens: keep the top bar clear of the stat box and audio button */
@media (max-width: 640px) {
  #topbar {
    left: auto; right: 52px; transform: none; gap: 8px; padding: 4px 8px;
    /* stay clear of the stat box on the left; wrap to a second line if tight */
    max-width: calc(100vw - 188px);
    flex-wrap: wrap; justify-content: flex-end; row-gap: 2px;
    white-space: normal;
  }
  #alivecount { font-size: 12px; }
  #roundtime { font-size: 11px; }
  #shrinkwarn-text { display: none; } /* just the blinking ⚠, the bar is tight */
  #statbox { width: min(118px, 32vw); padding: 6px 9px; }
  #statrow { font-size: 10px; }
  #minimap { top: calc(var(--sa-top) + 52px); }
  #roster { top: 240px; font-size: 10px; }
  /* menu content starts below the fixed profile / audio chips (extra
     specificity so the short-screen padding rules don't override it) */
  #overlay #menu { padding-top: max(84px, calc(var(--sa-top) + 76px)); }
  /* the showroom frames a wide, short bike: on a phone the extra height is
     just empty grid between the title and PLAY */
  #showroom { aspect-ratio: 2.5 / 1; }
}

/* ---------------- phone gameplay HUD ----------------
   A phone has room for the arena or for a scoreboard, not both. Keep the
   middle of the screen clear: numbers you act on stay, the rest goes. */
@media (max-width: 640px), (max-height: 480px) {
  #minimap { width: 104px; height: 104px; right: 8px; }
  /* names + win counts are lobby information; mid-round all you need is who is
     still alive, so the roster collapses to a strip of colour chips */
  #roster:not(.race) {
    right: 8px; top: calc(var(--sa-top) + 166px); width: auto; max-width: 116px;
    display: flex; flex-wrap: wrap; gap: 5px; justify-content: flex-end;
    padding: 6px 7px;
  }
  #roster:not(.race) .n, #roster:not(.race) .w { display: none; }
  #roster:not(.race) .r { line-height: 1; }
  #roster:not(.race) .dot { width: 11px; height: 11px; border-radius: 2px; }
  #roster.race { top: calc(var(--sa-top) + 166px); max-height: 190px; overflow: hidden; }
  #feed { top: calc(var(--sa-top) + 62px); max-width: 58vw; }
  /* the USE button already names the item under your thumb */
  #itemrow { display: none; }
  .feeditem { font-size: 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
  #toasts { top: 30%; }
  #spectate { bottom: calc(var(--sa-bottom) + 190px); }
  #ping { left: 8px; bottom: calc(var(--sa-bottom) + 4px); }
  #ping.quiet { display: none; }
  /* fingers need targets, not decorations */
  .optionpick button { padding: 12px 8px; font-size: 12px; }
  .swatches button { width: 40px; height: 34px; }
  .backbtn { padding: 10px 14px 10px 0; font-size: 12px; }
  .modalclose { width: 44px; height: 44px; right: 4px; top: 4px; font-size: 16px; }
  button.ghost { padding: 11px 14px; }
  #leavegame { padding: 7px 10px; }
}
#ping.warn { color: #ffb300; }
/* landscape phone: the pads own the sides, so pull the side HUD in */
@media (max-height: 480px) and (pointer: coarse) {
  #roster:not(.race), #roster.race { display: none; }
  #minimap { width: 84px; height: 84px; top: calc(var(--sa-top) + 40px); }
  #steerhint { bottom: calc(var(--sa-bottom) + 150px); }
}

/* phones in portrait: tighten the menu so little-to-no scrolling is needed */
@media (max-height: 950px) {
  #menu h1 { font-size: clamp(40px, 11vw, 70px); margin-bottom: 12px; }
  #showroom { width: 340px; margin: -6px auto 8px; }
  #name { padding: 11px 13px; margin-bottom: 10px; }
  .pickrow { min-height: 36px; }
  #play { padding: 15px; font-size: 18px; }
  #mainmenu { margin-top: 12px; gap: 7px; }
  .mrow { padding: 12px 13px; }
}
@media (max-height: 720px) {
  #menu { padding-top: 10px; padding-bottom: 10px; }
  #menu h1 { font-size: 44px; margin-bottom: 8px; }
  #showroom { width: 290px; margin-top: -2px; margin-bottom: 5px; }
  #name { padding: 9px 12px; margin-bottom: 8px; }
  .mlabel > span { font-size: 14px; }
}

/* --- portal build ------------------------------------------------------------
   Web-game portals (CrazyGames et al.) get an offline solo build: no server, so
   nothing that needs one is shown, and no links may leave the iframe. */
html.portal #menu-room,
html.portal .mrow[data-section="menu-room"],
html.portal #copylink,
html.portal #linkbox,
html.portal #savecard,
html.portal #lobsave,
html.portal #pb-alert,
html.portal #starshop,
html.portal #ping { display: none !important; }
