/* HEATLINE — touch / phone layer (loaded after ui.css; owned by the mobile work, ui.css stays untouched).
   Active only with body.touch (main.js sets it on touch devices or ?touch=1). Owns #touch (on-screen controls),
   #touch-rotate (portrait overlay), #lan (desktop card with the LAN URL + QR) and the compact HUD / menu / garage layout
   for small landscape screens (phone ≈ 844×390 CSS px). Control sizes are custom properties on #touch; behaviour
   tunables live in src/ui/TouchControls.js (TOUCH_DEFAULTS ← CONFIG.touch). */
:root { --sat: env(safe-area-inset-top, 0px); --sar: env(safe-area-inset-right, 0px); --sab: env(safe-area-inset-bottom, 0px); --sal: env(safe-area-inset-left, 0px); }

/* ---------------------------------------------------------------- page: no scroll / zoom / callouts, viewport follows the toolbar */
body.touch { touch-action: manipulation; overscroll-behavior: none; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; }
body.touch #game, body.touch #hud, body.touch #touch { touch-action: none; }
@supports (height: 100dvh) { body.touch #game, body.touch #ui { height: 100dvh; } }
body.touch .panel-body, body.touch .summary-panel, body.touch .menu-left { touch-action: pan-y; -webkit-overflow-scrolling: touch; }
body.touch #debug { pointer-events: none; }
/* large tap targets; keyboard hints mean nothing on a phone */
body.touch .btn { min-height: 46px; padding: 10px 18px; }
body.touch .btn.small { min-height: 40px; padding: 8px 14px; }
body.touch .menu-item { min-height: 46px; }
body.touch .garage-arrow { width: 72px; height: 120px; }
body.touch select { min-height: 40px; font-size: 16px; }          /* 16px: iOS does not zoom into the control */
body.touch input[type="range"] { height: 36px; }
body.touch .check input { width: 22px; height: 22px; }
body.touch .btn kbd, body.touch .garage-hint, body.touch .menu-footer, body.touch .panel-head kbd { display: none; }

/* ---------------------------------------------------------------- #touch: control layer (between HUD z 10 and menu z 20) */
#touch { position: absolute; inset: 0; pointer-events: none; z-index: 15; display: none; font-family: var(--font);
  --tc-pad: 14px; --tc-btn: 92px; --tc-gas: 108px; --tc-small: 52px; --tc-gap: 10px; --tc-pad-w: 230px; }
body.touch #touch { display: block; }
#touch .hidden { display: none !important; }
.touch-drive { position: absolute; inset: 0; pointer-events: none; }
.tbtn, .tpad { pointer-events: auto; touch-action: none; cursor: pointer; -webkit-user-select: none; user-select: none; }
.tbtn { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; border-radius: 16px;
  background: rgba(8, 12, 22, 0.42); border: 1px solid rgba(255, 255, 255, 0.16); box-shadow: inset 0 1px 0 rgba(255,255,255,0.08), 0 6px 20px rgba(0,0,0,0.35);
  color: rgba(232, 238, 252, 0.88); font-family: var(--display); font-size: 13px; letter-spacing: 0.18em; text-transform: uppercase; line-height: 1;
  backdrop-filter: blur(6px); transition: background 0.08s, border-color 0.08s, transform 0.08s, box-shadow 0.08s; }
