@media (prefers-color-scheme: dark) {
    :root {
        --orange: #E89968;
        --brown: #D4A384;
        --light: #1A120A;
        --cream: #241A10;
        --dark: #F5E6D3;
        --text: #F5E6D3;
        --muted: #B89F85;

        --success: #4ade80;
        --error: #f87171;

        --capybara-orange: #E89968;
        --capybara-brown: #D4A384;
        --capybara-light: #2A1E13;
        --capybara-dark: #F5E6D3;
        --white: #241A10;
        --black: #F5E6D3;
        --gray: #3A2D1F;

        --bg-dark: #1A120A;
        --bg-card: #241A10;
        --bg-input: #2F2215;
        --text-muted: #B89F85;
        --border: rgba(255, 255, 255, 0.10);
        --border-strong: rgba(255, 255, 255, 0.22);
        --brand-orange: #E89968;
        --brand-brown: #D4A384;
        --brand-dark: #F5E6D3;
        --brand-cream: #2F2215;
        --brand-light: #1A120A;
        --shadow-sm: 0 2px 12px rgba(0, 0, 0, 0.35);
        --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.45);

        /* Page-specific vars used by dashboard/help/products inline styles.
           Declared here so pages that set light defaults in their own <style>
           get overridden in dark mode without editing every page. */
        --card: #241A10;
        --line: rgba(255, 255, 255, 0.10);
        --danger: #f87171;
        --ok: #4ade80;
    }

    html,
    body {
        background-color: var(--light);
        color: var(--text);
    }

    /* Override hardcoded cream rgba() backgrounds seen across pages
       (top bar, modals, cards, etc.) with their dark equivalents. */
    .top,
    [class*="sticky"][style*="rgba(255"],
    .admin-header,
    .page-header {
        background: rgba(26, 18, 10, 0.94) !important;
        border-bottom-color: rgba(255, 255, 255, 0.08) !important;
    }

    .header {
        background: rgba(26, 18, 10, 0.88) !important;
        border-bottom-color: rgba(255, 255, 255, 0.08) !important;
    }

    .category-filter-wrap::after {
        background: linear-gradient(to right, transparent, #1A120A) !important;
    }

    .product-card {
        background: var(--cream) !important;
        box-shadow: 0 2px 12px rgba(0, 0, 0, 0.35) !important;
    }

    .product-card:hover {
        box-shadow: 0 12px 28px rgba(0, 0, 0, 0.5) !important;
    }

    .product-img {
        background: var(--cream) !important;
    }

    .empty,
    .loading {
        color: var(--muted);
    }

    .hero-overlay {
        background: linear-gradient(to right, rgba(0, 0, 0, 0.80) 0%, transparent 70%) !important;
    }

    @media (max-width: 768px) {
        .hero-overlay {
            background: linear-gradient(to top, rgba(0, 0, 0, 0.88), transparent) !important;
        }
    }

    .hero-btn {
        background: var(--cream) !important;
        color: var(--orange) !important;
    }

    .auth-link {
        background: rgba(255, 255, 255, 0.04) !important;
        border-color: rgba(255, 255, 255, 0.12) !important;
        color: var(--brown) !important;
    }

    .auth-link:hover {
        background: rgba(255, 255, 255, 0.08) !important;
    }

    .auth-link.primary {
        background: var(--orange) !important;
        border-color: var(--orange) !important;
        color: #1A120A !important;
    }

    .auth-link.primary:hover {
        background: var(--brown) !important;
        border-color: var(--brown) !important;
    }

    .auth-user-chip {
        background: rgba(255, 255, 255, 0.05) !important;
        border-color: rgba(255, 255, 255, 0.12) !important;
    }

    .auth-gear {
        background: rgba(255, 255, 255, 0.05) !important;
        border-color: rgba(255, 255, 255, 0.12) !important;
        color: var(--brown) !important;
    }

    .auth-gear:hover {
        background: rgba(255, 255, 255, 0.10) !important;
    }

    .footer {
        background: #120B06 !important;
        border-top-color: rgba(255, 255, 255, 0.06) !important;
    }

    input:not([type=radio]):not([type=checkbox]):not([type=file]),
    select,
    textarea {
        background: var(--cream);
        color: var(--text);
        border-color: rgba(255, 255, 255, 0.12);
    }

    input::placeholder,
    textarea::placeholder {
        color: var(--muted);
    }

    img:not(.no-dim):not([class*="logo"]):not([class*="icon"]):not([class*="avatar"]) {
        filter: brightness(0.92);
    }

    .category-btn {
        border-color: rgba(255, 255, 255, 0.15) !important;
        color: var(--muted);
    }

    .category-btn:hover {
        border-color: var(--orange);
        color: var(--orange);
    }

    .category-btn.active {
        background: var(--orange) !important;
        border-color: var(--orange) !important;
        color: #1A120A !important;
    }

    .back-btn {
        background: var(--cream) !important;
        border-color: rgba(255, 255, 255, 0.10) !important;
        color: var(--text) !important;
    }

    .back-btn:hover {
        background: #2F2215 !important;
        border-color: var(--orange) !important;
    }

    .buy-btn,
    .btn-next,
    .submit-btn {
        background: linear-gradient(135deg, #E89968 0%, #C97B45 100%) !important;
        color: #1A120A !important;
        box-shadow: 0 10px 24px rgba(232, 153, 104, 0.28) !important;
    }

    .mobile-buy-bar,
    .info-footer,
    .modal,
    .order-summary,
    .qty-section,
    .qty-control,
    .pay-modal-footer {
        background: #241A10 !important;
        border-color: rgba(255, 255, 255, 0.10) !important;
        color: var(--text) !important;
    }

    .phone-box {
        background: #1A120A !important;
        border-color: rgba(255, 255, 255, 0.12) !important;
        color: var(--text) !important;
    }

    .option-item,
    .payment-item {
        background: #2A1E12 !important;
        border-color: rgba(255, 255, 255, 0.10) !important;
        color: var(--text) !important;
    }

    .mobile-buy-bar {
        box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.35) !important;
    }

    .modal-overlay {
        background: rgba(0, 0, 0, 0.72) !important;
    }

    .modal-header,
    .pay-modal-footer {
        border-color: rgba(255, 255, 255, 0.08) !important;
    }

    .modal-close {
        background: rgba(255, 255, 255, 0.06) !important;
        color: var(--text) !important;
    }

    .modal-close:hover {
        background: rgba(255, 255, 255, 0.12) !important;
    }

    .country-select,
    .phone-input,
    .promo-input-wrap input {
        background: #2F2215 !important;
        color: var(--text) !important;
        border-color: rgba(255, 255, 255, 0.20) !important;
    }

    .option-item,
    .payment-item {
        border-color: rgba(255, 255, 255, 0.10) !important;
    }

    .option-item:hover,
    .payment-item:hover {
        border-color: rgba(232, 153, 104, 0.40) !important;
    }

    .option-item.selected,
    .payment-item.selected {
        background: rgba(232, 153, 104, 0.10) !important;
        border-color: var(--orange) !important;
    }

    .payment-item.disabled {
        background: rgba(255, 255, 255, 0.03) !important;
        border-color: rgba(255, 255, 255, 0.08) !important;
    }

    .upload-box {
        background: #241A10 !important;
        border-color: rgba(255, 255, 255, 0.16) !important;
    }

    .upload-box:hover {
        background: #2F2215 !important;
        border-color: var(--orange) !important;
    }

    .upload-box.has-file {
        background: rgba(74, 222, 128, 0.08) !important;
        border-color: rgba(74, 222, 128, 0.40) !important;
    }

    .btn-back {
        background: rgba(255, 255, 255, 0.08) !important;
        color: var(--text) !important;
    }

    .btn-back:hover {
        background: rgba(255, 255, 255, 0.14) !important;
    }

    body.blocked-page {
    }

    #ytFaqSection,
    #netflixEmailCodeNotice,
    #verificationCodeSection,
    #vpnInfoSection {
        background: #2F2215 !important;
        border-color: rgba(255, 255, 255, 0.10) !important;
    }

    #vpnNoteSection {
        background: #3A2D1F !important;
        border-color: rgba(255, 255, 255, 0.10) !important;
    }

    #codeDisplay {
        background: #2F2215 !important;
        border-color: rgba(255, 255, 255, 0.10) !important;
        color: var(--text) !important;
    }

    body[class*="theme-"] {
        background-image:
            radial-gradient(ellipse at 15% -10%, var(--accent-glow-1, rgba(212, 131, 76, 0.14)) 0%, transparent 55%),
            radial-gradient(ellipse at 85% 110%, var(--accent-glow-2, rgba(139, 90, 60, 0.12)) 0%, transparent 55%) !important;
    }

    .brand-mark {
        background: rgba(255, 255, 255, 0.05) !important;
        border-color: rgba(255, 255, 255, 0.10) !important;
    }

    .brand-mark:hover {
        background: rgba(255, 255, 255, 0.08) !important;
    }

    .copy-btn {
        background: #2F2215 !important;
        border-color: rgba(255, 255, 255, 0.18) !important;
        color: var(--brown) !important;
    }

    .copy-btn:hover {
        background: #3A2D1F !important;
        border-color: var(--brown) !important;
    }

    .btn-secondary {
        background: transparent !important;
        border-color: rgba(255, 255, 255, 0.20) !important;
        color: var(--brown) !important;
    }

    .btn-secondary:hover {
        background: #2F2215 !important;
        border-color: var(--brown) !important;
    }

    body > .header {
        background: rgba(26, 18, 10, 0.88) !important;
    }

    [style*="background: white"],
    [style*="background:#fff"],
    [style*="background: #fff"],
    [style*="background:#FFFFFF"],
    [style*="background: #FFFFFF"] {
    }

    /* ===== Login / Register pages ===== */
    .card {
        background: var(--cream) !important;
        border-color: rgba(255, 255, 255, 0.10) !important;
        box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35) !important;
    }

    .field input,
    .field select {
        background: #3A2916 !important;
        color: var(--text) !important;
        border-color: rgba(255, 255, 255, 0.20) !important;
    }

    .mode-btn {
        background: var(--cream) !important;
        border-color: rgba(255, 255, 255, 0.12) !important;
        color: var(--brown) !important;
    }

    .mode-btn.active {
        background: rgba(232, 153, 104, 0.15) !important;
        border-color: rgba(232, 153, 104, 0.4) !important;
    }

    .wa-prefix {
        background: rgba(255, 255, 255, 0.06) !important;
        border-color: rgba(255, 255, 255, 0.12) !important;
        color: var(--brown) !important;
    }

    /* ===== Product pages ===== */
    .main-img,
    .thumb {
        background: var(--cream) !important;
    }

    .feature {
        background: var(--cream) !important;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2) !important;
    }

    .toast {
        background: var(--cream) !important;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4) !important;
        color: var(--text) !important;
    }

    .step-dot {
        background: rgba(255, 255, 255, 0.12) !important;
    }

    .step-dot.active {
        background: var(--orange) !important;
    }

    .step-dot.done {
        background: var(--success) !important;
    }

    .btn-next:disabled {
        background: #3A2D1F !important;
        color: var(--muted) !important;
    }

    .payment-icon.fps {
        background: rgba(74, 222, 128, 0.12) !important;
    }

    .payment-icon.payme {
        background: rgba(255, 171, 0, 0.12) !important;
    }

    .payment-icon.alipay {
        background: rgba(59, 130, 246, 0.12) !important;
    }

    /* PC link row (product content box) */
    .pc-link-row {
        background: var(--cream) !important;
    }

    .pc-fade.left {
        background: linear-gradient(to right, #241A10 70%, transparent) !important;
    }

    .pc-fade.right {
        background: linear-gradient(to left, #241A10 70%, transparent) !important;
    }

    /* ===== Checkout modal inner ===== */
    .modal-body {
        color: var(--text) !important;
    }

    .order-summary {
        background: var(--cream) !important;
        border-color: rgba(255, 255, 255, 0.10) !important;
    }

    .qty-section,
    .qty-control {
        background: var(--cream) !important;
    }

    .promo-input-wrap {
        background: var(--cream) !important;
    }

    /* ===== Dashboard / Topup / Transactions ===== */
    .icon-btn,
    .topup-link,
    .item,
    .btn-action,
    .settings-card,
    .settings-section,
    .settings-mini-btn,
    .panel,
    .welcome,
    .tx-item,
    .topup-card,
    .info-card {
        background: var(--cream) !important;
        border-color: rgba(255, 255, 255, 0.10) !important;
        color: var(--text) !important;
    }

    .icon-btn,
    .topup-link,
    .btn-action,
    .settings-mini-btn {
        color: var(--brown) !important;
    }

    .icon-btn:hover,
    .topup-link:hover,
    .btn-action:hover,
    .settings-mini-btn:hover {
        background: rgba(255, 255, 255, 0.06) !important;
    }

    .btn-action.primary,
    .settings-mini-btn.primary,
    .btn-main {
        background: var(--brown) !important;
        color: #1A120A !important;
        border-color: var(--brown) !important;
    }

    .btn-action.danger {
        background: rgba(239, 68, 68, 0.1) !important;
        border-color: rgba(239, 68, 68, 0.35) !important;
        color: #ff9a9a !important;
    }

    .settings-edit-input,
    .field input,
    .field select {
        background: #2F2215 !important;
        color: var(--text) !important;
        border-color: rgba(255, 255, 255, 0.12) !important;
    }

    .balance {
        background: rgba(255, 255, 255, 0.04) !important;
        border-color: rgba(255, 255, 255, 0.10) !important;
    }

    .item-more {
        background: rgba(255, 255, 255, 0.02) !important;
        border-top-color: rgba(255, 255, 255, 0.08) !important;
    }

    .switch {
        background: #3A2D1F !important;
        border-color: rgba(255, 255, 255, 0.15) !important;
    }

    .switch::after {
        background: #E9DCCB !important;
    }

    .switch.on {
        background: var(--brown) !important;
    }

    .badge.active {
        background: rgba(74, 222, 128, 0.12) !important;
        color: #86efac !important;
        border-color: rgba(74, 222, 128, 0.32) !important;
    }

    .badge.expired {
        background: rgba(239, 68, 68, 0.12) !important;
        color: #ff9a9a !important;
        border-color: rgba(239, 68, 68, 0.32) !important;
    }

    .settings-sheet {
        background: linear-gradient(180deg, #241A10 0%, #1A120A 100%) !important;
        color: var(--text) !important;
    }

    .settings-top {
        background: linear-gradient(180deg, rgba(36, 26, 16, 0.98) 76%, rgba(36, 26, 16, 0)) !important;
    }

    .settings-close {
        background: rgba(255, 255, 255, 0.06) !important;
        border-color: rgba(255, 255, 255, 0.12) !important;
        color: var(--brown) !important;
    }

    .settings-edit-wrap {
        background: rgba(255, 255, 255, 0.03) !important;
        border-color: rgba(255, 255, 255, 0.10) !important;
    }

    .empty {
        background: rgba(255, 255, 255, 0.02) !important;
        border-color: rgba(255, 255, 255, 0.14) !important;
        color: var(--muted) !important;
    }

    @media (max-width: 900px) {
        body:has(.gallery) {
            background:
                radial-gradient(circle at top, rgba(232, 153, 104, 0.20), transparent 38%),
                linear-gradient(180deg, #120B06 0%, #1A120A 28%, #1A120A 100%) !important;
        }

        body:has(.gallery) .header {
            background-color: rgba(8, 5, 3, 0.62) !important;
            background-image: none !important;
            border-bottom-color: rgba(255, 255, 255, 0.08) !important;
            backdrop-filter: blur(20px) saturate(140%) !important;
            -webkit-backdrop-filter: blur(20px) saturate(140%) !important;
        }

        body:has(.gallery) .back-btn {
            background: rgba(18, 11, 6, 0.40) !important;
            border-color: rgba(255, 255, 255, 0.14) !important;
            color: #fff !important;
            box-shadow: 0 14px 28px rgba(0, 0, 0, 0.34) !important;
        }

        body:has(.gallery) .back-btn:hover {
            background: rgba(18, 11, 6, 0.56) !important;
            border-color: rgba(255, 255, 255, 0.22) !important;
        }

        body:has(.gallery) .header-title {
            color: #fff !important;
            text-shadow: 0 1px 6px rgba(0, 0, 0, 0.45);
        }

        body:has(.gallery) .gallery {
            background: #120B06 !important;
        }

        body:has(.gallery) .gallery::before {
            background: linear-gradient(180deg, rgba(8, 5, 3, 0.18) 0%, rgba(8, 5, 3, 0.10) 30%, rgba(8, 5, 3, 0.74) 100%) !important;
        }

        body:has(.gallery) .gallery::after {
            background: linear-gradient(180deg, rgba(26, 18, 10, 0) 0%, rgba(26, 18, 10, 0.92) 68%, #1A120A 100%) !important;
        }

        body:has(.gallery) .thumbs {
            background: rgba(26, 18, 10, 0.42) !important;
            border-color: rgba(255, 255, 255, 0.10) !important;
            box-shadow: 0 18px 36px rgba(0, 0, 0, 0.36) !important;
        }

        body:has(.gallery) .thumb {
            background: rgba(47, 34, 21, 0.84) !important;
            border-color: transparent !important;
            box-shadow: 0 10px 22px rgba(0, 0, 0, 0.36) !important;
        }

        body:has(.gallery) .thumb.active {
            border-color: rgba(232, 153, 104, 0.70) !important;
            box-shadow: 0 16px 28px rgba(0, 0, 0, 0.42) !important;
        }

        body:has(.gallery) .info-panel {
            background: rgba(26, 18, 10, 0.92) !important;
            border-color: rgba(255, 255, 255, 0.08) !important;
            box-shadow: 0 -16px 40px rgba(0, 0, 0, 0.38) !important;
        }

        body:has(.gallery) .feature {
            background: rgba(47, 34, 21, 0.76) !important;
            box-shadow: 0 10px 22px rgba(0, 0, 0, 0.22) !important;
        }

        body:has(.gallery) .mobile-buy-bar {
            background: #1A120A !important;
            border-top-color: rgba(255, 255, 255, 0.08) !important;
            box-shadow: 0 -16px 32px rgba(0, 0, 0, 0.34) !important;
            padding-bottom: max(14px, calc(10px + env(safe-area-inset-bottom))) !important;
        }
    }
}

@media (max-width: 900px) {
    body:has(.gallery) {
        background:
            radial-gradient(circle at top, rgba(212, 131, 76, 0.16), transparent 38%),
            linear-gradient(180deg, #FFFBF7 0%, #FFF8F0 28%, #FFF8F0 100%);
    }

    body:has(.gallery) .main {
        max-width: none;
        gap: 0;
        padding: 0 0 104px 0;
        position: relative;
    }

    body:has(.gallery) .loading,
    body:has(.gallery) .error {
        min-height: 100vh;
        padding: 120px 24px 160px;
    }

    body:has(.gallery) .gallery {
        max-width: 100%;
        min-height: clamp(340px, 56vh, 460px);
        padding-top: 0;
        position: relative;
        overflow: hidden;
        background: #1A120A;
    }

    body:has(.gallery) .gallery::before {
        content: '';
        position: absolute;
        inset: 0;
        background: linear-gradient(180deg, rgba(44, 27, 17, 0.20) 0%, rgba(44, 27, 17, 0.06) 32%, rgba(44, 27, 17, 0.58) 100%);
        pointer-events: none;
        z-index: 1;
    }

    body:has(.gallery) .gallery::after {
        content: '';
        position: absolute;
        left: 0;
        right: 0;
        bottom: -1px;
        height: 140px;
        background: linear-gradient(180deg, rgba(255, 248, 240, 0) 0%, rgba(255, 248, 240, 0.92) 66%, #FFF8F0 100%);
        pointer-events: none;
        z-index: 1;
    }

    body:has(.gallery) .main-img {
        width: 100%;
        height: clamp(340px, 56vh, 460px);
        min-height: clamp(340px, 56vh, 460px);
        aspect-ratio: auto;
        border-radius: 0;
        margin-bottom: 0;
        box-shadow: none;
    }

    body:has(.gallery) .main-img img {
        display: block;
        width: 100%;
        height: 100%;
        object-fit: cover;
        object-position: center;
        transform: scale(1.02);
    }

    body:has(.gallery) .thumbs {
        position: absolute;
        left: 16px;
        right: 16px;
        bottom: 22px;
        z-index: 2;
        gap: 8px;
        padding: 10px;
        overflow-x: auto;
        background: rgba(255, 255, 255, 0.18);
        border: 1px solid rgba(255, 255, 255, 0.30);
        border-radius: 18px;
        box-shadow: 0 16px 36px rgba(38, 22, 11, 0.18);
        backdrop-filter: blur(18px);
        -webkit-backdrop-filter: blur(18px);
        scrollbar-width: none;
    }

    body:has(.gallery) .thumbs:empty {
        display: none;
    }

    body:has(.gallery) .thumb {
        width: 58px;
        height: 58px;
        background: rgba(255, 255, 255, 0.84);
        border-width: 1.5px;
        border-color: transparent;
        box-shadow: 0 10px 20px rgba(17, 10, 6, 0.18);
        transition: transform 0.22s ease, border-color 0.22s ease, box-shadow 0.22s ease;
    }

    body:has(.gallery) .thumb.active {
        transform: translateY(-3px);
        border-color: rgba(255, 255, 255, 0.80);
        box-shadow: 0 14px 26px rgba(17, 10, 6, 0.22);
    }

    body:has(.gallery) .info-panel {
        max-width: 100%;
        height: auto;
        margin-top: -48px;
        padding: 18px 18px 0;
        position: relative;
        z-index: 3;
        background: rgba(255, 248, 240, 0.92);
        border: 1px solid rgba(255, 255, 255, 0.72);
        border-radius: 30px 30px 0 0;
        box-shadow: 0 -12px 40px rgba(56, 31, 14, 0.12);
        backdrop-filter: blur(18px);
        -webkit-backdrop-filter: blur(18px);
    }

    body:has(.gallery) .info-header {
        padding-bottom: 20px;
        margin-bottom: 20px;
    }

    body:has(.gallery) .title {
        font-size: clamp(20px, 5.6vw, 24px);
        line-height: 1.3;
        letter-spacing: -0.01em;
    }

    body:has(.gallery) .price-row {
        flex-wrap: wrap;
        row-gap: 8px;
    }

    body:has(.gallery) .info-scroll {
        padding-right: 0;
    }

    body:has(.gallery) .info-scroll::-webkit-scrollbar {
        display: none;
    }

    body:has(.gallery) .desc {
        font-size: 15px;
        line-height: 1.9;
    }

    body:has(.gallery) .feature {
        background: rgba(255, 255, 255, 0.68);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
    }

    body:has(.gallery) .mobile-buy-bar {
        padding: 12px 16px;
        padding-bottom: max(14px, calc(10px + env(safe-area-inset-bottom)));
        background: rgba(255, 248, 240, 0.86);
        border-top: 1px solid rgba(255, 255, 255, 0.68);
        box-shadow: 0 -16px 32px rgba(56, 31, 14, 0.12);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
    }

    body:has(.gallery) .mobile-buy-bar .buy-btn {
        box-shadow: 0 14px 28px rgba(212, 131, 76, 0.28);
    }

    body:has(.gallery) .header {
        background-color: rgba(29, 18, 10, 0.46);
        background-image: none;
        border-bottom-color: rgba(255, 255, 255, 0.10);
        backdrop-filter: blur(20px) saturate(140%);
        -webkit-backdrop-filter: blur(20px) saturate(140%);
    }

    body:has(.gallery) .header-inner {
        max-width: none;
        padding: calc(10px + env(safe-area-inset-top)) 16px 14px;
        gap: 12px;
    }

    body:has(.gallery) .back-btn {
        width: 44px;
        height: 44px;
        border-radius: 14px;
        background: rgba(255, 255, 255, 0.18);
        border-color: rgba(255, 255, 255, 0.30);
        color: #fff;
        box-shadow: 0 12px 28px rgba(0, 0, 0, 0.16);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
    }

    body:has(.gallery) .back-btn:hover {
        background: rgba(255, 255, 255, 0.28);
        border-color: rgba(255, 255, 255, 0.42);
    }

    body:has(.gallery) .header-title {
        color: #fff;
        text-shadow: 0 1px 6px rgba(0, 0, 0, 0.28);
    }
}

/* ============================
   Product image zoom + details expansion
   ============================ */

.pz-handle-zone {
    display: none;
    padding: 0;
    margin: 0;
    border: 0;
    background: transparent;
    cursor: pointer;
    z-index: 8;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.pz-handle-zone:focus-visible {
    outline: 2px solid rgba(212, 131, 76, 0.55);
    outline-offset: -4px;
    border-radius: 999px;
}

.pz-lightbox {
    position: fixed;
    inset: 0;
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.28s ease, visibility 0s linear 0.28s;
    -webkit-tap-highlight-color: transparent;
}

.pz-lightbox::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(16, 10, 6, 0.74);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}

.pz-lightbox-backdrop {
    position: absolute;
    inset: 0;
}

body.pz-lightbox-open {
    overflow: hidden;
}

body.pz-lightbox-open .pz-lightbox {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition-delay: 0s;
}

.pz-lightbox-stage {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.pz-lightbox-img {
    position: fixed;
    top: 50%;
    left: 50%;
    max-width: calc(100vw - 36px);
    max-height: calc(100vh - 104px);
    width: auto;
    height: auto;
    object-fit: contain;
    object-position: center;
    transform: translate(-50%, -50%) scale(0.82);
    opacity: 0;
    border-radius: 24px;
    box-shadow: 0 36px 84px rgba(0, 0, 0, 0.42);
    transition:
        transform 0.38s cubic-bezier(0.22, 1, 0.36, 1),
        opacity 0.26s ease;
    will-change: transform, opacity;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

body.pz-lightbox-open .pz-lightbox-img {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
}

@media (max-width: 900px) {
    .pz-lightbox-img {
        max-width: calc(100vw - 24px);
        max-height: calc(100vh - 120px);
        max-height: calc(100dvh - 120px);
    }
}

.pz-close {
    position: fixed;
    top: max(16px, calc(env(safe-area-inset-top) + 4px));
    right: max(16px, calc(env(safe-area-inset-right) + 4px));
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 0;
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transform: translateY(-10px) scale(0.94);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    transition: opacity 0.22s ease, transform 0.22s ease, background 0.18s ease;
}

body.pz-lightbox-open .pz-close {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.pz-close:hover {
    background: rgba(255, 255, 255, 0.24);
}

@media (max-width: 900px) {
    body:has(.gallery) .pz-handle-zone {
        display: block;
        position: absolute;
        top: 0;
        left: 50%;
        transform: translateX(-50%);
        width: 140px;
        height: 30px;
    }

    body:has(.gallery) .pz-handle-zone::before {
        content: '';
        position: absolute;
        top: 10px;
        left: 50%;
        transform: translateX(-50%);
        width: 48px;
        height: 5px;
        border-radius: 999px;
        background: rgba(139, 90, 60, 0.32);
        transition: background 0.2s ease, width 0.25s ease;
    }

    body:has(.gallery) .pz-handle-zone:hover::before,
    body:has(.gallery) .pz-handle-zone:active::before {
        background: rgba(139, 90, 60, 0.55);
        width: 56px;
    }

    body.pz-details-open:has(.gallery) .pz-handle-zone::before {
        background: rgba(212, 131, 76, 0.7);
    }

    body:has(.gallery) .gallery,
    body:has(.gallery) .gallery::after,
    body:has(.gallery) .main-img,
    body:has(.gallery) .main-img img,
    body:has(.gallery) .thumbs,
    body:has(.gallery) .info-panel,
    body:has(.gallery) .info-scroll,
    body:has(.gallery) .header,
    body:has(.gallery) .mobile-buy-bar {
        transition:
            transform 0.36s cubic-bezier(0.22, 1, 0.36, 1),
            opacity 0.28s ease,
            min-height 0.36s cubic-bezier(0.22, 1, 0.36, 1),
            height 0.36s cubic-bezier(0.22, 1, 0.36, 1),
            margin-top 0.36s cubic-bezier(0.22, 1, 0.36, 1),
            box-shadow 0.36s cubic-bezier(0.22, 1, 0.36, 1),
            background 0.28s ease;
    }

    body.pz-lightbox-open:has(.gallery) .gallery {
        transform: translateY(-10px) scale(1.01);
    }

    body.pz-lightbox-open:has(.gallery) .thumbs {
        opacity: 0;
        transform: translateY(18px);
        pointer-events: none;
    }

    body.pz-lightbox-open:has(.gallery) .info-panel {
        transform: translateY(36px);
        opacity: 0.5;
    }

    body.pz-lightbox-open:has(.gallery) .mobile-buy-bar,
    body.pz-lightbox-open:has(.gallery) .header {
        opacity: 0;
        pointer-events: none;
    }

    /* Details-open: image fully collapses, info-panel fills the screen below header. */
    body.pz-details-open:has(.gallery) .main {
        padding-top: 72px; /* clear fixed header (~69px) */
    }

    body.pz-details-open:has(.gallery) .gallery {
        height: 0;
        min-height: 0;
        overflow: hidden;
        opacity: 0;
        pointer-events: none;
    }

    body.pz-details-open:has(.gallery) .main-img {
        height: 0;
        min-height: 0;
    }

    body.pz-details-open:has(.gallery) .thumbs {
        opacity: 0;
        transform: translateY(-14px);
        pointer-events: none;
    }

    body.pz-details-open:has(.gallery) .info-panel {
        margin-top: 0;
        padding-top: 36px; /* room for the drag handle */
        border-radius: 0;
        background: var(--light);
        box-shadow: none;
    }

    /* Lock page scroll while details are open. html/body overflow is also
       set inline from product-zoom.js because `:has` on <html> is unreliable. */
    /* Details-open lets the whole page scroll naturally — no internal
       info-scroll region — so the customer can scroll anywhere (title +
       description) as one continuous page. */
    body.pz-details-open:has(.gallery) .info-scroll {
        max-height: none;
        overflow: visible;
        padding-bottom: 16px;
    }

    /* ---- Details-open + scrolled down: shrink the header to a compact
       preview (title + price only), keeping the handle visible and leaving
       more room for the description below. */
    body.pz-details-open:has(.gallery) .badge,
    body.pz-details-open:has(.gallery) .old-price,
    body.pz-details-open:has(.gallery) .discount {
        transition: opacity 0.28s ease, max-height 0.28s ease,
                    margin 0.28s ease, padding 0.28s ease;
    }

    body.pz-details-open.pz-details-scrolled:has(.gallery) .info-header {
        padding-bottom: 8px;
        margin-bottom: 8px;
    }

    body.pz-details-open.pz-details-scrolled:has(.gallery) .info-header .badge {
        opacity: 0;
        max-height: 0;
        margin: 0;
        padding-top: 0;
        padding-bottom: 0;
        overflow: hidden;
        pointer-events: none;
    }

    body.pz-details-open.pz-details-scrolled:has(.gallery) .old-price,
    body.pz-details-open.pz-details-scrolled:has(.gallery) .discount {
        display: none;
    }

    body.pz-details-open.pz-details-scrolled:has(.gallery) .title {
        font-size: 18px;
        letter-spacing: -0.01em;
        margin-bottom: 4px;
    }

    body.pz-details-open.pz-details-scrolled:has(.gallery) .price {
        font-size: 20px;
    }

    body.pz-details-open.pz-details-scrolled:has(.gallery) .price .currency {
        font-size: 13px;
    }

    /* With the header compact, grow the scroll area so the description
       takes up the freed space smoothly. */
    body.pz-details-open.pz-details-scrolled:has(.gallery) .info-scroll {
        max-height: calc(100vh - 72px - 36px - 40px - env(safe-area-inset-bottom));
        max-height: calc(100dvh - 72px - 36px - 40px - env(safe-area-inset-bottom));
    }

    /* Shared transitions so handle-tap and scroll-triggered state changes
       land in the same smooth animation. */
    body:has(.gallery) .title,
    body:has(.gallery) .price-row,
    body:has(.gallery) .price,
    body:has(.gallery) .info-header {
        transition:
            font-size 0.28s cubic-bezier(0.22, 1, 0.36, 1),
            padding 0.28s cubic-bezier(0.22, 1, 0.36, 1),
            margin 0.28s cubic-bezier(0.22, 1, 0.36, 1);
    }

    /* ---- Sticky in-flow preview (NOT details-open) ----
       As the user scrolls the page, the info-header sticks under the site
       header. Normal page scroll — no forced layout, no jumps. Scrolling
       back up reveals the photo naturally. */
    body:has(.gallery) .info-header {
        position: sticky;
        top: 69px;
        z-index: 4;
        background: var(--light);
        margin-left: -18px;
        margin-right: -18px;
        padding-left: 18px;
        padding-right: 18px;
    }

    /* Shrink the sticky header once it's pinned. Same compact preset as
       details-scrolled, for visual consistency between the two states. */
    body.pz-scrolled:has(.gallery) .info-header {
        margin-bottom: 0;
        box-shadow: 0 6px 18px rgba(56, 31, 14, 0.08);
    }

    body.pz-scrolled:has(.gallery) .info-header .badge {
        opacity: 0;
        max-height: 0;
        margin: 0;
        padding-top: 0;
        padding-bottom: 0;
        overflow: hidden;
        pointer-events: none;
    }

    body.pz-scrolled:has(.gallery) .old-price,
    body.pz-scrolled:has(.gallery) .discount {
        display: none;
    }

    body.pz-scrolled:has(.gallery) .title {
        font-size: 18px;
        letter-spacing: -0.01em;
        margin-bottom: 4px;
    }

    body.pz-scrolled:has(.gallery) .price {
        font-size: 20px;
    }

    body.pz-scrolled:has(.gallery) .price .currency {
        font-size: 13px;
    }

    /* When scrolled, make the site header solid chocolate so description
       content doesn't bleed through its translucent gradient.
       !important + separate longhand because the dark-mode .header rule
       uses !important and a gradient shorthand. */
    body.pz-scrolled:has(.gallery) .header {
        background-color: var(--light) !important;
        background-image: none !important;
        border-bottom-color: rgba(139, 90, 60, 0.10) !important;
    }

    /* When scrolled (or fully opened), swap the back-button and title to
       theme colors so they stay visible against the solid header background
       instead of disappearing into the white-translucent gallery overlay. */
    body.pz-scrolled:has(.gallery) .back-btn,
    body.pz-details-open:has(.gallery) .back-btn {
        background: rgba(139, 90, 60, 0.10) !important;
        border-color: rgba(139, 90, 60, 0.22) !important;
        color: var(--text) !important;
        box-shadow: none !important;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
    }

    body.pz-scrolled:has(.gallery) .back-btn:hover,
    body.pz-details-open:has(.gallery) .back-btn:hover {
        background: rgba(139, 90, 60, 0.18) !important;
        border-color: rgba(139, 90, 60, 0.32) !important;
    }

    body.pz-scrolled:has(.gallery) .header-title,
    body.pz-details-open:has(.gallery) .header-title {
        color: var(--text) !important;
        text-shadow: none !important;
    }

    /* Close the visible gap between features and the mobile buy bar by
       extending the info-panel's own background all the way down, instead of
       padding the main element (which leaves the body background visible). */
    body:has(.gallery) .main {
        padding-bottom: 0;
    }

    body:has(.gallery) .info-panel {
        padding-bottom: 96px;
    }
}

:root {
    color-scheme: light dark;
}
