* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  background: #0b0d10;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: #f2f4f2;
  user-select: none;
}

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

.panel {
  position: fixed;
  background: rgba(10, 12, 16, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  padding: 10px 12px;
  backdrop-filter: blur(6px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}

#standings {
  top: 14px;
  left: 14px;
  min-width: 190px;
  max-height: 60vh;
  overflow-y: auto;
  font-size: 13px;
}

#standings:empty { display: none; }

#standings .hdr {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 0 4px 5px;
  margin-bottom: 3px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1.5px;
}

#standings .srv { font-weight: 600; letter-spacing: 0; opacity: 0.55; white-space: nowrap; }
#standings .row.spec { opacity: 0.7; }
#standings .row.spec .pos { font-weight: 400; font-size: 12px; }
#standings .you { opacity: 0.55; font-weight: 400; margin-left: 4px; font-size: 11px; }

#standings .row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 3px 4px;
}

#standings .row.self { background: rgba(255, 213, 79, 0.16); border-radius: 6px; }
#standings .pos { width: 22px; font-weight: 700; opacity: 0.85; }
#standings .chip { width: 11px; height: 11px; border-radius: 50%; border: 1px solid rgba(0,0,0,0.5); }
#standings .nm { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 120px; }
#standings .lp { opacity: 0.75; font-variant-numeric: tabular-nums; }

#raceInfo {
  top: 14px;
  right: 14px;
  text-align: right;
  font-size: 15px;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
}

#raceInfo:empty { display: none; }
#raceInfo b { font-size: 21px; }
#raceInfo .grace { color: #ffab40; font-weight: 700; }

#topCenter {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  pointer-events: none;
  max-width: 92vw;
}

#phaseMsg {
  display: inline-block;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 1px;
  white-space: nowrap;
  background: rgba(10, 12, 16, 0.5);
  border-radius: 12px;
  padding: 6px 22px;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
}

#phaseMsg:empty { display: none; }

#subMsg { font-size: 15px; margin-top: 6px; opacity: 0.95; text-shadow: 0 2px 8px rgba(0,0,0,0.85); }

#bigCount {
  position: fixed;
  top: 34%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 150px;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 0 34px rgba(255, 90, 40, 0.95), 0 4px 14px rgba(0, 0, 0, 0.55);
  pointer-events: none;
  display: none;
}

#bigCount.pop { animation: pop 0.9s ease-out; display: block; }

@keyframes pop {
  0% { transform: translate(-50%, -50%) scale(1.7); opacity: 0; }
  18% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

#notice {
  position: fixed;
  top: 46%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 34px;
  font-weight: 900;
  letter-spacing: 2px;
  color: #ffd54f;
  text-shadow: 0 0 22px rgba(255, 170, 0, 0.8), 0 3px 10px rgba(0,0,0,0.7);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s;
}

#notice.show { opacity: 1; }

#joinWrap {
  position: fixed;
  left: 50%;
  bottom: 9%;
  transform: translateX(-50%);
  text-align: center;
  display: none;
  z-index: 7; /* above the HUD (#minimap, #speedo) so the ride pop-up clears it; #overlay is 20 */
}

#nameRow {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 14px;
}

#nameRow label {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 2px;
  opacity: 0.85;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
}

#nameInput {
  width: 180px;
  font: inherit;
  font-size: 18px;
  font-weight: 700;
  text-align: center;
  color: #fff;
  background: rgba(0, 0, 0, 0.45);
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-radius: 10px;
  padding: 8px 12px;
  outline: none;
  backdrop-filter: blur(6px);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

#nameInput:focus { border-color: #ffd54f; box-shadow: 0 0 18px rgba(255, 213, 79, 0.35); }
#nameInput.bad { border-color: #ef5350; }
#nameInput:disabled { opacity: 0.6; cursor: default; }

/* ---- lobby pop-up cards (map vote + garage) ---- */
/* Both are hidden until their toggle button in the join row opens them; only one is open at a time. */
.popCard {
  display: none;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 16px;
  backdrop-filter: blur(6px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.popClose {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  line-height: 22px;
  color: #fff;
  background: rgba(0, 0, 0, 0.45);
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.08s ease;
}

.popClose:hover { background: rgba(40, 44, 52, 0.7); border-color: rgba(255, 255, 255, 0.6); }
.popClose:active { transform: scale(0.92); }

/* Map vote card: centred on the screen, 4 tiles across x 2 rows. */
#mapVote {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 540px; /* 4 x (104px thumb + 12px pad + 4px border) + 3 x 8px gap + 32px card padding */
  max-width: 92vw;
  padding: 14px 16px 12px;
  text-align: center;
  z-index: 8;
}

#mapVoteTitle {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 2px;
  opacity: 0.85;
  margin-bottom: 10px;
}