.tbtn small { font-family: var(--font); font-size: 8px; letter-spacing: 0.1em; color: var(--muted); text-transform: none; }
.tbtn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.tbtn.on { background: rgba(47, 227, 255, 0.28); border-color: rgba(47, 227, 255, 0.8); color: #fff; transform: scale(0.96); box-shadow: 0 0 24px rgba(47, 227, 255, 0.35); }
.tbtn.gas.on { background: rgba(74, 222, 128, 0.3); border-color: var(--green); box-shadow: 0 0 24px rgba(74, 222, 128, 0.35); }
.tbtn.brake.on { background: rgba(255, 77, 77, 0.3); border-color: var(--red); box-shadow: 0 0 24px rgba(255, 77, 77, 0.35); }
.tbtn.hand.on { background: rgba(255, 181, 46, 0.3); border-color: var(--amber); box-shadow: 0 0 24px rgba(255, 181, 46, 0.35); }

/* steering (bottom-left): two buttons or the drag pad */
.touch-steer { position: absolute; left: calc(var(--tc-pad) + var(--sal)); bottom: calc(var(--tc-pad) + var(--sab)); display: flex; gap: var(--tc-gap); align-items: flex-end; pointer-events: none; }
.touch-steer .tbtn { width: var(--tc-btn); height: var(--tc-btn); font-size: 30px; font-family: var(--font); }
.tpad { position: relative; width: var(--tc-pad-w); height: var(--tc-btn); border-radius: 16px; background: rgba(8, 12, 22, 0.42); border: 1px solid rgba(255,255,255,0.16); backdrop-filter: blur(6px); overflow: hidden; }
.tpad-track { position: absolute; left: 18px; right: 18px; top: 50%; height: 4px; margin-top: -2px; border-radius: 2px; background: rgba(255, 255, 255, 0.14); }
.tpad-track::before, .tpad-track::after { content: "◀"; position: absolute; top: 50%; transform: translateY(-50%); font-size: 13px; color: rgba(255, 255, 255, 0.35); left: -6px; }
.tpad-track::after { content: "▶"; left: auto; right: -6px; }
.tpad-knob { position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; border-radius: 50%; transform: translate(-50%, -50%);
  background: radial-gradient(circle at 35% 35%, rgba(255,255,255,0.4), rgba(47,227,255,0.35) 60%, rgba(47,227,255,0.15)); border: 1px solid rgba(47, 227, 255, 0.6); box-shadow: 0 0 16px rgba(47, 227, 255, 0.3); transition: transform 0.05s linear; }
.tpad.on .tpad-knob { box-shadow: 0 0 26px rgba(47, 227, 255, 0.65); border-color: var(--cyan); }
.tpad-lbl { position: absolute; bottom: 5px; left: 0; right: 0; text-align: center; font-family: var(--display); font-size: 9px; letter-spacing: 0.26em; color: var(--muted); text-transform: uppercase; pointer-events: none; }

/* pedals (bottom-right): [Rückblick] [Handbremse] / [Bremse] [Gas] */
.touch-pedals { position: absolute; right: calc(var(--tc-pad) + var(--sar)); bottom: calc(var(--tc-pad) + var(--sab)); display: grid;
  grid-template-columns: var(--tc-btn) var(--tc-gas); grid-template-rows: var(--tc-small) var(--tc-gas); gap: var(--tc-gap); align-items: end; pointer-events: none; }
.touch-pedals .tbtn.look { grid-column: 1; grid-row: 1; height: var(--tc-small); font-size: 9px; flex-direction: row; gap: 6px; }
.touch-pedals .tbtn.look svg { width: 18px; height: 18px; }
.touch-pedals .tbtn.hand { grid-column: 2; grid-row: 1; height: var(--tc-small); font-size: 10px; }
.touch-pedals .tbtn.horn { grid-column: 1; grid-row: 1; height: var(--tc-small); font-size: 10px; }
.touch-pedals .tbtn.brake { grid-column: 1; grid-row: 2; height: var(--tc-btn); }
.touch-pedals .tbtn.gas { grid-column: 2; grid-row: 2; height: var(--tc-gas); font-size: 17px; }

/* system bar (top): pause + fullscreen — sits left of the minimap while driving */
.touch-sys { position: absolute; top: calc(10px + var(--sat)); right: calc(10px + var(--sar)); display: flex; gap: 8px; pointer-events: none; }
.touch-sys .tbtn { width: 44px; height: 44px; border-radius: 12px; }
#touch.playing .touch-sys { right: calc(234px + var(--sar)); }

/* ---------------------------------------------------------------- HUD on touch devices (any size): nothing under the thumbs */
body.touch .hud-tl { left: calc(14px + var(--sal)); top: calc(12px + var(--sat)); }
body.touch .hud-tr { right: calc(14px + var(--sar)); top: calc(12px + var(--sat)); }
body.touch .hud-tc { top: calc(12px + var(--sat)); }
body.touch .hud-bl { left: calc(14px + var(--sal)); bottom: calc(var(--tc-pad) + var(--sab) + var(--tc-btn) + 12px); }
body.touch .hud-br { right: auto; left: 50%; transform: translateX(-50%); bottom: calc(8px + var(--sab)); flex-direction: row; align-items: flex-end; gap: 10px; }
body.touch .hud-center { bottom: calc(262px + var(--sab)); }
body.touch .pause-overlay { pointer-events: auto; }

/* ---------------------------------------------------------------- phone landscape (≈ 844×390): compact HUD, smaller controls */
@media (max-height: 520px) {
  body.touch #touch { --tc-pad: 10px; --tc-btn: 76px; --tc-gas: 92px; --tc-small: 44px; --tc-gap: 8px; --tc-pad-w: 200px; }
  body.touch .touch-steer .tbtn { font-size: 26px; }
  body.touch .touch-pedals .tbtn.gas { font-size: 14px; }
  body.touch .tbtn { font-size: 11px; letter-spacing: 0.14em; border-radius: 14px; }
  body.touch .tbtn small { font-size: 7px; }
  body.touch .touch-sys .tbtn { width: 40px; height: 40px; }
  body.touch #touch.playing .touch-sys { right: calc(118px + var(--sar)); }
  /* HUD: canvases carry inline sizes from HUDController._setupCanvas → !important */
  body.touch .hud-tl { left: calc(10px + var(--sal)); top: calc(8px + var(--sat)); gap: 4px; }
  body.touch .pill { font-size: 11px; letter-spacing: 0.2em; padding: 4px 10px 3px; }
  body.touch .heat { padding: 3px 8px; gap: 6px; }
  body.touch .heat-level { font-size: 18px; min-width: 30px; }
  body.touch .star { width: 14px; height: 14px; }
  body.touch .hud-map-label { display: none; }
  body.touch .hud-tr { right: calc(10px + var(--sar)); top: calc(8px + var(--sat)); }
  body.touch .minimap { width: 96px !important; height: 96px !important; border-width: 1px; }
  body.touch .hud-tc { top: calc(8px + var(--sat)); }
  body.touch .warn-banner { font-size: 13px; letter-spacing: 0.2em; padding: 5px 12px; }
  body.touch .warn-banner small { font-size: 9px; }
  body.touch .hud-bl { left: calc(10px + var(--sal)); top: calc(76px + var(--sat)); bottom: auto; gap: 12px; padding: 5px 10px; }
  body.touch .stat b { font-size: 16px; }
  body.touch .stat.score b { font-size: 18px; }
  body.touch .hud-bl .lbl { font-size: 8px; letter-spacing: 0.12em; }
  body.touch .score-pop { font-size: 13px; }
  body.touch .hud-br { bottom: calc(6px + var(--sab)); gap: 8px; }
  body.touch .gauge { width: 112px !important; height: 112px !important; }
  body.touch .dmg { width: 150px; padding: 4px 8px; gap: 6px; }
  body.touch .dmg .lbl { font-size: 8px; }
  body.touch .dmg b { font-size: 12px; min-width: 32px; }
  body.touch .dmg-bar { height: 6px; }
  body.touch .hud-center { bottom: calc(128px + var(--sab)); }
  body.touch .arrest { width: 90px !important; height: 90px !important; }
  body.touch #toasts { top: 58px; gap: 5px; }
  body.touch .toast { font-size: 12px; min-width: 160px; padding: 6px 10px; }
  /* pause / summary fit the height */
  body.touch .pause-box { padding: 16px 20px; gap: 8px; }
  body.touch .pause-box h2 { font-size: 24px; margin-bottom: 2px; }
  body.touch .pause-box .meta { margin-top: 0; }
  body.touch .summary-panel { padding: 14px 18px 14px; max-height: 96vh; }
  body.touch .sum-reason { font-size: 26px; }
  body.touch .sum-sub { margin: 4px 0 8px; }
  body.touch .sum-score { margin-bottom: 8px; }
  body.touch .sum-score b { font-size: 34px; }
  body.touch .sum-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 6px; }
  body.touch .sum-cell { padding: 6px 8px; }
  body.touch .sum-cell b { font-size: 17px; }
  body.touch .sum-coins { margin-bottom: 8px; padding: 8px 12px; }
  body.touch .sum-coins-head b { font-size: 26px; }
  body.touch .sum-actions { margin-top: 10px; }
  /* menu: 8 items + title in 390 px */
  body.touch .menu-left { padding: 12px 20px 12px calc(20px + var(--sal)); gap: 6px; justify-content: flex-start; overflow-y: auto; }
  body.touch .menu-title .t1 { font-size: 14px; }
  body.touch .menu-title .t2 { font-size: 36px; }
  body.touch .menu-tag { font-size: 10px; margin-top: -2px; }
  body.touch .menu-list { margin-top: 2px; gap: 0; }
  body.touch .menu-item { min-height: 36px; font-size: 15px; padding: 4px 14px 4px 22px; letter-spacing: 0.12em; }
  body.touch .menu-item.active { padding-left: 28px; }
  body.touch .menu-item .sub { display: none; }
  body.touch .menu-right { inset: 8px calc(8px + var(--sar)) 8px calc(8px + var(--sal)); }
  body.touch .panel-head { padding: 8px 14px; }
  body.touch .panel-head h2 { font-size: 16px; }
  body.touch .panel-body { padding: 10px 14px 14px; gap: 10px; }
  body.touch .settings-row { grid-template-columns: 120px 1fr 48px; gap: 8px; font-size: 13px; }
  /* garage: the card is anchored above the car by JS (inline transform) — shrink its contents instead of the card */
  body.touch .garage-top { top: calc(8px + var(--sat)); left: calc(14px + var(--sal)); }
  body.touch .garage-title { font-size: 20px; }
  body.touch .garage-sub { font-size: 9px; }
  body.touch .gcard { width: 230px; padding: 10px 12px; }
  body.touch .gcard-name { font-size: 18px; }
  body.touch .gcard-class { font-size: 9px; margin-top: 2px; }
  body.touch .gcard-sil { width: 150px; height: 62px; margin: 2px auto 0; }
  body.touch .gcard-nums { padding: 5px 0; }
  body.touch .gcard-nums b { font-size: 20px; }
  body.touch .gcard-nums span { font-size: 8px; margin-top: 2px; }
  body.touch .gcard-drive, body.touch .gcard-bars { display: none; }
  body.touch .gcard-lock { margin-top: 6px; padding: 5px 8px; font-size: 11px; }
  body.touch .garage-arrow { width: 56px; height: 96px; font-size: 40px; }
  body.touch .garage-bottom { padding: 8px calc(14px + var(--sar)) calc(8px + var(--sab)) calc(14px + var(--sal)); gap: 10px; }
  body.touch .garage-strip { display: none; }
  body.touch .garage-confirm-box { padding: 14px 16px 12px; }
}
/* tablets / narrow desktop windows with touch: minimap is 150 px (ui.css ≤ 900 px) */
@media (max-width: 900px) and (min-height: 521px) {
  body.touch #touch.playing .touch-sys { right: calc(184px + var(--sar)); }
}

