/**
 * @license
 * SPDX-License-Identifier: Apache-2.0
*/

@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;500;700;900&family=Noto+Serif+SC:wght@700;900&family=Poppins:wght@700;900&family=Ma+Shan+Zheng&family=Orbitron:wght@400;700&display=swap');

/* --- Global Styles & Variables --- */
:root {
    --text-primary: #2c3e50;
    --text-secondary: #7f8c8d;
    --text-cta: #34495e;
    --bg-light: #f4f6f8;
    --bg-panel: #ffffff;
    --border-color: #ddd;
    --accent-color: #2c3e50;
    --shadow-color-light: rgba(0,0,0,0.1);
    --shadow-color-deep: rgba(44, 62, 80, 0.2);
}

/* --- General Page Layout --- */
body {
    background: linear-gradient(180deg, #eaf5ff 0%, var(--bg-light) 100%);
    font-family: 'Noto Sans SC', sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    margin: 0;
    padding: 20px;
    min-height: 100vh;
    box-sizing: border-box;
}

/* --- Controls Panel --- */
.controls-panel {
    background-color: var(--bg-panel);
    padding: 15px;
    border-radius: 12px;
    box-shadow: 0 8px 25px var(--shadow-color-light);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 15px;
    margin-bottom: 25px;
    max-width: 95%;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.control-group label {
    font-weight: 500;
    color: #555;
    font-size: 14px;
    white-space: nowrap;
}

#templateSelector {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.template-button, .control-button, .print-button, #sizePresetSelector {
    padding: 8px 16px;
    background-color: #f0f2f5;
    color: #333;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}
select#sizePresetSelector {
    padding-right: 30px;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23333' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 12px;
}

.template-button:hover, .control-button:hover, .print-button:hover, #sizePresetSelector:hover {
    background-color: #e0e4e8;
    transform: translateY(-1px);
}

.template-button.active, .control-button.active {
    background-color: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

#bgColorPicker {
    width: 28px;
    height: 28px;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    cursor: pointer;
    padding: 0;
    background: transparent;
}
#bgColorPicker::-webkit-color-swatch-wrapper { padding: 0; }
#bgColorPicker::-webkit-color-swatch { border-radius: 50%; border: none; }
#bgColorPicker::-moz-color-swatch { border-radius: 50%; border: none; }


