:root {
  --blue: #002d62;
  --red: #ce1126;
  --yellow: #ffd400;
  --ink: #111827;
  --panel: rgba(255, 255, 255, 0.94);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #8fcdf2;
  font-family: 'Nunito', system-ui, sans-serif; color: var(--ink);
  user-select: none; -webkit-user-select: none;
}
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#touch button { touch-action: none; }
.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; color: #fff;
  text-shadow: 0 2px 0 #000, 0 0 8px rgba(0,0,0,.6); }
#hudTL { position: absolute; left: 20px; top: 14px; }
#pos { font-family: 'Bungee', sans-serif; font-size: 72px; line-height: 1; }
#pos small { font-size: 26px; opacity: .85; margin-left: 4px; }
#posSuf { font-size: 38px; vertical-align: top; }
#lap { font-family: 'Bungee', sans-serif; font-size: 22px; margin-top: 4px; }
#itemSlot {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%);
  width: 96px; text-align: center;
}
#itemIcon {
  width: 88px; height: 88px; margin: 0 auto; border-radius: 18px;
  background: rgba(0,0,0,.35); border: 4px solid #fff; font-size: 54px;
  display: flex; align-items: center; justify-content: center; text-shadow: none;
  box-shadow: 0 4px 0 rgba(0,0,0,.35);
}
#itemIcon.rolling { animation: pulse .12s infinite alternate; }
@keyframes pulse { to { transform: scale(1.08); } }
#itemName { font-weight: 900; font-size: 15px; margin-top: 4px; }
#hudTR { position: absolute; right: 18px; top: 14px; text-align: right; }
#timer { font-family: 'Bungee', sans-serif; font-size: 28px; }
#minimap { width: 190px; height: 190px; margin-top: 6px; border-radius: 16px;
  background: rgba(0, 30, 60, .35); border: 3px solid rgba(255,255,255,.8); }
