/* fonts */
@font-face {
    font-family: 'DM Sans 9pt';
    src: url('res/fonts/DMSans-9ptRegular.woff2') format('woff2'),
        url('res/fonts/DMSans-9ptRegular.woff') format('woff');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Bitter';
    src: url('res/fonts/Bitter-Thin.woff2') format('woff2'),
        url('res/fonts/Bitter-Thin.woff') format('woff');
    font-weight: 100;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Bitter';
    src: url('res/fonts/Bitter-ThinItalic.woff2') format('woff2'),
        url('res/fonts/Bitter-ThinItalic.woff') format('woff');
    font-weight: 100;
    font-style: italic;
    font-display: swap;
}

@font-face {
    font-family: 'Roboto Slab';
    src: url('res/fonts/RobotoSlab-Regular.woff2') format('woff2'),
        url('res/fonts/RobotoSlab-Regular.woff') format('woff');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Fira Code';
    src: url('res/fonts/FiraCode-Light.woff2') format('woff2'),
        url('res/fonts/FiraCode-Light.woff') format('woff');
    font-weight: 300;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'DM Sans 9pt';
    src: url('res/fonts/DMSans-9ptItalic.woff2') format('woff2'),
        url('res/fonts/DMSans-9ptItalic.woff') format('woff');
    font-weight: normal;
    font-style: italic;
    font-display: swap;
}

:root {
    --message-width: 900px;
    --chat-width: 1000px;
    --contrast-outline: 5px solid var(--bg-color);
    --hue: 230;
    --saturation: 5%;
}

:root,
.light,
.dark .dark {
    --fg-color: hsla(var(--hue), var(--saturation), 97%);
    --bg-color: hsla(var(--hue), var(--saturation), 90%);
    --fg-color-hover: hsla(var(--hue), var(--saturation), 85%);
    --half-color: hsla(var(--hue), var(--saturation), 50%);
    --dim-text-color: hsla(var(--hue), var(--saturation), 30%);
    --text-color: hsla(var(--hue), var(--saturation), 10%);
    --text-color-hover: hsla(var(--hue), var(--saturation), 20%);
}

.dark {
    --bg-color: hsla(var(--hue), var(--saturation), 8%);
    --fg-color: hsla(var(--hue), var(--saturation), 15%);
    --fg-color-hover: hsla(var(--hue), var(--saturation), 20%);
    --dim-text-color: hsla(var(--hue), var(--saturation), 60%);
    --text-color-hover: hsla(var(--hue), var(--saturation), 80%);
    --text-color: hsla(var(--hue), var(--saturation), 90%);
}

body {
    height: 100dvh;
    padding: 0;
}

/* basic rules */

code {
    background: var(--bg-color);
    color: var(--red);
    font-family: var(--font-mono);
    padding: 2.5px 5px;
    border-radius: var(--border-radius);
    font-size: 1.1rem;
}

pre code,
code.block {
    background-color: var(--bg-color);
    display: block;
    white-space: pre;
    color: var(--text-color);
    padding: 10px 20px;
    box-shadow: inset 105px 0 0 -100px var(--text-color);
    overflow-x: auto;
}

hr {
    margin: 5px 0;
    background-color: var(--bg-color);
}

h1,
h2,
h3,
h4,
h5,
h6 {
    font-weight: bold;
    user-select: auto;
}

h1 {
    color: var(--text-color);
    font-size: 2rem;
    text-align: center;
}

a {
    color: var(--blue);
    font-weight: bold;
    text-decoration: none;
}

