:root {
    --primary-color: #007bff;
    --secondary-color: #0056b3;
    --background-color: #f0f2f5;
    --text-color: #333;
    --border-color: #ddd;
    --shadow-color: rgba(0, 0, 0, 0.1);
}

body {
    font-family: 'Noto Sans', sans-serif;
    background-color: var(--background-color);
    margin: 0;
    padding: 10px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    box-sizing: border-box;
}

.main-container {
    background-color: #fff;
    padding: 15px;
    border-radius: 10px;
    box-shadow: 0 4px 8px var(--shadow-color);
    width: 100%;
    max-width: 800px;
    text-align: center;
    border: 1px solid var(--border-color);
    box-sizing: border-box;
    overflow: hidden;
}

.area2 {
    display: flex;
    justify-content: space-between;
    align-items: stretch;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.area3 {
    width: 100%;
    max-width: 60%;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    padding: 10px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    margin-bottom: 15px;
    box-shadow: 0 2px 4px var(--shadow-color);
}

textarea {
    width: 100%;
    height: 200px;
    padding: 8px;
    border-radius: 5px;
    border: 1px solid #ccc;
    resize: none;
    font-family: inherit;
    font-size: 14px;
    margin-bottom: 10px;
    box-sizing: border-box;
    transition: box-shadow 0.3s;
}

textarea:focus {
    box-shadow: 0 0 5px var(--primary-color);
}

button {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: #fff;
    border: none;
    padding: 10px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.3s, transform 0.3s, box-shadow 0.3s;
    align-self: center;
    width: 48%;
    margin-top: 10px;
    box-shadow: 0 2px 4px var(--shadow-color);
}

button:hover {
    background: linear-gradient(135deg, var(--secondary-color), var(--primary-color));
    transform: translateY(-2px);
    box-shadow: 0 4px 8px var(--shadow-color);
}

button:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px var(--shadow-color);
}

.area1 {
    width: 100%;
    max-width: 35%;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    padding: 10px;
    box-sizing: border-box;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    box-shadow: 0 2px 4px var(--shadow-color);
    max-height: 300px;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: var(--primary-color) var(--background-color);
    padding-right: 16px;
}

.area1::-webkit-scrollbar {
    width: 8px;
}

.area1::-webkit-scrollbar-track {
    background: var(--background-color);
    border-radius: 4px;
    margin: 2px;
}

.area1::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 4px;
}

.area1::-webkit-scrollbar-thumb:hover {
    background: var(--secondary-color);
}

.control-group {
    width: calc(50% - 4px - 4px);
    margin-bottom: 8px;
    min-width: 100px;
}

.control-group:has(#bg-image),
.control-group:has(#bg-fit),
.control-group:has(#clear-bg),
.control-group:has(textarea) {
    width: 100%;
}

label {
    display: block;
    margin-bottom: 3px;
    font-size: 12px;
    color: #555;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

input[type="number"],
select,
input[type="color"],
input[type="text"],
input[type="range"] {
    width: 100%;
    padding: 4px 6px;
    border-radius: 5px;
    border: 1px solid #ccc;
    font-size: 12px;
    box-sizing: border-box;
}

input[type="number"] {
    -moz-appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input:focus {
    box-shadow: 0 0 5px var(--primary-color);
}

.area5 {
    display: flex;
    justify-content: space-between;
    align-items: stretch;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    padding: 10px;
    box-sizing: border-box;
    flex-wrap: wrap;
    box-shadow: 0 2px 4px var(--shadow-color);
}

.preview-area {
    width: 100%;
    max-width: 60%;
    height: 250px;
    overflow: auto;
    border: 1px solid #ccc;
    border-radius: 5px;
    box-sizing: border-box;
    margin-bottom: 15px;
    box-shadow: 0 2px 4px var(--shadow-color);
    display: flex;
    align-items: center;
    justify-content: center;
}

#canvas {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.area6 {
    width: 100%;
    max-width: 35%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.button-group {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
}

.link-group {
    margin-bottom: 10px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.link-group input {
    cursor: pointer;
}

footer {
    margin-top: 15px;
    text-align: center;
}

footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-size: 14px;
}

footer a:hover {
    text-decoration: underline;
}

@media (max-width: 768px) {
    .area2, .area5 {
        flex-direction: column;
        align-items: center;
    }

    .area3, .area1, .preview-area, .area6 {
        max-width: 100%;
    }

    button {
        width: 100%;
    }

    .control-group {
        width: 100%;
    }
    
    .button-group button {
        margin-bottom: 10px;
    }

    .area1 {
        padding-right: 10px;
    }
}

.loading {
    cursor: wait;
    opacity: 0.7;
}

// 添加错误提示样式
.error-message {
    color: #ff4444;
    font-size: 12px;
    margin-top: 5px;
}

// 添加加载状态指示器样式
.loading-indicator {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 10px 20px;
    border-radius: 5px;
    display: none;
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0);
    z-index: 1000;
    transition: background-color 0.3s ease;
    cursor: zoom-out;
}

.modal.show {
    background-color: rgba(0, 0, 0, 0.85);
}

.modal-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.95);
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
    width: 800px;
    max-width: 90vw;
    border-radius: 4px;
    overflow: hidden;
}

.modal.show .modal-content {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
}

.modal-content canvas {
    background-color: white;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.3);
    width: 100%;
    height: auto;
    display: block;
}

#preview-canvas {
    cursor: zoom-in;
    transition: transform 0.2s ease;
}

#preview-canvas:hover {
    transform: scale(1.02);
}

.modal-close {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s;
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.modal-hint {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
    opacity: 0;
    transition: opacity 0.3s;
}

.modal.show .modal-hint {
    opacity: 1;
}

/* 为文件上传按钮添加样式 */
input[type="file"] {
    width: 100%;
    padding: 4px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    font-size: 12px;
}

/* 小按钮样式 */
.small-btn {
    padding: 4px 8px;
    font-size: 12px;
    width: 100%;
    margin-top: 0;
}

/* 确保背景图片控制组占据整行 */
.control-group:has(#bg-image),
.control-group:has(#bg-fit),
.control-group:has(#clear-bg) {
    width: 100%;
}

/* 特定控制组占据整行 */
.control-group:has(#bg-image),
.control-group:has(#bg-fit),
.control-group:has(#clear-bg),
.control-group:has(textarea) {
    width: 100%;
}

/* 建议的控制组配对顺序 */
.control-group:nth-child(odd) {
    margin-right: 4px;
}

.input-with-unit {
    position: relative;
}

.input-with-unit input[type="number"] {
    padding-right: 20px; /* 为百分号预留空间 */
}

.input-with-unit::after {
    content: '%';
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 12px;
    color: #555;
}
