/* Stage Kings: Handy und Tablet (Touch-Bedienung). Alles hier gilt nur, wenn die Oberfläche ein Touch-Gerät erkannt hat (#ui.touch,
   gesetzt in js/ui.js, Test-Parameter ?touch=1). Die Desktop-Darstellung bleibt davon unberührt.
   Inhalt: Gesten sperren · Touch-Knöpfe im Daumenbogen · Lenk-Hinweis und Knüppel · Dreh-Hinweis · HUD-Anordnung · Menüs mit Trefferflächen ≥ 48 px. */

/* ---------- Gesten: kein Markieren, kein Kontextmenü, kein Zoom, kein Pull-to-Refresh ---------- */
html, body { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; overscroll-behavior: none; }
#buehne { touch-action: none; -webkit-touch-callout: none; }
#ui { -webkit-touch-callout: none; }
.s-inhalt, .st-inhalt, .zp-bahnen, .zp-bahn, .b-text { touch-action: pan-y; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.textfeld, .namensfeld { -webkit-user-select: text; user-select: text; -webkit-touch-callout: default; }
#ui.touch button, #ui.touch .knopf, #ui.touch .schalter, #ui.touch .seg-knopf, #ui.touch .tab { touch-action: manipulation; }

/* Bildschirmhöhe ohne Adressleiste, wo es auf die Höhe ankommt */
@supports (height: 100dvh) {
  @media (max-aspect-ratio: 1/1) {
    .pause-bahn { height: 64dvh; }
    .zp-rang { height: 38dvh; }
    .werk-seite { grid-template-rows: 20dvh minmax(0, 1fr); }
  }
}

/* ============================================================================================
   Touch-Knöpfe: Daumenbogen rechts unten. Mittelpunkte (--x, --y) und Durchmesser (--d) in Einheiten --u (≈ 1 px am Handy, bis 1,3 px am Tablet),
   gemessen von der rechten unteren Ecke. GAS liegt in der Ecke, Bremse/Drift/Hüpfer im inneren Bogen, Turbo und die Luft-Knöpfe außen.
   ============================================================================================ */
#ui.touch .touch-knoepfe { --u: clamp(.9px, .27vmin, 1.3px); display: block; position: absolute; right: calc(var(--sicher-r) + 10px); bottom: calc(var(--sicher-u) + 10px); width: 0; height: 0; pointer-events: none; }
#ui.touch .tk {
  position: absolute; right: calc((var(--x) - var(--d) / 2) * var(--u)); bottom: calc((var(--y) - var(--d) / 2) * var(--u));
  width: calc(var(--d) * var(--u)); height: calc(var(--d) * var(--u));
  display: grid; place-items: center; align-content: center; gap: calc(3 * var(--u)); padding: 0;
  background: rgba(0, 0, 0, .3); color: #fff; border: 2px solid rgba(255, 255, 255, .88); border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .4), inset 0 0 0 1px rgba(0, 0, 0, .25);
  font: 700 max(10px, calc(10.5 * var(--u)))/1 var(--f-mono); letter-spacing: .04em; text-shadow: 0 0 3px rgba(0, 0, 0, .8);
  cursor: pointer; pointer-events: auto; touch-action: none; -webkit-tap-highlight-color: transparent;
  transition: background-color .05s, color .05s, transform .06s;
}
#ui.touch .tk::before { content: ''; position: absolute; inset: -5px; border-radius: 50%; }   /* etwas größere Trefferfläche */
#ui.touch .tk.druck, #ui.touch .tk:active { background: #fff; color: #000; border-color: #fff; text-shadow: none; transform: scale(.93); box-shadow: 0 0 0 2px rgba(0, 0, 0, .5), 0 0 14px rgba(194, 24, 63, .9); }
#ui.touch .tk-icon { display: block; width: calc(var(--d) * .34 * var(--u)); height: calc(var(--d) * .34 * var(--u)); max-width: 30px; max-height: 30px; }
#ui.touch .tk-icon svg { width: 100%; height: 100%; display: block; }
#ui.touch .tk .tk-text { display: block; }
#ui.touch .tk.rolle .tk-text { display: block; }
#ui.touch .tk.gas { --x: 52; --y: 52; --d: 92; font-size: max(12px, calc(14 * var(--u))); letter-spacing: .1em; border-width: 2.5px; background: rgba(109, 0, 26, .42); }
#ui.touch .tk.gas.druck { background: #fff; }
#ui.touch .tk.bremse { --x: 164; --y: 50; --d: 66; }
#ui.touch .tk.drift  { --x: 131; --y: 123; --d: 58; }
#ui.touch .tk.huepf  { --x: 50; --y: 152; --d: 70; }
#ui.touch .tk.turbo  { --x: 284; --y: 52; --d: 58; }
#ui.touch .tk.spezial { --x: 264; --y: 117; --d: 56; }
#ui.touch .tk.pose   { --x: 212; --y: 168; --d: 56; }
#ui.touch .tk.rolle-l { --x: 134; --y: 203; --d: 54; }
#ui.touch .tk.rolle-r { --x: 42; --y: 224; --d: 54; }

