/* ==========================================================================
   Dotykové ovládání + responzivní HUD na mobilu (body.touch).
   Načítá se PO style.css (a po CSS, které vkládají moduly, má vyšší specifičnost
   díky prefixu body.touch). Režim ovládání nastavuje input.setMode() do
   body[data-tc-mode] = car | foot | bike | tram | ride (main.js podle stavu hráče).
   Rozložení:  vlevo dole minimapa (+ 🗺️ na jejím rohu), nad ní poloha/navigace;
               vpravo dole joystick, nad ním tachometr a kontextová akce (= E);
               vpravo nahoře ⏸️ 📣 🎥 💺 (na šířku v řadě). Vše s env(safe-area-inset-*).
   ========================================================================== */

body.touch {
  --sa-t: env(safe-area-inset-top, 0px);
  --sa-r: env(safe-area-inset-right, 0px);
  --sa-b: env(safe-area-inset-bottom, 0px);
  --sa-l: env(safe-area-inset-left, 0px);
  --tc-pad: 16px;          /* odstup od okraje */
  --tc-joy: 148px;         /* průměr joysticku */
  --tc-mm: 124px;          /* minimapa (CSS velikost, canvas je 180×180) */
  --tc-speedo: 80px;
  --tc-btn: 48px;
}

/* ---- tlačítka vpravo nahoře ---- */
body.touch.playing #touch-controls .tc-actions {
  right: calc(var(--tc-pad) + var(--sa-r));
  top: calc(12px + var(--sa-t));
  gap: 8px;
}
body.touch #touch-controls .tc-round { width: var(--tc-btn); height: var(--tc-btn); font-size: 20px; }
body.touch #touch-controls .tc-hide { display: none !important; }

/* ---- kontextová akce (= E): pilulka s ikonou a popiskem nad joystickem ---- */
body.touch #touch-controls .tc-act {
  position: absolute;
  right: calc(var(--tc-pad) + var(--sa-r));
  bottom: calc(var(--tc-pad) + var(--sa-b) + var(--tc-joy) + var(--tc-speedo) + 22px);
  min-width: 132px; height: 54px; padding: 0 16px 0 10px;
  gap: 8px; border-radius: 27px;
  background: rgba(255,178,50,.9); border-color: #ffd479; color: #10141c;
  font-size: 17px; letter-spacing: .3px;
  animation: tc-act-in .18s ease-out;
}
body.touch #touch-controls .tc-act .tc-ico { font-size: 24px; }
body.touch #touch-controls .tc-act .tc-lbl { white-space: nowrap; }
body.touch #touch-controls .tc-act.tc-off { background: rgba(14,20,30,.6); border-color: rgba(255,255,255,.3); color: #b9c4d6; }
body.touch #touch-controls .tc-act.active { transform: scale(.95); }
@keyframes tc-act-in { from { transform: scale(.85); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---- joystick ---- */
body.touch #touch-controls .tc-joy {
  width: var(--tc-joy); height: var(--tc-joy);
  right: calc(var(--tc-pad) + var(--sa-r));
  bottom: calc(var(--tc-pad) + var(--sa-b));
}

/* ---- kolo: ⚡ šlapat naplno + 🛑 brzda vlevo od joysticku ---- */
#touch-controls .tc-bike { display: none; }
body.touch[data-tc-mode="bike"] #touch-controls .tc-bike {
  display: flex; flex-direction: column; gap: 12px;
  position: absolute;
  right: calc(var(--tc-pad) + var(--sa-r) + var(--tc-joy) + 12px);
  bottom: calc(var(--tc-pad) + var(--sa-b) + 4px);
}
body.touch #touch-controls .tc-bike .tc-round { width: 58px; height: 58px; font-size: 24px; }

/* ---- 🗺️ na pravém horním rohu minimapy ---- */
body.touch #touch-controls #tc-map {
  left: calc(var(--tc-pad) + var(--sa-l) + var(--tc-mm) - 30px);
  bottom: calc(var(--tc-pad) + var(--sa-b) + var(--tc-mm) - 30px);
  width: 42px; height: 42px; font-size: 18px;
}

