/* ============================================
   RESET & BASE STYLES
   ============================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Light Theme */
    --bg-primary: #fafafa;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f5f5f5;
    --border-color: #e0e0e0;
    --text-primary: #1a1a1a;
    --text-secondary: #6b7280;
    --user-msg-bg: #ffffff;
    --ai-msg-bg: #f8f9fa;
    --input-bg: #ffffff;
    --input-border: #d1d5db;
    --input-focus-border: #6366f1;
    --send-btn-bg: #6366f1;
    --send-btn-hover: #4f46e5;
    --code-bg: #f8f9fa;
    --code-text: #e11d48;
    --code-border: #e5e7eb;
    --avatar-user: #6366f1;
    --avatar-ai: #1e293b;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --header-bg: rgba(255, 255, 255, 0.8);
    --header-border: #e5e7eb;
}

[data-theme="dark"] {
    /* Dark Theme */
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #141414;
    --border-color: #2a2a2a;
    --text-primary: #e5e5e5;
    --text-secondary: #a3a3a3;
    --user-msg-bg: #1a1a1a;
    --ai-msg-bg: #141414;
    --input-bg: #1a1a1a;
    --input-border: #3a3a3a;
    --input-focus-border: #818cf8;
    --send-btn-bg: #6366f1;
    --send-btn-hover: #818cf8;
    --code-bg: #1a1a1a;
    --code-text: #f472b6;
    --code-border: #2a2a2a;
    --avatar-user: #6366f1;
    --avatar-ai: #3b82f6;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
    --header-bg: rgba(15, 15, 15, 0.8);
    --header-border: #2a2a2a;
}

body {
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color 0.3s ease, color 0.3s ease;
    position: relative;
    touch-action: manipulation; /* Prevent double-tap zoom */
}

/* ============================================
   ANIMATED BACKGROUND
   ============================================ */
.animated-background {
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
}

.animated-background.visible {
    opacity: 1;
    visibility: visible;
}

.bg-gradient {
    position: absolute;
    inset: 0;
    background: linear-gradient(
        135deg,
        rgba(99, 102, 241, 0.12) 0%,
        rgba(139, 92, 246, 0.12) 25%,
        rgba(236, 72, 153, 0.12) 50%,
        rgba(99, 102, 241, 0.12) 75%,
        rgba(139, 92, 246, 0.12) 100%
    );
    background-size: 400% 400%;
    animation: gradientMove 15s ease infinite;
    opacity: 1;
}

[data-theme="dark"] .bg-gradient {
    background: linear-gradient(
        135deg,
        rgba(99, 102, 241, 0.08) 0%,
        rgba(139, 92, 246, 0.08) 25%,
        rgba(59, 130, 246, 0.08) 50%,
        rgba(99, 102, 241, 0.08) 75%,
        rgba(139, 92, 246, 0.08) 100%
    );
    background-size: 400% 400%;
    opacity: 0.4;
}

@keyframes gradientMove {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

.bg-particles {
    position: absolute;
    inset: 0;
}

.particle {
    position: absolute;
    width: 6px;
    height: 6px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    border-radius: 50%;
    opacity: 0.6;
    animation: floatParticle 20s infinite ease-in-out;
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.5);
}