#mapVoteGrid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.mapTile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 6px 5px;
  font: inherit;
  color: #f2f4f2;
  background: rgba(0, 0, 0, 0.45);
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.08s ease;
}

.mapTile:hover:not(:disabled) { border-color: rgba(255, 255, 255, 0.5); transform: translateY(-1px); }
.mapTile:disabled { cursor: default; opacity: 0.55; }
.mapTile.lead { border-color: rgba(255, 213, 79, 0.55); }
.mapTile.mine { border-color: #ffd54f; box-shadow: 0 0 16px rgba(255, 213, 79, 0.35); }
.mapTile.win { border-color: #38c956; box-shadow: 0 0 18px rgba(56, 201, 86, 0.45); opacity: 1; }

.mapTile canvas {
  width: 104px;
  height: 64px;
  max-width: 100%;
  border-radius: 6px;
  display: block;
}

.mapTile .mapName {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.mapTile .mapCount {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 20px;
  padding: 1px 6px;
  font-size: 11px;
  font-weight: 800;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.7);
  color: #ffd54f;
}

.mapTile .mapCount:empty { display: none; }

#mapVoteStatus {
  margin-top: 8px;
  font-size: 12px;
  font-weight: 600;
  opacity: 0.85;
  min-height: 14px;
}

#btnRow {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.toggleBtn {
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  white-space: nowrap;
  color: #fff;
  background: rgba(0, 0, 0, 0.45);
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  padding: 11px 18px;
  cursor: pointer;
  backdrop-filter: blur(6px);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, transform 0.08s ease;
}

.toggleBtn:hover:not(:disabled) { background: rgba(40, 44, 52, 0.7); }
.toggleBtn:active:not(:disabled) { transform: scale(0.96); }
.toggleBtn.open {
  color: #ffd54f;
  border-color: #ffd54f;
  background: rgba(255, 213, 79, 0.16);
  box-shadow: 0 0 14px rgba(255, 213, 79, 0.35);
}
.toggleBtn:disabled { opacity: 0.5; cursor: default; }

#joinBtn {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 2px;
  padding: 16px 48px;
  color: #fff;
  background: linear-gradient(180deg, #38c956, #1d8a37);
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-radius: 14px;
  cursor: pointer;
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.5), 0 0 30px rgba(56, 201, 86, 0.35);
  transition: transform 0.08s ease, filter 0.15s ease;
}

#joinBtn:hover:not(:disabled) { transform: scale(1.05); filter: brightness(1.1); }
#joinBtn:active:not(:disabled) { transform: scale(0.97); }
#joinBtn:disabled { background: linear-gradient(180deg, #4c554d, #39423b); cursor: default; opacity: 0.9; box-shadow: none; }

/* Garage card: pops up above the join row, flush with its right edge (under the YOUR RIDE button). */
#carRow {
  position: absolute;
  right: 0;
  bottom: calc(100% + 12px);
  width: 232px;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 12px 14px 16px;
}

@media (max-width: 900px) {
  #carRow {
    right: auto;
    left: 50%;
    transform: translateX(-50%);
  }
}

#carRow .carLabel {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 2px;
  opacity: 0.85;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
}

#styleRow, #colorRow {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 6px;
}

#colorRow { max-width: 232px; }
#styleRow { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; width: 100%; }

.styleBtn {
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #fff;
  background: rgba(0, 0, 0, 0.45);
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  padding: 6px 10px;
  cursor: pointer;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, transform 0.08s ease;
}

.styleBtn:hover:not(:disabled) { background: rgba(40, 44, 52, 0.7); }
.styleBtn:active:not(:disabled) { transform: scale(0.96); }
.styleBtn.sel {
  color: #ffd54f;
  border-color: #ffd54f;
  background: rgba(255, 213, 79, 0.16);
  box-shadow: 0 0 14px rgba(255, 213, 79, 0.35);
}

.swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5), inset 0 -3px 5px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  padding: 0;
  transition: transform 0.1s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.swatch:hover:not(:disabled) { transform: scale(1.1); }
.swatch.sel {
  border-color: #ffd54f;
  transform: scale(1.2);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.6), 0 0 14px rgba(255, 213, 79, 0.6), inset 0 -3px 5px rgba(0, 0, 0, 0.3);
}

.styleBtn:disabled, .swatch:disabled { opacity: 0.5; cursor: default; }

