/**
 * DJO Dictee
 * Copyright (C) 2026 ngkon
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

:root {
    --main-gradient-fg:
        radial-gradient(at 47% -56%, rgb(30, 230, 130), rgba(30, 230, 130, 0)),
        linear-gradient(135deg, rgb(0, 130, 230), rgb(0, 160, 190));
    --main-gradient-bg:
        linear-gradient(1deg, rgba(0, 0, 0, 0.75), rgba(0, 0, 0, 0.75)),
        radial-gradient(at 44vw 200vh, rgb(30, 230, 130), rgba(30, 230, 130, 0)),
        linear-gradient(135deg, rgb(0, 130, 230), rgb(0, 160, 190));

    --red-gradient-bg:
        radial-gradient(at 45% 80%, rgb(230, 30, 30), rgba(30, 0, 0, 0)),
        linear-gradient(135deg, rgb(190, 0, 30), rgb(130, 0, 0));
    --red-gradient-fg:
        radial-gradient(at 45% 80%, salmon, rgba(30, 0, 0, 0)),
        linear-gradient(135deg, rgb(250, 90, 70), rgb(255, 100, 100));

    --green-gradient-bg:
        radial-gradient(at 75% 40%, rgb(30, 230, 30), rgba(0, 30, 0, 0)),
        linear-gradient(135deg, rgb(0, 190, 30), rgb(0, 130, 0));
    --green-gradient-fg:
        radial-gradient(at 75% 40%, lightgreen, rgba(0, 30, 0, 0)),
        linear-gradient(135deg, rgb(50, 230, 80), rgb(0, 130, 70));

    --orange-gradient-fg:
        radial-gradient(at 65% 80%, orange, rgba(60, 30, 0, 0)),
        linear-gradient(135deg, rgb(230, 130, 20), rgb(230, 155, 45));

    --main-color: #fff;
    --gray-color: #bbb;
    --grid-card: #fff2;
    --input-background: #0004;
    --overlay-background: #000c;

    --spacing: 1rem;
    --dialog-spacing: 3rem;
}

@keyframes introduction {
    from {
        opacity: 0;
        transform: translateY(3rem);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
@keyframes confirm-warning {
    0%, 100% {
        background-blend-mode: lighten;
    }
    50% {
        background-blend-mode: unset;
    }
}

body {
    margin: var(--spacing);
    overflow-x: hidden;
    background: var(--main-gradient-bg);
    background-attachment: fixed;
    font-family: Montserrat, sans-serif;
    line-height: 1.25;
    color: var(--main-color);

    --dialog-transition-time: 0.75s; /* changed by JS */
}
body::backdrop {
    background: var(--main-gradient-bg); /* work in fullscreen mode too */
}

.container {
    display: grid;
    gap: var(--spacing);
    width: 100%;
    height: calc(100vh - var(--spacing) * 2);
    margin: 0;

    & > div {
        animation-name: introduction;
        animation-duration: 2s;
        animation-fill-mode: backwards;
    }
    &.Home {
        grid-template-areas:
          "Heading Heading Heading"
          "Status Status How"
          "Why Experiences Experiences"
          "Footer Footer Footer";
        grid-template-rows: 0fr auto auto 0fr;
        grid-template-columns: 1fr 0.5fr 1fr;
    }
    &.Dictee {
        height: fit-content;
        display: none;
        flex-direction: column;
        justify-content: space-between;
        align-items: center;
        margin: var(--spacing) 0;

        .DicteeForm, .DicteeSubmit {
            width: 50%;
            min-width: 1000px;
        }
        .DicteeForm {
            flex: auto;
            display: flex;
            flex-direction: column;

            input {
                width: 150px;
                margin: 1px;
                padding: 2px 4px;
                border-radius: 6px;
            }

            p {
                flex: auto;
            }

            button {
                display: none;
                width: auto;
                font-size: 24px;

                img {
                    height: 24px;
                }
            }
        }
        .DicteeSubmit {
            display: flex;
            flex-direction: column;

            button {
                width: unset;
            }
            p {
                margin: 0.5em var(--spacing);
            }
        }
    }
    &.Examiner {
        grid-template-areas:
          "Heading Heading"
          "Contents Participants"
          "Contents Dashboard"
          "Footer Footer";
        grid-template-rows: 0fr 1fr 0fr 0fr;
        grid-template-columns: 2fr 1fr;
    }
}

