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

:root {
    --primary: #FF6B9D;
    --primary-dark: #E85A8A;
    --bg: #FAFAFA;
    --surface: #FFFFFF;
    --text: #1A1A1A;
    --text-secondary: #666666;
    --border: #E5E5E5;
    --shadow: rgba(0, 0, 0, 0.08);
    --radius: 16px;
}

[data-theme="blue"] {
    --primary: #4A90E2;
    --primary-dark: #357ABD;
}

[data-theme="purple"] {
    --primary: #9B59B6;
    --primary-dark: #8E44AD;
}

[data-theme="green"] {
    --primary: #2ECC71;
    --primary-dark: #27AE60;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow-x: hidden;
    /* iOS刘海屏适配 */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
}

/* 启动画面 */
.splash-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #FFFFFF;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    animation: fadeOut 0.5s ease 2.5s forwards;
}

@keyframes fadeOut {
    to {
        opacity: 0;
        visibility: hidden;
    }
}

.splash-content {
    text-align: center;
}

.splash-icon {
    width: 120px;
    height: 120px;
    margin: 0 auto 32px;
    position: relative;
}

.logo-circle {
    width: 100%;
    height: 100%;
    border: 2px solid #000000;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    animation: elegantSpin 2s ease-in-out;
}

@keyframes elegantSpin {
    0% {
        transform: rotate(0deg) scale(0.9);
        opacity: 0;
    }
    40% {
        transform: rotate(120deg) scale(1);
        opacity: 1;
    }
    60% {
        transform: rotate(240deg) scale(1);
    }
    100% {
        transform: rotate(360deg) scale(1);
        opacity: 1;
    }
}

.logo-b {
    font-size: 48px;
    font-weight: 300;
    color: #000000;
    font-family: 'Georgia', serif;
    letter-spacing: 2px;
}

.splash-title {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 32px;
    line-height: 1.4;
    color: var(--text);
    animation: slideUp 0.8s ease 0.2s both;
}

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

.splash-loader {
    width: 40px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 0 auto;
    overflow: hidden;
    animation: slideUp 0.8s ease 0.4s both;
}

.splash-loader::after {
    content: '';
    display: block;
    width: 50%;
    height: 100%;
    background: var(--primary);
    border-radius: 2px;
    animation: loading 1.5s ease-in-out infinite;
}

@keyframes loading {
    0%, 100% {
        transform: translateX(-100%);
    }
    50% {
        transform: translateX(200%);
    }
}

/* 屏幕通用样式 */
.screen {
    min-height: 100vh;
    padding-bottom: 20px;
}

.screen-header {
    display: flex;
    align-items: center;
    padding: 16px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.back-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: none;
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

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

.back-btn svg {
    width: 24px;
    height: 24px;
}

.screen-header h2 {
    font-size: 20px;
    font-weight: 600;
    margin-left: 12px;
}

.history-btn,
.new-conversation-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
}

.history-btn:hover,
.new-conversation-btn:hover {
    background: var(--primary);
    color: white;
    transform: scale(1.05);
}

.history-btn svg,
.new-conversation-btn svg {
    width: 20px;
    height: 20px;
}

/* 主屏幕 */
.home-container {
    padding: 40px 20px;
    max-width: 600px;
    margin: 0 auto;
}

.home-header {
    text-align: center;
    margin-bottom: 48px;
}

.home-title {
    font-size: 36px;
    font-weight: 700;
    color: #000000;
    margin-bottom: 8px;
}

.home-subtitle {
    font-size: 16px;
    color: var(--text-secondary);
}

.home-cards {
    display: grid;
    gap: 16px;
    margin-bottom: 80px;
}

.home-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 24px;
    cursor: pointer;
    transition: all 0.3s;
    border: 2px solid transparent;
}

.home-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 24px var(--shadow);
    border-color: var(--primary);
}

.card-icon {
    width: 48px;
    height: 48px;
    background: transparent;
    border: 2px solid #000000;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}

.card-icon svg {
    width: 24px;
    height: 24px;
    color: #000000;
    stroke-width: 1.5;
}

.home-card h3 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 8px;
}

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

