/* T-78: on-screen race controls for phones / tablets (web/touch.js).
   Landscape-first, thumb zones at the bottom corners, safe-area aware, never scrolls/zooms/selects.
   Sizes are in vmin (= the screen height in landscape) so they scale with the device; the small
   corner buttons keep a 44 px minimum touch target. */

html.tc-on, html.tc-on body {
  touch-action: none; overscroll-behavior: none; -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
}
#tc {
  position: fixed; inset: 0; z-index: 5; pointer-events: none; display: none;
  --a: 0.55;            /* control opacity (settings) */
  --sl: env(safe-area-inset-left, 0px); --sr: env(safe-area-inset-right, 0px);
  --sb: env(safe-area-inset-bottom, 0px); --st: env(safe-area-inset-top, 0px);
  font: 700 3.2vmin/1 system-ui, -apple-system, "Segoe UI", sans-serif; color: #fff;
  -webkit-user-select: none; user-select: none; touch-action: none;
}
#tc.show { display: block; }
#tc [data-ctl], #tc .tc-small, #tc-set, #tc-tilt { pointer-events: auto; touch-action: none; }

.tc-btn {
  position: absolute; box-sizing: border-box; display: flex; align-items: center; justify-content: center;
  border-radius: 3vmin; border: 0.45vmin solid rgba(255, 255, 255, 0.55);
  background: rgba(20, 24, 30, 0.38); opacity: var(--a); letter-spacing: 0.05em;
  text-shadow: 0 0 0.6vmin #000; transition: transform 60ms, background 60ms, opacity 120ms;
}
.tc-btn.on { background: rgba(202, 244, 138, 0.55); border-color: #caf48a; transform: scale(0.94); opacity: 1; color: #111; text-shadow: none; }
.tc-btn.hide, #tc .hide { display: none !important; }
.tc-btn small { display: block; font-size: 2.2vmin; font-weight: 600; opacity: 0.8; }

/* Left thumb: steering (buttons mode). */
#tc-left  { left: calc(var(--sl) + 3vmin);  bottom: calc(var(--sb) + 3vmin); width: 26vmin; height: 26vmin; font-size: 8vmin; border-radius: 50%; }
#tc-right { left: calc(var(--sl) + 32vmin); bottom: calc(var(--sb) + 3vmin); width: 26vmin; height: 26vmin; font-size: 8vmin; border-radius: 50%; }
/* Slide mode: a floating stick anywhere in the left 42% of the screen. */
#tc-slide {
  left: 0; bottom: 0; width: 42vw; height: 72vh; border: 0; border-radius: 0; background: transparent;
  align-items: flex-end; justify-content: flex-start; padding: 0 0 calc(var(--sb) + 3vmin) calc(var(--sl) + 4vmin);
  font-size: 2.6vmin; color: rgba(255, 255, 255, 0.7);
}
#tc-slide.on { background: transparent; transform: none; color: transparent; }
#tc-knob, #tc-base {
  position: absolute; display: none; pointer-events: none; border-radius: 50%; transform: translate(-50%, -50%);
}
#tc-base { width: 30vmin; height: 12vmin; border-radius: 6vmin; border: 0.4vmin solid rgba(255, 255, 255, 0.5); background: rgba(0, 0, 0, 0.25); }
#tc-knob { width: 11vmin; height: 11vmin; background: rgba(202, 244, 138, 0.75); border: 0.4vmin solid #fff; }
/* Tilt mode: the left thumb brakes. */
#tc-lbrake { left: calc(var(--sl) + 3vmin); bottom: calc(var(--sb) + 3vmin); width: 30vmin; height: 26vmin; }

/* Right thumb: pedals, nitro, handbrake, gears. */
#tc-gas    { right: calc(var(--sr) + 3vmin);  bottom: calc(var(--sb) + 3vmin);  width: 21vmin; height: 37vmin; font-size: 4.2vmin; }
#tc-brake  { right: calc(var(--sr) + 27vmin); bottom: calc(var(--sb) + 3vmin);  width: 18vmin; height: 20vmin; }
#tc-ebrake { right: calc(var(--sr) + 27vmin); bottom: calc(var(--sb) + 26vmin); width: 18vmin; height: 14vmin; font-size: 2.6vmin; }
#tc-nos    { right: calc(var(--sr) + 3vmin);  bottom: calc(var(--sb) + 43vmin); width: 21vmin; height: 15vmin; border-radius: 7.5vmin; border-color: rgba(120, 200, 255, 0.8); }
/* T-105: thumb slid up off the gas = nitro. */
#tc-gas.nos { background: rgba(120, 200, 255, 0.6); border-color: #9fd8ff; }
#tc-gas small { font-size: 2vmin; margin-top: 0.8vmin; }
#tc-gas { flex-direction: column; }
#tc-nos.on { background: rgba(120, 200, 255, 0.6); border-color: #9fd8ff; }
#tc-up     { right: calc(var(--sr) + 48vmin); bottom: calc(var(--sb) + 20vmin); width: 14vmin; height: 14vmin; font-size: 4vmin; }
#tc-down   { right: calc(var(--sr) + 48vmin); bottom: calc(var(--sb) + 3vmin);  width: 14vmin; height: 14vmin; font-size: 4vmin; }
/* Drag race: big shift where the brakes were, lanes on the left. */
#tc.drag #tc-up { right: calc(var(--sr) + 27vmin); bottom: calc(var(--sb) + 3vmin); width: 20vmin; height: 37vmin; font-size: 4.2vmin; }
#tc.drag #tc-down { right: calc(var(--sr) + 50vmin); bottom: calc(var(--sb) + 3vmin); }