/* ---- co je v kterém režimu vidět ---- */
#tc-cam, #tc-sit { display: none !important; }
body.touch[data-tc-mode="car"] #tc-cam, body.touch[data-tc-mode="bike"] #tc-cam,
body.touch[data-tc-mode="tram"] #tc-cam, body.touch[data-tc-mode="ride"] #tc-cam { display: flex !important; }
body.touch[data-tc-mode="tram"] #tc-sit { display: flex !important; }
/* pěšky / v tramvaji / jako spolujezdec se netroubí */
body.touch[data-tc-mode="foot"] #tc-horn, body.touch[data-tc-mode="tram"] #tc-horn,
body.touch[data-tc-mode="ride"] #tc-horn { display: none !important; }
/* cestující (tramvaj, spolujízda): žádné řízení — jen akce (Vystoupit) + kamera */
body.touch[data-tc-mode="tram"] #touch-controls .tc-joy,
body.touch[data-tc-mode="ride"] #touch-controls .tc-joy { display: none; }
body.touch[data-tc-mode="tram"] #touch-controls .tc-act,
body.touch[data-tc-mode="ride"] #touch-controls .tc-act { bottom: calc(var(--tc-pad) + var(--sa-b) + 8px); }
/* pěšky tachometr nepotřebuju → akce hned nad joystickem */
body.touch[data-tc-mode="foot"] #speedo, body.touch[data-tc-mode="tram"] #speedo { display: none; }
body.touch[data-tc-mode="foot"] #touch-controls .tc-act {
  bottom: calc(var(--tc-pad) + var(--sa-b) + var(--tc-joy) + 14px);
}

/* ---- HUD: kompaktně, se safe-area, bez překryvu s ovládáním ---- */
body.touch #speedo {
  width: var(--tc-speedo); height: var(--tc-speedo);
  right: calc(var(--tc-pad) + var(--sa-r) + (var(--tc-joy) - var(--tc-speedo)) / 2);
  bottom: calc(var(--tc-pad) + var(--sa-b) + var(--tc-joy) + 10px);
  border-width: 2px;
}
body.touch #speed-value { font-size: 26px; }
body.touch #speed-unit { font-size: 10px; letter-spacing: 1px; margin-top: 2px; }
body.touch #speed-gear { font-size: 11px; min-height: 12px; margin-top: 1px; }
body.touch #car-name { display: none; }

body.touch #stats {
  left: calc(10px + var(--sa-l)); top: calc(10px + var(--sa-t));
  font-size: 13px; line-height: 1.5; padding: 6px 10px;
}
/* sanitky a FPS na mobilu jen zabírají místo (FPS ukáže ?fps / ESC grafika) */
body.touch #stats > div:not(#money-line) { display: none; }

body.touch #minimap {
  width: var(--tc-mm); height: var(--tc-mm);
  left: calc(var(--tc-pad) + var(--sa-l));
  bottom: calc(var(--tc-pad) + var(--sa-b));
}
body.touch #location-box {
  left: calc(var(--tc-pad) + var(--sa-l));
  bottom: calc(var(--tc-pad) + var(--sa-b) + var(--tc-mm) + 8px);
  max-width: min(200px, calc(100vw - var(--tc-joy) - 3 * var(--tc-pad) - var(--sa-l) - var(--sa-r)));
  font-size: 13px; padding: 4px 9px;
}
body.touch #nav-banner {
  left: calc(var(--tc-pad) + var(--sa-l));
  bottom: calc(var(--tc-pad) + var(--sa-b) + var(--tc-mm) + 52px);
  max-width: min(220px, calc(100vw - var(--tc-joy) - 3 * var(--tc-pad)));
  font-size: 14px; padding: 6px 10px;
}
body.touch #chat {
  left: calc(10px + var(--sa-l)); top: calc(52px + var(--sa-t));
  width: min(58vw, 300px);
}
body.touch #chat-log { max-height: 18vh; }
body.touch #chat-input { padding: 7px 10px; font-size: 16px; /* < 16px = iOS zoomuje stránku */ }
body.touch #score-pop { top: calc(var(--sa-t) + 64px); font-size: 17px; padding: 8px 14px 8px 10px; max-width: 92vw; }
body.touch #score-pop .bn-tag { font-size: 14px; }
/* náboje / nápověda pěstí: nad joystick, ne přes minimapu */
body.touch #ammo-hud {
  right: calc(var(--tc-pad) + var(--sa-r)) !important;
  bottom: calc(var(--tc-pad) + var(--sa-b) + var(--tc-joy) + 84px) !important;
  font-size: 22px !important; max-width: 60vw;
}
body.touch #ammo-hud div { font-size: 12px !important; }

