:root {
    color-scheme: dark;
    --brand-color: #ce3daf;
    --dark-bg: #1a1a2e;
    --chat-bg: rgba(26, 26, 46, 0.1);
    --max-width: 870px;
    --padding-container: 20px;
    --text-color: #ffffff;
    --input-bg: rgba(255, 255, 255, 0.1);
    --border-radius: 12px;
    --transition-speed: 0.3s;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.12);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.2);
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --transition-fast: 150ms;
    --transition-normal: 300ms;
    --transition-slow: 500ms;
}

@font-face {
    font-family: "Cascadia Code";
    src: url("/static/fonts/CascadiaCode.woff2") format("woff2");
    font-display: swap;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    color-scheme: dark;
    background-color: var(--dark-bg);
}

html,
body {
    height: 100%;
    overflow: hidden;
    position: fixed;
    width: 100%;
    margin: 0;
    padding: 0;
}

body {
    font-family: "Cascadia Code", monospace;
    background: var(--dark-bg);
    color: var(--text-color);
    min-height: 100vh;
    min-height: -webkit-fill-available;
    padding: var(--padding-container);
    display: flex;
    justify-content: center;
    line-height: 1.6;
    position: relative;
    overflow-y: auto;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

.chat-container {
    width: 100%;
    max-width: var(--max-width);
    height: calc(100vh - var(--padding-container) * 2);
    height: calc(100dvh - var(--padding-container) * 2);
    display: flex;
    flex-direction: column;
    background: var(--chat-bg);
    position: relative;
    z-index: 0;
    border: 2px solid var(--brand-color);
    border-radius: var(--border-radius);
    overflow: hidden;
    padding-bottom: env(safe-area-inset-bottom);
    transform: translateZ(0);
    backface-visibility: hidden;
    box-shadow:
        0 0 20px var(--brand-color),
        inset 0 0 20px rgba(206, 61, 175, 0.3);
    animation: borderGlow 4s infinite alternate;
}

.matrix-bg {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
    opacity: 0.3;
    pointer-events: none;
    background: transparent;
    overflow: hidden;
    display: flex;
    justify-content: space-around;
}

.matrix-line {
    width: 1px;
    height: 100%;
    background: linear-gradient(180deg, transparent, var(--brand-color), transparent);
    animation: matrix-rain 3s infinite;
    animation-duration: calc(3s + (var(--i) * 0.2s));
    transform: translateY(-100%);
}

.chat-container::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(206, 61, 175, 0.05);
    z-index: 1;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.chat-container::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(to bottom, transparent 50%, rgba(206, 61, 175, 0.15) 50%);
    background-size: 100% 4px;
    animation: scanline 10s linear infinite;
    pointer-events: none;
    z-index: 2;
}

.chat-header {
    position: relative;
    z-index: 4;
    padding: 1rem;
    border-bottom: 1px solid var(--brand-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    background: rgba(0, 0, 0, 0.2);
}

.chat-logo {
    height: 128px;
    width: 128px;
    display: flex;
    align-items: center;
}

.chat-logo img {
    height: 100%;
    width: 100%;
    object-fit: contain;
    filter: drop-shadow(0 0 8px rgba(206, 61, 175, 0.5));
    transition: transform var(--transition-speed) ease;
}

.chat-logo img:hover {
    transform: scale(1.05);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.clear-button {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--brand-color);
    color: var(--text-color);
    border-radius: 50px;
    cursor: pointer;
    transition: all var(--transition-speed) ease;
    font-size: 0.9rem;
}

.clear-button:hover {
    background: var(--brand-color);
    transform: translateY(-2px);
    box-shadow: 0 0 15px rgba(206, 61, 175, 0.5);
}

.clear-chat-btn.hidden {
    display: none;
}

@media (max-width: 768px) {
}

.social-link {
    display: flex;
    align-items: center;
    height: fit-content;
    padding: 8px 16px;
    border-radius: 50px;
    background: var(--input-bg);
    border: 1px solid var(--brand-color);
    color: var(--text-color);
    text-decoration: none;
    transition: all var(--transition-speed) ease;
    font-size: 0.9rem;
    will-change: transform;
}

.social-link i {
    font-style: normal;
    margin-right: 6px;
}

.social-link:hover {
    background: var(--brand-color);
    transform: translateY(-2px);
    box-shadow: 0 0 15px rgba(206, 61, 175, 0.5);
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    position: relative;
    z-index: 3;
    background-size: cover;
    background-position: center;
    transition: background-image 1s ease-in-out;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
}

.message {
    max-width: 80%;
    margin: 1rem 0;
    padding: 1rem;
    border-radius: var(--border-radius);
    border: 1px solid var(--brand-color);
    box-shadow:
        0 0 15px rgba(206, 61, 175, 0.2),
        inset 0 0 20px rgba(206, 61, 175, 0.1);
    font-size: 0.95rem;
    letter-spacing: 0.02em;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    opacity: 0;
    animation: fadeIn 0.3s ease forwards;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.clear-chat-btn {
    position: sticky;
    top: 0;
    float: right;
    margin: 10px;
    padding: 8px;
    background: rgba(206, 61, 175, 0.2);
    border: 1px solid var(--brand-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-speed) ease;
    z-index: 10;
}

.clear-chat-btn:hover {
    background: var(--brand-color);
    transform: scale(1.1);
    box-shadow: 0 0 15px var(--brand-color);
}

.clear-chat-btn i {
    font-size: 1rem;
    color: var(--text-color);
}

.user-message {
    margin-left: auto;
    background: rgba(206, 61, 175, 0.25) !important;
}

.bot-message {
    margin-right: auto;
    background: rgba(26, 26, 46, 0.95) !important;
}

.chat-background {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 0;
    opacity: 0.3;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    transition: opacity 1s ease-in-out;
    pointer-events: none;
    animation: cyberpunkGlow 8s infinite;
    filter: hue-rotate(0deg);
}

.input-container {
    position: relative;
    z-index: 4;
    padding: 1rem;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom));
    border-top: 1px solid var(--brand-color);
    display: flex;
    gap: 1rem;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 -5px 15px rgba(206, 61, 175, 0.1);
}

