/* stylelint-disable no-descending-specificity */
:root {
  /* using inverse to support dark and light variants  */
  --pill-bg-color-selected: var(--s2a-color-background-inverse);
  --pill-rounded-corners-setting: 50px;
}

.tabs {
  position: relative;
  margin: 0;
  background-color: var(--s2a-color-gray-25);
  z-index: 1;

  &.background-transparent {
    background: transparent;
  }

  .tabs-wrapper {
    display: flex;
    width: 100%;
    justify-content: flex-start;
  }

  .tab-indicator {
    position: absolute;
    top: var(--s2a-spacing-2xs);
    bottom: var(--s2a-spacing-2xs);
    left: 0;
    background: var(--pill-bg-color-selected);
    border-radius: var(--pill-rounded-corners-setting);
    transition: transform 0.25s ease, width 0.35s ease;
    pointer-events: none;
    z-index: 0;
  }

  [role='tablist'] {
    position: relative;
    display: flex;
    z-index: 2;

    /* ScrollProps - If content exceeds height of container, overflow! */
    overflow: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scrollbar-width: none; /* Use alongside -webkit-scrollbar */
    background: var(--s2a-color-transparent-black-04);
    border-radius: var(--pill-rounded-corners-setting);

    &::-webkit-scrollbar {
      display: none; /* Safari and Chrome */
    }

    .tab-list-container {
      display: flex;
      width: auto;
      min-width: 300px;
      box-sizing: content-box;
      align-items: center;
      align-self: stretch;
      position: relative; /* for slider */
    }

    .btn-wrapper {
      display: flex;
      padding: var(--s2a-spacing-2xs);
      flex-direction: column;
      align-items: flex-start;
      align-self: stretch;
    }

    button.tab-button {
      color: var(--s2a-color-content-subtle);
      cursor: pointer;
      font-family: var(--body-font-family);
      text-align: center;
      font-style: normal;
      margin: 0;
      border-radius: var(--pill-rounded-corners-setting);
      border: var(--s2a-border-width-md) solid transparent;
      padding: 0 var(--s2a-spacing-lg);
      text-decoration: none;
      transition: color 0.1s ease-in-out;
      outline: none;
      -webkit-tap-highlight-color: transparent;
      white-space: nowrap;
      width: auto;
      position: relative;
      z-index: 1;
      flex: 1 0 auto;
      background: transparent;
      height: 32px;

      &:hover {
        color: var(--s2a-color-content-default);
      }

      &[aria-selected="true"] {
        color: var(--s2a-color-content-inverse);
        background: var(--pill-bg-color-selected);
        transition: background 0s 0.25s, color 0.2s 0s ease-out;
      }

      &:focus-visible {
        outline: var(--s2a-border-width-sm) solid var(--s2a-color-focus-ring-default);
        outline-offset: -2px;
      }
    }
  }

  /* --- Variants below override the defaults above --- */

  &.radio > .tabs-wrapper {
    [role='radiogroup'] {
      overflow: visible;

      .tab-list-container {
        display: flex;
        align-items: center;
        min-width: 0;
        gap: var(--s2a-spacing-md);
        background: var(--s2a-color-background-subtle);
        border-radius: var(--pill-rounded-corners-setting);
        padding: var(--s2a-spacing-sm) var(--s2a-spacing-md);
      }

      .tab-list-label {
        color: var(--s2a-color-content-subtle);
        white-space: nowrap;
        margin: 0;
      }

      .btn-wrapper {
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: var(--s2a-spacing-xs);
      }

      input.tab-button {
        appearance: none;
        box-sizing: border-box;
        margin: 0;
        width: 20px;
        height: 20px;
        min-width: 20px;
        flex: 0 0 auto;
        border: 2px solid var(--s2a-color-gray-400);
        border-radius: 100%;
        background: transparent;
        cursor: pointer;
        outline: none;
        -webkit-tap-highlight-color: transparent;
        transition: border 150ms;
      }

      .tab-button-label {
        color: var(--s2a-color-content-subtle);
        cursor: pointer;
        font-family: var(--body-font-family);
        text-decoration: none;
        white-space: nowrap;
      }

      .btn-wrapper:hover {
        input.tab-button {
          border-color: var(--pill-bg-color-selected);
        }

        .tab-button-label {
          color: var(--s2a-color-content-default);
        }
      }

      input.tab-button:checked {
        border-color: var(--pill-bg-color-selected);
        background: var(--pill-bg-color-selected);
        box-shadow: inset 0 0 0 4px var(--s2a-color-background-subtle);

        + .tab-button-label {
          color: var(--s2a-color-content-default);
        }
      }

      input.tab-button:focus-visible {
        outline: 2px solid var(--s2a-color-blue-800);
        outline-offset: 2px;
      }
    }
  }

  &.radio.dark > .tabs-wrapper {
    [role='radiogroup'] {
      .tab-list-container {
        background: var(--s2a-color-background-default);
      }

      input.tab-button:checked {
        border-color: var(--s2a-color-background-inverse);
        background: var(--s2a-color-background-inverse);
        box-shadow: inset 0 0 0 4px var(--s2a-color-background-default);
      }

      .btn-wrapper:hover input.tab-button {
        border-color: var(--s2a-color-background-inverse);
      }
    }
  }

  &.quiet > .tabs-wrapper {
    [role='tablist'] {
      background: transparent;
      border-radius: 0;
      overflow: visible;

      .tab-list-container {
        min-width: 0;
        gap: var(--s2a-spacing-lg);
      }

      .btn-wrapper {
        padding: 0;
        align-items: center;
        align-self: auto;
      }

      button.tab-button {
        border-radius: 0;
        border-width: 0;
        border-bottom: var(--s2a-border-width-md) solid transparent;
        padding: var(--s2a-spacing-3xs) 0 var(--s2a-spacing-2xs);
        height: auto;
        flex: 0 0 auto;
        color: var(--s2a-color-content-subtle);
        font-family: var(--heading-font-family);

        &[aria-selected="true"] {
          background: transparent;
          color: var(--s2a-color-content-default);
          border-bottom-color: var(--s2a-color-blue-800);
        }
      }
    }
  }

  &.pill.dark > .tabs-wrapper {
    [role='tablist'] {
      background: var(--s2a-color-background-default);

      button.tab-button[aria-selected="true"] {
        background: var(--s2a-color-background-inverse);
        color: var(--s2a-color-content-inverse);
      }

      button.tab-button:hover:not([aria-selected="true"]) {
        color: var(--s2a-color-content-default);
      }

      .tab-indicator {
        background: var(--s2a-color-background-inverse);
      }
    }
  }

  &.radio,
  &.quiet,
  &.pill.dark {
    background: transparent;
  }

  @media (width < 768px) {
    overflow-x: clip;

    .tabs-wrapper {
      width: 100vw;
      position: relative;
      left: 50%;
      transform: translateX(-50%);
      justify-content: flex-start;
      overflow-x: auto;
      scrollbar-width: none; /* Use alongside -webkit-scrollbar */

      &::-webkit-scrollbar {
        display: none;
      }
    }

    [role='tablist'],
    [role='radiogroup'] {
      overflow: visible;
      margin: 0 var(--s2a-spacing-24);
    }

    &.quiet {
      > .tabs-wrapper {
        width: auto;
        margin: 0;
      }

      &.center > .tabs-wrapper {
        justify-content: center;
      }
    }
  }

  @media (width >= 768px) {
    &.center .tabs-wrapper {
      justify-content: center;
    }

    &.right .tabs-wrapper {
      justify-content: flex-end;
    }
  }
}