/* ---- panel odjezdů na zastávce (tramstops.js) ---- */
body.touch #tstop-panel {
  position: fixed;
  right: calc(var(--tc-pad) + var(--sa-r));
  left: auto;
  bottom: calc(var(--tc-pad) + var(--sa-b) + var(--tc-joy) + var(--tc-speedo) + 90px);
  width: min(290px, calc(100vw - 2 * var(--tc-pad) - var(--sa-l) - var(--sa-r)));
  font-size: 13px; padding: 6px 9px 7px;
  max-height: calc(100vh - var(--tc-joy) - var(--tc-speedo) - 200px - var(--sa-t) - var(--sa-b));
  overflow: hidden;
}
body.touch[data-tc-mode="tram"] #tstop-panel, body.touch[data-tc-mode="ride"] #tstop-panel {
  bottom: calc(var(--tc-pad) + var(--sa-b) + 76px);
}

/* ---- panel jízdy tramvají (tramride.js) ---- */
body.touch #tramride-panel {
  top: auto; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tc-pad) + var(--sa-b) + var(--tc-mm) + 52px);
  min-width: 0; width: max-content; max-width: calc(100vw - 2 * var(--tc-pad) - var(--sa-l) - var(--sa-r));
  font-size: 13px; padding: 6px 10px; box-sizing: border-box;
}
/* klávesové nápovědy (E/X/C) na dotyku nedávají smysl — jsou tlačítka */
body.touch #tramride-panel .tr-keys { display: none; }
body.touch #tramride-hint { bottom: auto; top: calc(var(--sa-t) + 64px); max-width: 88vw; font-size: 14px; text-align: center; }

/* ---- na ŠÍŘKU (nízký displej): menší ovládání, tlačítka nahoře v řadě ---- */
@media (max-height: 500px) {
  body.touch { --tc-pad: 12px; --tc-joy: 118px; --tc-mm: 104px; --tc-speedo: 66px; --tc-btn: 42px; }
  body.touch.playing #touch-controls .tc-actions { flex-direction: row-reverse; top: calc(8px + var(--sa-t)); }
  body.touch #touch-controls .tc-joy-stick { width: 50px; height: 50px; margin-left: -25px; margin-top: -25px; }
  /* tachometr vlevo od joysticku (nad ním by se nevešla akce) */
  body.touch #speedo {
    right: calc(var(--tc-pad) + var(--sa-r) + var(--tc-joy) + 10px);
    bottom: calc(var(--tc-pad) + var(--sa-b));
  }
  body.touch #touch-controls .tc-act {
    bottom: calc(var(--tc-pad) + var(--sa-b) + var(--tc-joy) + 12px);
    height: 46px; min-width: 116px; font-size: 15px;
  }
  body.touch[data-tc-mode="bike"] #touch-controls .tc-bike {
    flex-direction: row;
    right: calc(var(--tc-pad) + var(--sa-r) + var(--tc-joy) + var(--tc-speedo) + 20px);
  }
  body.touch #touch-controls .tc-bike .tc-round { width: 52px; height: 52px; }
  body.touch #location-box, body.touch #nav-banner { max-width: 34vw; }
  body.touch #stats { top: calc(6px + var(--sa-t)); }
  body.touch #chat { top: calc(44px + var(--sa-t)); width: min(34vw, 300px); }
  body.touch #chat-log { max-height: 30vh; }
  body.touch #tstop-panel {
    top: calc(60px + var(--sa-t)); bottom: auto;
    width: min(270px, 40vw);
    max-height: calc(100vh - 60px - var(--tc-joy) - 90px - var(--sa-t) - var(--sa-b));
  }
  body.touch[data-tc-mode="tram"] #tstop-panel, body.touch[data-tc-mode="ride"] #tstop-panel {
    bottom: auto; max-height: calc(100vh - 130px - var(--sa-t) - var(--sa-b));
  }
  body.touch #tramride-panel { top: calc(8px + var(--sa-t)); bottom: auto; max-width: 46vw; }
  body.touch #ammo-hud { bottom: calc(var(--tc-pad) + var(--sa-b) + var(--tc-joy) + 66px) !important; }
}