input {
    flex: 1;
    padding: 1rem;
    border: 1px solid var(--brand-color);
    border-radius: 8px;
    background: var(--input-bg);
    color: var(--text-color);
    font-family: "Cascadia Code", monospace;
    font-size: 0.9rem;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

input::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

input:focus {
    outline: 2px solid var(--brand-color);
    outline-offset: 2px;
    box-shadow: 0 0 10px var(--brand-color);
}

button {
    padding: 1rem 2rem;
    border: 1px solid var(--brand-color);
    border-radius: 8px;
    background: var(--brand-color);
    color: var(--text-color);
    cursor: pointer;
    transition: all var(--transition-speed) ease;
    font-family: "Cascadia Code", monospace;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 0.9rem;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

button:hover {
    background: transparent;
    box-shadow: 0 0 15px var(--brand-color);
}

.loading-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 1rem;
    margin: 1rem 0;
    background: rgba(206, 61, 175, 0.1);
    border: 1px solid var(--brand-color);
    border-radius: var(--border-radius);
    width: fit-content;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.loading-dot {
    width: 8px;
    height: 8px;
    background: var(--brand-color);
    border-radius: 50%;
    animation: loadingPulse 1.5s infinite;
}

.loading-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.loading-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes loadingPulse {
    0%,
    100% {
        opacity: 0.3;
        transform: scale3d(0.8, 0.8, 1);
    }
    50% {
        opacity: 1;
        transform: scale3d(1.2, 1.2, 1);
    }
}

@keyframes borderGlow {
    0% {
        box-shadow:
            0 0 20px var(--brand-color),
            inset 0 0 20px rgba(206, 61, 175, 0.3);
    }
    100% {
        box-shadow:
            0 0 40px var(--brand-color),
            inset 0 0 40px rgba(206, 61, 175, 0.5);
    }
}

@keyframes cyberpunkGlow {
    0% {
        filter: hue-rotate(0deg) brightness(1) saturate(1);
        opacity: 0.15;
    }
    25% {
        filter: hue-rotate(45deg) brightness(1.1) saturate(1.2);
        opacity: 0.18;
    }
    50% {
        filter: hue-rotate(90deg) brightness(1) saturate(1);
        opacity: 0.15;
    }
    75% {
        filter: hue-rotate(180deg) brightness(1.1) saturate(1.2);
        opacity: 0.18;
    }
    100% {
        filter: hue-rotate(360deg) brightness(1) saturate(1);
        opacity: 0.15;
    }
}

@keyframes scanline {
    0% {
        transform: translateY(0%);
    }
    100% {
        transform: translateY(100%);
    }
}

@keyframes matrix-rain {
    0% {
        transform: translateY(-100%);
        opacity: 0;
    }
    50% {
        opacity: 1;
    }
    100% {
        transform: translateY(100%);
        opacity: 0;
    }
}

::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
}

::-webkit-scrollbar-thumb {
    background: var(--brand-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #ff71ce;
}

@media (max-width: 768px) {
    :root {
        --padding-container: 13px;
    }

    .chat-container {
        border-radius: 8px;
        border-width: 1.5px;
    }

    .chat-header {
        padding: 0.75rem;
        gap: 0.5rem;
    }

    .chat-logo {
        height: 64px;
        width: 64px;
    }

    .social-link {
        padding: 6px 12px;
        font-size: 0.8rem;
        min-height: 44px;
    }

    .message {
        max-width: 90%;
        font-size: 0.9rem;
    }

    .input-container {
        padding: 0.75rem;
    }

    input,
    button {
        font-size: 0.85rem;
        min-height: 44px;
    }

    button {
        padding: 1rem 1.5rem;
    }

    body {
        -webkit-text-size-adjust: none;
    }
}

@supports (-webkit-touch-callout: none) {
    html {
        height: -webkit-fill-available;
    }

    body {
        min-height: -webkit-fill-available;
    }

    .chat-container {
        height: calc(100vh - var(--padding-container) * 2 - env(safe-area-inset-top) - env(safe-area-inset-bottom));
        height: calc(100dvh - var(--padding-container) * 2 - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    }
}

@media (prefers-reduced-motion: reduce) {
    .chat-background,
    .chat-container::before,
    .chat-container::after,
    .chat-container,
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

@media print {
    .chat-container {
        border: none;
        box-shadow: none;
    }

    .input-container,
    .chat-background {
        display: none;
    }

    .messages {
        overflow: visible;
    }
}