.tab-content .tabpanel {
  .section {
    position: relative;

    picture.section-background {
      z-index: 0;
    }

    > .content {
      z-index: 1;
      position: relative;
      margin: 0 auto;
    }

    &[class*='-up'] > .content {
      width: 100%;
    }
  }
}

/* Section Metadata - keep for testing ace1205 when merch is available */
.tabs-background-transparent {
  .tabs,
  .tabs [role='tablist'],
  .tabs [role='tablist'] button.tab-button[aria-selected="true"] {
    background: transparent;
  }
}

/* Animation for tab content entrance */
@keyframes tab-content-in {
  from {
    opacity: 0;
    transform: translateY(16px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.tabs.staggered-intro-merch-cards .tab-content-container .tabpanel.tab-entering .section merch-card {
  animation: tab-content-in 0.5s ease both;

  &:nth-child(2) { animation-delay: 0.1s; }
  &:nth-child(3) { animation-delay: 0.2s; }
  &:nth-child(4) { animation-delay: 0.3s; }
  &:nth-child(5) { animation-delay: 0.4s; }
  &:nth-child(6) { animation-delay: 0.5s; }
  &:nth-child(7) { animation-delay: 0.6s; }
  &:nth-child(8) { animation-delay: 0.7s; }
}


@media (prefers-reduced-motion: reduce) {
  .tabs.staggered-intro-merch-cards .tab-content-container .tabpanel.tab-entering .section merch-card {
    animation: none;
  }
}

@media (width >= 1920px) {
  .tabpanel > .section[class*='-up'] > .content,
  .tabpanel > .section[class*='grid-width-'] > .content {
    width: auto;
  }
}
