/* Touch targets (pointer: coarse). Every control reaches 44 × 44px, Apple's minimum, without
   changing how it looks: an invisible ::before (or padding offset by a negative margin) grows the
   hit area where there is free space, and stops short of a neighbouring target. Press feedback is
   added where a tap otherwise showed nothing. Measured at 390 and 360px with
   a local tap audit.

   The ::before rule fits any size: in a positioned box, top and bottom percentages are of its
   height and left and right of its width, so inset min(0px, 50% - 22px) leaves a box that is
   already 44px alone and grows a smaller one to exactly 44px, centred. */
@media (pointer: coarse) {
  [data-site] {
    :is(
      [data-slot="heading-link"],
      [data-component="changelog-timeline"] [data-slot="version"],
      [data-component="changelog-toolbar"] [data-slot="filter"] a,
      [data-slot="subscribe"] [data-slot="trigger"],
      [data-slot="carousel-nav"] button,
      [data-component="product-card"] h3 a,
      [data-slot="copy-label"],
      [data-slot="learn-more"],
      [data-component="press-contacts"] a,
      [data-component="code-tabs"] [data-slot="tabs"] button,
      /* Added by the responsive sweep (5 Nov): breadcrumb links (18px tall), the voice sheet's Hex
         link (40px) and the sidebar and bare-page logos (24 × 26px), each with free space around it. */
      [data-component="breadcrumb"] a,
      [data-component="voice-mode"] a[data-slot="hex"],
      [data-component="changelog-entry"] a[data-slot="show-more"],
      [data-component="changelog-pages"] a,
      :is([data-component="sidebar"], [data-component="bare-chrome"], header[data-slot="sidebar"]) a[data-slot="logo"]
    ) {
      position: relative;

      &::before {
        content: "";
        position: absolute;
        inset: min(0px, calc(50% - 22px));
      }
    }

    /* Header. The GitHub mark's link grows from 40 to 44px, centred on the mark, which stays 54px in
       from the page edge (github-link.css), so its target meets the menu button's. The banner's ×
       follows its centre line. */
    [data-component="topbar"] [data-component="github-link"] {
      --github-size: 2.75rem;
    }

    /* The fixed corner mark beside the sidebar (touch tablets) and on bare pages: 44px too. Set on
       the site root, where github-link.css derives the mark's inset and the room other controls
       leave for it from the size, so it stays centred on the voice orb's axis. Doubled to outrank
       github-link.css's own [data-site] rule. */
    &[data-site] {
      --github-size: 2.75rem;
    }

    @media (max-width: 60rem) {
      &:not([data-bare]) > [data-component="announcement-banner"] button[data-slot="dismiss"] {
        --dismiss-centre: calc(var(--edge) + env(safe-area-inset-right, 0px) + 3.375rem);
      }
    }

    :is(
      [data-component="topbar"] [data-slot="logo"],
      [data-component="topbar"] [data-component="github-link"],
      [data-component="menu-toggle"]
    ) {
      transition: transform 160ms var(--ease-out);

      &:active {
        transform: scale(0.94);
      }
    }

    /* The banner's ×: a 44px square, the bar's full height, on the GitHub mark's centre line.
       button: outranks site-banner.css, which loads later. */
    [data-component="announcement-banner"] button[data-slot="dismiss"] {
      inset-inline-end: calc(var(--dismiss-centre) - 22px);
      bottom: 0;
      width: 44px;
      height: 44px;

      &:active {
        color: var(--bar-highlight);
      }
    }

    /* The first accordion and FAQ row starts level with the section label, so it had no padding
       above its text (37px tall). It gets the same 10px as the other rows, taken back by a negative
       margin. */
    [data-component="faq"] li:first-child [data-slot="faq-question"] {
      --padding-top: 0.625rem;
      margin-top: -0.625rem;
    }

    /* Section titles that copy their link, and the changelog's titles: a press dims or underlines
       them (they are already in the strong colour, so the colour change showed nothing). */
    [data-slot="heading-link"] {
      transition:
        color 150ms ease,
        opacity 100ms var(--ease-out);

      &:active {
        opacity: 0.6;
      }
    }

    [data-component="changelog-entry"] [data-slot="copy-heading"] {
      /* Inline, so the padding grows the hit area of every line without moving the text. */
      padding-block: max(0px, calc((2.75rem - 1em) / 2));

      &:active {
        text-decoration: underline;
        text-decoration-thickness: 1px;
        text-decoration-color: var(--border-strong);
        text-underline-offset: 0.2em;
      }
    }

    /* Changelog. The area chips scroll sideways, which clips anything outside the scroller, so it
       gets room for their 44px targets above and below. */
    [data-component="changelog-toolbar"][data-filters="areas"] [data-slot="filter"] {
      padding-block: 9px;
      margin-block: -9px;
    }

    [data-component="changelog-entry"] details[data-slot="group"] > summary {
      min-height: 2.75rem;
      margin-block: -10px;
    }

    /* The site's buttons keep their 4px band; shorter ones (Copy command, 32px) reach 44px. The :is()
       matches site.css's own selector, which this file follows. */
    :is([data-component="site-button"], [data-component="block"] [data-slot="more"])::after {
      inset: min(-0.25rem, calc(50% - 22px)) 0;
    }

    [data-component="changelog-entry"] [data-slot="meta"] :is(a, [data-slot="copy-link"]) {
      padding-block: calc((2.75rem - 1lh) / 2);
      margin-block: calc((1lh - 2.75rem) / 2);
    }

    /* A video's pause and play button: 32px drawn, 44px target. */
    [data-slot="play"]::before {
      content: "";
      position: absolute;
      inset: -6px;
    }

    [data-component="code-tabs"] [data-slot="tabs"] button::before {
      inset: 0 -10px;
    }

    /* The press fill of the sticky menu rows and the open Contents list's rows reaches both screen
       edges; the label and chevron stay on the content edge and the menu column. The border image's outset paints past the box
       without making the page wider. */
    :is([data-slot="section-toggle"], [data-component="contents-menu"] :is(summary, a)):active {
      background: var(--row-press);
      border-image: linear-gradient(var(--row-press), var(--row-press)) fill 0 / 0 / 0 100vmax;
    }

    /* The asset buttons on /brand and /press: asset-buttons.css. */

    /* The colour formats are stacked rows that touch, so each row is 44px tall itself. */
    &[data-page="brand"] [data-slot="formats"] [data-slot="format"] {
      min-height: 2.75rem;
    }

    /* The badge style tabs (Frame, Cells…): 44px tall, meeting in their 20px gaps. ::after, since the
       square tab style draws its marker with ::before. */
    &[data-page="brand"] [data-slot="style-tabs"] button {
      position: relative;

      &::after {
        content: "";
        position: absolute;
        inset: min(0px, calc(50% - 22px)) -0.625rem;
      }
    }

    /* Home: the contributor avatars' targets meet, so a tap between two still opens one. */
    [data-component="oss-proof"] [data-slot="people"] a::before {
      content: "";
      position: absolute;
      inset: calc(var(--avatar-gap) / -2);
    }

    [data-component="product-card"] h3 a {
      height: 2.75rem;
      margin-block: calc((1lh - 2.75rem) / 2);
      transition: opacity 100ms var(--ease-out);

      &:active {
        opacity: 0.6;
      }
    }

    /* The Contents rail and the docs sidebar: 44px rows (the rail's padding inside each item, so the
       pipe still marks the label's line). The rows grow; each label stays centred in its row. */
    /* Doubled to outrank on-this-page.css, which loads after this file on some pages. */
    [data-component="on-this-page"][data-component] {
      --rail-pad: calc((2.75rem - 20px) / 2);
    }

    [data-component="docs-nav"] a {
      min-block-size: 2.75rem;
      align-items: center;
    }

    /* Range inputs (/font): 44px tall to the finger, the 16px track drawn where it was. */
    input[type="range"] {
      padding-block: 14px;
      margin-block: -14px;
    }

    /* Touch tablets beside the sidebar (iPad landscape, 961px and wider): the 44px rows and controls
       the phone layout already has (site.css, max-width 60rem). Approved by David (5 Nov). */
    @media (min-width: 60.0625rem) {
      [data-component="sidebar"] nav a {
        min-block-size: 2.75rem;
        align-items: center;
      }

      [data-component="secondary-nav"] {
        ul {
          gap: 0;
        }

        li > a,
        li > [data-component="language-picker"] [data-slot="trigger"] {
          min-block-size: 2.75rem;
          align-items: center;
          padding-block: 0;
          margin-block: 0;
        }
      }

      /* In a 44px row the status label's baseline alignment (site.css, footer list) put it below the
         uptime bars; centre both. Repeated attributes outrank that rule. */
      [data-component="site-footer"][data-component] [data-component="status"] [data-slot="status-label"][data-slot] {
        align-self: center;
      }

      [data-component="theme-toggle"] :is(button, a) {
        width: 2.75rem;
        height: 2.75rem;
      }

      [data-slot="copyright"] a {
        display: inline-block;
        padding-block: 0.8125rem;
        margin-block: -0.8125rem;
      }

      /* 36px buttons keep their look; an invisible band above and below makes the target 44px. */
      /* Not the asset buttons (asset-buttons.css gives them their own reach) or the top bar's. */
      :is([data-component="site-button"], [data-component="block"] [data-slot="more"]):not(
        [data-component="topbar"] *,
        [data-slot="meta"] *
      ) {
        position: relative;

        &::after {
          content: "";
          position: absolute;
          inset: min(-0.25rem, calc(50% - 22px)) 0;
        }
      }

      /* The product pages' previous and next chevrons beside the GitHub mark: 44px wide, as on
         phones, and 44px tall to the finger. */
      [data-component="product-cycle"] a[href] {
        position: relative;
        width: 2.75rem;

        &::before {
          content: "";
          position: absolute;
          inset: min(0px, calc(50% - 22px)) 0;
        }
      }
    }
  }
}
