@import './variables/colors.css';
@import './variables/layout.css';
@import './variables/font.css';
@import './buttons.css';

/**
 * Blog: post list (template-parts/archive.php) and single post (template-parts/single.php).
 * Cards follow the product cards in product-list.css; pills follow .button.outlined.
 */

/* main.blog, not .blog: WordPress also puts "blog" on <body> of the posts page. */
main.blog {
  --blog-radius: var(--border-radius-round);
  --blog-radius-small: 20px;
  --blog-reading-width: 720px;
  /* The page background (Elementor kit) is --beige-light, so surfaces need a visible outline. */
  --blog-surface: var(--beige-lighter);
  --blog-outline: 2px solid var(--beige);

  color: var(--brown);
  /* Same top space as the shop pages (woocommerce.css), so the heading clears the overlapping logo. */
  padding-block: 5em 3em;
}

/* Shared bits */

.blog-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5em;
  margin: 0;
  color: var(--gray);
  font-size: var(--font-size-small);
}

.blog-category {
  display: inline-block;
  color: var(--accent-salmon);
  font-size: var(--font-size-small);
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  text-decoration: none;

  &:hover {
    color: var(--accent-blue);
  }
}

.blog-pill,
.blog-tags a {
  display: inline-grid;
  place-items: center;
  height: 32px;
  padding: 0 1em;
  border: 1px solid var(--brown);
  border-radius: var(--border-radius-round);
  color: var(--brown);
  font-size: var(--font-size-small);
  font-weight: 700;
  text-decoration: none;
  transition: 150ms ease-out;
  transition-property: background-color, color, border-color;

  &:is(:hover, :focus-visible, .is-active) {
    background-color: var(--brown);
    border-color: var(--brown);
    color: var(--beige-light);
  }
}

/* Post list */

.blog-header {
  margin-bottom: 2em;
  text-align: center;

  & .page-heading {
    margin-bottom: 0.5em;
  }
}

.blog-header__description {
  max-width: 40em;
  margin: 0 auto 1em;
}

.blog-categories {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5em;
}

.blog-posts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1em;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* Same tile as .products .product in product-list.css: flat --beige-lighter, round corners, no hover. */
.blog-card {
  display: flex;
  flex-direction: column;
  padding: 1.5em;
  background-color: var(--beige-lighter);
  border-radius: var(--border-radius-round);
}

.blog-card__image {
  display: block;
  overflow: hidden;
  aspect-ratio: 16 / 10;
  border-radius: var(--blog-radius-small);

  & img,
  & .blog-card__placeholder {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  & .blog-card__placeholder {
    background-color: var(--beige);
  }
}

.blog-card__body {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  gap: 0.5em;
  margin-top: 1em;
}

.blog-card__title {
  margin: 0;
  color: var(--brown);
  font-size: var(--font-size-large);
  line-height: 1.25;

  & a {
    color: inherit;
    text-decoration: none;
  }
}

.blog-card__excerpt {
  flex-grow: 1;

  & p {
    margin: 0.25em 0 1em;
  }
}

.blog-card__more.button {
  width: 100%;
  text-align: center;
}

.blog-empty {
  padding: 3em 1em;
  text-align: center;
  font-size: var(--font-size-large);
}

/* Pagination (list and paged posts) */

.blog-pagination {
  margin-top: 2.5em;

  & .nav-links,
  &.page-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5em;
  }

  & .page-numbers,
  &.page-links > :is(a, span) {
    display: inline-grid;
    place-items: center;
    min-width: 40px;
    height: 40px;
    padding: 0 0.75em;
    border: var(--blog-outline);
    border-radius: var(--border-radius-round);
    background-color: var(--blog-surface);
    color: var(--accent-blue);
    font-weight: 700;
    text-decoration: none;
    transition: 150ms ease-out;
    transition-property: background-color, border-color, color;
  }

  & a:hover {
    background-color: var(--accent-salmon);
    border-color: var(--accent-salmon);
    color: var(--beige-light);
  }

  & .current,
  &.page-links > span:not(.page-links-title) {
    background-color: var(--accent-blue);
    border-color: var(--accent-blue);
    color: var(--beige-light);
  }

  & .dots {
    background: none;
    border-color: transparent;
  }
}

/* Single post */

.blog-single__header,
.blog-content,
.blog-single__footer,
.blog-comments {
  max-width: var(--blog-reading-width);
  margin-inline: auto;
}

.blog-single__header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5em;
  margin-bottom: 2em;
  text-align: center;

  & .page-heading {
    margin: 0;
  }
}

.blog-back {
  margin: 2em 0 0;
  text-align: center;
}

.blog-single__image {
  max-width: 1100px;
  margin: 0 auto 2.5em;

  & img {
    display: block;
    width: 100%;
    max-height: 560px;
    object-fit: cover;
    border-radius: var(--blog-radius);
  }
}

