/* ===== Base Reset ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #f97316;
    --primary-light: #fff7ed;
    --primary-hover: #ea580c;
    --accent: #8b5cf6;
    --accent-hover: #7c3aed;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --border: #e5e7eb;
    --bg: #f3f4f6;
    --white: #ffffff;
    --danger: #ef4444;
    --danger-light: #fef2f2;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 25px -3px rgba(0,0,0,0.15);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --transition: all 0.2s ease;
}

/* 本地字体声明 */
@font-face {
    font-family: 'Archivo Black';
    src: url('../assets/fonts/Sans Serif/archivo-black-v23-latin-regular.woff2') format('woff2');
}
@font-face {
    font-family: 'DM Sans';
    src: url('../assets/fonts/Sans Serif/dm-sans-v17-latin-regular.woff2') format('woff2');
}
@font-face {
    font-family: 'Merriweather';
    src: url('../assets/fonts/Serif/merriweather-v33-latin-regular.woff2') format('woff2');
}
@font-face {
    font-family: 'Cormorant Garamond';
    src: url('../assets/fonts/Serif/cormorant-garamond-v21-latin-regular.woff2') format('woff2');
}
@font-face {
    font-family: 'Oswald';
    src: url('../assets/fonts/Display/oswald-v57-latin-regular.woff2') format('woff2');
}
@font-face {
    font-family: 'Anton';
    src: url('../assets/fonts/Display/anton-v27-latin-regular.woff2') format('woff2');
}
@font-face {
    font-family: 'Caveat';
    src: url('../assets/fonts/Script/caveat-v23-latin-regular.woff2') format('woff2');
}
@font-face {
    font-family: 'Meie Script';
    src: url('../assets/fonts/Script/meie-script-v22-latin-regular.woff2') format('woff2');
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text-primary);
    overflow: hidden;
    user-select: none;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-header {
    height: 56px;
    background: var(--white);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    position: relative;
    z-index: 20;
    flex-shrink: 0;
}
.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
}
.logo-img {
    width: 100px;
    height: 38px;
    object-fit: contain;
}
.header-center {
    display: flex;
    align-items: center;
    gap: 10px;
}
.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}
.btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    border: none;
    font-size: 13px;
    cursor: pointer;
    text-decoration: none;
    transition: var(--transition);
    white-space: nowrap;
}
.btn i {
    width: 15px;
    height: 15px;
}
.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}
.btn-ghost:hover {
    background: var(--bg);
    color: var(--text-primary);
}
.btn-accent {
    background: var(--accent);
    color: white;
    border: none;
    font-weight: 600;
}
.btn-accent:hover {
    background: var(--accent-hover);
    color: white;
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.editor-layout {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.sidebar {
    width: 224px;
    background: var(--white);
    border-right: 1px solid var(--border);
    padding: 10px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
    scrollbar-width: thin;
    z-index: 10;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.sidebar-section { display: flex; flex-direction: column; gap: 5px; position: relative; }
.section-title {
    font-size: 10px;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    margin-bottom: 1px;
    padding: 0 2px;
}
.btn-group { display: flex; flex-direction: column; gap: 4px; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.btn-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 4px; }

.tool-btn {
    display: flex;
    align-items: center;
    gap: 7px;
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--white);
    font-size: 12px;
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition);
    text-align: left;
    white-space: nowrap;
    position: relative;
}
.tool-btn:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}
.tool-btn:active { transform: translateY(0); }
.tool-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn-icon { width: 16px; height: 16px; flex-shrink: 0; }
.chevron-icon { width: 12px; height: 12px; margin-left: auto; }

