@import '../settings';
@import '../colours';
@import '../mixins';

$animation-time: 0.25s;

$tile: '.tile';

#{$tile} {
  display: flex;
  justify-content: center;
  position: relative;
  overflow: hidden;
  contain: content;
  background: var(--tile-background, #{$colour-sea-blue});
  text-align: center;
  color: $colour-sky-white;
  aspect-ratio: 1/1;

  &--has-link {
    & > * {
      pointer-events: none;
    }

    & > a,
    & > button,
    & > input,
    & > label {
      pointer-events: initial;
    }

    & > a {
      position: absolute;
      top: 0;
      bottom: 0;
      left: 0;
      right: 0;
      cursor: pointer;
    }
  }

  &.tile-gradient {
    background: linear-gradient(
        45deg,
        rgba(0, 0, 0, 0.2),
        rgba(255, 255, 255, 0.2),
        rgba(0, 0, 0, 0.2)
      )
      var(--tile-background, #{$colour-sea-blue});
  }

  &__header,
  &__subtitle {
    color: $colour-sky-white;
    text-shadow: 0 4px 4px rgba(0, 0, 0, 0.4);
    margin: 0;
    line-height: 1;
  }

  &__header {
    display: block;
    margin-top: 0.5em;
    margin-bottom: 0;
  }

  &__main-content {
    position: relative;
    width: 100%;
  }

  &__description {
    &--animated {
      transition: transform $animation-time linear;
    }
    display: block;
    padding: 0.7rem;
    line-height: 1.6;
    width: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    height: 50%;
    position: absolute;
    margin: 0;
    bottom: 0;
    left: 0;
    overflow-y: hidden;
    transform: translateY(33%);

    pointer-events: none;

    a,
    button {
      pointer-events: initial;
    }
  }

  &__background-image {
    transition: background-color $animation-time ease;
    position: absolute;
    top: 0;
    left: 0;
    opacity: 0.8;
    width: 100%;
    height: 100%;
    padding: $global-padding * 0.5;

    img {
      transition: filter $animation-time ease-out;
      width: 100%;
      height: 100%;
    }
  }

  // Animations
  &:hover,
  &:focus,
  &:focus-within {
    #{$tile}__main-content {
      outline-offset: -1ch;
    }

    #{$tile}__description--animated {
      transform: translateY(0);
      overflow-y: auto;
    }

    #{$tile}__background-image {
      background-color: rgba(0, 0, 0, 0.1);
      img {
        filter: blur(0.1rem);
      }
    }
  }

  // CSS hack to have 1/1 aspect-ratio
  &::before {
    content: '';
    padding-bottom: 100%; // meaning, 100% of the width to bottom padding
  }
}

@media (prefers-reduced-motion) {
  #{$tile} #{$tile}__description {
    transform: translateY(0);
    overflow-y: auto;
  }
}
