/* mobile-touch.css — map touch controls on phones (see js/mobile-touch.js).
   The phone layout is (max-width: 640px), (pointer: coarse) and
   (orientation: portrait) and (max-width: 1100px), i.e. phones and portrait
   touch tablets; the same list is in mobile-map.css, mobile-sheet.css and
   the mobile-*.js files. The crosshair is also on touch-only screens of
   any size ((pointer: coarse) and (hover: none)), so landscape touch
   tablets get it in the desktop layout (no html.mmap-on; placed at the end
   of this file). Mouse desktops never see it. The crosshair parts show
   only while the mode is on (html.mtouch-xhair). Map buttons stay at z-index <= 20, under the
   sheet (30-40), menus (50) and toasts. */

#cv-ui { touch-action: none; }          /* #map-wrap has it too: no page zoom/scroll on the map */

.mtouch-fab, .mtouch-cross, .mtouch-coords, .mtouch-bar { display: none; }

:root { --mtouch-go: var(--accent2); --mtouch-go-fg: #ffffff; --mtouch-mark: var(--danger); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --mtouch-go-fg: #04211c; } }
:root[data-theme="dark"] { --mtouch-go-fg: #04211c; }

/* phone layout, plus touch-only screens (the look of the crosshair, label
   and bar; the desktop-layout placement is at the end of this file) */
@media (max-width: 640px), (pointer: coarse) and (orientation: portrait) and (max-width: 1100px), (pointer: coarse) and (orientation: landscape) and (max-height: 500px), (max-width: 950px) and (orientation: landscape) and (max-height: 500px), (pointer: coarse) and (hover: none) {
  /* round button under the Layers button (#right sits 58 px down, 46 px tall) */
  .mmap-on .mtouch-fab {
    display: grid; position: absolute; z-index: 20; top: 114px;
    right: max(12px, env(safe-area-inset-right, 0px)); width: 46px; height: 46px;
  }
  /* while the 3D panel is open (it starts at 114 px), sit beside Layers */
  .mmap-on:has(#v3d:not([hidden])) .mtouch-fab { top: 58px; right: calc(max(12px, env(safe-area-inset-right, 0px)) + 54px); }
  .mmap-on .mtouch-fab[aria-pressed="true"] { background: var(--mtouch-go); color: var(--mtouch-go-fg); border-color: var(--mtouch-go); }
  .mmap-on .mtouch-fab:active { transform: scale(.96); }

  /* fixed crosshair; left/top set by the script (the free map area's centre) */
  .mtouch-xhair .mtouch-cross {
    display: block; position: absolute; z-index: 15; width: 64px; height: 64px;
    transform: translate(-50%, -50%); pointer-events: none;
    filter: drop-shadow(0 0 1.5px color-mix(in srgb, var(--surface2, #fff) 90%, transparent));
  }
  .mtouch-cross::before, .mtouch-cross::after { content: ""; position: absolute; background: var(--mtouch-mark); }
  .mtouch-cross::before { left: 31px; top: 0; width: 2px; height: 64px; }
  .mtouch-cross::after { top: 31px; left: 0; height: 2px; width: 64px; }
  .mtouch-cross i {
    position: absolute; left: 23px; top: 23px; width: 18px; height: 18px; box-sizing: border-box;
    border-radius: 50%; border: 2px solid var(--mtouch-mark); background: color-mix(in srgb, #fff 35%, transparent);
  }

  .mtouch-xhair .mtouch-coords {
    display: block; position: absolute; z-index: 15; transform: translateX(-50%); pointer-events: none;
    max-width: calc(100vw - 32px); padding: 5px 10px; border-radius: 9px; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
    font: 600 11.5px/1.3 var(--mono); color: var(--fg);
    background: var(--mmap-glass); -webkit-backdrop-filter: var(--card-backdrop); backdrop-filter: var(--card-backdrop);
    border: 1px solid var(--line); box-shadow: var(--shadow);
  }
  .mtouch-coords:empty { visibility: hidden; }

  /* action bar just above the sheet; the legend chip shares that corner, so
     it steps aside while the mode is on */
  .mtouch-xhair .mtouch-bar {
    display: block; position: fixed; z-index: 20;
    left: max(12px, env(safe-area-inset-left, 0px)); right: max(12px, env(safe-area-inset-right, 0px));
    bottom: calc(var(--m-sheet-h, 64px) + 12px);
    padding: 8px 8px 8px; border-radius: 18px;
    background: var(--mmap-glass); -webkit-backdrop-filter: var(--card-backdrop); backdrop-filter: var(--card-backdrop);
    border: 1px solid var(--line); box-shadow: var(--shadow-lg);
    animation: mtouch-rise .18s cubic-bezier(.2, .7, .2, 1);
  }
  .mtouch-xhair.mmap-on #legend-dock { visibility: hidden; }
  .mtouch-hint { margin: 0 4px 8px; font: 500 11.5px/1.35 var(--font); color: var(--fg2); }
  .mtouch-row { display: flex; gap: 8px; }
  .mtouch-row button {
    height: 48px; border-radius: 14px; cursor: pointer; font: 600 14px var(--font);
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    -webkit-tap-highlight-color: transparent;
  }
  .mtouch-row button svg { width: 18px; height: 18px; flex: none; }
  .mtouch-row button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  .mtouch-add { flex: 1 1 auto; min-width: 0; padding: 0 12px; border: 0; background: var(--mtouch-go); color: var(--mtouch-go-fg); }
  .mtouch-add span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mtouch-add:disabled { opacity: .45; cursor: default; }
  .mtouch-ib { flex: none; width: 48px; padding: 0; border: 0; color: var(--fg); background: color-mix(in srgb, var(--fg) 8%, transparent); }
  .mtouch-done { flex: none; padding: 0 16px; color: var(--fg); background: transparent; border: 1px solid var(--border); }
  .mtouch-row button:not(:disabled):active { transform: scale(.97); }

  @keyframes mtouch-rise { from { opacity: 0; transform: translateY(8px); } }
}

@media (max-width: 640px) and (prefers-reduced-motion: reduce), (pointer: coarse) and (orientation: portrait) and (max-width: 1100px) and (prefers-reduced-motion: reduce), (pointer: coarse) and (orientation: landscape) and (max-height: 500px) and (prefers-reduced-motion: reduce), (max-width: 950px) and (orientation: landscape) and (max-height: 500px) and (prefers-reduced-motion: reduce), (pointer: coarse) and (hover: none) and (prefers-reduced-motion: reduce) {
  .mtouch-xhair .mtouch-bar { animation: none; }
  .mtouch-fab:active, .mtouch-row button:not(:disabled):active { transform: none; }
}

/* Landscape touch tablets (and large touch screens) keep the desktop
   layout, with finger-sized targets: at least 44 x 44 px. Sizes grow with
   min-width/height; the small round buttons (ⓘ, ×, −, the theme switch,
   the sim chip) keep their look and get an invisible 44 px hit area from
   ::after. Portrait tablets get the phone layout instead (above). */
@media (pointer: coarse) and (min-width: 641px) and (orientation: landscape), (pointer: coarse) and (min-width: 1101px) {
  html:not(.mmap-on) #toolpanels { --tp-w: 300px; }
  html:not(.mmap-on) .rail-btn { width: 44px; height: 44px; }

  /* Survey controls */
  html:not(.mmap-on) .sc-play { height: 44px; }
  html:not(.mmap-on) .ibtn, html:not(.mmap-on) .ibtn.solid { width: 44px; height: 44px; }
  html:not(.mmap-on) .sc-tools { gap: 0; }
  html:not(.mmap-on) #panel .sv { min-height: 44px; justify-content: center; }

  /* Map layers toolbar */
  html:not(.mmap-on) #layers .ib { width: 44px; height: 44px; border-radius: 15px; }
  html:not(.mmap-on) #layers.layers-bar { padding: 4px; }

  /* segmented pills: the pill itself is the target */
  html:not(.mmap-on) .seg { padding: 0; }
  html:not(.mmap-on) .seg button { min-height: 44px; padding-left: 14px; padding-right: 14px; }
  html:not(.mmap-on) #v3d .seg button { padding-left: 10px; padding-right: 10px; }

  /* 3D panel */
  html:not(.mmap-on) #v3d #btn-3d-big, html:not(.mmap-on) #v3d #btn-3d-close { min-width: 44px; min-height: 44px; font-size: 14px; }
  html:not(.mmap-on) #v3d .mini input { height: 44px; min-width: 62px; }   /* room for "auto" even when the panel is narrow */
  /* with 44 px buttons the one-row header needs ~660 px: below that, the
     title, enlarge and close make the first row (the title gives way; its
     basis leaves room for the two buttons and their gaps) and the
     controls wrap to the second */
  @container (max-width: 680px) {
    html:not(.mmap-on) #v3d .head h3 { order: -2; flex: 1 1 calc(100% - 2 * 44px - 2 * 6px - 1px); min-width: 0; margin-right: 0; }
    html:not(.mmap-on) #v3d .head #btn-3d-big, html:not(.mmap-on) #v3d .head #btn-3d-close { order: -1; }
  }

  /* other buttons and fields */
  html:not(.mmap-on) .btn { min-height: 44px; }
  html:not(.mmap-on) #topbar .btn, html:not(.mmap-on) #btn-setup, html:not(.mmap-on) #logout-btn { min-height: 44px; }
  html:not(.mmap-on) #legend-dock .lg-chip { min-height: 44px; }

  /* small round buttons: same look, 44 px invisible hit area */
  html:not(.mmap-on) .card-min, html:not(.mmap-on) .card-x { position: relative; }
  html:not(.mmap-on) .card-min::after, html:not(.mmap-on) .card-x::after,
  html:not(.mmap-on) #sim-chip .sc-stop::after {
    content: ""; position: absolute; left: 50%; top: 50%; width: 44px; height: 44px;
    transform: translate(-50%, -50%); border-radius: 50%;
  }
  html:not(.mmap-on) #sim-chip .sc-stop, html:not(.mmap-on) #sim-chip .sc-finish { position: relative; }
  html:not(.mmap-on) #sim-chip .sc-finish::after,
  html:not(.mmap-on) #theme-btn::after {
    content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 44px; transform: translateY(-50%);
  }
  /* ⓘ: the circle stays 16 px. Its overflow is clipped (the letter is
     hidden by text-indent), so clip with a margin instead of hiding: the
     44 px ::after then still takes the taps. (Measured: same position as
     with overflow:hidden everywhere but the setup title, fixed below.) */
  html:not(.mmap-on) .info { overflow: clip; overflow-clip-margin: 14px; }
  html:not(.mmap-on) .setup-card h1 .info { vertical-align: -5px; }
  html:not(.mmap-on) .info::after {
    content: ""; position: absolute; left: 50%; top: 50%; width: 44px; height: 44px;
    transform: translate(-50%, -50%); border-radius: 50%;
  }
}

/* Phone landscape: the crosshair button stays under Layers (left of the
   side panel, --m-sheet-w), the action bar sits at the bottom of the free
   map area between the rail and the panel: one row of buttons, no hint
   line; the crosshair is centred above it (centre() in mobile-touch.js). */
@media (pointer: coarse) and (orientation: landscape) and (max-height: 500px), (max-width: 950px) and (orientation: landscape) and (max-height: 500px) {
  .mmap-on .mtouch-fab, .mmap-on:has(#v3d:not([hidden])) .mtouch-fab {
    top: 62px; right: calc(var(--m-sheet-w, 0px) + max(12px, env(safe-area-inset-right, 0px)));
    transition: right var(--mland-ease, .25s ease);
  }
  .mtouch-xhair .mtouch-bar {
    left: calc(var(--mland-rail, 64px) + 12px); right: calc(var(--m-sheet-w, 0px) + max(12px, env(safe-area-inset-right, 0px)));
    bottom: max(10px, env(safe-area-inset-bottom, 0px));
    max-width: 460px; margin: 0 auto; padding: 6px;
  }
  /* short screen: one compact row of 44 px buttons; the hint stays for
     screen readers only (the free map height is what the crosshair and
     its label need, see centre() in mobile-touch.js) */
  .mland-on .mtouch-hint {
    position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
    clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
  }
  .mtouch-row button { height: 44px; }
  .mtouch-ib { width: 44px; }
  /* label beside the crosshair (right, else left) when the room under it is
     short: the script adds .mtouch-side / .mtouch-side-l */
  .mtouch-xhair .mtouch-coords.mtouch-side { transform: translateY(-50%); }
  .mtouch-xhair .mtouch-coords.mtouch-side-l { transform: translate(-100%, -50%); }
  .mtouch-xhair .mtouch-coords.mtouch-wrap { white-space: normal; overflow-wrap: anywhere; }
}
@media (pointer: coarse) and (orientation: landscape) and (max-height: 500px) and (prefers-reduced-motion: reduce), (max-width: 950px) and (orientation: landscape) and (max-height: 500px) and (prefers-reduced-motion: reduce) {
  .mmap-on .mtouch-fab { transition: none; }
}

/* Crosshair in the desktop layout on touch-only screens (landscape touch
   tablets). The round button sits under the Map layers toolbar (#right is
   10 px down; the toolbar is 54 px tall with 44 px buttons, see above).
   The crosshair and label are placed by the script as on phones. The bar
   sits at the bottom centre of the free map area; the script sets
   --mtouch-bl/-br/-bb (its left, right and bottom inside #map-wrap: past
   the left panels and Side views, above the 3D panel and the legend). */
@media (pointer: coarse) and (hover: none) {
  html:not(.mmap-on) .mtouch-fab {
    display: grid; place-items: center; position: absolute; z-index: 12; top: 74px; right: 10px;
    width: 46px; height: 46px; padding: 0; border-radius: 50%; cursor: pointer;
    color: var(--fg); border: 1px solid var(--line); box-shadow: var(--shadow);
    -webkit-tap-highlight-color: transparent;
  }
  html:not(.mmap-on) .mtouch-fab svg { width: 22px; height: 22px; display: block; }
  html:not(.mmap-on) .mtouch-fab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  html:not(.mmap-on) .mtouch-fab[aria-pressed="true"] { background: var(--mtouch-go); color: var(--mtouch-go-fg); border-color: var(--mtouch-go); }
  html:not(.mmap-on) .mtouch-fab:active { transform: scale(.96); }
  /* the simulation chip sits at the same spot: the button goes below it */
  html:not(.mmap-on) body:has(#sim-chip:not([hidden])) .mtouch-fab { top: 128px; }
  /* the enlarged 3D panel covers the map: nothing to aim at */
  html:not(.mmap-on) body:has(#v3d.big:not([hidden])) :is(.mtouch-fab, .mtouch-cross, .mtouch-coords, .mtouch-bar) { display: none; }

  /* label and bar: the look of the desktop cards */
  html:not(.mmap-on) .mtouch-coords, html:not(.mmap-on) .mtouch-bar, html:not(.mmap-on) .mtouch-fab:not([aria-pressed="true"]) {
    background: linear-gradient(color-mix(in srgb, var(--glass) var(--card-pct), transparent), color-mix(in srgb, var(--glass) var(--card-pct), transparent)), var(--glass-floor);
    -webkit-backdrop-filter: var(--card-backdrop); backdrop-filter: var(--card-backdrop);
    border-color: var(--line);
  }
  html:not(.mmap-on).mtouch-xhair .mtouch-bar {
    position: absolute; z-index: 12; box-sizing: border-box;
    left: calc(var(--mtouch-bl, 0px) + 12px); right: calc(var(--mtouch-br, 0px) + 12px);
    bottom: var(--mtouch-bb, 12px);
    max-width: 440px; margin: 0 auto; padding: 8px;
  }
  html:not(.mmap-on) .mtouch-hint { margin: 0 6px 8px; }
  html:not(.mmap-on) .mtouch-bar.mtouch-tight .mtouch-hint { display: none; }   /* little height: see deskCentre() */
  /* little width: no plus sign, less padding (and a shorter label, from the script) */
  html:not(.mmap-on) .mtouch-bar.mtouch-narrow .mtouch-row { gap: 6px; }
  html:not(.mmap-on) .mtouch-bar.mtouch-narrow .mtouch-add { padding: 0 8px; }
  html:not(.mmap-on) .mtouch-bar.mtouch-narrow .mtouch-add svg { display: none; }
  html:not(.mmap-on) .mtouch-bar.mtouch-narrow .mtouch-ib { width: 44px; }
  html:not(.mmap-on) .mtouch-bar.mtouch-narrow .mtouch-done { padding: 0 12px; }
}