.settings-btn {
    position: fixed;
    bottom: 32px;
    right: 32px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: var(--primary);
    color: white;
    cursor: pointer;
    box-shadow: 0 8px 16px var(--shadow);
    transition: transform 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.settings-btn:hover {
    transform: scale(1.1);
}

.settings-btn svg {
    width: 24px;
    height: 24px;
}

/* 设置页面 */
.settings-container {
    padding: 20px;
    max-width: 600px;
    margin: 0 auto;
}

.settings-section {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 16px;
}

.settings-section h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 16px;
}

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

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

.form-group input,
.form-group select {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 15px;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
}

.btn-primary,
.btn-secondary {
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    width: 100%;
    margin-top: 8px;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow);
}

.btn-secondary {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--surface);
}

/* 源码查看页面 */
.source-container {
    padding: 20px;
    max-width: 800px;
    margin: 0 auto;
}

.source-section {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
}

.source-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.source-header h3 {
    font-size: 18px;
    font-weight: 600;
}

.btn-copy {
    padding: 8px 16px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-copy:hover {
    background: var(--primary-dark);
}

.source-code {
    background: #F5F5F5;
    border-radius: 8px;
    padding: 16px;
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.6;
    overflow-x: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.source-credit {
    text-align: center;
    font-size: 12px;
    color: var(--text-secondary);
    padding: 20px;
    line-height: 1.6;
}

/* 生成器页面 */
.generator-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    padding: 20px;
    max-width: 1400px;
    margin: 0 auto;
}

@media (max-width: 1024px) {
    .generator-container {
        grid-template-columns: 1fr;
    }
}

.chat-interface {
    background: var(--surface);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    height: calc(100vh - 140px);
}

.chat-history {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
}

.chat-message {
    margin-bottom: 16px;
    animation: messageIn 0.3s ease;
}

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

.chat-message.user {
    text-align: right;
}

.message-bubble {
    display: inline-block;
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 15px;
    line-height: 1.5;
}

.chat-message.user .message-bubble {
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-message.ai .message-bubble {
    background: var(--bg);
    color: var(--text);
    border-bottom-left-radius: 4px;
}

.chat-input-area {
    padding: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 12px;
}

.chat-input-area textarea {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 15px;
    resize: none;
    min-height: 80px;
    font-family: inherit;
}

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

.btn-send {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    background: var(--primary);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

.btn-send:hover {
    transform: scale(1.1);
}

.btn-send svg {
    width: 20px;
    height: 20px;
}

/* 预览区域 */
.preview-section,
.code-result-section {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
    height: calc(100vh - 140px);
    display: flex;
    flex-direction: column;
}

.preview-section h3,
.code-result-section h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 16px;
}

.bubble-preview {
    flex: 1;
    background: #F0F0F0;
    border-radius: 12px;
    padding: 20px;
    overflow-y: auto;
}

.preview-chat {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.preview-msg {
    display: flex;
}

.preview-msg.ai {
    justify-content: flex-start;
}

.preview-msg.user {
    justify-content: flex-end;
}

.preview-bubble {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 15px;
    line-height: 1.5;
}

.preview-msg.ai .preview-bubble {
    background: white;
    color: #333;
    border: 2px solid #000;
    border-radius: 4px 20px 20px 20px;
}

.preview-msg.user .preview-bubble {
    background: #FFD1DC;
    color: #000;
    border: 2px solid #000;
    border-radius: 20px 4px 20px 20px;
}

.code-result {
    flex: 1;
    background: #F5F5F5;
    border-radius: 8px;
    padding: 16px;
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.6;
    overflow-x: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.preview-actions,
.result-actions {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

.preview-actions button,
.result-actions button {
    flex: 1;
}

/* 收藏空间 */
.collection-container {
    padding: 20px;
    max-width: 1000px;
    margin: 0 auto;
}

.collection-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    background: var(--surface);
    padding: 8px;
    border-radius: 12px;
}

.tab-btn {
    flex: 1;
    padding: 12px 24px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 15px;
    font-weight: 500;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.tab-btn.active {
    background: var(--primary);
    color: white;
}

.collection-content {
    display: grid;
    gap: 16px;
}

.collection-item {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
    border: 2px solid var(--border);
    transition: all 0.2s;
}

.collection-item:hover {
    border-color: var(--primary);
    box-shadow: 0 4px 12px var(--shadow);
}

.collection-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.collection-item-title {
    font-size: 16px;
    font-weight: 600;
}

.collection-item-date {
    font-size: 12px;
    color: var(--text-secondary);
}

.collection-item-preview {
    background: #F5F5F5;
    border-radius: 8px;
    padding: 12px;
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: 12px;
    max-height: 150px;
    overflow: hidden;
    margin-bottom: 12px;
    position: relative;
}

.collection-item-preview::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 40px;
    background: linear-gradient(transparent, #F5F5F5);
}

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

.collection-item-actions button {
    flex: 1;
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-view {
    background: var(--bg);
    color: var(--text);
}

.btn-view:hover {
    background: var(--border);
}

.theme-selector {
    display: flex;
    gap: 12px;
}

.theme-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 3px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
}

.theme-btn:hover {
    transform: scale(1.1);
}

.theme-btn.active {
    border-color: var(--text);
}

.btn-export {
    background: var(--primary);
    color: white;
}

.btn-export:hover {
    opacity: 0.9;
}

.btn-delete {
    background: #FF4757;
    color: white;
}

.btn-delete:hover {
    opacity: 0.9;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.empty-state svg {
    width: 80px;
    height: 80px;
    margin-bottom: 16px;
    opacity: 0.3;
}

.empty-state p {
    font-size: 16px;
}

/* 预设列表 */
.preset-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.preset-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background: var(--bg);
    border-radius: 8px;
    border: 1px solid var(--border);
}

.preset-item-name {
    font-size: 14px;
    font-weight: 500;
}

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

.preset-item-actions button {
    padding: 4px 12px;
    border: none;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-load {
    background: var(--primary);
    color: white;
}

.btn-remove {
    background: transparent;
    color: var(--text-secondary);
}

.btn-remove:hover {
    color: #FF4757;
}

/* 加载状态 */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* 错误提示 */
.error-message {
    background: #FFE5E5;
    color: #FF4757;
    padding: 12px 16px;
    border-radius: 8px;
    margin: 12px 0;
    font-size: 14px;
    border-left: 4px solid #FF4757;
}

/* 成功提示 */
.success-message {
    background: #E5FFE5;
    color: #2ECC71;
    padding: 12px 16px;
    border-radius: 8px;
    margin: 12px 0;
    font-size: 14px;
    border-left: 4px solid #2ECC71;
}

/* 响应式设计 */
@media (max-width: 768px) {
    body {
        padding-bottom: calc(env(safe-area-inset-bottom) + 20px);
    }
    
    .home-title {
        font-size: 28px;
    }
    
    .settings-btn {
        bottom: calc(20px + env(safe-area-inset-bottom));
        right: 20px;
        width: 48px;
        height: 48px;
    }
    
    .generator-container {
        padding: 12px;
        gap: 12px;
    }
    
    .chat-interface {
        height: auto;
        min-height: 50vh;
        max-height: 60vh;
    }
    
    .preview-section,
    .code-result-section {
        height: auto;
        min-height: 400px;
    }
    
    .chat-input-area {
        padding: 12px;
        gap: 8px;
        flex-wrap: nowrap;
    }
    
    .chat-input-area textarea {
        min-height: 60px;
        max-height: 120px;
        font-size: 16px; /* 防止iOS自动缩放 */
    }
    
    .btn-send {
        flex-shrink: 0;
        width: 44px;
        height: 44px;
    }
    
    .screen-header {
        padding: 12px 16px;
    }
    
    .screen-header h2 {
        font-size: 18px;
        flex: 1;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    
    .history-btn,
    .new-conversation-btn {
        width: 36px;
        height: 36px;
    }
    
    .message-bubble {
        max-width: 85%;
        font-size: 14px;
    }
    
    .code-result,
    .source-code {
        font-size: 11px;
        padding: 12px;
    }
    
    .collection-item-actions {
        flex-wrap: wrap;
    }
    
    .collection-item-actions button {
        min-width: calc(50% - 4px);
    }
}

/* 超小屏幕优化 */
@media (max-width: 480px) {
    .home-container {
        padding: 24px 16px;
    }
    
    .home-title {
        font-size: 24px;
    }
    
    .home-card {
        padding: 20px;
    }
    
    .generator-container {
        padding: 8px;
    }
    
    .chat-history {
        padding: 12px;
    }
    
    .preview-actions,
    .result-actions {
        flex-direction: column;
        gap: 8px;
    }
    
    .preview-actions button,
    .result-actions button {
        width: 100%;
    }
}
