* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

body {
    background: linear-gradient(145deg, #0b1729 0%, #1a2a3f 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 16px;
}

.app {
    width: 100%;
    max-width: 800px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(12px);
    border-radius: 32px;
    box-shadow: 0 30px 60px rgba(0, 10, 30, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.2);
    overflow: hidden;
}

.loading {
    padding: 60px;
    text-align: center;
    color: #a0b8d4;
    font-size: 1.2rem;
}

.chat-container {
    display: flex;
    flex-direction: column;
    height: 650px;
    padding: 24px;
}

/* 头部样式 */
.header {
    margin-bottom: 20px;
}

.room-info {
    width: 100%;
}

.room-info .label {
    font-size: 0.85rem;
    color: #9bb5d9;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
    display: block;
}

.room-id-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #0f1e30;
    padding: 12px 18px;
    border-radius: 60px;
    border: 1px solid #2b415b;
    width: 100%;
}

.room-id {
    font-size: 1rem;
    color: white;
    font-weight: 500;
    word-break: break-all;
    flex: 1;
    font-family: 'Courier New', monospace;
    line-height: 1.5;
    padding: 4px 0;
}

.copy-btn {
    background: #1f324b;
    border: none;
    padding: 8px 20px;
    border-radius: 40px;
    color: white;
    cursor: pointer;
    font-size: 0.9rem;
    border: 1px solid #3d5675;
    white-space: nowrap;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 5px;
}

.copy-btn:hover {
    background: #2a405e;
    transform: scale(1.02);
}

.stats {
    margin-top: 12px;
    text-align: right;
    color: #8affbc;
    font-size: 0.95rem;
    background: #0f1e30;
    padding: 6px 16px;
    border-radius: 30px;
    display: inline-block;
    float: right;
}

.online-count {
    font-weight: 700;
    color: #8affbc;
    font-size: 1.1rem;
}

/* 昵称设置区域 */
.nickname-section {
    background: #112436;
    border-radius: 50px;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    color: #b6cef0;
    border: 1px solid #2d4561;
    clear: both;
}

.nickname-section span {
    font-size: 0.95rem;
    font-weight: 500;
    color: #8aa9d9;
}

.nickname-section input {
    flex: 1;
    background: #1b3049;
    border: none;
    padding: 10px 16px;
    border-radius: 40px;
    color: white;
    border: 1px solid #3b5780;
    outline: none;
    font-size: 0.95rem;
}

.nickname-section input:focus {
    border-color: #5f8fd9;
}

.nickname-section button {
    background: #3f5e86;
    border: none;
    padding: 8px 20px;
    border-radius: 40px;
    color: white;
    cursor: pointer;
    font-size: 0.9rem;
    border: 1px solid #6f8fb7;
    transition: all 0.2s;
}

.nickname-section button:hover {
    background: #4d6e9a;
}

/* 消息列表区域 - 修正版 */
.messages {
    flex: 1;
    background: #0e1b2b;
    border-radius: 24px;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 20px;
    border: 1px solid #2b3f5a;
}

/* 消息行 - 使用flex确保左右分明 */
.message-row {
    display: flex;
    width: 100%;
}

/* 自己发的消息行 - 靠右 */
.message-row.own {
    justify-content: flex-end;
}

/* 别人发的消息行 - 靠左 */
.message-row.other {
    justify-content: flex-start;
}

/* 系统消息行 - 居中 */
.message-row.system {
    justify-content: center;
}

/* 消息气泡容器 */
.message-bubble {
    max-width: 70%;
    display: flex;
    flex-direction: column;
}

/* 消息内容区域 */
.message-content {
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.4;
    word-wrap: break-word;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

/* 自己消息内容 - 蓝色气泡 */
.message-row.own .message-content {
    background: #1f4a9e;
    color: white;
    border-bottom-right-radius: 4px;
}

/* 别人消息内容 - 灰色气泡 */
.message-row.other .message-content {
    background: #233952;
    color: #e1ecff;
    border-bottom-left-radius: 4px;
}

/* 系统消息内容 */
.message-row.system .message-content {
    background: #1b334d;
    color: #b4d0f5;
    font-size: 0.85rem;
    padding: 6px 16px;
    border-radius: 30px;
    border: 1px solid #3a5270;
}

/* 用户名 - 独立行 */
.message-username {
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 4px;
    padding: 0 4px;
}

/* 自己消息的用户名 - 靠右 */
.message-row.own .message-username {
    color: #aad0ff;
    text-align: right;
}

/* 别人消息的用户名 - 靠左 */
.message-row.other .message-username {
    color: #ffd966;
    text-align: left;
}

/* 系统消息不需要用户名 */
.message-row.system .message-username {
    display: none;
}

/* 消息时间 */
.message-time {
    font-size: 0.6rem;
    opacity: 0.6;
    margin-top: 4px;
    padding: 0 4px;
    color: #a0b8d4;
}

/* 自己消息的时间 - 靠右 */
.message-row.own .message-time {
    text-align: right;
}

/* 别人消息的时间 - 靠左 */
.message-row.other .message-time {
    text-align: left;
}

/* 输入区域 */
.input-area {
    display: flex;
    gap: 12px;
    background: #112436;
    border-radius: 60px;
    padding: 6px 6px 6px 20px;
    border: 1px solid #314d70;
}

.input-area input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 14px 5px;
    color: white;
    font-size: 1rem;
    outline: none;
}

.input-area input::placeholder {
    color: #607b9f;
}

.input-area button {
    background: #2e6bcb;
    border: none;
    border-radius: 60px;
    padding: 0 32px;
    color: white;
    font-weight: 600;
    cursor: pointer;
    font-size: 1rem;
    border: 1px solid #6f9bf5;
    transition: all 0.2s;
}

.input-area button:hover {
    background: #1f4a9e;
}

/* 底部提示 */
.footer {
    text-align: center;
    color: #5f7da3;
    font-size: 0.8rem;
    margin-top: 12px;
    padding: 8px;
}

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

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

.messages::-webkit-scrollbar-track {
    background: #1a2a3f;
    border-radius: 10px;
}

.messages::-webkit-scrollbar-thumb {
    background: #3d5675;
    border-radius: 10px;
}

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

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

    .app {
        max-width: 100%;
        border-radius: 0;
        height: 100vh;
    }

    body {
        padding: 0;
    }

    .room-id-wrapper {
        flex-direction: column;
        align-items: stretch;
        border-radius: 30px;
        padding: 10px;
    }

    .room-id {
        font-size: 0.9rem;
        margin-bottom: 8px;
    }

    .copy-btn {
        width: 100%;
        justify-content: center;
    }

    .message-bubble {
        max-width: 85%;
    }

    .nickname-section {
        flex-wrap: wrap;
        padding: 10px;
    }

    .nickname-section span {
        width: 100%;
        margin-bottom: 5px;
    }

    .nickname-section input {
        width: 100%;
    }

    .nickname-section button {
        width: 100%;
    }

    .stats {
        float: none;
        display: block;
        text-align: center;
        margin-top: 10px;
    }
}

/* 小屏幕手机 */
@media (max-width: 480px) {
    .message-bubble {
        max-width: 90%;
    }

    .message-content {
        padding: 8px 12px;
        font-size: 0.9rem;
    }

    .input-area {
        padding: 4px 4px 4px 12px;
    }

    .input-area button {
        padding: 0 20px;
        font-size: 0.9rem;
    }
}