/* Phone and tablet layout.
 *
 * The desktop design lives in the elements' own `style` attributes — that is the
 * shape the prototype arrived in and it is what a wide screen still gets. A
 * stylesheet rule cannot outrank an inline declaration, so the overrides below
 * are marked `!important`: it is the one thing that does. Everything marked that
 * way is a do-not-exceed-the-desktop override, never a new value on a property
 * nothing else sets.
 *
 * Nothing here reaches past 1080px, so the desktop layout is untouched by
 * construction and `tests/responsive.js` keeps it that way.
 *
 * Breakpoints, widest first:
 *   1080px  tablet landscape  four-column grids lose a column
 *    900px  tablet portrait   the two-column screens stack
 *    720px  phone             drawer menu, two columns, tighter rhythm
 *    480px  small phone       the largest type shrinks, the basket line reflows
 *    360px  narrow phone      the header's own three controls have to fit
 *
 * The drawer is closed from a resize listener in src/component.js once the
 * header shows its own navigation again; MOBILE_NAV_MAX there has to stay equal
 * to the 720 below.
 */

/* ------------------------------------------------------------------ base ---
 * Not a breakpoint: what a touch browser needs to be told at any width.
 */

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* A phone's 100vh is taller than what is on screen while the URL bar is shown,
   which parks the footer below the fold on the short screens. svh is the small,
   stable viewport; browsers without it keep the 100vh from the markup. */
@supports (min-height: 100svh) {
  .site {
    min-height: 100svh !important;
  }
}

/* The header's own navigation is the desktop one. The toggle and the drawer are
   hidden until the phone breakpoint turns them on, so a wide screen never sees
   them and the markup can carry them unconditionally. */
.nav-toggle,
.nav-drawer {
  display: none;
}

.nav-toggle {
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 5px;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  padding: 0;
  background: transparent;
  border: 1px solid #2c2c2c;
  cursor: pointer;
}

.nav-toggle span {
  display: block;
  width: 20px;
  height: 2px;
  background: #ece9e2;
  transition: transform 0.18s ease, opacity 0.18s ease;
}

.nav-toggle[aria-expanded="true"] span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.nav-toggle[aria-expanded="true"] span:nth-child(2) {
  opacity: 0;
}

.nav-toggle[aria-expanded="true"] span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* Anchored to the sticky header, which is the nearest positioned ancestor. It
   must stay `absolute`: the header's backdrop-filter makes it the containing
   block for a fixed child, so `fixed` would not mean the viewport here. */
.nav-drawer {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  flex-direction: column;
  padding: 4px 14px 12px;
  background: #0b0b0b;
  border-bottom: 1px solid #232323;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.55);
}

.nav-drawer.is-open {
  display: flex;
}

.drawer-link {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 50px;
  padding: 0;
  font-family: inherit;
  font-size: 12.5px;
  letter-spacing: 0.16em;
  text-align: left;
  text-transform: uppercase;
  color: #b7b4ac;
  background: none;
  border: none;
  border-bottom: 1px solid #1c1c1c;
  cursor: pointer;
}

.drawer-link:last-child {
  border-bottom: none;
}

/* ------------------------------------------------------------------ 1080 ---
 * Tablet landscape. Four columns of product card stop being readable before the
 * two-column screens need to move.
 */
@media (max-width: 1080px) {
  .grid-catalog {
    grid-template-columns: repeat(3, 1fr) !important;
  }

  .masonry {
    columns: 2 !important;
  }

  .foot-grid {
    grid-template-columns: 1fr 1fr !important;
  }
}

/* ------------------------------------------------------------------- 900 ---
 * Tablet portrait. Every two-column screen becomes one column: a 380px product
 * card next to a 330px description is worse than the description underneath.
 */
@media (max-width: 900px) {
  .split-product,
  .split-cart,
  .split-manifest {
    grid-template-columns: 1fr !important;
  }

  .split-product {
    gap: 24px !important;
  }

  .split-manifest {
    gap: 28px !important;
  }

  /* 78vh of a portrait tablet is most of the screen; the copy only needs room. */
  .hero {
    height: min(70vh, 640px) !important;
    min-height: min(560px, 70svh) !important;
  }

  .hero-sm {
    height: min(52vh, 420px) !important;
  }
}

