@layer blocksy, reset, base, layout, components, utilities;

@media (width > 760px) {
  /* Responsive font sizes for Desktop - this is not nested in a layer group and root:root is used in order to override the values assigned in theme.json */
  :root:root {
    --wp--preset--font-size--fs-300: 0.875rem;
    --wp--preset--font-size--fs-400: 1rem;
    --wp--preset--font-size--fs-500: 1.125rem;
    --wp--preset--font-size--fs-600: 1.25rem;
    --wp--preset--font-size--fs-700: 1.5rem;
    --wp--preset--font-size--fs-800: 2rem;
    --wp--preset--font-size--fs-900: 3rem;
    --wp--preset--font-size--fs-1000: 3.75rem;
  }
}

@layer base {
  :root {
    /* 
    * Generate relative and perceptually scaled variations of a base color set in theme.json. 
    * These can then be aliased by semantic variables in semantic-tokens.php, just as you 
    * would with --wp--preset--color variables. 
    * See https://piccalil.li/blog/a-pragmatic-guide-to-modern-css-colours-part-one/ 
    */

    /* Example:
    --green-300: oklch(from var(--wp--preset--color--green-500) calc(l + 0.055) calc(c * 0.09) calc(h - 17)); 
    */
  }
}

@layer blocksy {
  /* Flow spacing for Blocksy's blog posts - needs !important to override theme styles */
  .entry-content.is-layout-flow > * + * {
    margin-block-start: 1em !important;
  }
}

@layer layout {
  /* Selects all elements that have a direct sibling preceding them (for content flow). Added to parent element to ensure spacing between all elements. */
  .flow > * + * {
    margin-block-start: var(--flow-space, 1em);
  }

  .flow[data-flow-space="medium"] > * + * {
    --flow-space: 3em;
  }

  .flow[data-flow-space="large"] > * + * {
    --flow-space: 4.5em;
  }

  .flow[data-flow-space="xlarge"] > * + * {
    --flow-space: 6em;
  }

  .grid-flow {
    display: grid;
    gap: var(--grid-flow-space, 1rem);

    align-content: start;
    justify-items: start;
  }

  /* Layout utility class that creates space between flex items */
  .flex-group {
    display: flex;
    flex-wrap: wrap;
    /* Use the custom property locally in a component, otherwise use the fallback */
    gap: var(--flex-group-gap, 1.5rem);

    &[data-justify="center"] {
      justify-content: center;
    }
  }

  .wrapper {
    --wrapper-max-width: 1130px !important;
    --wrapper-padding: 1rem;

    max-width: var(--wrapper-max-width);
    margin-inline: auto;
    padding-inline: var(--wrapper-padding);

    /* helps to match the Figma file */
    box-sizing: content-box !important;
  }

  .wrapper[data-width="narrow"] {
    --wrapper-max-width: 720px !important;
  }

  .wrapper[data-width="wide"] {
    --wrapper-max-width: 1330px !important;
  }

  .section {
    padding-block: 3.75rem;

    @media (min-width: 760px) {
      padding-block: 8rem;

      &[data-padding="compact"] {
        padding-block: 4.5rem;
      }
    }

    /* 
      * Auto-fit makes grid cells stretch to fill available space while Auto-fill 
      * creates empty grid cells when there are fewer items than the defined 
      * number of columns. Auto-fill maintains the original grid structure even
      * with fewer content items than the number of columns. See https://www.youtube.com/watch?v=OZ6qKoq7RJU
    */
    .grid-auto-fit {
      /* --min-col-size: 500px; */
      display: grid;
      gap: 1rem;
      grid-template-columns: repeat(auto-fit, minmax(min(var(--min-col-size, 300px), 100%), 1fr));
    }

    /* Leaves empty cells if the content is smaller than the minimum column size. */
    .grid-auto-fill {
      /* --min-col-size: 500px; */
      display: grid;
      gap: 1rem;
      grid-template-columns: repeat(auto-fill, minmax(min(var(--min-col-size, 300px), 100%), 1fr));
    }
  }

  .equal-columns {
    display: grid;
    gap: var(--equal-columns-gap, 1rem);
    align-items: var(--column-layout-alignment, start);

    &[data-gap="large"] {
      --equal-columns-gap: 2rem;
    }

    &[data-vertical-alignment="centered"] {
      --column-layout-alignment: center;
    }

    &[data-vertical-alignment="bottom"] {
      --column-layout-alignment: end;
    }

    @media (width > 760px) {
      grid-auto-flow: column;
      grid-auto-columns: 1fr;
    }
  }
}

