/* style.css */
body {
    background-color: #eef1f5;
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* 新增：应用标题栏样式 */
.app-header {
    background: #ffffff;
    padding: 0 20px; /* 统一左右内边距 */
    height: 50px; /* 在所有尺寸下都使用较小的高度 */
    display: flex;
    align-items: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05); /* 阴影更精细 */
    position: sticky;
    top: 0;
    z-index: 900;
}

.app-title {
    font-family: 'Noto Sans SC', sans-serif;
    font-size: 1.25rem; /* 在所有尺寸下都使用较小的字号 */
    font-weight: 700;
    color: #1c1c1e;
    margin: 0;
}

.app-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 15px;
    max-width: 100%;
    min-height: 100vh;
}

.controls {
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    background: #fcfcfc;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    box-sizing: border-box; /* 新增: 解决小屏幕下的溢出问题 */
}

/* === 编辑面板现代化改造 === */
.controls fieldset {
    border: 1px solid rgba(0, 0, 0, 0.05); /* 新增: 添加一个非常细微的边框来强化轮廓 */
    padding: 0;
    margin: 30px 0 0 0;
    background-color: #ffffff;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.07); /* 修改: 增强阴影效果 */
}

.controls fieldset:first-of-type {
    margin-top: 0;
}

.controls legend {
    width: 100%;
    padding-bottom: 15px;
    margin-bottom: 15px;
    font-size: 1.15rem;
    font-weight: 700;
    color: #1c1c1e;
    border-bottom: 1px solid #f0f2f5;
}

.controls label {
    color: #3c3c43;
    font-weight: 600;
    font-size: 0.9rem;
}

.controls input[type="text"], 
.controls input[type="file"], 
.card-control textarea, 
.card-control input[type="text"] {
    background-color: #f6f7f9;
    border: 1px solid #e8e9ec;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.background-section,
.global-card-controls,
.card-section-control {
    background-color: #f6f7f9;
    border: 1px solid #e8e9ec;
    border-radius: 8px;
    padding: 15px;
    margin-top: 15px;
}

.card-section-control {
    border-top: none;
    padding-top: 15px;
    background: transparent;
    border: none;
}

.card-section-control:not(:first-of-type) {
     border-top: 1px solid #f0f2f5;
     margin-top: 25px;
     padding-top: 25px;
}

.global-card-controls .group-legend,
.card-section-title {
    border: none;
    font-size: 1rem;
    font-weight: 600;
    color: #1c1c1e;
    padding: 0;
    margin-bottom: 15px;
}

.background-options {
    background-color: #fff;
}
/* === 改造结束 === */

.controls h2, .controls legend {
    border-bottom: 2px solid #f0f2f5;
    padding-bottom: 10px;
    margin-bottom: 15px;
    color: #333;
}
.controls label {
    display: block;
    margin-top: 10px;
    margin-bottom: 5px;
    font-weight: 600;
    color: #555;
}
.controls input[type="text"], .controls input[type="file"] {
    width: 100%;
    padding: 10px;
    box-sizing: border-box;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
}

.controls input[type="text"]:focus {
    outline: none;
    border-color: #007AFF;
    box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.2);
}

.background-section {
    border: 1px solid #e9ecef;
    border-radius: 6px;
    padding: 10px;
    margin-top: 10px;
}

.background-options {
    margin-top: 8px;
    padding: 8px 12px;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.background-options .group-label {
    font-weight: 600;
    color: #555;
    margin: 0;
}

.background-options label {
    font-weight: normal;
    font-size: 14px;
    display: inline-block; /* Allow labels to sit next to radios */
    margin: 0;
}

.preview {
    width: 100%;
    max-width: 600px; /* 调整宽度以获得更好的文字排版 */
    margin: 0 auto;
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.1);
    overflow: hidden;
    transition: background-color 0.3s ease;
    padding: 15px;
    box-sizing: border-box;
    position: relative; /* 为蒙版伪元素定位 */
    background-size: cover;
    background-position: center;
}

/* 新增：字体切换的样式类 */
.preview.font-sans {
    font-family: 'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', sans-serif;
}

.preview.font-serif {
    font-family: 'Noto Serif SC', 'Songti SC', 'SimSun', serif;
}

.preview.has-bg-image::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--overlay-color, rgba(255, 255, 255, 0.5));
    border-radius: 20px; /* 匹配父元素的圆角 */
    z-index: 1;
    pointer-events: none; /* 确保不影响交互 */
    transition: background-color 0.3s ease;
}