[data-theme="dark"] .particle {
    background: linear-gradient(135deg, #6366f1, #3b82f6);
    opacity: 0.7;
    box-shadow: 0 0 15px rgba(99, 102, 241, 0.6);
}

.particle:nth-child(1) {
    left: 10%;
    animation-delay: 0s;
    animation-duration: 15s;
}

.particle:nth-child(2) {
    left: 20%;
    animation-delay: 2s;
    animation-duration: 18s;
}

.particle:nth-child(3) {
    left: 30%;
    animation-delay: 4s;
    animation-duration: 20s;
}

.particle:nth-child(4) {
    left: 40%;
    animation-delay: 1s;
    animation-duration: 16s;
}

.particle:nth-child(5) {
    left: 50%;
    animation-delay: 3s;
    animation-duration: 19s;
}

.particle:nth-child(6) {
    left: 60%;
    animation-delay: 5s;
    animation-duration: 17s;
}

.particle:nth-child(7) {
    left: 70%;
    animation-delay: 2.5s;
    animation-duration: 21s;
}

.particle:nth-child(8) {
    left: 80%;
    animation-delay: 4.5s;
    animation-duration: 18s;
}

.particle:nth-child(9) {
    left: 90%;
    animation-delay: 1.5s;
    animation-duration: 16s;
}

.particle:nth-child(10) {
    left: 15%;
    animation-delay: 3.5s;
    animation-duration: 20s;
}

.particle:nth-child(11) {
    left: 25%;
    animation-delay: 6s;
    animation-duration: 22s;
}

.particle:nth-child(12) {
    left: 35%;
    animation-delay: 7s;
    animation-duration: 18s;
}

.particle:nth-child(13) {
    left: 45%;
    animation-delay: 8s;
    animation-duration: 19s;
}

.particle:nth-child(14) {
    left: 55%;
    animation-delay: 9s;
    animation-duration: 21s;
}

.particle:nth-child(15) {
    left: 65%;
    animation-delay: 10s;
    animation-duration: 17s;
}

.particle:nth-child(16) {
    left: 75%;
    animation-delay: 11s;
    animation-duration: 23s;
}

.particle:nth-child(17) {
    left: 85%;
    animation-delay: 12s;
    animation-duration: 16s;
}

.particle:nth-child(18) {
    left: 5%;
    animation-delay: 13s;
    animation-duration: 24s;
}

.particle:nth-child(19) {
    left: 95%;
    animation-delay: 14s;
    animation-duration: 20s;
}

.particle:nth-child(20) {
    left: 12%;
    animation-delay: 15s;
    animation-duration: 18s;
}

.particle:nth-child(21) {
    left: 22%;
    animation-delay: 16s;
    animation-duration: 22s;
}

.particle:nth-child(22) {
    left: 32%;
    animation-delay: 17s;
    animation-duration: 19s;
}

.particle:nth-child(23) {
    left: 42%;
    animation-delay: 18s;
    animation-duration: 21s;
}

.particle:nth-child(24) {
    left: 52%;
    animation-delay: 19s;
    animation-duration: 17s;
}

.particle:nth-child(25) {
    left: 62%;
    animation-delay: 20s;
    animation-duration: 23s;
}

@keyframes floatParticle {
    0%, 100% {
        transform: translateY(100vh) translateX(0) scale(0);
        opacity: 0;
    }
    10% {
        opacity: 0.3;
    }
    50% {
        transform: translateY(50vh) translateX(50px) scale(1);
        opacity: 0.5;
    }
    90% {
        opacity: 0.3;
    }
    100% {
        transform: translateY(-10vh) translateX(100px) scale(0);
        opacity: 0;
    }
}

.bg-shapes {
    position: absolute;
    inset: 0;
}

.shape {
    position: absolute;
    border-radius: 50%;
    filter: blur(60px);
    opacity: 0.25;
    animation: shapeFloat 25s infinite ease-in-out;
}

.shape-1 {
    width: 300px;
    height: 300px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    top: 10%;
    left: 10%;
    animation-duration: 20s;
}

.shape-2 {
    width: 250px;
    height: 250px;
    background: linear-gradient(135deg, #8b5cf6, #ec4899);
    top: 60%;
    right: 10%;
    animation-duration: 25s;
    animation-delay: 5s;
}

.shape-3 {
    width: 200px;
    height: 200px;
    background: linear-gradient(135deg, #ec4899, #6366f1);
    bottom: 20%;
    left: 50%;
    animation-duration: 30s;
    animation-delay: 10s;
}

.shape-4 {
    width: 350px;
    height: 350px;
    background: linear-gradient(135deg, #6366f1, #3b82f6);
    top: 30%;
    right: 30%;
    animation-duration: 22s;
    animation-delay: 7s;
}

.shape-5 {
    width: 280px;
    height: 280px;
    background: linear-gradient(135deg, #ec4899, #8b5cf6);
    bottom: 10%;
    right: 20%;
    animation-duration: 28s;
    animation-delay: 12s;
}

.shape-6 {
    width: 320px;
    height: 320px;
    background: linear-gradient(135deg, #3b82f6, #6366f1);
    top: 50%;
    left: 5%;
    animation-duration: 24s;
    animation-delay: 15s;
}

.shape-7 {
    width: 240px;
    height: 240px;
    background: linear-gradient(135deg, #8b5cf6, #ec4899);
    top: 15%;
    left: 60%;
    animation-duration: 26s;
    animation-delay: 18s;
}

.shape-8 {
    width: 290px;
    height: 290px;
    background: linear-gradient(135deg, #6366f1, #3b82f6);
    bottom: 30%;
    right: 5%;
    animation-duration: 27s;
    animation-delay: 20s;
}

[data-theme="dark"] .shape {
    opacity: 0.3;
}

@keyframes shapeFloat {
    0%, 100% {
        transform: translate(0, 0) scale(1) rotate(0deg);
    }
    25% {
        transform: translate(50px, -50px) scale(1.1) rotate(90deg);
    }
    50% {
        transform: translate(-30px, 30px) scale(0.9) rotate(180deg);
    }
    75% {
        transform: translate(30px, 50px) scale(1.05) rotate(270deg);
    }
}

/* ============================================
   BACKGROUND GRID
   ============================================ */
.bg-grid {
    position: absolute;
    inset: 0;
    background-image: 
        linear-gradient(rgba(99, 102, 241, 0.08) 1px, transparent 1px),
        linear-gradient(90deg, rgba(99, 102, 241, 0.08) 1px, transparent 1px);
    background-size: 50px 50px;
    animation: gridMove 20s linear infinite;
    opacity: 0.6;
}

[data-theme="dark"] .bg-grid {
    background-image: 
        linear-gradient(rgba(99, 102, 241, 0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(99, 102, 241, 0.05) 1px, transparent 1px);
    opacity: 0.3;
}

@keyframes gridMove {
    0% {
        transform: translate(0, 0);
    }
    100% {
        transform: translate(50px, 50px);
    }
}

/* ============================================
   ANIMATED LINES
   ============================================ */
.bg-lines {
    position: absolute;
    inset: 0;
}

.line {
    position: absolute;
    background: linear-gradient(90deg, transparent, rgba(99, 102, 241, 0.4), transparent);
    height: 2px;
    width: 100%;
    animation: lineMove 15s linear infinite;
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.3);
}

.line-1 {
    top: 20%;
    animation-duration: 15s;
    animation-delay: 0s;
}

.line-2 {
    top: 40%;
    animation-duration: 18s;
    animation-delay: 3s;
    background: linear-gradient(90deg, transparent, rgba(139, 92, 246, 0.2), transparent);
}

.line-3 {
    top: 60%;
    animation-duration: 20s;
    animation-delay: 6s;
    background: linear-gradient(90deg, transparent, rgba(236, 72, 153, 0.2), transparent);
}

.line-4 {
    top: 80%;
    animation-duration: 17s;
    animation-delay: 9s;
    background: linear-gradient(90deg, transparent, rgba(99, 102, 241, 0.15), transparent);
}

.line-5 {
    top: 10%;
    animation-duration: 22s;
    animation-delay: 12s;
    background: linear-gradient(90deg, transparent, rgba(59, 130, 246, 0.2), transparent);
}

[data-theme="dark"] .line {
    background: linear-gradient(90deg, transparent, rgba(99, 102, 241, 0.3), transparent);
}

[data-theme="dark"] .line-2 {
    background: linear-gradient(90deg, transparent, rgba(139, 92, 246, 0.3), transparent);
}

[data-theme="dark"] .line-3 {
    background: linear-gradient(90deg, transparent, rgba(59, 130, 246, 0.3), transparent);
}

[data-theme="dark"] .line-4 {
    background: linear-gradient(90deg, transparent, rgba(99, 102, 241, 0.25), transparent);
}

[data-theme="dark"] .line-5 {
    background: linear-gradient(90deg, transparent, rgba(59, 130, 246, 0.3), transparent);
}

@keyframes lineMove {
    0% {
        transform: translateX(-100%);
        opacity: 0;
    }
    10% {
        opacity: 1;
    }
    90% {
        opacity: 1;
    }
    100% {
        transform: translateX(100%);
        opacity: 0;
    }
}

/* ============================================
   ORBITAL ELEMENTS
   ============================================ */
.bg-orbits {
    position: absolute;
    inset: 0;
}

.orbit {
    position: absolute;
    border: 2px solid;
    border-radius: 50%;
    opacity: 0.3;
    animation: orbitRotate 30s linear infinite;
}

.orbit::before {
    content: '';
    position: absolute;
    width: 8px;
    height: 8px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    border-radius: 50%;
    top: -4px;
    left: 50%;
    transform: translateX(-50%);
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.5);
}

.orbit-1 {
    width: 400px;
    height: 400px;
    border-color: rgba(99, 102, 241, 0.2);
    top: 10%;
    left: 20%;
    animation-duration: 30s;
}

.orbit-2 {
    width: 500px;
    height: 500px;
    border-color: rgba(139, 92, 246, 0.2);
    bottom: 15%;
    right: 15%;
    animation-duration: 40s;
    animation-direction: reverse;
}

.orbit-3 {
    width: 350px;
    height: 350px;
    border-color: rgba(236, 72, 153, 0.2);
    top: 50%;
    left: 50%;
    margin-left: -175px;
    margin-top: -175px;
    animation-duration: 35s;
}

[data-theme="dark"] .orbit {
    opacity: 0.15;
    border-color: rgba(99, 102, 241, 0.3);
}

[data-theme="dark"] .orbit-2 {
    border-color: rgba(139, 92, 246, 0.3);
}

[data-theme="dark"] .orbit-3 {
    border-color: rgba(59, 130, 246, 0.3);
}

@keyframes orbitRotate {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

/* ============================================
   HEADER
   ============================================ */
.app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--header-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--header-border);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.header-content {
    max-width: 768px;
    margin: 0 auto;
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

.header-content .sidebar-toggle {
    position: fixed;
    left: 1rem;
    top: 0.5rem;
    margin: 0;
    z-index: 150;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Desktop: sidebar overlays, no layout changes */

.header-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    position: fixed;
    right: 1.5rem;
    top: 0.5rem;
    z-index: 150;
}


.logo-wrap {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    position: relative;
}

.logo-orbit {
    width: 28px;
    height: 28px;
    border-radius: 999px;
    border: 1px solid rgba(99, 102, 241, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.04);
}

[data-theme="dark"] .logo-orbit {
    border-color: rgba(129, 140, 248, 0.7);
    box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.9);
}

.logo-orbit::before {
    content: '';
    position: absolute;
    width: 140%;
    height: 140%;
    background: conic-gradient(from 180deg, #6366f1, #8b5cf6, #ec4899, #6366f1);
    animation: orbitSpin 6s linear infinite;
    opacity: 0.9;
}

.logo-orbit-inner {
    position: relative;
    width: 85%;
    height: 85%;
    border-radius: inherit;
    background: radial-gradient(circle at 30% 0%, #f9fafb, #e5e7eb);
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: 700;
    color: #111827;
}

[data-theme="dark"] .logo-orbit-inner {
    background: radial-gradient(circle at 30% 0%, #111827, #020617);
    color: #e5e7eb;
}

.logo-orbit-inner::before {
    content: 'F';
}

@keyframes orbitSpin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.logo {
    font-size: 1.25rem;
    font-weight: 600;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #ec4899 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin: 0;
    background-size: 200% 200%;
    animation: gradientShift 3s ease infinite, logoGlow 2s ease-in-out infinite;
    position: relative;
    cursor: pointer;
    transition: transform 0.3s ease;
}

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

.logo-pill {
    font-size: 0.75rem;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.4);
    background: radial-gradient(circle at 0 0, rgba(148, 163, 184, 0.15), transparent);
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

[data-theme="dark"] .logo-pill {
    border-color: rgba(75, 85, 99, 0.8);
    background: radial-gradient(circle at 0 0, rgba(37, 99, 235, 0.25), transparent);
}

@keyframes logoGlow {
    0%, 100% {
        filter: drop-shadow(0 0 5px rgba(99, 102, 241, 0.3));
    }
    50% {
        filter: drop-shadow(0 0 15px rgba(139, 92, 246, 0.5));
    }
}

@keyframes logoGlowHover {
    0%, 100% {
        opacity: 0.3;
        transform: scale(1);
    }
    50% {
        opacity: 0.5;
        transform: scale(1.1);
    }
}

.theme-toggle {
    width: 40px;
    height: 40px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    color: var(--text-primary);
    padding: 0;
}

.theme-toggle:hover {
    background: var(--bg-tertiary);
    border-color: var(--input-focus-border);
}

.theme-toggle svg {
    width: 20px;
    height: 20px;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.theme-toggle:hover svg {
    transform: rotate(180deg);
}

[data-theme="dark"] .sun-icon {
    display: none;
}

[data-theme="light"] .moon-icon {
    display: none;
}

/* ============================================
   SIDEBAR
   ============================================ */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 280px;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 2px 0 20px rgba(0, 0, 0, 0.1);
    -webkit-overflow-scrolling: touch;
}

.sidebar.open {
    transform: translateX(0);
}

.sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.user-section {
    position: relative;
}

.current-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.2s ease;
}

.current-user:hover {
    background: var(--bg-primary);
    border-color: var(--input-focus-border);
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 1rem;
    color: white;
    flex-shrink: 0;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
}

.user-info {
    flex: 1;
    min-width: 0;
}

.user-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.redo-invite-btn {
    width: 100%;
    padding: 0.75rem 1rem;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.2s ease;
}

.redo-invite-btn:hover {
    background: rgba(59, 130, 246, 0.1);
    border-color: #3b82f6;
    color: #3b82f6;
    transform: translateY(-1px);
}

.delete-all-btn {
    width: 100%;
    padding: 0.75rem 1rem;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.2s ease;
}

.delete-all-btn:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: #ef4444;
    color: #ef4444;
    transform: translateY(-1px);
}

.sidebar-close-btn {
    width: 100%;
    padding: 0.65rem 1rem;
    background: var(--bg-tertiary);
    border: 1px dashed var(--border-color);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    transition: all 0.2s ease;
}

.sidebar-close-btn:hover {
    border-color: var(--input-focus-border);
    color: var(--input-focus-border);
    transform: translateY(-1px);
}

/* Registration Modal */
.registration-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1500;
    visibility: hidden;
    opacity: 0;
}

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

.registration-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 2rem;
    max-width: 400px;
    width: 90%;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.3s ease;
}

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

.registration-content h2 {
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 1.5rem 0;
    text-align: center;
}

#username-input {
    width: 100%;
    padding: 1rem 1.25rem;
    background: var(--input-bg);
    border: 2px solid var(--input-border);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 1.125rem;
    font-family: inherit;
    transition: all 0.3s ease;
    box-sizing: border-box;
    text-align: center;
}

#username-input:focus {
    outline: none;
    border-color: var(--input-focus-border);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

#username-input::placeholder {
    color: var(--text-secondary);
}

.user-menu-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    padding: 0;
    flex-shrink: 0;
}

.user-menu-btn:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
}

.user-menu {
    position: absolute;
    top: calc(100% + 0.5rem);
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: var(--shadow-lg);
    z-index: 10;
    opacity: 0;
    transform: translateY(-10px);
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    max-height: 0;
    overflow: hidden;
}

.user-menu.open {
    opacity: 1;
    transform: translateY(0);
    pointer-events: all;
    max-height: 400px;
}

.user-menu-item {
    width: 100%;
    padding: 0.75rem 1rem;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: all 0.2s ease;
    border-bottom: 1px solid var(--border-color);
}

.user-menu-item:hover {
    background: var(--bg-tertiary);
}

.user-list {
    max-height: 300px;
    overflow-y: auto;
}

.user-list::-webkit-scrollbar {
    width: 6px;
}

.user-list::-webkit-scrollbar-track {
    background: transparent;
}

.user-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.user-item {
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border-bottom: 1px solid var(--border-color);
}

.user-item:last-child {
    border-bottom: none;
}

.user-item:hover {
    background: var(--bg-tertiary);
}

.user-item.active {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.1), rgba(139, 92, 246, 0.1));
}

.user-item-avatar {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
    color: white;
    flex-shrink: 0;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
}

