/*
 * Adapted from Glass Button by Petr Knoll
 * https://codepen.io/Petr-Knoll/pen/QwWLZdx
 * https://freefrontend.com/code/2025-05-29-glass-button/
 *
 * MIT License
 * Copyright (c) 2025 Petr Knoll
 *
 * 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 NONINFRINGEMENT. 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 IN THE
 * SOFTWARE.
 */

@property --download-angle-1 {
  syntax: "<angle>";
  inherits: false;
  initial-value: -75deg;
}

@property --download-angle-2 {
  syntax: "<angle>";
  inherits: false;
  initial-value: -45deg;
}

.download-button-wrap {
  --anim--hover-time: 400ms;
  --anim--hover-ease: cubic-bezier(0.25, 1, 0.5, 1);
  display: inline-block;
  position: relative;
  font-size: 1.125rem;
  line-height: 1.25;
  z-index: 2;
  border-radius: 999vw;
  background: transparent;
  pointer-events: none;
  transition: all var(--anim--hover-time) var(--anim--hover-ease);
}

.download-button-shadow {
  --shadow-cutoff: 2em;
  position: absolute;
  width: calc(100% + var(--shadow-cutoff));
  height: calc(100% + var(--shadow-cutoff));
  top: calc(0% - var(--shadow-cutoff) / 2);
  left: calc(0% - var(--shadow-cutoff) / 2);
  filter: blur(clamp(2px, 0.125em, 12px));
  overflow: visible;
  pointer-events: none;
}

.download-button-shadow::after {
  content: "";
  position: absolute;
  z-index: 0;
  inset: 0;
  border-radius: 999vw;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0.1));
  width: calc(100% - var(--shadow-cutoff) - 0.25em);
  height: calc(100% - var(--shadow-cutoff) - 0.25em);
  top: calc(var(--shadow-cutoff) - 0.5em);
  left: calc(var(--shadow-cutoff) - 0.875em);
  padding: 0.125em;
  box-sizing: border-box;
  mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  mask-composite: exclude;
  transition: all var(--anim--hover-time) var(--anim--hover-ease);
  overflow: visible;
  opacity: 1;
}

.download-button {
  --border-width: clamp(1px, 0.0625em, 4px);
  display: block;
  text-decoration: none;
  cursor: pointer;
  position: relative;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  pointer-events: auto;
  z-index: 3;
  background: linear-gradient(
    -75deg,
    rgba(255, 255, 255, 0.28),
    rgba(255, 255, 255, 0.55),
    rgba(255, 255, 255, 0.28)
  );
  border-radius: 999vw;
  box-shadow:
    inset 0 0.125em 0.125em rgba(0, 0, 0, 0.05),
    inset 0 -0.125em 0.125em rgba(255, 255, 255, 0.5),
    0 0.25em 0.125em -0.125em rgba(0, 0, 0, 0.2),
    0 0 0.1em 0.25em inset rgba(255, 255, 255, 0.2),
    0 0 0 0 rgba(255, 255, 255, 1);
  backdrop-filter: blur(clamp(1px, 0.125em, 4px));
  transition: all var(--anim--hover-time) var(--anim--hover-ease);
}

.download-button:hover {
  transform: scale(0.975);
  backdrop-filter: blur(0.01em);
  box-shadow:
    inset 0 0.125em 0.125em rgba(0, 0, 0, 0.05),
    inset 0 -0.125em 0.125em rgba(255, 255, 255, 0.5),
    0 0.15em 0.05em -0.1em rgba(0, 0, 0, 0.25),
    0 0 0.05em 0.1em inset rgba(255, 255, 255, 0.5),
    0 0 0 0 rgba(255, 255, 255, 1);
}

.download-button span {
  position: relative;
  display: block;
  user-select: none;
  font-family: inherit;
  color: #102c40;
  text-shadow: 0em 0.25em 0.05em rgba(0, 0, 0, 0.1);
  transition: all var(--anim--hover-time) var(--anim--hover-ease);
  padding-inline: 1.5em;
  padding-block: 0.875em;
}

.download-button:hover span {
  text-shadow: 0.025em 0.025em 0.025em rgba(0, 0, 0, 0.12);
}

