@font-face {
    font-family: 'LiciumFont2022';
    src: url('fonts/LiciumFont2022-Light.woff2') format('woff2');
    font-weight: 300;
    font-style: normal;
}
@font-face {
    font-family: 'LiciumFont2022';
    src: url('fonts/LiciumFont2022-Normal.woff2') format('woff2');
    font-weight: 400;
    font-style: normal;
}
@font-face {
    font-family: 'LiciumFont2022';
    src: url('fonts/LiciumFont2022-Regular.woff2') format('woff2');
    font-weight: 500;
    font-style: normal;
}
@font-face {
    font-family: 'LiciumFont2022';
    src: url('fonts/LiciumFont2022-Medium.woff2') format('woff2');
    font-weight: 600;
    font-style: normal;
}
@font-face {
    font-family: 'LiciumFont2022';
    src: url('fonts/LiciumFont2022-Bold.woff2') format('woff2');
    font-weight: 700;
    font-style: normal;
}

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

:root {
    --bg: #f0ebe3;
    --sidebar-bg: #1a1a2e;
    --sidebar-text: #ddd;
    --accent: #e8a87c;
    --accent-hover: #d4936a;
    --input-bg: #252545;
    --border: #3a3a5c;
    --radius: 8px;
    --shadow: 0 4px 24px rgba(0,0,0,0.15);
}

html, body {
    height: 100%;
    font-family: -apple-system, "Microsoft YaHei", "PingFang SC", "Noto Sans SC", sans-serif;
    background: var(--bg);
    color: #333;
    overflow: hidden;
    -webkit-text-size-adjust: 100%;
}

.app {
    display: flex;
    height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
    width: 380px;
    min-width: 380px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 16px rgba(0,0,0,0.1);
    z-index: 10;
}

.sidebar-header {
    padding: 24px 24px 16px;
    border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
    font-size: 22px;
    font-weight: 700;
    color: #fff;
    letter-spacing: 1px;
}

.sidebar-header .subtitle {
    font-size: 13px;
    color: #888;
    margin-top: 4px;
}

.sidebar-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 24px;
}

