/* Reset, typography, links, focus ring, motion, page transitions and safe areas. */

@layer base {
  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }

  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    /*
     * Anchor links and keyboard focus land clear of the sticky bars: below the bars on top (--chrome-h: the title bar
     * and, on a tablet in portrait, the tabs; the header of the website; nothing on a tablet in landscape) and the
     * category chips, above the tab bar and the home indicator under it. Without the bottom padding a link that
     * gets focus can sit behind the tab bar.
     */
    scroll-padding-top: calc(var(--chrome-h) + var(--chips-h) + var(--s-2));
    scroll-padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + var(--s-2) + var(--toast-band));
  }

  /*
   * Dynamic Type: where the system has a text size (Safari and the web views of iPhone and iPad) the text follows
   * the setting of the person, and every size in rem with it. The font stays the one of the look.
   */
  @supports (font: -apple-system-body) {
    html {
      font: -apple-system-body;
      font-family: var(--font-body);
    }
  }

  /* The tabs are at the top on a tablet in portrait, there is no tab bar to clear. */
  @media (min-width: 600px) and (min-height: 501px), (min-width: 600px) and (pointer: fine) {
    html {
      scroll-padding-bottom: calc(var(--s-4) + var(--toast-band));
    }
  }

  /* Expanded: no chips (the categories are in the sidebar) and no tab bar. */
  @media (min-width: 1024px) {
    html {
      scroll-padding-top: calc(var(--chrome-h) + var(--s-4));
      scroll-padding-bottom: calc(var(--s-4) + var(--toast-band));
    }
  }

  /*
   * While a message is up (above the cart bar, or above the foot of the cart) the keyboard focus scrolls to above it as well: a
   * control that gets focus is not left under the message (the band is the room that the dock keeps for one, --toast-room).
   * The end of the cart page, where the message floats above the foot and the page is no longer for it, keeps that room too
   * (--toast-end, cart.css): scroll padding cannot move the last control of a page that has nothing more to scroll. The script
   * writes the real height of the box of the messages and keeps it when the message goes (toast_controller.js): this rule is the
   * room until it has measured.
   */
  html:has(.toast) {
    --toast-band: var(--toast-room);
    --toast-end: var(--toast-room);
  }

  /*
   * The cart bar, the foot of the cart and the foot of the page of a dish float above the bottom of the page: a link that
   * gets focus scrolls to above them as well (and above the tab bar, which --bottom-bars is). The cart panel has no bar.
   */
  html:has(.cartbar) {
    scroll-padding-bottom: calc(var(--bottom-bars) + var(--cartbar-h) + var(--s-2) + var(--toast-band));
  }

  html:has(.cart-foot),
  html:has(.dish-form--page) {
    scroll-padding-bottom: calc(var(--bottom-bars) + var(--cart-foot-h) + var(--s-2) + var(--toast-band));
  }

  html:has(.cartbar):has(.dish-form--page) {
    scroll-padding-bottom: calc(var(--bottom-bars) + var(--cart-foot-h) + var(--cartbar-h) + var(--s-2) + var(--toast-band));
  }

  @media (min-width: 1024px) {
    html:has(.cartbar):not(:has(.dish-form--page)) {
      scroll-padding-bottom: calc(var(--s-4) + var(--toast-band));
    }
  }

  /* A phone on its side: the chips scroll away, the slim bars stay. */
  @media (pointer: coarse) and (max-height: 500px) {
    html {
      scroll-padding-top: calc(var(--chrome-h) + var(--s-2));
    }
  }

  body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--page);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 1rem;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
  }

  h1,
  h2,
  h3,
  h4,
  h5,
  h6,
  p,
  ul,
  ol,
  dl,
  dd,
  figure,
  blockquote {
    margin: 0;
  }

  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    font-weight: 700;
    line-height: 1.25;
  }

  ul[class],
  ol[class] {
    padding: 0;
    list-style: none;
  }

  img,
  svg,
  video {
    max-width: 100%;
  }

  img {
    display: block;
    height: auto;
  }

  a {
    color: var(--primary);
    text-underline-offset: 0.15em;
  }

  button,
  input,
  select,
  textarea {
    font: inherit;
    color: inherit;
  }

  button,
  [role='button'],
  a,
  input,
  select,
  label {
    touch-action: manipulation;
  }

  /* The hand over what can be clicked is for a mouse; a finger has no pointer to change. */
  @media (hover: hover) and (pointer: fine) {
    a[href],
    button,
    [role='button'],
    label[for],
    select,
    input[type='checkbox'],
    input[type='radio'],
    input[type='submit'] {
      cursor: pointer;
    }
  }

  [hidden] {
    display: none !important;
  }

  address {
    font-style: normal;
  }

  table {
    border-collapse: collapse;
  }

  /* A visible focus ring for keyboard users, on the light page and on the teal header. */
  :focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
  }

  .topbar :focus-visible,
  .hero-band :focus-visible,
  .site-header :focus-visible,
  .sidebar__brand:focus-visible {
    outline-color: var(--focus-on-header);
  }

  /* Smooth scrolling only for people who have not asked for less motion. */
  @media (prefers-reduced-motion: no-preference) {
    html {
      scroll-behavior: smooth;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
      scroll-behavior: auto !important;
    }

    /* No cross-fade between pages either. */
    ::view-transition-group(*),
    ::view-transition-old(*),
    ::view-transition-new(*) {
      animation: none !important;
    }
  }

  /*
   * A page change is a quick cross-fade (Turbo asks the browser for it: the view-transition meta tag in the layout).
   * The bars that every page has stay where they are; only what changes in them fades.
   */
  @media (prefers-reduced-motion: no-preference) {
    ::view-transition-old(root),
    ::view-transition-new(root) {
      animation-duration: 160ms;
      animation-timing-function: ease-out;
    }

    .chrome {
      view-transition-name: chrome;
    }

    .tabbar {
      view-transition-name: tabbar;
    }

    .site-header {
      view-transition-name: site-header;
    }

    .sidebar {
      view-transition-name: sidebar;
    }
  }

  /* Screen titles, category headings: the display font of the look. */
  .display {
    font-family: var(--font-display);
    font-style: var(--display-style);
    font-weight: var(--display-weight);
  }

  .icon {
    display: inline-block;
    flex: none;
    width: 1.375rem;
    height: 1.375rem;
    vertical-align: -0.25em;
  }

  .icon--sm {
    width: 1rem;
    height: 1rem;
    vertical-align: -0.15em;
  }

  /* An icon grows with the text size of the user, except in a control of a fixed size (44px), which it must fit. */
  .icon-btn .icon,
  .add .icon,
  .searchfield__submit .icon,
  .site-header__search-submit .icon,
  .site-header__cart .icon {
    width: min(1.375rem, 24px);
    height: min(1.375rem, 24px);
  }
}