/* 预览区的个人信息样式 */
.profile-header {
    padding: 30px 15px;
    text-align: center;
    background-color: #f0f2f5;
    background-size: cover;
    background-position: center;
    position: relative;
    color: #333;
    border-radius: 12px;
    transition: background-color 0.3s ease; /* 为背景色变化添加平滑过渡 */
    z-index: 2; /* 确保在蒙版之上 */
}
.avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: 4px solid #fff;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    object-fit: cover;
}
.profile-header h1 { 
    margin: 10px 0 5px; 
    font-size: 1.5rem;
    font-weight: 700;
}
.profile-header p { 
    margin: 0; 
    color: #666; 
    font-size: 0.9rem;
    line-height: 1.4;
    text-shadow: none; /* Reset text-shadow */
    transition: color 0.3s ease; /* Add transition */
}

/* 卡片容器样式 - JS Masonry Layout */
#dual-column-cards-container {
    position: relative; /* Crucial for absolute positioning of cards */
    width: 100%;
    transition: height 0.3s ease; /* Animate height changes */
    margin-top: 0; /* Default margin */
    box-sizing: border-box; /* 新增：确保padding被包含在宽度内，防止溢出 */
    /* Padding is on the .preview parent */
    z-index: 2; /* 确保在蒙版之上 */
}

#single-column-cards-container {
    position: relative;
    z-index: 2; /* 确保在蒙版之上 */
}

#single-column-cards-container .card {
    margin-bottom: 15px;
}

/* 单个卡片样式 */
.card {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    border: none;
    transition: all 0.3s ease;
    box-sizing: border-box;
    position: relative;
}

/* 新增：为可编辑元素提供视觉反馈和占位符样式 */
[contenteditable="true"]:focus {
    outline: 2px solid rgba(0, 122, 255, 0.5);
    box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.2);
    border-radius: 4px;
}

[contenteditable="true"]:empty::before {
    content: attr(data-placeholder);
    color: #999;
    pointer-events: none; /* 确保伪元素不影响点击 */
}


.card.align-center {
    text-align: center;
}

.card.align-left {
    text-align: left;
}

.card.card-has-bg {
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

/* 新增：卡片背景图蒙版样式 */
.card.card-has-bg::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--card-overlay-color, rgba(255, 255, 255, 0.5));
    border-radius: 10px; /* 匹配卡片的圆角 */
    z-index: 1;
    pointer-events: none;
    transition: background-color 0.3s ease;
}


.card.no-shadow {
    box-shadow: none;
}

#dual-column-cards-container .card {
    position: absolute; /* Crucial for JS layout */
}

.card:hover {
    transform: translateY(-1px) scale(1.02);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.card-title { 
    margin: 0 0 8px; 
    font-weight: 600;
    color: #333;
    transition: color 0.3s ease;
    position: relative;
    z-index: 2;
}
.card-content { 
    margin: 0; 
    white-space: pre-wrap;
    line-height: 1.5;
    color: #555;
    overflow-wrap: break-word;
    transition: color 0.3s ease;
    position: relative;
    z-index: 2;
}

/* 卡片控制器样式 */
.card-control {
    border: 1px solid #e0e0e0;
    padding: 15px;
    margin-bottom: 15px;
    border-radius: 8px;
    background: #fafafa;
    position: relative; /* 为拖拽手柄定位 */
    padding-left: 40px; /* 为拖拽手柄留出空间 */
}

/* 新增：滚动到编辑卡片时的临时高亮效果 */
@keyframes highlight-fade {
    from {
        background-color: rgba(0, 122, 255, 0.15);
        box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.2);
    }
    to {
        background-color: initial;
        box-shadow: initial;
    }
}

.card-control.highlight-scroll {
    animation: highlight-fade 1.5s ease-out;
}


