:root {
    --pages-bg-color: #181A1B;
    --panel-bg-color: #222426;
    --disabled-color: #2D2D2D;
    --hover-bg-color: #2D3033;
    --light-bg-color: #3A3E42;
    --icons-bg-color: #3A3E42;
    --infos-bg-color: #0000;
    --hover-fg-color: #CCD1d6;
    --light-fg-color: #FFD45C;
    --icons-fg-color: #7C848D;
    --infos-fg-color: #6E747C;

    --onlink-color: #49D77E;
    --unlink-color: #F87171;

    --title-sub-color: #A5ACB4;
    --transparent-img:
        linear-gradient(45deg, #0007 25%, transparent 25%, transparent 75%, #0007 75%) 0 0 / 1rem 1rem,
        linear-gradient(-45deg, #0007 25%, transparent 25%, transparent 75%, #0007 75%) 0 0 / 1rem 1rem,
        #FFF2;
}

html {
    font-size: 16px;
}

body *:not(script, style) {
    display: flex;
    box-sizing: border-box;
}

:hover {
    cursor: pointer;
    user-select: none;
}

details[open]:not(:has(summary[class])) {
    z-index: 100;
}

details[open]>summary:not([class])::after {
    position: fixed;
    left: 0;
    top: 0;
    width: 100vw;
    height: 100vh;
    content: '';
}

body {
    background: var(--pages-bg-color);
    margin: 0;
    padding: 0;
    display: flex;
    height: 100%;
    color: var(--hover-fg-color);

    #root {
        height: 100vh;
        width: 100vw;
        gap: 1rem;

        #navigation-panel {
            background: var(--panel-bg-color);
            flex-direction: column;
            flex-shrink: 0;
            margin: 1rem 0 1rem 1rem;
            padding: 1rem;
            border-radius: 0.6rem;
            min-width: 6rem;
            max-width: 16rem;
            width: 16rem;

            #navigation-content {
                flex: 1;
                flex-direction: column;

                .title-bar {
                    justify-content: space-between;
                    flex-direction: row-reverse;
                    align-items: center;
                    margin-bottom: 1rem;

                    .title {
                        flex: 1;
                        font-weight: 700;
                        font-size: 1.2rem;
                    }

                    .collapse-button {
                        padding: 0.5rem;
                        border-radius: 0.5rem;
                        color: var(--icons-fg-color);
                    }

                    .collapse-button:hover {
                        background: var(--light-bg-color);
                        color: var(--hover-fg-color);
                    }
                }

                .title-bar[open] svg {
                    transform: rotate(180deg);
                }

                .header {
                    flex-direction: column;

                    summary {
                        flex: 1;
                        background: var(--hover-bg-color);
                        min-height: 5rem;
                        padding: 0.5rem;
                        border-radius: 0.5rem;
                        align-items: center;

                        #device-thumb {
                            height: 100%;
                            aspect-ratio: 1 / 1;
                            border-radius: 0.5rem;
                            background: var(--transparent-img);
                        }

                        #device-infos {
                            flex-direction: column;
                            margin-left: 0.5rem;
                            flex: 1;

                            .sub-title {
                                color: var(--title-sub-color);
                                font-weight: 600;
                                font-size: 0.75rem;
                                margin-bottom: 0.2rem;
                            }

                            #device-info {
                                justify-content: space-between;
                                align-items: center;
                            }
                        }
                    }

                    #device-list {
                        position: absolute;
                        margin-top: 0.5rem;
                        padding: 0.25rem;
                        background: var(--hover-bg-color);
                        border-radius: 0.5rem;
                        width: 29rem;

                        .list {
                            flex: 1;
                            flex-direction: column;
                            border-radius: 0.5rem;
                            background: var(--panel-bg-color);
                            padding: 0.5rem;
                            gap: 1rem;

                            >div {
                                background: var(--light-bg-color);
                                border-radius: 0.5rem;
                                padding: 0.5rem;
                                font-weight: 600;
                            }

                            >div:not([selected]):hover {
                                background: var(--icons-fg-color);
                            }

                            .device-item {
                                height: 6rem;
                                border: 1px solid transparent;

                                .device-thumb {
                                    height: 100%;
                                    aspect-ratio: 1 / 1;
                                    border-radius: 0.5rem;
                                    background: var(--transparent-img);
                                }

                                .device-infos {
                                    flex: 1;
                                    flex-direction: column;
                                    justify-content: space-between;
                                    margin-left: 0.5rem;

                                    .device-name {
                                        justify-content: space-between;
                                        align-items: center;
                                    }

                                    .device-info {
                                        flex-direction: column;
                                        font-size: 0.75rem;

                                        .firmware-ver::before {
                                            content: "　固件：";
                                        }

                                        .serial-number::before {
                                            content: "序列号：";
                                        }

                                        .status::after {
                                            color: var(--unlink-color);
                                            content: "已断开";
                                        }

                                        .status[linked]::after {
                                            color: var(--onlink-color);
                                            content: "已连接";
                                        }
                                    }
                                }

                                .menu {
                                    flex-direction: column;

                                    .button {
                                        justify-content: center;
                                        height: 2rem;
                                        width: 2rem;
                                        border-radius: 0.3rem;
                                    }

                                    .button:hover {
                                        background: var(--icons-fg-color);
                                    }
                                }
                            }

                            #device-add {
                                justify-content: center;
                            }
                        }

                        .list:has(>:nth-child(3))>.device-item:hover {
                            border-color: var(--light-fg-color);
                        }
                    }

                    summary:hover {
                        background: var(--light-bg-color);
                    }
                }

                .header[open] {
                    svg {
                        transform: rotate(180deg);
                    }

                    summary {
                        background: var(--light-bg-color);
                    }
                }

                #settings {
                    flex: 1;
                    flex-direction: column;
                    align-items: center;
                    margin-top: 1rem;
                    gap: 0.5rem;

                    >div {
                        width: 100%;
                        padding: 0.5rem;
                        border-radius: 0.5rem;
                        align-items: center;
                        color: var(--icons-fg-color);

                        .setting-name {
                            margin-left: 0.5rem;
                            color: var(--hover-fg-color);
                        }
                    }

                    >div:hover {
                        background: var(--hover-bg-color);
                        color: var(--hover-fg-color);
                    }

                    >div[selected] {
                        background: var(--light-bg-color);

                        svg {
                            color: var(--light-fg-color);
                        }
                    }
                }

                #system {
                    flex-direction: column;
                    color: var(--infos-fg-color);
                    gap: 0.5rem;

                    #update {
                        border-radius: 0.5rem;
                        padding: 0.5rem;
                        justify-content: center;
                        background: var(--hover-bg-color);
                        font-weight: 600;
                    }

                    #update:hover {
                        background: var(--light-bg-color);
                        color: var(--light-fg-color);
                    }

                    #system-info {
                        justify-content: center;
                    }
                }
            }
        }

        #navigation-panel:not(:has(.title-bar[open])) {
            width: 6rem;

            #navigation-content {
                .title-bar {
                    justify-content: center;

                    .title {
                        display: none;
                    }
                }

                .header {
                    summary {
                        min-height: 4rem;

                        #device-infos {
                            display: none;
                        }
                    }
                }

                #settings>div {
                    width: auto;

                    .setting-name {
                        display: none;
                    }
                }

                #system {
                    text-align: center;
                    width: 3.5rem;
                }
            }
        }

        #content-panel {
            flex: 1;
            flex-direction: column;
            align-items: center;
            min-width: 64rem;

            #content-panel-header {
                justify-content: space-around;
                background: var(--panel-bg-color);
                margin: 1rem 0;
                min-height: 5rem;
                width: 100%;
                max-width: 76rem;
                border-radius: 0.6rem;

                #profiles {
                    border-radius: 0.6rem 0 0 0.6rem;
                    flex: 1;
                    position: relative;
                    flex-direction: column;
                    justify-content: space-between;

                    summary {
                        flex: 1;
                        justify-content: space-between;
                        align-items: center;

                        #profile {
                            margin-left: 1rem;
                        }

                        #menu-button {
                            gap: 0.5rem;

                            .hotkeys {
                                gap: 0.5rem;

                                >* {
                                    align-items: center;
                                    font-size: 0.8rem;
                                    padding: 0 0.5rem;
                                    border-radius: 0.5rem;
                                    background: var(--icons-bg-color);
                                }
                            }
                        }
                    }

                    #profile-list {
                        width: 100%;
                        position: absolute;
                        margin-top: 0.5rem;
                        padding: 1rem;
                        border-radius: 0.6rem;
                        flex-direction: column;
                        background: var(--hover-bg-color);
                        gap: 0.5rem;

                        .menu {
                            input {
                                flex: 1;
                                margin-right: 1rem;
                                padding: 0 0.5rem;
                                border-radius: 0.4rem;
                                border: 1px solid transparent;
                                background: var(--panel-bg-color);
                                color: var(--hover-fg-color);
                            }

                            .profile-add {
                                padding: 0.5rem 1rem;
                                border-radius: 0.4rem;
                                background: var(--light-bg-color);
                            }
                        }

                        .profile-item {
                            height: 3rem;
                            border-radius: 0.5rem;
                            background: var(--light-bg-color);
                            padding: 0.5rem;
                            align-items: center;
                        }

                        .profile-item:hover {
                            background: var(--icons-fg-color);
                        }
                    }
                }

                #profiles:hover {
                    background: var(--hover-bg-color);
                }

                #profiles[open] {
                    background: var(--hover-bg-color);

                    svg {
                        transform: rotate(180deg);
                    }
                }

                #menubar {
                    flex: 1;
                    flex-direction: row-reverse;
                    align-items: center;
                    margin-right: 1.5rem;

                    #save-to-device {
                        font-weight: 600;
                        align-items: center;
                        padding: 0.5rem 2rem;
                        border-radius: 0.5rem;
                        background: var(--disabled-color);
                        color: var(--infos-fg-color);
                    }

                    #save-to-device[disabled] {
                        [unlock] {
                            display: none;
                        }
                    }

                    #save-to-device:not([disabled]) {
                        background: var(--light-fg-color);
                        color: var(--panel-bg-color);

                        [locked] {
                            display: none;
                        }
                    }
                }
            }
        }
    }
}

#authorization-prompt {
    position: fixed;
    width: 100vw;
    height: 100vh;
    align-items: center;
    justify-content: center;
    background: #0007;

    div {
        background: var(--light-fg-color);
        color: var(--panel-bg-color);
        text-align: center;
        opacity: 0.8;
        border-radius: 0.5rem;
        padding: 5rem;
    }
}

#authorization-prompt[hidden] {
    display: none;
}