/* ═══════════════════════════════════════════════════════════════════════
   DREV — touch driving layout (js/touch-joystick.js)
   Console-shooter style: floating stick on the left half, action arc on
   the right, one compact speed readout at the top. While a vehicle is
   active on a touch screen nothing else is drawn over the road.
   Portrait and landscape each get their own placement; safe-area aware.
   ═══════════════════════════════════════════════════════════════════════ */
#drive-touch, #drive-hud { display: none; }

@media (pointer: coarse), (hover: none) {
  body.vehicle-session-active:not(.drawer-open):not(.drev-assist-app-open) #drive-touch { display: block; }
  body.vehicle-session-active:not(.drawer-open):not(.drev-assist-app-open):not(.drev-cockpit-view) #drive-hud { display: flex; }

  /* ── Declutter: the drive view owns the screen ─────────────────────── */
  body.vehicle-session-active #nav-bar,
  body.vehicle-session-active #fleet-rail,
  body.vehicle-session-active #weather-chip,
  body.vehicle-session-active #ops-panel,
  body.vehicle-session-active #asset-console,
  body.vehicle-session-active #veh-card,
  body.vehicle-session-active #mode-badge,
  body.vehicle-session-active #cam-strip,
  body.vehicle-session-active #ctrl-hint,
  body.vehicle-session-active #business-return,
  body.vehicle-session-active #drev-fab,
  body.vehicle-session-active #drev-fab-menu,
  body.vehicle-session-active #drev-assist-fab,
  body.vehicle-session-active #cascade-fab,
  body.vehicle-session-active #touch-controls,
  body.vehicle-session-active #station-popup,
  body.vehicle-session-active .mapboxgl-ctrl-top-right,
  body.vehicle-session-active .mapboxgl-ctrl-bottom-right .mapboxgl-ctrl-group { display: none !important; }

  #drive-touch {
    position: fixed; inset: 0; z-index: 640;
    pointer-events: none;
    -webkit-user-select: none; user-select: none;
    -webkit-touch-callout: none;
    font-family: var(--font-data, 'Inter', system-ui, sans-serif);
  }

  /* ── Zones ─────────────────────────────────────────────────────────── */
  .dt-zone { position: absolute; pointer-events: auto; touch-action: none; }
  .dt-zone-move { left: 0; bottom: 0; width: 52%; height: 60%; }
  .dt-actions { position: absolute; inset: 0; pointer-events: none; }
  .dt-zone-lift { display: none; right: 0; bottom: 0; width: 48%; height: 46%; }
  body[data-drive-cls="vtol"] .dt-zone-lift { display: block; }

  /* ── Sticks ────────────────────────────────────────────────────────── */
  .dt-stick {
    --size: clamp(104px, 30vw, 132px);
    position: absolute;
    width: var(--size); height: var(--size);
    transform: translate(-50%, -50%);
    pointer-events: none;
    opacity: .5;
    transition: opacity .15s ease;
  }
  .dt-stick[data-stick="move"] {
    left: var(--sx, calc(env(safe-area-inset-left) + 22px + var(--size) / 2));
    top: var(--sy, calc(100% - env(safe-area-inset-bottom) - 30px - var(--size) / 2));
  }
  .dt-stick[data-stick="lift"] {
    left: calc(100% - env(safe-area-inset-right) - 22px - var(--size) / 2);
    top: calc(100% - env(safe-area-inset-bottom) - 30px - var(--size) / 2);
    opacity: .7;
  }
  .dt-stick.engaged { opacity: 1; transition: none; }
  .dt-ring {
    position: absolute; inset: 0; border-radius: 50%;
    border: 2px solid rgba(160, 230, 255, .55);
    background: radial-gradient(circle, rgba(10, 30, 46, .38), rgba(3, 10, 20, .22) 70%);
    box-shadow: inset 0 0 18px rgba(64, 194, 230, .14);
  }
  .dt-stick[data-stick="lift"] .dt-ring { border-color: rgba(130, 235, 170, .6); }
  .dt-knob {
    position: absolute; left: 50%; top: 50%;
    width: 44%; height: 44%; border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, rgba(225, 248, 255, .95), rgba(80, 170, 210, .9) 70%);
    box-shadow: 0 2px 10px rgba(0, 0, 0, .45);
    transform: translate(calc(-50% + var(--kx, 0px)), calc(-50% + var(--ky, 0px)));
  }
  .dt-label {
    position: absolute; left: 50%; top: calc(100% + 4px); transform: translateX(-50%);
    font-size: 10px; font-weight: 800; letter-spacing: 1.4px; white-space: nowrap;
    color: rgba(230, 246, 255, .8); text-shadow: 0 1px 4px #000;
  }
  .dt-stick.engaged .dt-label { opacity: 0; }

  /* ── Action buttons (thumb arc, bottom-right) ──────────────────────── */
  #drive-touch .dt-btn {
    position: absolute; pointer-events: auto; touch-action: none;
    display: grid; place-items: center;
    border-radius: 50%; min-height: 0; max-height: none; padding: 0; margin: 0;
    border: 2px solid rgba(190, 236, 255, .55);
    background: rgba(6, 20, 34, .55);
    color: #eaf8ff; font: 800 11px/1 inherit; letter-spacing: 1px;
    -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
    -webkit-tap-highlight-color: transparent;
  }
  #drive-touch .dt-btn.active { background: rgba(80, 200, 255, .55); border-color: #c9f3ff; }
  #drive-touch .dt-boost {
    width: 78px; height: 78px;
    right: calc(env(safe-area-inset-right) + 20px);
    bottom: calc(env(safe-area-inset-bottom) + 34px);
    border-color: rgba(255, 196, 92, .8); color: #ffe2a8; font-size: 12px;
  }
  #drive-touch .dt-boost.active { background: rgba(255, 170, 40, .55); }
  #drive-touch .dt-brake {
    width: 62px; height: 62px;
    right: calc(env(safe-area-inset-right) + 112px);
    bottom: calc(env(safe-area-inset-bottom) + 24px);
    border-color: rgba(255, 120, 120, .75); color: #ffd2d2;
  }
  #drive-touch .dt-brake.active { background: rgba(230, 60, 60, .55); }
  #drive-touch .dt-cam {
    width: 64px; height: 44px; border-radius: 22px;
    top: calc(env(safe-area-inset-top) + 10px);
    right: calc(env(safe-area-inset-right) + 84px);
  }
  #drive-touch .dt-exit {
    width: auto; min-width: 64px; height: 44px; padding: 0 14px; border-radius: 22px;
    top: calc(env(safe-area-inset-top) + 10px);
    right: calc(env(safe-area-inset-right) + 10px);
    border-color: rgba(255, 140, 140, .6); color: #ffd6d6;
  }

  /* Aircraft: LIFT/YAW stick takes the bottom-right; BOOST + CAM stack above. */
  body[data-drive-cls="vtol"] #drive-touch .dt-brake,
  body[data-drive-cls="spacecraft"] #drive-touch .dt-brake { display: none; }
  body[data-drive-cls="vtol"] #drive-touch .dt-boost {
    width: 60px; height: 60px;
    bottom: calc(env(safe-area-inset-bottom) + 30px + clamp(104px, 30vw, 132px) + 30px);
    right: calc(env(safe-area-inset-right) + 20px);
  }

  /* ── Compact readout (replaces the desktop instrument console) ─────── */
  #drive-hud {
    position: fixed; z-index: 641;
    top: calc(env(safe-area-inset-top) + 10px);
    left: calc(env(safe-area-inset-left) + 10px);
    max-width: calc(100% - 172px - env(safe-area-inset-left) - env(safe-area-inset-right));
    align-items: center; gap: 8px;
    padding: 6px 12px; border-radius: 14px;
    background: rgba(3, 12, 22, .62);
    border: 1px solid rgba(150, 220, 255, .22);
    -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
    color: #eaf8ff; pointer-events: none;
    font-family: var(--font-data, 'Inter', system-ui, sans-serif);
  }
  .dh-name { display: none; font-size: 11px; font-weight: 700; letter-spacing: .6px; color: rgba(220, 240, 250, .8); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 30vw; }
  .dh-speed { display: flex; align-items: baseline; gap: 4px; }
  .dh-speed b { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; min-width: 2ch; text-align: right; }
  .dh-speed small { font-size: 10px; font-weight: 800; letter-spacing: 1px; color: #8fe3ff; }
  .dh-chip { font-size: 11px; font-weight: 700; letter-spacing: .5px; color: rgba(225, 242, 250, .85); white-space: nowrap; }
  .dh-chip:empty { display: none; }

  /* ── Landscape phones ──────────────────────────────────────────────── */
  @media (orientation: landscape) and (max-height: 520px) {
    .dt-stick { --size: clamp(100px, 30vh, 124px); }
    .dt-zone-move { width: 44%; height: calc(100% - 64px); }
    .dt-zone-lift { width: 40%; height: calc(100% - 64px); }
    #drive-touch .dt-boost { width: 72px; height: 72px; bottom: calc(env(safe-area-inset-bottom) + 22px); right: calc(env(safe-area-inset-right) + 24px); }
    #drive-touch .dt-brake { width: 58px; height: 58px; right: calc(env(safe-area-inset-right) + 110px); bottom: calc(env(safe-area-inset-bottom) + 16px); }
    .dt-stick[data-stick="move"] { top: var(--sy, calc(100% - env(safe-area-inset-bottom) - 22px - var(--size) / 2)); }
    .dt-stick[data-stick="lift"] { top: calc(100% - env(safe-area-inset-bottom) - 22px - var(--size) / 2); }
    body[data-drive-cls="vtol"] #drive-touch .dt-boost { width: 52px; height: 52px; right: calc(env(safe-area-inset-right) + 30px + clamp(100px, 30vh, 124px)); bottom: calc(env(safe-area-inset-bottom) + 22px); }
      #drive-hud { left: 50%; transform: translateX(-50%); max-width: calc(100% - 360px); }
    .dh-name { display: inline; }
  }

  /* Seated view: the instrument panel is the readout; keep thumbs' ghosts faint. */
  body.drev-cockpit-view .dt-stick:not(.engaged) { opacity: .32; }
  body.drev-cockpit-view #drive-touch .dt-btn:not(.active) { background: rgba(6, 20, 34, .35); }

  @media (prefers-reduced-motion: reduce) { .dt-stick { transition: none; } }
}