#joinMsg { margin-top: 8px; font-size: 15px; font-weight: 600; min-height: 20px; text-shadow: 0 2px 8px rgba(0,0,0,0.8); }

#results {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: none;
  min-width: 340px;
  padding: 18px 22px;
  font-size: 15px;
}

#results h2 {
  text-align: center;
  font-size: 24px;
  margin-bottom: 10px;
  letter-spacing: 1px;
}

#results .rrow {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 4px 6px;
  border-radius: 6px;
}

#results .rrow.self { background: rgba(255, 213, 79, 0.16); }
#results .pos { width: 30px; font-weight: 800; }
#results .pos.first { color: #ffd54f; }
#results .chip { width: 12px; height: 12px; border-radius: 50%; border: 1px solid rgba(0,0,0,0.5); }
#results .nm { flex: 1; }
#results .tm { font-variant-numeric: tabular-nums; opacity: 0.85; }
#results .next { text-align: center; margin-top: 10px; opacity: 0.8; font-size: 13px; }

#speedo {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: none;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  pointer-events: none;
}

#gauge { position: relative; width: 200px; height: 120px; }
#gauge svg { position: absolute; inset: 0; filter: drop-shadow(0 2px 6px rgba(0,0,0,0.6)); }
#speedVal {
  position: absolute;
  left: 0; right: 0; top: 52px;
  text-align: center;
  font-size: 44px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 10px rgba(0,0,0,0.8);
}
#speedUnit { position: absolute; left: 0; right: 0; top: 98px; text-align: center; font-size: 12px; opacity: 0.8; letter-spacing: 2px; }

#boostWrap {
  position: relative;
  width: 200px;
  height: 18px;
  background: rgba(0,0,0,0.5);
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 9px;
  overflow: hidden;
}
#boostBar { height: 100%; width: 100%; background: linear-gradient(90deg, #29b6f6, #7c4dff); transition: width 0.08s linear; }
#boostBar.ready { background: linear-gradient(90deg, #ffd54f, #ff6d00); }
/* 50% activation threshold marker */
#boostWrap::after { content: ''; position: absolute; left: 50%; top: 0; bottom: 0; width: 1px; background: rgba(255,255,255,0.45); pointer-events: none; }
#boostWrap span { position: absolute; inset: 0; text-align: center; font-size: 11px; font-weight: 700; line-height: 18px; letter-spacing: 1px; text-shadow: 0 1px 3px #000; }

#minimap {
  position: fixed;
  left: 14px;
  bottom: 14px;
  width: 240px;
  height: 160px;
  background: rgba(10, 12, 16, 0.5);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 12px;
  backdrop-filter: blur(6px);
  display: none;
}

#hint {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 13px;
  opacity: 0.7;
  pointer-events: none;
  text-shadow: 0 1px 4px rgba(0,0,0,0.8);
  white-space: nowrap;
}

#controls {
  position: fixed;
  top: 14px;
  right: 14px;
  display: flex;
  gap: 6px;
  z-index: 5;
}

#raceInfo:not(:empty) ~ #controls { top: auto; bottom: 150px; }

#controls select, #controls button {
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  background: rgba(10, 12, 16, 0.62);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 8px;
  padding: 5px 9px;
  cursor: pointer;
  backdrop-filter: blur(6px);
}

#controls button:hover, #controls select:hover { background: rgba(40, 44, 52, 0.8); }

#fps {
  position: fixed;
  top: 52px;
  right: 14px;
  font-size: 11px;
  opacity: 0.55;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

#overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 12, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

#overlay .box { font-size: 22px; font-weight: 700; letter-spacing: 1px; }

/* Shown when the server reports it is not sharing its lobby (no Redis) and
   we are not on localhost: every instance is then its own world. */
#modeWarn {
  position: fixed;
  left: 50%;
  bottom: 34px;
  transform: translateX(-50%);
  display: none;
  max-width: 92vw;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  background: rgba(198, 40, 40, 0.88);
  border: 1px solid rgba(255, 120, 120, 0.7);
  border-radius: 10px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
  pointer-events: none;
  z-index: 9; /* above the lobby pop-ups (7/8) so it is never hidden; still under #overlay */
}

@media (max-width: 720px) {
  #mapVote { width: auto; min-width: 260px; }
  #mapVoteGrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .mapTile canvas { width: 92px; height: 56px; }
  #btnRow { flex-wrap: wrap; gap: 8px; }
  #joinBtn { order: -1; flex-basis: 100%; }
  #standings { display: none; }
  #hint { display: none; }
  #minimap { width: 160px; height: 106px; }
  #gauge { transform: scale(0.8); transform-origin: bottom right; }
}
