////
/// Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
///
/// Permission is hereby granted, free of charge, to any person obtaining a
/// copy of this software and associated documentation files (the "Software"),
/// to deal in the Software without restriction, including without limitation
/// the rights to use, copy, modify, merge, publish, distribute, sublicense,
/// and/or sell copies of the Software, and to permit persons to whom the
/// Software is furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
/// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
/// DEALINGS
////

// ----------------------------------------------------------------------------
// Keyframes
// ----------------------------------------------------------------------------

// Pumping heart animation
@keyframes heart {
  0%,
  40%,
  80%,
  100% {
    transform: scale(1);
  }

  20%,
  60% {
    transform: scale(1.15);
  }
}

// ----------------------------------------------------------------------------
// Rules
// ----------------------------------------------------------------------------

// Scoped in typesetted content to match specificity of regular content
.md-typeset {

  // Twitter icon
  .twitter {
    color: #00acee;
  }

  // Mastodon icon - it's not the exact brand color, because that doesn't work
  // well on dark backgrounds, so we lightened it up a bit.
  .mastodon {
    color: #897ff8;
  }

  // Insiders video
  .mdx-video {
    width: auto;

    // Insiders video container
    &__inner {
      position: relative;
      width: 100%;
      height: 0;
      padding-bottom: 56.138%;
    }

    // Insiders video iframe
    iframe {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      overflow: hidden;
      border: none;
    }
  }

  // Pumping heart
  .mdx-heart {
    animation: heart 1000ms infinite;
  }

  // Insiders color (for links, etc.) // remove
  .mdx-insiders {
    color: $clr-pink-500;
  }

  // BETA #####################################################################

  // Badge
  .mdx-badge {
    font-size: 0.85em;

    // Badge with heart
    &--heart {
      --md-typeset-a-color:              hsla(#{hex2hsl($clr-pink-500)}, 1);
      --md-accent-fg-color:              hsla(#{hex2hsl($clr-pink-a200)}, 1);
      --md-accent-fg-color--transparent: hsla(#{hex2hsl($clr-pink-500)}, 0.1);

      color: $clr-pink-500;

      // Animate icon
      .twemoji {
        animation: heart 1000ms infinite;
      }
    }

    // Badge moved to the right
    &--right {
      float: right;
      margin-left: 0.35em;
    }

    // Badge icon
    &__icon {
      padding: px2rem(4px);
      background: var(--md-accent-fg-color--transparent);
      border-start-start-radius: px2rem(2px);
      border-end-start-radius: px2rem(2px);

      // If icon is alone, round corners
      &:last-child {
        border-radius: px2rem(2px);
      }
    }

    // Badge text
    &__text {
      padding: px2rem(4px) px2rem(6px);
      border-start-end-radius: px2rem(2px);
      border-end-end-radius: px2rem(2px);
      box-shadow: 0 0 0 1px inset var(--md-accent-fg-color--transparent);
    }
  }

  // BETA #####################################################################

  // Switch buttons
  .mdx-switch button {
    cursor: pointer;
    transition: opacity 250ms;

    // Button on focus/hover
    &:is(:focus, :hover) {
      opacity: 0.75;
    }

    // Code block
    > code {
      display: block;
      color: var(--md-primary-bg-color);
      background-color: var(--md-primary-fg-color);
    }
  }

  // Two-column layout
  .mdx-columns {

    // Column
    ol,
    ul {
      columns: 2;

      // [mobile portrait -]: Reset columns on mobile
      @include break-to-device(mobile portrait) {
        columns: initial;
      }
    }

    // Column item
    li {
      break-inside: avoid;
    }
  }

  // Language list
  .mdx-flags {
    margin: 2em auto;

    // Language list
    ol {
      list-style: none;

      // Language list item
      li {
        margin-bottom: 1em;
      }
    }

    // Language item
    &__item {
      display: flex;
      gap: px2rem(12px);
    }

    // Language content
    &__content {
      display: flex;
      flex: 1;
      flex-direction: column;

      // Language name
      span {
        display: inline-flex;
        align-items: baseline;
        justify-content: space-between;
      }

      // Language link
      > span:nth-child(2) {
        font-size: 80%;
      }

      // Language code
      code {
        float: right;
      }
    }
  }

  // Social card
  .mdx-social {
    position: relative;
    height: min(#{px2rem(540px)}, 80vw);

    // Social card image on hover
    &:hover .mdx-social__image {
      background-color: rgba(228, 228, 228, 0.05);
    }

    // Social card layer
    &__layer {
      position: absolute;
      margin-top: px2rem(80px);
      transition: 250ms cubic-bezier(0.7, 0, 0.3, 1);
      transform-style: preserve-3d;

      // Social card layer on hover
      &:hover {

        // Social card label
        .mdx-social__label {
          opacity: 1;
        }

        // Social card image
        .mdx-social__image {
          background-color: rgba(127, 127, 127, 0.99);
        }

        // Hide top layers
        ~ .mdx-social__layer {
          opacity: 0;
        }
      }
    }

    // Social card image
    &__image {
      box-shadow:
        px2rem(-5px) px2rem(5px) px2rem(10px)
        rgba(0, 0, 0, 0.05);
      transition: all 250ms;
      transform: rotate(-40deg) skew(15deg, 15deg) scale(0.7);

      // Actual image
      img {
        display: block;
      }
    }

    // Social card label
    &__label {
      position: absolute;
      display: block;
      padding: px2rem(4px) px2rem(8px);
      color: var(--md-default-bg-color);
      background-color: var(--md-default-fg-color--light);
      opacity: 0;
      transition: all 250ms;
    }

    // Transform on hover
    @for $i from 6 through 0 {
      &:hover .mdx-social__layer:nth-child(#{$i}) {
        transform: translateY(#{($i - 3) * -10}px);
      }
    }
  }
}