/* ---- výběrník na mobilu: „📍 Moje poloha" pořád po ruce (plovoucí dole) ---- */
#cs-geo-fab { display: none; }
@media (max-width: 1000px) {
  #city-select:not(.hidden) #cs-geo-fab {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    position: fixed; z-index: 60;
    left: 50%; transform: translateX(-50%);
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    width: min(88vw, 340px); height: 54px;
    font: 800 18px/1 system-ui, sans-serif; letter-spacing: .5px;
    color: #fff; background: linear-gradient(180deg, #ff5c9a, #c2306a);
    border: 2px solid rgba(255,190,215,.8); border-radius: 27px;
    box-shadow: 0 10px 28px rgba(0,0,0,.55), 0 0 0 4px rgba(255,92,154,.18);
    cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  }
  #city-select:not(.hidden) #cs-geo-fab:active { transform: translateX(-50%) scale(.97); }
  /* bez geolokace (citymap nevykreslila .city-geo) nebo když už je tlačítko na mapě vidět → schovat */
  #city-select:not(:has(.city-geo)) #cs-geo-fab, #cs-geo-fab.cs-away { display: none !important; }
  #city-select .city-box { padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px)); }
  /* přímo na mapě: velké a zřetelné, chyby čitelně v rámečku */
  .cs-where .city-geo { width: min(100%, 360px); padding: 16px 20px; font-size: 19px; }
  .cs-where .cm-geo-status {
    font-size: 15px; line-height: 1.45; padding: 10px 12px; border-radius: 10px;
    background: rgba(8,12,18,.6); border: 1px solid rgba(120,170,255,.2); text-align: left;
  }
  .cs-where .cm-geo-status.err { color: #ffb3b3; background: rgba(90,14,24,.55); border-color: rgba(255,110,130,.5); }
  .cs-where .cm-geo-status.ok { border-color: rgba(93,255,158,.45); }
  .cs-where .cm-geo-status .cm-go { display: inline-block; margin-top: 8px; padding: 10px 14px; font-size: 15px; }
}
/* FPS · ping (DRI-89): vpravo nahoře jsou dotyková tlačítka → nahoře uprostřed pod stavem online */
body.touch #netstat { right: auto; left: 50%; transform: translateX(-50%); top: calc(40px + var(--sa-t)); font-size: 11px; }
body.touch.br-mode #netstat { top: calc(2px + var(--sa-t)); }

/* ==========================================================================
   MOBIL A TABLET (mobile.js: body.mob, .mob-phone / .mob-tablet) — stabilita a ovládání prstem
   ========================================================================== */