/* ------------------------------------------------------------------- 720 ---
 * Phone. The header gives up its row of links to the drawer, the grids go to
 * two columns, and every control that a thumb has to hit gets a real height.
 */
@media (max-width: 720px) {
  .site-head {
    gap: 10px !important;
    padding: 10px max(14px, env(safe-area-inset-left)) 10px
      max(14px, env(safe-area-inset-right)) !important;
  }

  .brand {
    gap: 8px !important;
    flex: 1 1 auto !important;
    min-width: 0 !important;
    min-height: 44px;
  }

  /* The wordmark is the only thing in the header that is allowed to give way,
     so a three-figure cart count can never push the row wider than the phone.
     The 360px block below keeps it from having to. */
  .brand-name {
    font-size: 16px !important;
    letter-spacing: 0.12em !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .site-nav {
    display: none !important;
  }

  .nav-toggle {
    display: flex;
  }

  .cart-btn {
    min-height: 44px;
    padding: 9px 11px !important;
    font-size: 10.5px !important;
    letter-spacing: 0.1em !important;
  }

  /* "Весь каталог →", "Назад к каталогу" and "Удалить" are 14px of type with no
     box of their own; a thumb needs the box. Same for the contact link that
     ends the manifesto. */
  .link-sm,
  .cart-remove,
  .contact-link {
    display: inline-flex;
    align-items: center;
    min-height: 38px;
  }

  /* The hero stops being a box with pinned corners and becomes a column: the
     photograph stays an absolute layer behind it, the text is in flow, and the
     bottom of the copy is pushed down by margin-top:auto. Clipping a call to
     action because a headline wrapped one line further is not acceptable. */
  .hero {
    height: auto !important;
    min-height: min(520px, 72svh) !important;
    display: flex !important;
    flex-direction: column;
  }

  .hero-meta {
    position: static !important;
    padding: 16px 18px 0 !important;
    font-size: 10px !important;
  }

  .hero-copy {
    position: static !important;
    margin-top: auto !important;
    padding: 0 18px 26px !important;
  }

  .hero-title {
    font-size: clamp(32px, 11.5vw, 54px) !important;
  }

  .hero-copy p {
    margin: 16px 0 20px !important;
    font-size: 12.5px !important;
  }

  .ticker-run {
    font-size: 12.5px !important;
  }

  .shell {
    padding-left: 18px !important;
    padding-right: 18px !important;
  }

  .sec-title {
    font-size: 23px !important;
  }

  /* Two columns of card is the phone norm: wide enough for a name and a price,
     narrow enough to compare. */
  .grid-featured,
  .grid-catalog,
  .grid-lookbook {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  .card-body {
    padding: 12px 12px 14px !important;
    gap: 9px !important;
  }

  .card-sm-body {
    padding: 11px 11px 13px !important;
    gap: 8px !important;
  }

  .card-name {
    font-size: 14px !important;
    min-height: 0 !important;
  }

  .card-price {
    font-size: 16px !important;
  }

  /* The category chip over the photograph is 9px on a wide screen, where the
     card is 340px across. On a 176px card it needs to be readable instead. */
  .cat-tag {
    font-size: 10.5px !important;
  }

  /* The card's add button is a 34px square on a wide screen; a thumb gets the
     44 it wants, and the icon stays 18px because it is sized in the markup. */
  .add-mini {
    width: 44px !important;
    height: 44px !important;
  }

  .chip,
  .size-chip,
  .opt-row,
  .add-mini,
  .qty-btn {
    transition: opacity 0.12s ease;
  }

  /* Without a pointer there is no hover to lean on: the tap itself lights up. */
  .chip:active,
  .size-chip:active,
  .opt-row:active,
  .add-mini:active,
  .qty-btn:active {
    opacity: 0.65;
  }

  .chip {
    display: inline-flex !important;
    align-items: center;
    min-height: 42px;
    padding: 0 14px !important;
  }

  .size-chip {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    min-width: 50px !important;
    min-height: 46px;
    padding: 0 !important;
  }

  .opt-row {
    min-height: 48px;
    padding: 13px 14px !important;
  }

  .product-title {
    font-size: clamp(24px, 8vw, 40px) !important;
  }

  .price-row {
    flex-wrap: wrap !important;
    gap: 10px !important;
  }

  .lede {
    font-size: 14.5px !important;
  }

  /* A row of buttons that fits a wide screen wraps into a column here, each one
     the full width of the page and 48px tall. */
  .btn-row {
    flex-direction: column !important;
    gap: 10px !important;
  }

  .btn-row > * {
    width: 100% !important;
    text-align: center !important;
    padding: 15px 18px !important;
  }

  .qty-btn {
    width: 40px !important;
    height: 40px !important;
  }

  .cart-thumb {
    width: 68px !important;
    height: 86px !important;
  }

  .checkout {
    padding: 18px !important;
  }

  /* 16px is the smallest font iOS Safari will not zoom the page for when the
     field takes focus. */
  .field {
    font-size: 16px !important;
    min-height: 48px;
    padding: 13px 12px !important;
  }

  .btn-submit {
    min-height: 54px;
  }

  /* The manifest banner's headline is two long lines; on a phone it needs the
     same treatment as the hero. */
  .hero-sm {
    height: auto !important;
    min-height: min(360px, 52svh) !important;
    display: flex !important;
    flex-direction: column;
  }

  .hero-sm-copy {
    position: static !important;
    margin-top: auto !important;
    padding: 22px 18px 26px !important;
  }

  .hero-sm-title {
    font-size: clamp(26px, 8.5vw, 44px) !important;
  }

  .quote {
    margin: 30px 0 !important;
    padding-left: 16px !important;
  }

  .foot-grid {
    grid-template-columns: 1fr !important;
    gap: 26px !important;
  }

  .foot-link,
  .foot-grid a {
    display: flex;
    align-items: center;
    min-height: 38px;
  }

  .foot-legal {
    padding-left: 18px !important;
    padding-right: 18px !important;
    padding-bottom: max(16px, env(safe-area-inset-bottom)) !important;
  }

  /* Orders and the empty basket are centred boxes with a lot of air around
     them; on a phone that air is most of the screen. */
  .order-box {
    padding: 48px 12px !important;
  }
}

/* ------------------------------------------------------------------- 480 ---
 * Small phone. What is left is type that is simply too large for a 320px line,
 * and a basket line whose price column no longer fits beside the controls.
 */
@media (max-width: 480px) {
  .hero-title {
    font-size: clamp(30px, 12vw, 46px) !important;
  }

  .grid-catalog,
  .grid-featured {
    gap: 1px !important;
  }

  .cart-line {
    flex-wrap: wrap !important;
    gap: 12px !important;
    padding: 14px !important;
  }

  .cart-price {
    flex: 1 1 100% !important;
    display: flex !important;
    justify-content: space-between !important;
    align-items: baseline;
    text-align: left !important;
  }

  .split-cart {
    gap: 22px !important;
  }

  .quote {
    font-size: 21px !important;
  }
}

/* ------------------------------------------------------------------- 360 ---
 * The narrowest phones still in use (a 320px screen). The header is the only
 * row that runs out of space there: with the wordmark at 16px the wordmark, the
 * cart and the button come to 309px against the 292px a 320px screen has left
 * after the padding. Twelve pixels of padding and a smaller wordmark buy the
 * ~21px that is missing, so the wordmark is not left to the ellipsis above.
 */
@media (max-width: 360px) {
  .site-head {
    padding-left: max(12px, env(safe-area-inset-left)) !important;
    padding-right: max(12px, env(safe-area-inset-right)) !important;
  }

  .brand-name {
    font-size: 14px !important;
    letter-spacing: 0.08em !important;
  }
}

/* A marquee that never stops is a vestibular problem; the strip still reads. */
@media (prefers-reduced-motion: reduce) {
  .ticker-run {
    animation: none !important;
  }
}
