html, body {
  margin: 0; padding: 0; height: 100%; overflow: hidden;
  background: #0d0f12; color: #e8e4da;
  font-family: "Arial Black", "Helvetica Neue", Arial, sans-serif;
  user-select: none;
}
#game-canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

#ui-root { position: fixed; inset: 0; pointer-events: none; }
.screen {
  position: absolute; inset: 0; display: none;
  flex-direction: column; align-items: center; justify-content: center;
  text-align: center; pointer-events: auto;
}
.screen.visible { display: flex; }
.screen.passthrough { pointer-events: none; }

.title {
  font-size: clamp(44px, 9vw, 96px); line-height: 0.95; letter-spacing: 4px;
  color: #f5c518;
  text-shadow: 0 4px 0 #7a4d00, 0 8px 24px rgba(0,0,0,.8);
  transform: skew(-4deg);
}
.heading { font-size: clamp(34px, 6vw, 64px); color: #f5c518; letter-spacing: 3px; margin: 0 0 8px; }
.subtitle { color: #b8b2a4; margin: 4px 0 18px; font-family: Arial, sans-serif; font-weight: bold; }
.esc-hint { color: #8a857a; margin: 2px 0 0; font-family: Arial, sans-serif; font-size: 13px; letter-spacing: 1px; }
.car-select { display: flex; align-items: center; justify-content: center; gap: 18px; margin: 6px 0 2px; }
#menu-car-name {
  min-width: 240px; text-align: center; color: #ffd94d; font-size: 20px;
  letter-spacing: 2px; text-shadow: 0 2px 0 #000;
}
.car-arrow {
  font: inherit; font-size: 20px; cursor: pointer; color: #e8e4da;
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.25);
  border-radius: 6px; padding: 4px 14px;
}
.car-arrow:hover { background: rgba(255,217,77,.25); color: #ffd94d; }

#screen-loading, #screen-menu, #screen-upgrades, #screen-results {
  background: radial-gradient(ellipse at center, rgba(13,15,18,.55) 0%, rgba(13,15,18,.92) 100%);
}

.big-btn {
  font: inherit; font-size: 26px; letter-spacing: 2px; cursor: pointer;
  padding: 16px 42px; margin: 10px; color: #111;
  background: linear-gradient(180deg, #ffd94d, #f5a518);
  border: 0; border-radius: 6px; box-shadow: 0 5px 0 #7a4d00, 0 10px 22px rgba(0,0,0,.6);
  transform: skew(-4deg);
}
.big-btn:hover { filter: brightness(1.1); }
.big-btn:active { transform: skew(-4deg) translateY(3px); box-shadow: 0 2px 0 #7a4d00; }
.mid-btn {
  font: inherit; font-size: 16px; letter-spacing: 1px; cursor: pointer;
  padding: 10px 26px; margin: 4px; color: #e8e4da;
  background: #2a2e35; border: 2px solid #565d68; border-radius: 6px;
}
.mid-btn:hover { background: #363c46; }
.small-btn {
  font-family: Arial, sans-serif; font-size: 12px; cursor: pointer;
  margin-top: 10px; padding: 6px 14px; color: #8b8578;
  background: none; border: 1px solid #3a3f47; border-radius: 4px;
}
.small-btn:hover { color: #e8e4da; }

.menu-stats { display: flex; gap: 26px; margin: 8px 0 14px; font-size: 18px; color: #d8d2c4; }
.menu-stats span { background: rgba(0,0,0,.45); padding: 8px 16px; border-radius: 6px; border: 1px solid #3a3f47; }

/* Menu options: graphics quality + FPS toggle */
.menu-options { display: flex; align-items: center; gap: 12px; margin-top: 10px; font-family: Arial, sans-serif; font-size: 12px; color: #8b8578; flex-wrap: wrap; justify-content: center; }
.opt-label { letter-spacing: 1px; }
#gfx-btns { display: flex; gap: 4px; }
.opt-btn {
  font-family: inherit; font-size: 12px; letter-spacing: 1px; cursor: pointer;
  padding: 6px 10px; color: #8b8578;
  background: none; border: 1px solid #3a3f47; border-radius: 4px;
}
.opt-btn:hover { color: #e8e4da; }
.opt-btn.active { color: #111; background: #ffd94d; border-color: #ffd94d; font-weight: bold; }
.opt-check { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.opt-check kbd { border: 1px solid #3a3f47; border-radius: 3px; padding: 0 4px; font-size: 10px; }

/* FPS readout (toggle: F key or menu checkbox) */
#fps-meter {
  position: fixed; top: 10px; left: 10px; z-index: 60; display: none;
  font-family: 'Courier New', monospace; font-size: 14px; font-weight: bold;
  color: #7dff8a; background: rgba(0,0,0,.55);
  padding: 4px 10px; border-radius: 4px; border: 1px solid #2a3a2e;
  pointer-events: none;
}
#fps-meter.visible { display: block; }
.credits { position: absolute; bottom: 14px; left: 0; right: 0; font-family: Arial, sans-serif; font-size: 11px; color: #6b665b; padding: 0 30px; }

.loading-bar { width: min(420px, 70vw); height: 18px; background: #22262d; border: 2px solid #565d68; border-radius: 9px; overflow: hidden; }
#loading-fill { height: 100%; width: 0%; background: linear-gradient(90deg, #f5a518, #ffd94d); transition: width .15s; }
#loading-label { font-family: Arial, sans-serif; color: #b8b2a4; }

/* HUD */
#hud { justify-content: space-between; }
#hud-top {
  width: 100%; display: flex; justify-content: space-between; align-items: flex-start;
  padding: 18px 28px; box-sizing: border-box;
}
#hud-round, #hud-alive { font-size: 20px; color: #e8e4da; background: rgba(0,0,0,.5); padding: 8px 16px; border-radius: 6px; }
#hud-score { font-size: 34px; color: #f5c518; background: rgba(0,0,0,.5); padding: 4px 22px; border-radius: 6px; }
#hud-bottom { width: 100%; padding: 20px 28px; box-sizing: border-box; display: flex; justify-content: space-between; align-items: flex-end; }
/* Per-system damage meter (bottom-right): top-down car diagram, each of the
   8 components colored by stage — green → yellow → orange → red → black. */
#hud-systems { background: rgba(0,0,0,.55); border: 1px solid #3a3f47; border-radius: 8px; padding: 10px 12px; }
.sys-title { font-size: 12px; letter-spacing: 2px; color: #b8b2a4; margin-bottom: 4px; text-align: center; }
#sys-diagram { display: block; margin: 0 auto; }
#sys-diagram text { font-family: Arial, sans-serif; font-size: 9px; fill: #9d978a; }
#sys-diagram text.dead { fill: #ff6a55; }
#hud-systems [data-sys] { stroke: #16181d; stroke-width: 1.5; transition: fill .15s; }
#hud-systems [data-sys].dead { stroke: #d93b2b; }
/* Flashing red: a system at 10% or less is about to go. */
#hud-systems [data-sys].critflash { animation: sysflash .45s infinite; }
#sys-diagram text.critflash { animation: sysflashtext .45s infinite; }
@keyframes sysflash { 0%, 100% { fill: #d93b2b; } 50% { fill: #380b06; } }
@keyframes sysflashtext { 0%, 100% { fill: #ff5a3c; } 50% { fill: #5a1008; } }
#hud-hint { font-family: Arial, sans-serif; font-size: 12px; color: #8b8578; background: rgba(0,0,0,.4); padding: 6px 10px; border-radius: 4px; }
#hud-message {
  position: absolute; top: 22%; left: 0; right: 0; text-align: center;
  font-size: 42px; color: #ffd94d; letter-spacing: 3px;
  text-shadow: 0 3px 0 #7a4d00, 0 6px 18px rgba(0,0,0,.8);
  opacity: 0; transition: opacity .3s; transform: skew(-4deg);
}
#hud-message.show { opacity: 1; }

/* Upgrades */
.coins-line { font-size: 22px; color: #ffd94d; margin: 6px 0 14px; }
#upgrade-list { display: flex; flex-direction: column; gap: 10px; width: min(560px, 92vw); margin-bottom: 14px; }
.upgrade-row {
  display: flex; align-items: center; gap: 14px; text-align: left;
  background: rgba(0,0,0,.5); border: 1px solid #3a3f47; border-radius: 8px; padding: 12px 16px;
}
.upgrade-info { flex: 1; }
.upgrade-name { font-size: 18px; color: #e8e4da; }
.upgrade-desc { font-family: Arial, sans-serif; font-size: 12px; color: #9d978a; margin-top: 2px; }
.upgrade-pips { display: flex; gap: 4px; }
.pip { width: 16px; height: 16px; border-radius: 3px; background: #22262d; border: 1px solid #565d68; }
.pip.on { background: #f5c518; border-color: #f5c518; }
.buy-btn {
  font: inherit; font-size: 14px; cursor: pointer; min-width: 96px;
  padding: 10px 12px; color: #111; background: linear-gradient(180deg, #ffd94d, #f5a518);
  border: 0; border-radius: 6px;
}
.buy-btn:disabled { background: #3a3f47; color: #8b8578; cursor: default; }

/* Results */
#results-table { border-collapse: collapse; margin: 10px 0 16px; min-width: min(520px, 92vw); }
#results-table th, #results-table td { padding: 7px 16px; font-size: 15px; }
#results-table th { color: #9d978a; font-family: Arial, sans-serif; font-size: 12px; letter-spacing: 1px; border-bottom: 2px solid #3a3f47; }
#results-table tr.winner td { color: #ffd94d; }
#results-table tr.player td { background: rgba(245,197,24,.08); }
#results-table td { border-bottom: 1px solid #262a31; color: #d8d2c4; }
#results-score-line { font-size: 20px; color: #e8e4da; margin-bottom: 4px; }

#hud-nitro {
  font-size: 22px; color: #6ec8ff; background: rgba(0,0,0,.5);
  padding: 8px 18px; border-radius: 6px; letter-spacing: 1px;
}
#hud-nitro.boosting { color: #ffd94d; animation: nitroflash .25s infinite alternate; }
@keyframes nitroflash { from { transform: scale(1); } to { transform: scale(1.12); } }

#hud-boosts { display: flex; gap: 10px; align-items: center; }
#hud-octane { font-size: 18px; color: #ff9a2e; background: rgba(0,0,0,.5); padding: 8px 14px; border-radius: 6px; display: none; }
#hud-octane.active { display: block; }

/* --- Multiplayer menu + lobby --- */
.mp-field { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.mp-field label { color: #b8b2a4; font-family: Arial, sans-serif; font-weight: bold; letter-spacing: 2px; font-size: 14px; }
.mp-columns { display: flex; gap: 22px; flex-wrap: wrap; justify-content: center; }
.mp-panel {
  background: #171a1f; border: 2px solid #3a3f47; border-radius: 10px;
  padding: 18px 22px; display: flex; flex-direction: column; gap: 10px; min-width: 260px;
}
.mp-panel h3 { margin: 0 0 4px; color: #ffd94d; letter-spacing: 2px; font-size: 18px; }
#screen-mp input[type="text"], #screen-mp input[type="password"],
#screen-mp input:not([type]) {
  font: inherit; font-size: 18px; padding: 10px 12px; color: #e8e4da;
  background: #0d0f12; border: 2px solid #565d68; border-radius: 6px;
  letter-spacing: 1px; text-transform: uppercase;
}
#screen-mp input:focus { outline: none; border-color: #ffd94d; }
#mp-callsign { width: 220px; }
#mp-join-code { text-align: center; letter-spacing: 6px; }
.mp-check { color: #b8b2a4; font-family: Arial, sans-serif; font-size: 14px; display: flex; gap: 8px; align-items: center; }
.mp-check input { accent-color: #f5a518; width: 18px; height: 18px; }
.mp-error { color: #d93b2b; font-family: Arial, sans-serif; font-weight: bold; min-height: 22px; margin: 10px 0 0; }

.lobby-code { color: #ffd94d; letter-spacing: 8px; text-shadow: 0 2px 0 #000; }
#lobby-players { display: flex; flex-direction: column; gap: 6px; min-width: 420px; max-width: 90vw; margin-bottom: 14px; }
.lobby-row {
  display: grid; grid-template-columns: 1fr auto auto; gap: 14px; align-items: center;
  background: #171a1f; border: 2px solid #3a3f47; border-radius: 8px; padding: 10px 16px;
}
.lobby-name { font-size: 20px; letter-spacing: 1px; }
.lobby-car { color: #b8b2a4; font-family: Arial, sans-serif; font-size: 13px; text-transform: uppercase; }
.lobby-badges { display: flex; gap: 6px; }
.badge { font-family: Arial, sans-serif; font-size: 11px; font-weight: bold; letter-spacing: 1px; padding: 3px 8px; border-radius: 4px; }
.badge.host { background: #7a4d00; color: #ffd94d; }
.badge.you { background: #2a2e35; color: #e8e4da; border: 1px solid #565d68; }
.badge.ready { background: #2d5a1e; color: #7dc242; }
.badge.waiting { background: #2a2e35; color: #8b8578; }

.lobby-cars-label { color: #ffd94d; letter-spacing: 2px; font-size: 16px; margin: 6px 0 8px; }
.lobby-cars-sub { color: #8b857a; font-family: Arial, sans-serif; font-size: 12px; letter-spacing: 0; }
#lobby-car-grid { display: grid; grid-template-columns: repeat(4, minmax(120px, 1fr)); gap: 8px; max-width: 90vw; }
.lobby-car-btn {
  font: inherit; font-size: 13px; text-transform: uppercase; letter-spacing: 1px;
  padding: 10px 8px; color: #e8e4da; cursor: pointer;
  background: #2a2e35; border: 2px solid #565d68; border-radius: 6px;
  display: flex; flex-direction: column; gap: 2px; align-items: center;
}
.lobby-car-btn:hover:not(:disabled) { border-color: #ffd94d; }
.lobby-car-btn.mine { background: #3d4a1e; border-color: #7dc242; }
.lobby-car-btn.taken { opacity: .45; cursor: not-allowed; }
.car-owner { font-family: Arial, sans-serif; font-size: 10px; color: #ffd94d; text-transform: none; }
.lobby-bots { color: #8b857a; font-family: Arial, sans-serif; font-size: 13px; margin: 10px 0 0; }
.lobby-actions { display: flex; gap: 10px; align-items: center; margin-top: 10px; }
#btn-lobby-ready.active { background: linear-gradient(180deg, #9be15d, #7dc242); box-shadow: 0 5px 0 #2d5a1e, 0 10px 22px rgba(0,0,0,.6); }
#btn-lobby-start:disabled { opacity: .45; cursor: not-allowed; filter: grayscale(.6); }

/* --- Series: standings + pit stop + podium --- */
.subheading { color: #ffd94d; letter-spacing: 3px; font-size: 18px; margin: 18px 0 6px; }
#standings-block { margin-top: 4px; }
#standings-table, #podium-table { border-collapse: collapse; min-width: 420px; max-width: 92vw; }
#standings-table th, #standings-table td,
#podium-table th, #podium-table td { padding: 6px 14px; text-align: left; font-size: 15px; }
#standings-table th, #podium-table th { color: #8b857a; font-family: Arial, sans-serif; font-size: 11px; letter-spacing: 2px; border-bottom: 2px solid #3a3f47; }
#standings-table tr.player td, #podium-table tr.player td { color: #ffd94d; }
.bot-tag { font-family: Arial, sans-serif; font-size: 9px; font-weight: bold; color: #8b857a; border: 1px solid #3a3f47; border-radius: 3px; padding: 1px 4px; vertical-align: middle; letter-spacing: 1px; }

#podium-champion {
  font-size: clamp(40px, 8vw, 84px); color: #f5c518; letter-spacing: 4px;
  text-shadow: 0 4px 0 #7a4d00, 0 8px 24px rgba(0,0,0,.8);
  display: flex; flex-direction: column; align-items: center; margin-bottom: 14px;
}
.podium-pts { font-size: 20px; color: #b8b2a4; letter-spacing: 2px; text-shadow: none; }
#podium-table tr.podium-1 td { color: #f5c518; font-size: 18px; }
#podium-table tr.podium-2 td { color: #d8d8d8; }
#podium-table tr.podium-3 td { color: #d08a4b; }
