:root {
    --gap-width: 1rem;
    --line-height: 1.5rem;
    --view-background-color: transparent;

    --stroke-width: .5rem;
    --half-stroke-width: calc(var(--stroke-width) / 2);
    --stroke-color: gray;

    --border-radius: var(--half-stroke-width);
}

html,
body {
    margin: 0
}

.pattern__thumbnail {
    float: left;
    margin: 0;
    line-height: 64px;
    color: purple;
    text-align: center;
}

.tree {
    margin: 0 auto;
    width: fit-content;
    background-color: var(--view-background-color);
}

.subtree {
    display: grid;
    grid-template-columns: auto auto;
    grid-template-rows: auto auto;
    grid-template-areas:
        "parent parent parent parent parent parent"
        "child child child child child child"
    ;
    gap: calc(calc(2 * var(--gap-width)) + var(--line-height)) 0;
    /* vertical gap between parent and child */

    background-color: transparent;
}

.child {
    grid-area: child;
    min-height: 200px;
    margin: 0 auto;

    position: relative;

    /* to position the marker on top */
    &::before {
        /* marker on top */
        display: block;
        content: "";
        height: var(--gap-width);
        width: var(--stroke-width);
        position: absolute;
        right: 50%;
        transform: translate(var(--half-stroke-width), calc(-1 * var(--gap-width)));
        background-color: var(--stroke-color);
    }
}

.parent {
    min-height: 200px;
    margin: 0 calc(var(--gap-width) / 2);

    display: grid;
    align-items: end;

    position: relative;
    /* to position the bracket below */

    /* bracket below is a rectangle with 1-2 visible borders */
    &::after {
        display: block;
        content: "";
        height: calc(var(--gap-width) - var(--half-stroke-width));
        border: 1px solid var(--stroke-color);
        position: absolute;
        bottom: calc(calc(-1 * calc(var(--gap-width) + var(--half-stroke-width))) - var(--line-height));
        background-color: transparent;

        /* right part of the bracket .parent + .parent:after */
        left: calc(calc(0px - var(--gap-width)) - var(--half-stroke-width));
        width: calc(50% + var(--gap-width));

        border-width: 0 var(--stroke-width) var(--stroke-width) 0;
        border-bottom-right-radius: calc(2 * var(--stroke-width));

    }

    /* middle part of the bracket, if there is one .parent before and another one afterwards */
    &+.parent:has(+ .parent) {
        &::after {
            left: calc(-1 * var(--gap-width));
            width: calc(var(--gap-width) + 100%);
            border-width: 0 0 var(--stroke-width) 0;
            border-bottom-right-radius: unset;
        }

        &::before {
            display: block;
            content: "";
            height: var(--gap-width);
            border-left: var(--stroke-width) solid var(--stroke-color);
            position: absolute;
            bottom: calc(calc(-1 * var(--gap-width)) - var(--line-height));
            left: calc(50% - var(--half-stroke-width));
        }
    }

    /* left part of the bracket */
    &:first-child::after {
        left: unset;
        right: calc(calc(0px - var(--gap-width)) - var(--half-stroke-width));
        width: calc(50% + var(--gap-width));

        border-width: 0 0 var(--stroke-width) var(--stroke-width);
        border-bottom-right-radius: unset;
        border-bottom-left-radius: calc(2 * var(--stroke-width));
    }
}

/* reuseImage is an only child, so it doesnt need the curly brace on the bottom */
.subtree.reuseImage>.parent:after {
    border-bottom: none;
    border-radius: 0;
}

/* i want to replace this with a button to edit the reused image */
.subtree.reuseImage>.parent:before {
    display: block;
    content: "";
    height: var(--gap-width);
    border-left: var(--stroke-width) solid var(--stroke-color);
    position: absolute;
    bottom: calc(calc(-1 * var(--gap-width)) - var(--line-height));
    left: calc(50% - var(--half-stroke-width));
}