.print-button {
    background-color: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.font-slider { width: 80px; }

.size-input {
    width: 45px; text-align: center; border: 1px solid var(--border-color);
    border-radius: 4px; padding: 4px; font-size: 13px; color: #333;
    -moz-appearance: textfield;
}
.size-input::-webkit-outer-spin-button, .size-input::-webkit-inner-spin-button {
    -webkit-appearance: none; margin: 0;
}
.unit-display { font-size: 14px; color: #888; margin-left: -4px; }
.divider { width: 1px; height: 25px; background-color: #e0e0e0; margin: 0 5px; }
#customSizeInputs { gap: 8px; align-items: center; }
#customSizeInputs input { width: 50px; }
.hidden { display: none !important; }
.print-tip { font-size: 12px; color: #e74c3c; font-weight: bold; }


/* --- Poster Container & Content (COMMON STYLES) --- */
.poster-container {
    width: 100%; max-width: 600px; container-type: inline-size;
    aspect-ratio: var(--aspect-ratio, 210 / 297); background: var(--bg-panel);
    box-shadow: 0 20px 50px var(--shadow-color-deep); display: flex;
    flex-direction: column; padding: 5% 5% 4%; box-sizing: border-box;
    border-radius: 12px; position: relative; transition: all 0.4s ease; overflow: hidden;
}
.main-content-area {
    flex-grow: 1; width: 100%; min-height: 0; position: relative;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    border-radius: 8px; transition: background-color 0.3s;
}
.main-content-area:hover { background-color: rgba(0,0,0,0.02); }
.upload-text {
    color: #b0b0b0; text-align: center; font-size: 5cqi; font-weight: bold;
}
.preview-image {
    max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 1.5cqi;
    opacity: 0; transition: opacity 0.4s ease, transform 0.2s ease;
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    transform: scale(var(--main-image-scale, 1));
}
.image-shadow { filter: drop-shadow(0 1.5cqi 3cqi rgba(44, 62, 80, 0.25)); }
.hidden-input { display: none; }
.bottom-info-panel {
    flex-shrink: 0; width: 100%; margin-top: 2cqi; padding-top: 2cqi;
    border-top: 1px solid rgba(0,0,0,0.05);
}
.bottom-info-wrapper {
    display: flex; max-width: 98%; margin: 0 auto;
}
[contenteditable] { outline: 2px solid transparent; transition: outline 0.2s ease; }
[contenteditable]:focus { outline: 2px solid #74b9ff; background-color: rgba(116, 185, 255, 0.1); border-radius: 4px; }
.poster-title { line-height: 1.2; font-size: 6cqi; margin: 0 0 1.5cqi 0; }
.poster-synopsis { line-height: 1.6; font-size: 1.8cqi; margin: 0; }
.cta-text { line-height: 1.5; font-size: 2.2cqi; }
.qr-section { display: flex; align-items: flex-end; gap: 1.5cqi; }
.qr-placeholder {
    width: 18cqi; height: 18cqi; cursor: pointer; position: relative;
    overflow: hidden; flex-shrink: 0; transition: all 0.3s ease;
}
.qr-placeholder .preview-image { object-fit: contain; border-radius: 6px; }

/* --- THEME: Classic (Default) --- */
.theme-classic .decoration {
    position: absolute; pointer-events: none; border-color: #e0e0e0; border-style: solid;
    border-width: 0; transition: all 0.3s ease;
}
.theme-classic:hover .decoration { border-color: var(--accent-color); }
.theme-classic .corner-tl { top: 2.5%; left: 2.5%; width: 25px; height: 25px; border-top-width: 2px; border-left-width: 2px; }
.theme-classic .corner-tr { top: 2.5%; right: 2.5%; width: 25px; height: 25px; border-top-width: 2px; border-right-width: 2px; }
.theme-classic .corner-bl { bottom: 2.5%; left: 2.5%; width: 25px; height: 25px; border-bottom-width: 2px; border-left-width: 2px; }
.theme-classic .corner-br { bottom: 2.5%; right: 2.5%; width: 25px; height: 25px; border-bottom-width: 2px; border-right-width: 2px; }
.theme-classic .bottom-info-wrapper { justify-content: space-between; align-items: flex-end; }
.theme-classic .poster-title { font-weight: 900; color: var(--text-primary); }
.theme-classic .poster-synopsis { color: var(--text-secondary); }
.theme-classic .cta-text { font-weight: 500; color: var(--text-cta); text-align: right; }
.theme-classic .qr-placeholder { border: 2px dashed #d0d0d0; border-radius: 8px; background-color: #f8f8f8; }
.theme-classic .qr-placeholder:hover { border-color: var(--accent-color); background-color: #f0f2f5; }

/* --- THEME: Modern --- */
.theme-modern .bottom-info-panel { border-top-color: #eee; }
.theme-modern .bottom-info-wrapper { flex-direction: column; align-items: center; text-align: center; gap: 2cqi; }
.theme-modern .text-info { order: 2; }
.theme-modern .qr-section { order: 1; flex-direction: column; align-items: center; gap: 1cqi; }
.theme-modern .cta-text { text-align: center; font-weight: 500; font-size: 2cqi; }
.theme-modern .poster-title { font-weight: 700; color: var(--text-primary); }
.theme-modern .poster-synopsis { color: #555; max-width: 85%; margin: 0 auto; font-weight: 400; }
.theme-modern .qr-placeholder { border: 1px solid #eee; border-radius: 8px; background-color: #fafafa; }

/* --- THEME: Ink --- */
.theme-ink .decoration {
    position: absolute; pointer-events: none; border-color: #444; border-style: solid;
    border-width: 0; transition: all 0.3s ease;
}
.theme-ink:hover .decoration { border-color: var(--accent-color); }
.theme-ink .corner-tl { top: 2.5%; left: 2.5%; width: 40px; height: 40px; border-top-width: 3px; border-left-width: 3px; }
.theme-ink .corner-tr { top: 2.5%; right: 2.5%; width: 40px; height: 40px; border-top-width: 3px; border-right-width: 3px; }
.theme-ink .corner-bl { bottom: 2.5%; left: 2.5%; width: 40px; height: 40px; border-bottom-width: 3px; border-left-width: 3px; }
.theme-ink .corner-br { bottom: 2.5%; right: 2.5%; width: 40px; height: 40px; border-bottom-width: 3px; border-right-width: 3px; }
.theme-ink .bottom-info-wrapper { display: grid; grid-template-columns: 1fr auto; align-items: flex-end; gap: 2cqi; }
.theme-ink .text-info { background-color: rgba(44, 62, 80, 0.9); padding: 2cqi; border-radius: 8px; }
.theme-ink .poster-title { font-family: 'Noto Serif SC', serif; font-weight: 900; color: #f4f6f8; font-size: 6.5cqi; }
.theme-ink .poster-synopsis { color: #ccc; }
.theme-ink .cta-text { color: var(--text-primary); font-weight: 500; text-align: right; }
.theme-ink .qr-placeholder { border: 2px solid #e0e0e0; background: #fff; border-radius: 8px; }

/* --- Shape & Decoration Base --- */
.shape { position: absolute; display: none; pointer-events: none; z-index: 0; transition: all 0.4s ease; }
.decoration { display: none; }
.theme-classic .decoration, .theme-ink .decoration { display: block; }

/* --- THEME: Memphis --- */
.theme-memphis { background: #FDF6E3; }
.theme-memphis .bottom-info-panel { border-top-color: #2c3e50; }
.theme-memphis .bottom-info-wrapper { flex-direction: column; align-items: flex-start; gap: 2cqi; position: relative; z-index: 1; }
.theme-memphis .text-info { width: 100%; }
.theme-memphis .poster-title { font-family: 'Poppins', sans-serif; font-weight: 900; color: #FF0054; }
.theme-memphis .poster-synopsis { color: #3D1E6D; }
.theme-memphis .cta-text { font-weight: 700; color: #3D1E6D; }
.theme-memphis .qr-section { align-self: flex-end; }
.theme-memphis .qr-placeholder { border: 3px solid #3D1E6D; border-radius: 6px; }
.theme-memphis .shape { display: block; }
.theme-memphis .shape-1 { background: #FFD600; width: 25%; height: 0; padding-bottom: 25%; border-radius: 50%; top: 5%; left: -5%; }
.theme-memphis .shape-2 { background: #00A8A8; width: 15%; height: 0; padding-bottom: 15%; top: 60%; right: -5%; clip-path: polygon(50% 0%, 0% 100%, 100% 100%); }
.theme-memphis .shape-3 { width: 30%; height: 10%; background-image: radial-gradient(circle, #FF0054 20%, transparent 25%); background-size: 20px 20px; top: 8%; right: 10%; }
.theme-memphis .shape-4 { border: 4px solid #3D1E6D; width: 15%; height: 15%; bottom: 20%; left: 5%; transform: rotate(15deg); }


/* --- THEME: Chinese Style --- */
.theme-chinese { background: #FDFBF8 url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 1600 800"><g fill-opacity="0.08"><path fill="%23e8e8e8" d="M486 705.8c-109.3-21.8-223.4-32.2-335.3-19.4C99.5 692.1 49 703 0 719.8V800h843.8c-115.9-33.2-230.8-68.1-347.6-92.2L486 705.8zM1600 0H0v719.8c49-16.8 99.5-27.8 150.7-33.5c111.9-12.7 226-2.4 335.3 19.4L496.3 708c116.7 24 231.7 59 347.6 92.2H1600V0z"/></g></svg>') no-repeat bottom center; background-size: cover; }
.theme-chinese .bottom-info-panel { border-top: 1px solid #D6C6B3; }
.theme-chinese .bottom-info-wrapper { justify-content: space-between; align-items: flex-end; }
.theme-chinese .text-info { position: relative; padding-right: 6cqi; }
.theme-chinese .poster-title { font-family: 'Ma Shan Zheng', cursive; font-weight: normal; color: #2c3e50; font-size: 8cqi; }
.theme-chinese .poster-synopsis { color: #594A3C; }
.theme-chinese .cta-text { font-weight: 500; color: #594A3C; text-align: right; }
.theme-chinese .qr-placeholder { border: 1px solid #D6C6B3; border-radius: 4px; background-color: rgba(255,255,255,0.7); }
.theme-chinese .text-info::after { content: '奋斗'; font-family: 'Noto Serif SC', serif; position: absolute; bottom: 0; right: 0; color: #C0392B; border: 2.5px solid #C0392B; padding: 0.5cqi 0.8cqi; font-size: 2.5cqi; border-radius: 4px; font-weight: 700; }

/* --- THEME: Sci-Fi --- */
.theme-scifi { background: #0D0D1A; color: #E0E0E0; background-image: radial-gradient(#00FFFF1A 1px, transparent 1px), radial-gradient(#FA00FF1A 1px, transparent 1px); background-size: 40px 40px; background-position: 0 0, 20px 20px; }
.theme-scifi [contenteditable]:focus { outline: 2px solid #00FFFF; background-color: rgba(0, 255, 255, 0.1); }
.theme-scifi .bottom-info-panel { border-top-color: rgba(0, 255, 255, 0.3); }
.theme-scifi .bottom-info-wrapper { justify-content: space-between; align-items: flex-end; }
.theme-scifi .poster-title { font-family: 'Orbitron', sans-serif; font-weight: 700; color: #FFFFFF; text-shadow: 0 0 5px #00FFFF, 0 0 10px #00FFFF, 0 0 15px #00FFFF; }
.theme-scifi .poster-synopsis { color: #B0C4DE; }
.theme-scifi .cta-text { color: #00FFFF; text-shadow: 0 0 3px #00FFFF; }
.theme-scifi .qr-placeholder { border: 1px solid rgba(0, 255, 255, 0.5); background: rgba(0, 255, 255, 0.05); }
.theme-scifi .upload-text { color: #00FFFF80; }
.theme-scifi .shape { display: block; border: 1px solid rgba(0, 255, 255, 0.4); }
.theme-scifi .shape-1 { width: 30%; height: 15%; top: 5%; left: 5%; border-width: 0 0 1px 1px; }
.theme-scifi .shape-2 { width: 30%; height: 15%; bottom: 25%; right: 5%; border-width: 1px 1px 0 0; text-align: right; }
.theme-scifi .shape-2::before { content: 'SYS_SCAN_OK'; font-family: 'Orbitron', sans-serif; font-size: 1.5cqi; color: rgba(0, 255, 255, 0.5); padding: 0.5cqi; }


/* --- Print Styles --- */
@media print {
    @page {
        size: var(--print-width) var(--print-height);
        margin: 0;
    }

    body {
        background: #FFF !important;
        padding: 0;
        margin: 0;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* Hide everything on the page that is not the poster container */
    body > *:not(.poster-container) {
        display: none !important;
    }
    
    .poster-container {
        /* Make sure the poster is visible and reset any screen-specific styles */
        display: flex !important;
        visibility: visible !important;
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        margin: 0 !important;
        max-width: none !important;
        box-shadow: none !important;
        border-radius: 0 !important;
        
        /* Set background explicitly for printing */
        background: var(--print-background, var(--bg-panel)) !important;
        
        /* The key fix: use zoom instead of transform.
           Zoom scales the element AND its layout space, preventing clipping. */
        zoom: var(--print-scale, 1);
    }
    
    /* Ensure special theme elements render correctly in print */
    .decoration, .shape { display: block !important; }
    h1, p, div { font-family: 'Noto Sans SC', 'Noto Serif SC', 'Poppins', 'Ma Shan Zheng', 'Orbitron', sans-serif !important; }
    [contenteditable]:focus { outline: none; background-color: transparent; }
    .theme-ink .text-info { background-color: rgba(44, 62, 80, 0.9) !important; }
    .theme-scifi { background: #0D0D1A !important; }
    .theme-scifi .poster-title { text-shadow: 0 0 5px #00FFFF, 0 0 10px #00FFFF, 0 0 15px #00FFFF !important; }
    .theme-scifi .cta-text { text-shadow: 0 0 3px #00FFFF !important; }
    .theme-chinese .text-info::after { content: '奋斗' !important; }
}