.heading {
    grid-area: Heading;
    display: flex;
    justify-content: space-between;
    height: 100px;

    .logo {
        display: flex;
        align-items: center;
        gap: var(--spacing);
        img {
            height: 5em;
        }
        h1 {
            margin: 0;
            font-size: 5em;
        }
    }
    .hyperlinks {
        display: flex;
        gap: calc(var(--spacing) * 2);
    }
}
.footer {
    grid-area: Footer;
    text-align: center;
    animation-delay: 1s;

    p {
        margin: 0.5em;
    }
}

a {
    color: inherit;
    height: fit-content;
    text-decoration: underline;
    cursor: pointer;

    &:hover {
        text-decoration: none;
    }

    &[target="_blank"]::after {
        content: "";
        background-image: url("/static/icons/external-link.svg");
        background-size: 100%;
        display: inline-block;
        width: 18px;
        height: 18px;
        margin-left: 2px;
        vertical-align: text-bottom;
    }
}

.card {
    background-color: var(--grid-card);
    border-radius: var(--spacing);
    &.Status {
        grid-area: Status;
        animation-delay: 0.2s;
        display: flex;
        flex-direction: column;
        justify-content: space-between;

        #status-cards {
            display: flex;
            flex: auto;
            gap: var(--spacing);
            margin-bottom: 0;

            div {
                width: stretch;
                display: flex;
                flex-direction: column;
                justify-content: center;
                align-items: center;
                gap: 8px;

                background-color: var(--grid-card);
                padding: var(--spacing) 0;
                border-radius: var(--spacing);

                h2 {
                    margin: 0;
                }
                img {
                    width: 80px;
                }
            }
        }
    }
    &.How {
        grid-area: How;
        animation-delay: 0.4s;
    }
    &.Why {
        grid-area: Why;
        animation-delay: 0.6s;
    }
    &.Experiences {
        grid-area: Experiences;
        animation-delay: 0.8s;
        display: flex;
        flex-direction: column;
    }

    &.Contents {
        grid-area: Contents;
        animation-delay: 0.3s;
        display: flex;
        flex-direction: column;

        & > div {
            display: flex;
            flex-direction: column;
            flex-basis: 90%;
            gap: var(--spacing);

            p {
                margin: 0;
                display: flex;
                justify-content: space-between;
            }
            em {
                color: var(--gray-color);
            }
            & > div {
                display: flex;
                flex-direction: column;
                gap: 4px;


                &#dictee-contents-wrapper {
                    flex-basis: 80%;
                }
                textarea {
                    flex-basis: 90%;
                }
            }
        }
    }
    &.Participants {
        grid-area: Participants;
        animation-delay: 0.5s;

        #participant-list {
            display: flex;
            flex-direction: column;
            background-color: var(--grid-card);
            border-radius: var(--spacing);
            overflow-y: auto;

            p {
                display: flex;
                justify-content: space-between;
                align-items: center;
                margin: 0;
                padding: 8px;

                b {
                    margin-left: calc(var(--spacing) - 8px);

                    span {
                        font-weight: normal;
                        font-size: small;
                    }
                }
                em {
                    color: var(--gray-color);
                    margin-left: 4px;
                }
                strong {
                    font-size: medium;
                }

                .button-wrapper {
                    display: flex;
                    gap: calc(var(--spacing) / 2);
                    background: unset;
                }
                button {
                    width: 40px;
                    height: 40px;

                    img {
                        height: 24px;
                    }
                }

                .cheats {
                    background: var(--orange-gradient-fg);
                    background-blend-mode: multiply;
                    border-radius: var(--spacing);
                    padding: 0 calc(var(--spacing) / 2);
                    gap: var(--spacing);

                    &, & div {
                        display: flex;
                        align-items: center;
                    }
                    & div {
                        gap: 4px;
                        font-weight: bold;
                    }
                }
            }
            hr {
                width: calc(100% - 16px);
                margin: 0 8px;
            }
        }
        #no-participants img {
            width: 25%;
            margin: auto;
            margin-top: 10%;
            display: block;
        }
        #no-participants p {
            text-align: center;
        }
    }
    &.Dashboard {
        grid-area: Dashboard;
        animation-delay: 0.7s;

        #dashboard-items {
            display: flex;
            flex-direction: column;
            justify-content: space-between;

            div {
                display: flex;
                justify-content: space-between;
                align-items: center;
                gap: var(--spacing);

                h2 {
                    margin: 0.5em 0;
                }
                button {
                    display: none;
                    width: fit-content;
                    font-size: 1.2em;
                    padding-left: 32px;
                    padding-right: 32px;
                }
            }
        }
    }

    .subcards-grid {
        flex-basis: 80%;
        display: grid;
        height: -webkit-fill-available;
        grid-template-columns: auto auto;
        gap: var(--spacing);

        & > div {
            background-color: var(--grid-card);
            border-radius: var(--spacing);
            display: flex;
            flex-direction: column;
            justify-content: space-between;

            & > * {
                margin: var(--spacing);
            }
            .rating {
                display: flex;
                margin-top: -10px;
            }
        }
    }
    & > * {
        margin: var(--spacing);
    }
}

