* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --primary: #7c3aed;
    --primary-light: #8b5cf6;
    --primary-dark: #6d28d9;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --dark: #1a1a2e;
    --darker: #16213e;
    --light: #2a2a3a;
    --lighter: #3a3a4a;
    --text: #e2e8f0;
    --text-secondary: #94a3b8;
    --border: #334155;
    --message-own: #7c3aed;
    --message-other: #2d3748;
    --shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: var(--dark);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
}

.app {
    height: 100vh;
    position: relative;
}

/* 加入页面 */
.join-page {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--darker) 0%, var(--dark) 100%);
    padding: 20px;
}

.join-container {
    width: 100%;
    max-width: 400px;
    background: var(--light);
    border-radius: 30px;
    padding: 30px 25px;
    box-shadow: var(--shadow);
    animation: slideUp 0.5s ease;
}

.logo {
    text-align: center;
    margin-bottom: 30px;
}

.logo i {
    font-size: 50px;
    color: var(--primary);
    margin-bottom: 15px;
}

.logo h1 {
    font-size: 28px;
    margin-bottom: 5px;
}

.logo p {
    color: var(--text-secondary);
    font-size: 14px;
}

.join-form {
    margin-bottom: 30px;
}

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

.input-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    color: var(--text-secondary);
}

.room-input {
    display: flex;
    gap: 10px;
}

.room-input input {
    flex: 1;
    padding: 15px;
    background: var(--darker);
    border: 1px solid var(--border);
    border-radius: 15px;
    color: var(--text);
    font-size: 18px;
    text-align: center;
    letter-spacing: 4px;
}

.room-input input:focus {
    outline: none;
    border-color: var(--primary);
}

.random-room {
    width: 50px;
    background: var(--primary);
    border: none;
    border-radius: 15px;
    color: white;
    font-size: 20px;
    cursor: pointer;
}

#name-input {
    width: 100%;
    padding: 15px;
    background: var(--darker);
    border: 1px solid var(--border);
    border-radius: 15px;
    color: var(--text);
    font-size: 16px;
}

#name-input:focus {
    outline: none;
    border-color: var(--primary);
}

.join-btn {
    width: 100%;
    padding: 16px;
    background: var(--primary);
    border: none;
    border-radius: 15px;
    color: white;
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    cursor: pointer;
    transition: all 0.3s;
}

.join-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
}

.features {
    display: flex;
    justify-content: space-around;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.feature {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    color: var(--text-secondary);
    font-size: 12px;
}

.feature i {
    font-size: 20px;
    color: var(--primary-light);
}

/* 聊天页面 */
.chat-page {
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--dark);
}

.status-bar {
    background: var(--darker);
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    position: relative;
    z-index: 10;
}

.status-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.back-btn {
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 20px;
    padding: 5px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.back-btn:hover {
    background: var(--light);
}

.room-info {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--light);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 14px;
}

.room-info i {
    color: var(--primary-light);
}

.status-right {
    display: flex;
    align-items: center;
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--light);
    border-radius: 20px;
    font-size: 13px;
}

.connection-status .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--warning);
    animation: pulse 1.5s infinite;
}

.connection-status.connected .dot {
    background: var(--success);
    animation: none;
}

/* 主内容区 */
.main-content {
    flex: 1;
    display: flex;
    position: relative;
    overflow: hidden;
}

/* 用户抽屉 */
.users-drawer {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    background: var(--darker);
    z-index: 20;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.3);
}

.users-drawer.active {
    transform: translateX(0);
}

.drawer-header {
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
}

.drawer-header h3 {
    font-size: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.close-drawer {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-drawer:hover {
    background: var(--light);
}

.users-list {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
}

.user-item {
    padding: 12px;
    background: var(--light);
    border-radius: 12px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 18px;
    color: white;
    position: relative;
}

.user-status {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--success);
    border: 2px solid var(--light);
}

.user-status.checking {
    background: var(--warning);
}

.user-status.disconnected {
    background: var(--danger);
}

.user-info {
    flex: 1;
}

.user-name {
    font-weight: 500;
    font-size: 15px;
    display: flex;
    align-items: center;
    gap: 5px;
    margin-bottom: 3px;
}

.user-name i {
    font-size: 12px;
    color: var(--primary);
}

.user-p2p-status {
    font-size: 12px;
    color: var(--text-secondary);
}

.connection-stats {
    padding: 15px;
    background: var(--light);
    border-top: 1px solid var(--border);
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.stat-item i {
    width: 20px;
    color: var(--primary-light);
}

.stat-value {
    color: var(--text);
    margin-left: auto;
}

/* 聊天区域 */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
}

.show-users-btn {
    position: absolute;
    top: 15px;
    left: 15px;
    z-index: 5;
    background: var(--primary);
    border: none;
    color: white;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    cursor: pointer;
    box-shadow: var(--shadow);
}

.online-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--danger);
    color: white;
    font-size: 11px;
    padding: 2px 5px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 70px 15px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.message {
    max-width: 85%;
    animation: fadeIn 0.3s;
}

.message.own {
    align-self: flex-end;
}

.message.other {
    align-self: flex-start;
}

.message.system {
    align-self: center;
    max-width: 90%;
}

.message-content {
    padding: 12px 16px;
    border-radius: 20px;
    word-wrap: break-word;
    font-size: 15px;
    line-height: 1.4;
    position: relative;
}