blockquote {
    border-left: 5px solid #999;
    background: color-mix(in srgb, #999 15%, transparent);
    padding: 10px 20px;
}

table {
    width: 100%;
    border-collapse: collapse;

    th,
    td {
        padding: 10px;
        text-align: left;
    }

    th {
        background-color: var(--bg-color);
        border-bottom: 3px solid var(--fg-color);
    }

    td {
        background-color: var(--bg-color);
    }

    tr:first-child th:first-child {
        border-top-left-radius: var(--border-radius);
    }

    tr:first-child th:last-child {
        border-top-right-radius: var(--border-radius);
    }

    tr:last-child td:first-child {
        border-bottom-left-radius: var(--border-radius);
    }

    tr:last-child td:last-child {
        border-bottom-right-radius: var(--border-radius);
    }
}

*::selection {
    background-color: var(--text-color);
    color: var(--bg-color);
}

.serif {
    --font: "Bitter", "Georgia", serif;
}

.slab {
    --font: "Roboto Slab", "Georgia", serif;
}

.mono {
    --font: "Fira Code", "Cascadia Code", monospace;
}

.spacer {
    flex: 1;
}

/* specific styles */

#main {
    background-color: var(--bg-color);
    height: 100%;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 20px;

    &.chat {
        justify-content: flex-start;
    }

    &.screenshot {
        #settings-button {
            display: none;
        }

        #new-chat-button {
            display: none;
        }

        #model-select {
            display: none;
        }

        .controls-container {
            display: none;
        }

        #messages-viewport {
            padding: 20px;
        }
    }
}

.controls-container {
    display: flex;
    flex-direction: column;
    background-color: var(--fg-color);
    outline: var(--contrast-outline);
    padding: 10px;
    border-radius: 30px;
    max-width: 750px;
    width: 95%;
    /* box shadow to hide whatever is below the prompt */
    box-shadow: 0 50px 0 var(--bg-color);
    transition:
        outline 0.2s ease,
        outline-offset 0.2s ease,
        background-color 0.2s ease,
        color 0.2s ease;

    .chat & {
        position: fixed;
        bottom: 20px;
        max-width: var(--chat-width);
        width: 95%
    }

    .pending-images-container {
        display: flex;
        flex-wrap: wrap;
        gap: 10px;

        .pending-image-container {
            position: relative;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;

            .pending-image {
                width: 100px;
                height: 100px;
                background-color: var(--fg-color);
                border-radius: var(--border-radius);
                object-fit: cover;
                position: relative;
            }
        }
    }

    #prompt {
        width: 100%;
        padding: 10px;
        border-radius: var(--border-radius);
        background-color: var(--fg-color);
        color: var(--text-color);
        font-size: 1.25rem;
        font-family: var(--font);
        resize: none;
        min-height: 50px;
        height: auto;
        max-height: 200px;

        &:focus {
            box-shadow: none;
        }
    }

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

        button {
            height: 30px;
            width: 30px;
            font-size: 1.5rem;
            border-radius: 1337px;
            display: flex;
            justify-content: center;
            align-items: center;
            cursor: pointer;
            background-color: var(--fg-color);
            color: var(--text-color);

            &:hover {
                background-color: var(--fg-color-hover);
            }
        }

        #send {
            background-color: var(--text-color);
            color: var(--bg-color);
            width: 35px;
            height: 35px;
        }
    }

    &.dragover {
        outline: 3px solid var(--blue);
        outline-offset: 2px;

        &::after {
            opacity: 0.5;
        }
    }

    &::after {
        content: "add_circle";
        font-family: var(--font-icons);
        font-variation-settings:
            'FILL' 1,
            'wght' 400,
            'GRAD' 0,
            'opsz' 24;
        font-size: 5rem;
        position: absolute;
        pointer-events: none;
        top: 50%;
        left: 50%;
        transform: translateX(-50%);
        opacity: 0;
        transition: opacity 0.2s ease;
    }
}

.remove-image-button {
    position: absolute;
    top: 5px;
    right: 5px;
    background-color: #000;
    color: #fff;
    border-radius: 1337px;
    width: 20px;
    height: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    opacity: 0.75;
}

#title-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    user-select: none;

    .chat & {
        display: none;
    }

    .title {
        font-size: 3rem;
        font-weight: normal;
    }

    .description {
        color: var(--dim-text-color);
        font-size: 1rem;
        font-family: var(--font);
    }
}

.popup-content {
    max-width: 650px;

    .popup-header {
        display: flex;
        justify-content: space-between;
        user-select: none;
        align-items: center;
        text-align: center;
        justify-content: center;
        font-size: 4rem;
    }
}

#settings-button {
    position: fixed;
    top: 20px;
    right: 20px;
    background-color: var(--fg-color);
    color: var(--text-color);
    height: 3rem;
    width: 3rem;
    font-size: 2rem;
    border-radius: var(--border-radius);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    z-index: 10;
}

