/* 全局样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #4a5cc4 0%, #3d4db8 50%, #2d3a8c 100%);
    min-height: 100vh;
    color: #333;
    overflow: hidden;
}

/* 主应用容器 */
.app-container {
    max-width: 414px;
    margin: 0 auto;
    min-height: 100vh;
    background: linear-gradient(135deg, #4a5cc4 0%, #3d4db8 50%, #2d3a8c 100%);
    position: relative;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

/* 角色选择页样式 */
header {
    text-align: center;
    padding: 40px 20px 30px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

header h1 {
    font-size: 28px;
    font-weight: 600;
    margin-bottom: 8px;
}

header p {
    font-size: 16px;
    opacity: 0.9;
}

.character-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    padding: 20px;
}

.character-card {
    background: white;
    border-radius: 16px;
    padding: 20px;
    text-align: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid transparent;
}

.character-card:hover,
.character-card:active {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    border-color: #667eea;
}

.character-avatar {
    font-size: 48px;
    margin-bottom: 12px;
    display: block;
}

.character-card h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
    color: #333;
}

.character-card p {
    font-size: 14px;
    color: #666;
    line-height: 1.4;
}

/* 聊天页面样式 */
.chat-container {
    width: 414px;
    max-width: 100vw;
    margin: 0 auto;
    height: 100vh;
    background: white;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

.chat-header {
    background: rgba(102, 126, 234, 0.8);
    backdrop-filter: blur(15px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    position: relative;
    z-index: 2;
}

.back-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    transition: background 0.3s ease;
}

.back-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.character-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.character-avatar-small {
    width: 50px;
    height: 50px;
    object-fit: cover;
    border-radius: 50%;
}

.character-details h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 2px;
}

.character-details p {
    font-size: 14px;
    opacity: 0.9;
}

/* 羁绊值样式 */
.bond-value {
    font-size: 14px;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.25);
    backdrop-filter: blur(10px);
    padding: 8px 14px;
    border-radius: 20px;
    white-space: nowrap;
    transition: all 0.3s ease;
    flex-shrink: 0;
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

#bondValue {
    color: #FFD700;
    font-weight: 700;
    margin-left: 4px;
}

.bond-updated {
    animation: bondPulse 1s ease;
    background: rgba(255, 215, 0, 0.3) !important;
}

@keyframes bondPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* 聊天背景容器 - 绝对定位背景层 */
.chat-background-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    /* 备用渐变背景 */
    background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #667eea 100%);
    /* 背景图片 - 如果存在会覆盖渐变 */
    background-image: url('./resource/backgrounds/chat-bg.jpg');
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: local;
}

.chat-background-wrapper::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.1);
    pointer-events: none;
    z-index: 0;
}

.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 16px;
    position: relative;
    background: transparent;
    z-index: 2;
    min-height: 0;
    max-height: calc(100vh - 180px);
}


.message {
    display: flex;
    gap: 12px;
    max-width: 85%;
    position: relative;
    z-index: 1;
}

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

