/* The same opt-in classes work in Classic, in Gutenberg and on the published page. */
:is(#penci-post-entry-inner, .editor-styles-wrapper, .mce-content-body)
:is(table.te-teaser-table, figure.is-style-te-teasers table):has(> :is(thead, tbody) > tr > :nth-child(2):last-child):not(:has(tr > :nth-child(3), table, [rowspan], [colspan])) {
  display: table;
  table-layout: fixed;
  width: 100%;
  margin: 0;
  border-collapse: collapse;
  overflow: visible;

  & :is(th, td) {
    position: static;
    width: auto;
    box-shadow: none;
    border: 0;
    text-align: left;
    vertical-align: top;
  }
  & th { padding: 10px 12px; font-size: 14px; font-weight: 600; line-height: 1.35; }
  & :is(th, td):first-child { width: 23%; }
  & td { padding: 14px 12px; border-bottom: 1px solid #d6dbe0; background: transparent; color: inherit; }
  & td:first-child {
    font: 600 16px/1.45 Consolas, monospace;
    font-variant-numeric: slashed-zero;
    -webkit-user-select: all;
    user-select: all;
    overflow-wrap: anywhere;
  }
  & td:last-child :is(a:has(img), picture, img) {
    display: block;
    position: static;
    transform: none;
    width: 100%;
    max-width: 100%;
    height: auto;
    margin: 0;
    padding: 0;
    border: 0;
    box-shadow: none;
    background: none;
    float: none;
  }
  /* Gutenberg inserts inline images into table cells with an explicit pixel width. */
  & td:last-child img[style] {
    width: 100% !important;
    height: auto !important;
  }
  & img { border-radius: 6px; object-fit: contain; }
  @media (max-width: 600px) {
    &, & :is(tbody, tr, td) { display: block; width: 100%; max-width: 100%; box-sizing: border-box; }
    & thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
    & tbody tr { margin: 0 0 16px; }
    & tbody td { border: 0; padding: 0 12px; }
    & tbody tr:first-child td:first-child { padding-top: 12px; }
    & tbody td:first-child { width: 100%; margin: 0 0 6px; }
  }
}


/* In a Gutenberg three-column comparison, Soledad's fixed label column
   should fit a word. The table already provides its own scrollport. */
:is(#penci-post-entry-inner, .editor-styles-wrapper, .mce-content-body) :is(table.te-compare-table, figure.is-style-te-compare table):has(> :is(tbody, thead) > tr:first-child > :nth-child(3):last-child) {
  & > :is(thead, tbody, tfoot) > tr > :is(th, td) {
    padding: .5em .65em;
    word-break: normal;
    overflow-wrap: normal;
  }
  @media (max-width: 700px) {
    & > :is(thead, tbody, tfoot) > tr > :is(th, td) {
      font-size: 14px;
    }
  }
  /* A pinned label would cover part of the last data column here. */
  @media (max-width: 375px) {
    & > :is(thead, tbody, tfoot) > tr > :first-child {
      position: static;
    }
  }
  &:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: -2px;
  }
}

@media (max-width: 600px) {
  :is(#penci-post-entry-inner, .editor-styles-wrapper, .mce-content-body) .gallery.is-style-te-steps {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
    margin-block: 0.65em 1em;
  }
  :is(#penci-post-entry-inner, .editor-styles-wrapper, .mce-content-body) .gallery.is-style-te-steps > .gallery-item {
    width: 100%;
    float: none;
    margin: 0;
  }
  :is(#penci-post-entry-inner, .editor-styles-wrapper, .mce-content-body) .gallery.is-style-te-steps > br {
    display: none;
  }
  :is(#penci-post-entry-inner, .editor-styles-wrapper, .mce-content-body) .gallery.is-style-te-steps .gallery-icon a {
    display: block;
    padding: 0;
    background-image: none;
  }
  :is(#penci-post-entry-inner, .editor-styles-wrapper, .mce-content-body) .gallery.is-style-te-steps .gallery-icon img {
    margin: 0;
    padding: 0;
  }
}
:is(#penci-post-entry-inner, .editor-styles-wrapper, .mce-content-body) .gallery.is-style-te-steps .gallery-icon a:focus-visible {
  outline: 2px solid var(--te-control-focus);
  outline-offset: 2px;
}

@media (max-width: 600px) {
  :is(#penci-post-entry-inner, .editor-styles-wrapper, .mce-content-body) .gallery.is-style-te-filmstrip {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: min(84%, 280px);
    align-items: start;
    gap: 12px;
    max-width: 100%;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    scroll-padding-inline: 18%;
    margin-block: 0.65em 1em;
    padding-bottom: 4px;
  }
  :is(#penci-post-entry-inner, .editor-styles-wrapper, .mce-content-body) .gallery.is-style-te-filmstrip > .gallery-item {
    width: 100%;
    min-width: 0;
    float: none;
    margin: 0;
    scroll-snap-align: start;
  }
  :is(#penci-post-entry-inner, .editor-styles-wrapper, .mce-content-body) .gallery.is-style-te-filmstrip > br,
  :is(#penci-post-entry-inner, .editor-styles-wrapper, .mce-content-body) .gallery.is-style-te-filmstrip::after {
    display: none;
  }
  :is(#penci-post-entry-inner, .editor-styles-wrapper, .mce-content-body) .gallery.is-style-te-filmstrip .gallery-icon a {
    display: block;
    padding: 0;
    background-image: none;
  }
  :is(#penci-post-entry-inner, .editor-styles-wrapper, .mce-content-body) .gallery.is-style-te-filmstrip .gallery-icon img {
    display: block;
    width: 100%;
    height: auto;
    margin: 0;
    padding: 0;
  }
  :is(#penci-post-entry-inner, .editor-styles-wrapper, .mce-content-body) .gallery.is-style-te-filmstrip .gallery-icon a:focus-visible {
    outline: 2px solid var(--te-control-focus, #1165f1);
    outline-offset: -3px;
  }
}

/* Modern Gallery blocks contain figure.wp-block-image. Older blocks use a list. */
@media (max-width: 600px) {
  :is(#penci-post-entry-inner, .editor-styles-wrapper) .wp-block-gallery:is(.is-style-te-steps, .is-style-te-filmstrip) {
    &, & > .blocks-gallery-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
    & > .blocks-gallery-grid { grid-column: 1 / -1; width: 100%; }
    &.is-style-te-filmstrip:not(:has(> .blocks-gallery-grid)),
    &.is-style-te-filmstrip > .blocks-gallery-grid {
      grid-template-columns: none;
      grid-auto-flow: column;
      grid-auto-columns: min(84%, 280px);
      overflow-x: auto;
      scroll-snap-type: x proximity;
    }
    & :is(figure.wp-block-image, li.blocks-gallery-item) {
      width: 100% !important; /* WordPress assigns a column-count width with higher specificity. */
      min-width: 0;
      margin: 0;
      scroll-snap-align: start;
    }
    & img { display: block; width: 100%; height: auto; object-fit: contain; }
  }
}