.user-item-name {
    flex: 1;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.new-chat-btn {
    width: 100%;
    padding: 0.75rem 1rem;
    background: linear-gradient(135deg, var(--send-btn-bg) 0%, #8b5cf6 100%);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}

.new-chat-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    background: linear-gradient(135deg, var(--send-btn-hover) 0%, #7c3aed 100%);
}

.new-chat-btn:active {
    transform: translateY(0);
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.sidebar-content::-webkit-scrollbar {
    width: 6px;
}

.sidebar-content::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-content::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.chat-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.chat-item {
    padding: 0.75rem;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    position: relative;
    background: transparent;
    border: 1px solid transparent;
    /* Improved touch target */
    min-height: 56px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.chat-item:hover {
    background: var(--bg-tertiary);
    border-color: var(--border-color);
}

.chat-item.active {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.1), rgba(139, 92, 246, 0.1));
    border-color: var(--input-focus-border);
}

.chat-item-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.chat-item-title {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-preview {
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-actions {
    display: flex;
    gap: 0.25rem;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.chat-item:hover .chat-item-actions {
    opacity: 1;
}

.chat-item-btn {
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    padding: 0;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.chat-item-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.chat-item-btn.delete:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.sidebar-toggle {
    width: 40px;
    height: 40px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease, box-shadow 0.2s ease, opacity 0.3s ease;
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    border: none;
    padding: 0;
}

.sidebar-toggle:hover {
    background: var(--bg-tertiary);
    box-shadow: var(--shadow-md);
}

.sidebar-toggle:active {
    opacity: 0.8;
}

.sidebar-toggle-icon.hidden {
    opacity: 0;
    visibility: hidden;
}

body.sidebar-open .sidebar-toggle-icon {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 199;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    backdrop-filter: blur(2px);
    display: block; /* Always visible, just transparent when sidebar closed */
}

.sidebar.open + .sidebar-overlay {
    opacity: 1;
    pointer-events: all;
}

@media (min-width: 769px) {
    /* Show overlay on desktop too - sidebar overlays, doesn't push */
    .sidebar-overlay {
        display: block;
    }
}

@media (max-width: 768px) {
    .sidebar-overlay {
        touch-action: manipulation;
    }
}

/* ============================================
   APP CONTAINER
   ============================================ */
.app-container {
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    transition: background-color 0.3s ease;
    position: relative;
    z-index: 1;
    overflow-x: hidden;
    width: 100%;
    opacity: 0;
    visibility: hidden;
}

.app-container.visible {
    opacity: 1;
    visibility: visible;
}

.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 768px;
    width: 100%;
    margin: 0 auto;
    position: relative;
    overflow: hidden;
    /* No transitions - sidebar doesn't affect layout */
}

/* ============================================
   CHAT TOOLBAR / SEARCH
   ============================================ */
.chat-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1.5rem 0.25rem 1.5rem;
    max-width: 768px;
    margin: 0 auto;
    gap: 0.75rem;
}

.chat-toolbar-left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    border: 1px solid rgba(148, 163, 184, 0.5);
    background: rgba(248, 250, 252, 0.8);
    color: #0f172a;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    position: relative;
}

/* Green Status (Fast/Normal) */
.status-green .status-dot {
    background: radial-gradient(circle at 30% 30%, #dcfce7, #22c55e);
    box-shadow:
        0 0 0 4px rgba(34, 197, 94, 0.25),
        0 0 10px rgba(34, 197, 94, 0.5),
        inset 0 0 4px rgba(255, 255, 255, 0.6);
}

.status-green .status-dot::after {
    content: "";
    position: absolute;
    inset: -3px;
    border-radius: 999px;
    border: 1px solid rgba(34, 197, 94, 0.45);
    opacity: 0.7;
}

[data-theme="dark"] .status-green .status-dot {
    background: radial-gradient(circle at 30% 30%, #bbf7d0, #16a34a);
    box-shadow:
        0 0 0 4px rgba(34, 197, 94, 0.35),
        0 0 12px rgba(34, 197, 94, 0.55),
        inset 0 0 5px rgba(255, 255, 255, 0.4);
}

[data-theme="dark"] .status-green .status-dot::after {
    border-color: rgba(34, 197, 94, 0.6);
}

/* Yellow Status (Slow) */
.status-yellow .status-dot {
    background: radial-gradient(circle at 30% 30%, #fffceb, #facc15);
    box-shadow:
        0 0 0 4px rgba(250, 204, 21, 0.25),
        0 0 10px rgba(250, 204, 21, 0.5),
        inset 0 0 4px rgba(255, 255, 255, 0.6);
}

.status-yellow .status-dot::after {
    content: "";
    position: absolute;
    inset: -3px;
    border-radius: 999px;
    border: 1px solid rgba(250, 204, 21, 0.45);
    opacity: 0.7;
}

[data-theme="dark"] .status-yellow .status-dot {
    background: radial-gradient(circle at 30% 30%, #fef3c7, #fbbf24);
    box-shadow:
        0 0 0 4px rgba(251, 191, 36, 0.35),
        0 0 12px rgba(251, 191, 36, 0.55),
        inset 0 0 5px rgba(255, 255, 255, 0.4);
}

[data-theme="dark"] .status-yellow .status-dot::after {
    border-color: rgba(251, 191, 36, 0.6);
}

/* Red Status (Down/Critical) */
.status-red .status-dot {
    background: radial-gradient(circle at 30% 30%, #fee2e2, #ef4444);
    box-shadow:
        0 0 0 4px rgba(239, 68, 68, 0.25),
        0 0 10px rgba(239, 68, 68, 0.5),
        inset 0 0 4px rgba(255, 255, 255, 0.6);
    animation: pulseRed 2s ease-in-out infinite;
}

.status-red .status-dot::after {
    content: "";
    position: absolute;
    inset: -3px;
    border-radius: 999px;
    border: 1px solid rgba(239, 68, 68, 0.45);
    opacity: 0.7;
}

[data-theme="dark"] .status-red .status-dot {
    background: radial-gradient(circle at 30% 30%, #fecaca, #dc2626);
    box-shadow:
        0 0 0 4px rgba(239, 68, 68, 0.35),
        0 0 12px rgba(239, 68, 68, 0.55),
        inset 0 0 5px rgba(255, 255, 255, 0.4);
}

[data-theme="dark"] .status-red .status-dot::after {
    border-color: rgba(239, 68, 68, 0.6);
}

@keyframes pulseRed {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.8;
        transform: scale(1.1);
    }
}

.status-label {
    letter-spacing: 0.05em;
    font-weight: 600;
}

/* Status wrapper for tooltip positioning */
.status-wrapper {
    position: relative;
    display: inline-flex;
}

/* Status message tooltip */
.status-message-tooltip {
    position: absolute;
    top: calc(100% + 12px);
    left: 50%;
    transform: translateX(-50%) translateY(-8px) scale(0.9);
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 1000;
    min-width: 280px;
    max-width: 400px;
    filter: drop-shadow(0 10px 30px rgba(0, 0, 0, 0.3));
}

.status-wrapper:hover .status-message-tooltip,
.status-wrapper:focus-within .status-message-tooltip {
    opacity: 1;
    transform: translateX(-50%) translateY(0) scale(1);
    pointer-events: all;
}

.status-message-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 0.875rem 1rem;
    font-size: 0.8125rem;
    line-height: 1.5;
    color: var(--text-primary);
    box-shadow: var(--shadow-lg);
    text-align: left;
    position: relative;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

[data-theme="dark"] .status-message-content {
    background: rgba(26, 26, 26, 0.95);
    border-color: rgba(55, 65, 81, 0.8);
}

.status-message-arrow {
    position: absolute;
    top: -6px;
    left: 50%;
    transform: translateX(-50%);
    width: 12px;
    height: 12px;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    border-top: 1px solid var(--border-color);
    transform: translateX(-50%) rotate(45deg);
}

[data-theme="dark"] .status-message-arrow {
    background: rgba(26, 26, 26, 0.95);
    border-color: rgba(55, 65, 81, 0.8);
}

/* Status-specific tooltip colors */
.status-green.status-pill ~ .status-message-tooltip .status-message-content {
    background: rgba(236, 253, 245, 0.98);
    border-color: rgba(34, 197, 94, 0.3);
    color: #15803d;
}

.status-green.status-pill ~ .status-message-tooltip .status-message-arrow {
    background: rgba(236, 253, 245, 0.98);
    border-left-color: rgba(34, 197, 94, 0.3);
    border-top-color: rgba(34, 197, 94, 0.3);
}

.status-yellow.status-pill ~ .status-message-tooltip .status-message-content {
    background: rgba(254, 252, 232, 0.98);
    border-color: rgba(250, 204, 21, 0.3);
    color: #a16207;
}

.status-yellow.status-pill ~ .status-message-tooltip .status-message-arrow {
    background: rgba(254, 252, 232, 0.98);
    border-left-color: rgba(250, 204, 21, 0.3);
    border-top-color: rgba(250, 204, 21, 0.3);
}

.status-red.status-pill ~ .status-message-tooltip .status-message-content {
    background: rgba(254, 242, 242, 0.98);
    border-color: rgba(239, 68, 68, 0.3);
    color: #991b1b;
}

.status-red.status-pill ~ .status-message-tooltip .status-message-arrow {
    background: rgba(254, 242, 242, 0.98);
    border-left-color: rgba(239, 68, 68, 0.3);
    border-top-color: rgba(239, 68, 68, 0.3);
}

[data-theme="dark"] .status-green.status-pill ~ .status-message-tooltip .status-message-content {
    background: rgba(6, 78, 59, 0.95);
    border-color: rgba(34, 197, 94, 0.5);
    color: #86efac;
}

[data-theme="dark"] .status-yellow.status-pill ~ .status-message-tooltip .status-message-content {
    background: rgba(113, 63, 18, 0.95);
    border-color: rgba(250, 204, 21, 0.5);
    color: #fde68a;
}

[data-theme="dark"] .status-red.status-pill ~ .status-message-tooltip .status-message-content {
    background: rgba(127, 29, 29, 0.95);
    border-color: rgba(239, 68, 68, 0.5);
    color: #fca5a5;
}

[data-theme="dark"] .status-green.status-pill ~ .status-message-tooltip .status-message-arrow {
    background: rgba(6, 78, 59, 0.95);
    border-left-color: rgba(34, 197, 94, 0.5);
    border-top-color: rgba(34, 197, 94, 0.5);
}

[data-theme="dark"] .status-yellow.status-pill ~ .status-message-tooltip .status-message-arrow {
    background: rgba(113, 63, 18, 0.95);
    border-left-color: rgba(250, 204, 21, 0.5);
    border-top-color: rgba(250, 204, 21, 0.5);
}

[data-theme="dark"] .status-red.status-pill ~ .status-message-tooltip .status-message-arrow {
    background: rgba(127, 29, 29, 0.95);
    border-left-color: rgba(239, 68, 68, 0.5);
    border-top-color: rgba(239, 68, 68, 0.5);
}

/* Make status pill interactive */
.status-pill {
    cursor: pointer;
    transition: all 0.2s ease;
    /* Improved touch target */
    min-height: 32px;
    display: inline-flex;
    align-items: center;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.status-pill:hover {
    transform: translateY(-1px);
}

@media (max-width: 768px) {
    .status-pill {
        min-height: 44px;
        padding: 0.35rem 0.75rem;
    }
}

/* Status pill colors based on status */
.status-green.status-pill {
    gap: 0.55rem;
    border-color: rgba(34, 197, 94, 0.6);
    color: #15803d;
    background: rgba(236, 253, 245, 0.9);
}

.status-yellow.status-pill {
    gap: 0.55rem;
    border-color: rgba(250, 204, 21, 0.6);
    color: #a16207;
    background: rgba(254, 252, 232, 0.9);
}

.status-red.status-pill {
    gap: 0.55rem;
    border-color: rgba(239, 68, 68, 0.6);
    color: #991b1b;
    background: rgba(254, 242, 242, 0.9);
}

.status-temp {
    background: rgba(239, 246, 255, 0.9);
    border-color: rgba(129, 140, 248, 0.6);
    color: #1d4ed8;
}

[data-theme="dark"] .status-pill {
    background: rgba(15, 23, 42, 0.9);
    border-color: rgba(55, 65, 81, 0.9);
    color: #e5e7eb;
}

[data-theme="dark"] .status-green.status-pill {
    border-color: rgba(34, 197, 94, 0.7);
    color: #86efac;
    background: rgba(6, 78, 59, 0.4);
}

[data-theme="dark"] .status-yellow.status-pill {
    border-color: rgba(250, 204, 21, 0.7);
    color: #fde68a;
    background: rgba(113, 63, 18, 0.4);
}

[data-theme="dark"] .status-red.status-pill {
    border-color: rgba(239, 68, 68, 0.7);
    color: #fca5a5;
    background: rgba(127, 29, 29, 0.4);
}

[data-theme="dark"] .status-temp {
    background: rgba(15, 23, 42, 0.9);
    border-color: rgba(129, 140, 248, 0.9);
    color: #a5b4fc;
}


.chat-toolbar-right {
    flex: 1;
    display: flex;
    justify-content: flex-end;
}

.search-box {
    min-width: 0;
    max-width: 320px;
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    box-shadow: var(--shadow-sm);
}

.search-icon {
    color: var(--text-secondary);
    flex-shrink: 0;
}

.search-box input {
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 0.8rem;
    width: 100%;
    outline: none;
}

.search-box input::placeholder {
    color: var(--text-secondary);
}

.search-box:focus-within {
    border-color: var(--input-focus-border);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.search-filters {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    margin-left: 0.25rem;
    padding-left: 0.5rem;
    border-left: 1px solid var(--border-color);
}

.filter-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.filter-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--border-color);
}

.filter-btn.active {
    background: var(--send-btn-bg);
    color: white;
    border-color: var(--send-btn-bg);
}

.filter-btn.active#filter-liked {
    background: rgba(34, 197, 94, 0.15);
    color: #15803d;
    border-color: rgba(34, 197, 94, 0.4);
}

.filter-btn.active#filter-disliked {
    background: rgba(248, 113, 113, 0.15);
    color: #b91c1c;
    border-color: rgba(248, 113, 113, 0.4);
}

[data-theme="dark"] .filter-btn.active#filter-liked {
    background: rgba(22, 163, 74, 0.35);
    color: #86efac;
    border-color: rgba(34, 197, 94, 0.9);
}

[data-theme="dark"] .filter-btn.active#filter-disliked {
    background: rgba(127, 29, 29, 0.55);
    color: #fecaca;
    border-color: rgba(248, 113, 113, 0.95);
}

.filter-btn svg {
    width: 14px;
    height: 14px;
}

.message-filtered-out {
    opacity: 0.3;
    pointer-events: none;
}

/* Desktop: sidebar overlays, no layout changes */

/* ============================================
   CHAT CONTAINER
   ============================================ */
#chat-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    position: relative;
    min-height: 0;
}

#chat-container::-webkit-scrollbar {
    width: 8px;
}

#chat-container::-webkit-scrollbar-track {
    background: transparent;
}

#chat-container::-webkit-scrollbar-thumb {
    background: transparent;
    border-radius: 4px;
    transition: background-color 0.3s ease;
}

#chat-container.scrolling::-webkit-scrollbar-thumb {
    background: var(--border-color);
}

