/* The touch layer (touch conventions §B.1, §C.1): full-size tap targets on
   every device that has any touch input, whatever its width. app.html links it
   after its head styles, so at equal specificity a rule here wins. Each token
   has its twin in TOUCH_CONSTANTS (public/lib/touch.js); outside the coarse
   query the tokens are not defined, so every use gives a fallback. Checked by
   test/touch-targets.test.js against test/touch/targets.json. */

@media (any-pointer: coarse) {
  .tut-btn { min-height: var(--tap-min); }
  #aircraft-modal .ac-extra > summary { min-height: var(--tap-min); padding-block: 10px; }
  #m-search-input + .btn { min-width: var(--tap-min); }
  #m-search-results .sri-main[role="button"] {
    display: flex; flex-direction: column; justify-content: center;
    min-height: var(--tap-min);
  }
  :root {
    --tap-min: 44px;
    --tap-gap: 8px;
    --tap-gap-danger: 16px;
    --tap-main: 48px;
    --tap-undo: 48px;
    --tap-fly-end: 52px;
    --tap-fly-second: 48px;
    --field-min: 44px;
    --field-text: 16px;
  }
}

/* Two quick taps are two taps, never a page zoom (TW-086). :where() gives the
   rule no specificity, so .wpt-reorder's touch-action:none and Leaflet's map
   rules still win. Outside the coarse query: it holds on any touch device. */
:where(button, a, [role=button], .topbar, .mobile-dock, .mobile-sheet, .ck-modal-backdrop) {
  touch-action: manipulation;
}

/* Press states (touch conventions §J.1): a 14 % tint painted inside the
   control's own shape, over its fill, so a filled button keeps its fill and a
   button with an inline background still shows the press. Outside the coarse
   query, so a mouse press shows too. */
.btn:active, .tap:active, .tap-row:active,
.user-menu-item:active, .mobile-layer-btn:active, .ruler-control button:active,
.fit-route-control button:active, .leaflet-bar a:active, .wpt-row:active, .tut-btn:active,
.layer-close:active {
  box-shadow: inset 0 0 0 100vmax color-mix(in srgb, currentColor 14%, transparent);
}

/* A route point held to move it lifts (S22). A filter, not a box-shadow: the
   route icon's markup sets an inline box-shadow, which would win. */
.wpt-marker-icon.wpt-lifted {
  transform: scale(1.15);
  filter: drop-shadow(0 6px 8px rgba(0,0,0,.6));
  transition: transform .12s;
}

@media (any-pointer: coarse) {
  /* Shared classes (touch conventions §C.1). No display on .btn or .btn-sm:
     a hidden button must stay hidden. An inline font-size still wins. */
  .btn, .btn-sm { min-height: var(--tap-min); font-size: 13px; }
  .tap {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: var(--tap-min); min-height: var(--tap-min);
  }
  .tap-danger { margin-block-start: var(--tap-gap-danger); margin-inline-start: var(--tap-gap-danger); }

  /* The map: zoom, Measure, show whole route, Undo and the Route sheet's
     remove buttons. */
  .leaflet-touch .leaflet-bar a { width: var(--tap-min); height: var(--tap-min); line-height: var(--tap-min); }
  .leaflet-touch .leaflet-control-zoom {
    display: flex; flex-direction: column; gap: var(--tap-gap); border: none; background: none;
  }
  .leaflet-touch .leaflet-control-zoom a.leaflet-control-zoom-in,
  .leaflet-touch .leaflet-control-zoom a.leaflet-control-zoom-out {
    border: 2px solid rgba(0,0,0,.2); border-radius: 6px; background-clip: padding-box;
  }
  .ruler-control button, .fit-route-control button { height: var(--tap-min); min-width: var(--tap-min); }
  .map-undo-btn { min-height: var(--tap-undo); min-width: var(--tap-undo); font-size: 14px; }
  /* The buttons only: the attribution keeps Leaflet's 0 margin, or it wraps
     and rises over the Layers sheet's last row. */
  .leaflet-bottom.leaflet-right .leaflet-bar { margin-bottom: 8px; margin-right: 8px; }
  /* The 44 x 44 hit area around the drawn 32 px square. */
  .wpt-del.tap { padding: 6px; background-clip: content-box; margin-inline-start: var(--tap-gap); }
}

@media (any-pointer: coarse) {
  /* The phone chart buttons; their two-column grid is layout and stays in
     app.html's phone block. */
  .mobile-layer-btn { min-height: var(--tap-min); min-width: 56px; font-size: 12px; padding: 0 6px; }
}

@media (any-pointer: coarse) {
  .tap-gap { gap: var(--tap-gap); }

  /* Popups: the airport, waypoint and traffic popups share Leaflet's close
     (app.html keeps its right and top). */
  .leaflet-container a.leaflet-popup-close-button {
    width: var(--tap-min); height: var(--tap-min); line-height: var(--tap-min); font-size: 22px;
  }
  .leaflet-popup-content .ap-popup-id { padding-right: 48px; }
  /* The hazard card keeps the close's column as the airport id does: its
     first hazard, and every hazard while the list scrolls. The first reaches
     past the close's foot (6 + 44 from the card's top, the card's padding
     starting at 15), so Add starts 8 px or more below the close. */
  .leaflet-popup-content .hazard-card-item:first-child,
  .leaflet-popup-content .hazard-card-scrolls .hazard-card-item { padding-right: 48px; }
  .leaflet-popup-content .hazard-card-item:first-child { min-height: 36px; }
  /* The traffic popup's callsign keeps the close's column the same way, and
     its table starts below the close's foot. */
  .leaflet-popup-content .traffic-popup-id { padding-right: 48px; min-height: 36px; }
  /* Popup actions stack full width, the main one at the foot. A destructive
     one keeps its 16 px above; beside nothing, it needs no inline margin. */
  .ap-popup-actions { flex-direction: column; }
  .ap-popup-actions .btn { width: 100%; justify-content: center; }
  .ap-popup-actions .tap-danger { margin-inline-start: 0; }
  .ap-tabs { gap: var(--tap-gap); }
  .ap-tabs button { min-height: var(--tap-min); font-size: 13px; }
  .np-orig summary { display: flex; align-items: center; min-height: var(--tap-min); font-size: 13px; }
  /* Text floors (§B.2): labels 12 px; the raw NOTAM text as large as the
     decoded line. */
  .np-group, .np-time, .np-orig div, .rw-wind, .rw-note, .rw-name span { font-size: 12px; }
  .ap-popup-notam, .rw-end, .rw-name { font-size: 13px; }
}

