/* ==================== 变量 & 容器 ==================== */
.wpo-app {
    --wpo-gold: #b08d57;
    --wpo-gold-dark: #6b5024;
    --wpo-gold-light: #e5dcc8;
    --wpo-paper: #fffdf8;
    --wpo-bg: #faf8f3;
    --wpo-text: #2b2b2b;

    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
    color: var(--wpo-text);
}

/* ==================== 表单卡片 ==================== */
.wpo-card {
    background: #fff;
    border: 1px solid var(--wpo-gold-light);
    border-radius: 10px;
    padding: 36px 40px;
    box-shadow: 0 6px 28px rgba(0,0,0,.06);
}
.wpo-form-title {
    text-align: center;
    font-size: 26px;
    color: var(--wpo-gold-dark);
    letter-spacing: 8px;
    text-indent: 8px;
    margin: 0 0 10px;
    font-weight: 600;
}
.wpo-form-sub {
    text-align: center;
    color: #999;
    font-size: 14px;
    margin: 0 0 28px;
    padding-bottom: 22px;
    border-bottom: 1px dashed var(--wpo-gold-light);
}

#wpo-form .wpo-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px 22px;
    margin-bottom: 18px;
}
#wpo-form label {
    display: block;
    font-size: 14px;
    color: var(--wpo-gold-dark);
    font-weight: 600;
}
#wpo-form .wpo-full { margin-bottom: 18px; }
#wpo-form .req { color: #c62828; }

#wpo-form input[type=text],
#wpo-form input[type=date],
#wpo-form input[type=datetime-local],
#wpo-form input[type=file],
#wpo-form textarea {
    display: block;
    width: 100%;
    margin-top: 7px;
    padding: 10px 13px;
    border: 1px solid #ddd3bd;
    border-radius: 6px;
    background: #fff;
    font-size: 14px;
    font-family: inherit;
    color: var(--wpo-text);
    transition: border-color .2s, box-shadow .2s;
    box-sizing: border-box;
}
#wpo-form input[type=date],
#wpo-form input[type=datetime-local] {
    -webkit-appearance: none;
    appearance: none;
}
#wpo-form input[type=file] { padding: 8px 10px; background: #faf8f3; }

#wpo-form input:focus,
#wpo-form textarea:focus {
    outline: none;
    border-color: var(--wpo-gold);
    box-shadow: 0 0 0 3px rgba(176,141,87,.15);
}
#wpo-form input[type=date]::-webkit-calendar-picker-indicator,
#wpo-form input[type=datetime-local]::-webkit-calendar-picker-indicator {
    cursor: pointer;
    opacity: .55;
}
#wpo-form input[type=date]::-webkit-calendar-picker-indicator:hover,
#wpo-form input[type=datetime-local]::-webkit-calendar-picker-indicator:hover {
    opacity: 1;
}

#wpo-form textarea { resize: vertical; line-height: 1.7; }

.wpo-actions {
    text-align: center;
    margin-top: 28px;
    padding-top: 22px;
    border-top: 1px dashed var(--wpo-gold-light);
}

/* ==================== 遗像裁剪区 ==================== */
.wpo-crop-area {
    margin-top: 14px;
    padding: 18px;
    background: #faf8f3;
    border: 1px solid var(--wpo-gold-light);
    border-radius: 10px;
}
.wpo-crop-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}
.wpo-crop-title {
    font-size: 14px;
    color: var(--wpo-gold-dark);
    font-weight: 700;
    letter-spacing: 1px;
}
.wpo-crop-reset {
    background: none;
    border: 1px solid var(--wpo-gold-light);
    color: var(--wpo-gold-dark);
    font-size: 12px;
    padding: 4px 12px;
    border-radius: 4px;
    cursor: pointer;
    transition: all .2s;
}
.wpo-crop-reset:hover { background: #fff; }

.wpo-crop-body {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    flex-wrap: wrap;
}

.wpo-crop-stage {
    position: relative;
    width: 240px;
    height: 308px;
    border-radius: 6px;
    overflow: hidden;
    background: #e8e8e8;
    flex-shrink: 0;
    cursor: grab;
    box-shadow: 0 4px 14px rgba(0,0,0,.1);
    touch-action: none;
}
.wpo-crop-stage:active { cursor: grabbing; }
.wpo-crop-stage canvas {
    display: block;
    width: 100%;
    height: 100%;
    user-select: none;
    -webkit-user-drag: none;
}
.wpo-crop-border {
    position: absolute;
    inset: 0;
    border: 1px dashed rgba(255,255,255,.75);
    pointer-events: none;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,.15);
}

.wpo-crop-side {
    flex: 1;
    min-width: 180px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding-top: 6px;
}