#chat-container::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ============================================
   WELCOME SCREEN
   ============================================ */
.welcome-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 2rem;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s ease;
}

.welcome-content {
    text-align: center;
    max-width: 500px;
}

.welcome-content h1 {
    font-size: 3rem;
    font-weight: 700;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #ec4899 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.75rem;
    letter-spacing: -0.02em;
    background-size: 200% 200%;
    animation: gradientShift 3s ease infinite, welcomeTitleGlow 2s ease-in-out infinite;
    position: relative;
    text-shadow: 0 0 30px rgba(99, 102, 241, 0.3);
    filter: drop-shadow(0 0 20px rgba(139, 92, 246, 0.4));
}

.welcome-content h1::before {
    content: 'Frostbyte';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, #6366f1, #8b5cf6, #ec4899);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    background-size: 200% 200%;
    animation: gradientShift 3s ease infinite;
    z-index: -1;
    filter: blur(10px);
    opacity: 0.5;
}

@keyframes welcomeTitleGlow {
    0%, 100% {
        filter: drop-shadow(0 0 20px rgba(99, 102, 241, 0.4)) drop-shadow(0 0 40px rgba(139, 92, 246, 0.2));
        transform: scale(1);
    }
    50% {
        filter: drop-shadow(0 0 30px rgba(99, 102, 241, 0.6)) drop-shadow(0 0 60px rgba(139, 92, 246, 0.4));
        transform: scale(1.02);
    }
}

.welcome-content p {
    font-size: 1.125rem;
    color: var(--text-secondary);
    font-weight: 400;
    animation: welcomeSubtitleFade 3s ease-in-out infinite;
    position: relative;
}

@keyframes welcomeSubtitleFade {
    0%, 100% {
        opacity: 0.7;
        transform: translateY(0);
    }
    50% {
        opacity: 1;
        transform: translateY(-5px);
    }
}

.welcome-screen.hidden {
    opacity: 0;
    visibility: hidden;
    transform: scale(0.95);
    pointer-events: none;
}

/* ============================================
   MESSAGES
   ============================================ */