h1, h3 {
    font-style: italic;
    text-transform: uppercase;
    font-weight: 800;
    overflow: hidden;
    line-height: 1;
    padding: 0 4px; /* prevent cutoffs at first/last char */
}
h3 {
    font-size: 2em;
    margin: 0.5em;

    &.flex {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
}
h4 {
    font-size: 1.2em;
    margin: 0.5em 0;
}


button {
    width: 100%;
    padding: 8px 0;
    font-family: inherit;
    font-style: italic;
    font-weight: 800;
    font-size: 2em;
    text-transform: uppercase;
    color: inherit;
    border: none;
    outline: none;
    border-radius: var(--spacing);

    display: flex;
    justify-content: center;
    align-items: center;
    gap: var(--spacing);
    cursor: pointer;
    transition: 0.5s ease;

    &:not(:disabled):hover {
        filter: brightness(1.1);

        img.img-l {
            transform: translateX(-16px);
        }
        img.img-r {
            transform: translateX(16px);
        }
    }
    &:disabled {
        filter: grayscale(1);
        cursor: unset;
    }
    img {
        height: 36px;
        transition: inherit;

        &.rot180 {
            rotate: 180deg;
        }
    }

    &.confirm-warning {
        animation-name: confirm-warning;
        animation-duration: 0.5s;
        animation-iteration-count: infinite;
    }
    &.small {
        font-size: 1.2em;
        font-weight: bold;

        img {
            height: 24px;
        }
    }
}

input, textarea {
    background: var(--input-background);
    border: 1px solid var(--main-color);
    border-radius: var(--spacing);
    padding: calc(var(--spacing) / 2);
    outline: none;
    color: inherit;
    font-family: inherit;
}

textarea {
    resize: none;
}

fieldset {
    background: var(--input-background);
    border-radius: var(--spacing);

    input {
        width: 100%;
        background: none;
        border: none;
        border-top: 2px solid #fff0;
        border-bottom: 2px solid #fff0;
        border-radius: 0;
        padding: 4px 0;
        font-size: 1.2em;
        font-weight: bold;
        transition: 0.15s ease;

        &:focus {
            border-bottom: 2px solid var(--main-color);
        }
    }
}

button.main-bg {
    background: var(--main-gradient-fg);
}
.main-fg {
    color: transparent;
    background: var(--main-gradient-fg);
    background-clip: text;
}
.red-fg {
    color: transparent;
    background: var(--red-gradient-fg);
    background-clip: text;
}
.red-bg {
    background: linear-gradient(1deg, rgba(0, 0, 0, 0.25), rgba(0, 0, 0, 0.25)), var(--red-gradient-bg);
}
.green-fg {
    color: transparent;
    background: var(--green-gradient-fg);
    background-clip: text;
}
.green-bg {
    background: linear-gradient(1deg, rgba(0, 0, 0, 0.25), rgba(0, 0, 0, 0.25)), var(--green-gradient-bg);
}
.orange-fg {
    color: transparent;
    background: var(--orange-gradient-fg);
    background-clip: text;
}

#overlay {
    position: absolute;
    left: 0;
    top: 0;
    width: 100vw;
    height: 100vh;
    z-index: 2;
    pointer-events: none;
    background-color: var(--overlay-background);
    backdrop-filter: blur(6px);
    opacity: 0;
    transition: var(--dialog-transition-time) ease;
}

