:root {
    --grass-colour: #006000;
}

* {
    box-sizing: border-box;
    user-select: none;
    transition: all 0.2s ease-in-out;

    &:disabled {
        cursor: not-allowed;
    }

    .hidden {
        display: none !important;
    }
}

body {
    background-color: #112233;
    font-family: 'Roboto', Arial, sans-serif;
    font-weight: bold;
    font-size: 16px;
    color: #ffffff;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100svh;
    overflow: hidden;
    overscroll-behavior: none;
}

body.raceMode {
    #stadiumContainer {
        grid-area: 1 / 2 / 3 / 4 !important;
    }

    .garageContainer,
    .neuralNetworkContainer {
        opacity: 0;
        position: relative;
        translate: 375px 0;
        pointer-events: none;
    }

    .naturalSelectionContainer {

        .inputControlContainer>.option:not(:has(#tickLimit)),
        .statusBoard {
            opacity: 0;
            translate: -100px 0;
            pointer-events: none;
        }
    }

    .miscellaneousContainer {
        grid-area: 1 / 4 / 3 / 5 !important;
    }

    .leaderboardContainer {
        .id {
            display: initial !important;
        }

        .generation {
            display: none !important;
        }
    }

    .tipsContainer {
        .tips {
            opacity: 0.5 !important;
            width: 0 !important;
        }
    }
}

input:invalid,
input:user-invalid {
    background-color: #ff0000a0 !important;
}

.button {
    border: 1px solid var(--buttonColour);
    color: #ffffff;
    background-color: #ffffff20;
    font-weight: bold;
    padding: 3px 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 5px;
    cursor: pointer;

    &:hover {
        background-color: var(--buttonColour);
        color: #000000;
    }
}

.outline {
    border-radius: 10px;
    outline: 2px solid #ffffff60;
}

#whatButton {
    --size: 60px;

    font-size: 40px;
    width: var(--size);
    height: var(--size);
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background-color: #ffffff20;
    color: #ffffff;
    border: 5px solid #ffffff;
    cursor: help;

    &:hover {
        background-color: #ffffff40;
    }
}

#mainContainer:not(:has(#whatButton:hover)) {
    & .whatText {
        display: none;
    }
}

.whatText {
    position: absolute;
    z-index: 99;
    font-size: 60px;
    background-color: #000000a0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    text-align: center;

    translate: calc(var(--padding) * -1) calc(var(--padding) * -1);
}