.user-message {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-avatar {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 50%;
    flex-shrink: 0;
}

.message-content {
    background: rgba(245, 245, 245, 0.95);
    padding: 12px 16px;
    border-radius: 18px;
    position: relative;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.user-message .message-content {
    background: rgba(102, 126, 234, 0.9);
    color: white;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.message-content p {
    font-size: 16px;
    line-height: 1.4;
    margin: 0;
}

.chat-input {
    padding: 20px;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(15px);
    border-top: 1px solid rgba(255, 255, 255, 0.3);
    position: sticky;
    bottom: 0;
    z-index: 100;
}

.input-container {
    display: flex;
    gap: 12px;
    align-items: center;
}

#messageInput {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid rgba(224, 224, 224, 0.4);
    border-radius: 24px;
    font-size: 16px;
    outline: none;
    transition: border-color 0.3s ease;
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(10px);
}

#messageInput:focus {
    border-color: rgba(102, 126, 234, 0.8);
    background: rgba(255, 255, 255, 0.8);
}

#sendBtn {
    background: rgba(102, 126, 234, 0.9);
    backdrop-filter: blur(10px);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 12px 20px;
    border-radius: 24px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

#sendBtn:hover {
    background: rgba(102, 126, 234, 1);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

#sendBtn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* 加载动画 */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* ===== 新布局样式 ===== */

/* 顶部标题区域 */
.top-header {
    flex-shrink: 0;
    padding: 20px 16px 16px 16px;
}

/* 主要内容区域 - 左右两部分布局 */
.main-content {
    flex: 1;
    padding: 0 16px 100px 16px;
    overflow: visible;
    min-height: auto;
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.app-title {
    font-size: 28px;
    font-weight: 700;
    color: white;
    text-align: left;
    font-style: italic;
    margin-bottom: 16px;
}

.search-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* 左侧部分：功能按钮 + 左列卡片 */
.left-section {
    width: 50%;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* 右侧部分：右列卡片 */
.right-section {
    width: 50%;
    display: flex;
    flex-direction: column;
}

/* 功能按钮区域 */
.feature-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* 角色卡片容器 */
.character-cards-left,
.character-cards-right {
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow: visible;
    height: auto;
}

.search-box {
    flex: 1;
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 20px;
    padding: 8px 16px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.search-icon {
    margin-right: 8px;
    opacity: 0.7;
}

.search-box input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: rgba(255, 255, 255, 0.8);
    font-size: 14px;
}

.search-box input::placeholder {
    color: rgba(255, 255, 255, 0.6);
}

.profile-icon {
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* 功能按钮样式 */
.feature-btn {
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
    width: 100%;
}

.feature-btn-inactive {
    opacity: 0.8;
    cursor: default;
}

.feature-icon {
    font-size: 24px;
    flex-shrink: 0;
}

.feature-text {
    flex: 1;
}

.feature-title {
    font-size: 15px;
    font-weight: 600;
    color: white;
    margin-bottom: 2px;
}

.feature-desc {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.7);
    line-height: 1.3;
}

/* 每日限免样式保持与其他功能按钮一致 */
.daily-reward {
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
    width: 100%;
    opacity: 0.8;
    cursor: default;
}

/* 角色卡片样式 */
.character-card {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    transition: all 0.3s ease;
    cursor: pointer;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    width: 100%;
    height: auto;
    min-height: fit-content;
    display: flex;
    flex-direction: column;
}

.character-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
}

/* 卡片自适应高度 */
.character-card {
    height: auto;
    min-height: fit-content;
}

/* 卡片图片区域 */
.card-image {
    position: relative;
    height: 200px;
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    overflow: hidden;
    border-radius: 12px 12px 0 0;
}

.character-avatar-large {
    width: 100%;
    height: 100%;
    object-fit: cover;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.2));
}

.card-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.6));
    padding: 12px;
}

.character-tags {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.tag {
    background: rgba(255, 255, 255, 0.9);
    color: #333;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
}

/* 卡片信息区域 */
.card-info {
    padding: 16px;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.character-name {
    font-size: 16px;
    font-weight: 600;
    color: #333;
    margin-bottom: 8px;
}

.character-stats {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 8px;
}

.stat-icon {
    font-size: 14px;
}

.stat-count {
    font-size: 12px;
    color: #666;
    font-weight: 500;
}

.character-description {
    font-size: 13px;
    color: #666;
    line-height: 1.4;
}

/* 底部导航栏 */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 414px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    display: flex;
    padding: 8px 0 20px 0;
    z-index: 1000;
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px;
    position: relative;
    transition: all 0.2s ease;
}

.nav-item-active .nav-icon {
    color: #4a5cc4;
    transform: scale(1.1);
}

.nav-item-active .nav-label {
    color: #4a5cc4;
    font-weight: 600;
}

.nav-item-inactive {
    opacity: 0.6;
}

.nav-icon {
    font-size: 20px;
    transition: all 0.2s ease;
}

.nav-label {
    font-size: 11px;
    color: #666;
    font-weight: 500;
}

.nav-badge {
    position: absolute;
    top: 4px;
    right: 12px;
    background: #ff4757;
    color: white;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 16px;
    text-align: center;
}

/* 响应式调整 */
@media (max-width: 375px) {
    .character-grid {
        grid-template-columns: 1fr;
        gap: 12px;
        padding: 16px;
    }
    
    .character-card {
        padding: 16px;
    }
    
    .character-avatar {
        font-size: 40px;
    }
    
    header {
        padding: 30px 16px 24px;
    }
    
    header h1 {
        font-size: 24px;
    }
    
    .chat-header {
        padding: 16px;
        gap: 12px;
    }
    
    .bond-value {
        font-size: 12px;
        padding: 6px 10px;
    }
    
    .character-details h3 {
        font-size: 16px;
    }
    
    .character-details p {
        font-size: 12px;
    }
    
    .app-title {
        font-size: 24px;
    }
    
    .top-section {
        padding: 16px 12px;
    }
    
    .waterfall-grid {
        padding: 0 12px 100px 12px;
    }
    
    .feature-buttons {
        gap: 8px;
    }
    
    .feature-btn {
        padding: 12px;
    }
}