.dialog {
    position: absolute;
    opacity: 0;
    background-color: var(--grid-card);
    border-radius: var(--dialog-spacing);
    overflow-x: hidden;
    overflow-y: auto;
    z-index: 3;

    display: flex;
    flex-direction: column;
    justify-content: space-around;

    & > * {
        display: none;
        opacity: 0;
        transition: var(--dialog-transition-time) ease;
    }
    h1 {
        text-align: center;
        font-size: 4em;
        margin: 0.5em 0;
    }
    h3 {
        text-align: center;
        margin-bottom: 1.2em;
    }
    img[src*="tenor"] {
        display: block;
        margin: var(--spacing) auto;
        width: 50%;
        border-radius: var(--spacing);
        pointer-events: none;
    }

    .dialog-text {
        width: 60%;
        margin: auto;

        ol ol {
            list-style: lower-latin;
        }
    }
    .dialog-inputs {
        width: 50%;
        margin: auto;
        display: flex;
        flex-direction: column;
        gap: var(--spacing);

        #name-error {
            text-align: center;
            user-select: none;
        }
        p + fieldset {
            margin-top: -1em;
        }
    }
    .dialog-buttons {
        display: flex;
        gap: var(--spacing);
        margin: var(--dialog-spacing) 0;
    }

    #result {
        flex-direction: column;
        gap: var(--spacing);

        h1 {
            font-size: 8em;
            margin: 0;
        }
        h4 {
            text-align: center;
            font-size: 1.5em;
            margin: 0.3em 0;
        }
        button {
            margin-top: 2em;
        }
    }
    #inspector {
        #comparison {
            display: flex;
            gap: var(--dialog-spacing);

            div {
                width: 50%;
            }
        }
        #comparison, button {
            width: calc(100% - var(--dialog-spacing) * 2);
            margin: var(--spacing) var(--dialog-spacing);
        }
    }

    h5 {
        text-align: center;
        color: var(--gray-color);
        font-size: 1.1em;
        margin: 2em 0;
        span {
            color: var(--main-color);
        }
    }
}
noscript .dialog {
    opacity: 1;
    width: 100vw;
    height: 100vh;
    left: 0;
    top: 0;
    background-color: var(--overlay-background);
    border-radius: 0;
    backdrop-filter: sepia(1) saturate(7) blur(8px);
    justify-content: center;

    * {
        display: block;
        opacity: inherit;
    }
}
@media only screen and (width < 1100px) {
    body {
        overflow: hidden;
    }
    #too-small {
        opacity: 1;
        width: 100vw;
        height: 100vh;
        left: 0;
        top: 0;
        background-color: var(--overlay-background);
        border-radius: 0;
        backdrop-filter: sepia(1) saturate(7) blur(8px);
        justify-content: center;

        * {
            display: block;
            opacity: inherit;
        }
    }
}

.sonner {
    position: absolute;
    left: calc(50vw);
    top: -100px;

    padding: var(--spacing);
    border-radius: var(--spacing);
    transition: top 0.5s ease;
    pointer-events: none;
    z-index: 5;

    display: flex;
    align-items: center;
    gap: var(--spacing);

    --expire-bar-height: 3px;
    --expire-transition: none;
    --expire-clip-path: inset(calc(100% - var(--expire-bar-height)) 100% 0 0);

    #sonner-text {
        font-size: 1.2em;
        font-weight: bold;
    }
    &::after {
        content: "";
        position: absolute;
        left: 0;
        bottom: 0;

        transition: var(--expire-transition);
        clip-path: var(--expire-clip-path);
        width: 100%;
        height: 100%;
        background-color: var(--main-color);
        border-radius: inherit;
    }
}
.cheat-details {
    & summary::marker {
        color: salmon;
    }
    & div {
        padding-left: 20px;
    }
}