@layer components {
  /* Hero */
  .hero {
    text-align: center;
    background-size: cover;
    font-size: var(--font-size-md);
    color: var(--text-high-contrast);
  }

  .hero__title {
    font-size: var(--font-size-heading-xl);

    > span {
      display: block;
    }
  }

  /* Mushroom Guide Class is not registered in a framework group - use classic CSS class in Gutenberg editor */
  .mushroom-guide {
    /* Define custom properties scoped to the Mushroom Guide section*/
    --card-title-font-size: var(--font-size-lg);
    --card-title-color: var(--text-high-contrast);

    --card-gap: 0.75rem;
  }

  .faq-bento-grid {
    --card-title-color: var(--text-high-contrast);

    display: grid;
    gap: 1rem;
    grid-template-areas:
      "card-one"
      "card-two"
      "card-three"
      "card-four";

    /* Assign grid areas to the card child elements */
    .card:nth-child(1) {
      grid-area: card-one;
    }
    .card:nth-child(2) {
      grid-area: card-two;
    }
    .card:nth-child(3) {
      grid-area: card-three;
    }
    .card:nth-child(4) {
      grid-area: card-four;
    }

    /* Ensure the images fill the space assigned to them */
    .card > img {
      height: 100%;
      object-fit: cover;
      /* object-position: top left; */
    }

    @media (width > 600px) {
      grid-template-columns: repeat(2, 1fr);

      /* 2 sets of quotation marks represent 2 rows of the grid */
      grid-template-areas:
        "card-one card-two"
        "card-three card-four";

      /* alternate image placement from the top to the bottom for even cards. Avoid doing this if your card has a focusable element like a link or button. */
      .card:nth-child(even) img {
        order: 3;
      }
    }

    @media (width > 900px) {
      grid-template-columns: repeat(3, 1fr);

      grid-template-areas:
        "card-one card-two card-four"
        "card-three card-three card-four";

      /* Adjust the image size and placement in the third card to fill in the empty space */
      .card:nth-child(3) {
        display: grid;
        grid-template-columns: 300px 1fr;

        img {
          grid-column: 1;
          grid-row: 1 / 3;
        }
      }
    }
  }

  /* Card Flex Layout */
  .card {
    /* Flexbox is preferred over grid for more flexible placement of the child elements */
    display: flex;
    flex-direction: column;
    /* Use the custom property locally in a component, otherwise use the fallback */
    gap: var(--card-gap, 1rem);
    padding: 1rem;
    background-color: var(--background-light);
    border-radius: var(--border-radius-3);

    img {
      border-radius: var(--border-radius-2);
    }
  }

  .card__title {
    /* Use the custom property locally in a component, otherwise use the fallback */
    font-size: var(--card-title-font-size, var(--font-size-heading-sm));

    color: var(--card-title-color, var(--text-brand));
  }

  .card__note {
    margin-top: auto;
    background-color: var(--background-extra-light);
    padding: 0.75rem;
    border-radius: var(--border-radius-2);
  }

  /* Button */
  .button {
    display: inline flex;
    cursor: pointer;
    font-family: var(--ff-heading);
    font-weight: 700;
    font-size: var(--font-size-md);
    background-color: var(--background-accent-main);
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius-1);

    &:hover,
    &:focus-visible {
      background: var(--background-accent-light);
      color: var(--text-high-contrast);
    }
  }

  .button[data-button="secondary"] {
    background-color: var(--text-brand-light);
    color: var(--text-high-contrast);

    &:hover,
    &:focus-visible {
      background: var(--text-brand);
    }
  }

  select {
    font-family: var(--ff-heading);
    background-color: var(--background-accent-main) !important;
    color: var(--text-high-contrast) !important;
    padding: 0.5rem 0.5rem 0.5rem 1rem !important;
    border: 0;
    border-radius: var(--border-radius-2) !important;
    /* .flex-group layout utility class used */

    /* reset theme overrides */
    width: initial !important;
    height: initial !important;
  }

  .tag-list {
    /* .flex-group layout utility class used */

    > li {
      font-family: var(--ff-heading);
      font-size: var(--font-size-sm);
      color: var(--text-high-contrast);
      padding: 0 0.5rem;
      background-color: var(--tag-background);
      border-radius: var(--border-radius-1);

      &[data-edible="edible"] {
        --tag-background: var(--background-accent-main);
      }
      &[data-edible="toxic"] {
        --tag-background: var(--wp--preset--color--red-500);
      }

      &[data-season="summer"] {
        --tag-background: var(--background-accent-main);
      }
      &[data-season="fall"] {
        --tag-background: var(--wp--preset--color--orange-500);
      }
      &[data-season="spring"] {
        --tag-background: var(--wp--preset--color--teal-500);
      }
    }
  }
}

@layer utilities {
  .text-center {
    text-align: center;
  }
  .text-brand {
    color: var(--text-brand);
  }
  .text-high-contrast {
    color: var(--text-high-contrast);
  }

  .section-title {
    font-size: var(--font-size-heading-lg);
  }

  .background-main {
    background-color: var(--background-main);
  }
  .background-light {
    background-color: var(--background-light);
  }
  .background-extra-light {
    background-color: var(--background-extra-light);
  }
  .background-dark {
    background-color: var(--background-dark);
  }
  .background-extra-dark {
    background-color: var(--background-extra-dark);
  }

  .background-accent {
    background-color: var(--background-accent-dark);
  }

  .font-size-heading-sm {
    font-size: var(--font-size-heading-sm);
  }
  .font-size-heading-regular {
    font-size: var(--font-size-heading-regular);
  }
  .font-size-heading-lg {
    font-size: var(--font-size-heading-lg);
  }
  .font-size-heading-xl {
    font-size: var(--font-size-heading-xl);
  }

  .font-size-sm {
    font-size: var(--font-size-sm);
  }
  .font-size-regular {
    font-size: var(--font-size-regular);
  }
  .font-size-md {
    font-size: var(--font-size-md);
  }
  .font-size-lg {
    font-size: var(--font-size-lg);
  }

  [hidden] {
    display: none;
  }

  .visually-hidden {
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    height: 1px;
    overflow: hidden;
    position: absolute;
    white-space: nowrap;
    width: 1px;
  }
}
