/* Public storefront touch layouts. The outer gate also protects narrow desktop windows. */
@media (hover: none) and (pointer: coarse) and (max-width: 1366px) {
  /* Keep the masthead to two rows on phones, with search spanning the second. */
  html body header.csm-floating-header[data-header-theme] #shop-menu-toggle { min-height: 44px; }
  html body header.csm-floating-header .csm-header-search input { font-size: 16px; }
  html body header.csm-floating-header .csm-header-search form button {
    flex: 0 0 auto; min-width: 44px; min-height: 44px;
  }
  .csm-floating-header .csm-header-account .csm-header-more-panel a {
    display: flex; align-items: center; min-height: 44px;
  }
  html body .csm-floating-header #shop-navigation .csm-finder-panels a {
    min-height: 44px; overflow-wrap: anywhere;
  }
  html body .csm-floating-header #shop-navigation summary { min-height: 44px; }
  html body .csm-floating-header #shop-navigation .csm-header-more-panel a {
    white-space: normal; overflow-wrap: anywhere; min-height: 44px;
  }

  @media (max-width: 600px) {
    html body header.csm-floating-header[data-header-theme] {
      grid-template-columns: minmax(0, 1fr) auto auto;
      gap: 6px 8px;
      padding: 7px 9px !important;
    }
    html body header.csm-floating-header[data-header-theme] .csm-header-brand {
      grid-area: 1 / 1; min-width: 0; gap: 6px;
    }
    html body header.csm-floating-header[data-header-theme] .csm-header-logo {
      width: 38px; height: 38px; flex-basis: 38px;
    }
    .csm-floating-header .csm-header-wordmark { font-size: clamp(11px, 3vw, 14px); overflow-wrap: anywhere; }
    .csm-floating-header .csm-header-wordmark small { display: none; }
    html body header.csm-floating-header[data-header-theme] #shop-menu-toggle {
      grid-area: 1 / 2; padding-inline: 7px; min-width: 44px;
    }
    html body header.csm-floating-header[data-header-theme] .csm-header-account > :is(summary, .csm-header-account-link) { padding-inline: 7px; }
    html body header.csm-floating-header[data-header-theme] .csm-header-account > :is(summary, .csm-header-account-link) svg { display: none; }
    html body header.csm-floating-header[data-header-theme] .csm-header-search { grid-area: 2 / 1 / 3 / -1; }
    .csm-floating-header .csm-header-account .csm-header-more-panel { max-width: calc(100vw - 40px); }
  }

  @media (max-width: 350px) {
    html body header.csm-floating-header[data-header-theme] #shop-menu-toggle,
    html body header.csm-floating-header[data-header-theme] .csm-header-account > :is(summary, .csm-header-account-link) {
      padding-inline: 6px; font-size: 12px;
    }
    html body header.csm-floating-header[data-header-theme] .csm-header-logo {
      width: 34px; height: 34px; flex-basis: 34px;
    }
    .csm-floating-header .csm-header-wordmark { font-size: 10px; overflow-wrap: normal; }
  }

  /* Tablet navigation reuses the public links and category finder in a drawer. */
  @media (min-width: 761px) {
    /* Fix the World header geometry before the tablet controller initializes. */
    html:is(.touch-tablet, :where(:has(body.electric-horizon))) body header.csm-floating-header[data-header-theme] {
      display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(180px, 340px) auto;
      position: relative; isolation: auto; z-index: 70;
      gap: clamp(8px, 1.6vw, 20px);
      min-height: 0; padding: 9px clamp(10px, 1.7vw, 24px) !important;
    }
    html:is(.touch-tablet, :where(:has(body.electric-horizon))) body .csm-floating-header .csm-header-brand { grid-area: 1 / 1; min-width: 0; }
    html:is(.touch-tablet, :where(:has(body.electric-horizon))) body .csm-floating-header #shop-menu-toggle {
      display: block; grid-area: 1 / 2; padding: 0 10px; min-width: 44px;
    }
    html:is(.touch-tablet, :where(:has(body.electric-horizon))) body header.csm-floating-header .csm-header-search { grid-area: 1 / 3; min-width: 0; }
    html:is(.touch-tablet, :where(:has(body.electric-horizon))) body .csm-floating-header .csm-header-account { grid-area: 1 / 4; }
    html:is(.touch-tablet, :where(:has(body.electric-horizon))) body .csm-floating-header #shop-navigation {
      display: none !important; position: absolute !important;
      inset: calc(100% + 6px) auto auto 0 !important;
      flex-direction: column; flex-wrap: nowrap; align-items: stretch; gap: 4px;
      width: min(100%, 580px) !important; max-height: calc(100dvh - var(--touch-header-bottom, 85px) - 14px);
      overflow: auto; overscroll-behavior: contain; padding: 10px !important;
      border: 1px solid var(--masthead-edge); border-radius: 12px;
      background: var(--masthead-panel) !important; box-shadow: 0 10px 30px #0008;
    }
    html.touch-tablet body .csm-floating-header #shop-navigation.mobile-open,
    html:not(.touch-tablet) body.electric-horizon .csm-floating-header #shop-navigation:target {
      display: flex !important;
    }
    html:is(.touch-tablet, :where(:has(body.electric-horizon))) body .csm-floating-header #shop-navigation > .mobile-nav-heading {
      display: flex; align-items: center; justify-content: space-between; padding-inline: 9px;
    }
    html.touch-tablet body .csm-floating-header #shop-navigation > a { white-space: normal; }
    html.touch-tablet body .csm-floating-header #shop-dropdown .csm-category-finder,
    html.touch-tablet body .csm-floating-header #shop-navigation > details > .csm-header-more-panel {
      position: static; width: 100%; max-width: 100%; max-height: none; box-shadow: none;
    }
    .touch-tablet .csm-floating-header #close-shop-menu { width: 44px; height: 44px; }
    .touch-tablet .csm-floating-header ~ .shop-backdrop:not([hidden]) { z-index: 60; }
    html.touch-tablet body:has(#filters.show) .csm-floating-header { z-index: 51; }
    html.touch-tablet body.storefront-page main #catalog .shop-layout { display: block; }
    html.touch-tablet body.storefront-page main #catalog #filters:not(.show) { display: none !important; }
    html.touch-tablet body.storefront-page main #catalog #filters.show {
      display: block !important; position: fixed !important;
      inset: 0 auto 0 0 !important; width: min(425px, 85vw); max-width: none;
      z-index: 81; margin: 0; min-height: 0; max-height: 100dvh !important;
    }
    .touch-tablet #catalog .results-toolbar { flex-wrap: nowrap !important; }
    html.touch-tablet body.storefront-page main #catalog #filter-toggle { display: inline-flex !important; gap: 7px; align-items: center; }
    html.touch-tablet body.storefront-page main #catalog :is(.mobile-filter-close,.mobile-filter-actions) { display: flex !important; }
    .touch-tablet #catalog .mobile-filter-actions { gap: 8px; flex-wrap: wrap; }
    .touch-tablet body.shop-panel-open { overflow: hidden; }
    .touch-tablet body:has(#filters.show) .csm-floating-header ~ .shop-backdrop:not([hidden]) { inset: 0; }
  }

  html body.storefront-page main #catalog #filters.show {
    padding: 14px 16px max(16px, env(safe-area-inset-bottom)) !important;
    background: #151a21 !important; border-radius: 0 !important;
    overflow: auto !important; overscroll-behavior: contain;
  }
  html body.storefront-page.full-world[data-world="onepiece"] main #catalog #filters.show { background: #f4e6c5 !important; }
  html body.storefront-page main #catalog #filters.show .sidebar-group-body label:not([hidden]),
  html body.storefront-page main #catalog #filters.show summary { min-height: 44px !important; }
  #filters.show :is(.mobile-filter-close,#clear,#price,#mobile-clear-filters,#apply-filters) { min-height: 44px; }
  #filters.show .mobile-filter-close { min-width: 44px; align-items: center; justify-content: center; }
  #filters.show .mobile-filter-actions {
    position: sticky; bottom: -1px; z-index: 2;
    padding: 9px 0 max(9px, env(safe-area-inset-bottom));
    background: linear-gradient(transparent, #151a21 12%);
  }
  body[data-world="onepiece"] #filters.show .mobile-filter-actions { background: linear-gradient(transparent,#f4e6c5 12%); }
  #filters.show :is(select,input[type="search"],input[type="number"]) { font-size: 16px !important; }
  html body.storefront-page #catalog :is(#sort,#filter-toggle) { min-height: 44px; font-size: 16px !important; }
  html body.storefront-page #catalog #sort { max-width: 100%; }
  html body.storefront-page #catalog .active-filters button { min-height: 44px; }
  @media (max-width: 760px) {
    .storefront-page #catalog :is(#filter-toggle,#sort,#load-more) { scroll-margin-top: 150px; }
  }
  body:has(.csm-floating-header) :is(#catalog,#vault-catalogue,#sf-preview,#upcoming-events,#about,#visit) {
    scroll-margin-top: calc(var(--shop-header-height, 0px) + 12px);
  }
  @media (min-width: 761px) {
    .touch-tablet body:has(.csm-floating-header) :is(#catalog,#vault-catalogue,#sf-preview,#upcoming-events,#about,#visit) { scroll-margin-top: 16px; }
  }

  /* Avoid a tiny image hotspot for the homepage's primary action. */
  @media (max-width: 600px) {
    html body #cs-cinema.worlds-c { aspect-ratio: auto !important; display: grid !important; }
    body:has(.csm-floating-header) [data-singles-shortcut] { min-height: 44px; white-space: normal !important; }
    html body #cs-cinema.worlds-c > img { position: static; display: block; height: auto; aspect-ratio: 1672 / 941; }
    html body #cs-cinema.worlds-c .wc-copy { position: static; }
    html body #cs-cinema.worlds-c .wc-copy a {
      position: static; display: grid; place-items: center;
      width: auto; height: auto; margin: 8px; padding: 8px 14px;
      transform: none; text-indent: 0; white-space: normal; text-align: center;
      background: #f4c477; color: #241508; border-radius: 7px; font-size: 16px;
    }
  }

  /* Phone product actions stay readable; tall dialogs scroll inside the frame. */
  body #product-dialog[open] .product-dialog-bar { position: sticky; top: 0; z-index: 12; }
  body #product-dialog[open] :is(.gallery-toolbar button,.detail-copy button,.detail-copy a.primary,.detail-copy a.secondary) { min-height: 44px; }
  body #product-dialog[open] .detail-photo-thumbs {
    flex-wrap: nowrap; max-width: 100%; min-width: 0; overflow-x: auto;
    overscroll-behavior-inline: contain;
  }
  body #product-dialog[open] .detail-photo-thumbs button { flex-shrink: 0; }
  body :is(#product-dialog,#rarity-zoom,#vault-demo-detail,#sf-zoom,#event-details)[open] {
    overscroll-behavior: contain;
    max-height: calc(100dvh - max(16px, env(safe-area-inset-top) + env(safe-area-inset-bottom)));
  }
  @media (max-width: 600px) {
    body #product-dialog[open] .detail-art #detail-main-photo {
      height: clamp(145px, 38dvh, 310px);
    }
    body #product-dialog[open] .detail-copy { overflow-wrap: anywhere; }
  }
  @media (max-height: 520px) {
    body #product-dialog[open] .detail-art #detail-main-photo {
      height: clamp(144px, 46dvh, 225px);
    }
  }

  @media (max-width: 600px), (max-height: 520px) {
    body #product-dialog[open] .detail-art #detail-main-photo { min-height: 0; }
  }

  /* Singles search, demo cards and photo zoom. */
  .singles-store .sf-filters :is(input:not([type=checkbox]),select) { min-height: 44px; font-size: 16px; }
  .singles-store .sf-search { display: grid; grid-template-columns: minmax(0, 1fr) auto; }
  .singles-store .sf-search input { min-width: 0; }
  .singles-store .sf-more > summary { display: list-item; padding-block: 12px; min-height: 44px; }
  .singles-store :is(#sf-clear,.sf-back,.sf-contact-actions a,.sf-preview-actions button) { min-height: 44px; }
  .singles-store #sf-zoom > div { position: sticky; top: -1px; z-index: 1; background: inherit; }
  .singles-store #sf-zoom img { width: auto; max-width: 100%; height: min(70dvh, 720px); }
  @media (max-width: 600px) {
    .singles-store .sf-filter-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .singles-store .sf-filter-row label { min-width: 0; }
    .singles-store .sf-filter-row label :is(select,input:not([type=checkbox])) { width: 100%; min-width: 0; padding-inline: 6px; }
    .singles-store .vault-hero-copy { padding-top: 12px; }
    .singles-store .vault-hero-inner { min-height: 0; }
  }

  /* Keep the help launcher out of the way of drawers and focused forms. */
  .csm-chat .csm-chat-form input { min-height: 44px; font-size: 16px; }
  .csm-chat .csm-chat-close, .csm-chat .csm-chat-form button { min-width: 44px; min-height: 44px; }
  body.shop-panel-open .csm-chat,
  body:has(.csm-floating-header input:focus) .csm-chat:not(:has(.csm-chat-panel:not([hidden]))) {
    visibility: hidden;
  }
  @media (max-width: 600px) {
    .csm-chat .csm-chat-launch { width: 48px; height: 48px; justify-content: center; padding: 0; font-size: 0; gap: 0; }
    .csm-chat { right: max(10px,env(safe-area-inset-right)); bottom: calc(max(10px,env(safe-area-inset-bottom)) + var(--chat-keyboard,0px)); }
    .csm-chat .csm-chat-panel { max-height: min(520px, calc(100dvh - 86px)); }
    .csm-chat[data-keyboard] .csm-chat-panel { max-height: calc(var(--chat-viewport) - 24px); }
  }

  /* Secondary forms and public events/auctions controls. */
  body:has(.csm-floating-header) :is(main,.csm-chat-panel,dialog) :is(input[type=email],input[type=password],input[type=tel],input[type=text],input[type=number],textarea) {
    font-size: max(16px, 1em);
  }
  #event-details[open] :is(button,a.primary,a.secondary),
  #upcoming-events :is(button,a.primary,a.secondary),
  .wrap :is(.auction-lot-actions button,.bid-panel button,.market-section .filter button,a.lot-card,.detail-copy .button) { min-height: 44px; }
  .wrap :is(.auction-lot-actions,.lot-price,.section-heading) { overflow-wrap: anywhere; }
}