/* Pause / camera / settings: a row centred at the top (T-105; the race HUD's position / laps /
   times fill the top corners). */
.tc-small {
  position: absolute; box-sizing: border-box; min-width: 44px; min-height: 44px; width: 9vmin; height: 9vmin;
  display: flex; align-items: center; justify-content: center; border-radius: 1.8vmin;
  background: rgba(20, 24, 30, 0.45); border: 2px solid rgba(255, 255, 255, 0.45); opacity: var(--a);
  font-size: max(13px, 2.6vmin);
}
.tc-small.on { background: rgba(202, 244, 138, 0.6); color: #111; opacity: 1; }
#tc-pause, #tc-cam, #tc-gear { top: calc(var(--st) + 2vmin); }
#tc-cam   { left: calc(50% + (var(--sl) - var(--sr)) / 2 - max(44px, 9vmin) / 2); }
#tc-pause { left: calc(50% + (var(--sl) - var(--sr)) / 2 - max(44px, 9vmin) * 1.5 - 2vmin); }
#tc-gear  { left: calc(50% + (var(--sl) - var(--sr)) / 2 + max(44px, 9vmin) / 2 + 2vmin); }
.tc-small svg { width: 55%; height: 55%; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

/* Tilt meter (tilt mode). */
#tc-tilt { position: absolute; left: 50%; top: calc(var(--st) + 4vmin + max(44px, 9vmin)); width: 30vmin; height: 1.6vmin; transform: translateX(-50%);
  border-radius: 1vmin; background: rgba(0, 0, 0, 0.35); border: 1px solid rgba(255, 255, 255, 0.4); pointer-events: none; opacity: var(--a); }
#tc-tilt i { position: absolute; top: -0.6vmin; width: 1.2vmin; height: 2.8vmin; margin-left: -0.6vmin; left: 50%; background: #caf48a; border-radius: 0.5vmin; }

/* Settings panel. */
#tc-set {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); display: none;
  width: min(92vw, 560px); max-height: 92vh; overflow: auto; box-sizing: border-box; padding: 14px 18px;
  background: rgba(12, 14, 18, 0.94); border: 1px solid rgba(255, 255, 255, 0.25); border-radius: 12px;
  font: 500 15px/1.35 system-ui, -apple-system, "Segoe UI", sans-serif; color: #ddd; touch-action: pan-y;
}
#tc-set.open { display: block; }
#tc-set h3 { margin: 0 0 8px; font-size: 17px; color: #fff; }
#tc-set .row { display: flex; align-items: center; gap: 10px; margin: 9px 0; flex-wrap: wrap; }
#tc-set .row > span { min-width: 120px; }
#tc-set button {
  font: 600 14px system-ui, sans-serif; min-height: 40px; padding: 6px 14px; border-radius: 8px;
  background: #2a2f37; color: #eee; border: 1px solid #444;
}
#tc-set button.sel { background: #caf48a; color: #111; border-color: #caf48a; }
#tc-set input[type=range] { flex: 1; min-width: 140px; }
#tc-set .note { font-size: 12px; color: #8b949e; }

/* Portrait: ask for landscape (racing needs both thumbs). */
#tc-rotate {
  position: fixed; inset: 0; z-index: 20; display: none; flex-direction: column; gap: 12px; align-items: center;
  justify-content: center; background: rgba(0, 0, 0, 0.9); color: #ddd; text-align: center; padding: 2rem;
  font: 600 18px system-ui, -apple-system, sans-serif;
}
#tc-rotate svg { width: 64px; height: 64px; fill: none; stroke: #caf48a; stroke-width: 1.8; }
@media (orientation: portrait) {
  html.tc-on.tc-game #tc-rotate { display: flex; }
}