.patina-node {
    box-sizing: border-box;
    width: 200px;
    min-height: 200px;
    /* padding: .5rem; */

    background: black;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.33);
    background-size: contain;

    position: relative;
    overflow: hidden;
    border-radius: 3px;

    label {
        display: none;
        /* inline-block; */
        width: 30%;
    }

    select {
        width: calc(100% - 1rem);
        margin-top: .5rem;
    }

    input {
        width: 100%;
    }

    p {
        margin: 0;
        background-color: rgba(255, 255, 255, .67);
    }

    /*

    button.active {
        background-color: rgb(216, 215, 137);
        right: 0;
        bottom: .5rem;
        width: 95%;
        border: none;
        padding: .5rem;

    }
        */
}

.patina-node__button-switch {
    position: absolute;
    top: -53px;
    transform: translateX(-50%);
}

select.patina-node__type {
    font-weight: bold;
    width: 100%;
    background: var(--stroke-color);
    border: none;
    color: white;
    padding: 0 1rem;
    margin-top: 0;
    position: relative;
    bottom: 1px;
}

.patina-node__patternConfig {
    background-color: rgba(255, 255, 255, .67);
    width: 85%;
    border-radius: 3px;
    position: absolute;
    left: 0;
    margin-top: .5rem;

    max-height: 115px;
    padding: .5rem;
    overflow: scroll;

    select,
    input {
        width: 100%;
        background: white;
        border-radius: 4px;
        border: 1px solid gray;
        margin: 0 0 1px 0;
    }
}

p.patina-node__purpose {
    position: absolute;
    top: 100%;
    left: 15%;
    right: 15%;
    padding: 0 .5rem;
    margin: 0;
    line-height: var(--line-height);
    color: white;
    background: var(--stroke-color);
}


.jsonpatina-container {
    position: fixed;
    right: 0px;
    top: 0px;
    height: 100%;
    width: 50%;
    min-width: 750px;
    max-width: 100vw;
    z-index: 1;

    transition: transform .2s ease-out;
    transform: translate(calc(100% - 30px), calc(100% - 30px)) scale(.5);
    transform-origin: top left;
}

.jsonpatina-container:focus-within {
    transform: translate(0, 0) scale(1);
}

.jsonpatina-textarea {
    width: 100%;
    height: 100%;
    outline: 1px solid;

    &.error {
        background-color: lightcoral;
    }
}

.button-close-textarea {
    position: absolute;
    top: 50px;
    right: 50px;
}

.button-textarea-to-jsonpatina {
    position: absolute;
    top: 10px;
    left: -200px;
}

.button-draw-jsonpatina {
    position: absolute;
    top: 100px;
    right: 50px;
}

.button-open-new-tab {
    position: fixed;
    right: 0px;
    bottom: 60px;
    z-index: 1;
}

.patina-node__button-filter {
    position: absolute;
    right: -86%;
    width: 100%;
    bottom: 0;
    text-align: left;
}

.filter-dialog {
    text-align: left;
    border: none;
    background-color: rgb(216, 215, 137);
    border-radius: 3px;

    .close-button {
        position: absolute;
        right: .5rem;
        bottom: .5rem;
    }

    h2 {
        margin: 0;
    }

    p {
        margin: .5rem 0;
    }

    form {
        display: flex;
        flex-direction: column;
    }

    .filter-row {
        background-color: white;
        padding: .5rem;
    }

    label {
        width: 10rem;
        display: inline-block;
    }

    .add-select-filter {
        margin: .5rem auto 0 auto;
    }

    p.very-small {
        font-size: .8rem;
        margin-bottom: 0;
    }
}

.filter-dialog::backdrop {
    background: rgb(0 0 0 /.25);
}

body.dialog-open .patina-node {
    opacity: .25;

    &.highlighted {
        opacity: 1;

        .patina-node__type {
            background-color: rgb(216, 215, 137);
            color: black;
        }

        .patina-node__button-filter {
            background-color: rgb(216, 215, 137);
            right: 0;
            bottom: .5rem;
            width: 95%;
            border: none;
            padding: .5rem;
        }
    }
}