/* ---------------------------------------------------------------- portrait: "bitte Gerät drehen" (CSS only; a tap tries fullscreen + lock) */
#touch-rotate { display: none; position: fixed; inset: 0; z-index: 70; flex-direction: column; align-items: center; justify-content: center; gap: 16px; text-align: center; padding: 24px;
  background: radial-gradient(900px 500px at 50% 40%, #16213a 0%, var(--bg) 70%); color: var(--text); }
@media (orientation: portrait) { body.touch #touch-rotate { display: flex; } }
#touch-rotate .rot-icon { width: 54px; height: 92px; border: 3px solid var(--cyan); border-radius: 12px; box-shadow: 0 0 30px rgba(47, 227, 255, 0.35), inset 0 0 18px rgba(47,227,255,0.12); animation: rotateHint 2.4s var(--ease) infinite; position: relative; }
#touch-rotate .rot-icon::after { content: ""; position: absolute; left: 50%; bottom: 6px; width: 14px; height: 3px; margin-left: -7px; border-radius: 2px; background: rgba(47, 227, 255, 0.6); }
@keyframes rotateHint { 0%, 15% { transform: rotate(0); } 50%, 80% { transform: rotate(-90deg); } 100% { transform: rotate(0); } }
#touch-rotate h2 { margin: 0; font-family: var(--display); font-size: 24px; letter-spacing: 0.22em; text-transform: uppercase; }
#touch-rotate p { margin: 0; color: var(--muted); font-size: 14px; letter-spacing: 0.08em; max-width: 320px; line-height: 1.5; }
@media (prefers-reduced-motion: reduce) { #touch-rotate .rot-icon { animation: none; transform: rotate(-90deg); } }

/* ---------------------------------------------------------------- #lan: desktop card "Am Handy spielen" (main.js, data from /__heatline/lan) */
#lan { position: absolute; right: 16px; bottom: 16px; z-index: 25; display: flex; gap: 12px; align-items: center; padding: 10px 30px 10px 12px; max-width: 380px;
  background: var(--glass-strong); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 16px 50px rgba(0,0,0,0.5); font-size: 12px; color: var(--muted); animation: riseIn 0.3s var(--ease); }
#lan svg { width: 96px; height: 96px; flex: none; border-radius: 6px; }
#lan .lan-title { font-family: var(--display); font-size: 12px; letter-spacing: 0.22em; text-transform: uppercase; color: var(--amber); }
#lan .lan-url { font-family: ui-monospace, Consolas, "Courier New", monospace; font-size: 15px; color: #fff; margin: 3px 0; word-break: break-all; user-select: all; -webkit-user-select: all; }
#lan .lan-alt { font-family: ui-monospace, Consolas, monospace; font-size: 11px; opacity: 0.75; margin-bottom: 3px; word-break: break-all; }
#lan .lan-note { font-size: 10.5px; line-height: 1.4; }
#lan .lan-close { position: absolute; top: 2px; right: 6px; background: none; border: 0; color: var(--muted); font-size: 18px; cursor: pointer; padding: 2px 6px; }
#lan .lan-close:hover { color: #fff; }
body.touch #lan { display: none; }

/* ---------------------------------------------------------------- very short landscape screens (≤ 400 px: iPhone 375, 740×360 emulation): the 8-item menu fits without scrolling */
@media (max-height: 400px) {
  body.touch .menu-left { padding-top: 6px; padding-bottom: 6px; gap: 2px; }
  body.touch .menu-title .t1 { font-size: 12px; }
  body.touch .menu-title .t2 { font-size: 30px; line-height: 1; }
  body.touch .menu-tag { display: none; }
  body.touch .menu-item { min-height: 30px; font-size: 14px; padding-top: 2px; padding-bottom: 2px; }
  body.touch .garage-top { top: calc(6px + var(--sat)); }
  body.touch .garage-coins { padding: 5px 12px 5px 9px; }
  body.touch .garage-coins b { font-size: 19px; }
  body.touch .garage-coins .unit { font-size: 10px; }
  body.touch .garage-coins-sub { font-size: 9px; }
}
