/* Controles táctiles (src/mobile/pad.js, montados por src/mobile/touch.js y por el cliente del streaming)
   y HUD para pantalla táctil (html.touch-ui). Mano izquierda: joystick flotante (nace bajo el pulgar en la
   mitad izquierda); mano derecha: DERRAPE, TURBO, FRENA y PODER en abanico, sin botón de acelerar.
   El velocímetro sube a la esquina de arriba a la derecha y el letrero de calle se va (lo dice el minimapa). */
html.touch-ui, html.touch-ui body { overscroll-behavior: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
html.touch-ui canvas { touch-action: none; }

.tc6 { --sl: max(14px, env(safe-area-inset-left)); --sr: max(14px, env(safe-area-inset-right)); --sb: max(12px, env(safe-area-inset-bottom));
  position: fixed; inset: 0; height: auto; pointer-events: none; z-index: 30; touch-action: none; transition: opacity .2s; }
.tc6.off { opacity: 0; visibility: hidden; }
.tc6 .tbtn { position: fixed; pointer-events: auto; touch-action: none; margin: 0; padding: 0; border-radius: 50%;
  border: 3px solid rgba(251, 247, 238, .85); color: #fbf7ee; font-family: var(--ui, sans-serif); font-weight: 900; font-size: 13px; letter-spacing: .5px; text-transform: uppercase;
  background: rgba(20, 10, 30, .38); box-shadow: 0 3px 0 rgba(20, 10, 30, .55); -webkit-backdrop-filter: none; backdrop-filter: none;
  text-shadow: 0 2px 0 rgba(20, 10, 30, .8); transition: transform .06s, background .06s; }
.tc6 .tbtn.on { transform: scale(.93); box-shadow: 0 1px 0 rgba(20, 10, 30, .55); }

/* joystick: zona de toque (mitad izquierda, bajo la franja del HUD) y base flotante con anillo y pomo */
.tc6 .tjoy-zone { position: fixed; left: 0; top: 22%; width: 50%; bottom: 0; pointer-events: auto; touch-action: none; }
.tc6 .tjoy { position: fixed; left: 120px; top: 70%; width: 0; height: 0; pointer-events: none; }
.tc6 .tjoy-ring { position: absolute; left: -58px; top: -58px; width: 116px; height: 116px; border-radius: 50%; box-sizing: border-box;
  border: 3px solid rgba(251, 247, 238, .5); background: radial-gradient(circle, rgba(20, 10, 30, .18) 0 55%, rgba(20, 10, 30, .32) 100%);
  opacity: .45; transition: opacity .12s; }
.tc6 .tjoy-knob { position: absolute; left: -27px; top: -27px; width: 54px; height: 54px; border-radius: 50%; background: rgba(255, 210, 63, .55);
  border: 3px solid rgba(251, 247, 238, .9); box-shadow: 0 3px 0 rgba(20, 10, 30, .55); opacity: .5; transition: opacity .12s, background .08s; }
.tc6 .tjoy-hint { position: absolute; left: 0; top: -84px; translate: -50% 0; white-space: nowrap; font: 900 11px var(--ui, sans-serif); letter-spacing: .08em;
  text-transform: uppercase; color: #fbf7ee; text-shadow: 0 2px 0 rgba(20, 10, 30, .8); opacity: .7; transition: opacity .2s; }
.tc6 .tjoy.held .tjoy-ring, .tc6 .tjoy.held .tjoy-knob { opacity: 1; }
.tc6 .tjoy.held .tjoy-hint { opacity: 0; }
.tc6 .tjoy.up .tjoy-knob { background: rgba(87, 240, 0, .75); }
.tc6 .tjoy.down .tjoy-knob { background: rgba(255, 31, 61, .7); }

/* mano derecha: abanico para el pulgar (DERRAPE y TURBO, los de siempre, más grandes) */
.tc6 .tbtn.drift { right: var(--sr); bottom: var(--sb); width: 88px; height: 88px; font-size: 14px; background: rgba(255, 210, 63, .42); }
.tc6 .tbtn.boost { right: calc(var(--sr) + 98px); bottom: calc(var(--sb) + 4px); width: 76px; height: 76px; background: rgba(0, 208, 255, .42); }
.tc6 .tbtn.brake { right: calc(var(--sr) + 8px); bottom: calc(var(--sb) + 98px); width: 64px; height: 64px; font-size: 12px; background: rgba(255, 31, 61, .32); }
.tc6 .tbtn.item { right: calc(var(--sr) + 90px); bottom: calc(var(--sb) + 90px); width: 62px; height: 62px; font-size: 12px; background: rgba(255, 31, 142, .42); }
.tc6 .tbtn.brake.on { background: rgba(255, 31, 61, .6); } .tc6 .tbtn.drift.on { background: rgba(255, 210, 63, .7); }
.tc6 .tbtn.boost.on { background: rgba(0, 208, 255, .7); } .tc6 .tbtn.item.on { background: rgba(255, 31, 142, .7); }


/* pausa: arriba al centro, chica (el aviso de la franja va más abajo) */
.tc6 .tbtn.pause { left: 50%; top: max(6px, env(safe-area-inset-top)); translate: -50% 0; width: 44px; height: 44px; border-width: 2px; background: rgba(20, 10, 30, .5); }
.tc6 .tbtn.pause i { position: absolute; top: 13px; width: 5px; height: 14px; background: #fbf7ee; border-radius: 1px; }
.tc6 .tbtn.pause i:first-child { left: 14px; } .tc6 .tbtn.pause i:last-child { right: 14px; }

/* ---- HUD con controles táctiles ---- */
html.touch-ui .menu .ctrl, html.touch-ui .opt-go kbd, html.touch-ui .menu kbd, html.touch-ui .pause-hint { display: none; }
html.touch-ui .hud-bl .map-sign { display: none; }
/* teléfono horizontal (390 px de alto): velocímetro arriba a la derecha, minimapa más chico */
@media (max-height: 480px) {
  html.touch-ui .hud-br { right: max(8px, env(safe-area-inset-right)); top: 76px; bottom: auto; scale: .36; transform-origin: 100% 0; }
  html.touch-ui .hud-combo { right: auto; left: 50%; bottom: auto; top: 60px; translate: -50% 0; scale: .5; transform-origin: 50% 0; }
  html.touch-ui .hud-bl { top: 23%; scale: .56; }
  html.touch-ui .hud-notice { top: 58px; }
  /* flechas de ataque de los rivales (src/race): más arriba y chicas, lejos de TURBO y del timón */
  html.touch-ui .rp .rp-chase { bottom: 150px; scale: .75; }
}
/* teléfono vertical: el HUD arriba, los controles abajo */
@media (max-width: 700px) and (orientation: portrait) {
  .tc6 .tjoy-zone { top: 45%; }
  .tc6 .tbtn.drift { right: var(--sr); bottom: calc(var(--sb) + 8px); width: 76px; height: 76px; font-size: 12px; }
  .tc6 .tbtn.boost { right: calc(var(--sr) + 86px); bottom: calc(var(--sb) + 12px); width: 64px; height: 64px; font-size: 11px; }
  .tc6 .tbtn.brake { right: calc(var(--sr) + 6px); bottom: calc(var(--sb) + 94px); width: 56px; height: 56px; font-size: 11px; }
  .tc6 .tbtn.item { right: calc(var(--sr) + 78px); bottom: calc(var(--sb) + 86px); width: 54px; height: 54px; font-size: 11px; }
  html.touch-ui .hud-br { right: max(8px, env(safe-area-inset-right)); top: 96px; bottom: auto; scale: .42; transform-origin: 100% 0; }
  html.touch-ui .hud-combo { right: auto; left: 50%; bottom: auto; top: 150px; translate: -50% 0; scale: .5; transform-origin: 50% 0; }
  html.touch-ui .hud-bl { top: 96px; scale: .5; }
}

/* sugerencia de girar el celular: solo en vertical y fuera de carrera */
.rotate-hint { display: none; }
@media (orientation: portrait) and (max-width: 700px) {
  html.touch-ui .rotate-hint:not(.racing) { display: flex; align-items: center; gap: 10px; position: fixed; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); translate: -50% 0; z-index: 40; pointer-events: none;
    padding: 8px 14px; border-radius: 10px; background: rgba(20, 10, 30, .82); border: 2px solid #ffd23f; color: #fbf7ee; font-family: var(--ui, sans-serif); font-weight: 800; font-size: 13px; white-space: nowrap; }
  html.touch-ui .rotate-hint b { width: 14px; height: 22px; border: 2px solid #ffd23f; border-radius: 3px; animation: rotHint 2.4s ease-in-out infinite; }
}
@keyframes rotHint { 0%, 30% { rotate: 0deg; } 55%, 85% { rotate: -90deg; } 100% { rotate: 0deg; } }

/* sin teclado: ni la «E» de la casilla del poder ni la «O» de Configuración (menú y pausa) */
html.touch-ui .it-slot .it-key, html.touch-ui .st-open kbd, html.touch-ui .pause kbd { display: none; }
/* carteles y flecha del próximo giro más chicos en el celular (tapaban el mototaxi y la pausa) */
@media (max-height: 480px) {
  html.touch-ui .wpop { scale: .62; transform-origin: 0 0; }
  html.touch-ui .wturn .in { scale: .62; }
}
@media (max-width: 700px) and (orientation: portrait) {
  html.touch-ui .wturn .in { scale: .7; }
}

/* ---- Ronda 3: menú, Configuración y resultados en el celular ---- */
/* la sugerencia de girar el celular solo en el menú principal: ni sobre Configuración (tapaba
   «Restaurar valores» y «Listo»), ni en la pausa, ni sobre el podio. La clase .off la pone touch.js
   (sin :has() en html: invalidaría el estilo de toda la página con cada cambio del HUD) */
html.touch-ui .rotate-hint.off { display: none !important; }

/* menú principal en horizontal (390 px de alto): logo con tope de alto, todo más junto, el aviso a la vista */
@media (max-height: 480px) {
  html.touch-ui .menu { justify-content: center; padding: max(6px, env(safe-area-inset-top)) 0 max(6px, env(safe-area-inset-bottom)); box-sizing: border-box; }
  html.touch-ui .menu .logo { width: auto !important; height: min(28vh, 112px) !important; max-width: 80vw; }
  html.touch-ui .menu .tag { margin: 0 0 8px; font-size: 14px; padding: 4px 12px; }
  html.touch-ui .menu-opts { flex-direction: row; align-items: stretch; gap: 10px; }
  html.touch-ui .opt-go { font-size: 22px; padding: 8px 24px; }
  html.touch-ui .opt-laps { font-size: 15px; padding: 2px 10px; }
  html.touch-ui .opt-laps b { font-size: 21px; }
  html.touch-ui .st-open.in-menu { margin-top: 8px; min-height: 34px; font-size: 13px; }
  html.touch-ui .menu .rule { margin-top: 8px; font-size: 12px; padding: 4px 10px; max-width: 80vw; }
  html.touch-ui .menu .press { margin-top: 8px; font-size: 14px; }
}
/* Configuración en pantallas angostas (vertical, o horizontal de 667 px como el iPhone SE): las cinco
   pestañas a la vista (antes MOTOTAXI y CONTROLES quedaban fuera, en una fila que había que deslizar) */
@media (max-width: 760px) {
  html.touch-ui .st-tabs { overflow: visible; padding: 6px 6px; gap: 4px; }
  html.touch-ui .st-tab { flex: 1 1 0; min-width: 0; flex-direction: column; gap: 3px; padding: 6px 2px; font-size: 11px; letter-spacing: .02em; text-align: center; justify-content: center; }
  html.touch-ui .st-tab svg { width: 18px; height: 18px; }
}

/* resultados con el dedo: el podio, la tabla y el aviso caben en la pantalla */
html.touch-ui .rp-res-wrap { padding: max(6px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); }
html.touch-ui .rp-again { order: 10; margin-top: 10px; padding: 6px 18px; border: 2px solid #ffd23f; border-radius: 999px; background: rgba(20, 10, 30, .78); }
html.touch-ui .rp-tomenu { order: 11; margin-top: 8px; padding: 6px 16px; min-height: 36px; border: 2px solid rgba(251, 247, 238, .55); border-radius: 6px; background: rgba(20, 10, 30, .7); color: #fbf7ee;
  font: 800 13px var(--ui, sans-serif); letter-spacing: .1em; text-transform: uppercase; pointer-events: auto; }
html.touch-ui .rp-table { min-width: 0; font-size: 12px; }
html.touch-ui .rp-table th { padding: 4px 6px; font-size: 10px; letter-spacing: 1px; }
html.touch-ui .rp-table td { padding: 3px 6px; }
html.touch-ui .rp-table td:nth-last-child(-n+2) { white-space: nowrap; }
html.touch-ui .rp-table td.p { font-size: 15px; }
html.touch-ui .rp-table .hide-s { display: none; }
@media (max-width: 520px) {
  html.touch-ui .rp-res-wrap h1, html.touch-ui .rp-res-wrap h2 { zoom: .8; }
  html.touch-ui .rp-podium { gap: 8px; }
  html.touch-ui .rp-step .who { zoom: .58; } /* el nombre (lienzo chicha de hasta 220 px) pisaba al del lado en escalones de 110 px */
  html.touch-ui .rp-step .st { zoom: .8; }
  html.touch-ui .rp-table { margin-top: 8px; }
  html.touch-ui .rp-again { zoom: .72; margin-top: 14px; }
}
/* horizontal (390 px de alto): título arriba, podio a la izquierda y tabla a la derecha, aviso abajo */
@media (max-height: 480px) {
  html.touch-ui .rp-res-wrap { display: grid; grid-template-columns: auto auto; grid-template-rows: auto auto 1fr auto; justify-content: center; justify-items: center; align-items: center; column-gap: 22px; max-width: none; }
  html.touch-ui .rp-res-wrap h1 { grid-column: 1 / -1; zoom: .62; margin: 0; }
  html.touch-ui .rp-res-wrap h2 { grid-column: 1 / -1; zoom: .7; margin: 0 0 6px; }
  html.touch-ui .rp-podium { grid-column: 1; zoom: .52; min-height: 0; }
  html.touch-ui .rp-table { grid-column: 2; margin-top: 0; }
  html.touch-ui .rp-again { grid-column: 1 / -1; zoom: .7; margin-top: 8px; }
  html.touch-ui .rp-tomenu { position: absolute; right: max(10px, env(safe-area-inset-right)); bottom: max(8px, env(safe-area-inset-bottom)); margin: 0; }
}
/* tableta horizontal (más de 480 px de alto, p. ej. 1280×800): el velocímetro sube arriba a la derecha,
   debajo de la vuelta y el tiempo (abajo lo tapaban DERRAPE, TURBO y ACELERA), y el minimapa sube por
   encima del timón */
@media (min-height: 481px) and (orientation: landscape) {
  html.touch-ui .hud-br { right: max(14px, env(safe-area-inset-right)); top: 188px; bottom: auto; scale: .6; transform-origin: 100% 0; }
  html.touch-ui .hud-bl { bottom: calc(max(12px, env(safe-area-inset-bottom)) + 108px); }
}

/* (oleada 15a) LIMPIAR: solo con la pantalla manchada por la paloma (.show, lo pone src/items/palomas.js; en
   el streaming, el cliente según el estado del anfitrión). Con el joystick (14s) va en la mano derecha, a la
   izquierda del abanico de botones: se alcanza con el pulgar derecho sin soltar el joystick y no tapa el
   velocímetro (arriba a la derecha) ni el minimapa */
.tc6 .tbtn.wipe { display: none; right: calc(var(--sr) + 186px); bottom: calc(var(--sb) + 26px); width: 84px; height: 84px; font-size: 13px; font-weight: 900; background: rgba(251, 247, 238, .72); color: #140a1e; border-color: #140a1e; text-shadow: none; }
.tc6 .tbtn.wipe.show { display: block; animation: tcWipe .5s ease-in-out infinite alternate; }
.tc6 .tbtn.wipe.on { background: rgba(0, 208, 255, .8); }
@keyframes tcWipe { from { box-shadow: 0 0 0 0 rgba(0, 208, 255, 0); } to { box-shadow: 0 0 0 8px rgba(0, 208, 255, .6); } }
@media (max-width: 700px), (max-height: 480px) {
  .tc6 .tbtn.wipe { width: 74px; height: 74px; font-size: 12px; right: calc(var(--sr) + 180px); bottom: calc(var(--sb) + 22px); }
}
@media (max-width: 700px) and (orientation: portrait) {
  .tc6 .tbtn.wipe { right: calc(var(--sr) + 4px); bottom: calc(var(--sb) + 160px); }
}