/* 新增：拖拽手柄样式 */
.drag-handle {
    position: absolute;
    top: 0;
    left: 0;
    width: 40px; /* 匹配父元素的左内边距，覆盖整个热区 */
    height: 100%;
    cursor: grab;
    color: #b0b0b0;
    user-select: none; /* 防止拖动时选中文本 */
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.drag-handle:active {
    cursor: grabbing;
}

/* 新增：拖拽过程中的视觉反馈样式 */
.card-control.dragging {
    opacity: 0.5;
    background: #eef1f5;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.card-control textarea { 
    width: 100%; 
    min-height: 60px; 
    resize: vertical;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 8px;
    font-size: 14px;
    box-sizing: border-box; /* 新增: 解决文本框溢出问题 */
}

.card-control input[type="text"] {
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 8px;
    font-size: 14px;
}

/* 新增：卡片背景图控制器样式 */
.card-bg-control {
    display: flex;
    gap: 10px;
    align-items: center;
    margin: 8px 0;
}

.card-bg-control input[type="file"] {
    flex-grow: 1;
    width: 100%; /* 确保在 flex 容器中正确填充 */
}

.card-bg-control .clear-card-bg-btn {
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid #ddd;
    background-color: #f1f2f6;
    cursor: pointer;
    font-size: 12px;
    flex-shrink: 0; /* 防止按钮被压缩 */
}

.card-bg-control .clear-card-bg-btn:hover {
    background-color: #e5e6eb;
}

/* 新增: 卡片对齐控制器样式 */
.card-alignment-control {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px; /* 与其他控件保持间距 */
    font-size: 13px;
}

.card-alignment-control > label {
    margin: 0;
    cursor: pointer;
    font-weight: 600;
    color: #555;
}

.card-alignment-control input[type="radio"] {
    margin-left: 4px;
}

.card-alignment-control input[type="radio"] + label {
    font-weight: normal;
    cursor: pointer;
}

/* 新增：为字体选择下拉框添加样式 */
#global-font-family-select {
    width: 150px; /* 给下拉框一个合适的宽度 */
    padding: 6px;
    border: 1px solid #ddd;
    border-radius: 6px;
    background-color: #fff;
    font-size: 14px;
    -webkit-appearance: none; /* 移除原生外观 */
    -moz-appearance: none;
    appearance: none;
    background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20width%3D%2220%22%20height%3D%2220%22%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%3E%3Cpath%20d%3D%22M5%208l5%205%205-5z%22%20fill%3D%22%23555%22/%3E%3C/svg%3E');
    background-repeat: no-repeat;
    background-position: right 5px center;
    background-size: 1.2em;
}

/* 新增：卡片背景图显示方式选项样式 */
.card-bg-options {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    padding: 6px 10px;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    background-color: #fff;
    font-size: 13px;
}

.card-bg-options label {
    margin: 0;
    cursor: pointer;
}

.card-bg-options label.group-label {
    font-weight: 600;
    color: #555;
    margin: 0;
}

.card-bg-options input[type="radio"] {
    margin-right: 2px;
}

/* 新增：用于将颜色选择器并排显示的样式 */
.color-controls-row {
    display: flex;
    gap: 15px;
    align-items: flex-start;
    margin-top: 10px;
}

.color-control-group {
    flex: 1;
}

.color-control-group label {
    margin-top: 0;
}

.misc-controls {
    margin-top: 10px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.misc-controls label {
    margin: 0;
    font-weight: normal;
    font-size: 14px;
}

.global-card-controls {
    border: 1px solid #007AFF;
    border-radius: 8px;
    padding: 10px 15px 15px;
    margin-bottom: 20px;
    background: #f5faff;
}

.global-card-controls .group-legend {
    font-weight: 600;
    color: #007AFF;
    padding: 0 5px;
    margin-left: -5px;
    font-size: 15px;
}

.card-section-control {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid #e9ecef;
}

.card-section-title {
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 1rem;
    color: #333;
}

.delete-card-btn {
    background: #ff4757;
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    margin-top: 8px;
    float: right;
}

.delete-card-btn:hover {
    background: #e03c48;
}

#add-card-btn, #export-btn, #add-single-card-btn, #add-dual-card-btn {
    background: #007AFF;
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    width: 100%;
    margin-top: 10px;
    transition: background-color 0.2s ease;
}

#add-card-btn:hover, #export-btn:hover:not(:disabled), #add-single-card-btn:hover, #add-dual-card-btn:hover {
    background: #0056CC;
}

/* 新增：为导入/导出按钮组添加样式 */
.action-buttons-container {
    display: flex;
    flex-direction: column; /* 垂直排列 */
    gap: 10px;
    margin-top: 20px;
}

.config-actions {
    display: flex;
    gap: 10px;
}

.config-actions button {
    flex: 1;
    background-color: #8e8e93; /* 低调的灰色 */
    color: white;
    border: none;
    padding: 8px 0; /* 较小的内边距 */
    border-radius: 6px; /* 较小的圆角 */
    cursor: pointer;
    font-size: 13px; /* 较小的字号 */
    font-weight: 500;
    transition: background-color 0.2s ease;
}

.config-actions button:hover {
    background-color: #636366;
}

