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

html, body {
  height: 100%;
  overflow: hidden;
  background: #14171c;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: #eef1f5;
}

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

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

#raceinfo {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  background: rgba(16, 19, 24, 0.75);
  border: 1px solid rgba(232, 139, 30, 0.5);
  border-radius: 10px;
  padding: 8px 18px;
  font-size: 15px;
  letter-spacing: 0.4px;
  white-space: nowrap;
}
#raceinfo b { color: #ffb64d; }
#raceinfo .dim { color: #9aa3af; font-size: 12px; }

#roomcode {
  position: absolute; top: 14px; right: 14px;
  background: rgba(16, 19, 24, 0.75);
  border: 1px solid #3a414c;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #8ecfff;
}

#announce {
  position: absolute; top: 22%; left: 50%; transform: translateX(-50%) scale(0.8);
  font-size: 44px; font-weight: 900; text-align: center;
  color: #ffb64d;
  text-shadow: 0 3px 0 #000, 0 0 26px rgba(232, 139, 30, 0.55);
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  white-space: nowrap;
}
#announce.show { opacity: 1; transform: translateX(-50%) scale(1); }

#toasts {
  position: absolute; right: 14px; top: 64px;
  display: flex; flex-direction: column; gap: 8px;
  max-width: 340px;
}
.toast {
  background: rgba(16, 19, 24, 0.85);
  border-left: 4px solid #e88b1e;
  border-radius: 6px;
  padding: 9px 14px;
  font-size: 14px;
  animation: slidein 0.25s ease-out;
}
.toast.out { opacity: 0; transition: opacity 0.5s; }
@keyframes slidein { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }

#speed {
  position: absolute; left: 26px; bottom: 22px;
  display: flex; align-items: baseline; gap: 8px;
}
#speed b {
  font-size: 58px; font-weight: 900; font-variant-numeric: tabular-nums;
  text-shadow: 0 3px 0 #000;
}
#speed span { font-size: 16px; color: #9aa3af; font-weight: 700; }

#status {
  position: absolute; right: 26px; bottom: 22px;
  text-align: right;
  display: flex; flex-direction: column; gap: 6px; align-items: flex-end;
}
#carname { font-size: 18px; font-weight: 800; letter-spacing: 1px; text-shadow: 0 2px 0 #000; }
#healthbar {
  width: 220px; height: 14px;
  background: rgba(16, 19, 24, 0.8);
  border: 1px solid #3a414c;
  border-radius: 7px;
  overflow: hidden;
}
#healthbar i {
  display: block; height: 100%; width: 100%;
  background: #6fce4e;
  transition: width 0.3s, background 0.3s;
}
#score { font-size: 13px; color: #9aa3af; }

#hint {
  position: absolute; bottom: 4px; left: 50%; transform: translateX(-50%);
  font-size: 12.5px; color: #8b93a0;
  background: rgba(16, 19, 24, 0.6);
  border-radius: 6px 6px 0 0;
  padding: 4px 14px;
  white-space: nowrap;
  transition: opacity 1.2s;
}
#hint.fade { opacity: 0; }

