*,
*::after,
*::before {
  box-sizing: border-box;
}

:root {
  font-size: 14px;
  --color-text: #333;
  --color-bg: #fff;
  --color-link: #929292;
  --color-link-hover: #000;
  --page-padding: 5vw;
  --c-gap: 5vw;
  --r-gap: 5vw;
  --column-size: 80px;
  --column-count: 3;
}

body {
  margin: 0;
  color: var(--color-text);
  background-color: var(--color-bg);
  font-family: 'halyard-display', sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.demo-3 {
  --color-text: #ffffff;
  --color-bg: #5e5d59;
  --color-link: #040404;
  --color-link-hover: #d63937;
}

.demo-4 {
  --color-text: #ffffff;
  --color-link: #fece5c;
  --color-link-hover: #ffffff;
}

@media (scripting: enabled) {
  .loading {
    &::before,
    &::after {
      content: '';
      position: fixed;
      z-index: 10000;
    }

    &::before {
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background: var(--color-bg);
    }

    &::after {
      top: 50%;
      left: 50%;
      width: 100px;
      height: 1px;
      margin: 0 0 0 -50px;
      background: var(--color-link);
      animation: loaderAnim 1.5s ease-in-out infinite alternate forwards;
    }
  }
}

@keyframes loaderAnim {
  0% {
    transform: scaleX(0);
    transform-origin: 0% 50%;
  }

  50% {
    transform: scaleX(1);
    transform-origin: 0% 50%;
  }

  50.1% {
    transform: scaleX(1);
    transform-origin: 100% 50%;
  }

  100% {
    transform: scaleX(0);
    transform-origin: 100% 50%;
  }
}

a {
  text-decoration: none;
  color: var(--color-link);
  outline: none;
  cursor: pointer;

  &:hover {
    text-decoration: underline;
    color: var(--color-link-hover);
  }

  &:focus {
    outline: none;
    background: lightgrey;

    &:not(:focus-visible) {
      background: transparent;
    }

    &:focus-visible {
      outline: 2px solid red;
      background: transparent;
    }
  }
}

.frame {
  padding: 2rem var(--page-padding) 0;
  display: grid;
  z-index: 1000;
  position: relative;
  grid-row-gap: 1rem;
  pointer-events: none;
  justify-items: start;
  grid-template-columns: 100%;
  grid-template-areas:
    'title'
    'back'
    'archive'
    'github'
    'demos'
    'info'
    'tags'
    'sponsor';

  #cdawrap {
    justify-self: start;
    grid-area: sponsor;
  }

  a,
  button {
    pointer-events: auto;
  }

  .frame__title {
    grid-area: title;
    font-size: inherit;
    font-weight: inherit;
    margin: 0;
  }

  .frame__back {
    grid-area: back;
    justify-self: start;
  }

  .frame__archive {
    grid-area: archive;
    justify-self: start;
  }

  .frame__github {
    grid-area: github;
  }

  .frame__tags {
    grid-area: tags;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
  }

  .frame__demos {
    grid-area: demos;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
  }

  .frame__info {
    grid-area: info;
    margin: 0;
    padding: 2px 3px 4px;
    border: 1px solid;
    border-radius: 3px;
    line-height: 0.8;
  }

  @media screen and (min-width: 53em) {
    grid-template-columns: auto auto auto auto auto 1fr;
    grid-template-rows: auto auto auto;
    grid-column-gap: 2rem;
    grid-template-areas:
      'title back github archive tags sponsor'
      'demos demos demos ... ... sponsor'
      'info info info ... ... sponsor';

    #cdawrap {
      justify-self: end;
      text-align: right;
      max-width: 300px;
    }
  }
}

.grid {
  display: grid;
  padding: 10rem var(--page-padding);
  margin: 0 auto;
  grid-template-columns: repeat(var(--column-count), minmax(var(--column-size), 1fr));
  grid-column-gap: var(--c-gap);
  grid-row-gap: var(--r-gap);
  @media screen and (min-width: 65em) {
    --column-count: 7;
  }
}

.grid__item {
  margin: 0;
}

.grid__item-img {
  aspect-ratio: 128 / 160;
  background-size: cover;
  background-position: center;
}

.grid__column {
  display: flex;
  flex-direction: column;
  gap: var(--c-gap);
}

.grid__item-caption {
  font-size: 11px;
  font-weight: 500;
  margin-top: 0.15rem;
}

/* Demo variations */

.demo-2 .grid__item {
  transform: scaleX(var(--si, 1)) scaleY(var(--sy, 1));
  transform-origin: var(--to, 50% 50%);
  will-change: transform;
}

.demo-2 .grid {
  @media screen and (min-width: 65em) {
    --column-count: 7;
  }
}

.demo-3 {
  --c-gap: 5px;
}

.demo-3 .grid {
  @media screen and (min-width: 65em) {
    --column-count: 5;
  }
}

.demo-4 {
  --c-gap: 0vw;
}

.demo-4 .grid__item-caption {
  display: none;
}

.demo-4 .grid {
  padding: 0;
  @media screen and (min-width: 65em) {
    --column-count: 9;
    --page-padding: 0;
  }
}

.demo-4 .frame {
  position: fixed;
  width: 100%;
  top: 0;
  left: 0;
  align-content: start;
  height: 100vh;
  background: linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.85) 0rem,
    rgba(0, 0, 0, 0) 20rem,
    rgba(0, 0, 0, 0) calc(100% - 20rem),
    rgba(0, 0, 0, 0.85) 100%
  );
}
