@use '../abstracts' as *;
@use 'prose';

// ============================================================
// Post content — the_content() (.entry-content)
//
// The shared prose rules live in _prose.scss (the editor uses them too);
// this file adds what only the front end needs: the column, the drop cap,
// alignments and core's classic-content classes.
// ============================================================

.entry-content {
  max-width: 700px; margin: 48px auto 0;

  @include prose.rules;

  // A float at the end must not escape the container
  &::after { content: ""; display: block; clear: both; }

  // ---- Drop cap — the post's first top-level paragraph, when it is long
  // enough to carry one (inc/content.php adds .alonely-drop-cap); core's own
  // .has-drop-cap takes over when an author sets it ----
  > p.alonely-drop-cap::first-letter {
    font-family: $font-serif;
    font-size: 3.2em; float: left; line-height: 0.85;
    padding: 6px 12px 0 0; color: var(--accent-deep);
  }

  // A short paragraph must hold its drop cap, or the next one wraps round it
  // (unit-test-findings: "Core never clears a drop cap")
  > p.alonely-drop-cap::after {
    content: "";
    display: block;
    clear: both;
  }
}

// ---- Wide and full alignments (front end only; the editor sizes them from
// theme.json's layout) ----
// The text column is 700px; wide = 900px, full = the page. cqi reads body
// (a container — base/_base.scss), which is the page without the scrollbar.
.entry-content {
  .alignwide {
    width: min(900px, calc(100cqi - 48px));
    max-width: none;
    margin-left: calc(50% - min(450px, 50cqi - 24px));
  }

  .alignfull {
    width: 100cqi;
    max-width: none;
    margin-left: calc(50% - 50cqi);

    img { border-radius: 0; }
  }

  // Full suits a picture, not a line of text: text-bearing Full blocks start
  // at the page's own gutter (.wrap's padding), as TT1 pads them
  // (unit-test-findings "Full width with text")
  :is(.wp-block-columns, p, .wp-block-heading, .wp-block-list, .wp-block-quote, .wp-block-pullquote, .wp-block-group:not(.has-background)).alignfull {
    padding-left: 24px;
    padding-right: 24px;

    @include below(mobile) {
      padding-left: 18px;
      padding-right: 18px;
    }
  }

  @include below(mobile) {
    .alignwide { width: calc(100cqi - 36px); margin-left: calc(50% - 50cqi + 18px); }
  }
}

// ---- Captions (classic editor) ----
.wp-caption {
  max-width: 100%;

  img { display: block; margin: 0; }
}

// ---- [gallery] shortcode ----
.gallery {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;

  @for $i from 1 through 9 {
    &.gallery-columns-#{$i} { grid-template-columns: repeat($i, minmax(0, 1fr)); }
  }

  @include below(mobile) {
    &[class*="gallery-columns-"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  }
}

.gallery-item {
  margin: 0;
  text-align: center;

  // Square tiles: the larger sizes picked in inc/content.php are not cropped
  img {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: var(--radius-sm);
  }
}

// One column: the image as it is, not a square
.gallery-columns-1 .gallery-item img { aspect-ratio: auto; }

// ---- Embeds — responsive aspect ratios ----
.wp-block-embed {
  .wp-block-embed__wrapper { position: relative; width: 100%; }

  &.wp-has-aspect-ratio .wp-block-embed__wrapper {
    &::before { content: ""; display: block; }
    iframe, video { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: var(--radius-md); }
  }

  &.wp-embed-aspect-16-9 .wp-block-embed__wrapper::before { padding-top: 56.25%; }
  &.wp-embed-aspect-4-3 .wp-block-embed__wrapper::before { padding-top: 75%; }
  &.wp-embed-aspect-21-9 .wp-block-embed__wrapper::before { padding-top: 42.86%; }
  &.wp-embed-aspect-1-1 .wp-block-embed__wrapper::before { padding-top: 100%; }
  &.wp-embed-aspect-9-16 .wp-block-embed__wrapper::before { padding-top: 177.78%; }
}

// ---- Password-protected posts ----
.post-password-form {
  padding: 26px 30px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  background: var(--glass);

  p { margin: 0 0 14px; color: var(--ink-soft); font-size: 15.5px; }

  p:last-of-type {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 12px;
    margin-bottom: 0;
  }

  label {
    display: flex;
    flex: 1 1 14rem;
    flex-direction: column;
    gap: 4px;
    font-size: 14px;
    color: var(--ink-soft);
  }

  input[type="password"] {
    height: 44px;
    padding: 0 4px;
    border: none;
    border-bottom: 1px solid var(--rule-strong);
    background: transparent;
    color: var(--ink);
    font: inherit;
    font-size: 15px;
    outline: none;

    &:focus { border-color: var(--accent); }
    &:focus-visible { border-bottom-width: 2px; border-color: var(--accent-deep); }
  }

  input[type="submit"] {
    height: 44px;
    padding: 0 26px;
    border: none;
    border-radius: $pill-radius;
    background: var(--btn-grad);
    color: var(--on-accent);
    font-family: $font-sans;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
  }
}

// ---- wp_link_pages() — paginated posts ----
.page-links {
  clear: both; // printed after the content, so after any trailing float (TT1)
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 2em;
  padding-top: 20px;
  border-top: 1px solid var(--rule);
  font-size: 14.5px;
  color: var(--ink-faint);

  .post-page-numbers { @include page-chip; }
}