#mainContainer {
    display: grid;
    grid-template-columns: 375px 600px 375px 145px;
    grid-template-rows: repeat(2, 300px) auto;
    grid-column-gap: 10px;
    grid-row-gap: 10px;
    padding: 5px;
    overflow: hidden;
    position: relative;

    &>div {
        overflow: hidden;
    }

    &>#stadiumContainer {
        grid-area: 1 / 2 / 3 / 3;

        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        background-color: var(--grass-colour);
        position: relative;
        overscroll-behavior: none;

        .tutorialText {
            position: absolute;
            bottom: 0;
            left: 0;
            z-index: 99;
            pointer-events: none;
            font-size: 12px;
            color: #ffffff80;
            font-weight: normal;
            padding: 5px 10px;
        }

        #clearStadiumButton {
            position: absolute;
            bottom: 0;
            right: 0;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 5px;
            cursor: pointer;
            color: #ffffff;
            font-weight: bold;
            text-shadow: 0 0 5px #000000;
            border: none;
            background-color: #ff6060;
            border-top-left-radius: 5px;
            z-index: 99;
            text-decoration: underline;
            font-size: 12px;

            &:hover {
                background-color: #ff0000;
            }
        }

        canvas {
            position: absolute;
            cursor: none;
            overscroll-behavior: none;
        }

        #hintCanvas {
            z-index: 10;
        }

        #carCanvas {
            z-index: 5;
        }

        #trackCanvas {
            z-index: 2;
        }
    }

    &>.garageContainer {
        grid-area: 1 / 3 / 2 / 4;

        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;

        .garageCanvasContainer {
            display: flex;
            align-items: center;
            justify-content: center;
            position: relative;

            #frontText,
            #backText {
                --padding: 20px;

                position: absolute;
                z-index: 1;
                font-size: 20px;
                color: #ffffff;
                display: flex;
                align-items: center;
                justify-content: center;
                text-align: center;
                overflow: visible;
                text-wrap: nowrap;
                width: 0;
                height: 0;
                left: 50%;
            }

            #frontText {
                top: var(--padding);
            }

            #backText {
                bottom: var(--padding);
            }
        }

        #garageCanvas {
            background-color: var(--grass-colour);
        }

        .probeAngleContainer {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            gap: 2px;
            height: 280px;
            margin: 10px;

            &>#probeAngles {
                padding-inline: 5px;
                resize: none;
                min-width: 55px;
                max-width: 55px;
                flex-grow: 1;
                scrollbar-width: thin;
                text-align: right;
                background-color: #ffffff20;
                border: none;
                color: #ffffff;
                border-radius: 2px;
                font-family: 'Cascadia Code', 'Courier New', Courier, monospace;
                font-weight: bold;
            }
        }
    }

    &>.neuralNetworkContainer {
        grid-area: 2 / 3 / 3 / 5;

        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: center;
        padding: 10px;
        gap: 10px;

        .title {
            align-self: center;
            text-decoration: solid underline;
            margin-bottom: 10px;
        }

        .inputControlContainer {
            flex-grow: 1;
            height: 100%;
            display: flex;
            flex-direction: column;
            align-items: flex-end;
            justify-content: center;
            gap: 2px;

            label {
                cursor: help;
                font-weight: normal;
            }
        }

        .diagramContainer {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: space-between;
            margin-left: 10px;
            margin-right: 15px;
        }

        #layerContainer {
            --labelTop: -25px;

            display: flex;
            flex-direction: row;
            align-items: center;
            justify-content: space-between;
            width: 100%;
            height: 30px;
            position: relative;
            margin-top: calc(var(--labelTop) * -1);

            .inputLayerContainer,
            .hiddenLayersContainer,
            .outputLayerContainer {
                display: flex;
                flex-direction: column;
                align-items: center;
                justify-content: center;
                text-align: center;
                width: 0;
                overflow: visible;
                height: 100%;
            }

            .hiddenLayersContainer {
                flex-grow: 1;
                padding-inline: 35px;
            }

            .layerLabel {
                top: var(--labelTop);
                position: absolute;
                display: flex;
                align-items: center;
                justify-content: center;
                width: 0;
                text-align: center;
            }

            #hiddenLayers {
                height: 100%;
                display: flex;
                flex-direction: row;
                align-items: center;
                justify-content: center;
                background-color: #ffffff20;
                color: #ffffff;
                text-align: center;
                padding: 0;
                margin: 0;
                border: none;
                border-radius: 5px;
                resize: none;
                font-size: 20px;
                height: 100%;
                line-height: 30px;
                overflow: hidden;
                width: 100%;
                font-family: 'Cascadia Code', 'Courier New', Courier, monospace;
                font-weight: bold;

                &:disabled {
                    background-color: #ffffff40;
                }
            }
        }
    }

    &>.naturalSelectionContainer {
        grid-area: 1 / 1 / 2 / 2;

        --padding: 10px;
        display: flex;
        flex-direction: column;
        padding: var(--padding);
        gap: 10px;

        .inputControlContainer {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            gap: 2px;

            .option {
                display: flex;
                flex-direction: row;
                align-items: center;
                justify-content: space-between;
                width: 100%;

                input {
                    width: 100px;
                    text-align: right;
                    padding-right: 5px;
                    background-color: #ffffff20;
                    border: none;
                    color: #ffffff;
                    border-radius: 2px;
                    font-family: 'Cascadia Code', 'Courier New', Courier, monospace;
                    font-weight: bold;

                    &::-webkit-inner-spin-button,
                    &::-webkit-outer-spin-button {
                        -webkit-appearance: none;
                        margin: 0;
                    }

                    &[type=checkbox] {
                        width: initial;
                    }
                }
            }

            label {
                cursor: help;
                font-weight: normal;
            }
        }

        .statusBoard {
            flex-grow: 1;
            outline: 2px solid #ffffff20;
            border-radius: 5px;
            background-color: #00000060;

            display: flex;
            flex-direction: column;
            overflow: hidden;

            .header,
            .row {
                display: grid;
                grid-template-columns: 1fr 2fr 2fr 2fr;
                font-weight: normal;
            }

            .header {
                padding-block: 3px;
                background-color: #ffffff20;

                div {
                    text-align: center;
                    position: relative;

                    &:not(:last-child)::after {
                        content: '';
                        position: absolute;
                        top: -50vh;
                        right: 0px;
                        display: block;
                        height: 100vh;
                        width: 1px;
                        background-color: #ffffff20;
                    }
                }
            }

            .row {
                padding-block: 2px;

                div {
                    text-align: right;
                    padding-right: 10px;
                    font-family: 'Cascadia Code', 'Courier New', Courier, monospace;
                }
            }

            .scroll {
                overflow-y: auto;
                direction: rtl;
                flex-grow: 1;

                scroll-snap-type: proximity;
                scrollbar-width: thin;
                scrollbar-color: #ffffff40 #00000040;

                * {
                    direction: ltr;
                }
            }
        }

        .bottom {
            display: flex;
            flex-direction: row;
            align-items: center;
            justify-content: space-between;
            gap: 10px;

            #tickCounter {
                display: flex;
                align-items: center;
                justify-content: center;
                flex-grow: 1;
                height: 100%;
                background-color: #ffffff20;
                position: relative;
                overflow: hidden;
                border-radius: 5px;
                font-weight: normal;

                &::after {
                    background-color: #00aa0080;
                    content: '';
                    position: absolute;
                    top: 0;
                    left: calc(var(--progress) - 100%);
                    z-index: -1;
                    width: 100%;
                    height: 100%;
                }
            }
        }
    }

    &>.leaderboardContainer {
        grid-area: 2 / 1 / 3 / 2;

        display: flex;
        flex-direction: column;
        align-items: center;

        .leaderboardTableContainer {
            display: flex;
            flex-direction: column;
            flex-grow: 1;
            overflow: hidden;
            width: 100%;
        }

        .id,
        .header>.id,
        .entry>.id {
            display: none;
            text-align: center;
            padding: 0;
        }

        .entry>.id {
            word-break: break-all;
        }

        .header,
        .entry {
            display: grid;
            grid-template-columns: 1fr 1fr 1.5fr 1.2fr 1.5fr 1.5fr;
        }

        .header {
            padding-block: 8px;
            background-color: #ffffff20;

            div {
                text-align: center;
                position: relative;
                cursor: help;

                &:not(:last-child)::after {
                    content: '';
                    position: absolute;
                    top: -500vh;
                    right: 0px;
                    display: block;
                    height: 1000vh;
                    width: 1px;
                    background-color: #ffffff20;
                    pointer-events: none;
                }
            }
        }

        .entry {
            padding-block: 5px;

            div {
                display: flex;
                align-items: flex-end;
                justify-content: flex-end;
                cursor: pointer;
                overflow: visible;
                text-align: right;
                padding-right: 10px;
                font-weight: normal;
                font-family: 'Cascadia Code', 'Courier New', Courier, monospace;
                font-size: 14px;
            }

            &.selected {
                background-color: #f8f8ff;
                color: #000000;
            }
        }

        .scroll {
            overflow-y: auto;
            direction: rtl;
            flex-grow: 1;
            background-color: #00000040;

            scroll-snap-type: proximity;
            scrollbar-width: thin;
            scrollbar-color: #ffffff40 #00000040;

            * {
                direction: ltr;
            }
        }

        .leaderboardBottomBar {
            width: 100%;
            padding: 10px;
            display: flex;
            flex-direction: row;
            align-items: center;
            justify-content: space-between;
        }

        #exportSelectedCarButton {
            --buttonColour: #88ff88;
        }

        #resetLeaderboardButton {
            --buttonColour: #ff8888;
        }
    }

    &>.miscellaneousContainer {
        grid-area: 1 / 4 / 2 / 5;

        display: flex;
        flex-direction: column;
        align-items: flex-end;
        justify-content: flex-start;
        gap: 10px;
        font-size: 14px;

        #resetSettingsButton {
            --buttonColour: #ff8888;
        }

        #importCar {
            --buttonColour: #8888ff;
        }

        .raceModeContainer {
            display: flex;
            flex-direction: row;
            align-items: center;
            justify-content: center;
            gap: 5px;
            background-color: #ffffff20;
            padding: 2px 8px;
            border-radius: 5px;
            border: 1px solid #00ff0080;
        }

        .scoring {
            display: flex;
            flex-direction: column;
            align-items: flex-start;
            justify-content: flex-start;
            background-color: #ffffff20;
            padding: 5px;
            border-radius: 5px;
            align-self: flex-start;

            width: 100%;
            flex-grow: 1;
            font-weight: normal;
            font-size: 12px;
            overflow: auto;
            scrollbar-width: thin;
            scrollbar-color: #ffffff40 #00000040;
            border: 2px solid #ffff88a0;
        }

        .tickSpeedControls {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: flex-end;
            flex-grow: 1;
            width: 100%;

            &>div {
                width: 100%;
                display: flex;
                flex-direction: row;
                align-items: center;
                justify-content: space-between;
                gap: 5px;
            }

            input {
                width: 50px;
                text-align: right;
                background-color: #ffffff20;
                border: none;
                color: #ffffff;
                border-radius: 2px;
                font-family: 'Cascadia Code', 'Courier New', Courier, monospace;
                font-weight: bold;

                &::-webkit-inner-spin-button,
                &::-webkit-outer-spin-button {
                    -webkit-appearance: none;
                    margin: 0;
                }
            }
        }
    }

    &>#dragPrompt {
        position: absolute;
        width: 100%;
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        z-index: 99;
        background-color: rgba(0, 0, 0, 0.6);
        color: #ffffff;
        padding: 20px;
        border-radius: 10px;
        text-align: center;
        font-size: 24px;
        font-weight: bold;
        pointer-events: none;
    }

    .tipsContainer {
        grid-area: 3 / 1 / 4 / 5;
        width: 100%;
        height: 1lh;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        overflow: hidden;

        .tips {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: flex-start;
            overflow: scroll;
            scrollbar-width: none;
            pointer-events: none;
            width: 100%;
            scroll-behavior: smooth;
        }

        .tip {
            font-weight: normal;
            text-wrap: nowrap;
        }
    }
}

#carPeeker {
    transition: none;
    z-index: 99;
    pointer-events: none;
    position: absolute;
    background-color: rgba(from var(--carColour, #000000) r g b / 0.8);
    backdrop-filter: blur(5px);
    translate: 0 -100%;
    color: #ffffff;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 5px;
    border-radius: 5px;
    border: 2px solid #ffffff;
    text-shadow: 0 0 10px #000000;
    top: -100vh;
    left: -100vw;

    .right {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 10px;

        .carPeekerProbeAnglesContainer,
        .carPeekerNeuralNetworkContainer {
            background-color: #00000080;
            padding: 10px;
            border-radius: 10px;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            gap: 10px;
        }
    }
}

@keyframes focusHighlight {
    0% {
        box-shadow: 0 0 0 0px #ffeb3b80, 0 0 10px 2px #ffeb3b80;
        outline: 2px solid #ffeb3b;
    }

    70% {
        box-shadow: 0 0 0 10px #ffeb3b40, 0 0 20px 6px #ffeb3b80;
        outline: 2px solid #ffeb3b;
    }

    100% {
        box-shadow: none;
        outline: none;
    }
}

.focus-animate {
    animation: focusHighlight 1s ease-out;
}