/* Phones and touch screens (iPhone Safari first): every control is at least 44 px in each direction,
   the tap target Apple and WCAG ask for, and a menu opens as a sheet from the bottom of the screen
   instead of a panel that can run off its edge. Linked after every page's own stylesheet, so it wins
   over their desktop sizes. A text link inside a sentence keeps its size (WCAG's inline exception);
   a short link that stands alone gets an invisible 44 px hit area (a::after), so the layout is unchanged. */

@media (max-width: 720px), (pointer: coarse) {
  /* Buttons, pills and chips that are links or buttons */
  .brand,
  .button,
  .button.quiet,
  .button.small,
  .back-note,
  .link-pill,
  .link-pill.small,
  .filter,
  .filters a,
  .sheet-filters a,
  a.topic,
  .topic-chip,
  .segmented .seg,
  .pin > summary,
  .pills a,
  .in-study,
  .rail-actions .button,
  .lib-anchors a,
  .settings-index a {
    min-height: 44px;
  }
  .pills a { display: inline-flex; align-items: center; }
  .filter,
  .filters a,
  .sheet-filters a {
    min-width: 44px;
    justify-content: center;
  }
  /* A verse card's links: its notes and cross-references, one per row */
  /* (padding on an inline link widens what a tap hits without moving the text) */
  .tx-pop .tx-notes { gap: 0; }
  .tx-pop .tx-notes > li { padding-top: 12px; padding-bottom: 12px; }
  .tx-pop .tx-notes > li > a { padding-top: 12px; padding-bottom: 12px; }
  .tx-pop > p > a,
  .tx-pop .tx-card-head > a {
    display: inline-block;
    padding-top: 12px;
    padding-bottom: 12px;
  }
  /* Rows of short links (a topic's passages, a chapter's commentary) are spaced for a thumb */
  .used-by > li { padding-top: 12px !important; padding-bottom: 12px !important; }
  /* So are a summary's themes, each with its time, a series' parts in a study, and the nearby parts of a series */
  .tx-themes ul { row-gap: 0; }
  .tx-themes li { padding-top: 12px; padding-bottom: 12px; }
  .live-unit { padding-top: 12px; padding-bottom: 12px; }
  .conn-parts { gap: 0; }
  .conn-parts > li { padding-top: 12px; padding-bottom: 12px; }
  .segmented { padding: 2px; }

  /* Square tool buttons: move up and down, remove, the "⋯" menu, the player's skips, the graph's zoom */
  .tool,
  .icon-button,
  .section-row .icon-button,
  .conn-menu > summary.conn-menu-button,
  .player-ui .skip-back,
  .player-ui .skip-fwd,
  .graph-zoom .button {
    min-width: 44px;
    min-height: 44px;
  }
  .conn.has-menu > .conn-top { padding-right: 44px; }
  .conn > .conn-menu { top: 4px; right: -10px; }

  /* Disclosure rows */
  .status-line > summary,
  .live-parts > summary,
  .rail-more > summary,
  .rail-hidden > summary,
  .conn-group > summary,
  .add-item .menu-panel > details > summary {
    min-height: 44px;
  }
  .map-group > summary { min-height: 44px; justify-content: center; }
  /* These keep the browser's disclosure triangle (display: list-item), so padding sets their height */
  .correct-any > summary,
  .more-options > summary,
  .more-rows > summary,
  .passage-text > summary,
  .email-link > summary,
  .card details:not([class]) > summary {
    min-height: 44px;
    padding-top: 10px;
    padding-bottom: 10px;
  }

  /* Form fields. iOS draws a native <select> at its own small height, so it is drawn here instead
     (:root, so it wins over a page's own select rule such as .stack-form select) */
  input:not([type="checkbox"]):not([type="radio"]),
  .search-field input,
  textarea {
    min-height: 44px;
  }
  :root select {
    -webkit-appearance: none;
    appearance: none;
    min-height: 44px;
    padding-right: 34px;
    background-image: url(chevron-down.svg?v=7d7f4c4274fa534a);
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 12px 12px;
  }
  /* A checkbox or radio is tapped through its whole label row */
  input[type="checkbox"],
  input[type="radio"] {
    width: 22px;
    height: 22px;
  }
  .check,
  .pin-choice,
  .choices > label,
  label:has(> input[type="checkbox"]),
  label:has(> input[type="radio"]) {
    min-height: 44px;
    align-items: center;
  }
  .check input,
  .pin-choice input {
    margin-top: 0;
  }

  /* Short links that stand on their own line: a 44 px hit area around them, without moving anything */
  a.ts,
  a.tx-marker,
  a.tx-jump,
  .crumbs a,
  a.hit-title,
  .live-unit-text > a,
  .conn-series > a,
  .conn-parts a,
  .rail-row > a,
  .tx-body a.tx-cite,
  a.conn-title,
  a.unit-title,
  a.rail-strong,
  .note-meta a.series,
  a.passage-page,
  .used-by a.verses,
  a.topic-link,
  a.queue-title,
  .card-head > a,
  .section-head > a,
  .rail-link,
  .map-parts a,
  .item-chips a,
  .side-head > a,
  .main-passage a.ref,
  .passage-row a.ref,
  .detail-rows a.ref,
  li > a.ref:first-child,
  .used-by a,
  a.sheet-only,
  .sec-scripture blockquote p:first-child a,
  .sec-commentary p > a:only-child,
  .map-passage a.ref,
  .cost-list a {
    position: relative;
  }
  a.ts::after,
  a.tx-marker::after,
  a.tx-jump::after,
  .crumbs a::after,
  a.hit-title::after,
  .live-unit-text > a::after,
  .conn-series > a::after,
  .conn-parts a::after,
  .rail-row > a::after,
  .tx-body a.tx-cite::after,
  a.conn-title::after,
  a.unit-title::after,
  a.rail-strong::after,
  .note-meta a.series::after,
  a.passage-page::after,
  .used-by a.verses::after,
  a.topic-link::after,
  a.queue-title::after,
  .card-head > a::after,
  .section-head > a::after,
  .rail-link::after,
  .map-parts a::after,
  .item-chips a::after,
  .side-head > a::after,
  .main-passage a.ref::after,
  .passage-row a.ref::after,
  .detail-rows a.ref::after,
  li > a.ref:first-child::after,
  .used-by a::after,
  a.sheet-only::after,
  .sec-scripture blockquote p:first-child a::after,
  .sec-commentary p > a:only-child::after,
  .map-passage a.ref::after,
  .cost-list a::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    width: max(100%, 44px);
    height: max(100%, 44px);
    transform: translate(-50%, -50%);
  }
  /* A link that wraps onto two lines is one box, so its hit area is one box too */
  .cost-list a,
  .conn-parts a { display: inline-block; }
}