#settings-content {
    display: flex;
    width: 800px;
    max-width: 95%;
    gap: 5px;
    overflow-y: auto;

    .settings-section {
        display: flex;
        flex-direction: column;
        gap: 10px;
        padding: 10px;
        --setting-width: 300px;
    }

    #system-prompt {
        width: 100%;
        padding: 10px;
        font-size: 1.15em;
        resize: vertical
    }

    .settings-item {
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 10px;
        width: 100%;
        justify-content: space-between;

        label {
            font-size: 1.25em;
            color: var(--text-color);
        }

        .option-select {
            width: 100%;
            font-size: 1em;
            max-width: var(--setting-width);
        }

        &:has(textarea) {
            flex-direction: column;
            align-items: flex-start;
            width: 100%;
        }
    }

    #hue-value::after {
        content: "°";
    }

    #saturation-value::after {
        content: "%";
    }

    #temperature-value {
        font-size: 1.25em;
        color: var(--text-color);
        margin-left: 10px;
    }
}

.slider-container {
    width: var(--setting-width);
    display: flex;
    justify-content: end;

    .small-slider {
        width: 100%;
        max-width: var(--setting-width);
    }

    span {
        font-size: 1.25em;
        width: 50px;
        text-align: right;
        color: var(--text-color);
        margin-left: 10px;
    }
}

#model-select {
    background-color: var(--bg-color);
    color: var(--text-color);
    border-radius: var(--border-radius);
    padding: 10px 15px;
    font-size: 1.25rem;
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    cursor: pointer;
    display: flex;
    gap: 10px;
    align-items: center;
    z-index: 10;
}

#model-popup {
    position: fixed;
    top: 100px;
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--fg-color);
    color: var(--text-color);
    border-radius: var(--border-radius);
    display: flex;
    flex-direction: column;
    padding: 20px;
    padding-top: 20px;
    z-index: 10;
    outline: var(--contrast-outline);
    gap: 10px;
    max-height: 30em;
    width: 90%;
    max-width: 400px;
    overflow-y: auto;
    user-select: none;

    #model-settings {
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 2rem;
        position: absolute;
        top: 10px;
        right: 25px;
        cursor: pointer;
        height: 50px;
        width: 50px;
        z-index: 20;
        border-radius: var(--border-radius);
        color: var(--text-color);
        opacity: 0.5;

        &:hover {
            background-color: var(--fg-color-hover);
            opacity: 1;
        }
    }
}

.model-list-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    height: 40em;
    max-height: 65dvh;
    overflow-y: auto;
    width: 500px;
    max-width: 80dvw;
}

.model-list-section {
    display: flex;
    flex-direction: column;
    user-select: none;

    h2 {
        font-size: 1rem;
        font-weight: bold;
        opacity: 0.5;
        margin-left: 10px;
    }

    .model-list {
        display: flex;
        flex-direction: column;

        .model-item {
            display: flex;
            flex-direction: row;
            align-items: center;
            padding: 10px 20px;
            gap: 10px;
            cursor: pointer;
            border-radius: var(--border-radius);
            background-color: var(--fg-color);
            color: var(--text-color);
            width: 100%;

            .model-list-container & {
                cursor: auto;
            }

            .model-name {
                font-size: 1.25rem;
                font-weight: bold;
            }

            .model-hide-icon,
            .model-info-icon,
            .model-star-button {
                display: flex;
                justify-content: center;
                align-items: center;
                width: 40px;
                height: 40px;
                font-size: 1.75rem;
                border-radius: 1337px;
                opacity: 0.5;
                margin-left: auto;
                user-select: none;
                cursor: pointer;
                transition: opacity 0.2s ease;

                @media (hover: hover) {
                    &:hover {
                        opacity: 1;
                    }
                }
            }

            .model-star-button {
                margin-left: -10px;

                font-variation-settings: "FILL" 0;

                &.default {
                    font-variation-settings: "FILL" 1;
                    opacity: 1;
                }
            }

            &.invisible {
                opacity: 0.3;
            }

            @media (hover: hover) {
                &:hover {
                    background-color: var(--fg-color-hover);
                }
            }
        }
    }
}

.model-icon {
    width: 50px;
    height: 50px;
    border-radius: 1337px;
    background-color: var(--fg-color);
    display: flex;
    justify-content: center;
    align-items: center;

    &.mini {
        width: 40px;
        height: 40px;
    }
}

