* {
    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;
    color: #333;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

header {
    text-align: center;
    margin-bottom: 40px;
    color: white;
}

header h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
    font-weight: 700;
}

header p {
    font-size: 1.1em;
    opacity: 0.9;
}

main {
    display: grid;
    grid-template-columns: 1fr; /* 改为单列布局 */
    gap: 30px;
    background: white;
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
}

/* 调整预览区域样式使其居中 */
.preview-section {
    order: 2;
}

/* 调整编辑器区域样式 */
.editor-section {
    order: 1;
    max-width: 800px; /* 设置最大宽度 */
    margin: 0 auto; /* 水平居中 */
}

/* 调整预览容器样式 */
.preview-container {
    display: flex;
    justify-content: center; /* 水平居中 */
    margin-bottom: 20px;
}

.editor-section h3,
.preview-section h3 {
    font-size: 1.2em;
    margin-bottom: 20px;
    color: #2c3e50;
    border-bottom: 2px solid #e74c3c;
    padding-bottom: 10px;
}

.template-selector {
    margin-bottom: 30px;
}

.template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
    width: 100%;
    box-sizing: border-box;
    padding: 5px;
    min-height: 500px; /* 确保有足够高度显示所有模板 */
    overflow-y: auto; /* 如有需要添加滚动 */
}

.template-item {
    position: relative;
    cursor: pointer;
    border: 3px solid transparent;
    border-radius: 12px;
    overflow: hidden;
    transition: all 0.3s ease;
    aspect-ratio: 3/4;
    opacity: 1; /* 确保初始可见 */
}

.template-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

.template-item.active {
    border-color: #e74c3c;
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(231, 76, 60, 0.3);
}

.template-preview {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

img.template-preview {
    object-position: center;
    background: #f0f0f0;
}

.template-background {
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center;
}

.template-background[data-template-type="image"] {
    background-size: cover !important;
    background-position: center;
    width: 100%;
    height: 100%;
    position: absolute;
}

.template-name {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
    color: white;
    padding: 15px 10px 10px;
    font-size: 0.9rem;
    text-align: center;
    font-weight: 500;
}

.text-editor {
    display: flex;
    flex-direction: column;
}

#textInput {
    width: 100%;
    height: 200px;
    padding: 15px;
    border: 2px solid #ddd;
    border-radius: 10px;
    font-size: 1rem;
    font-family: inherit;
    resize: vertical;
    transition: border-color 0.3s ease;
}

#textInput:focus {
    outline: none;
    border-color: #e74c3c;
    box-shadow: 0 0 0 3px rgba(231, 76, 60, 0.1);
}

.editor-controls {
    display: flex;
    gap: 15px;
    margin-top: 20px;
}

.editor-controls button {
    flex: 1;
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

#previewBtn {
    background: #3498db;
    color: white;
}

#previewBtn:hover {
    background: #2980b9;
    transform: translateY(-2px);
}

#downloadBtn {
    background: #e74c3c;
    color: white;
}

#downloadBtn:hover {
    background: #c0392b;
    transform: translateY(-2px);
}

.preview-container {
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.cover-preview {
    width: 1242px;
    height: 1660px;
    position: relative;
    border-radius: 15px;
    overflow: hidden;
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.2);
    background: transparent; /* 将#f8f9fa改为transparent */
}

.template-background {
    width: 100%;
    height: 100%;
    position: relative;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

.text-overlay {
    position: absolute;
    padding: 20px;
    color: #333;
    font-weight: 500;
    line-height: 1.4;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.preview-text {
    font-size: inherit; /* 将固定值改为继承父元素样式 */
}

.preview-text h1 {
    font-size: 2em;
    font-weight: 700;
    margin-bottom: 10px;
    color: #2c3e50;
}

.preview-text h2 {
    font-size: 1.5em;
    font-weight: 600;
    margin-bottom: 8px;
    color: #34495e;
}

.preview-text h3 {
    font-size: 1.2em;
    font-weight: 600;
    margin-bottom: 6px;
    color: #34495e;
}

.preview-text strong {
    font-weight: 700;
    color: #e74c3c;
}

.preview-text em {
    font-style: italic;
    color: #8e44ad;
}

.preview-text p {
    margin-bottom: 10px;
}

/* 响应式设计 */
@media (max-width: 1024px) {
    main {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .cover-preview {
        width: 250px;
        height: 333px;
    }
}

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

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

/* 添加全局动画样式 */
@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes slideOutRight {
  from { transform: translateX(0); opacity: 1; }
  to { transform: translateX(100%); opacity: 0; }
}

/* 0702 */
/* 添加模板选择器样式 */
.template-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    padding: 15px;
    min-height: 100px;
}

.template-item {
    width: 120px;
    height: 160px;
    border: 2px solid #ddd;
    border-radius: 8px;
    cursor: pointer;
    overflow: hidden;
    transition: all 0.3s;
    position: relative;
    opacity: 1; /* 移除延迟加载透明度 */
}

.template-item:hover {
    border-color: #4a90e2;
    transform: translateY(-3px);
}

.template-item.selected {
    border-color: #4a90e2;
    box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.3);
}

.template-preview-img{
    object-fit: contain; /* 替换cover为contain完整显示图片 */
    width: 100%;
    height: 100%;
}
.template-preview-css {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: cover !important;
    background-position: center !important;
}

.template-name {
    padding: 8px;
    font-size: 12px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.loading-state,
.empty-state,
.error-state {
    width: 100%;
    padding: 40px 0;
    text-align: center;
    color: #666;
    font-size: 14px;
}

.error-state {
    color: #e74c3c;
}

.empty-state {
    color: #999;
}

.editor-section {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.text-editor {
    width: 100%;
}

#textInput {
    width: 100%;
    height: 250px; /* 适当增加高度 */
}