.btn-primary { background: var(--primary); color: white; border-color: var(--primary); justify-content: center; font-weight: 600; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-secondary { background: var(--white); color: var(--text-primary); border-color: var(--border); justify-content: center; font-weight: 500; }
.btn-secondary:hover { background: var(--bg); border-color: var(--primary); color: var(--primary); }
.btn-danger { color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: var(--danger-light); border-color: var(--danger); }
.btn-block { justify-content: center; }
.btn-sm { padding: 6px 8px; font-size: 11px; gap: 4px; }
.btn-sm .btn-icon { width: 13px; height: 13px; }

.export-btn-enhanced {
    padding: 12px 14px;
    font-size: 14px;
    font-weight: 700;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--primary) 0%, #fb923c 100%);
    box-shadow: 0 2px 8px rgba(249,115,22,0.3);
    transition: all 0.3s ease;
}
.export-btn-enhanced:hover {
    background: linear-gradient(135deg, var(--primary-hover) 0%, #f97316 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(249,115,22,0.4);
}

.export-popup {
    display: none;
    position: absolute;
    left: 0;
    top: calc(100% + 4px);
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 6px 0;
    z-index: 111;
    width: 200px;
}
.export-popup.active { display: block; }
.export-option { display: flex; align-items: center; gap: 8px; padding: 9px 14px; cursor: pointer; font-size: 12px; color: var(--text-primary); transition: var(--transition); }
.export-option:hover { background: var(--primary-light); color: var(--primary); }
.export-option i { width: 15px; height: 15px; flex-shrink: 0; }
.export-divider { height: 1px; background: var(--border); margin: 4px 0; }

.shape-btn-wrapper { position: relative; }
.shape-popup {
    display: none;
    position: absolute;
    left: 0;
    top: calc(100% + 4px);
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 10px 12px;
    z-index: 110;
    width: 205px;
    max-height: 600px;
    overflow-y: auto;
}
.shape-popup.active { display: block; }
.shape-popup::-webkit-scrollbar { width: 4px; }
.shape-popup::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.shape-category-title {
    font-size: 10px; font-weight: 700; color: var(--text-secondary);
    text-transform: uppercase; letter-spacing: 0.6px;
    padding: 8px 0 4px 2px; border-bottom: 1px solid var(--border); margin-bottom: 6px;
}
.shape-category-title:first-of-type { padding-top: 0; }
.shape-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; margin-bottom: 6px; }
.shape-item {
    aspect-ratio: 1/1; border: 2px solid var(--border); border-radius: var(--radius-sm);
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    background: #fafafa; transition: var(--transition); padding: 5px; max-width: 50px; max-height: 50px;
}
.shape-item:hover { border-color: var(--primary); background: var(--primary-light); transform: scale(1.06); box-shadow: var(--shadow-sm); }
.shape-item svg { width: 80%; height: 80%; pointer-events: none; display: block; max-width: 38px; max-height: 38px; }

