:root {
    --text-primary: #111827;
    --text-muted: #6b7280;
    --border-card: rgba(0, 0, 0, 0.09);
    --bg-page: #f0f2f5;
    --bg-card: #ffffff;
    --bg-img: #f5f5f5;
    --popular-blue: #4a90d9;
    --free-green: #16a34a;
    --premium-amber: #b45309;
    --sale-red: rgba(210, 40, 40, 0.92);
}
*,
*::before,
*::after {
    box-sizing: border-box;
}
html,
body {
    margin: 0;
    padding: 0;
}
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg-page);
    color: var(--text-primary);
    min-height: 100vh;
}
.page-header {
    position: relative;
    background: #fff;
    border-bottom: 1px solid rgb(0 0 0 / 0.08);
}
.page-header .container {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 11px 16px;
    margin: 0;
}
.page-header h1 {
    flex: 1;
    margin: 0;
    font-size: 17px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.2px;
    text-align: center;
}
.page-back-btn {
    position: absolute;
    left: 4px;
    top: 50%;
    transform: translateY(-50%);
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: none;
    border: none;
    padding: 4px 10px 4px 2px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 15px;
    font-weight: 600;
    color: #334155;
    cursor: pointer;
    line-height: 1;
    -webkit-tap-highlight-color: transparent;
}
.page-back-btn svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}
.page-back-btn:hover { color: #0f172a; }
.header-cart {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-primary);
}
.header-cart svg {
    width: 22px;
    height: 22px;
}
.sale-banner-sticky {
    position: sticky;
    top: 0;
    z-index: 999;
    display: flex;
    align-items: center;
    background: linear-gradient(90deg, #831843 0%, #be185d 50%, #db2777 100%);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    text-align: left;
    padding: 4px 12px;
    height: 34px;
    min-height: 34px;
    letter-spacing: 0.02em;
    box-shadow: 0 6px 18px rgb(0 0 0 / 0.08);
    visibility: hidden;
    opacity: 0;
    transition:
        opacity 0.2s ease,
        visibility 0.2s ease;
    overflow: hidden;
}
.sale-banner-sticky.active {
    visibility: visible;
    opacity: 1;
}
.sale-inner {
    display: flex;
    align-items: center;
    gap: 6px;
    max-width: 1200px;
    margin: 0 auto;
    padding: 4px 8px;
}
.container-wide {
    padding: 0;
}
.sale-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    flex: 0 0 16px;
    background: none;
    border-radius: 0;
    padding: 0;
}
.sale-icon img {
    width: 18px;
    height: 18px;
    display: block;
}
.sale-icon + .sale-text {
    margin-left: 0;
}
.sale-text {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex-wrap: wrap;
}
.sale-label {
    font-size: 12px;
    font-weight: 700;
    color: rgb(255 255 255 / 0.95);
    letter-spacing: 0.02em;
    text-transform: uppercase;
}
.sale-off {
    font-size: 15px;
    font-weight: 800;
    color: #fff200;
    text-shadow: 0 1px 0 rgb(0 0 0 / 0.08);
}
.sale-msg {
    font-size: 12px;
    font-weight: 600;
    color: rgb(255 255 255 / 0.92);
    opacity: 0.95;
}
.sale-timer {
    font-size: 12px;
    color: rgb(255 255 255 / 0.9);
    font-weight: 600;
}
.sale-banner-sticky.is-intro {
    padding: 0;
    background: linear-gradient(135deg, #7c0a2a 0%, #be185d 45%, #db2777 75%, #f472b6 100%);
    overflow: hidden;
}
.sale-flash-intro {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 14px 16px 12px;
    text-align: center;
    animation: sfi-fadein 0.35s ease forwards;
}
.sale-flash-intro.is-hiding {
    animation: sfi-fadeout 0.45s ease forwards;
}
.sale-flash-percent {
    font-size: clamp(40px, 11vw, 76px);
    font-weight: 900;
    color: #fff200;
    line-height: 1;
    letter-spacing: -2px;
    text-shadow:
        0 2px 14px rgb(0 0 0 / 0.3),
        0 0 40px rgb(255 242 0 / 0.35);
    animation:
        sfi-bounce 0.65s cubic-bezier(0.36, 0.07, 0.19, 0.97) both,
        sfi-pulse 1.7s ease-in-out 0.65s infinite;
}
.sale-flash-subtitle {
    font-size: clamp(13px, 3.8vw, 19px);
    font-weight: 800;
    color: #fff;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    margin-top: 5px;
    opacity: 0.96;
    animation: sfi-slidein 0.45s ease 0.18s both;
}
.sale-flash-tag {
    margin-top: 7px;
    display: inline-block;
    background: rgb(255 255 255 / 0.18);
    border: 1px solid rgb(255 255 255 / 0.38);
    border-radius: 20px;
    padding: 3px 14px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.09em;
    color: rgb(255 255 255 / 0.9);
    text-transform: uppercase;
    animation: sfi-slidein 0.45s ease 0.32s both;
}
@keyframes sfi-fadein {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
@keyframes sfi-fadeout {
    from {
        opacity: 1;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale(0.95);
    }
}
@keyframes sfi-bounce {
    0% {
        transform: scale(0.35) rotate(-5deg);
        opacity: 0;
    }
    55% {
        transform: scale(1.13) rotate(1deg);
    }
    75% {
        transform: scale(0.95) rotate(-0.5deg);
    }
    100% {
        transform: scale(1) rotate(0);
        opacity: 1;
    }
}
@keyframes sfi-pulse {
    0%,
    100% {
        text-shadow:
            0 2px 14px rgb(0 0 0 / 0.3),
            0 0 22px rgb(255 242 0 / 0.28);
    }
    50% {
        text-shadow:
            0 2px 14px rgb(0 0 0 / 0.3),
            0 0 55px rgb(255 242 0 / 0.6);
    }
}
@keyframes sfi-slidein {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
@media (max-width: 520px) {
    .sale-inner {
        gap: 8px;
    }
    .sale-text {
        min-width: 0;
    }
    .sale-msg {
        display: none;
    }
    .sale-off {
        font-size: 13px;
    }
    .sale-icon {
        width: 16px;
        height: 16px;
        padding: 0;
    }
    .sale-icon img {
        width: 16px;
        height: 16px;
    }
}
.container {
    max-width: 100%;
    margin: 0;
    padding: 0;
}
.main-content {
    padding: 0;
}
.template-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    padding: 8px;
    background: var(--bg-page);
}
.template-grid:empty {
    min-height: 80vh;
}
@media (min-width: 920px) {
    .template-grid {
        grid-template-columns: repeat(6, 1fr);
    }
}
.template-item {
    border: 1px solid var(--border-card);
    background: var(--bg-card);
    overflow: hidden;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    -webkit-tap-highlight-color: rgb(0 0 0 / 0.04);
    transition: border-color 0.15s;
}
.template-item:hover {
    border: 2px solid transparent;
    background-image: linear-gradient(var(--bg-card), var(--bg-card)), linear-gradient(135deg, #22c55e, #831843);
    background-origin: border-box;
    background-clip: padding-box, border-box;
}
.template-item.most-popular {
    border: 2px solid var(--popular-blue);
}
.template-item[data-template-id="t2"],
.template-item[data-template-id="t3"] {
    border: none;
}
.template-item[data-template-id="t2"]:hover,
.template-item[data-template-id="t3"]:hover {
    border: 2px solid transparent;
    background-image: linear-gradient(var(--bg-card), var(--bg-card)), linear-gradient(135deg, #22c55e, #831843);
    background-origin: border-box;
    background-clip: padding-box, border-box;
}
.template-image-container {
    position: relative;
    width: 100%;
    aspect-ratio: 210 / 297;
    background: var(--bg-img);
    overflow: hidden;
    flex-shrink: 0;
    border-bottom: 1px solid rgb(0 0 0 / 0.09);
}
.template-image-container.is-loading {
    background: linear-gradient(90deg, #e8e8e8 25%, #f4f4f4 50%, #e8e8e8 75%);
    background-size: 200% 100%;
    animation: tpl-shimmer 1.4s ease-in-out infinite;
}
@keyframes tpl-shimmer {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}
.template-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    -webkit-user-drag: none;
    user-drag: none;
    -webkit-user-select: none;
    user-select: none;
    opacity: 0;
    transition: opacity 0.28s ease;
}
.template-image.is-loaded {
    opacity: 1;
}
.badge {
    position: absolute;
    font-size: 10px;
    font-weight: 600;
    line-height: 1;
    padding: 3px 7px;
    border-radius: 4px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 5;
}
.badge-discount {
    top: 8px;
    left: 8px;
    background: rgb(210 40 40 / 0.92);
    color: #fff;
}
.badge-tier {
    bottom: 0;
    left: 0;
    border-radius: 0 4px 0 0;
}
.badge-tier.popular {
    background: rgb(74 144 217 / 0.92);
    color: #fff;
}
.badge-tier.premium {
    background: rgb(180 117 23 / 0.92);
    color: #fff;
}
.badge-tier.purchased {
    background: rgb(22 163 74 / 0.88);
    color: #fff;
}
.template-meta {
    height: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
    padding: 0 8px;
    background: #fff;
}
.template-name {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 58%;
    flex-shrink: 1;
}
.template-price {
    display: flex;
    align-items: center;
    gap: 3px;
    flex-shrink: 0;
    white-space: nowrap;
}
.price-free {
    font-size: 11px;
    font-weight: 700;
    color: #fff;
    background: var(--free-green);
    display: none;
    padding: 2px 7px;
    border-radius: 20px;
    line-height: 1.5;
}
.price-new {
    font-size: 13px;
    font-weight: 700;
    color: #0284c7;
}
.price-old {
    font-size: 12px;
    font-weight: 600;
    color: #9d9d9d;
    position: relative;
}
.price-old::after {
    content: "";
    position: absolute;
    left: 0;
    top: 50%;
    width: 100%;
    height: 1px;
    background: #10005db8;
    transform: rotate(-1deg);
    transform-origin: center;
}
.price-discount {
    color: #16a34a;
    font-size: 11px;
    font-weight: 600;
    margin-right: 4px;
    white-space: nowrap;
}
.placeholder-frame {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    height: 100%;
}
.placeholder-icon svg {
    width: 36px;
    height: 36px;
    display: block;
}
.placeholder-icon svg path,
.placeholder-icon svg rect,
.placeholder-icon svg line {
    stroke: #cbd5e1;
    stroke-width: 1.6;
    fill: none;
}
.placeholder-label {
    font-size: 11px;
    color: #94a3b8;
    font-weight: 500;
}
.loading-spinner {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 0;
    color: var(--text-muted);
    font-size: 14px;
}
.multi-page-indicator {
    position: absolute;
    bottom: 6px;
    right: 6px;
    background: rgb(0 0 0 / 0.55);
    color: #fff;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 8px;
    z-index: 4;
}
.template-image.is-fade {
    opacity: 0;
    transition: opacity 0.28s ease;
}
.template-image.is-fade.is-visible,
.template-image.is-visible {
    opacity: 1;
}
.orig-price {
    text-decoration: line-through;
    color: #888;
    font-weight: 400;
    margin-right: 4px;
}
.sale-price {
    color: #d97706;
    font-weight: 700;
}
.pdf-page {
    background: #fff;
}
