@layer base {
  *,
  *::before,
  *::after {
    font: inherit;
    font-variant-numeric: tabular-nums;
    color: inherit;
    -webkit-text-size-adjust: none;
  }
}


html,
body {
  height: 100dvh;
}


body {
  padding-top: var(--app-safe-top);
  padding-left: var(--app-safe-left);
  padding-right: var(--app-safe-right);
  background-color: var(--toolbar-background-color);


  > [purpose="sheet"] {
    border-top-left-radius: var(--sheet-border-radius);
    border-top-right-radius: var(--sheet-border-radius);
    max-height: var(--app-sheet-height);
    padding-bottom: var(--app-safe-bottom);
    outline: none;


    [purpose="heading"] {
      text-box: trim-both cap alphabetic;
      overflow: visible;
    }
  }


  a:is(:link, :visited) {
    color: var(--active-color);
    text-underline-offset: 0.2rem;
  }


  b,
  button,
  button > span {
    font-weight: 600;
  }
}


#game-market-view {
  > [purpose="tablist"] {
    min-height: var(--viewkit-toolbar-height);
    padding-bottom: var(--app-safe-bottom);
    border-top: var(--toolbar-border);
  }
}


:is([is="view"], [is="host"]) {
  > [purpose="heading"]:has(> .logo) {
    padding-block: 0.8rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;


    > .logo {
      display: block;
      align-self: center;
      width: auto;
      height: 4.8rem;
    }


    &:not(:has(> .name)) > .logo {
      height: 6.9rem;
    }


    > .name {
      font-size: 1.5rem;
      font-weight: 600;
      line-height: 1;
      letter-spacing: 0.1rem;
      text-box: trim-both cap alphabetic;
    }
  }


  > header[purpose="toolbar"] {
    align-items: center;
    border-bottom: var(--toolbar-border);


    fieldset:has(> .toolbar-menu) {
      border: none;


      > button[aria-haspopup="dialog"] {
        &[data-menu-hide-focus-ring] { outline: none; }

        &:not([data-filter-active]) > .filter-menu-icon > .funnel-fill,
        &[data-filter-active] > .filter-menu-icon > :not(.funnel-fill) {
          display: none;
        }

        &:has(+ .toolbar-menu[open]) {
          anchor-name: --viewkit-menu-button;
          opacity: 0;
          transition: opacity 0.2s;
        }
      }


      > dialog.toolbar-menu {
        position: absolute;
        outline: none;
        position-anchor: --viewkit-menu-button;
        inset: auto;
        margin: 0;
        box-shadow:
          0px 0px 0px 1px rgba(0, 0, 0, 0.06),
          0px 1px 2px -1px rgba(0, 0, 0, 0.06),
          0px 2px 4px 0px rgba(0, 0, 0, 0.04);
        border: var(--toolbar-border);
        border-radius: calc(1.8rem + 0.8rem);
        padding: 0.8rem;
        max-height: calc(100dvh - var(--app-safe-top) - var(--app-safe-bottom) - 1.6rem);
        overflow: auto;
        color: inherit;
        background: var(--viewkit-light-background);
        display: grid;
        align-content: start;
        gap: 0.8rem;
        transform-origin: top right;

        &:not([anchorto]),
        &[anchorto="top-left"] {
          left: anchor(left);
          top: anchor(top);
          position-try-fallbacks:
            --viewkit-anchor-top-right,
            --viewkit-anchor-bottom-left,
            --viewkit-anchor-bottom-right;
        }

        &[anchorto="top-right"] {
          top: anchor(top);
          right: anchor(right);
          position-try-fallbacks:
            --viewkit-anchor-top-left,
            --viewkit-anchor-bottom-left,
            --viewkit-anchor-bottom-right;
        }

        &:not([open]) {
          display: none;
        }

        &[open] {
          animation: viewkit-menu-open 0.2s ease;
        }

        &::backdrop { background: rgb(0 0 0 / 20%); }

        @supports not (top: anchor(top)) {
          position: fixed;
          inset: 0;
          margin: auto;
        }


        &.list-options {
          width: min(29rem, calc(100vw - var(--app-safe-left) - var(--app-safe-right) - 1.6rem));
          max-height: calc(100dvh - var(--app-safe-top) - var(--app-safe-bottom) - 7.2rem);
          padding: 1.2rem;
          gap: 1.2rem;
          overflow: auto;

          &, & * {
            cursor: default;
            -webkit-user-select: none;
            user-select: none;
          }

          .options-group {
            display: grid;
            gap: 0.4rem;
          }

          h2 {
            font-size: 1.4rem;
            font-weight: 600;
          }

          .switch-row {
            padding-inline: 0.4rem;

            input {
              width: 3rem;
              height: 1.8rem;
              padding: 0.2rem;

              &::before { width: 1.4rem; height: 1.4rem; }
              &:checked::before { translate: 1.2rem; }
            }
          }

          .filter-symbol {
            display: grid;
            place-items: center;
            width: 1.8rem;

            > svg { width: 100%; height: auto; fill: currentColor; }

            &:empty::before {
              content: "";
              width: 1.2rem;
              aspect-ratio: 1;
              border: 1px dashed var(--color-gray);
              border-radius: 0.3rem;
            }
          }

          .filter-count {
            margin-inline-start: auto;
            font-variant-numeric: tabular-nums;
            color: var(--color-gray);
          }

          .options-heading {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 0.8rem;
          }

          .option-action {
            padding-inline: 0.4rem;
            height: 3.2rem;
            font-size: 1.3rem;
            font-weight: 500;
            color: var(--color-blue);
            background: transparent;

            > span { font-weight: inherit; }
          }

          [data-sort-direction] {
            display: inline-flex;
            align-items: center;
            gap: 0.4rem;

            > svg { width: 1.8rem; }

            &[data-reversed] svg { rotate: 180deg; }
          }
        }

        > button {
          justify-content: start;
        }


        > hr {
          margin-block: 0.4rem;
          border: none;
          border-radius: 100vmax;
          height: 0.3rem;
          background: var(--toolbar-border-color);
        }
      }
    }
  }
}


@position-try --viewkit-anchor-top-left {
  inset: auto;
  top: anchor(top);
  left: anchor(left);
}

@position-try --viewkit-anchor-top-right {
  inset: auto;
  top: anchor(top);
  right: anchor(right);
}

@position-try --viewkit-anchor-bottom-left {
  inset: auto;
  bottom: anchor(bottom);
  left: anchor(left);
}

@position-try --viewkit-anchor-bottom-right {
  inset: auto;
  right: anchor(right);
  bottom: anchor(bottom);
}


@keyframes viewkit-menu-open {
  from {
    opacity: 0;
    scale: 0;
  }

  to {
    opacity: 1;
    scale: 1;
  }
}

mark {
  color: inherit;
  background: #ffe6a0;
  border-radius: 0.2rem;
}
