:root {
  --noche: #0d2a5c;
  --panel: rgba(12, 36, 82, .90);
  --rojo: #e8142d;
  --oro: #ffc21a;
  --verde: #12a150;
  --nieve: #f2f8ff;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--noche); }
body {
  font-family: ui-rounded, "SF Pro Rounded", "Baloo 2", "Segoe UI", system-ui, sans-serif;
  color: var(--nieve);
  -webkit-user-select: none; user-select: none; touch-action: none;
}
#lienzo { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.pantalla { position: fixed; inset: 0; pointer-events: none; }
.pantalla > * { pointer-events: auto; }
.centro { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px; }

.logo { margin: 0 0 12px; font-size: clamp(26px, 4vw, 38px); line-height: 1.05; text-shadow: 0 3px 0 var(--rojo); }
.logo b { color: var(--oro); margin: 0 .18em; }
#cargando { background: var(--noche); pointer-events: auto; }
.barra { width: min(320px, 80vw); height: 14px; border-radius: 9px; background: #ffffff22; overflow: hidden; }
.barra i { display: block; height: 100%; width: 0; background: var(--oro); transition: width .2s; }

.panel {
  background: var(--panel); border: 3px solid #ffffff30; border-radius: 22px; padding: 18px 20px;
  box-shadow: 0 18px 50px #00112e80; backdrop-filter: blur(6px);
}
#menu .panel {
  position: absolute; left: 16px; top: 16px; bottom: 16px; width: min(440px, calc(100% - 32px));
  overflow-y: auto; touch-action: pan-y;
}
h2 { font-size: 17px; margin: 14px 0 8px; color: var(--oro); }
h2 small { color: var(--nieve); font-weight: 500; }
label { display: block; font-weight: 700; margin-bottom: 6px; }
input:not([type=checkbox]) {
  width: 100%; font: inherit; font-size: 20px; font-weight: 700; padding: 10px 14px;
  border-radius: 12px; border: 3px solid #ffffff55; background: #fff; color: #10203f;
  -webkit-user-select: text; user-select: text;
}
button {
  font: inherit; font-weight: 800; cursor: pointer; color: #fff; background: #2c6fe0;
  border: 0; border-radius: 12px; padding: 10px 16px; box-shadow: 0 4px 0 #0006;
}
button:active { transform: translateY(2px); box-shadow: 0 2px 0 #0006; }
button:disabled { filter: grayscale(.8); opacity: .65; cursor: default; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--oro); outline-offset: 2px; }
.grande { width: 100%; font-size: 22px; padding: 14px; background: var(--rojo); margin-top: 12px; }
.suave { width: 100%; margin-top: 10px; background: #ffffff2b; }
.mini { font-size: 14px; padding: 6px 12px; }

.opciones { display: grid; gap: 8px; }
.tres { grid-template-columns: repeat(3, 1fr); }
.cinco { grid-template-columns: repeat(5, 1fr); }
.dos { grid-template-columns: 1fr 1fr; }
.opciones button { background: #ffffff1c; padding: 8px 4px; font-size: 13px; border: 3px solid transparent; }
.opciones button[aria-pressed="true"] { border-color: var(--oro); background: #ffffff38; }
.opciones button:disabled { cursor: default; }
.stat { display: grid; grid-template-columns: 1fr 1.2fr; gap: 2px 5px; align-items: center; margin-top: 5px; font-size: 10px; font-weight: 600; text-align: left; }
.stat i { height: 6px; border-radius: 4px; background: var(--oro); }
.colores { display: flex; justify-content: center; gap: 3px; margin-bottom: 4px; }
.colores i { width: 12px; height: 12px; border-radius: 50%; border: 1px solid #ffffffaa; }
.casilla { display: flex; gap: 8px; align-items: center; font-weight: 600; font-size: 14px; margin: 14px 0 0; }
.casilla input { width: 20px; height: 20px; }
.unirse { display: flex; gap: 8px; margin-top: 12px; }
.unirse input { text-transform: uppercase; letter-spacing: .2em; text-align: center; }
#aviso { min-height: 1.2em; margin: 10px 0 4px; font-weight: 700; color: #ffd75e; }
.ayuda { font-size: 12.5px; opacity: .8; margin: 4px 0 0; line-height: 1.5; }

.codigo { text-align: center; background: #ffffff17; border-radius: 16px; padding: 10px; }
.codigo span { display: block; font-size: 13px; }
.codigo strong { display: block; font-size: 46px; letter-spacing: .22em; color: var(--oro); -webkit-user-select: text; user-select: text; }
#pilotos { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
#pilotos li { display: flex; justify-content: space-between; gap: 8px; background: #ffffff17; border-radius: 10px; padding: 8px 12px; font-weight: 700; }
#pilotos li.yo { outline: 2px solid var(--oro); }
#pilotos li span:last-child { font-weight: 600; opacity: .85; font-size: 13px; text-align: right; }

#marcador { position: absolute; left: max(12px, env(safe-area-inset-left)); top: max(12px, env(safe-area-inset-top)); display: flex; flex-direction: column; gap: 6px; align-items: flex-start; pointer-events: none; }
.caja { background: var(--panel); border-radius: 12px; padding: 5px 14px; font-weight: 700; font-variant-numeric: tabular-nums; }
.caja b { font-size: 21px; color: var(--oro); }
.puesto b { font-size: 38px; }
#orden { margin: 4px 0 0; padding: 6px 12px 6px 30px; background: #0c2452a8; border-radius: 12px; font-size: 14px; font-weight: 700; }
#orden li.yo { color: var(--oro); }
#mapa { position: absolute; right: max(12px, env(safe-area-inset-right)); top: max(12px, env(safe-area-inset-top)); width: 220px; height: 180px; background: #0c2452b0; border-radius: 14px; pointer-events: none; }
#extras { position: absolute; right: max(12px, env(safe-area-inset-right)); top: 204px; display: flex; gap: 8px; }
#extras button { background: #0c2452cc; }
#velocidad { position: absolute; right: 16px; bottom: 16px; font-weight: 800; text-shadow: 0 2px 6px #002; pointer-events: none; }
#velocidad b { font-size: 46px; color: var(--oro); }
#mensaje {
  position: absolute; left: 0; right: 0; top: 24%; text-align: center; pointer-events: none;
  font-size: clamp(34px, 9vw, 96px); font-weight: 900; color: #fff; padding: 0 12px;
  -webkit-text-stroke: 2px #0d2a5c; text-shadow: 0 6px 0 #e8142d, 0 10px 30px #0009;
}
#tactil { display: none; position: absolute; left: 0; right: 0; bottom: max(14px, env(safe-area-inset-bottom)); justify-content: space-between; padding: 0 max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left)); pointer-events: none; }
#tactil div { display: flex; gap: 14px; pointer-events: auto; }
#tactil button { width: 76px; height: 76px; padding: 0; border-radius: 50%; font-size: 28px; line-height: 1; background: #0c2452b8; border: 3px solid #fff8; touch-action: none; -webkit-touch-callout: none; }
#tactil small { display: block; font-size: 10px; margin-top: 4px; }
#tactil [data-tecla="gas"] { background: #12a150cc; }
#tactil [data-tecla="freno"] { background: #b3122acc; }
#tactil button.pulsado { background: var(--oro); color: #10203f; }
/* girando con el movil: un pedal para cada pulgar */
#tactil.inclinar .flechas { display: none; }
#tactil.inclinar .pedales { flex: 1; justify-content: space-between; }
#tactil.inclinar button { width: 112px; height: 112px; font-size: 40px; }
#tactil.inclinar small { font-size: 13px; }
#girar { display: none; }
@media (pointer: coarse) {
  #tactil { display: flex; }
  #velocidad { left: 0; right: 0; bottom: 14px; text-align: center; }
  #velocidad b { font-size: 30px; }
}
@media (pointer: coarse) and (orientation: portrait) {
  #girar { display: block; position: absolute; left: 12px; right: 12px; bottom: 150px; text-align: center; font-weight: 800; text-shadow: 0 2px 6px #002; pointer-events: none; }
}

#resultados { background: #06173a99; pointer-events: auto; }
.ancho { width: min(640px, 100%); max-height: 100%; overflow: auto; text-align: center; touch-action: pan-y; }
#ganador { font-size: clamp(26px, 5vw, 40px); color: #fff; margin-top: 0; text-shadow: 0 3px 0 var(--rojo); }
.tabla { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th { font-size: 12px; color: var(--oro); }
th, td { padding: 7px 6px; border-bottom: 1px solid #ffffff2a; }
tr.yo { background: #ffffff1f; }
td:last-child { font-weight: 900; font-size: 19px; }

/* movil en horizontal: panel estrecho a la izquierda */
@media (orientation: landscape) and (max-height: 500px) {
  #menu .panel { left: max(8px, env(safe-area-inset-left)); top: 8px; bottom: 8px; width: min(400px, 56%); padding: 10px 14px; }
  #menu .logo { font-size: 22px; margin-bottom: 6px; }
  .cinco button { font-size: 11px; }
}
@media (max-width: 760px) and (orientation: portrait) {
  #menu .panel { left: 8px; right: 8px; width: auto; top: 34%; bottom: 8px; padding: 14px; }
  #menu .logo { font-size: 24px; }
  .cinco { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 760px) {
  #mapa { width: 128px; height: 105px; }
  #extras { top: 124px; flex-direction: column; align-items: flex-end; }
  #orden { display: none; }
  .puesto b { font-size: 28px; }
}
@media (max-height: 500px) {
  #mapa { width: 128px; height: 105px; }
  #extras { top: 124px; flex-direction: column; align-items: flex-end; }
  #orden { display: none; }
  .caja { padding: 2px 10px; font-size: 13px; }
}