/* Hochformat: schmaler und höher (der linke Daumen braucht unten links Platz) */
@media (max-aspect-ratio: 1/1) {
  #ui.touch .tk.gas    { --x: 50; --y: 52; --d: 88; }
  #ui.touch .tk.bremse { --x: 146; --y: 40; --d: 64; }
  #ui.touch .tk.huepf  { --x: 50; --y: 152; --d: 68; }
  #ui.touch .tk.drift  { --x: 130; --y: 118; --d: 56; }
  #ui.touch .tk.turbo  { --x: 200; --y: 96; --d: 56; }
  #ui.touch .tk.spezial { --x: 130; --y: 192; --d: 54; }
  #ui.touch .tk.pose   { --x: 200; --y: 170; --d: 54; }
  #ui.touch .tk.rolle-r { --x: 50; --y: 240; --d: 54; }
  #ui.touch .tk.rolle-l { --x: 130; --y: 262; --d: 54; }
}

/* ---------- Lenken: blasser Ring links zeigt den Bereich; beim Berühren springt der Knüppel unter den Daumen ---------- */
#ui.touch .lenk-hinweis { display: block; position: absolute; left: calc(var(--sicher-l) + 20vw); bottom: calc(var(--sicher-u) + 24vh); width: 104px; height: 104px; color: #fff; opacity: .42; pointer-events: none; transition: opacity .2s; filter: drop-shadow(0 0 2px rgba(0, 0, 0, .6)); }
#ui.touch .lenk-hinweis svg { width: 100%; height: 100%; }
#ui.touch .lenk-hinweis.weg { opacity: 0; }
#ui.touch .lenk-knueppel { display: block; position: fixed; left: -60px; top: -60px; width: 120px; height: 120px; opacity: 0; pointer-events: none; color: #fff; will-change: transform; filter: drop-shadow(0 0 2px rgba(0, 0, 0, .6)); }
#ui.touch .lenk-knueppel.an { opacity: .8; }
.lk-ring, .lk-ring svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.lk-knauf { position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; margin: -23px 0 0 -23px; border-radius: 50%; background: rgba(255, 255, 255, .88); border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, .5), 0 0 12px rgba(194, 24, 63, .7); will-change: transform; }
@media (max-aspect-ratio: 1/1) {
  #ui.touch .lenk-hinweis { left: calc(var(--sicher-l) + 5vw); bottom: calc(var(--sicher-u) + 34vh); width: 96px; height: 96px; }
}

/* ---------- Dreh-Hinweis (Hochformat) und Kurz-Notiz ---------- */
#ui.touch .dreh-hinweis { display: flex; position: absolute; left: 0; right: 0; margin: 0 auto; top: calc(var(--sicher-o) + 30vh); width: min(88vw, 340px); min-height: 64px; align-items: center; gap: 14px; padding: 12px 14px 12px 18px; background: rgba(0, 0, 0, .9); color: #fff; border: 1px solid rgba(255, 255, 255, .7); border-left: 8px solid var(--burgund-hell); border-radius: 0; text-align: left; pointer-events: auto; cursor: pointer; text-shadow: none; animation: bahn-ein .3s ease-out both; }
#ui.touch .dreh-hinweis[hidden] { display: none; }
.dh-icon { flex: none; width: 34px; height: 34px; }
.dh-icon svg { width: 100%; height: 100%; }
.dh-text { flex: 1; display: flex; flex-direction: column; gap: 4px; font: 400 14px/1.3 var(--f-text); }
.dh-text b { font: 800 15px/1.2 var(--f-kopf); letter-spacing: .01em; }
.dh-zu { flex: none; display: grid; place-items: center; width: 32px; height: 32px; font: 400 26px/1 var(--f-text); opacity: .8; }
.h-notiz { position: absolute; left: 0; right: 0; margin: 0 auto; width: fit-content; top: calc(var(--sicher-o) + 22vh); max-width: min(90vw, 460px); margin: 0; padding: 10px 14px; background: rgba(0, 0, 0, .86); border-left: 4px solid var(--burgund-hell); font: 500 13px/1.35 var(--f-mono); letter-spacing: .04em; text-align: center; text-shadow: none; }
.h-notiz[hidden] { display: none; }