.message.own .message-content {
    background: var(--message-own);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.other .message-content {
    background: var(--message-other);
    color: var(--text);
    border-bottom-left-radius: 4px;
}

.message.system .message-content {
    background: var(--light);
    color: var(--text-secondary);
    font-size: 13px;
    padding: 8px 16px;
    border-radius: 30px;
}

.message-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 4px;
    padding: 0 5px;
}

.message.own .message-info {
    justify-content: flex-end;
}

.message-sender {
    font-weight: 600;
    color: var(--primary-light);
}

/* 图片消息 */
.image-message {
    max-width: 200px;
    max-height: 200px;
    border-radius: 12px;
    cursor: pointer;
}

/* 语音消息 */
.voice-message {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 180px;
}

.voice-play-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.voice-waveform {
    flex: 1;
    height: 36px;
    background: rgba(255,255,255,0.1);
    border-radius: 18px;
    position: relative;
    overflow: hidden;
}

.voice-progress {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 0%;
    background: var(--primary-light);
    transition: width 0.1s linear;
}

.voice-duration {
    font-size: 12px;
    color: var(--text-secondary);
    min-width: 35px;
}

/* 文件消息 */
.file-message {
    display: flex;
    align-items: center;
    gap: 12px;
}

.file-icon {
    font-size: 28px;
    color: var(--primary-light);
}

.file-info {
    flex: 1;
}

.file-name {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 2px;
}

.file-size {
    font-size: 11px;
    color: var(--text-secondary);
}

.file-download {
    color: var(--primary-light);
    text-decoration: none;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* 正在输入指示器 */
.typing-indicator {
    padding: 10px 20px;
    display: flex;
    gap: 4px;
    justify-content: center;
    align-items: center;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

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

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

/* 底部区域 */
.bottom-area {
    background: var(--darker);
    border-top: 1px solid var(--border);
    padding: 12px 15px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
}

.action-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 10px;
    overflow-x: auto;
    padding-bottom: 5px;
    -webkit-overflow-scrolling: touch;
}

.action-btn {
    background: var(--light);
    border: none;
    color: var(--text);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    cursor: pointer;
    flex-shrink: 0;
}

.action-btn:hover {
    background: var(--lighter);
}

.input-wrapper {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

#message-input {
    flex: 1;
    background: var(--light);
    border: 1px solid var(--border);
    border-radius: 22px;
    padding: 12px 16px;
    color: var(--text);
    font-size: 15px;
    resize: none;
    max-height: 100px;
    outline: none;
}

#message-input:focus {
    border-color: var(--primary);
}

.send-btn {
    background: var(--primary);
    border: none;
    color: white;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

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

/* 录音面板 */
.record-panel {
    background: var(--light);
    border-radius: 30px;
    padding: 15px;
    margin-top: 10px;
    display: flex;
    align-items: center;
    gap: 15px;
    animation: slideUp 0.3s;
}

.record-timer {
    font-size: 20px;
    font-weight: 600;
    color: var(--primary);
    min-width: 60px;
}

.record-wave {
    flex: 1;
    height: 40px;
    background: var(--darker);
    border-radius: 20px;
    position: relative;
    overflow: hidden;
}

.record-wave::after {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 100%;
    background: linear-gradient(90deg, var(--primary) 0%, var(--primary-light) 100%);
    opacity: 0.3;
    animation: wave 1s ease-in-out infinite;
}

.record-actions {
    display: flex;
    gap: 8px;
}

.record-cancel, .record-send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.record-cancel {
    background: var(--danger);
    color: white;
}

.record-send {
    background: var(--success);
    color: white;
}

.record-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* 通话面板 */
.call-panel {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--dark);
    z-index: 30;
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.3s;
}

.call-header {
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--darker);
}

.close-call {
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 20px;
    cursor: pointer;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.video-container {
    flex: 1;
    position: relative;
    background: #000;
}

#remote-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

#local-video {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 120px;
    height: 160px;
    object-fit: cover;
    border-radius: 10px;
    border: 2px solid var(--primary);
}

.call-controls {
    position: absolute;
    bottom: 30px;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    gap: 20px;
    padding: 20px;
}

.call-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    transition: all 0.3s;
}

.call-btn.mute-audio, .call-btn.mute-video {
    background: var(--light);
    color: var(--text);
}

.call-btn.mute-audio.muted, .call-btn.mute-video.muted {
    background: var(--danger);
    color: white;
}

.call-btn.end-call {
    background: var(--danger);
    color: white;
}

/* 表情面板 */
.emoji-panel {
    position: absolute;
    bottom: 100px;
    left: 15px;
    right: 15px;
    background: var(--light);
    border-radius: 20px;
    padding: 15px;
    box-shadow: var(--shadow);
    z-index: 25;
    max-width: 300px;
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 10px;
}

.emoji-item {
    font-size: 28px;
    text-align: center;
    padding: 5px;
    border-radius: 10px;
    cursor: pointer;
}

.emoji-item:hover {
    background: var(--lighter);
}

/* 工具类 */
.hidden {
    display: none !important;
}

/* 动画 */
@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(50px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.3;
    }
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-10px);
    }
}

@keyframes wave {
    0%, 100% {
        transform: scaleX(1);
    }
    50% {
        transform: scaleX(1.2);
    }
}

/* 滚动条美化 */
::-webkit-scrollbar {
    width: 4px;
}

::-webkit-scrollbar-track {
    background: var(--darker);
}

::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 2px;
}