.canvas-area {
    position: relative; flex: 1; display: flex; justify-content: center; align-items: center;
    background: #e5e7eb; padding: 20px; overflow: hidden; min-width: 0;
}
.canvas-zoom-controls {
    position: absolute; top: 8px; left: 12px; display: flex; align-items: center; gap: 2px;
    background: rgba(255,255,255,0.95); border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 4px 6px; z-index: 50; box-shadow: var(--shadow-sm);
}
.canvas-layer-controls {
    position: absolute; top: 8px; right: 12px; display: flex; align-items: center; gap: 2px;
    background: rgba(255,255,255,0.95); border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 4px 6px; z-index: 50; box-shadow: var(--shadow-sm);
}
.zoom-btn {
    width: 28px; height: 28px; border: none; background: transparent; border-radius: 4px;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: var(--transition); color: var(--text-secondary);
}
.zoom-btn:hover { background: var(--bg); color: var(--primary); }
.zoom-value { font-size: 11px; font-weight: 600; color: var(--text-primary); min-width: 40px; text-align: center; }
.canvas-wrapper {
    background: var(--white);
    border-radius: 4px;
    box-shadow: var(--shadow-md);
    flex-shrink: 0;
    position: relative;
    transition: background 0.3s ease;
}
.canvas-wrapper.transparent-bg {
    background-image: linear-gradient(45deg, #d0d0d0 25%, transparent 25%, transparent 75%, #d0d0d0 75%, #d0d0d0),
        linear-gradient(45deg, #d0d0d0 25%, transparent 25%, transparent 75%, #d0d0d0 75%, #d0d0d0);
    background-size: 20px 20px;
    background-position: 0 0, 10px 10px;
    background-color: #f0f0f0;
}
.canvas-container { margin: 0 auto !important; border-radius: 4px; overflow: hidden; }
.canvas-container canvas { display: block; }

/* 物体操作按钮 - 紧贴物体右上角，竖排 */
.obj-action-btn {
    position: absolute;
    width: 20px;
    height: 20px;
    border-radius: 4px;
    background: white;
    border: 1px solid var(--border);
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    z-index: 60;
    transition: all 0.15s ease;
    padding: 0;
    color: var(--text-secondary);
}
.obj-action-btn:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
    transform: scale(1.1);
}
.obj-delete-btn { color: var(--danger); }
.obj-delete-btn:hover { background: #fee2e2; border-color: var(--danger); color: var(--danger); }
.obj-copy-btn { color: #6366f1; }
.obj-copy-btn:hover { background: #e0e7ff; border-color: #6366f1; }

/* 其他控件保持不变 */
.number-input { flex: 1; padding: 6px 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 11px; outline: none; min-width: 0; }
.number-input:focus { border-color: var(--primary); }
.size-separator { color: var(--text-secondary); font-size: 12px; flex-shrink: 0; }
.select-input { padding: 7px 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 11px; background: var(--white); cursor: pointer; outline: none; width: 100%; }
.select-input:focus { border-color: var(--primary); }
.color-input { width: 100%; height: 30px; border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; background: var(--white); padding: 2px; }
.form-group { display: flex; flex-direction: column; gap: 3px; }
.form-group label { font-size: 11px; color: var(--text-secondary); font-weight: 500; }

.settings-panel {
    width: 260px; background: var(--white); border-left: 1px solid var(--border);
    padding: 14px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px;
    flex-shrink: 0; scrollbar-width: thin;
}
.settings-panel::-webkit-scrollbar { width: 4px; }
.settings-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.panel-section { display: flex; flex-direction: column; gap: 10px; }
.panel-tip { font-size: 12px; color: var(--text-secondary); padding: 10px; background: var(--bg); border-radius: var(--radius-sm); text-align: center; }
.sub-title { font-size: 12px; font-weight: 600; color: var(--text-primary); margin-bottom: -2px; }
.range-input {
    width: 100%; height: 4px; border-radius: 2px; background: var(--border);
    outline: none; cursor: pointer; -webkit-appearance: none; appearance: none;
}
.range-input::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; background: var(--primary); cursor: pointer; }
.range-value { font-size: 11px; color: var(--text-secondary); text-align: right; }
.align-buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; }
.align-btn { padding: 7px 0; border: 1px solid var(--border); background: var(--white); border-radius: var(--radius-sm); cursor: pointer; display: flex; align-items: center; justify-content: center; transition: var(--transition); }
.align-btn i { width: 13px; height: 13px; }
.align-btn:hover { border-color: var(--primary); color: var(--primary); }
.align-btn.active { background: var(--primary); color: white; border-color: var(--primary); }

.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 1000; align-items: center; justify-content: center; }
.modal-overlay.active { display: flex; }
.modal-dialog { background: var(--white); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); width: 90vw; max-width: 820px; max-height: 85vh; display: flex; flex-direction: column; overflow: hidden; }
.modal-dialog-sm { max-width: 440px; }
.modal-dialog-md { max-width: 520px; }
.modal-dialog-drop { max-width: 480px; }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-close { width: 32px; height: 32px; border-radius: 50%; border: none; background: var(--bg); cursor: pointer; display: flex; align-items: center; justify-content: center; transition: var(--transition); }
.modal-close:hover { background: #e5e7eb; color: var(--danger); }

.drop-zone {
    margin: 16px 24px; border: 2px dashed var(--border); border-radius: var(--radius-lg);
    padding: 30px 20px; text-align: center; background: #fafafa;
    transition: all 0.3s ease; cursor: pointer;
}
.drop-zone.drag-over { border-color: var(--primary); background: var(--primary-light); box-shadow: 0 0 0 4px rgba(249,115,22,0.1); }
.drop-zone-icon { margin-bottom: 12px; }
.drop-zone-title { font-weight: 600; font-size: 16px; color: var(--text-primary); margin-bottom: 4px; }
.drop-zone-subtitle { font-size: 13px; color: var(--text-secondary); margin-bottom: 8px; }
.drop-zone-hint { font-size: 11px; color: #9ca3af; margin-top: 12px; }
.drop-preview-row { display: flex; gap: 8px; padding: 0 24px; overflow-x: auto; margin-top: 8px; }
.drop-preview-thumb { width: 60px; height: 60px; border-radius: 8px; object-fit: cover; border: 2px solid var(--border); flex-shrink: 0; }

.asset-search { padding: 12px 16px; border-bottom: 1px solid #e5e7eb; }
.asset-search input { width: 100%; height: 38px; padding: 0 14px; border: 1px solid #d1d5db; border-radius: 8px; font-size: 14px; outline: none; box-sizing: border-box; }
.asset-search input:focus { border-color: #6366f1; }
.modal-tabs { display: flex; gap: 2px; padding: 10px 16px; border-bottom: 1px solid var(--border); flex-shrink: 0; flex-wrap: wrap; }
.modal-tab { padding: 7px 14px; border: none; background: transparent; border-radius: 20px; cursor: pointer; font-size: 12px; font-weight: 500; color: var(--text-secondary); transition: var(--transition); }
.modal-tab:hover { background: var(--bg); color: var(--text-primary); }
.modal-tab.active { background: var(--primary); color: white; }
.modal-body { flex: 1; overflow-y: auto; padding: 16px; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; align-content: start; }
.modal-body-collage { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-body-removebg { padding: 20px; display: flex; flex-direction: column; gap: 14px; align-items: center; }

.template-card { border: 2px solid var(--border); border-radius: var(--radius-md); cursor: pointer; transition: var(--transition); overflow: hidden; background: #fafafa; }
.template-card:hover { border-color: var(--primary); box-shadow: var(--shadow-md); transform: translateY(-2px); }
.template-thumb { width: 100%; aspect-ratio: 1/1; background: #f0f0f0; display: flex; align-items: center; justify-content: center; overflow: hidden; padding: 6px; }
.template-thumb img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.template-thumb svg { width: 100%; height: 100%; pointer-events: none; }
.template-info { padding: 8px 10px; text-align: center; border-top: 1px solid var(--border); }
.template-name { font-size: 11px; font-weight: 600; color: var(--text-primary); }
.template-cat { font-size: 10px; color: var(--text-secondary); }
.template-tags { font-size: 9px; color: #9ca3af; margin-top: 2px; }
.premium-lock { font-size: 10px; color: #f59e0b; margin-top: 3px; font-weight: 600; }

.loading-dialog { background: var(--white); border-radius: var(--radius-lg); padding: 40px 50px; text-align: center; box-shadow: var(--shadow-lg); }
.loading-dialog p { margin-top: 16px; font-size: 14px; color: var(--text-secondary); }
.spinner { width: 40px; height: 40px; border: 4px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }

.removebg-preview-wrapper { position: relative; width: 200px; height: 200px; border: 2px dashed var(--border); border-radius: var(--radius-md); overflow: hidden; display: flex; align-items: center; justify-content: center; background-image: linear-gradient(45deg, #e0e0e0 25%, transparent 25%, transparent 75%, #e0e0e0 75%, #e0e0e0), linear-gradient(45deg, #e0e0e0 25%, transparent 25%, transparent 75%, #e0e0e0 75%, #e0e0e0); background-size: 20px 20px; background-position: 0 0, 10px 10px; background-color: #f5f5f5; }
.removebg-preview-wrapper img { max-width: 100%; max-height: 100%; object-fit: contain; position: relative; z-index: 1; }
.bg-option-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: center; }
.bg-radio-label { display: flex; align-items: center; gap: 5px; font-size: 12px; cursor: pointer; padding: 6px 12px; border: 2px solid var(--border); border-radius: var(--radius-sm); transition: var(--transition); background: var(--white); }
.bg-radio-label:hover { border-color: var(--primary); }
.bg-radio-label.active-bg-option { border-color: var(--primary); background: var(--primary-light); color: var(--primary); font-weight: 600; }
.bg-radio-label input { display: none; }

.app-footer { height: 36px; background: var(--white); border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: center; font-size: 11px; color: var(--text-secondary); flex-shrink: 0; }

.checkbox-label { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-secondary); cursor: pointer; font-weight: 500; }
.checkbox-label input[type="checkbox"] { width: 15px; height: 15px; cursor: pointer; accent-color: var(--primary); }
.custom-size-row { display: flex; gap: 4px; align-items: center; }

@media (max-width: 1200px) {
    .sidebar { width: 190px; padding: 8px; gap: 6px; }
    .tool-btn { padding: 7px 8px; font-size: 11px; gap: 5px; }
    .btn-icon { width: 14px; height: 14px; }
    .settings-panel { width: 220px; padding: 10px; }
    .shape-popup { width: 220px; }
}
@media (max-width: 900px) {
    .editor-layout { flex-direction: column; height: auto; min-height: calc(100vh - 56px - 36px); }
    .sidebar { width: 100%; flex-direction: row; flex-wrap: wrap; gap: 6px; border-right: none; border-bottom: 1px solid var(--border); }
    .sidebar-section { flex: 1; min-width: 140px; }
    .canvas-area { padding: 12px; min-height: 350px; }
    .settings-panel { width: 100%; flex-direction: row; flex-wrap: wrap; gap: 10px; border-left: none; border-top: 1px solid var(--border); }
    .shape-popup { left: auto; right: 0; width: 200px; }
    .canvas-layer-controls { top: 44px; right: 12px; }
}