.message {
    display: flex;
    gap: 1.25rem;
    padding: 1.75rem 1.5rem;
    animation: fadeIn 0.4s ease-out;
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.message.user-msg {
    border-left: 3px solid rgba(99, 102, 241, 0.35);
}

.message.ai-msg {
    border-left: 3px solid rgba(236, 72, 153, 0.3);
}

[data-theme="dark"] .message.user-msg {
    border-left-color: rgba(129, 140, 248, 0.7);
}

[data-theme="dark"] .message.ai-msg {
    border-left-color: rgba(251, 113, 133, 0.7);
}

.message:last-child {
    border-bottom: none;
}

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

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
    color: white;
    background: linear-gradient(135deg, var(--avatar-user) 0%, #8b5cf6 100%);
}

.ai-msg .message-avatar {
    background: linear-gradient(135deg, var(--avatar-ai) 0%, #334155 100%);
}

[data-theme="dark"] .ai-msg .message-avatar {
    background: linear-gradient(135deg, var(--avatar-ai) 0%, #6366f1 100%);
}

.message-content {
    flex: 1;
    min-width: 0;
    padding-top: 0.25rem;
}

.message-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.35rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.message-meta-left {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.message-author {
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    font-size: 0.7rem;
}

.message-role-pill {
    padding: 0.05rem 0.4rem;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.6);
    font-size: 0.65rem;
}

.user-msg .message-role-pill {
    background: rgba(219, 234, 254, 0.85);
    border-color: rgba(96, 165, 250, 0.8);
    color: #1d4ed8;
}

.ai-msg .message-role-pill {
    background: rgba(254, 242, 242, 0.9);
    border-color: rgba(248, 113, 113, 0.8);
    color: #b91c1c;
}

[data-theme="dark"] .user-msg .message-role-pill {
    background: rgba(15, 23, 42, 0.9);
    border-color: rgba(96, 165, 250, 0.8);
    color: #bfdbfe;
}

[data-theme="dark"] .ai-msg .message-role-pill {
    background: rgba(24, 24, 27, 0.9);
    border-color: rgba(248, 113, 113, 0.8);
    color: #fecaca;
}

.message-id {
    padding: 0.05rem 0.45rem;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.6);
    font-size: 0.65rem;
    cursor: pointer;
    user-select: none;
    /* Improved touch target */
    min-height: 32px;
    display: inline-flex;
    align-items: center;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.message-id:hover {
    border-color: var(--input-focus-border);
}

@media (max-width: 768px) {
    .message-id {
        min-height: 44px;
        padding: 0.25rem 0.65rem;
    }
}

.message-timestamp {
    font-size: 0.7rem;
    opacity: 0.8;
}

.message-actions {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

/* Better spacing for message actions on mobile */
@media (max-width: 768px) {
    .message-actions {
        gap: 0.5rem; /* Increased gap for better touch targets */
        padding: 0.25rem 0;
    }
    
    /* Better spacing between message action buttons */
    .message-action-btn {
        margin: 0 0.125rem;
    }
}

.message-action-btn {
    width: 24px;
    height: 24px;
    border-radius: 999px;
    border: 1px solid transparent;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    transition: all 0.2s ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.message-action-btn:hover {
    background: var(--bg-tertiary);
    border-color: var(--border-color);
    color: var(--text-primary);
}

.message-action-btn svg {
    width: 14px;
    height: 14px;
}

.reaction-btn.like {
    color: #15803d;
    border-color: rgba(34, 197, 94, 0.4);
}

.reaction-btn.dislike {
    color: #b91c1c;
    border-color: rgba(248, 113, 113, 0.4);
}

.reaction-btn.like.active {
    background: rgba(34, 197, 94, 0.12);
    border-color: rgba(34, 197, 94, 0.65);
    color: #15803d;
}

.reaction-btn.dislike.active {
    background: rgba(248, 113, 113, 0.12);
    border-color: rgba(248, 113, 113, 0.7);
    color: #b91c1c;
}

[data-theme="dark"] .reaction-btn.like {
    color: #86efac;
    border-color: rgba(74, 222, 128, 0.45);
}

[data-theme="dark"] .reaction-btn.dislike {
    color: #fecaca;
    border-color: rgba(248, 113, 113, 0.45);
}

[data-theme="dark"] .reaction-btn.like.active {
    background: rgba(22, 163, 74, 0.35);
    border-color: rgba(34, 197, 94, 0.9);
    color: #bbf7d0;
}

[data-theme="dark"] .reaction-btn.dislike.active {
    background: rgba(127, 29, 29, 0.55);
    border-color: rgba(248, 113, 113, 0.95);
    color: #fecaca;
}

.message-search-match {
    box-shadow: 0 0 0 1px rgba(129, 140, 248, 0.7);
    background-image: linear-gradient(90deg, rgba(129, 140, 248, 0.08), transparent);
}

[data-theme="dark"] .message-search-match {
    box-shadow: 0 0 0 1px rgba(129, 140, 248, 0.9);
    background-image: linear-gradient(90deg, rgba(30, 64, 175, 0.45), transparent);
}

.typing-placeholder .typing-dots {
    display: inline-flex;
    gap: 0.3rem;
    margin-top: 0.65rem;
}

.typing-dots span {
    width: 7px;
    height: 7px;
    border-radius: 999px;
    background: var(--text-secondary);
    animation: typingDot 1.2s ease-in-out infinite;
    opacity: 0.7;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingDot {
    0%, 100% { transform: translateY(0); opacity: 0.4; }
    50% { transform: translateY(-4px); opacity: 1; }
}

[data-theme="dark"] .message-search-match {
    box-shadow: 0 0 0 1px rgba(129, 140, 248, 0.9);
    background-image: linear-gradient(90deg, rgba(30, 64, 175, 0.45), transparent);
}

.message-content p {
    margin: 0 0 1.25rem 0;
    line-height: 1.8;
    color: var(--text-primary);
    font-size: 0.9375rem;
    word-wrap: break-word;
    transition: color 0.3s ease;
}

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

/* Markdown Headings */
.message-content h1 {
    font-size: 1.75rem;
    font-weight: 700;
    margin: 1.5rem 0 1rem 0;
    color: var(--text-primary);
    line-height: 1.4;
}

.message-content h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 1.5rem 0 0.875rem 0;
    color: var(--text-primary);
    line-height: 1.4;
}

.message-content h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 1.25rem 0 0.75rem 0;
    color: var(--text-primary);
    line-height: 1.5;
}

.message-content h1:first-child,
.message-content h2:first-child,
.message-content h3:first-child {
    margin-top: 0;
}

/* Markdown Bold and Italic */
.message-content strong {
    font-weight: 600;
    color: var(--text-primary);
}

.message-content em {
    font-style: italic;
    color: var(--text-primary);
}

/* Markdown Lists */
.message-content ul,
.message-content ol {
    margin: 1rem 0;
    padding-left: 1.5rem;
    color: var(--text-primary);
}

.message-content ul {
    list-style-type: disc;
}

.message-content ol {
    list-style-type: decimal;
}

.message-content li {
    margin: 0.5rem 0;
    line-height: 1.7;
    color: var(--text-primary);
}

.message-content li p {
    margin: 0;
}

.message-content ul ul,
.message-content ol ol,
.message-content ul ol,
.message-content ol ul {
    margin: 0.5rem 0;
}

/* Inline Code */
.message-content .inline-code,
.message-content code.inline-code {
    background: var(--code-bg);
    color: var(--code-text);
    padding: 0.2em 0.4em;
    border-radius: 4px;
    font-size: 0.875em;
    font-family: 'Courier New', Courier, monospace;
    border: 1px solid var(--code-border);
}

/* LaTeX/MathJax styling */
.message-content .MathJax {
    color: var(--text-primary);
}

.message-content .MathJax_SVG,
.message-content .MathJax_SVG_Display {
    color: var(--text-primary) !important;
}

[data-theme="dark"] .message-content .MathJax {
    color: var(--text-primary);
}

/* MathJax inline math */
.message-content mjx-container {
    display: inline-block;
    margin: 0 0.1em;
    vertical-align: baseline;
}

/* MathJax display math (block) */
.message-content mjx-container[display="true"] {
    display: block;
    margin: 1rem 0;
    text-align: center;
    overflow-x: auto;
}

/* ============================================
   USER MESSAGE
   ============================================ */
.user-msg {
    background: var(--user-msg-bg);
    transition: background-color 0.3s ease;
}

.user-msg .message-content p {
    color: var(--text-primary);
}

/* ============================================
   AI MESSAGE
   ============================================ */
.ai-msg {
    background: var(--ai-msg-bg);
    transition: background-color 0.3s ease;
}

.ai-msg .message-content p {
    color: var(--text-primary);
}

/* ============================================
   CODE BLOCKS
   ============================================ */
.code-block {
    position: relative;
    background: var(--code-bg);
    border: 1px solid var(--code-border);
    border-radius: 10px;
    margin: 1.25rem 0;
    overflow: hidden;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.code-block pre {
    margin: 0;
    padding: 1.25rem;
    overflow-x: auto;
    font-size: 0.875rem;
    line-height: 1.7;
}

.code-block code {
    font-family: "JetBrains Mono", "Fira Code", "Consolas", "Monaco", monospace;
    color: var(--text-primary);
    white-space: pre;
    transition: color 0.3s ease;
}

.copy-btn {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    padding: 0.5rem 0.875rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: "Inter", sans-serif;
    opacity: 0;
    transform: translateY(-4px);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.code-block:hover .copy-btn {
    opacity: 1;
    transform: translateY(0);
}

.copy-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--input-focus-border);
}

.copy-btn.copied {
    background: linear-gradient(135deg, var(--send-btn-bg) 0%, #8b5cf6 100%);
    color: white;
    border-color: transparent;
    opacity: 1;
}

/* ============================================
   INPUT CONTAINER
   ============================================ */
.input-container {
    padding: 1.5rem 2.5rem 2rem 2.5rem;
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    transition: background-color 0.3s ease, border-color 0.3s ease;
    position: relative;
    z-index: 10;
    flex-shrink: 0;
    overflow: visible;
}

.slow-response-warning {
    max-width: 768px;
    margin: 0 auto;
    padding: 0.35rem 1.2rem;
    font-size: 0.78rem;
    color: #92400e;
    background: rgba(252, 211, 77, 0.15);
    border: 1px solid rgba(251, 191, 36, 0.6);
    border-radius: 999px;
    text-align: center;
    margin-bottom: 0.5rem;
}

[data-theme="dark"] .slow-response-warning {
    color: #fde68a;
    background: rgba(250, 204, 21, 0.12);
    border-color: rgba(250, 204, 21, 0.45);
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    background: var(--input-bg);
    border: 2px solid var(--input-border);
    border-radius: 20px;
    padding: 0.875rem 1.125rem;
    gap: 0.875rem;
    transition: all 0.3s ease, box-shadow 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-sm);
    -webkit-tap-highlight-color: transparent;
}

.input-wrapper:focus-within {
    border-color: var(--input-focus-border);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1), var(--shadow-md);
    transform: translateY(-1px);
    transition: all 0.3s ease, box-shadow 1.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.input-wrapper:focus-within:not(.typing) {
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1), var(--shadow-md);
}

.input-wrapper.sending {
    animation: inputSlideUp 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.input-wrapper.sending .input-glow {
    opacity: 0 !important;
    transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

.input-wrapper.sending:focus-within {
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.05), var(--shadow-sm) !important;
    transition: box-shadow 0.4s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

@media (max-width: 768px) {
    .input-wrapper.sending {
        animation: none; /* Disable animation on mobile to prevent jump */
    }
}

@keyframes inputSlideUp {
    0% {
        transform: translateY(0) scale(1);
    }
    30% {
        transform: translateY(-15px) scale(0.95);
        opacity: 0.8;
    }
    60% {
        transform: translateY(-5px) scale(1.02);
    }
    100% {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

#user-input {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 16px; /* Minimum 16px to prevent zoom on iOS */
    font-family: inherit;
    resize: none;
    outline: none;
    min-height: 24px;
    max-height: 200px;
    overflow-y: auto;
    line-height: 1.6;
    padding: 0;
    margin: 0;
    transition: color 0.3s ease;
    vertical-align: middle;
    appearance: none;
    -webkit-appearance: none;
    -webkit-tap-highlight-color: transparent;
}

#user-input::placeholder {
    color: var(--text-secondary);
}

#user-input::-webkit-scrollbar {
    width: 6px;
}

#user-input::-webkit-scrollbar-track {
    background: transparent;
}

#user-input::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.send-button {
    position: relative;
    overflow: hidden;
    width: 36px;
    height: 36px;
    border: none;
    background: linear-gradient(135deg, var(--send-btn-bg) 0%, #8b5cf6 100%);
    color: white;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s ease;
    padding: 0;
    box-shadow: var(--shadow-sm);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.send-button:hover:not(:disabled) {
    background: linear-gradient(135deg, var(--send-btn-hover) 0%, #7c3aed 100%);
    transform: scale(1.05);
    box-shadow: var(--shadow-md);
}

[data-theme="dark"] .send-button:hover:not(:disabled) {
    background: linear-gradient(135deg, var(--send-btn-hover) 0%, #a78bfa 100%);
}

.send-button:active:not(:disabled) {
    transform: scale(0.95);
}

.send-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.send-icon {
    display: block;
    width: 18px;
    height: 18px;
}

.loader {
    display: none;
    width: 18px;
    height: 18px;
    color: white;
}

.send-button.loading .send-icon {
    display: none;
}

.send-button.loading .loader {
    display: block;
}

.input-footer {
    margin-top: 1rem;
    text-align: center;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.input-footer p {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin: 0;
    transition: color 0.3s ease;
}

.tos-link {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-decoration: none;
    opacity: 0.7;
    transition: opacity 0.2s ease, color 0.2s ease;
    /* Improved touch target */
    padding: 0.5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    min-width: 44px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

@media (max-width: 768px) {
    .tos-link {
        padding: 0.75rem;
    }
}

.tos-link:hover {
    opacity: 1;
    color: var(--send-btn-bg);
}

/* ============================================
   ANIMATIONS & EFFECTS
   ============================================ */

/* Input Glow Effect */
.input-glow {
    position: absolute;
    inset: -2px;
    border-radius: 20px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6, #ec4899);
    opacity: 0;
    z-index: -1;
    filter: blur(12px);
    transition: opacity 1.5s ease-out;
    pointer-events: none;
}

.input-wrapper.focused .input-glow {
    opacity: 0.2;
    transition: opacity 1.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.input-wrapper.typing {
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1), var(--shadow-md);
    transition: box-shadow 1.5s cubic-bezier(0.4, 0, 0.2, 1);
    animation: typingPulse 1.5s ease-in-out infinite;
    animation-delay: 1.5s;
    animation-fill-mode: both;
}

.input-wrapper:not(.typing) {
    transition: box-shadow 1.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.input-wrapper.typing .input-glow {
    opacity: 0.2;
    transition: opacity 1.5s cubic-bezier(0.4, 0, 0.2, 1);
    animation: typingGlow 1.5s ease-in-out infinite;
    animation-delay: 1.5s;
    animation-fill-mode: both;
}

/* Ensure glow fades down slowly when typing stops (but stays at typing start level if focused) */
.input-wrapper:not(.typing):not(:focus-within) .input-glow {
    opacity: 0;
    transition: opacity 2.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.input-wrapper:not(.typing):focus-within .input-glow {
    opacity: 0.2;
    transition: opacity 1.5s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes typingPulse {
    0% {
        box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1), var(--shadow-md);
    }
    50% {
        box-shadow: 0 0 0 6px rgba(99, 102, 241, 0.15), var(--shadow-md);
    }
    100% {
        box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1), var(--shadow-md);
    }
}

@keyframes typingGlow {
    0% {
        opacity: 0.2;
        transform: scale(1);
    }
    50% {
        opacity: 0.35;
        transform: scale(1.02);
    }
    100% {
        opacity: 0.2;
        transform: scale(1);
    }
}

@keyframes glowPulse {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.5; }
}

/* Send Button Glow */
.send-button-glow {
    position: absolute;
    inset: -4px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    opacity: 0;
    filter: blur(8px);
    transition: opacity 0.3s ease;
    z-index: -1;
    pointer-events: none;
}

.send-button:hover:not(:disabled) .send-button-glow {
    opacity: 0.6;
    animation: buttonGlow 1.5s ease-in-out infinite;
}

.send-button.send-animate {
    animation: sendPulse 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes buttonGlow {
    0%, 100% { opacity: 0.6; transform: scale(1); }
    50% { opacity: 0.8; transform: scale(1.1); }
}

@keyframes sendPulse {
    0% { transform: scale(1); }
    50% { transform: scale(0.9); }
    100% { transform: scale(1); }
}

/* Ripple Effect */
.ripple {
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.6);
    transform: scale(0);
    animation: rippleAnimation 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
}

@keyframes rippleAnimation {
    to {
        transform: scale(4);
        opacity: 0;
    }
}

/* Message Enter Animations */
.message-enter {
    opacity: 0;
    transform: translateY(60px) scale(0.9);
    animation: messageSlideUp 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.user-msg.message-enter {
    transform: translateY(80px) scale(0.85) translateX(-20px);
    animation: userMessageSlideUp 0.7s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes messageSlideUp {
    0% {
        opacity: 0;
        transform: translateY(60px) scale(0.9);
        filter: blur(10px);
    }
    50% {
        opacity: 0.7;
        transform: translateY(-5px) scale(1.02);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
        filter: blur(0);
    }
}

@keyframes userMessageSlideUp {
    0% {
        opacity: 0;
        transform: translateY(80px) scale(0.85) translateX(-20px);
        filter: blur(10px);
    }
    40% {
        opacity: 0.6;
        transform: translateY(-10px) scale(1.05) translateX(5px);
    }
    70% {
        transform: translateY(3px) scale(0.98) translateX(-2px);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1) translateX(0);
        filter: blur(0);
    }
}

.message-complete {
    animation: messageComplete 0.3s ease-out;
}

@keyframes messageComplete {
    0% { transform: scale(1); }
    50% { transform: scale(1.02); }
    100% { transform: scale(1); }
}

/* Message Shimmer Effect */
.message {
    position: relative;
    overflow: hidden;
}

.message-shimmer {
    position: absolute;
    inset: 0;
    width: 50%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(99, 102, 241, 0.15),
        rgba(139, 92, 246, 0.15),
        rgba(99, 102, 241, 0.15),
        transparent
    );
    animation: shimmer 1.5s ease-out forwards;
    pointer-events: none;
    z-index: 1;
    border-radius: 12px;
}

@keyframes shimmer {
    0% { 
        transform: translateX(-100%);
        opacity: 0;
    }
    10% {
        opacity: 1;
    }
    90% {
        opacity: 1;
    }
    100% { 
        transform: translateX(calc(100% + 200%));
        opacity: 0;
    }
}

/* Avatar Animations */
.avatar-pulse {
    animation: avatarPulse 1.5s ease-in-out infinite;
}

.avatar-bounce {
    animation: avatarBounce 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes avatarPulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.7);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 0 0 8px rgba(99, 102, 241, 0);
    }
}

@keyframes avatarBounce {
    0% {
        transform: scale(0) rotate(-180deg);
        opacity: 0;
    }
    50% {
        transform: scale(1.2) rotate(10deg);
    }
    100% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
}

/* Code Block Animations */
.code-block-enter {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
    animation: codeBlockSlide 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes codeBlockSlide {
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.code-block:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Welcome Screen Animation */
.welcome-screen {
    animation: welcomeFadeIn 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.welcome-content h1 {
    animation: welcomeTitle 1s cubic-bezier(0.16, 1, 0.3, 1) 0.2s both;
}

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

.welcome-content p {
    animation: welcomeSubtitle 1s cubic-bezier(0.16, 1, 0.3, 1) 0.4s both;
}

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

/* Theme Toggle Animation */
.theme-toggle {
    transition: background-color 0.2s ease, border-color 0.2s ease;
}


.theme-toggle:active {
    opacity: 0.8;
}

.theme-toggle svg {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.theme-toggle:hover .sun-icon,
.theme-toggle:hover .moon-icon {
    transform: rotate(180deg);
}

/* Copy Button Enhanced */
.copy-btn {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.copy-btn:hover {
    transform: translateY(-2px);
}

.copy-btn:active {
    transform: translateY(0);
}

/* Error Message */
.error-msg {
    border-left: 4px solid #ef4444;
    animation: errorShake 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes errorShake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

/* Smooth Scroll */
#chat-container {
    scroll-behavior: smooth;
}

/* Enhanced Focus States */
.input-wrapper:focus-within {
    animation: inputFocus 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes inputFocus {
    0% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-2px) scale(1.01); }
    100% { transform: translateY(-1px) scale(1); }
}

/* Logo Animation */
.logo {
    background-size: 200% 200%;
    animation: gradientShift 3s ease infinite;
}

@keyframes gradientShift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

/* Message Hover Effects */
.message:hover {
    background: var(--bg-tertiary);
    transition: background-color 0.2s ease;
}

.user-msg:hover {
    background: var(--user-msg-bg);
}

/* Loading State Enhancements */
.send-button.loading {
    animation: loadingPulse 1.5s ease-in-out infinite;
}

@keyframes loadingPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* Scrollbar Enhancements */
#chat-container::-webkit-scrollbar-thumb {
    transition: background-color 0.3s ease;
}

#chat-container::-webkit-scrollbar-thumb:hover {
    background: var(--input-focus-border);
}

/* Input Placeholder Animation */
#user-input::placeholder {
    transition: opacity 0.3s ease;
}

#user-input:focus::placeholder {
    opacity: 0.5;
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */
@media (max-width: 768px) {
    html, body {
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        /* Enable smooth swipe gestures */
        overscroll-behavior-x: none;
    }
    
    .app-container {
        overflow-x: hidden;
        /* Prevent horizontal scroll during swipe */
        overscroll-behavior-x: none;
    }
    
    .sidebar {
        width: 85%;
        max-width: 320px;
        box-shadow: 4px 0 30px rgba(0, 0, 0, 0.3);
        /* Smooth swipe animation */
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        will-change: transform;
    }
    
    /* Swipe indicator on edge */
    .main::before {
        content: '';
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 2px;
        background: linear-gradient(to bottom, 
            transparent,
            rgba(99, 102, 241, 0.3),
            transparent
        );
        opacity: 0;
        transition: opacity 0.3s ease;
        pointer-events: none;
        z-index: 150;
    }
    
    .main.swipe-active::before {
        opacity: 1;
    }
    
    .sidebar-toggle {
        left: 0.75rem;
        top: 0.5rem;
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
        will-change: left;
        transform: none !important;
        touch-action: manipulation;
    }
    
    .main {
        max-width: 100%;
        padding: 0;
        overflow-x: hidden;
    }

    .header-content {
        padding: 0.75rem 1rem;
        min-height: 60px;
    }
    
    .header-content .sidebar-toggle {
        position: fixed;
        left: 0.75rem;
        top: 0.25rem;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 150;
    }
    
    .header-actions {
        position: fixed;
        right: 1rem;
        top: 0.25rem;
        z-index: 150;
    }
    
    .theme-toggle {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
        touch-action: manipulation;
    }
    
    .app-header {
        padding: 0;
        position: relative;
        z-index: 100;
    }

    .message {
        padding: 1rem 0.75rem;
        gap: 0.75rem;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    
    .message-content {
        word-wrap: break-word;
        overflow-wrap: break-word;
        max-width: 100%;
    }
    
    .message-avatar {
        width: 32px;
        height: 32px;
        min-width: 32px;
        min-height: 32px;
        font-size: 0.75rem;
        flex-shrink: 0;
    }

    .input-container {
        padding: 0.75rem;
        padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
        position: sticky;
        bottom: 0;
        z-index: 10;
    }
    
    .input-wrapper {
        padding: 0.75rem 1rem;
        border-radius: 16px;
        min-height: 48px;
    }
    
    #user-input {
        font-size: 16px; /* Keep 16px on mobile to prevent zoom */
        min-height: 24px;
        line-height: 1.5;
    }
    
    .send-button {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
        touch-action: manipulation;
    }

    .welcome-screen {
        padding: 1.5rem;
    }
    
    .welcome-content {
        max-width: 100%;
    }

    .welcome-content h1 {
        font-size: 2rem;
        line-height: 1.2;
    }

    .welcome-content p {
        font-size: 1rem;
        line-height: 1.5;
    }
    
    .sidebar-header {
        padding: 0.75rem;
    }
    
    .current-user {
        padding: 0.625rem;
        min-height: 44px;
    }
    
    .user-avatar {
        width: 36px;
        height: 36px;
        min-width: 36px;
        min-height: 36px;
        font-size: 0.875rem;
    }
    
    .new-chat-btn {
        padding: 0.75rem 1rem;
        font-size: 0.875rem;
        min-height: 44px;
        touch-action: manipulation;
    }
    
    .chat-item {
        padding: 0.875rem;
        min-height: 56px;
        touch-action: manipulation;
        /* Increased spacing between items */
        margin-bottom: 0.25rem;
    }
    
    /* Better spacing for touch targets */
    .chat-item-content {
        padding-right: 0.5rem;
    }
    
    .chat-item-btn {
        touch-action: manipulation;
    }
    
    .delete-all-btn {
        min-height: 44px;
        touch-action: manipulation;
    }
    
    .logo {
        font-size: 1.125rem;
    }
    
    #chat-container {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }
    
    .code-block {
        font-size: 0.8125rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .message-content h1,
    .message-content h2,
    .message-content h3 {
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    
    /* Status tooltip responsive */
    .status-message-tooltip {
        min-width: 240px;
        max-width: 320px;
        left: 50%;
        right: auto;
    }
    
    .status-message-content {
        font-size: 0.75rem;
        padding: 0.75rem 0.875rem;
    }
}

@media (max-width: 480px) {
    .sidebar {
        width: 90%;
        max-width: 100%;
    }
    
    .message {
        padding: 0.875rem 0.625rem;
        gap: 0.625rem;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    .message-avatar {
        width: 28px;
        height: 28px;
        min-width: 28px;
        min-height: 28px;
        font-size: 0.6875rem;
        flex-shrink: 0;
    }

    .message-content {
        font-size: 0.875rem;
        line-height: 1.7;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    
    .message-content p {
        font-size: 0.875rem;
        line-height: 1.7;
    }

    .logo {
        font-size: 1rem;
    }
    
    .header-content {
        padding: 0.625rem 0.75rem;
        min-height: 56px;
    }
    
    .header-content .sidebar-toggle {
        position: fixed;
        left: 0.5rem;
        top: 0.25rem;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        width: 40px;
        height: 40px;
        min-width: 40px;
        min-height: 40px;
    }
    
    .header-actions {
        position: fixed;
        right: 0.75rem;
        top: 0.25rem;
    }
    
    .theme-toggle {
        width: 40px;
        height: 40px;
        min-width: 40px;
        min-height: 40px;
    }
    
    .input-container {
        padding: 0.625rem;
        padding-bottom: max(0.625rem, env(safe-area-inset-bottom));
        position: sticky;
        bottom: 0;
    }
    
    .input-wrapper {
        padding: 0.625rem 0.875rem;
        min-height: 44px;
    }
    
    .send-button {
        width: 40px;
        height: 40px;
        min-width: 40px;
        min-height: 40px;
    }
    
    .welcome-screen {
        padding: 1rem;
    }
    
    .welcome-content {
        padding: 1rem;
        max-width: 100%;
    }
    
    .welcome-content h1 {
        font-size: 1.75rem;
        line-height: 1.2;
    }
    
    .welcome-content p {
        font-size: 0.9375rem;
    }
    
    .sidebar-header {
        padding: 0.625rem;
    }
    
    .current-user {
        padding: 0.5rem;
        gap: 0.625rem;
        min-height: 44px;
    }
    
    .user-avatar {
        width: 32px;
        height: 32px;
        min-width: 32px;
        min-height: 32px;
    }
    
    .new-chat-btn {
        padding: 0.625rem 0.875rem;
        font-size: 0.8125rem;
        min-height: 44px;
    }
    
    .chat-item {
        padding: 0.625rem;
        min-height: 44px;
    }
    
    .code-block {
        font-size: 0.75rem;
    }
    
    .user-name {
        font-size: 0.8125rem;
    }
    
    .user-id {
        font-size: 0.6875rem;
    }
}

/* ============================================
   INVITE CODE MODAL - UNDERWATER AESTHETIC
   ============================================ */
.invite-code-modal {
    position: fixed;
    inset: 0;
    z-index: 3000;
    display: none; /* Hidden by default */
    align-items: center;
    justify-content: center;
    overflow: hidden;
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
    backdrop-filter: blur(0px);
}

/* Prevent app interaction when invite code not completed */
.app-container.blocked {
    pointer-events: none;
    opacity: 0.3;
    filter: blur(2px);
}

.invite-background {
    position: absolute;
    inset: 0;
    background: #000000;
    overflow: hidden;
    z-index: 1;
    background: radial-gradient(ellipse at center, #0a0a0f 0%, #000000 100%);
}

/* Animated gradient layers */
.water-layer {
    position: absolute;
    width: 200%;
    height: 200%;
    opacity: 0.9;
    animation: gradientFlow 20s ease-in-out infinite;
    filter: blur(100px);
    will-change: transform;
}

.water-layer-1 {
    background: radial-gradient(ellipse at center, 
        rgba(59, 130, 246, 0.8) 0%,
        rgba(96, 165, 250, 0.6) 25%,
        rgba(147, 197, 253, 0.4) 50%,
        rgba(59, 130, 246, 0.2) 75%,
        transparent 100%
    );
    top: -50%;
    left: -50%;
    animation-duration: 15s;
    animation-delay: 0s;
    filter: blur(120px);
}

.water-layer-2 {
    background: radial-gradient(ellipse at center, 
        rgba(96, 165, 250, 0.7) 0%,
        rgba(59, 130, 246, 0.6) 30%,
        rgba(147, 197, 253, 0.4) 60%,
        rgba(96, 165, 250, 0.2) 85%,
        transparent 100%
    );
    top: -30%;
    right: -50%;
    animation-duration: 18s;
    animation-delay: 2s;
    animation-direction: reverse;
    filter: blur(110px);
}

.water-layer-3 {
    background: radial-gradient(ellipse at center, 
        rgba(147, 197, 253, 0.75) 0%,
        rgba(59, 130, 246, 0.6) 35%,
        rgba(96, 165, 250, 0.4) 65%,
        rgba(147, 197, 253, 0.2) 90%,
        transparent 100%
    );
    bottom: -40%;
    left: -30%;
    animation-duration: 22s;
    animation-delay: 4s;
    filter: blur(130px);
}

@keyframes gradientFlow {
    0%, 100% {
        transform: translate(0, 0) rotate(0deg) scale(1);
        opacity: 0.9;
    }
    25% {
        transform: translate(20%, -20%) rotate(15deg) scale(1.3);
        opacity: 1;
    }
    50% {
        transform: translate(-15%, 15%) rotate(-12deg) scale(0.85);
        opacity: 0.8;
    }
    75% {
        transform: translate(15%, 20%) rotate(8deg) scale(1.15);
        opacity: 0.95;
    }
}

/* Floating gradient orbs */
.bubbles {
    position: absolute;
    inset: 0;
    overflow: hidden;
}

.bubble {
    position: absolute;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, 
        rgba(59, 130, 246, 0.7),
        rgba(96, 165, 250, 0.5),
        rgba(147, 197, 253, 0.3),
        rgba(59, 130, 246, 0.1),
        transparent
    );
    filter: blur(50px);
    animation: orbFloat 20s infinite ease-in-out;
    opacity: 0.7;
    box-shadow: 
        0 0 100px rgba(59, 130, 246, 0.4),
        0 0 200px rgba(96, 165, 250, 0.2),
        inset 0 0 50px rgba(147, 197, 253, 0.1);
}

.bubble-1 {
    width: 300px;
    height: 300px;
    left: 10%;
    bottom: 20%;
    animation-duration: 15s;
    animation-delay: 0s;
}

.bubble-2 {
    width: 400px;
    height: 400px;
    left: 20%;
    bottom: 60%;
    animation-duration: 18s;
    animation-delay: 1s;
}

.bubble-3 {
    width: 250px;
    height: 250px;
    left: 35%;
    bottom: 10%;
    animation-duration: 12s;
    animation-delay: 2s;
}

.bubble-4 {
    width: 350px;
    height: 350px;
    left: 50%;
    bottom: 40%;
    animation-duration: 16s;
    animation-delay: 0.5s;
}

.bubble-5 {
    width: 280px;
    height: 280px;
    left: 65%;
    bottom: 70%;
    animation-duration: 14s;
    animation-delay: 1.5s;
}

.bubble-6 {
    width: 320px;
    height: 320px;
    left: 80%;
    bottom: 30%;
    animation-duration: 19s;
    animation-delay: 2.5s;
}

.bubble-7 {
    width: 200px;
    height: 200px;
    left: 15%;
    bottom: 50%;
    animation-duration: 13s;
    animation-delay: 3s;
}

.bubble-8 {
    width: 380px;
    height: 380px;
    left: 70%;
    bottom: 15%;
    animation-duration: 17s;
    animation-delay: 1s;
}

.bubble-9 {
    width: 290px;
    height: 290px;
    left: 40%;
    bottom: 80%;
    animation-duration: 15s;
    animation-delay: 2s;
}

.bubble-10 {
    width: 260px;
    height: 260px;
    left: 90%;
    bottom: 55%;
    animation-duration: 14s;
    animation-delay: 0.8s;
}

@keyframes orbFloat {
    0% {
        transform: translate(0, 0) scale(0.9) rotate(0deg);
        opacity: 0.7;
        filter: blur(50px);
    }
    25% {
        opacity: 0.9;
        transform: translate(60px, -30px) scale(1.2) rotate(90deg);
        filter: blur(45px);
    }
    50% {
        opacity: 0.8;
        transform: translate(-40px, -50px) scale(0.85) rotate(180deg);
        filter: blur(55px);
    }
    75% {
        opacity: 0.85;
        transform: translate(50px, -40px) scale(1.1) rotate(270deg);
        filter: blur(48px);
    }
    100% {
        transform: translate(-30px, -70px) scale(0.9) rotate(360deg);
        opacity: 0.6;
        filter: blur(52px);
    }
}

/* Invite content */
.invite-content {
    position: relative;
    z-index: 10;
    text-align: center;
    padding: 4rem 3rem;
    max-width: 600px;
    width: 90%;
    animation: inviteFadeIn 1s cubic-bezier(0.4, 0, 0.2, 1);
    background: transparent;
}

.invite-content::before {
    content: '';
    position: absolute;
    inset: -2px;
    background: linear-gradient(135deg, 
        rgba(59, 130, 246, 0.1) 0%,
        rgba(96, 165, 250, 0.05) 50%,
        rgba(147, 197, 253, 0.1) 100%
    );
    border-radius: 24px;
    z-index: -1;
    opacity: 0.6;
    filter: blur(40px);
    animation: contentGlow 4s ease-in-out infinite;
}

@keyframes contentGlow {
    0%, 100% {
        opacity: 0.4;
        transform: scale(1);
    }
    50% {
        opacity: 0.7;
        transform: scale(1.05);
    }
}

@keyframes inviteFadeIn {
    from {
        opacity: 0;
        transform: translateY(40px) scale(0.95);
        filter: blur(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
        filter: blur(0);
    }
}

.invite-header {
    margin-bottom: 3.5rem;
    position: relative;
}

.invite-header::after {
    display: none;
}

.invite-title {
    font-size: 3.5rem;
    font-weight: 800;
    background: linear-gradient(135deg, 
        rgba(255, 255, 255, 1) 0%,
        rgba(230, 240, 255, 1) 30%,
        rgba(200, 230, 255, 1) 60%,
        rgba(173, 216, 255, 1) 100%
    );
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 1rem;
    background-size: 200% 200%;
    animation: titleGradient 6s ease infinite;
    letter-spacing: -0.02em;
    line-height: 1.1;
    position: relative;
}

@keyframes titleGradient {
    0% {
        background-position: 0% 50%;
    }
    25% {
        background-position: 50% 0%;
    }
    50% {
        background-position: 100% 50%;
    }
    75% {
        background-position: 50% 100%;
    }
    100% {
        background-position: 0% 50%;
    }
}

.invite-subtitle {
    font-size: 1.25rem;
    color: rgba(200, 230, 255, 1);
    font-weight: 400;
    letter-spacing: 1px;
}

/* Code input container */
.code-input-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
    position: relative;
    padding: 2rem 0;
}

.code-input-container::before {
    display: none;
}

.code-inputs {
    display: flex;
    gap: 1.25rem;
    justify-content: center;
    align-items: center;
    position: relative;
    padding: 1rem;
    margin-top: -3rem;
}

.code-digit {
    width: 70px;
    height: 85px;
    text-align: center;
    font-size: 2.5rem;
    font-weight: 700;
    background: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(30px);
    border: 2px solid rgba(255, 255, 255, 0.6);
    border-radius: 16px;
    color: rgba(255, 255, 255, 1);
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    outline: none;
    caret-color: rgba(255, 255, 255, 1);
    box-shadow: 
        0 8px 32px rgba(0, 0, 0, 0.5),
        0 0 0 0 rgba(255, 255, 255, 0),
        0 0 30px rgba(255, 255, 255, 0.3),
        inset 0 2px 8px rgba(255, 255, 255, 0.1),
        inset 0 -2px 8px rgba(0, 0, 0, 0.2);
    position: relative;
}

.code-digit::before {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: 16px;
    background: linear-gradient(135deg, 
        rgba(59, 130, 246, 0.3),
        rgba(96, 165, 250, 0.2),
        rgba(147, 197, 253, 0.3)
    );
    opacity: 0;
    transition: opacity 0.4s ease;
    z-index: -1;
    filter: blur(10px);
}

.code-digit:hover::before {
    opacity: 0.6;
}

.code-digit:disabled {
    cursor: not-allowed;
    opacity: 0.7;
    background: rgba(255, 255, 255, 0.03);
    border-color: rgba(255, 255, 255, 0.3);
    box-shadow: 
        0 4px 20px rgba(0, 0, 0, 0.3),
        0 0 10px rgba(255, 255, 255, 0.1),
        inset 0 2px 5px rgba(255, 255, 255, 0.03);
}

.code-digit::selection {
    background: rgba(59, 130, 246, 0.3);
}

.code-digit:focus {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 1);
    box-shadow: 
        0 0 0 6px rgba(255, 255, 255, 0.4),
        0 0 0 12px rgba(59, 130, 246, 0.2),
        0 10px 40px rgba(255, 255, 255, 0.6),
        0 0 60px rgba(255, 255, 255, 0.7),
        0 0 100px rgba(59, 130, 246, 0.4),
        inset 0 2px 8px rgba(255, 255, 255, 0.2),
        inset 0 -2px 8px rgba(0, 0, 0, 0.1);
    transform: translateY(-4px) scale(1.08);
    animation: digitPulse 2s ease-in-out infinite;
}

.code-digit:focus::before {
    opacity: 1;
}

@keyframes digitPulse {
    0%, 100% {
        box-shadow: 
            0 0 0 6px rgba(255, 255, 255, 0.4),
            0 0 0 12px rgba(59, 130, 246, 0.2),
            0 10px 40px rgba(255, 255, 255, 0.6),
            0 0 60px rgba(255, 255, 255, 0.7),
            0 0 100px rgba(59, 130, 246, 0.4);
    }
    50% {
        box-shadow: 
            0 0 0 8px rgba(255, 255, 255, 0.5),
            0 0 0 16px rgba(59, 130, 246, 0.3),
            0 10px 40px rgba(255, 255, 255, 0.7),
            0 0 80px rgba(255, 255, 255, 0.8),
            0 0 120px rgba(59, 130, 246, 0.5);
    }
}

.code-digit.filled {
    background: rgba(59, 130, 246, 0.2);
    border-color: rgba(255, 255, 255, 0.9);
    box-shadow: 
        0 8px 32px rgba(59, 130, 246, 0.5),
        0 0 30px rgba(255, 255, 255, 0.4),
        0 0 50px rgba(59, 130, 246, 0.3),
        0 0 70px rgba(96, 165, 250, 0.2),
        inset 0 2px 8px rgba(255, 255, 255, 0.15),
        inset 0 -2px 8px rgba(59, 130, 246, 0.1);
    transform: scale(1.02);
    animation: filledGlow 2.5s ease-in-out infinite;
}

@keyframes filledGlow {
    0%, 100% {
        box-shadow: 
            0 8px 32px rgba(59, 130, 246, 0.5),
            0 0 30px rgba(255, 255, 255, 0.4),
            0 0 50px rgba(59, 130, 246, 0.3);
    }
    50% {
        box-shadow: 
            0 8px 32px rgba(59, 130, 246, 0.7),
            0 0 40px rgba(255, 255, 255, 0.5),
            0 0 70px rgba(59, 130, 246, 0.4);
    }
}

.code-digit.error {
    border-color: rgba(255, 100, 100, 0.8);
    background: rgba(255, 100, 100, 0.15);
    animation: shakeError 0.5s ease;
}

@keyframes shakeError {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-8px); }
    20%, 40%, 60%, 80% { transform: translateX(8px); }
}

.code-error {
    color: rgba(255, 150, 150, 0.95);
    font-size: 0.875rem;
    min-height: 1.5rem;
    opacity: 0;
    transition: opacity 0.3s ease;
    text-shadow: 0 2px 15px rgba(255, 100, 100, 0.6), 0 0 20px rgba(255, 0, 0, 0.4);
}

.code-error.show {
    opacity: 1;
}

/* Username section in invite modal */
.username-section {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: none;
    opacity: 0;
    transform: translateY(-20px);
}

.username-prompt {
    font-size: 1rem;
    color: rgba(200, 230, 255, 0.9);
    font-weight: 400;
    margin-bottom: 1rem;
    text-align: center;
    text-shadow: 0 2px 10px rgba(59, 130, 246, 0.4);
}

#username-input-invite {
    width: 100%;
    max-width: 300px;
    padding: 1rem 1.25rem;
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(20px);
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 12px;
    color: rgba(255, 255, 255, 0.95);
    font-size: 1.125rem;
    font-family: inherit;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-sizing: border-box;
    text-align: center;
    outline: none;
    caret-color: rgba(255, 255, 255, 1);
    box-shadow: 
        0 4px 20px rgba(0, 0, 0, 0.4),
        0 0 20px rgba(255, 255, 255, 0.2),
        inset 0 2px 5px rgba(255, 255, 255, 0.05);
}

#username-input-invite:focus {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 1);
    box-shadow: 
        0 0 0 4px rgba(255, 255, 255, 0.3),
        0 6px 30px rgba(255, 255, 255, 0.5),
        0 0 40px rgba(255, 255, 255, 0.6),
        0 0 60px rgba(255, 255, 255, 0.4),
        inset 0 2px 5px rgba(255, 255, 255, 0.1);
    transform: translateY(-2px) scale(1.02);
}

#username-input-invite::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

/* Responsive design for invite modal */
@media (max-width: 768px) {
    .invite-title {
        font-size: 2rem;
    }
    
    .invite-subtitle {
        font-size: 1rem;
    }
    
    .code-inputs {
        gap: 0.75rem;
    }
    
    .code-digit {
        width: 50px;
        height: 60px;
        font-size: 1.75rem;
    }
}

@media (max-width: 480px) {
    .invite-content {
        padding: 2rem 1.5rem;
    }
    
    .invite-title {
        font-size: 1.75rem;
    }
    
    .code-inputs {
        gap: 0.5rem;
    }
    
    .code-digit {
        width: 45px;
        height: 55px;
        font-size: 1.5rem;
    }
}
