* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #14171c; color: #eceff4;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
[hidden] { display: none !important; }

.screen { position: fixed; inset: 0; display: flex; flex-direction: column; }
.screen.overlay { background: rgba(10, 12, 16, 0.82); align-items: center; justify-content: center; }

/* ---------- menú ---------- */
#menu { padding: max(10px, env(safe-area-inset-top)) 14px 10px; overflow: hidden; }
#menu header { display: flex; align-items: baseline; gap: 14px; }
#menu h1 { margin: 0 0 6px; font-size: 22px; }
.error { color: #ff8a80; margin: 0; font-size: 13px; }
.menu-body { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; min-height: 0; }
.col { overflow-y: auto; padding-right: 4px; touch-action: pan-y; }
.col h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: #8b95a7; margin: 10px 0 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 7px 12px; border-radius: 999px; background: #222733; border: 2px solid transparent;
  font-size: 13px; cursor: pointer;
}
.chip.sel { border-color: #ffca28; background: #2c3140; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.card {
  background: #222733; border: 2px solid transparent; border-radius: 12px; padding: 8px;
  cursor: pointer; display: flex; flex-direction: column; gap: 4px;
}
.card.sel { border-color: #ffca28; background: #2c3140; }
.card.off { opacity: .45; pointer-events: none; }
.card canvas { width: 100%; height: 64px; display: block; background: #1a1e27; border-radius: 8px; object-fit: contain; } /* contain: el auto mantiene su forma aunque la tarjeta sea más ancha o más angosta */
.card .name { font-weight: 600; font-size: 13px; }
.card .tags { display: flex; flex-wrap: wrap; gap: 4px; }
.card .tags span { font-size: 10px; background: #323a4d; color: #c4cbd8; padding: 1px 7px; border-radius: 999px; }
.card .desc { font-size: 11px; color: #8b95a7; line-height: 1.25; }
.bars { display: grid; grid-template-columns: auto 1fr; gap: 2px 6px; font-size: 10px; color: #8b95a7; align-items: center; }
.bars i { display: block; height: 5px; border-radius: 3px; background: #4fc3f7; }
.opts { display: flex; gap: 14px; margin-top: 10px; }
.opts label { font-size: 12px; color: #8b95a7; display: flex; flex-direction: column; gap: 4px; }
select { background: #222733; color: #eceff4; border: 1px solid #3a4152; border-radius: 8px; padding: 6px 8px; font-size: 14px; }
#menu footer { padding-top: 8px; display: flex; justify-content: center; }
button.big {
  background: #ffca28; color: #1b1b1b; border: 0; border-radius: 12px;
  font-size: 18px; font-weight: 700; padding: 10px 44px; cursor: pointer;
}
button.big.alt { background: #2c3140; color: #eceff4; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 10px; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 2px solid #3a4152; color: #fff; font-size: 14px; cursor: pointer; padding: 0; background: #222733; }
.swatch.sel { border-color: #ffca28; transform: scale(1.15); }
/* personalización del auto (garaje) */
.deco-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin: 6px 0; }
.deco-grid label { display: flex; flex-direction: column; gap: 3px; font-size: 13px; color: #cfd8e3; }
.deco-grid input:not([type=range]), .deco-grid select { padding: 7px; border-radius: 8px; border: 1px solid #3a4152; background: #1a1e27; color: #fff; font: 600 15px system-ui, sans-serif; }
.deco-emo { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0; }
.deco-emo button { padding: 4px 7px; font-size: 18px; border-radius: 8px; border: 1px solid #3a4152; background: #222733; cursor: pointer; }
.deco-aviso { color: #ff8a80; }
/* vitrina 3D del garaje y Mi panel */
.gal-3d { width: 100%; aspect-ratio: 2 / 1; max-height: 46vh; border-radius: 14px; overflow: hidden; background: #0d0f12; touch-action: none; }
.gal-3d canvas.vitrina { display: block; width: 100%; height: 100%; }
#garage .gal.gal-3dmode .gal-main { position: sticky; top: 0; z-index: 3; background: inherit; }
.mm-auto img.foto3d { object-fit: contain; }
.motor-btn { width: 100%; margin: 6px 0 4px; user-select: none; -webkit-user-select: none; touch-action: none; }
.motor-btn.on { background: #ffca28; color: #222; }
.gal-3d { flex: 1; min-width: 0; }
#garage .gal.gal-3dmode .gal-main { background: #12151c; }
.deco-llantas { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 13px; color: #cfd8e3; margin: 6px 0 10px; }
.deco-llantas > span:last-child { display: flex; gap: 6px; flex-wrap: wrap; }
button.small { background: rgba(0,0,0,.45); color: #fff; border: 0; border-radius: 8px; width: 34px; height: 34px; font-size: 16px; }

/* ---------- juego ---------- */
#game { background: #2f7a35; }
#canvas { position: absolute; inset: 0; }
#hud { position: absolute; inset: 0; pointer-events: none; }
.hud-box {
  position: absolute; top: max(8px, env(safe-area-inset-top)); background: rgba(0,0,0,.5);
  padding: 4px 12px; border-radius: 10px; font-weight: 700; font-size: 18px;
}
#hud-pos { left: 10px; font-size: 24px; }
#hud-lap { left: 50%; transform: translateX(-50%); }
#hud-time { left: 50%; transform: translateX(-50%); top: calc(max(8px, env(safe-area-inset-top)) + 36px); font-size: 14px; font-weight: 600; }
#mute { position: absolute; right: 52px; top: max(8px, env(safe-area-inset-top)); pointer-events: auto; }
#quit { position: absolute; right: 10px; top: max(8px, env(safe-area-inset-top)); pointer-events: auto; }
#minimap {
  position: absolute; right: 10px; top: calc(max(8px, env(safe-area-inset-top)) + 42px);
  width: 170px; height: 120px; background: rgba(0,0,0,.22); border-radius: 10px; opacity: .85;
}
#hud-speed {
  position: absolute; left: 10px; top: calc(max(8px, env(safe-area-inset-top)) + 48px);
  font-size: 14px; font-weight: 600; background: rgba(0,0,0,.4); padding: 3px 10px; border-radius: 8px;
}
#countdown {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 110px; font-weight: 900; color: #fff; text-shadow: 0 4px 24px rgba(0,0,0,.7); pointer-events: none;
}

/* controles táctiles: solo en pantallas táctiles */
#touch { display: none; position: absolute; left: 0; right: 0; bottom: 0; padding: 0 18px max(14px, env(safe-area-inset-bottom)); justify-content: space-between; pointer-events: none; }
@media (pointer: coarse) { #touch { display: flex; } }
.pad { display: flex; gap: 14px; pointer-events: auto; }
.pad button {
  min-width: 92px; height: 92px; border-radius: 50%; border: 3px solid rgba(255,255,255,.55);
  background: rgba(0,0,0,.35); color: #fff; font-size: 20px; font-weight: 800; touch-action: none;
}
.pad.right button { border-radius: 22px; min-width: 120px; font-size: 15px; }
.pad button.on { background: rgba(255,202,40,.65); color: #111; }

/* ---------- resultados ---------- */
.results-box { background: #1b1f28; border-radius: 16px; padding: 16px 20px; width: min(720px, 94vw); max-height: 92vh; display: flex; flex-direction: column; gap: 10px; }
.results-box h2 { margin: 0; font-size: 20px; }
.table-wrap { overflow-y: auto; touch-action: pan-y; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: #8b95a7; font-weight: 500; padding: 4px 6px; position: sticky; top: 0; background: #1b1f28; }
td { padding: 4px 6px; border-top: 1px solid #272d3a; }
tr.me td { background: rgba(255,202,40,.14); font-weight: 700; }
tr.viewer td:nth-child(2) { color: #80deea; }
.results-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* aviso de girar el celular */
#rotate { display: none; position: fixed; inset: 0; z-index: 99; background: #14171c; align-items: center; justify-content: center; font-size: 22px; text-align: center; padding: 20px; }
@media (orientation: portrait) and (max-width: 700px) { #rotate { display: flex; } }
@media (max-height: 460px) {
  #menu h1 { font-size: 18px; margin-bottom: 0; }
  .card canvas { height: 48px; }
  .pad button { min-width: 78px; height: 78px; }
  .pad.right button { min-width: 104px; }
  #minimap { width: 130px; height: 92px; }
}

/* pantalla completa */
#fs { position: absolute; right: 94px; top: max(8px, env(safe-area-inset-top)); pointer-events: auto; }
button.fs-btn.corner { position: absolute; right: 12px; top: max(8px, env(safe-area-inset-top)); z-index: 3; }

/* tablas en dos columnas (16 pilotos) */
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.split table th { position: static; }
@media (max-height: 460px) {
  td, th { padding: 2px 5px; font-size: 12px; }
  .results-box { padding: 10px 14px; gap: 6px; }
  .results-box h2 { font-size: 17px; }
}
#game { overflow: hidden; }

.tire-chips .chip { font-size: 12px; padding: 5px 10px; }
.tire-desc { flex-basis: 100%; margin: 2px 0 0; color: #8b95a7; font-size: 12px; }
.pad button.hand { min-width: 84px; font-size: 12px; }
.pad button.back { min-width: 58px; width: 58px; height: 58px; font-size: 24px; align-self: flex-end; opacity: .8; } /* mirar atrás */
.pad .stack { display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.pad button.nitro { font-size: 14px; background: rgba(255,112,67,.55); height: 52px; transition: opacity .15s, transform .08s; }
.pad button.nitro.low { opacity: .4; filter: grayscale(.8); } /* no alcanza para una descarga */
.pad button.nitro.press { transform: scale(.94); }
.pad button.nitro.on { background: rgba(255,235,59,.8); color: #111; box-shadow: 0 0 12px #ffeb3b; opacity: 1; filter: none; }
@media (max-height: 460px) { .pad .stack button { height: 52px; } .pad .stack button.nitro { height: 44px; } }

/* ---------- información de pista y de carrera ---------- */
#hud-info {
  position: absolute; left: 10px; top: calc(max(8px, env(safe-area-inset-top)) + 80px); max-width: 210px;
  font-size: 12px; font-weight: 600; line-height: 1.35; background: rgba(0,0,0,.42); padding: 4px 10px; border-radius: 8px;
}
#hud-info:empty { display: none; }
#hud-info .i1 { color: #cfd8e3; font-weight: 500; }
#hud-info .good { color: #8bd68f; } #hud-info .mid { color: #ffd54f; } #hud-info .bad { color: #ff8a80; }
#hud-info .nbar { position: relative; height: 12px; margin-top: 3px; background: rgba(255,255,255,.15); border-radius: 6px; overflow: hidden; }
#hud-info .nbar i { position: absolute; inset: 0 auto 0 0; background: #ff9800; border-radius: 6px; }
#hud-info .nbar.on i { background: #ffeb3b; box-shadow: 0 0 8px #ffeb3b; }
#hud-info .nbar::after { content: ''; position: absolute; inset: 0; z-index: 2; pointer-events: none; background: linear-gradient(90deg, transparent calc(33.33% - 1px), rgba(0,0,0,.55) calc(33.33% - 1px) calc(33.33% + 1px), transparent calc(33.33% + 1px), transparent calc(66.66% - 1px), rgba(0,0,0,.55) calc(66.66% - 1px) calc(66.66% + 1px), transparent calc(66.66% + 1px)); } /* marcas de las 3 descargas */
#hud-info .nbar span { position: absolute; left: 6px; top: -1px; z-index: 1; font-size: 9px; font-weight: 800; letter-spacing: .6px; color: #111; mix-blend-mode: normal; }
#hud-info .i4 { display: inline-block; margin-top: 2px; padding: 0 8px; border-radius: 6px; background: #ff7043; color: #111; font-weight: 800; letter-spacing: .5px; }
@media (max-height: 420px) { #hud-info { font-size: 11px; max-width: 180px; top: calc(max(8px, env(safe-area-inset-top)) + 72px); } }
.trackcard { background: #232836; border-radius: 10px; padding: 8px 12px; margin: 4px 0 8px; text-align: left; }
.trackcard .tc-name { font-weight: 800; font-size: 15px; }
.trackcard .tc-forma { font-size: 12px; color: #ffe082; margin: 3px 0; } /* tipo de pista (BOP) */
.trackcard .tc-tags { display: flex; flex-wrap: wrap; gap: 5px; margin: 4px 0; }
.trackcard .tag { background: #343b4d; border-radius: 6px; padding: 1px 8px; font-size: 12px; }
.trackcard .tc-haz { font-size: 12px; color: #c9d1de; }
.trackcard .tc-tip { font-size: 12px; margin-top: 4px; font-weight: 700; }
.trackcard .tc-tip.ok { color: #8bd68f; } .trackcard .tc-tip.warn { color: #ffd54f; }
.tc-title { margin: 8px 0 0; }

/* ---------- controles y diagnóstico ---------- */
.ctl { display: flex; flex-direction: column; gap: 10px; max-width: 420px; }
.ctl label { display: flex; flex-direction: column; gap: 2px; font-size: 13px; color: #cfd8e3; }
.ctl .ends { display: flex; justify-content: space-between; font-size: 11px; color: #8b95a7; }
.ctl .ends i { font-style: normal; }
.ctl input[type=range] { width: 100%; }
.ctl label.chk { flex-direction: row; align-items: center; gap: 8px; }
#dbg {
  position: absolute; right: 10px; top: calc(max(8px, env(safe-area-inset-top)) + 56px); z-index: 4; pointer-events: none;
  font: 600 12px/1.35 ui-monospace, Menlo, Consolas, monospace; background: rgba(0,0,0,.6); padding: 4px 8px; border-radius: 8px; white-space: pre; color: #cfd8e3;
}
#dbg .good { color: #8bd68f; } #dbg .mid { color: #ffd54f; } #dbg .bad { color: #ff8a80; }

.card img.tc-mini { width: 100%; height: 64px; display: block; object-fit: cover; border-radius: 8px; background: #1a1e27; }
.volver-menu { display: inline-block; text-decoration: none; background: #2c3140; color: #eceff4; border-radius: 999px; padding: 6px 14px; font-weight: 700; font-size: 14px; align-self: center; }

/* desafíos 1 contra 1 */
.desafio-box { max-width: 520px; }
.d-lista { display: flex; flex-direction: column; gap: 6px; max-height: 40vh; overflow: auto; margin: 8px 0; }
.d-lista button { text-align: left; padding: 10px 12px; border-radius: 10px; border: 2px solid transparent; background: rgba(255,255,255,.08); color: inherit; font-size: 16px; }
.d-lista button.sel { border-color: #ffd54f; background: rgba(255,213,79,.15); }
.d-lista button:disabled { opacity: .45; }
.d-lista small { opacity: .7; margin-left: 6px; }
.d-opts { display: flex; gap: 14px; flex-wrap: wrap; margin: 6px 0; }
.d-opts select { font-size: 15px; padding: 4px; max-width: 260px; }
.d-buscar { width: 100%; box-sizing: border-box; font-size: 16px; padding: 8px 10px; border-radius: 10px; border: 1px solid rgba(255,255,255,.25); background: rgba(0,0,0,.3); color: inherit; margin-top: 6px; }
/* aviso de desafío recibido: se toca para ver el detalle (no interrumpe la carrera) */
.desafio-noti { position: fixed; top: 10px; left: 50%; transform: translateX(-50%); z-index: 85; background: linear-gradient(135deg, #ff7043, #e53935); color: #fff; border: 0; border-radius: 16px; padding: 10px 18px; font: 700 16px system-ui, sans-serif; box-shadow: 0 6px 20px rgba(0,0,0,.45); animation: noti-latido 1.2s ease-in-out infinite; max-width: 92vw; }
@keyframes noti-latido { 50% { transform: translateX(-50%) scale(1.05); } }
.b-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; background: rgba(255,255,255,.08); }
.b-item .b-txt { flex: 1; line-height: 1.25; }
.b-item small { opacity: .75; }
.b-item button { padding: 6px 10px; border-radius: 8px; border: 0; font-weight: 700; }
.b-item .b-si { background: #2e7d32; color: #fff; }
.b-item .b-si:disabled { background: #555; color: #bbb; }
.b-item .b-no { background: rgba(255,255,255,.15); color: inherit; }
.b-badge { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 9px; background: #e53935; color: #fff; font-size: 12px; font-weight: 800; line-height: 18px; text-align: center; }