#section {
  position: absolute; left: 50%; top: 150px; transform: translateX(-50%);
  font-family: 'Bungee', sans-serif; font-size: 26px; white-space: nowrap;
  padding: 6px 22px; border-radius: 40px; background: rgba(0,45,98,.75);
  opacity: 0; transition: opacity .5s;
}
#section.show { opacity: 1; }
#speedo { position: absolute; left: 22px; bottom: 20px; font-family: 'Bungee', sans-serif; font-size: 56px; }
#speedo small { font-size: 18px; margin-left: 6px; }
#driftMeter { width: 180px; height: 10px; border-radius: 6px; background: rgba(0,0,0,.4); overflow: hidden; margin-top: 4px; }
#driftFill { height: 100%; width: 0; background: #4cc9f0; transition: background .2s; }
#msg {
  position: absolute; left: 0; right: 0; top: 36%; text-align: center;
  font-family: 'Bungee', sans-serif; font-size: 96px; color: var(--yellow);
  text-shadow: 0 5px 0 var(--red), 0 8px 18px rgba(0,0,0,.6);
}
#msg.pop { animation: pop .35s ease-out; }
@keyframes pop { from { transform: scale(1.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
#sub {
  position: absolute; left: 0; right: 0; top: 56%; text-align: center;
  font-weight: 900; font-size: 30px;
}

/* modo concho */
body:not(.concho) .conchoOnly { display: none !important; }
body.concho .raceOnly { display: none !important; }
#cash { font-family: 'Bungee', sans-serif; font-size: 58px; line-height: 1; color: #86efac; }
#cash small { font-size: 24px; margin-right: 6px; color: #fff; }
#cash.bump { animation: pop .4s ease-out; }
#seats { font-family: 'Bungee', sans-serif; font-size: 18px; margin-top: 4px; }
#riders { margin-top: 8px; display: flex; flex-direction: column; gap: 5px; }
.rider { background: rgba(0,0,0,.45); border-radius: 10px; padding: 4px 10px; font-weight: 900; font-size: 14px; min-width: 190px; text-shadow: none; }
.rider.next { background: rgba(22,163,74,.75); }
.rider i { display: block; height: 4px; border-radius: 2px; background: #fde047; margin-top: 3px; }
#nextStop { position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%); font-weight: 900; font-size: 22px;
  background: rgba(15,118,110,.8); padding: 8px 22px; border-radius: 30px; white-space: nowrap; }
#nextStop:empty { display: none; }
#modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
#onlineBox { margin: 18px 0 8px; padding: 14px; border-radius: 18px; background: #eff6ff; border: 2px solid #bfdbfe; }
.onlRow { display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; margin-bottom: 10px; }
.onlRow label { font-weight: 900; color: #334155; }
#onlineBox input { font: 800 18px 'Nunito', sans-serif; padding: 9px 12px; border-radius: 12px; border: 2px solid #94a3b8; margin-left: 6px; }
#codeInput { width: 120px; text-transform: uppercase; letter-spacing: 4px; text-align: center; font-family: 'Bungee', sans-serif !important; }
#joinBtn { border: 0; border-radius: 14px; padding: 12px 20px; font: 400 18px 'Bungee', sans-serif; background: var(--blue); color: #fff; cursor: pointer; }
#createBtn { font-size: 20px; padding: 12px 24px; }
.or { font-weight: 800; color: #64748b; }
#netMsg, #lobbyMsg { text-align: center; font-weight: 800; color: #b91c1c; min-height: 1em; margin: 4px 0 0; }
#roomCode { font-family: 'Bungee', sans-serif; font-size: 72px; letter-spacing: 10px; color: var(--blue); text-shadow: 3px 3px 0 var(--yellow); margin: 4px 0 10px; }
#copyBtn { border: 0; border-radius: 14px; padding: 10px 18px; font: 800 17px 'Nunito', sans-serif; background: #16a34a; color: #fff; cursor: pointer; }
#lobbyInfo { font-weight: 800; color: #334155; }
#lobbyPlayers { list-style: none; padding: 0; margin: 10px auto; max-width: 380px; text-align: left; }
#lobbyPlayers li { padding: 10px 14px; border-radius: 12px; background: #f1f5f9; margin-bottom: 8px; font-size: 17px; }
#lobbyPlayers li.wait { color: #94a3b8; font-style: italic; }
#lobbyWait { color: #475569; font-weight: 700; }
#lobbyStart:disabled { opacity: .45; }
.mode { border: 3px solid #e2e8f0; border-radius: 18px; padding: 12px 16px; background: #fff; cursor: pointer; text-align: left; font-family: inherit; }
.mode b { display: block; font-family: 'Bungee', sans-serif; font-weight: 400; font-size: 20px; color: var(--blue); }
.mode span { font-size: 13px; color: #475569; }
.mode.on { border-color: var(--blue); box-shadow: 0 0 0 3px var(--yellow); }

#tracks { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.track { border: 3px solid #e2e8f0; border-radius: 18px; padding: 10px 14px; background: #fff; cursor: pointer; text-align: left; font-family: inherit; }
.track b { display: block; font-family: 'Bungee', sans-serif; font-weight: 400; font-size: 17px; color: var(--red); }
.track p { margin: 4px 0; font-size: 12.5px; color: #475569; }
.track small { font-weight: 800; color: #334155; font-size: 12px; }
.track.on { border-color: var(--blue); box-shadow: 0 0 0 3px var(--yellow); }
#loading.hidden { display: none; }

/* ---------- Screens ---------- */
.screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, rgba(0,45,98,.55), rgba(206,17,38,.35));
  overflow-y: auto; padding: 16px;
}
.panel {
  background: var(--panel); border-radius: 26px; padding: 26px 30px 22px;
  max-width: 980px; width: 100%; box-shadow: 0 20px 60px rgba(0,0,0,.35);
  position: relative; overflow: hidden; margin: auto;
}
.panel.small { max-width: 560px; text-align: center; }
.flagbar { position: absolute; left: 0; right: 0; top: 0; height: 8px; display: flex; }
.flagbar i { flex: 1; }
.flagbar i:nth-child(1) { background: var(--blue); }
.flagbar i:nth-child(2) { background: #fff; }
.flagbar i:nth-child(3) { background: var(--red); }
h1 { font-family: 'Bungee', sans-serif; font-size: 58px; margin: 6px 0 0; color: var(--blue);
  text-shadow: 3px 3px 0 var(--yellow); letter-spacing: 1px; }
h2 { font-family: 'Bungee', sans-serif; margin: 0; color: var(--red); font-size: 22px; }
h3 { margin: 16px 0 8px; font-weight: 900; text-transform: uppercase; font-size: 14px; letter-spacing: 1.5px; color: #475569; }
.tag { margin: 10px 0 0; font-size: 16px; line-height: 1.45; color: #334155; }
#cars { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.car {
  border: 3px solid #e2e8f0; border-radius: 18px; padding: 10px; cursor: pointer; background: #fff;
  transition: transform .12s, border-color .12s, box-shadow .12s; text-align: left;
  font-family: inherit;
}
.car:hover { transform: translateY(-3px); }
.car.on { border-color: var(--blue); box-shadow: 0 0 0 3px var(--yellow); }
.car canvas { width: 100%; height: auto; display: block; border-radius: 10px; background: linear-gradient(#bfe6ff, #e8f6ff 60%, #9aa0a6 61%); }
.car b { display: block; font-size: 16px; margin-top: 6px; }
.car .rt { font-size: 12px; font-weight: 900; color: var(--red); }
.car p { margin: 4px 0 6px; font-size: 12.5px; color: #475569; min-height: 32px; }
.stat { display: flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 800; color: #64748b; }
.stat span { width: 66px; }
.stat div { flex: 1; height: 7px; background: #e2e8f0; border-radius: 4px; overflow: hidden; }
.stat div i { display: block; height: 100%; background: var(--blue); }
.opts { display: flex; gap: 30px; flex-wrap: wrap; }
.seg { display: inline-flex; border-radius: 14px; overflow: hidden; border: 2px solid var(--blue); }
.seg button { border: 0; background: #fff; padding: 9px 16px; font: 800 15px 'Nunito', sans-serif; cursor: pointer; color: var(--blue); }
.seg button.on { background: var(--blue); color: #fff; }
button { font-family: 'Nunito', sans-serif; }
.big, .row button {
  border: 0; border-radius: 16px; padding: 14px 30px; font: 400 22px 'Bungee', sans-serif; cursor: pointer;
  background: #e2e8f0; color: var(--blue); box-shadow: 0 5px 0 rgba(0,0,0,.2);
}
.big { background: var(--red); color: #fff; box-shadow: 0 5px 0 #7f0a17; }
.startRow { display: flex; gap: 14px; justify-content: center; align-items: center; flex-wrap: wrap; margin: 20px 0 12px; }
#startBtn { font-size: 30px; padding: 14px 60px; }
#garageBtn { border: 3px solid var(--blue); border-radius: 16px; padding: 14px 20px; font: 400 18px 'Bungee', sans-serif; background: #fff; color: var(--blue); cursor: pointer; box-shadow: 0 5px 0 rgba(0,0,0,.15); }
#wallet { font-family: 'Bungee', sans-serif; font-size: 44px; color: #16a34a; margin-top: 8px; }
.ggrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.gcard { display: flex; align-items: center; gap: 12px; border: 2px solid #e2e8f0; border-radius: 16px; padding: 10px 12px; background: #fff; }
.gi { font-size: 34px; width: 44px; text-align: center; }
.gt { flex: 1; }
.gt b { font-size: 15px; }
.gt p { margin: 2px 0 4px; font-size: 12.5px; color: #475569; }
.pips { display: flex; gap: 4px; }
.pips i { width: 22px; height: 8px; border-radius: 4px; background: #e2e8f0; }
.pips i.on { background: #16a34a; }
.gcard button { border: 0; border-radius: 12px; padding: 10px 12px; font: 400 14px 'Bungee', sans-serif; background: #16a34a; color: #fff; cursor: pointer; white-space: nowrap; }
.gcard button:disabled { background: #cbd5e1; color: #64748b; cursor: default; }
.gcard button[data-tog] { background: #64748b; }
.gcard button[data-tog].on { background: var(--blue); }
.swatches { display: flex; gap: 6px; }
.swatches span { width: 22px; height: 22px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1px #94a3b8; cursor: pointer; }
.swatches span.on { box-shadow: 0 0 0 3px var(--blue); }
.big:active, .row button:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0,0,0,.2); }
.row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }
.controls { display: flex; flex-wrap: wrap; gap: 8px 16px; justify-content: center; font-size: 13px; color: #475569; font-weight: 700; }
kbd { background: #1e293b; color: #fff; border-radius: 6px; padding: 1px 7px; font: 700 12px monospace; margin-right: 3px; }
.items { text-align: center; font-size: 13.5px; color: #334155; margin: 10px 0 0; }
#resTable { width: 100%; border-collapse: collapse; margin-top: 10px; font-weight: 800; }
#resTable td { padding: 7px 8px; border-bottom: 1px solid #e2e8f0; text-align: left; }
#resTable td:first-child { font-family: 'Bungee', sans-serif; color: var(--red); width: 44px; }
#resTable td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
#resTable tr.me { background: #fff7cc; }
.sw { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: -2px; margin-right: 6px; border: 2px solid rgba(0,0,0,.25); }
#loading { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  font: 400 30px 'Bungee', sans-serif; color: #fff; background: var(--blue); z-index: 50; }

/* ---------- Touch ---------- */
#touch { position: fixed; inset: auto 0 0 0; height: 0; }
#touch button {
  width: 76px; height: 76px; border-radius: 50%; border: 3px solid rgba(255,255,255,.8);
  background: rgba(0,0,0,.35); color: #fff; font: 800 22px 'Nunito', sans-serif; pointer-events: auto;
}
#touch button.on { background: rgba(255,212,0,.6); }
#touch .tl { position: fixed; left: 16px; bottom: 90px; display: flex; gap: 14px; }
#touch .tr { position: fixed; right: 16px; bottom: 20px; display: grid; grid-template-columns: 76px 76px; gap: 12px; }
#touch .tr button[data-k="drift"] { font-size: 14px; }

@media (max-width: 820px) {
  #cars { grid-template-columns: repeat(2, 1fr); }
  #modes, #tracks, .ggrid { grid-template-columns: 1fr; }
  #cash { font-size: 38px; }
  .rider { min-width: 140px; font-size: 12px; }
  #nextStop { font-size: 15px; bottom: 110px; }
  h1 { font-size: 40px; }
  #pos { font-size: 48px; }
  #msg { font-size: 60px; }
  #section { font-size: 16px; top: 120px; }
  #minimap { width: 120px; height: 120px; }
  #speedo { font-size: 30px; left: 20px; bottom: 180px; }
  #itemIcon { width: 64px; height: 64px; font-size: 38px; }
  .panel { padding: 20px 16px; }
}