.model-info-popup {
    position: fixed;
    background-color: var(--fg-color);
    padding: 10px 20px;
    border-radius: var(--border-radius);
    outline: var(--contrast-outline);
    z-index: 20;
    display: flex;
    flex-direction: column;
    gap: 10px;
    animation: fadeIn 0.2s ease-in-out;

    .model-info-description {
        font-size: 1rem;
        color: var(--dim-text-color);
    }
}

#messages-viewport {
    display: none;
    width: 100%;
    justify-content: center;
    padding-top: 100px;
    padding-left: 20px;
    padding-right: 20px;
    padding-bottom: 150px;

    .chat & {
        display: flex;
    }

    #messages {
        display: flex;
        flex-direction: column;
        width: 100%;
        max-width: var(--chat-width);
    }
}

.message-container {
    display: flex;
    flex-direction: column;
    width: 100%;

    &.user {
        align-items: flex-end;
    }

    .message {
        display: flex;
        flex-direction: column;
        padding: 10px 20px;
        background-color: var(--fg-color);
        color: var(--text-color);
        max-width: var(--message-width);
        gap: 10px;
        min-height: 40px;
        font-size: 1.2rem;

        &.user {
            align-self: flex-end;
            border-radius: 20px 20px 0 20px;
        }

        &.assistant {
            align-self: flex-start;
            border-radius: 20px 20px 20px 0;
            background-color: var(--fg-color);
            color: var(--text-color);

            &.pending {
                display: flex;
                flex-direction: column;
                align-items: center;
                justify-content: center;
                padding: 15px 20px;
                gap: 10px;
                max-width: 90%;

                .pending-bar {
                    --loading-color: color-mix(in srgb, var(--text-color) 10%, transparent);
                    --loading-color-2: color-mix(in srgb, var(--text-color) 5%, transparent);
                    width: 100%;
                    height: 1em;
                    background: linear-gradient(90deg,
                            var(--loading-color) 25%,
                            var(--loading-color-2) 50%,
                            var(--loading-color) 75%);
                    background-size: 800px 100%;
                    animation: shimmer 3s infinite linear;
                    border-radius: 1337px;
                }
            }
        }

        .editing & {
            outline: 5px solid var(--blue);
            white-space: pre-wrap;
            line-height: normal;
        }

        .error & {
            background-color: var(--red);
            width: 100%;
            max-width: 100%;
            align-items: center;
            justify-content: center;
            display: flex;
            color: #fff;
            border-radius: var(--border-radius);
        }

        /* grow messages that look like they would be complicated to full size */
        &:has(pre),
        &:has(table),
        &:has(blockquote),
        &:has(ul),
        &:has(ol),
        &:has(div) {
            width: var(--message-width);
            max-width: 90%;

            @media (max-width: 600px) {
                width: 100%;
                max-width: 100%;
            }
        }

        /* links in message get an indicator */
        a::after {
            content: "link";
            color: var(--blue);
            padding-left: 0.1em;
            font-family: var(--font-icons)
        }
    }

    .message-button {
        background-color: transparent;
        color: var(--text-color);
        font-size: 1.5rem;
        width: 32px;
        height: 32px;
        border-radius: 1337px;
        cursor: pointer;
        color: var(--text-color);
        opacity: 0;
        transition: opacity 0.2s ease;

        .editing & {
            opacity: 0.25;
        }

        @media (max-width: 600px) {
            width: 30px;
            height: 30px;
            font-size: 1.25rem;
        }
    }

    &:hover .message-button {
        color: var(--text-color);
        opacity: 0.25;

        &:hover {
            color: var(--text-color);
            opacity: 1;
        }
    }
}

.timestamp {
    font-size: 0.8rem;
    color: var(--text-color);
    margin-top: -1.25rem;
    margin-bottom: 5px;
    margin-left: 10px;
    margin-right: 10px;
    opacity: 0;
    transition: opacity 0.2s ease;
    user-select: none;
    pointer-events: none;

    @media (hover: hover) {

        .message-container:hover &,
        .message-images:hover & {
            opacity: 0.5;
        }
    }
}

