/*
composition.css

Goals:
- Provide generic, high-level, flexible layouts as in Cube CSS (cube.fyi).
- Provide utility classes for every technique in Every Layout (every-layout.dev).
- Keep CSS as DRY as possible.

Directions:
1. Apply classes as needed, preferably in layout templates.
*/

@layer composition {
  /* ---------- Stack ---------- */
  .stack {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
  }

  .stack > * {
    margin-block: 0;
  }

  /* https://piccalil.li/blog/my-favourite-3-lines-of-css/ */
  .stack > * + * {
    margin-block-start: var(--layout-padding, 1em);
  }

  .stack:only-child {
    block-size: 100%;
  }

  /* Pushes footer to bottom of window WITH the stack margin.
https://every-layout.dev/layouts/stack#splitting-the-stack */
  .stack > :nth-child(2) {
    margin-block-end: auto;
  }

  /* ---------- Box ---------- */
  .box {
    padding: var(--layout-padding);
    /* border: var(--border); */
  }

  .box * {
    color: inherit;
  }

  .box.invert {
    color: var(--color-dark);
    background-color: var(--color-light);
  }

  /* ---------- Center ---------- */
  .center {
    box-sizing: content-box;
    margin-inline: auto;
    /* max-inline-size: var(--layout-measure); */
  }

  /* ---------- Cluster ---------- */
  .cluster {
    display: flex;
    flex-wrap: wrap;
    gap: var(--layout-padding);
    justify-content: flex-start;
    align-items: center;
  }

  /* ---------- Sidebar ---------- */
  .with-sidebar {
    display: flex;
    flex-wrap: wrap;
    gap: var(--layout-padding);
  }

  .with-sidebar > :first-child {
    flex-basis: var(--layout-measure);
    flex-grow: 1;
  }

  .with-sidebar > :last-child {
    flex-basis: 0;
    flex-grow: 999;
    min-inline-size: 50%;
  }

  /* ---------- Switcher ---------- */

  /* ---------- Cover ---------- */
  .cover {
    display: flex;
    flex-direction: column;
    min-block-size: 80vh;
  }

  .cover > * {
    margin-block: 1rem;
  }

  .cover > :first-child:not(section) {
    margin-block-start: 0;
  }

  .cover > :last-child:not(section) {
    margin-block-end: 0;
  }

  .cover > section {
    margin-block: auto;
  }

  /* ---------- Grid ---------- */
  .grid {
    display: grid;
    grid-gap: var(--layout-padding);
  }

  @supports (inline-size: min(var(--layout-measure), 100%)) {
    .grid {
      grid-template-columns: repeat(
        auto-fit,
        minmax(min(var(--layout-measure), 100%), 1fr)
      );
    }
  }

  /* ---------- Frame ---------- */
  .frame {
    --n: 16;
    --d: 9;
    aspect-ratio: var(--n) / var(--d);
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .frame > img,
  .frame > video {
    inline-size: 100%;
    block-size: 100%;
    object-fit: cover;
  }

  /* ---------- Reel ---------- */
  .reel {
    display: flex;
    /* block-size: 50vh; */
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-color: var(--color-theme) var(--color-dark);
  }

  .reel::-webkit-scrollbar {
    block-size: 1rem;
  }

  .reel::-webkit-scrollbar-track {
    background-color: var(--color-dark);
  }

  .reel::-webkit-scrollbar-thumb {
    background-color: var(--color-light);
    background-image: linear-gradient(
      var(--color-dark) 0,
      var(--color-dark) 0.25rem,
      var(--color-theme) 0.25rem,
      var(--color-theme) 0.75rem,
      var(--color-dark) 0.75rem
    );
  }

  .reel > * {
    flex: 0 0 auto;
  }

  .reel > img {
    block-size: 100%;
    flex-basis: auto;
    inline-size: auto;
  }

  .reel > * + * {
    margin-inline-start: var(--layout-padding);
  }

  /* to implement drag to scroll
https://joebailey.xyz/blog/dragging-to-scroll-with-javascript/ */
  .reel {
    cursor: grab;
  }

  .reel:active {
    cursor: grabbing;
  }

  /* ---------- Impostor ----------  */

  /* ---------- Icon ---------- */
  .icon {
    block-size: 0.75em;
    block-size: 1cap;
    inline-size: 0.75em;
    inline-size: 1cap;
  }
}