.blog-content {
  font-size: 1.0625em;
  line-height: 1.7;

  & > :first-child {
    margin-top: 0;
  }

  & :is(h2, h3, h4) {
    margin: 1.75em 0 0.5em;
    color: var(--brown-dark);
    font-family: var(--serif);
    line-height: 1.25;
  }

  & h2 { font-size: var(--font-size-xxlarge); }
  & h3 { font-size: var(--font-size-xlarge); }
  & h4 { font-size: var(--font-size-large); }

  & p,
  & :is(ul, ol) {
    margin: 0 0 1.25em;
  }

  & :is(ul, ol) {
    padding-inline-start: 1.5em;
  }

  & li + li {
    margin-top: 0.35em;
  }

  & li::marker {
    color: var(--accent-salmon);
  }

  & a {
    text-decoration: underline;
    text-underline-offset: 0.2em;
  }

  & img {
    height: auto;
    border-radius: var(--blog-radius-small);
  }

  & figure {
    margin: 2em 0;
  }

  & figcaption {
    margin-top: 0.5em;
    color: var(--gray);
    font-size: var(--font-size-small);
    text-align: center;
  }

  & blockquote {
    margin: 2em 0;
    padding: 1.25em 1.5em;
    background-color: var(--beige-lighter);
    border-inline-start: 4px solid var(--beige);
    border-radius: 0 var(--blog-radius-small) var(--blog-radius-small) 0;
    color: var(--brown-dark);
    font-family: var(--serif);
    font-size: var(--font-size-large);

    & p:last-child {
      margin-bottom: 0;
    }

    & cite {
      display: block;
      margin-top: 0.5em;
      color: var(--gray);
      font-family: var(--sans);
      font-size: var(--font-size-small);
      font-style: normal;
    }
  }

  & hr {
    width: 80px;
    margin: 2.5em auto;
    border: none;
    border-top: 2px solid var(--beige);
  }

  & :is(pre, code) {
    background-color: var(--beige-lighter);
    border-radius: 8px;
  }

  & code {
    padding: 0.1em 0.35em;
  }

  & pre {
    padding: 1em;
    overflow-x: auto;

    & code {
      padding: 0;
    }
  }

  & table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-small);

    & :is(th, td) {
      padding: 0.5em 0.75em;
      border-bottom: 1px solid var(--beige);
      text-align: start;
    }
  }
}

/* Posts built in Elementor bring their own layout. */
.blog-single--elementor .blog-content {
  max-width: none;
  font-size: inherit;
  line-height: inherit;
}

.blog-single__footer {
  margin-top: 3em;
  padding-top: 2em;
  border-top: 1px solid var(--beige);
}

.blog-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5em;
  margin-bottom: 2em;

  & a::before {
    content: '#';
  }
}

.blog-nav .nav-links {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1em;

  & .nav-next {
    grid-column: 2;
    text-align: end;
  }

  & a {
    display: flex;
    flex-direction: column;
    gap: 0.25em;
    height: 100%;
    padding: 1em 1.25em;
    background-color: var(--beige-lighter);
    border-radius: var(--blog-radius-small);
    text-decoration: none;
  }
}

.blog-nav__label {
  color: var(--gray);
  font-size: var(--font-size-small);
}

.blog-nav__title {
  color: var(--brown-dark);
  font-family: var(--serif);
  font-weight: 700;
}

/* Comments */

.blog-comments {
  margin-top: 3em;

  & :is(.title-comments, .comment-reply-title) {
    color: var(--brown-dark);
    font-family: var(--serif);
    font-size: var(--font-size-xlarge);
  }

  & .comment-list {
    margin: 0 0 2em;
    padding: 0;
    list-style: none;

    & .children {
      list-style: none;
      padding-inline-start: 1.5em;
    }
  }

  & .comment-body {
    margin-bottom: 1em;
    padding: 1.25em 1.5em;
    background-color: var(--beige-lighter);
    border-radius: var(--blog-radius-small);
  }

  & .comment-meta {
    margin-bottom: 0.5em;
    font-size: var(--font-size-small);

    & .avatar {
      border-radius: 50%;
    }
  }

  & .comment-form {
    display: flex;
    flex-direction: column;
    gap: 0.75em;

    & textarea {
      width: 100%;
    }
  }

  & .form-submit .submit {
    --local-primary: var(--accent-blue);
    height: 40px;
    padding: 0 1.5em;
    border: none;
    border-radius: var(--border-radius-round);
    background-color: var(--local-primary);
    color: var(--beige-light);
    font-weight: 700;
    cursor: pointer;
    transition: background-color 150ms ease-out;

    &:hover {
      background-color: var(--accent-salmon);
    }
  }
}

/* Mobile */

@media (max-width: 767px) {
  main.blog {
    padding-bottom: 2em;
  }

  main.blog .page-heading {
    font-size: 1.75em;
  }

  .blog-posts {
    grid-template-columns: 1fr;
  }

  .blog-card {
    padding: 1.25em;
  }

  .blog-single__image img {
    border-radius: var(--blog-radius-small);
  }

  .blog-nav .nav-links {
    grid-template-columns: 1fr;

    & .nav-next {
      grid-column: 1;
    }
  }
}
