@property --sibling-index {
    syntax: "<number>";
    inherits: false;
    initial-value: 0;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

@page {
    size: A4 portrait;
    margin: 0;
}

:root {
    --char-bg-color: light-dark(#121212, #ededed);
    --char-selected-bg-color: #1475f3;
    color-scheme: dark;

    @media print {
        color-scheme: light;
    }
}

html {
    margin: 0;
    line-height: 1.5;
}

body {
    font-family: ui-sans-serif, sans-serif;
    margin: 0;
    padding: 1rlh;
    block-size: 100dvb;
    background-color: light-dark(#fff, #121212);
    color: light-dark#ededed,(#121212);
}

main {
    inline-size: min(60dvb, 100% - 1rlh);
    container-type: inline-size;
    margin: 0 auto;
    display: grid;
    gap: .5rlh;
}

@scope (.page-header) {
    :scope {
        @media print { display: none; }
    }
    h1 {
        font-size: 2rem;
        margin: 0 0 .5rlh 0;
        text-align: center;
    }
    a:any-link {
        color: currentColor;
        text-decoration: none;
    }
}

@scope (#main-menu) {
    :scope {
        margin: 0;
        padding: 0;
        list-style: inside none;
        display: flex;
        flex-wrap: wrap;
        gap: .5rlh;

        @media print { display: none; }
    }
    button {
        padding: 1.25cqi 5cqi;
        background-color: transparent;
        color: inherit;
        border: 1px solid;
        border-radius: 2cqi;

        &:not(:disabled) {
            cursor: pointer;
        }

        svg {
            color: inherit;
            display: block;
            margin: 0;
            inline-size: 5cqi;
            block-size: 5cqi;
            pointer-events: none;
        }
    }
}

@scope (#grid) {
    :scope {
        font-family: monospace;
        inline-size: 100%;
        aspect-ratio: 1;
        display: grid;
        grid-template-columns: repeat(10, 1fr);
        grid-template-rows: repeat(10, 1fr);
        gap: 2px;
        cursor: pointer;
        -webkit-user-select: none;
        -moz-user-select: none;
        user-select: none;
        touch-action: none;
    }

    .char {
        font-size: 5cqi;
        aspect-ratio: 1;
        display: flex;
        flex-wrap: wrap;
        place-content: center;
        background-color: var(--char-bg-color);
        color: light-dark(#ededed,#121212);
        /* border-radius: .25rlh; */
        transition-property: opacity;
        transition-duration: 50ms;
        @supports (width: calc(sibling-index() * 1em)) {
            transition-delay: calc(sibling-index() * 10ms);
        }
        @supports not (width: calc(sibling-index() * 1em)) {
            transition-delay: calc(var(--sibling-index) * 10ms);
        }

        @starting-style {
            opacity: 0;
        }

        &.selected {
            background-color: var(--char-selected-bg-color);
            color: light-dark(#ededed, #ededed);
            @media print {
                background-color: var(--char-bg-color);
            }
        }
    }
}

#grid.capturing {
    isolation: isolate;
    transform-style: flat;
    color-scheme: light;
    background-color: #fff;
    border: 2px solid;
}
#grid.capturing .char.selected {
    background-color: var(--char-bg-color);
    color: light-dark(#ededed, #121212);
}

@scope (#output) {
    :scope {
        font-family: monospace;
        font-size: 5cqi;
        text-align: center;
        color: hsl(from var(--char-selected-bg-color) h s calc(l * 1.3));
        display: block;
        padding: .25rlh .5rlh;
        border: 1px solid;
        border-radius: .25rlh;

        &:empty {
            border-color: #808080;
        }

        &:empty::after {
            content: attr(data-max) " character password";
            color: #606060;
        }

        &:not(:empty) {
            cursor: pointer;
        }

        @media print { display: none; }
    }
    :scope::selection {
        color: #eee;
        background-color: var(--char-selected-bg-color);
    }
    :scope.copied {
        background-color: var(--char-selected-bg-color);
        color: #eee;
        border-color: var(--char-selected-bg-color);
    }

}
