:root {
    --bg-dark: #050110;
    --red-side: #ff2d55;
    --blue-side: #007aff;
    --purple-merge: #af52de;
    --glass-bg: rgba(255, 255, 255, 0.08);
    --glass-border: rgba(255, 255, 255, 0.12);
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.6);
    --accent: #a855f7;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #0a0a0f;
    color: #ffffff;
    min-height: 100vh;
    overflow-x: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

#webgl-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
}

.background-blobs {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    background: 
        radial-gradient(circle at 10% 50%, var(--red-side) 0%, transparent 50%),
        radial-gradient(circle at 90% 50%, var(--blue-side) 0%, transparent 50%),
        radial-gradient(circle at 50% 50%, var(--purple-merge) 0%, transparent 60%);
    filter: blur(80px);
    opacity: 0.6;
    animation: cosmicPulse 10s ease-in-out infinite alternate;
}

@keyframes cosmicPulse {
    0% {
        transform: scale(1) translate(0, 0);
        opacity: 0.5;
    }
    50% {
        transform: scale(1.1) translate(-2%, 2%);
        opacity: 0.7;
    }
    100% {
        transform: scale(1.05) translate(2%, -2%);
        opacity: 0.6;
    }
}

.black-hole {
    position: fixed;
    width: 600px;
    height: 600px;
    border-radius: 50%;
    filter: blur(100px);
    z-index: -2;
    opacity: 0.4;
    mix-blend-mode: screen;
}

.bh-red {
    background: var(--red-side);
    left: 50%;
    top: 50%;
    margin-left: -300px;
    margin-top: -300px;
    animation: orbitRed 25s linear infinite;
    mix-blend-mode: screen;
}

.bh-blue {
    background: var(--blue-side);
    left: 50%;
    top: 50%;
    margin-left: -300px;
    margin-top: -300px;
    animation: orbitBlue 18s linear infinite;
    mix-blend-mode: screen;
}

@keyframes orbitRed {
    from { transform: rotate(0deg) translateX(250px) rotate(0deg); }
    to { transform: rotate(360deg) translateX(250px) rotate(-360deg); }
}

@keyframes orbitBlue {
    from { transform: rotate(360deg) translateX(300px) rotate(-360deg); }
    to { transform: rotate(0deg) translateX(300px) rotate(0deg); }
}

.container {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 800px;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.container.chat-active {
    justify-content: flex-start;
    padding-top: 2rem;
    padding-bottom: 2rem;
}

.container.chat-active header {
    margin-bottom: 1rem;
}

.container.chat-active .logo {
    font-size: 2rem;
    margin-bottom: 0.2rem;
}

.container.chat-active .letter {
    animation: none;
}

.container.chat-active .sparkle {
    font-size: 0.8rem;
    right: -0.8rem;
}

.container.chat-active .subtitle {
    font-size: 1rem;
    color: var(--text-primary);
    font-weight: 500;
}

.container.chat-active .chat-history {
    max-height: calc(100vh - 350px);
    margin-bottom: 1rem;
    flex-grow: 1;
    width: 100%;
    display: flex;
    flex-direction: column;
}

header {
    text-align: center;
    margin-bottom: 3rem;
}

.logo {
    font-size: 5rem;
    font-weight: 700;
    letter-spacing: -2px;
    margin-bottom: 0.5rem;
    position: relative;
    font-style: italic;
    display: flex;
    justify-content: center;
}

.letter {
    display: inline-block;
    animation: wave 3s ease-in-out infinite;
}

.letter:nth-child(1) { animation-delay: 0.1s; }
.letter:nth-child(2) { animation-delay: 0.2s; }
.letter:nth-child(3) { animation-delay: 0.3s; }
.letter:nth-child(4) { animation-delay: 0.4s; }
.letter:nth-child(5) { animation-delay: 0.5s; }
.letter:nth-child(6) { animation-delay: 0.6s; }
.letter:nth-child(7) { animation-delay: 0.7s; }

@keyframes wave {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-15px); }
}

.sparkle {
    position: absolute;
    top: 0;
    right: -1.5rem;
    font-size: 1.5rem;
    color: #ffaa40;
}

.subtitle {
    font-size: 1.2rem;
    color: var(--text-secondary);
}

.header-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-top: 0.5rem;
}

.settings-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.settings-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.usage-display {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.05);
    padding: 0.4rem 1rem;
    border-radius: 100px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    width: fit-content;
    margin-left: auto;
}

.usage-display i {
    color: #8b5cf6;
}

.usage-display span {
    font-weight: 600;
    color: var(--text-primary);
}

.auth-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 1rem;
    border-radius: 100px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.auth-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

.auth-btn.image-btn.active {
    background: rgba(139, 92, 246, 0.3);
    border-color: rgba(139, 92, 246, 0.5);
    color: #8b5cf6;
}