.download-button span::after {
  content: "";
  display: block;
  position: absolute;
  width: calc(100% - var(--border-width));
  height: calc(100% - var(--border-width));
  top: calc(0% + var(--border-width) / 2);
  left: calc(0% + var(--border-width) / 2);
  box-sizing: border-box;
  border-radius: 999vw;
  overflow: clip;
  background: linear-gradient(
    var(--download-angle-2, -45deg),
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0.5) 40% 50%,
    rgba(255, 255, 255, 0) 55%
  );
  z-index: 3;
  mix-blend-mode: screen;
  pointer-events: none;
  background-size: 200% 200%;
  background-position: 0% 50%;
  background-repeat: no-repeat;
  transition:
    background-position calc(var(--anim--hover-time) * 1.25) var(--anim--hover-ease),
    --download-angle-2 calc(var(--anim--hover-time) * 1.25) var(--anim--hover-ease);
}

.download-button:hover span::after {
  background-position: 25% 50%;
}

.download-button:active span::after {
  background-position: 50% 15%;
  --download-angle-2: -15deg;
}

@media (hover: none) and (pointer: coarse) {
  .download-button span::after,
  .download-button:active span::after {
    --download-angle-2: -45deg;
  }
}

.download-button::after {
  content: "";
  position: absolute;
  z-index: 1;
  inset: 0;
  border-radius: 999vw;
  width: calc(100% + var(--border-width));
  height: calc(100% + var(--border-width));
  top: calc(0% - var(--border-width) / 2);
  left: calc(0% - var(--border-width) / 2);
  padding: var(--border-width);
  box-sizing: border-box;
  background:
    conic-gradient(
      from var(--download-angle-1, -75deg) at 50% 50%,
      rgba(0, 0, 0, 0.5),
      rgba(0, 0, 0, 0) 5% 40%,
      rgba(0, 0, 0, 0.5) 50%,
      rgba(0, 0, 0, 0) 60% 95%,
      rgba(0, 0, 0, 0.5)
    ),
    linear-gradient(180deg, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0.5));
  mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  mask-composite: exclude;
  transition:
    all var(--anim--hover-time) var(--anim--hover-ease),
    --download-angle-1 calc(var(--anim--hover-time) * 1.25) ease;
  box-shadow: inset 0 0 0 calc(var(--border-width) / 2) rgba(255, 255, 255, 0.5);
}

.download-button:hover::after {
  --download-angle-1: -125deg;
}

.download-button:active::after {
  --download-angle-1: -75deg;
}

@media (hover: none) and (pointer: coarse) {
  .download-button::after,
  .download-button:hover::after,
  .download-button:active::after {
    --download-angle-1: -75deg;
  }
}

.download-button-wrap:has(.download-button:hover) .download-button-shadow {
  filter: blur(clamp(2px, 0.0625em, 6px));
  transition: filter var(--anim--hover-time) var(--anim--hover-ease);
}

.download-button-wrap:has(.download-button:hover) .download-button-shadow::after {
  top: calc(var(--shadow-cutoff) - 0.875em);
  opacity: 1;
}

.download-button-wrap:has(.download-button:active) {
  transform: rotate3d(1, 0, 0, 25deg);
}

.download-button-wrap:has(.download-button:active) .download-button {
  box-shadow:
    inset 0 0.125em 0.125em rgba(0, 0, 0, 0.05),
    inset 0 -0.125em 0.125em rgba(255, 255, 255, 0.5),
    0 0.125em 0.125em -0.125em rgba(0, 0, 0, 0.2),
    0 0 0.1em 0.25em inset rgba(255, 255, 255, 0.2),
    0 0.225em 0.05em 0 rgba(0, 0, 0, 0.05),
    0 0.25em 0 0 rgba(255, 255, 255, 0.75),
    inset 0 0.25em 0.05em 0 rgba(0, 0, 0, 0.15);
}

.download-button-wrap:has(.download-button:active) .download-button-shadow {
  filter: blur(clamp(2px, 0.125em, 12px));
}

.download-button-wrap:has(.download-button:active) .download-button-shadow::after {
  top: calc(var(--shadow-cutoff) - 0.5em);
  opacity: 0.75;
}

.download-button-wrap:has(.download-button:active) span {
  text-shadow: 0.025em 0.25em 0.05em rgba(0, 0, 0, 0.12);
}

.download-button:focus-visible {
  outline: 2px solid #102c40;
  outline-offset: 4px;
}

@media (width < 480px) {
  .download-button-wrap {
    font-size: clamp(0.75rem, 3.8vw, 0.9375rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  .download-button-wrap {
    --anim--hover-time: 0ms;
  }

  .download-button:hover,
  .download-button-wrap:has(.download-button:active) {
    transform: none;
  }
}