/* 保持主导出按钮的样式 */
#export-btn {
    width: 100%;
    background: #007AFF;
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: background-color 0.2s ease;
}

#export-btn:hover:not(:disabled) {
    background-color: #0056CC;
}

#export-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* 响应式设计，适配更小的屏幕 */
@media (max-width: 400px) {
    .app-container {
        padding: 10px;
        gap: 15px;
    }
    
    .controls {
        padding: 15px;
    }
    
    .preview {
        border-radius: 8px;
    }
    
    .cards-container {
        /* gap: 8px; /* 移除，避免与JS中的10px冲突 */
        /* padding: 12px; */ /* 移除，这是导致双列和单列边距不一致的根源 */
    }
    
    .card {
        padding: 10px;
        font-size: 0.8rem;
        border-radius: 8px;
    }
    
    .card-title {
        font-size: 0.9rem;
    }
    
    .profile-header {
        padding: 25px 12px;
    }
    
    .avatar {
        width: 70px;
        height: 70px;
    }
}

/* 当处于导出模式时，移除所有不必要的阴影和边框，确保截图干净 */
/* .export-mode 已被JS离屏渲染取代，不再需要 */

/* === 新增：图片裁剪模态框样式 === */
.cropper-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.cropper-modal-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.cropper-container {
    background-color: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    max-width: 90vw;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

.cropper-container .img-container {
    max-width: 100%;
    max-height: calc(80vh - 100px); /* 减去按钮区域的高度 */
    overflow: hidden;
}

.cropper-container .img-container img {
    max-width: 100%;
    display: block;
}

.cropper-actions {
    margin-top: 15px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.cropper-actions button {
    background: #007AFF;
    color: white;
    border: none;
    padding: 10px 18px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
}

.cropper-actions button.cancel-btn {
    background: #e0e0e0;
    color: #333;
}

/* === 新增：下载模态框样式 === */
.download-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.download-modal-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.download-modal-container {
    background-color: white;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    text-align: center;
    max-width: 90vw;
    width: 350px;
}

#download-modal-title {
    margin-top: 0;
    margin-bottom: 20px;
    font-size: 1.2rem;
    color: #333;
}

#download-modal-content a {
    display: block;
    background: #007AFF;
    color: white;
    text-decoration: none;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 20px;
    transition: background-color 0.2s ease;
}

#download-modal-content a:hover {
    background-color: #0056CC;
}

#download-modal-close-btn {
    background: #e0e0e0;
    color: #333;
    border: none;
    padding: 10px 18px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    width: 100%;
}


/* === PC端双栏布局 (屏幕宽度 > 992px) === */
@media (min-width: 992px) {
    .app-container {
        max-width: 1400px;
        margin: 0 auto;
        padding: 25px;
        gap: 25px;
    }

    .main-content {
        display: flex;
        flex-direction: row;
        align-items: flex-start;
        gap: 25px;
        justify-content: center; /* 新增：让左右两栏在宽屏上居中显示 */
    }

    .controls {
        flex: 1 0 420px; /* 允许面板增长，基础宽度420px，防止收缩 */
        max-width: 600px; /* 设置一个最大宽度，避免在超宽屏上过分拉伸 */
        margin: 0; /* 覆盖移动端的 auto margin */
        position: sticky; /* 滚动时固定在页面上 */
        top: 25px; /* 与 app-container 的 padding 保持一致 */
        max-height: calc(100vh - 50px - 50px); /* 减去新的顶栏高度和上下边距 */
        overflow-y: auto; /* 当内容超出时显示滚动条 */
    }

    .preview {
        flex: 0 0 600px; /* 修改：固定宽度，不拉伸或压缩 */
        width: 600px;      /* 修改：显式设置宽度 */
        max-width: 600px;  /* 修改：覆盖移动端的 max-width */
        margin: 0; /* 覆盖移动端的 auto margin */
    }
}

/* 新增：卡片蒙版控制器样式 */
.card-overlay-controls {
    margin-top: 10px;
    padding: 10px;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    background-color: #fff;
}

.card-overlay-controls > label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #555;
}

.card-overlay-controls .color-controls-row {
    margin-top: 0;
}

.card-overlay-controls .color-control-group label {
    font-size: 13px;
    font-weight: normal;
}

.preview.font-size-small {
    font-size: 15px;
}
.preview.font-size-medium {
    font-size: 17px;
}
.preview.font-size-large {
    font-size: 19px;
}

.preview.mobile-mode {
    width: 375px !important;
    max-width: 375px !important;
    border-radius: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    padding: 10px;
}