main {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.chat-history {
    flex-grow: 1;
    max-height: calc(100vh - 300px);
    width: 100%;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    scroll-behavior: smooth;
}

.message {
    padding: 1.2rem;
    border-radius: 20px;
    max-width: 85%;
    line-height: 1.5;
    position: relative;
    word-wrap: break-word;
    font-size: 1rem;
    animation: messageSlide 0.3s ease-out;
    width: fit-content;
}

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

.message.user {
    align-self: flex-end;
    background: rgba(168, 85, 247, 0.2);
    border: 1px solid rgba(168, 85, 247, 0.3);
    border-bottom-right-radius: 4px;
}

.message.assistant {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-bottom-left-radius: 4px;
    width: 100%;
}

/* Markdown Styling */
.message pre {
    background: #0d1117;
    padding: 1.2rem;
    border-radius: 12px;
    margin: 0.8rem 0;
    overflow-x: auto;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.message code {
    font-family: 'Fira Code', 'Courier New', monospace;
    font-size: 0.95rem;
    color: #e6edf3;
}

.message p {
    margin-bottom: 0.8rem;
}

.message p:last-child {
    margin-bottom: 0;
}

.message ul, .message ol {
    margin-left: 1.5rem;
    margin-bottom: 0.8rem;
}

.message li {
    margin-bottom: 0.4rem;
}

.message a {
    color: #a855f7;
    text-decoration: none;
}

.message a:hover {
    text-decoration: underline;
}

.glass {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
}

.input-section {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    align-items: center;
}

.input-wrapper {
    width: 100%;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

textarea {
    background: transparent;
    border: none;
    color: white;
    font-size: 1.1rem;
    resize: none;
    width: 100%;
    outline: none;
    font-family: inherit;
}

textarea::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

.input-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.model-icon {
    width: 20px;
    height: 20px;
    border-radius: 4px;
}

.dropdown {
    position: relative;
    display: flex;
    justify-content: center;
}

.dropdown-content {
    display: none;
    position: absolute;
    bottom: calc(100% + 15px);
    left: 0;
    min-width: 260px;
    z-index: 1000;
    padding: 0.6rem;
    overflow: hidden;
    background: rgba(30, 30, 40, 0.9);
    backdrop-filter: blur(40px);
    -webkit-backdrop-filter: blur(40px);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 24px;
}

.dropdown-content.show {
    display: block;
    animation: dropdownPop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes dropdownPop {
    from { transform: translateY(20px) scale(0.95); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}

.dropdown-section {
    padding: 0.8rem 1rem 0.4rem;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.8;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    cursor: pointer;
    transition: background 0.2s ease;
    border-radius: 8px;
}

.dropdown-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.dropdown-item .model-icon {
    width: 24px;
    height: 24px;
    border-radius: 4px;
}

.pill-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 100px;
    cursor: pointer;
    font-weight: 500;
    color: var(--text-primary);
    transition: all 0.2s;
}

.pill-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

.send-btn {
    background: #a855f7;
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.2rem;
    transition: transform 0.2s, background 0.2s;
}

.send-btn:hover {
    transform: scale(1.05);
    background: #9333ea;
}

.model-selector-wrapper {
    display: flex;
    justify-content: center;
    width: 100%;
}

.model-info-display {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.6rem 1.2rem;
    border-radius: 100px;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.label {
    color: var(--text-secondary);
}

.model-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 500;
}

.model-icon {
    width: 20px;
    height: 20px;
    border-radius: 4px;
}

.model-controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.image-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    white-space: nowrap;
    opacity: 0.7;
}

.image-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    opacity: 1;
}

.image-btn.active {
    background: linear-gradient(135deg, #8b5cf6, #6366f1);
    border-color: rgba(139, 92, 246, 0.5);
    opacity: 1;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal.show {
    display: flex;
}

.modal-content {
    width: 90%;
    max-width: 500px;
    border-radius: 16px;
    padding: 2rem;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.5rem;
    color: var(--text-primary);
}

.close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.modal-body {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.setting-group h3 {
    margin: 0 0 1rem 0;
    font-size: 1rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.background-options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.75rem;
}

.bg-option {
    padding: 1rem;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9rem;
}

.bg-option:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(139, 92, 246, 0.5);
}

.bg-option.active {
    background: rgba(139, 92, 246, 0.3);
    border-color: rgba(139, 92, 246, 0.5);
    color: #8b5cf6;
}

.battle-container {
    display: flex;
    gap: 1.5rem;
    width: 100%;
    align-items: flex-start;
    margin-bottom: 2rem;
}

.battle-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-width: 0; /* Prevents overflow */
}

.battle-column .message.assistant {
    width: 100%;
    margin: 0;
}

.battle-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.battle-reveal-btn {
    margin-top: 1rem;
    padding: 0.8rem 1.5rem;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--glass-border);
    color: white;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
    font-weight: 600;
}

.battle-reveal-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.battle-reveal-btn.selected {
    background: var(--accent);
    border-color: white;
}

.revealed-name {
    margin-top: 0.5rem;
    font-weight: bold;
    color: #f59e0b;
    text-align: center;
    animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.typing-indicator {
    display: flex;
    gap: 4px;
    align-items: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-style: italic;
}

.typing-indicator::after {
    content: '...';
    display: inline-block;
    width: 20px;
    animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
    0%, 20% { content: ''; }
    40% { content: '.'; }
    60% { content: '..'; }
    80%, 100% { content: '...'; }
}

/* Scrollbar Styling */
.chat-history::-webkit-scrollbar {
    width: 6px;
}

.chat-history::-webkit-scrollbar-track {
    background: transparent;
}

.chat-history::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}
