/**
 * @anydigital/bricks
 * Framework-agnostic CSS utility helpers
 */

html {
  /* Prevent horizontal overflow and scrolling, modern way */
  overflow-x: clip;

  /* Font smoothing */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  /* Ensures body takes at least the full height of the viewport (using dynamic viewport height for better mobile support) */
  min-height: 100dvh;

  /* Make the body a flex container with column layout; main fills space */
  display: flex;
  flex-direction: column;
  > main {
    flex-grow: 1;
  }

  /* Hyphenation */
  hyphens: auto;
  /* Links and tables are better (safer) without hyphenation */
  a,
  table {
    hyphens: none;
  }
}

pre {
  padding: 1rem 1.5rem;
  padding-inline-end: 2rem;

  code {
    padding: 0;
  }

  @media screen and (max-width: 767px) {
    border-radius: 0;
  }
}

/* @import "./_prose"; */

/* Breakout CSS - Framework-agnostic utilities for breaking out images and figures */

.breakout {
  /* Prepare the container for breakout elements */
  padding-inline: 10%;
  max-width: calc(10% + 65ch + 10%);

  /* Breakout direct children only */
  & > * {
    &:is(
      table,
      pre,
      figure, video, iframe, canvas,
      /* Only breakout img/picture wrapped in <p> to avoid breaking badges, etc. */
      p > img, p > picture,
      /* Custom utility classes for other tags that need to be broken out */
      .breakout-item,
      .breakout-item-max
    ) {
      width: fit-content;
      min-width: 100%;
      max-width: 125%;
      margin-left: 50%;
      transform: translateX(-50%);
    }

    /* Respect img/picture min-width */
    &:is(p > img, p > picture) {
      min-width: auto;
    }

    /* Tables are so special :( */
    &:is(table):not(.does-not-exist) {
      /* @TODO: add postcss's `:not(.does-not-exist)` to tricks-wiki */
      /* Let them full-bleed */
      width: max-content;
      min-width: auto;
      max-width: 100vw;
      padding-inline: 7.5%;

      /* Let them scroll */
      display: block;
      overflow-x: auto;
      -webkit-overflow-scrolling: touch; /* Smooth scroll for iOS */

      th,
      td {
        padding-inline-start: 0;
      }
    }

    /* Max out the width of the element */
    &.breakout-item-max {
      width: 125% !important; /* !important is for cases like figure.breakout-item-max @TODO */
    }
  }
}

.breakout-all > * {
  &:is(h2, h3, h4, hr):not([class]) {
    position: relative;

    &::before {
      content: "";
      display: block;
      position: absolute;
      background: gray;
      opacity: 12.5%;
    }
  }

  &:is(h2, h3, h4):not([class]) {
    &::before {
      width: 10em;
      right: 100%;
      margin-right: 1rem;
      height: 0.25em;
      top: 50%;
      transform: translateY(-50%);
      background: linear-gradient(to left, gray, transparent);
    }

    &:where(hr + &) {
      &::before {
        display: none !important;
      }
    }
  }
  &:is(hr) {
    height: 0.5rem;
    border: none;
    overflow: visible;

    &::before {
      width: 100vw;
      left: 50%;
      height: 100%;
      transform: translateX(-50%);
    }
  }
}

/* Prism.js */

.token.treeview-part {
  .entry-line {
    width: 2.5em !important;
    opacity: 25%;
  }
  .entry-name:last-child {
    opacity: 50%;

    &::before {
      display: none !important;
    }
  }
}

/* @import "./_util"; */

table.borderless {
  th,
  td {
    border: none;
  }
}

/* Favicons in links @TODO: add to tricks-wiki */

a > i > img {
  max-height: 1.25em;
  margin-top: calc(-0.25em / 2);
  margin-inline-end: 0.25em;
}