/* ---------- A finger, not a mouse ---------- */
@media (pointer: coarse) {
  /* The audio scrubber: a 44 px tall input (the field rule above) around the same 4 px track, with a thumb a
     finger can find */
  .seek { height: 44px; }
  .seek::-webkit-slider-thumb { width: 24px; height: 24px; margin-top: -10px; }
  .seek::-moz-range-thumb { width: 20px; height: 20px; }

  /* iPhone Safari zooms the page into a field whose text is under 16 px: none is (the search fields are
     larger already) */
  :root input:not([type="checkbox"], [type="radio"], [type="range"], .search-box input, .find-form input),
  :root select,
  :root textarea {
    font-size: max(16px, 1em);
  }
}

/* ---------- Menus as a bottom sheet on a phone ---------- */
@media (max-width: 720px) {
  /* A long chip (a ministry's full name) wraps instead of running off the screen */
  .tchip { white-space: normal; overflow-wrap: anywhere; }

  details.menu[open] > .menu-panel {
    position: fixed;
    left: 0;
    right: 0;
    top: auto;
    bottom: 0;
    z-index: 61;
    width: auto;
    min-width: 0;
    max-width: none;
    max-height: calc(100dvh - 64px);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 8px max(12px, env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom))
      max(12px, env(safe-area-inset-left));
    border-width: 1px 0 0;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.18);
  }
  /* The grab bar at the top of the sheet */
  details.menu[open] > .menu-panel::before {
    content: "";
    flex: 0 0 auto;
    align-self: center;
    width: 36px;
    height: 4px;
    margin: 0 0 8px;
    border-radius: 2px;
    background: var(--line-strong);
  }
  /* The dimmed page behind the sheet belongs to the menu's summary, so tapping it closes the menu */
  details.menu[open] > summary::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 60;
    background: rgba(17, 22, 28, 0.36);
    cursor: default;
  }
  details.menu .menu-panel a,
  details.menu .menu-panel button {
    min-height: 48px;
  }
  details.menu[open] .menu-new { padding-left: 4px; padding-right: 4px; }
}

/* iPad Safari sends a click for a tap only on something that looks clickable: the dimmed page around
   the Review details drawer closes it */
@media (pointer: coarse) {
  .drawer-backdrop:not(.as-page) { cursor: pointer; }
  .drawer-backdrop:not(.as-page) > .drawer { cursor: auto; }
}