.message-images {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;

    &.user {
        justify-content: flex-end;
    }

    .message-image-container {
        position: relative;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;

        .message-image {
            height: 150px;
            background-color: var(--fg-color);
            border-radius: var(--border-radius);
            object-fit: cover;
        }
    }
}

.code-wrapper {
    position: relative;
    transition: max-height 0.2s ease;
    max-height: auto;
    border-radius: var(--border-radius);
    overflow: hidden;

    .code-buttons {
        position: absolute;
        top: 0;
        right: 0;
        display: flex;
        flex-direction: row;
        border-radius: 0 0 0 var(--border-radius);
        overflow: hidden;

        .button {
            background-color: var(--text-color);
            color: var(--bg-color);
            width: 38px;
            height: 38px;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 0;
            font-size: 1.5rem;
            border-radius: 0;

            @media (hover: hover) {
                &:hover {
                    background-color: var(--text-color-hover);
                }
            }

            @media (max-width: 600px) {
                width: 30px;
                height: 30px;
                font-size: 1.25rem;
            }
        }
    }

    &.collapsed {
        max-height: 38px;
        overflow: hidden;

        .code-buttons {
            border-radius: 0;
        }
    }
}

.api-key-container {
    display: flex;
    align-items: center;
    background-color: var(--bg-color);
    border-radius: var(--border-radius);
    z-index: 11;

    &:has(.api-key-input:focus) {
        box-shadow: var(--focus-outline);
    }

    &.collapsed {

        .api-key-input,
        .verify-button {
            width: 0;
            padding: 0;
            opacity: 0;
            pointer-events: none;
        }

        .key-button {
            border-radius: var(--border-radius);
        }
    }

    .key-button {
        color: var(--text-color);
        background-color: transparent;
        height: 3rem;
        width: 3rem;
        font-size: 2rem;
        display: flex;
        justify-content: center;
        align-items: center;
        cursor: pointer;
        border-radius: var(--border-radius) 0 0 var(--border-radius);
    }

    .api-key-input {
        width: var(--setting-width);
        height: 3rem;
        background-color: transparent;
        color: var(--text-color);
        font-size: 1rem;
        font-family: var(--font);
        transition: width 0.2s ease, padding 0.2s ease, opacity 0.2s ease;

        &:focus {
            box-shadow: none !important;
        }
    }

    .verify-button {
        background-color: transparent;
        color: var(--text-color);
        height: 3rem;
        width: 3rem;
        font-size: 1rem;
        border-radius: 0 var(--border-radius) var(--border-radius) 0;
        display: flex;
        justify-content: center;
        align-items: center;
        cursor: pointer;
        transition:
            width 0.2s ease,
            padding 0.2s ease,
            opacity 0.2s ease,
            background-color 0.2s ease;
    }
}

#new-chat-button {
    position: fixed;
    top: 20px;
    left: 20px;
    background-color: var(--fg-color);
    color: var(--text-color);
    height: 3rem;
    width: 3rem;
    font-size: 2rem;
    border-radius: var(--border-radius);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    outline: var(--contrast-outline);
    z-index: 10;
    user-select: none;
}

@keyframes shimmer {
    0% {
        background-position: -400px 0;
    }

    100% {
        background-position: 400px 0;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@media (hover:hover) {

    /* text color buttons */
    #send:hover {
        background-color: var(--text-color-hover);
    }

    /* fg color buttons */
    .key-button:hover,
    #new-chat-button:hover,
    .verify-button:hover,
    #settings-button:hover,
    #model-select:hover {
        background-color: var(--fg-color-hover);
    }

    /* red buttons */
    .remove-image-button:hover {
        background-color: var(--red);
        color: var(--fg-color);
        opacity: 1;
    }
}

@media (max-width: 600px) {
    code {
        font-size: 0.9rem;
    }

    .popup-background {
        padding: 1em;
    }

    #settings-content {
        max-width: 100%;
        width: 100%;
        max-height: 80dvh;
        padding: 20px 10px;
        font-size: 0.8rem;

        .settings-section {
            --setting-width: 200px;
        }
    }

    .controls-container #prompt {
        font-size: 1rem;
    }

    #system-prompt {
        width: 100%;
        max-width: 100%;
        font-size: 1rem;
    }

    .message-container {
        .message {
            font-size: 1rem;
        }

        .message-button {
            opacity: 0.25;
        }
    }
}