.wpo-crop-field {
    display: block;
}
.wpo-crop-field label {
    display: block;
    font-size: 13px;
    color: var(--wpo-gold-dark);
    font-weight: 600;
    margin-bottom: 6px;
}
#wpo-crop-zoom {
    width: 100%;
    accent-color: var(--wpo-gold-dark);
    cursor: pointer;
}

.wpo-crop-hint {
    font-size: 12px;
    color: #999;
    line-height: 1.7;
    padding: 10px 12px;
    background: #fff;
    border-radius: 6px;
    border: 1px dashed #ddd3bd;
}

.wpo-crop-remove {
    align-self: flex-start;
    background: none;
    border: 1px solid #e0b0b0;
    color: #b85c5c;
    font-size: 13px;
    padding: 6px 16px;
    border-radius: 4px;
    cursor: pointer;
    transition: all .2s;
}
.wpo-crop-remove:hover { background: #fdf2f2; }

/* ==================== 按钮 ==================== */
.wpo-btn {
    display: inline-block;
    padding: 12px 42px;
    font-size: 16px;
    letter-spacing: 3px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    transition: all .2s ease;
}
.wpo-btn-primary {
    background: linear-gradient(135deg, #8a6a30 0%, #6b5024 100%);
    color: #fff;
    box-shadow: 0 4px 14px rgba(107,80,36,.3);
}
.wpo-btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(107,80,36,.4);
}
.wpo-btn-primary:disabled {
    opacity: .6;
    cursor: not-allowed;
    transform: none;
}
.wpo-btn-ghost {
    background: #fff;
    color: var(--wpo-gold-dark);
    border: 1px solid var(--wpo-gold-light);
    padding: 11px 26px;
}
.wpo-btn-ghost:hover { background: #faf8f3; }

/* ==================== 模板选择器 ==================== */
.wpo-template-picker { margin-bottom: 18px; }
.wpo-picker-label {
    display: block;
    font-size: 14px;
    color: var(--wpo-gold-dark);
    font-weight: 600;
    margin-bottom: 10px;
}
.wpo-template-options {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
}
.wpo-tpl-opt {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border: 2px solid #e5dcc8;
    border-radius: 8px;
    cursor: pointer;
    transition: all .2s;
    background: #fff;
    font-size: 14px;
    color: #555;
    font-weight: 500;
    user-select: none;
    position: relative;
}
.wpo-tpl-opt:hover {
    border-color: var(--wpo-gold);
    background: #faf8f3;
}
.wpo-tpl-opt input[type=radio] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}
.wpo-tpl-opt:has(input:checked) {
    border-color: var(--wpo-gold);
    background: #faf8f3;
    box-shadow: 0 0 0 3px rgba(176,141,87,.15);
}
.wpo-tpl-opt:has(input:checked) .wpo-tpl-name {
    color: var(--wpo-gold-dark);
    font-weight: 700;
}
.wpo-tpl-swatch {
    width: 26px;
    height: 26px;
    border-radius: 4px;
    border: 1px solid #ddd;
    flex-shrink: 0;
}
.tpl-white  { background: #ffffff; }
.tpl-beige  { background: #fffdf8; }
.tpl-frame  {
    background: #fffdf8;
    position: relative;
    border: 2px solid #b08d57;
}
.tpl-frame::before {
    content: "";
    position: absolute;
    inset: 3px;
    border: 1px solid #d9cdb5;
    border-radius: 1px;
}

/* ==================== 预览 ==================== */
.wpo-preview-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.wpo-preview-tpl {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 8px 18px;
    background: #fff;
    border: 1px solid var(--wpo-gold-light);
    border-radius: 8px;
    font-size: 14px;
    color: #666;
}
.wpo-preview-tpl > span { color: var(--wpo-gold-dark); font-weight: 600; }
.wpo-preview-tpl label {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    color: #555;
}
.wpo-preview-tpl input[type=radio] {
    accent-color: var(--wpo-gold-dark);
    cursor: pointer;
}
.wpo-preview-tpl label:has(input:checked) {
    color: var(--wpo-gold-dark);
    font-weight: 700;
}

/* ==================== A4 纸张 ==================== */
.wpo-paper {
    width: 100%;
    max-width: 210mm;
    min-height: 297mm;
    margin: 0 auto;
    padding: 18mm 20mm;
    background: var(--wpo-paper);
    position: relative;
    border-radius: 2px;
    box-shadow: 0 8px 40px rgba(0,0,0,.12);
    font-family: "Songti SC", "STSong", "SimSun", "Noto Serif SC", serif;
    line-height: 2;
    color: var(--wpo-text);
    box-sizing: border-box;
}

/* 真实边框元素（替代 ::before，保证 html2canvas 渲染） */
.paper-frame {
    position: absolute;
    pointer-events: none;
    display: none;
    z-index: 0;
    border-radius: 2px;
    box-sizing: border-box;
}
.wpo-paper.tpl-white .paper-frame {
    display: block;
    inset: 8mm;
    border: 4px solid #000000;
}
.wpo-paper.tpl-beige .paper-frame {
    display: block;
    inset: 8mm;
    border: 4px solid var(--wpo-gold);
}
.wpo-paper.tpl-frame .paper-frame {
    display: block;
    inset: 11mm;
    border: 1px solid #d9cdb5;
}

/* 角花 */
.wpo-paper .corner {
    display: none;
    position: absolute;
    width: 46px;
    height: 46px;
    border: 2px solid var(--wpo-gold);
    opacity: .6;
}
.wpo-paper.tpl-frame .corner { display: block; }
.wpo-paper .corner-tl { top: 10mm; left: 10mm; border-right: none; border-bottom: none; }
.wpo-paper .corner-tr { top: 10mm; right: 10mm; border-left: none; border-bottom: none; }
.wpo-paper .corner-bl { bottom: 10mm; left: 10mm; border-right: none; border-top: none; }
.wpo-paper .corner-br { bottom: 10mm; right: 10mm; border-left: none; border-top: none; }

.paper-content {
    position: relative;
    z-index: 1;
    padding: 4mm 6mm;
}

.paper-title {
    text-align: center;
    font-size: 34pt;
    letter-spacing: 22px;
    text-indent: 22px;
    margin: 6mm 0 4mm;
    font-weight: 700;
    color: #1f1f1f;
}
.paper-title::after {
    content: "";
    display: block;
    width: 60px;
    height: 2px;
    background: #333;
    margin: 6mm auto 0;
}

/* 遗像：图片已经是灰度、固定尺寸，不需要 filter / object-fit */
.paper-photo { text-align: center; margin: 8mm 0 6mm; }
.paper-photo img {
    width: 42mm;
    height: 54mm;
    display: inline-block;
    border: 1px solid #999;
    padding: 3px;
    background: #fff;
    box-sizing: content-box;
    vertical-align: middle;
}

.paper-name {
    text-align: center;
    font-size: 22pt;
    letter-spacing: 10px;
    text-indent: 10px;
    margin: 4mm 0 2mm;
    font-weight: 700;
    color: #1f1f1f;
}
.paper-dates {
    text-align: center;
    font-size: 11pt;
    color: #8a8a8a;
    letter-spacing: 1px;
    margin-bottom: 8mm;
}

.paper-bio { font-size: 12.5pt; text-indent: 2em; color: #333; }
.paper-bio p { margin: 0 0 4mm; }

.paper-section {
    margin: 6mm 0;
    padding: 4mm 5mm;
    border-left: 3px solid #555;
    border-radius: 2px;
}
.paper-section h3 {
    font-size: 13pt;
    margin: 0 0 3mm;
    letter-spacing: 3px;
    font-weight: 600;
}
.paper-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0 10mm;
}
.paper-row p {
    margin: 1mm 0;
    font-size: 12pt;
    flex: 0 0 auto;
}
.paper-section p { margin: 1mm 0; font-size: 12pt; }
.paper-section p strong { font-weight: 600; }

.paper-sign {
    margin-top: 12mm;
    text-align: right;
    font-size: 13pt;
    line-height: 2.2;
    color: #333;
}
.paper-sign-date {
    margin-top: 6mm;
    letter-spacing: 2px;
}

/* 白底 */
.wpo-paper.tpl-white { background: #ffffff; }
.wpo-paper.tpl-white .paper-title::after { background: #000; }
.wpo-paper.tpl-white .paper-section {
    background: #f7f7f7;
    border-left: 4px solid #000;
}
.wpo-paper.tpl-white .paper-section h3,
.wpo-paper.tpl-white .paper-section p strong,
.wpo-paper.tpl-white .paper-sign-date {
    color: #000;
}

/* 米色 */
.wpo-paper.tpl-beige { background: #fffdf8; }
.wpo-paper.tpl-beige .paper-title::after { background: var(--wpo-gold); }
.wpo-paper.tpl-beige .paper-section {
    background: #faf7f0;
    border-left: 4px solid var(--wpo-gold);
}
.wpo-paper.tpl-beige .paper-section h3,
.wpo-paper.tpl-beige .paper-section p strong,
.wpo-paper.tpl-beige .paper-sign-date {
    color: var(--wpo-gold-dark);
}

/* 带边框 */
.wpo-paper.tpl-frame { background: #fffdf8; }
.wpo-paper.tpl-frame .paper-section {
    background: #faf7f0;
    border-left: 4px solid var(--wpo-gold);
}
.wpo-paper.tpl-frame .paper-section h3,
.wpo-paper.tpl-frame .paper-section p strong,
.wpo-paper.tpl-frame .paper-sign-date {
    color: var(--wpo-gold-dark);
}
.wpo-paper.tpl-frame .paper-content { padding: 12mm 8mm; }

/* ==================== 进度弹层 ==================== */
.wpo-progress {
    position: fixed;
    inset: 0;
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.wpo-progress-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,.55);
    backdrop-filter: blur(2px);
}
.wpo-progress-panel {
    position: relative;
    z-index: 1;
    width: 88%;
    max-width: 380px;
    background: #fff;
    border-radius: 14px;
    padding: 32px 28px 26px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,.3);
    animation: wpoModalIn .25s ease;
}
.wpo-progress-icon {
    font-size: 40px;
    line-height: 1;
    margin-bottom: 12px;
    animation: wpoPulse 1.4s ease-in-out infinite;
}
@keyframes wpoPulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50%      { transform: scale(1.12); opacity: .75; }
}
.wpo-progress-title {
    margin: 0 0 18px;
    font-size: 16px;
    color: var(--wpo-gold-dark);
    letter-spacing: 3px;
    font-weight: 600;
}
.wpo-progress-bar {
    width: 100%;
    height: 10px;
    background: #f0e9dc;
    border-radius: 999px;
    overflow: hidden;
    position: relative;
}
.wpo-progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #b08d57 0%, #6b5024 100%);
    border-radius: 999px;
    transition: width .35s ease;
}
.wpo-progress-text {
    margin-top: 14px;
    font-size: 13px;
    color: #888;
    letter-spacing: 1px;
    min-height: 18px;
}

/* ==================== 图片弹层 ==================== */
.wpo-img-modal {
    position: fixed;
    inset: 0;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
}
.wpo-img-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,.65);
    backdrop-filter: blur(2px);
}
.wpo-img-panel {
    position: relative;
    z-index: 1;
    width: 92%;
    max-width: 560px;
    max-height: 92vh;
    overflow-y: auto;
    background: #fff;
    border-radius: 12px;
    padding: 20px 22px 22px;
    box-shadow: 0 20px 60px rgba(0,0,0,.35);
    animation: wpoModalIn .25s ease;
}
@keyframes wpoModalIn {
    from { transform: translateY(16px) scale(.98); opacity: 0; }
    to   { transform: none; opacity: 1; }
}
.wpo-img-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}
.wpo-img-head h3 {
    margin: 0;
    font-size: 17px;
    color: var(--wpo-gold-dark);
    letter-spacing: 2px;
}
.wpo-img-close {
    background: none;
    border: none;
    font-size: 22px;
    color: #999;
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
}
.wpo-img-close:hover { color: #333; }

.wpo-img-preview {
    max-height: 60vh;
    overflow: auto;
    border: 1px solid #eee;
    border-radius: 8px;
    background: #f5f5f5;
    padding: 10px;
    text-align: center;
}
.wpo-img-preview img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
    border-radius: 4px;
    box-shadow: 0 4px 20px rgba(0,0,0,.15);
}
.wpo-img-tip {
    margin: 12px 0 16px;
    font-size: 13px;
    color: #888;
    text-align: center;
    line-height: 1.6;
}
.wpo-img-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