/* stránka se nesmí posouvat ani „gumovat" (iOS overscroll), tažení po hře není výběr textu ani zoom */
html:has(body.touch.playing), body.touch.playing { overflow: hidden; overscroll-behavior: none; }
body.touch.playing { position: fixed; inset: 0; width: 100%; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
body.touch #game { touch-action: none; }
body.touch #touch-controls .tc-btn, body.touch #touch-controls .tc-joy { touch-action: none; -webkit-tap-highlight-color: transparent; }
/* panely s vlastním posunem (výběrník, garáž, seznamy) se posouvat smí */
body.touch.playing .fr-box, body.touch.playing .esc-box, body.touch.playing #phone, body.touch.playing #mapview,
body.touch.playing #chat-log, body.touch.playing input, body.touch.playing textarea { touch-action: pan-y; -webkit-user-select: auto; user-select: auto; }
body.touch.playing #mapview { touch-action: none; }
/* iOS zoomuje stránku při fokusu pole s písmem < 16 px */
body.touch input, body.touch textarea, body.touch select { font-size: max(16px, 1em); }

/* ---- pěšky: střelba, skok, sprint, přebít — sloupec vlevo od joysticku ---- */
#touch-controls .tc-footbar { display: none; }
body.touch[data-tc-mode="foot"] #touch-controls .tc-footbar {
  display: flex; flex-direction: column; align-items: flex-end; gap: 10px;
  position: absolute;
  right: calc(var(--tc-pad) + var(--sa-r) + var(--tc-joy) + 12px);
  bottom: calc(var(--tc-pad) + var(--sa-b));
}
body.touch #touch-controls .tc-footbar .tc-round { position: static; width: 50px; height: 50px; font-size: 21px; }
body.touch #touch-controls .tc-footbar #tc-fire { width: 68px; height: 68px; font-size: 28px; background: rgba(214,60,60,.55); border-color: rgba(255,170,170,.7); }
body.touch #touch-controls .tc-footbar #tc-fire.active { background: rgba(240,80,80,.85); }
@media (max-height: 500px) {
  body.touch[data-tc-mode="foot"] #touch-controls .tc-footbar { flex-direction: row; align-items: flex-end; gap: 8px; }
  body.touch #touch-controls .tc-footbar .tc-round { width: 46px; height: 46px; }
  body.touch #touch-controls .tc-footbar #tc-fire { width: 60px; height: 60px; }
}
/* 🗺️ u minimapy: cíl pro prst ≥ 44 px */
body.touch #touch-controls #tc-map { width: 44px; height: 44px; }

/* ---- telefon na výšku: nabídka otočení (main.js rotateHint) ---- */
#rotate-hint {
  position: fixed; z-index: 70; left: 50%; transform: translateX(-50%);
  top: calc(96px + env(safe-area-inset-top, 0px));
  display: flex; align-items: center; gap: 6px; max-width: calc(100vw - 24px);
  padding: 6px 6px 6px 14px; border-radius: 999px;
  background: rgba(10,14,24,.82); color: #fff; font: 600 13px/1.2 system-ui, sans-serif;
  box-shadow: 0 0 0 1px rgba(120,170,255,.4), 0 6px 18px rgba(0,0,0,.45);
}
#rotate-hint.hidden { display: none; }
#rotate-hint button { width: 44px; height: 44px; margin: -6px -4px -6px 0; border: 0; border-radius: 50%; background: transparent; color: #cfd8e6; font-size: 16px; touch-action: manipulation; }

/* ---- ESC menu na úzkém displeji: řádky „− hodnota +" (hlasitosti, posun času) přes celou šířku — ve sloupci
   185 px přetékaly přes sousední tlačítko a „+" nebylo vidět ---- */
@media (max-width: 560px) {
  #esc-menu #esc-main .esc-vol, #esc-menu #esc-main .esc-time { grid-column: 1 / -1; }
}
#esc-menu .esc-vol, #esc-menu .esc-time { min-width: 0; }
#esc-menu .esc-vol .esc-btn, #esc-menu .esc-time .esc-btn { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
/* ---- výběrník: záložky vozidel (Auta … Raketa) se na úzkém displeji vejdou (dřív „Raketa" za okrajem) ---- */
@media (max-width: 560px) {
  .vt-tabs { gap: 2px; }
  .vt-tab { padding: 8px 2px; font-size: 12px; min-width: 0; min-height: 44px; overflow: hidden; text-overflow: ellipsis; }
  .color-swatch { min-width: 36px; min-height: 36px; }
}
/* ---- nastavení grafiky: přepínače pro prst (dřív 27 px vysoké) ---- */
body.touch .gfx-opt { min-height: 40px; min-width: 44px; }
body.touch #esc-menu .gfx-box { max-height: calc(100dvh - 12px); overflow-y: auto; -webkit-overflow-scrolling: touch; }
/* pěšky na výšku: sloupec tlačítek stojí mezi minimapou a joystickem → popisek polohy užší */
@media (min-height: 501px) { body.touch[data-tc-mode="foot"] #location-box { max-width: 138px; } }
body.touch .color-swatch { min-width: 36px; min-height: 36px; }