/* ---------- HUD auf Touch-Geräten ---------- */
#ui.touch .h-pause { width: 46px; height: 46px; left: calc(var(--sicher-l) + 12px); top: calc(var(--sicher-o) + 10px); }
#ui.touch .h-pause svg { width: 20px; height: 20px; }
#ui.touch .h-ku { top: calc(var(--sicher-o) + 64px); }
#ui.touch .h-stempel { left: calc(var(--sicher-l) + 70px); }
@media (min-aspect-ratio: 1/1) { #ui.touch .h-stempel { font-size: min(1.6vw, 3vh); } }
/* Zieltext: ui-hud.js setzt top neben das Bordkarten-Feld; auf Touch steht er fest (!important), siehe unten */
/* Bordkarte gedrückt halten = Roadbook */
#ui.touch .h-bord { pointer-events: auto; touch-action: none; padding: 6px; margin: -6px; }
/* Querformat: Tempo und Leisten links neben dem Knopfbogen, Balance-Bogen etwas höher, Bordkarte waagerecht unter den Punkten */
#ui.touch .h-ur { right: calc(var(--sicher-r) + 18px + 318 * clamp(.9px, .27vmin, 1.3px)); bottom: calc(var(--sicher-u) + 10px); width: auto; flex-direction: row; align-items: flex-end; gap: 12px; }
#ui.touch .h-linien { width: 96px; }
#ui.touch .h-linie { grid-template-columns: 4.6em minmax(0, 1fr); }
#ui.touch .h-powerups { order: -1; }
#ui.touch .h-bogen { left: 33vw; width: 28vw; bottom: calc(var(--sicher-u) + 13vh); }
#ui.touch .h-anpu { bottom: auto; top: 30vh; right: calc(var(--sicher-r) + 4vw); }
#ui.touch .h-pose { top: 26vh; }
@media (min-aspect-ratio: 1/1) {
  #ui.touch .h-bord { top: auto; bottom: auto; top: calc(var(--sicher-o) + 1.4vh + min(10.6vh, 7.2vw) + 58px); right: calc(var(--sicher-r) + 2.2vw); flex-direction: row-reverse; align-items: center; gap: 8px; }
  #ui.touch .h-bordleiste { flex-direction: row; gap: 3px; }
  #ui.touch .bf { width: 9px; height: 12px; min-height: 0; }
  #ui.touch .h-buchstaben { flex-direction: row; margin: 0; gap: 2px; }
  #ui.touch .bw b { font-size: 11px; }
  /* Zieltext, Power-up-Ansage und Pose links neben dem Knopfbogen, damit nichts unter den Knöpfen verschwindet */
  #ui.touch .h-zieltext { right: calc(var(--sicher-r) + 30px + 318 * clamp(.9px, .27vmin, 1.3px)); top: auto !important; bottom: calc(var(--sicher-u) + 30vh); max-width: 26vw; }
  #ui.touch .h-anpu { right: calc(var(--sicher-r) + 30px + 318 * clamp(.9px, .27vmin, 1.3px)); top: auto; bottom: calc(var(--sicher-u) + 46vh); max-width: 26vw; }
  #ui.touch .h-pose { right: calc(var(--sicher-r) + 30px + 318 * clamp(.9px, .27vmin, 1.3px)); top: 22vh; }
  #ui.touch .ergebnis-eintrag { flex-wrap: wrap; }
  #ui.touch .ergebnis-eintrag .namens-zeile { flex: 1 1 100%; }
  #ui.touch .ergebnis-eintrag .knopf { flex: 1 1 100%; }
  #ui.touch .ergebnis-knoepfe { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #ui.touch .ergebnis-knoepfe .knopf:last-child { grid-column: 1 / -1; }
  #ui.touch .ergebnis-knoepfe .knopf { font-size: .7rem; }
  #ui.touch .lenk-hinweis { bottom: calc(var(--sicher-u) + 30vh); }
}
@media (min-aspect-ratio: 1/1) and (max-height: 420px) {
  #ui.touch .h-ku { top: calc(var(--sicher-o) + 62px); }
  #ui.touch .h-links { bottom: calc(var(--sicher-u) + 2vh); }
}

/* Hochformat: oben eine saubere Zeile (Pause · Uhr | Punkte), Streckenlinie kürzer; Tempo rechts über dem Knopfbogen */
@media (max-aspect-ratio: 1/1) {
  .h-strecke { width: 30vw; --sw: 30vw; }
  .h-uhrblock { left: calc(var(--sicher-l) + 68px); }
  #ui.touch .h-ur { right: calc(var(--sicher-r) + 7vw); bottom: calc(var(--sicher-u) + 18px + 290 * clamp(.9px, .27vmin, 1.3px)); flex-direction: column; align-items: flex-end; width: 30vw; gap: .8vh; }
  #ui.touch .h-linien { width: 100%; }
  #ui.touch .h-powerups { order: 0; flex-direction: row; }
  #ui.touch .h-bord { top: 18vh; }
  #ui.touch .h-bogen { left: 22vw; width: 36vw; bottom: calc(var(--sicher-u) + 40vh); }
  #ui.touch .h-anpu { top: 34vh; right: calc(var(--sicher-r) + 9vw); }
  #ui.touch .h-pose.an { display: none; }   /* Hochformat: der Posenname steht schon in der Trickspalte, rechts ist kein Platz */
  #ui.touch .h-zieltext { top: 26vh !important; right: calc(var(--sicher-r) + 9vw); max-width: 44vw; }
  #ui.touch .h-mult { font-size: min(9vh, 17vw); }
  #ui.touch .h-topf { bottom: calc(var(--sicher-u) + 11.5vh); }
  #ui.touch .h-schalt { bottom: calc(var(--sicher-u) + 10vh); }
  #ui.touch .h-tricks { width: 36vw; bottom: calc(var(--sicher-u) + 16vh); }
  #ui.touch .h-stufe { top: 46vh; }
}

/* ============================================================================================
   Menüs auf Touch-Geräten: Trefferflächen ≥ 48 px, Bedientext ≥ 13 px, Abstand zwischen Knöpfen
   ============================================================================================ */
#ui.touch .knopf { min-height: 48px; font-size: .84rem; }
#ui.touch .knopf.gross { min-height: 56px; font-size: .95rem; }
#ui.touch .knopf.klein { min-height: 48px; font-size: .78rem; padding: .6em 1.1em; }
#ui.touch .knopf.zurueck { min-height: 48px; min-width: 48px; padding: .6em 1em; font-size: .8rem; }
#ui.touch .knopfzeile { gap: 10px; }
#ui.touch .schalter { min-height: 48px; font-size: .82rem; }
#ui.touch .schalter .sw { min-width: 4.8em; }
#ui.touch .seg { gap: .6em; flex-wrap: wrap; }
#ui.touch .seg-knopf { min-height: 48px; padding: .4em .7em; font-size: .84rem; }
#ui.touch .tabs { gap: .4em; flex-wrap: wrap; }
#ui.touch .tab { min-height: 48px; padding: .4em .6em; font-size: .84rem; }
#ui.touch .schieber { height: 48px; }
#ui.touch .schieber::-webkit-slider-thumb { width: 22px; height: 38px; margin-top: -18px; }
#ui.touch .schieber::-moz-range-thumb { width: 22px; height: 38px; }
#ui.touch .opt-name { font-size: .86rem; }
#ui.touch .opt-wert { font-size: .82rem; }
#ui.touch .opt-hilfe { font-size: .84rem; }
#ui.touch .abschnitt-titel, #ui.touch .st-ueber, #ui.touch .zp-kopf { font-size: .78rem; }
#ui.touch .meldung { font-size: .82rem; }
#ui.touch .textfeld, #ui.touch textarea.textfeld { font-size: 16px; }   /* unter 16 px zoomt iOS beim Antippen ins Feld */
#ui.touch .namensfeld { font-size: 18px; min-height: 48px; }
#ui.touch .tz-text { font-size: .88rem; }
#ui.touch .tz-text b { font-size: .78rem; }
#ui.touch .kappe { font-size: .76rem; }
#ui.touch .tz { grid-template-columns: minmax(6.5em, 9em) minmax(0, 1fr); }
#ui.touch .touch-gruppe { margin-bottom: 3vh; }
#ui.touch .steuer-seite .schritte { margin-top: 3vh; }
#ui.touch .textfeld { min-height: 48px; }
#ui.touch .bs-weiss { font-size: .58rem; letter-spacing: .06em; }

/* Hauptmenü: Halbbahnen (Optionen, Steuerung) mindestens 50 px; Fußzeile lesbar */
#ui.touch .bahn.halb { flex-basis: max(4.2vw, 50px); }
#ui.touch .bildstreifen { font-size: .62rem; }
@media (max-aspect-ratio: 1/1) {
  #ui.touch .bahn.halb { flex-basis: max(5.2vh, 52px); }
  #ui.touch .bahn.halb .b-titel { font-size: max(.9rem, min(3.6vw, 2.4vh)); }
  #ui.touch .b-angaben .ang { font-size: .66rem; }
  #ui.touch .tz-etappe { font-size: .72rem; }
  #ui.touch .b-text .starten { min-height: 58px; }
}

/* Startwahl: Blöcke nicht zusammenquetschen, sondern scrollen; STARTEN bleibt fest unten im Daumenbereich */
@media (max-aspect-ratio: 1/1) {
  .st-block { flex: none; }
  .st-inhalt { gap: 2.4vh; padding-bottom: 2.4vh; }
  .etappe { grid-template-columns: auto minmax(0, 1fr); padding: 1.4vh 4vw 1.6vh; min-height: 0; }
  .etappe .sperre { position: static; grid-column: 1 / -1; margin: .4vh -4vw -1.6vh; }
}
#ui.touch .st-fuss .knopf.gross { min-height: 60px; padding-bottom: calc(var(--sicher-u) * .6); }
#ui.touch .st-gold .seg-knopf, #ui.touch .st-gold button { min-height: 48px; }
#ui.touch .e-name { font-size: max(.82rem, min(1.2vw, 2.2vh)); }
#ui.touch .sperre { font-size: .7rem; }
#ui.touch .mess { font-size: .62rem; }
#ui.touch .bg-tricks { font-size: .64rem; }
#ui.touch .gold-hinweis { font-size: .66rem; }
#ui.touch .etappe, #ui.touch .buggy { min-height: 64px; }
@media (min-aspect-ratio: 1/1) and (max-height: 520px) {
  #ui.touch .e-name { font-size: .72rem; }
  #ui.touch .st-fuss .knopf.gross { min-height: 52px; }
  #ui.touch .st-kopf { padding: .6vh 3vw; }
}

/* Werkstatt: Buggy-Reiter groß genug, Lack-Karten antippbar */
#ui.touch .werk-auto { min-height: 52px; font-size: .78rem; }
#ui.touch .lack-karte { min-height: 60px; }
#ui.touch .lack-karte b { font-size: .8rem; }
#ui.touch .lack-karte span:not(.ico) { font-size: .66rem; }
#ui.touch .werk-auto { padding: .6em .5em; justify-content: center; }
#ui.touch .werk-auto b { display: none; }

/* Rangliste: Zeilen höher */
#ui.touch .tafel-zeile { min-height: 3.4em; }

/* Pause: große Knöpfe mit Abstand */
#ui.touch .pause-knoepfe .knopf { min-height: 54px; font-size: .9rem; }
#ui.touch .pause-klein { gap: 10px; }
#ui.touch .pause-klein .knopf { min-height: 50px; }
#ui.touch .pause-inhalt { padding-bottom: calc(var(--sicher-u) + 3vh); }

/* Zielprotokoll: Knöpfe ≥ 48 px mit Abstand; Namensfeld mit Bildschirmtastatur */
#ui.touch .ergebnis-knoepfe { gap: 10px; }
#ui.touch .ergebnis-knoepfe .knopf { min-height: 50px; font-size: .74rem; letter-spacing: .08em; }
#ui.touch .ergebnis-knoepfe .haupt { min-height: 58px; font-size: .92rem; }
#ui.touch .online-wahl { min-height: 48px; align-items: center; font-size: .86rem; }
#ui.touch .online-wahl .haken { width: 26px; height: 26px; }
#ui.touch .ergebnis-eintrag .knopf { min-height: 50px; }
#ui.touch .posten { font-size: .8rem; }
@media (max-aspect-ratio: 1/1) {
  #ui.touch .zp-bahn:last-child { padding-bottom: calc(var(--sicher-u) + 4vh); }
}