/* ---------- Meny ---------- */
#menu {
  position: fixed; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 50% 30%, #2a3140 0%, #14171c 75%);
  overflow-y: auto;
}
.panel {
  width: min(860px, 94vw);
  background: rgba(22, 26, 33, 0.92);
  border: 1px solid #343b46;
  border-radius: 16px;
  padding: 28px 30px 22px;
  margin: 20px 0;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.55);
}
.panel h1 {
  font-size: 42px; font-weight: 900; letter-spacing: 2px;
  color: #ffb64d;
  text-shadow: 0 3px 0 #000;
}
.panel .tag { color: #b9c1cc; font-size: 14.5px; margin: 10px 0 16px; line-height: 1.5; }

.optrow { display: flex; gap: 28px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.namelabel { display: block; font-size: 13px; color: #9aa3af; }
.seg { display: flex; gap: 4px; margin-top: 4px; }
.seg button {
  background: #101318; color: #9aa3af;
  border: 1px solid #3a414c; border-radius: 8px;
  padding: 9px 12px; font-size: 13px; font-weight: 700;
  cursor: pointer;
}
.seg button:hover { color: #eef1f5; }
.seg button.sel { background: #e88b1e; color: #14171c; border-color: #e88b1e; }
.namelabel input {
  display: block; margin-top: 4px;
  background: #101318; color: #eef1f5;
  border: 1px solid #3a414c; border-radius: 8px;
  padding: 9px 12px; font-size: 16px; width: 220px;
  outline: none;
}
.namelabel input:focus { border-color: #e88b1e; }

#carselect {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}
.card {
  background: #101318;
  border: 2px solid #2c333e;
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
  position: relative;
}
.card:hover { transform: translateY(-2px); }
.card.sel { border-color: #e88b1e; box-shadow: 0 0 0 1px #e88b1e, 0 6px 18px rgba(232, 139, 30, 0.2); }
.card .swatch {
  position: absolute; top: 12px; right: 12px;
  width: 26px; height: 26px; border-radius: 6px;
  border: 2px solid rgba(255, 255, 255, 0.25);
}
.card b { font-size: 16px; letter-spacing: 1px; }
.card p { font-size: 12px; color: #9aa3af; margin: 6px 0 8px; min-height: 30px; line-height: 1.35; }
.card .stats {
  display: grid; grid-template-columns: auto 1fr; gap: 1px 10px;
  font-size: 11px; color: #8b93a0;
}
.card .stats i { font-style: normal; color: #ffb64d; letter-spacing: 2px; font-size: 10px; }
.card .stats .dim, .card .stats i span.dim { color: #3a414c; }

.btnrow { display: flex; gap: 12px; align-items: stretch; flex-wrap: wrap; }
.btnrow.secondary { margin-top: 10px; }
.btnrow.secondary .btn { font-size: 13.5px; padding: 10px 16px; }
.btnrow.secondary .joinrow input { width: 74px; font-size: 16px; }
.btn {
  background: #e88b1e; color: #14171c;
  font-weight: 900; font-size: 16px; letter-spacing: 1px;
  border: 0; border-radius: 10px;
  padding: 13px 26px;
  cursor: pointer;
  transition: transform 0.12s, filter 0.12s;
}
.btn:hover { filter: brightness(1.12); transform: translateY(-1px); }
.btn.big { font-size: 18px; }
.btn.ghost {
  background: transparent; color: #9aa3af;
  border: 1px solid #3a414c;
  font-weight: 700;
}
.joinrow { display: flex; gap: 8px; }
.joinrow input {
  width: 92px; text-align: center;
  background: #101318; color: #8ecfff;
  border: 1px solid #3a414c; border-radius: 10px;
  font-size: 20px; font-weight: 900; letter-spacing: 4px;
  text-transform: uppercase;
  outline: none;
}
.joinrow input:focus { border-color: #8ecfff; }

.credits { margin-top: 10px; font-size: 11.5px; color: #6f7784; }
.credits a { color: #8b93a0; }
#netstatus { margin-top: 12px; font-size: 13.5px; color: #7fe37f; min-height: 18px; }
#netstatus.err { color: #ff8b7a; }

/* Live-resultattavlan */
#board {
  position: absolute; top: 56px; right: 14px;
  background: rgba(16, 19, 24, 0.82);
  border: 1px solid #3a414c;
  border-radius: 10px;
  padding: 8px 10px;
  min-width: 210px;
  font-size: 13px;
}
#board .bhead { color: #ffb64d; font-weight: 800; margin-bottom: 5px; font-variant-numeric: tabular-nums; }
#board .brow { display: flex; gap: 7px; align-items: baseline; padding: 1.5px 4px; border-radius: 5px; }
#board .brow b { width: 16px; color: #ffb64d; text-align: right; }
#board .brow span { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#board .brow i { font-style: normal; color: #9aa3af; font-variant-numeric: tabular-nums; }
#board .brow.me { background: rgba(232, 139, 30, 0.25); font-weight: 700; }

/* Positionsbar — var alla ligger på banan */
#raceprog {
  position: absolute; bottom: 30px; left: 50%; transform: translateX(-50%);
  width: min(680px, 60vw); height: 20px;
}
#raceprog .pline {
  position: absolute; top: 9px; left: 0; right: 0; height: 3px;
  background: rgba(255, 255, 255, 0.35); border-radius: 2px;
}
#raceprog .pmark {
  position: absolute; top: 3px; width: 13px; height: 13px;
  border-radius: 50%; border: 2px solid rgba(0, 0, 0, 0.6);
  transform: translateX(-50%);
  transition: left 0.12s linear;
}
#raceprog .pmark.me {
  width: 17px; height: 17px; top: 0;
  border: 3px solid #fff; z-index: 2;
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.7);
}

/* Banröstning */
#votepanel {
  position: absolute; top: 56px; left: 14px;
  background: rgba(16, 19, 24, 0.85);
  border: 1px solid #3a414c;
  border-radius: 10px;
  padding: 10px;
  pointer-events: auto;
}
#votepanel .vhead { color: #ffb64d; font-weight: 800; font-size: 13px; margin-bottom: 7px; }
#votepanel .vopt {
  display: flex; gap: 8px; align-items: baseline; width: 100%;
  background: #101318; color: #eef1f5;
  border: 1px solid #3a414c; border-radius: 8px;
  padding: 7px 10px; margin-bottom: 5px;
  font-size: 13.5px; font-weight: 700; cursor: pointer;
}
#votepanel .vopt:hover { border-color: #e88b1e; }
#votepanel .vopt.sel { background: #e88b1e; color: #14171c; border-color: #e88b1e; }
#votepanel .vopt b { color: #ffb64d; }
#votepanel .vopt.sel b { color: #14171c; }
#votepanel .vopt i { font-style: normal; margin-left: auto; font-weight: 400; color: #9aa3af; }
#votepanel .vopt.sel i { color: #14171c; }

#loading {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%);
  z-index: 11;
  background: rgba(16, 19, 24, 0.85);
  border: 1px solid #3a414c;
  border-radius: 8px;
  padding: 7px 16px;
  font-size: 13px; color: #9aa3af;
}

/* Plånbok */
#wallet { position: absolute; top: 14px; left: 14px; background: rgba(16,19,24,0.8); border: 1px solid #3a414c; border-radius: 8px; padding: 6px 12px; font-size: 15px; color: #ffe08a; }
/* Slutresultat */
#results { position: absolute; top: 12%; left: 50%; transform: translateX(-50%); width: min(460px, 92vw); background: rgba(16,19,24,0.92); border: 2px solid #e88b1e; border-radius: 14px; padding: 16px 20px; box-shadow: 0 18px 60px rgba(0,0,0,0.6); }
#results .rtitle { color: #ffb64d; font-weight: 900; font-size: 22px; text-align: center; margin-bottom: 10px; }
#results .rrow { display: flex; gap: 10px; align-items: baseline; padding: 4px 8px; border-radius: 6px; font-size: 15px; }
#results .rrow b { width: 30px; text-align: center; }
#results .rrow span { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#results .rrow i { font-style: normal; color: #7fe37f; font-weight: 700; }
#results .rrow.me { background: rgba(232,139,30,0.25); font-weight: 700; }
#results .rfoot { text-align: center; color: #9aa3af; margin-top: 10px; font-size: 13px; }
/* Sprutbutik */
#shop { position: absolute; inset: 0; z-index: 8; display: flex; flex-direction: column; align-items: center; justify-content: center; background: rgba(10,12,16,0.82); pointer-events: auto; }
#shop .shead { display: flex; align-items: center; gap: 16px; font-size: 24px; font-weight: 900; color: #ffb64d; margin-bottom: 14px; }
#shop .shead span { font-size: 18px; color: #ffe08a; }
#shop .shead button { margin-left: 10px; background: #2a2f36; color: #eef1f5; border: 0; border-radius: 8px; width: 34px; height: 34px; font-size: 18px; cursor: pointer; }
#shop .sgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; width: min(880px, 94vw); }
#shop .scard { background: #171a20; border: 2px solid #2c333e; border-radius: 12px; padding: 14px; }
#shop .scard.owned { border-color: #6fce4e; }
#shop .scard b { font-size: 16px; letter-spacing: 0.5px; }
#shop .scard p { font-size: 12.5px; color: #9aa3af; margin: 7px 0 12px; min-height: 46px; line-height: 1.4; }
#shop .sbuy { width: 100%; background: #e88b1e; color: #14171c; font-weight: 900; font-size: 15px; border: 0; border-radius: 9px; padding: 11px; cursor: pointer; }
#shop .sbuy:disabled { background: #33562f; color: #bfe0b3; cursor: default; }
#shop .scard.broke .sbuy { background: #4a3226; color: #b98e6e; }
#shop .sfoot { color: #8b93a0; font-size: 13px; margin-top: 14px; }