.sidebar-body::-webkit-scrollbar { width: 4px; }
.sidebar-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.section {
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.section:last-of-type {
    border-bottom: none;
}

.section-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* ---- Upload ---- */
.upload-area {
    position: relative;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    min-height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.upload-area:hover {
    border-color: var(--accent);
    background: rgba(232,168,124,0.05);
}

.upload-area.dragover {
    border-color: var(--accent);
    background: rgba(232,168,124,0.12);
}

.upload-placeholder {
    text-align: center;
    padding: 24px;
}

.upload-placeholder p {
    margin-top: 8px;
    font-size: 14px;
    color: #999;
}

.upload-hint {
    font-size: 11px;
    color: #666;
    display: block;
    margin-top: 4px;
}

.upload-preview {
    position: relative;
    width: 100%;
    padding: 8px;
}

.upload-preview img {
    width: 100%;
    max-height: 100px;
    object-fit: cover;
    border-radius: 4px;
    display: block;
}

.btn-icon {
    position: absolute;
    top: 12px;
    right: 12px;
    background: rgba(0,0,0,0.6);
    border: none;
    color: #fff;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.btn-icon:hover { background: rgba(0,0,0,0.85); }
/* ---- Text Library ---- */
.text-save-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 8px;
    gap: 8px;
}

.text-save-hint {
    font-size: 12px;
    color: #888;
    flex: 1;
    line-height: 1.5;
}

.btn-save-text {
    background: var(--accent);
    color: #1a1a2e;
    border: none;
    padding: 4px 12px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
}

.btn-save-text:hover {
    background: var(--accent-hover);
}

.text-library {
    max-height: 180px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.text-library::-webkit-scrollbar { width: 3px; }
.text-library::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.text-lib-item {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    padding: 6px 8px;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
}

.text-lib-item:hover {
    border-color: var(--accent);
    background: #2a2a4a;
}

.text-lib-content {
    flex: 1;
    font-size: 12px;
    line-height: 1.5;
    color: #ccc;
    word-break: break-all;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.text-lib-item .del-btn {
    flex: 0 0 18px;
    width: 18px;
    height: 18px;
    background: transparent;
    border: none;
    color: #666;
    font-size: 14px;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s, background 0.15s;
    margin-top: 1px;
}

.text-lib-item:hover .del-btn {
    opacity: 1;
}

.text-lib-item .del-btn:hover {
    color: #fff;
    background: rgba(200,60,60,0.7);
}

.text-lib-empty {
    text-align: center;
    color: #555;
    font-size: 12px;
    padding: 12px 0;
}

/* ---- Template Library ---- */
.template-save-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.template-name-input {
    flex: 1;
    min-width: 0;
    font-size: 12px;
    padding: 6px 10px;
}

.btn-save-template {
    background: var(--accent);
    color: #1a1a2e;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}

.btn-save-template:hover {
    background: var(--accent-hover);
}

.template-library {
    max-height: 220px;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.template-library::-webkit-scrollbar { width: 3px; }
.template-library::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.template-item {
    position: relative;
    aspect-ratio: 0.75;
    border-radius: 4px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color 0.2s, opacity 0.2s;
    background: var(--input-bg);
    display: flex;
    flex-direction: column;
}

.template-item:hover {
    border-color: rgba(232,168,124,0.4);
}

.template-thumb {
    flex: 1;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255,255,255,0.6);
    font-size: 10px;
    overflow: hidden;
}

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

.template-name {
    padding: 4px 6px;
    font-size: 11px;
    color: #ccc;
    background: rgba(0,0,0,0.4);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.template-item .del-btn {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 20px;
    height: 20px;
    background: rgba(0,0,0,0.55);
    border: none;
    color: #fff;
    border-radius: 50%;
    font-size: 10px;
    line-height: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 2;
}

.template-item:hover .del-btn {
    opacity: 1;
}

.template-item .del-btn:hover {
    background: rgba(200,60,60,0.8);
}

.template-item.default-template {
    border-color: rgba(232,168,124,0.5);
}

.template-lock {
    position: absolute;
    top: 4px;
    left: 4px;
    background: rgba(0,0,0,0.65);
    color: #fff;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 3px;
    z-index: 2;
}

.template-empty {
    grid-column: 1 / -1;
    text-align: center;
    color: #555;
    font-size: 12px;
    padding: 16px 0;
}

/* ---- Background Gallery ---- */
.bg-gallery {
    margin-top: 14px;
}

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

.gallery-title {
    font-size: 12px;
    color: #888;
    font-weight: 500;
}

.btn-add-gallery {
    background: var(--accent);
    color: #1a1a2e;
    border: none;
    padding: 3px 10px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-add-gallery:hover {
    background: var(--accent-hover);
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    max-height: 180px;
    overflow-y: auto;
    padding: 2px;
}

.gallery-grid::-webkit-scrollbar { width: 3px; }
.gallery-grid::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.gallery-item {
    position: relative;
    aspect-ratio: 0.75;
    border-radius: 4px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color 0.2s, opacity 0.2s;
    background: var(--input-bg);
}

.gallery-item:hover {
    border-color: rgba(232,168,124,0.4);
}

.gallery-item.selected {
    border-color: var(--accent);
    box-shadow: 0 0 8px rgba(232,168,124,0.25);
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.gallery-item .del-btn {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 20px;
    height: 20px;
    background: rgba(0,0,0,0.55);
    border: none;
    color: #fff;
    border-radius: 50%;
    font-size: 10px;
    line-height: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.15s;
}

.gallery-item:hover .del-btn {
    opacity: 1;
}

.gallery-item .del-btn:hover {
    background: rgba(200,60,60,0.8);
}

.gallery-empty {
    grid-column: 1 / -1;
    text-align: center;
    color: #555;
    font-size: 12px;
    padding: 16px 0;
}

/* ---- Form elements ---- */
.input, .textarea, .select {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: #eee;
    padding: 10px 14px;
    font-size: 15px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
    -webkit-appearance: none;
    appearance: none;
    -webkit-border-radius: var(--radius);
    touch-action: manipulation;
}

.input:focus, .textarea:focus, .select:focus {
    border-color: var(--accent);
}

.textarea {
    resize: vertical;
    min-height: 60px;
    line-height: 1.5;
}

.input::placeholder, .textarea::placeholder {
    color: #666;
}

.select {
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
    min-height: 40px;
}

.select option { background: #1a1a2e; }

.style-row {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    flex-wrap: wrap;
}

.style-group {
    flex: 1;
    min-width: 0;
}

.style-group label {
    display: block;
    font-size: 11px;
    color: #888;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.style-group:has(.color-picker) {
    flex: 0 0 auto;
}

.range {
    width: 100%;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--border);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

.range::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 2px solid var(--sidebar-bg);
}

.range::-webkit-slider-thumb:active {
    transform: scale(1.2);
}

.color-picker {
    width: 40px;
    height: 40px;
    padding: 2px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--input-bg);
    cursor: pointer;
}

.btn-toggle {
    width: 36px;
    height: 32px;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: #888;
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-toggle[data-active="true"] {
    background: var(--accent);
    color: #1a1a2e;
    border-color: var(--accent);
}

.align-group {
    display: flex;
    gap: 2px;
}

.btn-align {
    width: 32px;
    height: 32px;
    background: var(--input-bg);
    border: 1px solid var(--border);
    color: #888;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-align:first-child { border-radius: 4px 0 0 4px; }
.btn-align:last-child { border-radius: 0 4px 4px 0; }

.btn-align.active {
    background: var(--accent);
    color: #1a1a2e;
    border-color: var(--accent);
}

/* ---- Footer ---- */
.sidebar-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
}

.btn-primary, .btn-secondary {
    flex: 1;
    padding: 12px 16px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    touch-action: manipulation;
}

.btn-primary {
    background: var(--accent);
    color: #1a1a2e;
}

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

.btn-primary:active {
    transform: scale(0.97);
    opacity: 0.9;
}

.btn-secondary {
    background: var(--input-bg);
    color: #999;
    border: 1px solid var(--border);
    flex: 0 0 auto;
    padding: 12px 14px;
}

.btn-secondary:hover {
    background: #2a2a4a;
    color: #ccc;
}

.btn-secondary:active {
    transform: scale(0.97);
    opacity: 0.9;
}

/* ---- Preview ---- */
.preview-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
    position: relative;
}

.canvas-wrapper {
    position: relative;
    max-width: 100%;
    max-height: 100%;
    box-shadow: var(--shadow);
    border-radius: 4px;
    overflow: hidden;
    touch-action: none;
}

#posterCanvas {
    display: block;
    max-width: 100%;
    max-height: calc(100vh - 64px);
    cursor: default;
    touch-action: none;
    transition: box-shadow 0.2s;
}

#posterCanvas.dragging {
    box-shadow: 0 0 0 3px var(--accent);
}

.drag-hint {
    position: absolute;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.55);
    color: #ccc;
    font-size: 12px;
    padding: 6px 16px;
    border-radius: 12px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.4s;
}

.drag-hint.visible {
    opacity: 1;
}

/* ---- Responsive ---- */
@media (max-width: 820px) {
    html, body {
        height: auto;
        min-height: 100%;
        overflow-y: auto;
    }
    .app {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }
    .sidebar {
        width: 100%;
        min-width: 0;
        max-height: none;
        flex: none;
    }
    .sidebar-body {
        max-height: none;
        padding: 10px 14px;
    }
    .preview-area {
        padding: 10px;
        min-height: 300px;
        flex: none;
        justify-content: flex-start;
    }
    .canvas-wrapper {
        width: 100%;
        max-width: 100%;
    }
    .preview-area canvas {
        max-width: 100%;
        max-height: calc(100vh - 400px);
        display: block;
    }
    .sidebar-footer {
        padding: 10px 14px;
        position: relative;
        bottom: auto;
        background: var(--sidebar-bg);
        border-top: 1px solid var(--border);
    }
    .sidebar-footer .btn-primary,
    .sidebar-footer .btn-secondary {
        flex: 1;
        padding: 14px 16px;
        font-size: 15px;
    }
}

@media (max-width: 480px) {
    html, body {
        font-size: 15px;
    }
    .sidebar-body {
        padding: 8px 12px;
    }
    .sidebar-header {
        padding: 12px;
    }
    .sidebar-header h1 {
        font-size: 18px;
    }
    .sidebar-header .subtitle {
        font-size: 11px;
    }
    .section {
        padding: 10px 0;
    }
    .section-title {
        font-size: 13px;
        margin-bottom: 8px;
    }
    .input, .textarea {
        padding: 10px 12px;
        font-size: 15px;
    }
    .textarea {
        min-height: 50px;
    }
    .select {
        padding: 10px 12px;
        font-size: 14px;
        min-height: 40px;
    }
    .range {
        width: 100%;
        height: 40px;
        padding: 0;
    }
    .style-row {
        flex-wrap: wrap;
        gap: 6px;
    }
    .style-group {
        min-width: 60px;
        flex: 1 1 45%;
    }
    .style-group label {
        font-size: 11px;
        margin-bottom: 3px;
    }
    .btn-toggle {
        width: 40px;
        height: 40px;
        font-size: 15px;
    }
    .btn-align {
        padding: 8px 10px;
        font-size: 13px;
        min-width: 40px;
    }
    .sidebar-footer {
        padding: 10px;
        gap: 8px;
    }
    .sidebar-footer .btn-primary,
    .sidebar-footer .btn-secondary {
        padding: 12px;
        font-size: 14px;
        min-height: 44px;
    }
    .gallery-item {
        width: calc(50% - 5px);
        height: 70px;
    }
    .template-item {
        flex: 0 0 calc(50% - 5px);
        height: 60px;
    }
    .btn-small {
        padding: 6px 10px;
        font-size: 11px;
        min-width: 40px;
        min-height: 32px;
    }
    .drag-hint {
        font-size: 11px;
        padding: 5px 12px;
    }
    .upload-area {
        padding: 14px;
        min-height: 60px;
    }
}

.wx-preview-mask {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.85);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.wx-preview-mask.active { display: flex; }
.wx-preview-inner {
    position: relative;
    max-width: 100%;
    max-height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}
.wx-preview-inner img {
    max-width: 100%;
    max-height: calc(100vh - 120px);
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
.wx-preview-tip {
    color: #fff;
    font-size: 15px;
    margin: 0;
    text-align: center;
    opacity: 0.9;
}
.wx-preview-close {
    padding: 10px 32px;
    background: rgba(255,255,255,0.15);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 20px;
    font-size: 14px;
    cursor: pointer;
}