/* ── Desktop / mouse: same clean drive view, keyboard drives ─────── */
body.drive-desktop.vehicle-session-active:not(.drawer-open):not(.drev-assist-app-open) #drive-touch { display: block; }
body.drive-desktop.vehicle-session-active:not(.drawer-open):not(.drev-assist-app-open):not(.drev-cockpit-view) #drive-hud { display: flex; }
body.drive-desktop #drive-touch { position: fixed; inset: 0; z-index: 640; pointer-events: none; font-family: var(--font-data, 'Inter', system-ui, sans-serif); }
body.drive-desktop #drive-touch .dt-zone,
body.drive-desktop #drive-touch .dt-boost,
body.drive-desktop #drive-touch .dt-brake { display: none !important; }
body.drive-desktop #drive-touch .dt-btn {
  position: absolute; pointer-events: auto; display: grid; place-items: center;
  height: 44px; min-width: 72px; padding: 0 16px; border-radius: 22px; cursor: pointer;
  border: 2px solid rgba(190, 236, 255, .55); background: rgba(6, 20, 34, .6); color: #eaf8ff;
  font: 800 12px/1 inherit; letter-spacing: 1px; top: 14px;
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
body.drive-desktop #drive-touch .dt-btn:hover { background: rgba(40, 90, 120, .7); }
body.drive-desktop #drive-touch .dt-exit { right: 14px; border-color: rgba(255, 140, 140, .6); color: #ffd6d6; }
body.drive-desktop #drive-touch .dt-cam { right: 100px; }
body.drive-desktop #drive-hud {
  position: fixed; z-index: 641; top: 14px; left: 50%; transform: translateX(-50%);
  align-items: center; gap: 10px; padding: 8px 16px; border-radius: 14px;
  background: rgba(3, 12, 22, .62); border: 1px solid rgba(150, 220, 255, .22);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); color: #eaf8ff; pointer-events: none;
  font-family: var(--font-data, 'Inter', system-ui, sans-serif);
}
body.drive-desktop .dh-name { display: inline; font-size: 12px; font-weight: 700; color: rgba(220, 240, 250, .8); }
body.drive-desktop .dh-speed { display: flex; align-items: baseline; gap: 4px; }
body.drive-desktop .dh-speed b { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
body.drive-desktop .dh-speed small { font-size: 10px; font-weight: 800; letter-spacing: 1px; color: #8fe3ff; }
body.drive-desktop .dh-chip { font-size: 12px; font-weight: 700; color: rgba(225, 242, 250, .85); }
/* the flat console card, camera bar, nav and side panels give way to the cockpit */
body.drive-desktop.vehicle-session-active #asset-console,
body.drive-desktop.vehicle-session-active #veh-card,
body.drive-desktop.vehicle-session-active #cam-strip,
body.drive-desktop.vehicle-session-active #spawn-btn,
body.drive-desktop.vehicle-session-active #nav-bar,
body.drive-desktop.vehicle-session-active #mode-badge,
body.drive-desktop.vehicle-session-active #fleet-rail,
body.drive-desktop.vehicle-session-active #weather-chip,
body.drive-desktop.vehicle-session-active #business-return,
body.drive-desktop.vehicle-session-active #drev-fab,
body.drive-desktop.vehicle-session-active #drev-assist-fab,
body.drive-desktop.vehicle-session-active #station-popup { display: none !important; }
/* mission panel stays (it is the objective) but tucks under the top bar */
body.drive-desktop.vehicle-session-active #ops-panel { top: 70px !important; }
body.drive-desktop.vehicle-session-active #ops-abort { min-height: 30px; min-width: 64px; }
/* key hint shows for 5 s at the bottom centre, above nothing else */
body.drive-desktop.vehicle-session-active #ctrl-hint { bottom: 18px !important; }
/* mission panel above the cockpit frame so its ABORT stays reachable */
body.drive-desktop.vehicle-session-active #ops-panel { z-index: 620 !important; right: 14px !important; }