@media (any-pointer: coarse) {
  .tap-row { display: flex; align-items: center; min-height: var(--tap-min); width: 100%; }

  /* The Layers sheet: each row is one target (.tap-row); a larger box. */
  .wx-layer-check { width: 22px; height: 22px; }
}

@media (any-pointer: coarse) {
  /* A long press on the chart: iPhone Safari opens no image menu on a held
     tile or marker and so does not cancel the press. Text selection is left
     alone: popup text stays selectable. */
  .leaflet-tile-pane, .leaflet-marker-pane { -webkit-touch-callout: none; }
}

@media (any-pointer: coarse) {
  /* Sheets, dialogs and panels (touch conventions §E.3, S16): one close in a
     header that never scrolls away. */
  .layer-header { position: sticky; top: 0; z-index: 1; background: var(--sky-card); }
  /* The 44 x 44 close. Its drawn circle keeps today's size and tint as a
     centred ::before, so the look is unchanged; the press state darkens
     inside the button's own shape. */
  .layer-close {
    position: relative; isolation: isolate; background: none; padding: 0;
    min-width: var(--tap-min); min-height: var(--tap-min);
  }
  .layer-close::before {
    content: ''; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    z-index: -1; background: color-mix(in srgb, var(--text) 6%, transparent);
  }
  .sheet-close.layer-close::before { width: 28px; height: 28px; border-radius: 50%; }
  .ck-modal-close.layer-close::before { width: 26px; height: 26px; border-radius: var(--r-sm); }
  /* The flight-category legend's close: its plain glyph kept, a 44 x 44 hit
     area, and negative margins so the card does not grow. */
  .wx-legend-close {
    min-width: var(--tap-min); min-height: var(--tap-min);
    margin-block: -14px; margin-inline-end: -10px;
  }
  /* The airport charts panel's chart links: one full-size row each, 8 apart
     (the head's .chart-link margin). */
  #charts-list .chart-link { min-height: var(--tap-min); display: flex; align-items: center; }
  /* The Layers sheet's opacity slider: a full-size track. */
  #m-wx-opacity { min-height: var(--tap-min); }
}

@media (any-pointer: coarse) {
  /* The Account menu (TW-057, TW-058): each row full size and 8 apart; Log
     Out (.tap-danger) 16 below the divider above it. A row fills the
     menu's width, so Log Out takes no inline margin. */
  #user-menu .user-menu-item { min-height: var(--tap-min); }
  #user-menu .user-menu-item + .user-menu-item { margin-block-start: var(--tap-gap); }
  #user-menu .tap-danger { margin-inline-start: 0; }
}

@media (any-pointer: coarse) {
  /* A loaded plan's Confirm values (TW-028). */
  .plan-review button { min-height: var(--tap-min); font-size: 13px; padding: 0 14px; }
  /* The Load rows (TW-092, TW-055): the open button full size, its Delete a
     44 x 44 control 16 apart (the row's gap), so it takes no margin. */
  #load-list .load-open { min-height: var(--tap-min); }
  #load-list .load-del { min-width: var(--tap-min); min-height: var(--tap-min); margin-block-start: 0; margin-inline-start: 0; }
}

/* The question dialog #touch-ask (touch conventions §C.1 "The question shape",
   S6, S11): its buttons stacked full width, 8 apart and 16 around a
   destructive one, or two side by side, 16 apart when one is destructive.
   Layout holds on any device, so each token gives its fallback here. */
.ask-stack { display: flex; flex-direction: column; gap: var(--tap-gap, 8px); }
.ask-stack .btn { width: 100%; justify-content: center; }
.ask-stack .tap-danger:not(:first-child), .ask-stack .tap-danger + .btn {
  margin-block-start: calc(var(--tap-gap-danger, 16px) - var(--tap-gap, 8px));
}
.ask-stack .tap-danger { margin-inline-start: 0; }
.ask-stack .tap-danger:first-child { margin-block-start: 0; }
.ask-row { display: flex; flex-direction: row; gap: var(--tap-gap, 8px); }
.ask-row:has(.tap-danger) { gap: var(--tap-gap-danger, 16px); }
.ask-row .tap-danger { margin-block-start: 0; margin-inline-start: 0; }

/* The aircraft form's Save Aircraft and Cancel (TW-076): Cancel, which asks
   before it clears the form, sits 16 apart. */
.ac-form-actions { gap: var(--tap-gap-danger, 16px); }

@media (any-pointer: coarse) {
  /* A stacked question's buttons are main actions, 48 tall. */
  #touch-ask .ask-stack .btn { min-height: var(--tap-main, 48px); }
}
