@use 'private';

.yfm {
    &-code-floating-container {
        position: relative;

        .yfm-code-button {
            min-width: 20px;
            min-height: 20px;
            flex-shrink: 0;

            //reset default button style
            background: none;
            color: inherit;
            border: none;
            padding: 0;
            font: inherit;
            cursor: pointer;
            transition:
                opacity 0.1s ease-out,
                color 0.15s linear;

            &::before {
                opacity: 0.5;
            }
        }

        &:hover {
            .yfm-code-floating {
                opacity: 1;
            }
        }

        & > pre {
            border-radius: 10px;
            overflow: visible;

            // codeblock has line-wrapping and line-numbers
            code:has(> .yfm-line) {
                display: grid;
                grid-template-columns: auto 1fr;
            }

            code.wrap {
                white-space: pre-wrap;
                overflow-x: hidden;
            }
        }

        .yfm-code-floating {
            position: absolute;
            top: 12px;
            right: 16px;
            z-index: 1;

            opacity: 0;
            transition: opacity 0.1s ease-out;

            display: flex;
            flex-wrap: nowrap;
            gap: 4px;

            &::before {
                $background: var(
                    --yfm-color-code-background,
                    var(--yfm-color-code-background-private)
                );

                content: '';
                position: absolute;
                inset: 0;
                z-index: -1;
                background:
                    linear-gradient($background, $background),
                    var(--yfm-color-base, var(--yfm-color-base-private));
                opacity: 0.5;
                pointer-events: none;
            }

            &:focus,
            &:has(> .yfm-code-button:focus) {
                opacity: 1;
            }
        }

        .yfm-code-icon {
            pointer-events: none;
        }

        .yfm-code-prompt {
            color: var(--yfm-color-hljs-comment-private);
            pointer-events: none;
            user-select: none;
        }
    }

    & &-code-floating-container > pre > code {
        @media screen {
            @supports selector(::-webkit-scrollbar) {
                scrollbar-width: auto;
                scrollbar-color: auto;

                &:not(.wrap) {
                    padding-bottom: 10px;
                    overflow-x: scroll;
                }
            }
        }
    }

    &-clipboard-inline-code {
        transition: 0.3s;

        &:hover {
            cursor: pointer;
            background-color: var(
                --yfm-color-code-hovered-background,
                var(--yfm-color-code-background-hovered-private)
            );
        }
    }
}