/* ==================== 响应式 ==================== */
@media (max-width: 700px) {
    .wpo-card { padding: 26px 22px; }
    #wpo-form .wpo-grid { grid-template-columns: 1fr; gap: 14px; }
    .wpo-paper {
        padding: 10mm 8mm;
        min-height: auto;
    }
    .wpo-paper .corner { width: 28px; height: 28px; }
    .wpo-paper .corner-tl { top: 5mm; left: 5mm; }
    .wpo-paper .corner-tr { top: 5mm; right: 5mm; }
    .wpo-paper .corner-bl { bottom: 5mm; left: 5mm; }
    .wpo-paper .corner-br { bottom: 5mm; right: 5mm; }
    .wpo-paper.tpl-white .paper-frame,
    .wpo-paper.tpl-beige .paper-frame { inset: 5mm; border-width: 3px; }
    .wpo-paper.tpl-frame .paper-frame { inset: 7mm; }
    .paper-title { font-size: 24pt; letter-spacing: 12px; text-indent: 12px; }
    .paper-name { font-size: 17pt; }
    .paper-photo img { width: 34mm; height: 44mm; }
    .wpo-preview-bar { justify-content: center; }
    .wpo-img-panel { width: 96%; padding: 16px; }
    .wpo-img-actions { flex-direction: column; }
    .wpo-img-actions .wpo-btn { width: 100%; }
    .wpo-crop-body { gap: 14px; }
    .wpo-crop-stage { width: 200px; height: 257px; }
}