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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    color: #333;
}

.container {
    width: 100%;
    max-width: 900px;
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    position: relative;
}

header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    text-align: center;
}

header h1 {
    font-size: 2em;
    margin-bottom: 10px;
}

.subtitle {
    opacity: 0.9;
    font-size: 0.9em;
}

.screen {
    display: none;
    height: calc(100vh - 200px);
    min-height: 500px;
    flex-direction: column;
}

.screen.active {
    display: flex;
}

.card {
    padding: 40px;
    max-width: 500px;
    margin: 0 auto;
    width: 100%;
}

.card h2 {
    margin-bottom: 30px;
    text-align: center;
    color: #333;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: #555;
}

.form-group input {
    width: 100%;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 16px;
    transition: border-color 0.3s;
}

.form-group input:focus {
    outline: none;
    border-color: #667eea;
}

.btn-primary, .btn-secondary {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    width: 100%;
    margin-top: 10px;
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-secondary {
    background: #f5f5f5;
    color: #333;
    margin-top: 10px;
}

.btn-secondary:hover {
    background: #e0e0e0;
}

#generate-room {
    width: 100%;
    margin-top: 10px;
}

.chat-header {
    background: #f8f9fa;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #e0e0e0;
}

.header-actions {
    display: flex;
    gap: 10px;
}

.room-info {
    display: flex;
    gap: 20px;
    font-size: 0.9em;
}

.room-info strong {
    color: #667eea;
}

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #fafafa;
}

.message {
    margin-bottom: 15px;
    animation: fadeIn 0.3s;
}

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

.message-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 5px;
}

.message-username {
    font-weight: 600;
    color: #667eea;
}

.message-time {
    font-size: 0.8em;
    color: #999;
}

.message-content {
    background: white;
    padding: 12px 15px;
    border-radius: 12px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    word-wrap: break-word;
    line-height: 1.5;
}

.message.own .message-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    margin-left: auto;
    max-width: 70%;
}

.message.system {
    text-align: center;
    color: #999;
    font-size: 0.9em;
    font-style: italic;
}

.status-bar {
    background: #f8f9fa;
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    font-size: 0.85em;
    color: #666;
    border-top: 1px solid #e0e0e0;
}

.status-bar span {
    display: flex;
    align-items: center;
    gap: 5px;
}

.status-bar span::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #999;
}

.status-bar .connected::before {
    background: #4caf50;
}

.status-bar .connecting::before {
    background: #ff9800;
}

.input-area {
    padding: 15px 20px;
    background: white;
    border-top: 1px solid #e0e0e0;
}

.input-row {
    display: flex;
    gap: 10px;
    align-items: center;
}

#message-input {
    flex: 1;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 16px;
}

#message-input:focus {
    outline: none;
    border-color: #667eea;
}

#message-input:disabled {
    background: #f5f5f5;
    cursor: not-allowed;
}

.btn-file {
    padding: 12px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    font-size: 18px;
    transition: all 0.3s;
    flex-shrink: 0;
}

.btn-file:hover:not(:disabled) {
    background: #f5f5f5;
    border-color: #667eea;
}

.btn-file:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.file-preview {
    margin-top: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.file-preview.hidden {
    display: none;
}

.file-preview-item {
    position: relative;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    overflow: hidden;
    background: #f8f9fa;
}

.file-preview-item img,
.file-preview-item video {
    display: block;
    max-width: 150px;
    max-height: 150px;
    object-fit: cover;
}

.file-preview-item audio {
    width: 200px;
}

.file-preview-item .file-info {
    padding: 5px 10px;
    font-size: 0.8em;
    color: #666;
    background: white;
}

.file-preview-item .file-remove {
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(255, 0, 0, 0.7);
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.file-preview-item .file-remove:hover {
    background: rgba(255, 0, 0, 0.9);
}

.upload-progress {
    margin-top: 10px;
}

.upload-progress.hidden {
    display: none;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #e0e0e0;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 5px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    width: 0%;
    transition: width 0.3s;
}

.progress-text {
    font-size: 0.85em;
    color: #666;
}

/* 多媒体消息样式 */
.message-media {
    margin-top: 5px;
    border-radius: 8px;
    overflow: hidden;
    max-width: 100%;
}

.message-media img {
    max-width: 100%;
    max-height: 400px;
    display: block;
    border-radius: 8px;
}

.message-media video {
    max-width: 100%;
    max-height: 400px;
    display: block;
    border-radius: 8px;
}

.message-media audio {
    width: 100%;
    max-width: 400px;
}

.message-media .media-info {
    padding: 8px;
    background: rgba(0, 0, 0, 0.05);
    font-size: 0.85em;
    color: #666;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
}

.message.own .message-media .media-info {
    color: rgba(255, 255, 255, 0.9);
    background: rgba(255, 255, 255, 0.1);
    border-top-color: rgba(255, 255, 255, 0.2);
}

.loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.loading.hidden {
    display: none;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loading p {
    margin-top: 20px;
    color: #666;
}

/* 滚动条样式 */
.messages::-webkit-scrollbar {
    width: 8px;
}

.messages::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.messages::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.messages::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* 对话框样式 */
.dialog {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.dialog.hidden {
    display: none;
}

.dialog-content {
    background: white;
    padding: 30px;
    border-radius: 12px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.dialog-content h3 {
    margin-bottom: 15px;
    color: #333;
}

.dialog-content p {
    margin-bottom: 20px;
    color: #666;
    font-size: 0.9em;
}

.peer-id-display {
    display: flex;
    gap: 10px;
}

.peer-id-display input {
    flex: 1;
}

.dialog-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .container {
        border-radius: 0;
        height: 100vh;
    }

    .screen {
        height: calc(100vh - 150px);
    }

    .card {
        padding: 20px;
    }

    .room-info {
        flex-direction: column;
        gap: 5px;
    }
}
